dji_hardware_sync.hpp
Go to the documentation of this file.
1 
30 #ifndef HARDSYNC_H
31 #define HARDSYNC_H
32 
33 #include "dji_type.hpp"
34 #include "dji_vehicle_callback.hpp"
35 #include <string>
36 
37 #if defined(__linux__)
38 #include <atomic>
39 #endif
40 
41 namespace DJI
42 {
43 namespace OSDK
44 {
45 
46 // Forward Declarations
47 class Vehicle;
48 
58 {
59 
60 public:
61  typedef enum SatelliteIndex {
62  GPS,
63  GLONASS,
64  GALILEO,
65  BEIDOU,
66  MAX_INDEX_CNT,
67  } SatelliteIndex;
68 #pragma pack(1)
69 
70  typedef struct SyncSettings
71  {
72  uint32_t freq;
73  uint16_t tag;
74  } SyncSettings;
75 
76 #pragma pack()
77 
78  typedef enum NMEAType
79  {
80  GNGSA,
81  GNRMC,
82  TYPENUM
83  }NMEAType;
84 
85  typedef enum PPSSource
86  {
87  INTERNAL_GPS,
88  EXTERNAL_GPS,
89  RTK
90  }PPSSource;
91 
92 #if STM32
93  typedef time_ms RecvTimeMsg;
94 #elif defined(__linux__)
95  typedef timespec RecvTimeMsg;
96 #endif
97 
98  typedef struct NMEAData
99  {
100  std::string sentence;
101  uint32_t seq;
102  RecvTimeMsg timestamp; // this is OSDK recv time
103  }NMEAData;
104 
105  typedef struct GNGSAPackage
106  {
107  NMEAData Satellite[MAX_INDEX_CNT];
108  }GNGSAPackage;
109 public:
110  HardwareSync(Vehicle* vehiclePtr = 0);
111 
112  VehicleCallBackHandler ppsNMEAHandler;
113  VehicleCallBackHandler ppsUTCTimeHandler;
114  VehicleCallBackHandler ppsUTCFCTimeHandler;
115  VehicleCallBackHandler ppsSourceHandler;
116 
129  void setSyncFreq(uint32_t freqInHz, uint16_t tag = 0);
136  void startSync(SyncSettings& data);
143  void subscribeNMEAMsgs(VehicleCallBack cb, void *userData);
148  void unsubscribeNMEAMsgs();
155  bool getGNRMCMsg(NMEAData &nmea);
162  bool getGNGSAMsg(GNGSAPackage &GNGSA);
163 
170  void subscribeUTCTime(VehicleCallBack cb, void *userData);
175  void unsubscribeUTCTime();
181  bool getUTCTime(NMEAData &utc);
188  void subscribeFCTimeInUTCRef(VehicleCallBack cb, void *userData);
204  void subscribePPSSource(VehicleCallBack cb, void *userData);
209  void unsubscribePPSSource();
215  bool getPPSSource(PPSSource &source);
222  void writeData(const uint8_t cmdID, const RecvContainer *recvContainer);
223 
224 private:
225  void writeNMEA(const std::string &nmea);
226 
227  Vehicle* vehicle;
228 
229  //pthread_mutex_t mutexHardSync;
230  //pthread_cond_t condVarHardSync;
231 
232  NMEAData GPGSAData;
233  NMEAData GPRMCData;
234  GNGSAPackage GNGSAData;
235  NMEAData GNRMCData;
236 
237  NMEAData UTCData;
238  ACK::FCTimeInUTC fcTimeInUTC;
239  PPSSource ppsSourceType;
240 
241 #if STM32
242  typedef bool HWSyncDataFlag;
243 #elif defined(__linux__)
244  typedef std::atomic_bool HWSyncDataFlag;
245 #endif
246 
252  void setDataFlag(HWSyncDataFlag &flag, bool val);
253 
258  bool getDataFlag(HWSyncDataFlag &flag);
259 
268  void recordRecvTimeMsg(RecvTimeMsg &recvTime);
269 
270  HWSyncDataFlag GPGSAFlag;
271  HWSyncDataFlag GPRMCFlag;
272  HWSyncDataFlag GNGSAFlag;
273  HWSyncDataFlag GNRMCFlag;
274  HWSyncDataFlag UTCFlag;
275  HWSyncDataFlag fcTimeFlag;
276  HWSyncDataFlag ppsSourceFlag;
277 
278  template <class dataType>
279  bool writeDataHelper(HWSyncDataFlag &flag,
280  const dataType &msg,
281  dataType &copyMsg)
282  {
283  if(getDataFlag(flag) == true)
284  {
285  copyMsg = msg;
286  setDataFlag(flag, false);
287  return true;
288  }
289  return false;
290  }
291 
292  static void pollNemaDatacallback(Vehicle *vehicle, RecvContainer recvFrame, UserData userData);
293 
294 };
295 } // OSDK
296 } // DJI
297 
298 #endif // HARDSYNC_H
void * UserData
This is used as the datatype for all data arguments in callbacks.
Definition: dji_type.hpp:75
void subscribeNMEAMsgs(VehicleCallBack cb, void *userData)
Subscribe to NMEA messages with a callback function.
Definition: dji_hardware_sync.cpp:66
bool getGNRMCMsg(NMEAData &nmea)
Poll NMEA messages.
Definition: dji_hardware_sync.cpp:291
APIs for controlling Hardware Sync.
Definition: dji_hardware_sync.hpp:57
void unsubscribeFCTimeInUTCRef()
Unsubscribe to FC Time in UTC referece.
Definition: dji_hardware_sync.cpp:153
Type definition for new Vehicle-style callbacks.
void(* VehicleCallBack)(Vehicle *vehicle, RecvContainer recvFrame, UserData userData)
Function prototype for all callback functions used in the OSDK.
Definition: dji_vehicle_callback.hpp:76
void unsubscribeUTCTime()
Unsubscribe to UTC time tag.
Definition: dji_hardware_sync.cpp:128
bool getPPSSource(PPSSource &source)
Poll PPS source info.
Definition: dji_hardware_sync.cpp:285
Received info.
Definition: dji_vehicle_callback.hpp:59
void subscribeUTCTime(VehicleCallBack cb, void *userData)
Subscribe to UTC Time tag with a callback function.
Definition: dji_hardware_sync.cpp:114
The CallBackHandler struct allows users to encapsulate callbacks and data in one struct.
Definition: dji_vehicle_callback.hpp:83
void setSyncFreq(uint32_t freqInHz, uint16_t tag=0)
Call this API to start sending a hardware pulse and set up a software packet to accompany it.
Definition: dji_hardware_sync.cpp:50
bool getFCTimeInUTCRef(DJI::OSDK::ACK::FCTimeInUTC &fcTimeInUTC)
Poll FC Time in UTC referece.
Definition: dji_hardware_sync.cpp:279
bool getGNGSAMsg(GNGSAPackage &GNGSA)
Poll NMEA messages.
Definition: dji_hardware_sync.cpp:297
void writeData(const uint8_t cmdID, const RecvContainer *recvContainer)
Write data when received from UART.
Definition: dji_hardware_sync.cpp:244
Data type and Data Structure definitions for use throughout DJI OSDK.
void subscribePPSSource(VehicleCallBack cb, void *userData)
Subscribe to PPS source info with a callback function.
Definition: dji_hardware_sync.cpp:164
void startSync(SyncSettings &data)
Internal setter function that is called by setSyncFreq function.
Definition: dji_hardware_sync.cpp:59
void unsubscribePPSSource()
Unsubscribe to PPS source info.
Definition: dji_hardware_sync.cpp:178
Definition: dji_ack.cpp:38
void unsubscribeNMEAMsgs()
Unsubscribe to NMEA messages.
Definition: dji_hardware_sync.cpp:91
void subscribeFCTimeInUTCRef(VehicleCallBack cb, void *userData)
Subscribe to FC Time in UTC referece with a callback function.
Definition: dji_hardware_sync.cpp:139
This struct captures PushData when subscribe to UTC & FC time in hardware sync.
Definition: dji_ack.hpp:330
bool getUTCTime(NMEAData &utc)
Poll UTC time tag.
Definition: dji_hardware_sync.cpp:273