dji_legacy_linker.hpp
Go to the documentation of this file.
1 
30 #ifndef LEGACY_LINKER_H_
31 #define LEGACY_LINKER_H_
32 
33 #include "dji_vehicle_callback.hpp"
34 
39 #ifdef __linux__
40 #include <cstring>
41 #elif STM32
42 #include <stdlib.h>
44 #include <string.h>
45 #endif
46 
47 namespace DJI
48 {
49 namespace OSDK
50 {
51 // Forward Declaration
52 class Vehicle;
53 
54 /****************************Globals**************************************/
55 
56 #define MSG_ENABLE_FLAG_LEN 2
57 
58 //----------------------------------------------------------------------
59 // App layer function
60 //----------------------------------------------------------------------
61 
62 typedef struct
63 {
64  uint16_t sequence_number;
65  uint8_t session_id : 5;
66  uint8_t need_encrypt : 1;
67  uint8_t reserve : 2;
68 } req_id_t;
69 
70 #define SET_CMD_SIZE (2u)
71 
72 //----------------------------------------------------------------------
73 // Session Management
74 //----------------------------------------------------------------------
75 
76 #define ACK_SESSION_IDLE 0
77 #define ACK_SESSION_PROCESS 1
78 #define ACK_SESSION_USING 2
79 #define CMD_SESSION_0 0
80 #define CMD_SESSION_1 1
81 #define CMD_SESSION_AUTO 32
82 
83 #define POLL_TICK 20 // unit is ms
84 
85 //----------------------------------------------------------------------
86 // Codec Management
87 //----------------------------------------------------------------------
88 
89 // @todo replace this
90 #define _SDK_U32_SET(_addr, _val) (*((uint32_t*)(_addr)) = (_val))
91 #define _SDK_U16_SET(_addr, _val) (*((uint16_t*)(_addr)) = (_val))
92 
93 class OpenProtocol {
94 
95  public:
96 
97  /********************* Useful protocol related constants ******************/
98  static const int ACK_SIZE = 10;
99  static const uint8_t SOF = 0xAA;
100  static const int CRCHead = sizeof(uint16_t);
101  static const int CRCData = sizeof(uint32_t);
102  static const int CRCHeadLen = sizeof(OpenHeader) - CRCHead;
103  static const int PackageMin = sizeof(OpenHeader) + CRCData;
104 };
105 
106 class LegacyLinker
107 {
108 public:
110  LegacyLinker(Vehicle* vehicle);
111 
113  ~LegacyLinker();
114 
115  /************************** Init ******************************************/
116 public:
117  void init();
118 
119  /*******************************Send Pipeline*****************************/
120 public:
121  void send(const uint8_t cmd[], void *pdata, size_t len);
122 
123  void sendAsync(const uint8_t cmd[], void *pdata, size_t len, int timeout,
124  int retry_time, VehicleCallBack callback, UserData userData);
125 
126  void* sendSync(const uint8_t cmd[], void *pdata, size_t len,
127  int timeout, int retry_time);
128 
129  bool registerCMDCallback(uint8_t cmdSet, uint8_t cmdID,
130  VehicleCallBack &callback, UserData &userData);
131 
132  private:
133  Vehicle* vehicle;
134 
135  void initX5SEnableThread();
136  void *decodeAck(E_OsdkStat ret, uint8_t cmdSet, uint8_t cmdId,
137  RecvContainer recvFrame);
138  private:
139  uint8_t rawVersionACK[MAX_ACK_SIZE];
140 
141  // User space ACK types
142  ACK::ErrorCode ackErrorCode;
143  ACK::DroneVersion droneVersionACK;
144  ACK::HotPointStart hotpointStartACK;
145  ACK::HotPointRead hotpointReadACK;
148  ACK::WayPointInit waypointInitACK;
151  ACK::WayPointIndex waypointIndexACK;
152  ACK::WayPoint2CommonRsp wayPoint2CommonRspACK;
154  ACK::WayPointAddPoint waypointAddPointACK;
155  ACK::MFIOGet mfioGetACK;
156  ACK::ExtendedFunctionRsp extendedFunctionRspAck;
157  ACK::ParamAck paramAck;
158  ACK::SetHomeLocationAck setHomeLocationAck;
160  ACK::HeartBeatAck heartBeatAck;
161 
162  T_OsdkTaskHandle legacyX5SEnableHandle;
163  static void *legacyX5SEnableTask(void *arg);
164 }; // class LegacyLinker
165 
166 } // namespace OSDK
167 } // namespace DJI
168 
169 #endif // LEGACY_LINKER_H_
struct DJI::OSDK::ACK::WayPointAddPoint WayPointAddPoint
This struct is returned from the DJI::OSDK::WaypointMission::uploadIndexData blocking API.
void * UserData
This is used as the datatype for all data arguments in callbacks.
Definition: dji_type.hpp:75
struct DJI::OSDK::RecvContainer RecvContainer
Received info.
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
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...
struct DJI::OSDK::ACK::DroneVersion DroneVersion
This struct is returned from the DJI::OSDK::Vehicle::getDroneVersion blocking API.
struct DJI::OSDK::ACK::ParamAck ParamAck
This struct is returned from the DJI::OSDK::Control::writeParameterByHash blocking API.
struct DJI::OSDK::ACK::HotPointRead HotPointRead
This struct is returned from the DJI::OSDK::HotpointMission::readData blocking API.
struct DJI::OSDK::ACK::WayPointIndex WayPointIndex
This struct is returned from the DJI::OSDK::WaypointMission::waypointIndexDownload blocking API.
struct DJI::OSDK::ACK::HotPointStart HotPointStart
This struct is returned from the DJI::OSDK::HotpointMission::start blocking API.
Definition: dji_ack.cpp:38
struct DJI::OSDK::OpenHeader OpenHeader
The Header struct is meant to handle the open protocol header.