dji_broadcast.hpp
Go to the documentation of this file.
1 
30 #ifndef DJIBROADCAST_H
31 #define DJIBROADCAST_H
32 
33 #include "dji_telemetry.hpp"
34 #include "dji_vehicle_callback.hpp"
35 
36 namespace DJI
37 {
38 namespace OSDK
39 {
40 
53 {
54 public:
55  /*
56  * Frequency values
57  */
58  enum FREQ
59  {
60  FREQ_0HZ = 0,
61  FREQ_1HZ = 1,
62  FREQ_10HZ = 2,
63  FREQ_50HZ = 3,
64  FREQ_100HZ = 4,
65  FREQ_200HZ = 6,
66  FREQ_400HZ = 7,
67  FREQ_HOLD = 5,
68  };
69 
70  /*
71  * @note this enable flag helps you clarify what data
72  * is coming in from data broadcast
73  * If the user specify GPS @50Hz and gyro @10Hz
74  * The whole data packet from broadcast will come
75  * in @50 Hz but gyro will only come in every 5
76  * data packets.
77  * Use this enum with the passFlag then you can
78  * check what data is available
79  * EX:
80  * if (passFlag & DataBroadcast::DATA_ENABLE_FLAG::HAS_W){
81  * // you get gyro data
82  * }
83  */
84  enum DATA_ENABLE_FLAG
85  {
86  HAS_TIME = 0x0001,
87  HAS_Q = 0x0002,
88  HAS_A = 0x0004,
89  HAS_V = 0x0008,
90  HAS_W = 0x0010,
91  HAS_POS = 0x0020,
92  // below flags are for M100
93  HAS_MAG = 0x0040,
94  HAS_RC = 0x0080,
95  HAS_GIMBAL = 0x0100,
96  HAS_STATUS = 0x0200,
97  HAS_BATTERY = 0x0400,
98  HAS_DEVICE = 0x0800,
99  // below flags are for A3
100  A3_HAS_GPS = 0x0040,
101  A3_HAS_RTK = 0x0080,
102  A3_HAS_MAG = 0x0100,
103  A3_HAS_RC = 0x0200,
104  A3_HAS_GIMBAL = 0x0400,
105  A3_HAS_STATUS = 0x0800,
106  A3_HAS_BATTERY = 0x1000,
107  A3_HAS_DEVICE = 0x2000,
108  A3_HAS_COMPASS = 0x4000,
109  };
110 
111 public:
112  DataBroadcast(Vehicle* vehicle = 0);
113  ~DataBroadcast();
114 
115 public:
116  // Non-Blocking local-cache API
117  // clang-format off
118 
126 
135 
149 
159 
174 
184 
193 
210 
219 
229 
261 
271 
278  Telemetry::RC getRC() ;
279 
289 
298 
307 
316 
325  // clang-format on
326 
327 public:
337  void setBroadcastFreq(uint8_t* dataLenIs16, VehicleCallBack callback = 0,
338  UserData userData = 0);
347  ACK::ErrorCode setBroadcastFreq(uint8_t* dataLenIs16, int wait_timeout);
348 
354 
362 
367  void setBroadcastFreqToZero();
368 
374  uint16_t getPassFlag();
375 
376 public:
377  Vehicle* getVehicle() const;
378  void setVehicle(Vehicle* vehiclePtr);
379  /*
380  * @note Distinguish between different FW versions
381  */
382  void setVersionDefaults(uint8_t* frequencyBuffer);
383  void setFreqDefaultsM100_31(uint8_t* frequencyBuffer);
384  void setFreqDefaults(uint8_t* frequencyBuffer);
385 
386 public:
387  void setUserBroadcastCallback(VehicleCallBack callback, UserData userData);
388  VehicleCallBackHandler unpackHandler;
389 
390 public:
391  static void unpackCallback(Vehicle* vehicle, RecvContainer recvFrame,
392  UserData userData);
393  static void setFrequencyCallback(Vehicle* vehicle, RecvContainer recvFrame,
394  UserData userData);
395 
396 private:
397  // clang-format off
398  typedef enum FLAG {
399  // Common to A3/N3 and M100
400  FLAG_TIME = 0X0001,
401  FLAG_QUATERNION = 0X0002,
402  FLAG_ACCELERATION = 0X0004,
403  FLAG_VELOCITY = 0X0008,
404  FLAG_ANGULAR_RATE = 0X0010,
405  FLAG_POSITION = 0X0020,
406 
407  // Following are A3/N3 specific
408  FLAG_GPSINFO = 0X0040,
409  FLAG_RTKINFO = 0X0080,
410  FLAG_MAG = 0X0100,
411  FLAG_RC = 0X0200,
412  FLAG_GIMBAL = 0X0400,
413  FLAG_STATUS = 0X0800,
414  FLAG_BATTERY = 0X1000,
415  FLAG_DEVICE = 0X2000,
416  FLAG_COMPASS = 0x4000,
417 
418  // Following are M100 specific
419  FLAG_M100_MAG = 0x0040,
420  FLAG_M100_RC = 0x0080,
421  FLAG_M100_GIMBAL = 0x0100,
422  FLAG_M100_STATUS = 0x0200,
423  FLAG_M100_BATTERY = 0x0400,
424  FLAG_M100_DEVICE = 0x0800
425  } FLAG;
426  // clang-format on
427 
428 private:
433  void unpackData(RecvContainer* recvFrame);
434 
439  void unpackM100Data(RecvContainer* pRecvFrame);
440 
445  void unpackOldM600Data(RecvContainer* recvFrame);
446 
447  inline void unpackOne(FLAG flag, void* data, uint8_t*& buf, size_t size);
448 
449 public:
450  void setBroadcastLength(uint16_t length);
451  uint16_t getBroadcastLength();
452 
453 private:
454  // clang-format off
455  Telemetry::TimeStamp timeStamp ;
456  Telemetry::SyncStamp syncStamp ;
464  Telemetry::GPSInfo gps ;
465  Telemetry::RTK rtk ;
466  Telemetry::Mag mag ;
467  Telemetry::RC rc ;
468  Telemetry::Gimbal gimbal ;
469  Telemetry::Status status ;
470  Telemetry::Battery battery ;
471  Telemetry::SDKInfo info ;
472  Telemetry::Compass compass ;
473  /*
474  * @note Broadcast data for Matrice 100/600 older firmware that is fundamentally
475  * different from the A3/N3/M600 newer firmware
476  */
477  Telemetry::LegacyTimeStamp legacyTimeStamp;
478  Telemetry::LegacyVelocity legacyVelocity;
479  Telemetry::LegacyStatus legacyStatus;
480  Telemetry::LegacyBattery legacyBattery;
481  Telemetry::LegacyGPSInfo legacyGPSInfo;
482  // clang-format on
483 private:
484  Vehicle* vehicle;
485  uint16_t passFlag;
486  uint16_t broadcastLength;
487 
488  T_OsdkMutexHandle m_msgLock;
489  void lockMSG();
490  void freeMSG();
491 
492  VehicleCallBackHandler userCbHandler;
493 };
494 
495 } // OSDK
496 } // DJI
497 #endif // DJIBROADCAST_H
void * UserData
This is used as the datatype for all data arguments in callbacks.
Definition: dji_type.hpp:75
void setBroadcastFreqDefaults()
Definition: dji_broadcast.cpp:529
void setBroadcastFreqToZero()
Definition: dji_broadcast.cpp:613
struct for data broadcast and subscription, return obstacle info around the vehicle
Definition: dji_telemetry.hpp:300
void setBroadcastFreq(uint8_t *dataLenIs16, VehicleCallBack callback=0, UserData userData=0)
Definition: dji_broadcast.cpp:382
Telemetry::TimeStamp getTimeStamp()
Definition: dji_broadcast.cpp:86
struct indicates the signal level of GPS velocity info
Definition: dji_telemetry.hpp:245
struct for TOPIC_QUATERNION
Definition: dji_telemetry.hpp:188
Telemetry::SDKInfo getSDKInfo()
Definition: dji_broadcast.cpp:349
This struct is returned from all blocking calls, except certain mission calls that have explicit type...
Definition: dji_ack.hpp:146
Telemetry::Vector3f getAngularRate()
Definition: dji_broadcast.cpp:207
Telemetry::Vector3f getVelocity()
Definition: dji_broadcast.cpp:154
Type definition for new Vehicle-style callbacks.
Telemetry::RTK getRTKInfo()
Definition: dji_broadcast.cpp:263
struct for data broadcast, return RTK info
Definition: dji_telemetry.hpp:404
struct for data broadcast, return compass reading
Definition: dji_telemetry.hpp:455
Telemetry::Quaternion getQuaternion()
Definition: dji_broadcast.cpp:134
void(* VehicleCallBack)(Vehicle *vehicle, RecvContainer recvFrame, UserData userData)
Function prototype for all callback functions used in the OSDK.
Definition: dji_vehicle_callback.hpp:76
Telemetry::SyncStamp getSyncStamp()
Definition: dji_broadcast.cpp:111
struct for data broadcast, return gimbal angle
Definition: dji_telemetry.hpp:503
struct for data broadcast, timestamp from local cache
Definition: dji_telemetry.hpp:223
struct for data broadcast, software sync timestamp from local cache
Definition: dji_telemetry.hpp:234
struct for TOPIC_BATTERY_INFO and data broadcast, return battery status
Definition: dji_telemetry.hpp:530
struct for GPSInfo of data broadcast
Definition: dji_telemetry.hpp:802
Received info.
Definition: dji_vehicle_callback.hpp:59
Telemetry::Battery getBatteryInfo()
Definition: dji_broadcast.cpp:326
struct for multiple Topics
Definition: dji_telemetry.hpp:199
The CallBackHandler struct allows users to encapsulate callbacks and data in one struct.
Definition: dji_vehicle_callback.hpp:83
struct for data broadcast, return GPS data
Definition: dji_telemetry.hpp:272
Telemetry::GPSInfo getGPSInfo()
Definition: dji_broadcast.cpp:239
Telemetry::Compass getCompassData()
Definition: dji_broadcast.cpp:359
struct for TOPIC_CONTROL_DEVICE and data broadcast, return SDK info
Definition: dji_telemetry.hpp:541
struct for data broadcast, return flight status
Definition: dji_telemetry.hpp:518
uint16_t getPassFlag()
Definition: dji_broadcast.cpp:665
Telemetry API through asynchronous "Broadcast"-style messages.
Definition: dji_broadcast.hpp:52
uint8_t LegacyStatus
Return type for flight status data broadcast (only for M100). Returns VehicleStatus::M100FlightStatus...
Definition: dji_telemetry.hpp:791
Telemetry::Vector3f getAcceleration()
Definition: dji_broadcast.cpp:144
Telemetry::Mag getMag()
Definition: dji_broadcast.cpp:273
uint8_t LegacyBattery
Return type for battery data broadcast (only for M100). Returns percentage.
Definition: dji_telemetry.hpp:795
Matrice 100 Timestamp data, available in Broadcast telemetry (only for M100)
Definition: dji_telemetry.hpp:759
Telemetry::Gimbal getGimbal()
Definition: dji_broadcast.cpp:293
Enumeration of all telemetry data types, structures and maps.
struct for GPSInfo of data broadcast
Definition: dji_telemetry.hpp:380
Telemetry::RelativePosition getRelativePosition()
Definition: dji_broadcast.cpp:228
Telemetry::GlobalPosition getGlobalPosition()
Definition: dji_broadcast.cpp:217
Definition: dji_ack.cpp:38
struct for data broadcast, return magnetometer reading
Definition: dji_telemetry.hpp:439
Telemetry::VelocityInfo getVelocityInfo()
Definition: dji_broadcast.cpp:181
Telemetry::RC getRC()
Definition: dji_broadcast.cpp:283
struct for data broadcast and data subscription, return RC reading
Definition: dji_telemetry.hpp:463
Telemetry::Status getStatus()
Definition: dji_broadcast.cpp:303
Matrice 100 Velocity struct, returned in Broadcast telemetry (only for M100)
Definition: dji_telemetry.hpp:772