dji_ack.hpp
Go to the documentation of this file.
1 
31 #ifndef DJI_ACK_HPP
32 #define DJI_ACK_HPP
33 
34 #include "dji_command.hpp"
35 #include "dji_mission_type.hpp"
36 #include "dji_type.hpp"
37 #include "dji_version.hpp"
38 #include <map>
39 
40 namespace DJI
41 {
42 namespace OSDK
43 {
50 class ACK
51 {
52 public:
53 #pragma pack(1)
54  typedef struct Entry
55  {
56  uint8_t cmd_set;
57  uint8_t cmd_id;
58  uint16_t len;
59  uint8_t* buf; // ugly design before, now means the recv package data buf
60  uint8_t seqNumber;
61  Version::FirmWare version;
62  } Entry; // pack(1)
63 
64  /*
65  * ACK structures exposed to user
66  */
67 
68  typedef struct HotPointStartInternal
69  {
70  uint8_t ack;
71  float32_t maxRadius;
72  } HotPointStartInternal; // pack(1)
73 
74  typedef struct HotPointReadInternal
75  {
76  uint8_t ack;
77  HotPointSettings data;
78 
79  // TODO fix/remove once verified with FC team
80  uint8_t extraByte;
81  } HotPointReadInternal; // pack(1)
82 
83  typedef struct WayPointAddPointInternal
84  {
85  uint8_t ack;
86  uint8_t index;
87  } WayPointAddPointInternal; // pack(1)
88 
89  typedef struct WayPointIndexInternal
90  {
91  uint8_t ack;
92  WayPointSettings data;
93  } WayPointIndexInternal; // pack(1)
94 
95  typedef struct WayPoint2CommonRsp
96  {
97  Entry info;
98  bool updated = false;
99  } WayPoint2CommonRsp;
100 
101  typedef struct ExtendedFunctionRsp{
102  Entry info;
103  bool updated = false;
104  } ExtendedFunctionRsp;
105 
106  typedef struct WayPointVelocityInternal
107  {
108  uint8_t ack;
109  float32_t idleVelocity;
110  } WayPointVelocityInternal; // pack(1)
111 
112  typedef struct WayPointInitInternal
113  {
114  uint8_t ack;
116  } WayPointInitInternal; // pack(1)
117 
118  typedef struct MFIOGetInternal
119  {
120  uint8_t result;
121  uint32_t value;
122  } MFIOGetInternal; // pack(1)
123 
124  typedef struct ParamAckInternal
125  {
126  uint8_t retCode;
127  uint32_t hashValue;
128  uint8_t paramValue[8];
129  } ParamAckInternal; // pack(1)
130 
131  typedef struct SetHomeLocationAckInternal
132  {
133  uint8_t result;
134  uint8_t retCode;
135  } SetHomeLocationAckInternal; // pack(1)
136  /*
137  * ACK structures exposed to user
138  */
139 
146  typedef struct ErrorCode
147  {
148  Entry info;
149  uint32_t data;
150  } ErrorCode; // pack(1)
151 
156  typedef struct ParamAck
157  {
158  Entry info;
159  ParamAckInternal data;
160  bool updated = false;
161  } ParamAck; // pack(1)
162 
163  typedef struct SetHomeLocationAck
164  {
165  Entry info;
166  SetHomeLocationAckInternal data;
167  bool updated = false;
168  }SetHomeLocationAck;
173  typedef struct MFIOGet
174  {
175  ErrorCode ack;
176  uint32_t value;
177  } MFIOGet; // pack(1)
178 
183  typedef struct HotPointStart
184  {
185  ErrorCode ack;
186  float32_t maxRadius;
187  } HotPointStart; // pack(1)
188 
193  typedef struct HotPointRead
194  {
195  ErrorCode ack;
196  HotPointSettings data;
197 
198  // TODO fix/remove once verified with FC team
199  uint8_t extraByte;
200  } HotPointRead; // pack(1)
201 
206  typedef struct WayPointIndex
207  {
208  ErrorCode ack;
209  WayPointSettings data;
210  } WayPointIndex; // pack(1)
211 
216  typedef struct WayPointAddPoint
217  {
218  ErrorCode ack;
219  uint8_t index;
220  } WayPointAddPoint; // pack(1)
221 
226  typedef struct WayPointVelocity
227  {
228  ErrorCode ack;
229  float32_t idleVelocity;
230  } WayPointVelocity; // pack(1)
231 
235  typedef struct WayPointInit
236  {
237  ErrorCode ack;
239  } WayPointInit; // pack(1)
240 
245  typedef struct DroneVersion
246  {
247  ACK::ErrorCode ack;
248  Version::VersionData data;
249  } DroneVersion; // pack(1)
250 
255  typedef struct WayPointReachedData
256  {
257  uint8_t incident_type;
258  uint8_t waypoint_index;
259  uint8_t current_status;
260  uint8_t reserved_1;
261  uint8_t reserved_2;
262  } WayPointReachedData; // pack(1)
263 
268  typedef struct WayPointStatusPushData{
269  uint8_t mission_type;
270  uint8_t waypoint_index;
271  uint8_t current_status;
273  uint16_t reserved_1;
275 
279  static const int IMG_240P_SIZE = 240 * 320;
280  typedef uint8_t Image[IMG_240P_SIZE];
284  typedef struct ImageMeta
285  {
286  Image image;
287  char name[12];
288  } ImageMeta; // pack(1)
292  typedef struct StereoImgData
293  {
294  uint32_t frame_index;
295  uint32_t time_stamp;
296  uint8_t num_imgs;
297  /*
298  * There could be 50 different kinds of images coming from the drone,
299  * 5 camera pairs and 10 images types.
300  * Here we use an uint64_t to describe which image is coming
301  * from the USB line, each bit represents if there's data or not
302  * Please use AdvancedSensing::ReceivedImgDesc to match them
303  * For M210, we support up to 4 images at the same time
304  */
305  uint64_t img_desc;
306  // @note for M210, at most 4 imgs come at the same time.
307  ImageMeta img_vec[4];
308  } StereoImgData; // pack(1)
312  static const int IMG_VGA_SIZE = 640 * 480;
313  typedef uint8_t VGAImage[IMG_VGA_SIZE];
317  typedef struct StereoVGAImgData
318  {
319  uint32_t frame_index;
320  uint32_t time_stamp;
321  uint8_t num_imgs;
322  uint8_t direction;
323  // @note VGA imgs always come in pair
324  VGAImage img_vec[2];
325  } StereoVGAImgData; // pack(1)
326 
330  typedef struct FCTimeInUTC
331  {
332  uint32_t fc_timestamp_us;
333  uint32_t utc_yymmdd;
334  uint32_t utc_hhmmss;
335  } FCTimeInUTC; // pack(1)
336 
337  typedef struct HeartBeatAck
338  {
339  Entry info;
340  HeartBeatPack data;
341  } HeartBeatAck; //pack(1)
342 
343  typedef union TypeUnion {
344  uint8_t raw_ack_array[MAX_INCOMING_DATA_SIZE];
345  uint8_t versionACK[MAX_ACK_SIZE];
346  uint16_t ack;
347  uint8_t commandACK;
348  uint8_t missionACK;
349  uint8_t subscribeACK;
350  uint8_t mfioACK;
351 
352  /*
353  * ACK(s) containing ACK data plus extra payload
354  */
355  HotPointStartInternal hpStartACK;
356  HotPointReadInternal hpReadACK;
357  WayPointInitInternal wpInitACK;
358  WayPointAddPointInternal wpAddPointACK;
359  WayPointIndexInternal wpIndexACK;
360  WayPointVelocityInternal wpVelocityACK;
361  MFIOGetInternal mfioGetACK;
362  ParamAckInternal paramAckData;
363  SetHomeLocationAckInternal setHomeLocationACK;
364 
365  /*
366  * Push Data in ground-station mode
367  */
368  WayPointReachedData wayPointReachedData;
369  WayPointStatusPushData wayPointStatusPushData;
370 
371  /*
372  * Push Data from AdvancedSensing protocol
373  */
374  StereoImgData *stereoImgData;
375  StereoVGAImgData *stereoVGAImgData;
376 
377  /*
378  * Push Data from GPS or RTK
379  */
380  FCTimeInUTC fcTimeInUTC;
381  uint8_t ppsSourceType;
382  /*
383  * Heart Beat Pack between FC and OSDK
384  */
385  HeartBeatPack heartbeatpack;
386  } TypeUnion; // pack(1)
387 
388 #pragma pack()
389 
390 public:
392  static const bool SUCCESS;
394  static const bool FAIL;
395 
396  // Since control authority is a single command, we keep track of state in the
397  // ack-handling
398  // to unify next steps on receiving a control authority ack.
399  static const uint8_t OBTAIN_CONTROL = 1;
400  static const uint8_t RELEASE_CONTROL = 0;
401 
402 public:
412  static bool getError(ErrorCode ack);
413 
424  static void getErrorCodeMessage(ErrorCode ack, const char* func);
425 
426 private:
427  static void getCMDSetActivationMSG(ACK::ErrorCode ack);
428  static void getCommonErrorCodeMessage(ACK::ErrorCode ack);
429  static void getCMDSetSubscribeMSG(ACK::ErrorCode ack);
430  static void getCMDSetControlMSG(ACK::ErrorCode ack);
431  static void getMotorErrorMessage(ACK::ErrorCode ack);
432  static void getCMDIDSetControlMSG(uint8_t ack, Version::FirmWare version);
433  static void getCMDIDControlMSG(ACK::ErrorCode ack);
434  static void getCMDIDTaskMSG(ACK::ErrorCode ack);
435  static void getCMDIDSetArmMSG(ACK::ErrorCode ack);
436  static void getSetBroadcastMSG(ACK::ErrorCode ack);
437  static void getCMDSetMissionMSG(ACK::ErrorCode ack);
438  static void getCMDSetSyncMSG(ACK::ErrorCode ack);
439  static void getCMDSetVirtualRCMSG(ACK::ErrorCode ack);
440  static void getCMDSetMFIOMSG(ACK::ErrorCode ack);
441 
442  static const std::map<const uint32_t, const char*> createCommonErrorCodeMap();
443  static const std::map<const uint32_t, const char*>
444  createActivateErrorCodeMap();
445  static const std::map<const uint32_t, const char*>
446  createSubscribeErrorCodeMap();
447  static const std::map<const uint32_t, const char*>
448  createSetControlErrorCodeMap();
449  static const std::map<const uint32_t, const char*> createTaskErrorCodeMap();
450  static const std::map<const uint32_t, const char*>
451  createMissionErrorCodeMap();
452  static const std::map<const uint32_t, const char*> createMFIOErrorCodeMap();
453  static const std::map<const uint32_t, const char*> createSetArmErrorCodeMap();
454  static const std::map<const uint32_t, const char*>
455  createLegacyTaskErrorCodeMap();
456 }; // class ACK
457 
458 } // namespace OSDK
459 } // namespace DJI
460 #endif // DJI_ACK_HPP
uint8_t error_notification
Definition: dji_ack.hpp:272
HotPoint Mission Initialization settings.
Definition: dji_mission_type.hpp:52
struct DJI::OSDK::ACK::WayPointAddPoint WayPointAddPoint
This struct is returned from the DJI::OSDK::WaypointMission::uploadIndexData blocking API.
static const int IMG_VGA_SIZE
This constant variable defines number of pixels for VGA images.
Definition: dji_ack.hpp:312
uint8_t waypoint_index
Definition: dji_ack.hpp:258
This struct is returned from all blocking calls, except certain mission calls that have explicit type...
Definition: dji_ack.hpp:146
static const int IMG_240P_SIZE
This constant variable defines number of pixels for QVGA images.
Definition: dji_ack.hpp:279
static void getErrorCodeMessage(ErrorCode ack, const char *func)
Call this function to get a human-readable message that tells you the meaning of the ACK....
Definition: dji_ack.cpp:742
This struct is returned from the DJI::OSDK::Control::writeParameterByHash blocking API.
Definition: dji_ack.hpp:156
This struct is returned from the DJI::OSDK::HotpointMission::readData blocking API.
Definition: dji_ack.hpp:193
This struct is used in the readInitData non-blocking API callback.
Definition: dji_ack.hpp:235
This struct captures PushData when subscribe to QVGA images.
Definition: dji_ack.hpp:292
struct DJI::OSDK::ACK::WayPointInit WayPointInit
This struct is used in the readInitData non-blocking API callback.
struct DJI::OSDK::ACK::MFIOGet MFIOGet
This struct is returned from the DJI::OSDK::MFIO::getValue blocking API.
struct DJI::OSDK::ACK::ErrorCode ErrorCode
This struct is returned from all blocking calls, except certain mission calls that have explicit type...
uint8_t reserved_1
Definition: dji_ack.hpp:260
This struct is returned from the DJI::OSDK::WaypointMission::waypointIndexDownload blocking API.
Definition: dji_ack.hpp:206
This struct is returned from the DJI::OSDK::WaypointMission::updateIdleVelocity blocking API.
Definition: dji_ack.hpp:226
struct DJI::OSDK::ACK::DroneVersion DroneVersion
This struct is returned from the DJI::OSDK::Vehicle::getDroneVersion blocking API.
This struct captures PushData while ground-station is enabled on Assistant's SDK Page,...
Definition: dji_ack.hpp:255
This struct is returned from the DJI::OSDK::HotpointMission::start blocking API.
Definition: dji_ack.hpp:183
This struct captures PushData when subscribe to VGA images.
Definition: dji_ack.hpp:317
Waypoint Mission Initialization settings.
Definition: dji_mission_type.hpp:81
Mission related data struct for DJI OSDK library.
sub-struct for stereo image with raw data and camera name
Definition: dji_ack.hpp:284
struct DJI::OSDK::ACK::WayPointReachedData WayPointReachedData
This struct captures PushData while ground-station is enabled on Assistant's SDK Page,...
struct DJI::OSDK::ACK::ParamAck ParamAck
This struct is returned from the DJI::OSDK::Control::writeParameterByHash blocking API.
All DJI OSDK OpenProtocol Command IDs.
uint8_t current_status
Definition: dji_ack.hpp:271
struct DJI::OSDK::ACK::HotPointRead HotPointRead
This struct is returned from the DJI::OSDK::HotpointMission::readData blocking API.
struct DJI::OSDK::ACK::FCTimeInUTC FCTimeInUTC
This struct captures PushData when subscribe to UTC & FC time in hardware sync.
Waypoint settings for individual waypoints being added to the mission.
Definition: dji_mission_type.hpp:126
struct DJI::OSDK::ACK::StereoVGAImgData StereoVGAImgData
This struct captures PushData when subscribe to VGA images.
struct DJI::OSDK::ACK::WayPointIndex WayPointIndex
This struct is returned from the DJI::OSDK::WaypointMission::waypointIndexDownload blocking API.
static const bool FAIL
ACK::getError return type when blocking call is unsuccessful.
Definition: dji_ack.hpp:394
Data type and Data Structure definitions for use throughout DJI OSDK.
This struct is returned from the DJI::OSDK::MFIO::getValue blocking API.
Definition: dji_ack.hpp:173
This struct is returned from the DJI::OSDK::Vehicle::getDroneVersion blocking API.
Definition: dji_ack.hpp:245
struct DJI::OSDK::ACK::HotPointStart HotPointStart
This struct is returned from the DJI::OSDK::HotpointMission::start blocking API.
Definition: dji_ack.cpp:38
uint8_t waypoint_index
Definition: dji_ack.hpp:270
uint8_t current_status
Definition: dji_ack.hpp:259
Drone/SDK Version definition for DJI onboardSDK library.
This struct is returned from the DJI::OSDK::WaypointMission::uploadIndexData blocking API.
Definition: dji_ack.hpp:216
struct DJI::OSDK::ACK::WayPointStatusPushData WayPointStatusPushData
This struct captures PushData while ground-station is enabled on Assistant's SDK Page,...
Class for handling acknowledgements from the aircraft.
Definition: dji_ack.hpp:50
struct DJI::OSDK::ACK::WayPointVelocity WayPointVelocity
This struct is returned from the DJI::OSDK::WaypointMission::updateIdleVelocity blocking API.
struct DJI::OSDK::ACK::ImageMeta ImageMeta
sub-struct for stereo image with raw data and camera name
struct DJI::OSDK::ACK::StereoImgData StereoImgData
This struct captures PushData when subscribe to QVGA images.
static bool getError(ErrorCode ack)
Call this function with an ACK::ErrorCode returned from a blocking call to find out if the call succe...
Definition: dji_ack.cpp:615
This struct captures PushData while ground-station is enabled on Assistant's SDK Page,...
Definition: dji_ack.hpp:268
const size_t MAX_INCOMING_DATA_SIZE
Definition: dji_type.hpp:93
static const bool SUCCESS
ACK::getError return type when blocking call is successful.
Definition: dji_ack.hpp:392
This struct captures PushData when subscribe to UTC & FC time in hardware sync.
Definition: dji_ack.hpp:330