DJI Onboard SDK  4.0
dji_protocol_base.hpp
Go to the documentation of this file.
1 
30 #ifndef ONBOARDSDK_INTERNAL_DJI_PROTOCOL_BASE_H
31 #define ONBOARDSDK_INTERNAL_DJI_PROTOCOL_BASE_H
32 
33 #include "dji_ack.hpp"
34 #include "dji_aes.hpp"
35 #include "dji_hard_driver.hpp"
36 #include "dji_log.hpp"
37 #include "dji_thread_manager.hpp"
38 #include "dji_type.hpp"
39 
40 #ifdef STM32
41 #include <string.h>
42 #else
43 #include <cstring>
44 #endif
45 
46 namespace DJI
47 {
48 namespace OSDK
49 {
50 
51 #ifndef DJI_VEHICLECALLBACK_H
52 
57 typedef struct DispatchInfo
58 {
59  bool isAck;
60  bool isCallback;
61  uint8_t callbackID;
62 } DispatchInfo;
63 
68 typedef struct RecvContainer
69 {
70  DJI::OSDK::ACK::Entry recvInfo;
71  DJI::OSDK::ACK::TypeUnion recvData;
72  DJI::OSDK::DispatchInfo dispatchInfo;
74 #endif
75 
76 class ProtocolBase
77 {
78 public:
79  ProtocolBase();
80  virtual ~ProtocolBase();
81 
82  /************************** Init ******************************************/
83 public:
84  virtual void init(HardDriver* Driver, MMU* mmuPtr,
85  bool userCallbackThread = false) = 0;
86 
87  /************************** Send Pipeline *********************************/
88  // @todo is there any benefit to have an unified send function?
89  // public:
90  // //! highest level interface
91  // virtual void send(cmdContainer *cmd_container);
92 
93 protected:
95  virtual int sendInterface(void* cmdContainer) = 0;
96 
98  virtual int sendData(uint8_t* buf) = 0;
99 
100  /************************** Receive Pipeline ******************************/
101 public:
104  virtual RecvContainer* receive();
105 
106 protected:
107  typedef struct SDKFilter
108  {
109  uint32_t reuseIndex;
110  uint32_t reuseCount;
111  uint32_t recvIndex;
112  uint8_t* recvBuf;
113  uint8_t sdkKey[32]; // for encryption
114  uint8_t encode;
115  } SDKFilter;
116 
119  virtual bool readPoll();
120 
122 public:
123  virtual bool byteHandler(const uint8_t in_data);
124 
125 protected:
128  virtual bool streamHandler(uint8_t in_data);
129 
132  virtual void storeData(uint8_t in_data);
133 
136  virtual bool checkStream() = 0;
137 
140  virtual bool verifyHead() = 0;
141 
144  virtual bool verifyData() = 0;
145 
148  virtual bool callApp() = 0;
149 
152  virtual bool appHandler(void* protocolHeader) = 0;
153 
155  void prepareDataStream();
156 
158  void shiftDataStream();
159 
161  void reuseDataStream();
162 
163  /********************************** CRC **********************************/
164 protected:
165  virtual int crcHeadCheck(uint8_t* pMsg, size_t nLen) = 0;
166 
167  virtual int crcTailCheck(uint8_t* pMsg, size_t nLen) = 0;
168 
169  /*********************** Getters and setters ******************************/
170 public:
172  HardDriver* getDriver() const;
173 
175  ThreadAbstract* getThreadHandle() const;
176 
177  void setDriver(HardDriver* hardDriver_ptr);
178 
179  void setThreadHandle(ThreadAbstract* threadAbstract_ptr);
180 
182  void setHeaderLength(uint8_t length);
183 
185  void setMaxRecvLength(int length);
186 
187  int getBufReadPos();
188 
189  int getReadLen();
190 
191  RecvContainer* getReceivedFrame();
192 
193  /******************************* Member variables ************************/
194 protected:
196  HardDriver* deviceDriver;
197 
199  bool stopCond;
200  ThreadAbstract* threadHandle;
201 
203  uint16_t seq_num;
204 
206  int buf_read_pos;
207  int read_len;
208  int BUFFER_SIZE; // this should not be changed, init this in constructor
209  uint8_t* buf;
210  uint8_t HEADER_LEN;
211  int MAX_RECV_LEN;
212  RecvContainer* p_recvContainer;
213  SDKFilter* p_filter;
214 
216  bool reuse_buffer;
217 
219  bool is_large_data_protocol;
220 
221 }; // class ProtocolBase
222 
223 } // OSDK
224 
225 } // DJI
226 
227 #endif // ONBOARDSDK_INTERNAL_DJI_PROTOCOL_BASE_H
Serial device driver abstraction. Provided as an abstract class. Please inherit and implement for ind...
struct DJI::OSDK::RecvContainer RecvContainer
Received info.
Data protection and thread management abstract classes.
Dispatch info.
Definition: dji_vehicle_callback.hpp:48
Data type and Data Structure definitions for use throughout DJI OSDK.
Logging mechanism for printing status and error messages to the screen.
handle array of characters
Definition: commondatarangehandler.h:14
struct DJI::OSDK::DispatchInfo DispatchInfo
Dispatch info.
All DJI OSDK ACK parsing.