dji_flight_assistant_module.hpp
Go to the documentation of this file.
1 
29 #ifndef DJI_FLIGHT_ASSISTANT_MODULE_HPP
30 #define DJI_FLIGHT_ASSISTANT_MODULE_HPP
31 
32 #include "dji_vehicle_callback.hpp"
33 
34 namespace DJI {
35 namespace OSDK {
36 
37 #define MAX_PARAMETER_VALUE_LENGTH 8
38 class FlightLink;
39 class FlightAssistant {
40  public:
41  FlightAssistant(Vehicle *vehicle);
42  ~FlightAssistant();
43 
44  public:
45  const static uint16_t MAX_FLIGHT_HEIGHT = 500;
46  const static uint16_t MIN_GO_HOME_HEIGHT = 20;
47  const static uint32_t MAX_FLY_RADIUS = 20000;
48 
49  enum ParamHashValue : uint32_t {
50  USE_RTK_DATA = 1288992843,
51  GO_HOME_ALTITUDE = 952919004,
52  HORIZ_AVOID = 3001460201,
53  UPWARDS_AVOID = 854709684,
54  };
55 
56  enum RtkEnableData : uint8_t {
57  RTK_DISABLE = 0,
58  RTK_ENABLE = 1,
59  };
60  enum AvoidEnable : uint8_t {
61  AVOID_DISABLE = 0,
62  AVOID_ENABLE = 1,
63  };
64  enum UpwardsAvoidEnable : uint8_t {
65  UPWARDS_AVOID_DISABLE = 0,
66  UPWARDS_AVOID_ENABLE = 1,
67  };
68  enum HomeLocationType : uint8_t {
69  DJI_HOMEPOINT_AIRCRAFT_LOACTON =
70  0,
71  DJI_HOMEPOINT_SDK_SET_LOCAIION =
72  3,
73  };
74  typedef uint16_t GoHomeAltitude;
76 #pragma pack(1)
77  typedef struct ParameterData {
78  uint32_t hashValue;
79  uint8_t paramValue[MAX_PARAMETER_VALUE_LENGTH];
80  } ParameterData;
81 
83  typedef struct RtkEnableAck {
84  uint8_t retCode;
85  uint32_t hashValue;
86  uint8_t rtkEnable;
87  } RtkEnableAck;
88 
90  typedef struct AvoidEnableAck {
91  uint8_t retCode;
92  uint32_t hashValue;
93  uint8_t avoidEnable;
95 
96  typedef struct UpwardsAvoidEnableAck {
97  uint8_t retCode;
98  uint32_t hashValue;
99  uint8_t upwardsAvoidEnable;
100  } UpwardsAvoidEnableAck;
101 
103  typedef struct GoHomeAltitudeAck {
104  uint8_t retCode;
105  uint32_t hashValue;
106  GoHomeAltitude altitude;
108 
109  typedef struct SetHomeLocationData {
110  HomeLocationType homeType;
111  double latitude;
112  double longitude;
113  uint8_t healthy;
114  } SetHomeLocationData; // pack(1)
115 
116 #pragma pack()
117 
120  typedef struct UCBRetCodeHandler {
121  void (*UserCallBack)(ErrorCode::ErrorCodeType errCode, UserData userData);
122  UserData userData;
124 
125  static const int maxSize = 32;
126  UCBRetCodeHandler ucbHandler[maxSize];
127 
130  template <typename T>
132  void (*UserCallBack)(ErrorCode::ErrorCodeType errCode, T param,
133  UserData userData);
134  UserData userData;
135  };
136 
139  template <typename T>
141 
142  UCBRetCodeHandler *allocUCBHandler(void *callback, UserData userData);
143 
152  ErrorCode::ErrorCodeType writeParameterByHashSync(uint32_t hashValue,
153  void *data, uint8_t len,
154  int timeout);
164  void writeParameterByHashAsync(
165  uint32_t hashValue, void *data, uint8_t len,
166  void (*ackDecoderCB)(Vehicle *vehicle, RecvContainer recvFrame,
167  UCBRetCodeHandler *ucb),
168  void (*userCB)(ErrorCode::ErrorCodeType, UserData userData),
169  UserData userData, int timeout = 500, int retry_time = 2);
170 
178  ErrorCode::ErrorCodeType readParameterByHashSync(ParamHashValue hashValue,
179  void *param, int timeout);
180 
181  template <typename DataT>
182  void readParameterByHashAsync(
183  ParamHashValue hashValue,
184  void (*ackDecoderCB)(Vehicle *vehicle, RecvContainer recvFrame,
186  void (*userCB)(ErrorCode::ErrorCodeType, DataT data, UserData userData),
187  UserData userData, int timeout = 500, int retry_time = 2);
188 
195  ErrorCode::ErrorCodeType setRtkEnableSync(RtkEnableData rtkEnable,
196  int timeout);
197 
207  void setRtkEnableAsync(RtkEnableData rtkEnable,
208  void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
209  UserData userData),
210  UserData userData);
211 
218  ErrorCode::ErrorCodeType getRtkEnableSync(RtkEnableData &rtkEnable,
219  int timeout);
220 
230  void getRtkEnableAsync(void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
231  RtkEnableData rtkEnable,
232  UserData userData),
233  UserData userData);
234 
242  ErrorCode::ErrorCodeType setUpwardsAvoidanceEnabledSync(UpwardsAvoidEnable upwardsAvoidEnable,
243  int timeout);
244 
255  void setUpwardsAvoidanceEnabledAsync(UpwardsAvoidEnable upwardsAvoidEnable,
256  void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
257  UserData userData),
258  UserData userData);
259 
267  ErrorCode::ErrorCodeType getUpwardsAvoidanceEnabledSync(UpwardsAvoidEnable &upwardsAvoidEnable,
268  int timeout);
269 
280  void getUpwardsAvoidanceEnabledAsync(void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
281  UpwardsAvoidEnable upwardsEnable,
282  UserData userData),
283  UserData userData);
296  ErrorCode::ErrorCodeType setGoHomeAltitudeSync(GoHomeAltitude altitude,
297  int timeout);
298 
314  void setGoHomeAltitudeAsync(
315  GoHomeAltitude altitude,
316  void (*UserCallBack)(ErrorCode::ErrorCodeType retCode, UserData userData),
317  UserData userData);
318 
325  ErrorCode::ErrorCodeType getGoHomeAltitudeSync(GoHomeAltitude &altitude,
326  int timeout);
327 
337  void getGoHomeAltitudeAsync(
338  void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
339  GoHomeAltitude altitude, UserData userData),
340  UserData userData);
341 
348  ErrorCode::ErrorCodeType setCollisionAvoidanceEnabledSync(
349  AvoidEnable avoidEnable, int timeout);
350 
360  void setCollisionAvoidanceEnabledAsync(
361  AvoidEnable avoidEnable,
362  void (*UserCallBack)(ErrorCode::ErrorCodeType retCode, UserData userData),
363  UserData userData);
364 
371  ErrorCode::ErrorCodeType getCollisionAvoidanceEnabledSync(
372  AvoidEnable &avoidEnable, int timeout);
373 
383  void getCollisionAvoidanceEnabledAsync(
384  void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
385  AvoidEnable avoidEnable, UserData userData),
386  UserData userData);
387 
401  ErrorCode::ErrorCodeType setHomeLocationSync(SetHomeLocationData homeLocation,
402  int timeout);
403 
421  void setHomeLocationAsync(
422  SetHomeLocationData homeLocation,
423  void (*UserCallBack)(ErrorCode::ErrorCodeType retCode, UserData userData),
424  UserData userData);
425 
426  private:
427  FlightLink *flightLink;
428 
429  template <typename AckT>
430  static ErrorCode::ErrorCodeType commonDataUnpacker(RecvContainer recvFrame,
431  AckT &ack);
432  static void setParameterDecoder(Vehicle *vehicle, RecvContainer recvFrame,
433  UCBRetCodeHandler *ucb);
434 
435  static void getRtkEnableDecoder(Vehicle *vehicle, RecvContainer recvFrame,
437 
438  static void getAvoidEnableDecoder(Vehicle *vehicle, RecvContainer recvFrame,
440  static void getUpwardsAvoidEnableDecoder(Vehicle *vehicle, RecvContainer recvFrame,
442  static void getGoHomeAltitudeDecoder(Vehicle *vehicle,
443  RecvContainer recvFrame,
445  static void setHomePointAckDecoder(Vehicle *vehicle, RecvContainer recvFrame,
446  UCBRetCodeHandler *ucb);
452  static bool goHomeAltitudeValidCheck(uint16_t altitude);
453 };
454 }
455 }
456 
457 #endif // DJI_FLIGHT_ASSISTANT_MODULE_HPP
void * UserData
This is used as the datatype for all data arguments in callbacks.
Definition: dji_type.hpp:75
Definition: dji_flight_assistant_module.hpp:83
type of callback only deal the retCode for user
Definition: dji_flight_assistant_module.hpp:120
int64_t ErrorCodeType
Unified error type.
Definition: dji_error.hpp:144
Type definition for new Vehicle-style callbacks.
Definition: dji_flight_assistant_module.hpp:103
Received info.
Definition: dji_vehicle_callback.hpp:59
struct of callback deal the param and retCode for user  
Definition: dji_flight_assistant_module.hpp:131
Definition: dji_ack.cpp:38
Definition: dji_flight_assistant_module.hpp:90