DJI OnboardSDK学习笔记
DJI OnboardSDK学习笔记
风见尘 发表于12个月前
DJI OnboardSDK学习笔记
  • 发表于 12个月前
  • 阅读 227
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

摘要: 毕业设计选的题目是大疆的飞行器三维轨迹规划平台的设计与实现,用的硬件是M100,manifold,开发用的计算机的系统是ubuntu kylin 16.04下的Qt5.7.0,软件用的是大疆M100无人机配套的一系列软件如DJI GO(APP),DJI Assistant2等,源码用OnboardSDK3.1.9,ROS(Onoard-SDK-ROS),编程语言是C++,算法参考大疆给的三篇论文,如果后面有需要再另外附链接.我之前关于这方面的什么都没了解过,既没有C++基础,也没有空气动力学基础,更没有做过无人机相关的开发或比赛。前面有过几天的环境搭建与了解之后,现在开始学习与记录。

本文学习OnboardSDK的CoreAPI类。这个类的声明和简单的定义位于/osdk-core/inc/DJI_API.h文件中,此文件还定义了一下几个类(后面的并没有实现,但会在相应的文件里实现,后面会学习到):

class CoreAPI;
class Flight;
class Camera;
class VirtualRC;
class HotPoint;

该文件还定义了后面会用到的一些枚举类型,如下:

enum ACK_ERROR_CODE
{
  ACK_SUCCESS = 0x0000,
  ACK_PARAM_ERROR = 0x0001
};

enum ACK_COMMON_CODE
{
  ACK_COMMON_SUCCESS = 0x0000,
  ACK_COMMON_KEYERROR = 0xFF00,
  ACK_COMMON_NO_AUTHORIZATION = 0xFF01,
  ACK_COMMON_NO_RIGHTS = 0xFF02,
  ACK_COMMON_NO_RESPONSE = 0xFFFF
};

enum ACK_ACTIVE_CODE
{
  ACK_ACTIVE_SUCCESS = 0x0000,
  ACK_ACTIVE_PARAMETER_ERROR = 0x0001,
  ACK_ACTIVE_ENCODE_ERROR = 0x0002,
  ACK_ACTIVE_NEW_DEVICE = 0x0003,
  ACK_ACTIVE_APP_NOT_CONNECTED = 0x0004,
  ACK_ACTIVE_NO_INTERNET = 0x0005,
  ACK_ACTIVE_SERVER_REFUSED = 0x0006,
  ACK_ACTIVE_ACCESS_LEVEL_ERROR = 0x0007,
  ACK_ACTIVE_VERSION_ERROR = 0x0008
};

enum ACK_SETCONTROL_CODE
{
  ACK_SETCONTROL_ERROR_MODE = 0x0000,
  ACK_SETCONTROL_RELEASE_SUCCESS = 0x0001,
  ACK_SETCONTROL_OBTAIN_SUCCESS = 0x0002,
  ACK_SETCONTROL_OBTAIN_RUNNING = 0x0003,
  ACK_SETCONTROL_RELEASE_RUNNING = 0x0004,
  ACK_SETCONTROL_NEED_MODE_F = 0x0006,
  ACK_SETCONTROL_NEED_MODE_P = 0x0005,
  ACK_SETCONTROL_IOC = 0x00C9,

};

enum ACK_ARM_CODE
{
  ACK_ARM_SUCCESS = 0x0000,
  ACK_ARM_NEED_CONTROL = 0x0001,
  ACK_ARM_ALREADY_ARMED = 0x0002,
  ACK_ARM_IN_AIR = 0x0003,
};

enum TASK_ACK_CODE
{ 
  TASK_FAILURE = 0x01,
  TASK_SUCCESS = 0x02
};


//! @note end of ACKs

enum CMD_SET
{
  SET_ACTIVATION = 0x00,
  SET_CONTROL = 0x01,
  SET_BROADCAST = 0x02,
  SET_MISSION = 0x03,
  SET_SYNC = 0x04,
  SET_VIRTUALRC = 0x05
};

enum SYNC_CODE
{
  CODE_SYNC_BROADCAST = 0x00
};

enum HOTPOINT_CODE
{
  CODE_HOTPOINT_START = 0x20,
  CODE_HOTPOINT_STOP = 0x21,
  CODE_HOTPOINT_SETPAUSE = 0x22,
  CODE_HOTPOINT_YAWRATE = 0x23,
  CODE_HOTPOINT_RADIUS = 0x24,
  CODE_HOTPOINT_SETYAW = 0x25,
  CODE_HOTPOINT_LOAD = 0x26
};

enum FOLLOW_CODE
{
  CODE_FOLLOW_START = 0x30,
  CODE_FOLLOW_STOP = 0x31,
  CODE_FOLLOW_SETPAUSE = 0X32,
  CODE_FOLLOW_TARGET = 0X33
};

enum WAYPOINT_CODE
{
  CODE_WAYPOINT_INIT = 0x10,
  CODE_WAYPOINT_ADDPOINT = 0x11,
  CODE_WAYPOINT_SETSTART = 0x12,
  CODE_WAYPOINT_SETPAUSE = 0x13,
  CODE_WAYPOINT_DOWNLOAD = 0x14,
  CODE_WAYPOINT_INDEX = 0x15,
  CODE_WAYPOINT_SETVELOCITY = 0x16,
  CODE_WAYPOINT_GETVELOCITY = 0x17,
};

enum ACTIVATION_CODE
{
  CODE_GETVERSION = 0,
  CODE_ACTIVATE = 1,
  CODE_FREQUENCY = 0x10,
  CODE_TOMOBILE = 0xFE
};

enum CONTROL_CODE
{
  CODE_SETCONTROL = 0,
  CODE_TASK = 1,
  CODE_STATUS = 2,
  CODE_CONTROL = 3,
  CODE_SETARM = 5,
};

enum BROADCAST_CODE
{
  CODE_BROADCAST = 0x00,
  CODE_LOSTCTRL = 0x01,
  CODE_FROMMOBILE = 0x02,
  CODE_MISSION = 0x03,
  CODE_WAYPOINT = 0x04
};

enum VIRTUALRC_CODE
{
  CODE_VIRTUALRC_SETTINGS,
  CODE_VIRTUALRC_DATA
};

enum MISSION_TYPE
{
  MISSION_MODE_A,
  MISSION_WAYPOINT,
  MISSION_HOTPOINT,
  MISSION_FOLLOW,
  MISSION_IOC
};

enum BROADCAST_FREQ
{
  BROADCAST_FREQ_0HZ = 0,
  BROADCAST_FREQ_1HZ = 1,
  BROADCAST_FREQ_10HZ = 2,
  BROADCAST_FREQ_50HZ = 3,
  BROADCAST_FREQ_100HZ = 4,
  BROADCAST_FREQ_HOLD = 5,
};

接下来是实现CoreAPI.

API运行与两个轮询线程sendPoll(void) & readPoll(void)

后面的介绍中只列举类的方法和域以及说明他们的作用(返回类型),使用(如何调用,函数参数说明),有些函数已经用简单一看就知道的英文注释便了不再解释。

class CoreAPI
{
  public:
  /*CoreAPI的构造函数,有默认值的情况下给多个参数赋默认值,在调用时可以传入自己的值,置空时会使用默认值*/
  CoreAPI(HardDriver *Driver = 0, Version SDKVersion = 0, bool userCallbackThread = false,
        CallBack userRecvCallback = 0, UserData userData = 0);

  /**CoreAPI的构造函数的重载,此时在创建对象时需要给定初始化需要的参数,HardDriver *Driver 以指针形式传入硬件驱动
   *Version SDKVersion传入SDK版本号,CallBackHandler userRecvCallback传入回调函数,
   *bool userCallbackThread = false则传入用户回调线程标识,默认为false
   **/
  CoreAPI(HardDriver *Driver, Version SDKVersion, CallBackHandler userRecvCallback,
        bool userCallbackThread = false);

  /*API 必须运行在两个轮询线程中,分别为sendPoll和readPoll*/
  void sendPoll(void);
  void readPoll(void);
  //! @todo Implement callback poll handler,需要传入一个CoreAPI对象
  void callbackPoll(CoreAPI *api);

  //! @todo Pipeline refactoring,需要传入一个常数数据,同时提供uint8_t类型检查
  void byteHandler(const uint8_t in_data);
  //! @todo Implement stream handler
  void byteStreamHandler(uint8_t *buffer, size_t size);
  //ACK函数,需要传入id,以指针形式传入ack数据,以及ack数据长度
  void ack(req_id_t req_id, unsigned char *ackdata, int len);

  //! Notify caller ACK frame arrived,通知ACK到达,三个函数都需要传入协议头部
  void allocateACK(Header *protocolHeader);
  void notifyCaller(Header *protocolHeader);
  void notifyNonBlockingCaller(Header *protocolHeader);

  //@{
  /**
   * @remark
   * void send() - core overloaded function which can be invoked in three different ways.\n\n
   * void send(CallbackCommand *parameter) - main interface\n
   * (other two overloaded functions are builded on the base of this function)\n\n
   * Please be careful when passing in UserData, there might have memory leak problems.
   *
   */
  /**send()里的参数由openprotocol可以知道,send函数将会发送session_mode,is_enc,CMD_SET,cmd_id
   *protocol,len,callback,timeout,retry等数据,以send(Command *parameter)为最基本形式,
   *其他两种为函数的重载*/
  void send(unsigned char session_mode, unsigned char is_enc, CMD_SET cmd_set,
      unsigned char cmd_id, void *pdata, int len, CallBack ack_callback,
      /**@note Compatible for DJI_APP_Pro_send*/
      int timeout = 0, int retry_time = 1);
  void send(unsigned char session_mode, bool is_enc, CMD_SET cmd_set, unsigned char cmd_id,
      void *pdata, size_t len, int timeout = 0, int retry_time = 1,
      CallBack ack_handler = 0,
      /**@note Better interface entrance*/
      UserData userData = 0);

  /**@note Main interface*/
  void send(Command *parameter);
  //@}

  /// Activation Control  激活控制
  /**
   *
   * @brief
   * Send activation request to your flight controller
   * to check if: \n a) your application registered in your developer
   * account \n b) API Control enabled in the Assistant software\n\n
   * Proceed to programming if activation successful.
   */
  /**需要传入ActivateData激活数据(app_id,app_key,serialport,buadrate等)
  void activate(ActivateData *data, CallBack callback = 0, UserData userData = 0);

  /// Blocking API Control  组织控制
  /**
  * @remark
  * Blocks until ACK frame arrives or timeout occurs
  *
  * @brief
  * Send activation control to your flight controller to check if: \n a)
  * your application registered in your developer
  * account \n b) API Control enabled in the Assistant software\n\n
  * Proceed to programming if activation successful.
  *
  * @return ACK from flight controller
  *
  * @todo
  * Implement high resolution timer to catch ACK timeout
  */
  unsigned short activate(ActivateData *data, int timeout);

  void setControl(bool enable, CallBack callback = 0, UserData userData = 0);

  /// Blocking API Control
  /**
  * @remark
  * Blocks until ACK frame arrives or timeout occurs
  *
  * @brief
  * Obtain control
  *
  * @return ACK from flight controller
  *
  * @todo
  * Implement high resolution timer to catch ACK timeout
  */
  unsigned short setControl(bool enable, int timeout);

  /// Activation Control
  /**
   * @brief
   * Is your aircraft already activated ?
   */
  //设置是否被激活
  void setActivation(bool isActivated);

  /// Activation Control
  /**
   * Get Activation information
   */
  //获取激活数据,使用const修饰说明该函数为常函数,既不改变对象的成员变量不能调用任类中的任何非const函数
  ActivateData getAccountData() const;

  /// Activation Control
  //设置ACCOUNT数据
  void setAccountData(const ActivateData &value);
  //将数据发送给mobile
  void sendToMobile(uint8_t *data, uint8_t len, CallBack callback = 0, UserData userData = 0);

  /**
   * @drief
   * Set broadcast frequency.设置广播频率,以下是提供的12个广播频道0-11
   *
   * @remark
   * We offer 12 frequency channels to customize:\n\n
   * 0 - Timestamp\n                          时间戳
   * 1 - Attitude Quaterniouns\n              姿态四元组
   * 2 - Acceleration\n                       加速度
   * 3 - Velocity (Ground Frame)\n            Ground Frame坐标下的速度
   * 4 - Angular Velocity (Body Frame)\n      Body Frame坐标下的角速度
   * 5 - Position\n                           位置
   * 6 - Magnetometer\n                       磁力计             
   * 7 - RC Channels Data\n                   RC频道
   * 8 - Gimbal Data\n                        万向节数据
   * 9 - Flight Status\n                      飞行状态
   * 10 - Battery Level\n                     电池水平
   * 11 - Control Information\n               控制信息
   */
 //设置广播频率,需要以指针形式传入数据长度dataLenIs16,CallBack和UserData
  void setBroadcastFreq(uint8_t *dataLenIs16, CallBack callback = 0, UserData userData = 0);
 //上面函数的重载
  unsigned short setBroadcastFreq(uint8_t *dataLenIs16, int timeout);

  /**
   * Reset all broadcast frequencies to their default values
   */
  //设置默认的频道,无返回值
  void setBroadcastFreqDefaults();

  /**
   * Blocking API Control
   *
   * @brief
   * Set broadcast frequencies to their default values and block until
   * ACK arrives from flight controller
   *
   * @return ACK from flight controller
   *
   * @todo
   * Implement high resolution timer to catch ACK timeout
   */
  //设置高分辨率定时器捕捉ACK超时,有返回值,需要提供超时参数
  unsigned short setBroadcastFreqDefaults(int timeout);
   
  /*
   * Set all broadcast frequencies to zero. Only ACK data will stay on the line.
   */
  //设置广播频道归0
  void setBroadcastFreqToZero();

  /**
   * Let user know when ACK and Broadcast messages processed
   */
  //ACKFrameStatus和BroadcastFrameStatus的设置和获取
  void setACKFrameStatus(uint32_t usageFlag);
  uint32_t getACKFrameStatus();
  void setBroadcastFrameStatus(bool isFrame);
  bool getBroadcastFrameStatus();
  //SyncFreq,Key的设置
  void setSyncFreq(uint32_t freqInHz);
  void setKey(const char *key);

  //@{
  /**
   * Get aircraft version.
   *
   * @note
   * You can query your flight controller prior to activation.
   */
  //获取无人机版本,无返回值
  void getDroneVersion(CallBack callback = 0, UserData userData = 0);

  /**
   * Blocking API Control
   *
   * @brief
   * Get drone version from flight controller block until
   * ACK arrives from flight controller
   *
   * @return VersionData containing ACK value, CRC of the
   * protocol version and protocol version itself
   *
   * @todo
   * Implement high resolution timer to catch ACK timeout
   */
  //获取无人机版本,返回版本数据
  VersionData getDroneVersion(int timeout);

  /**Get broadcasted data values from flight controller.*/
  //获取广播数据返回广播数据
  BroadcastData getBroadcastData() const;
  //非阻塞CB线程使能标志
  bool nonBlockingCBThreadEnable;

  /**
   * Get timestamp from flight controller.从飞控获取时间戳
   *
   * @note
   * Make sure you are using appropriate timestamp broadcast frequency. See setBroadcastFreq\n
   * function for more details.           需要确定合适的广播频率
   */
  //获取时间戳,且不改变对象的成员和不调用该类非const函数
  TimeStampData getTime() const;

  /**
   * Get flight status at any time during a flight mission.  获取飞行任务期间的任何时刻的飞行状态
   */
  //获取飞行状态和控制信息
  FlightStatus getFlightStatus() const;
  CtrlInfoData getCtrlInfo() const;

  /**
   * Get battery capacity. 获取剩余电量
   *
   * @note
   * Flight missions will not perform if battery capacity is under %50. If battery capacity
   * drops below %50 during a flight mission, aircraft will automatically "go home".
   * 电量低于50%时飞机会自动 ”go home“
   */
  //获取剩余电量
  BatteryData getBatteryCapacity() const;
  //@}


  /**
   * Get serial device handler.
   */
 //获取串口驱动
  HardDriver *getDriver() const;
  //获取ACK
  SimpleACK getSimpleACK() const;
  /**
   * Get SDK version
   */
  //获取SDK版本
  Version getSDKVersion() const;

  /**设置回调setXXXCallback(...){...}  **/

  void setBroadcastCallback(CallBackHandler callback) { broadcastCallback = callback; }
  void setFromMobileCallback(CallBackHandler FromMobileEntrance);

  void setBroadcastCallback(CallBack handler, UserData userData = 0);
  void setFromMobileCallback(CallBack handler, UserData userData = 0);

  void setMisssionCallback(CallBackHandler callback) { missionCallback = callback; }
  void setHotPointCallback(CallBackHandler callback) { hotPointCallback = callback; }
  void setWayPointCallback(CallBackHandler callback) { wayPointCallback = callback; }
  void setFollowCallback(CallBackHandler callback) { followCallback = callback; }
  void setWayPointEventCallback(CallBackHandler callback);

  void setMisssionCallback(CallBack handler, UserData userData = 0);
  void setHotPointCallback(CallBack handler, UserData userData = 0);
  void setWayPointCallback(CallBack handler, UserData userData = 0);
  void setFollowCallback(CallBack handler, UserData userData = 0);
  void setWayPointEventCallback(CallBack handler, UserData userData = 0);

  //声明静态函数
  static void activateCallback(CoreAPI *api, Header *protocolHeader, UserData userData = 0);
  static void getDroneVersionCallback(CoreAPI *api, Header *protocolHeader, UserData userData = 0);
  static void setControlCallback(CoreAPI *api, Header *protocolHeader, UserData userData = 0);
  static void sendToMobileCallback(CoreAPI *api, Header *protocolHeader, UserData userData = 0);
  static void setFrequencyCallback(CoreAPI *api, Header *protocolHeader, UserData userData = 0);

  /** 
   * MOS Protocol parsing lirbary functions. MOS协议解析函数库
   */

  /**
   * Default MOS Protocol Parser. Calls other callback functions based on data
   */
  void parseFromMobileCallback(CoreAPI *api, Header *protocolHeader, UserData userData = 0);
  
  /**
   * Mobile Callback handler functions
   */
  void setObtainControlMobileCallback(CallBackHandler callback) {obtainControlMobileCallback = callback;}
  void setReleaseControlMobileCallback(CallBackHandler callback) {releaseControlMobileCallback = callback;}
  void setActivateMobileCallback(CallBackHandler callback) {activateMobileCallback = callback;}
  void setArmMobileCallback(CallBackHandler callback) {armMobileCallback = callback;}
  void setDisArmMobileCallback(CallBackHandler callback) {disArmMobileCallback = callback;}
  void setTakeOffMobileCallback(CallBackHandler callback) {takeOffMobileCallback = callback;}
  void setLandingMobileCallback(CallBackHandler callback) {landingMobileCallback = callback;}
  void setGoHomeMobileCallback(CallBackHandler callback) {goHomeMobileCallback = callback;}
  void setTakePhotoMobileCallback(CallBackHandler callback) {takePhotoMobileCallback = callback;}
  void setStartVideoMobileCallback(CallBackHandler callback) {startVideoMobileCallback = callback;}
  void setStopVideoMobileCallback(CallBackHandler callback) {stopVideoMobileCallback = callback;}

  /**
   * ACK decoder.ACK解码器
   */
  bool decodeACKStatus(unsigned short ack);

  /**
   * Flight mission decoder.飞行任务解码器
   */
  bool decodeMissionStatus(uint8_t ack);

  /**
   *@note  Thread data
   */
  bool stopCond;

  /**
   *@note  Thread data
   */

  uint32_t ack_data;
  HotPointReadACK hotpointReadACK;
  WayPointInitACK waypointInitACK;
  MissionACKUnion missionACKUnion;

  /// Open Protocol Control
  /**
   * Get Open Protocol packet information.  获取协议包信息
   */
  SDKFilter getFilter() const;

  /// HotPoint Mission Control   热点任务数据获取
  bool getHotPointData() const;

  /// WayPoint Mission Control   航点任务获取
  bool getWayPointData() const;

  // FollowMe mission Control    Follow me 任务获取
  bool getFollowData() const;

  /// HotPoint Mission Control   热点任务数据设置
  void setHotPointData(bool value);

  /// WayPoint Mission Control   航点任务设置
  void setWayPointData(bool value);

  /// Follow Me Mission Control  Follow me 任务设置
  void setFollowData(bool value);

  /**
   * Initialize serial device    初始化串口设备
   */
  void setDriver(HardDriver *value);

  /**
   * Set SDK version.            设置SDK版本
   */
  void setVersion(const Version &value);

  /**
   * Setters and getters for Mobile CMD variables - these are used 
   * when interacting with a Data Transparent Transmission App 
   */

  /** Core functions - getters */
  /**获取核心函数getXXX(){return xXXX}  **/

  bool getObtainControlMobileCMD() {return obtainControlMobileCMD;}
  bool getReleaseControlMobileCMD() {return releaseControlMobileCMD;}
  bool getActivateMobileCMD() {return activateMobileCMD;}
  bool getArmMobileCMD() {return armMobileCMD;}
  bool getDisArmMobileCMD() {return disArmMobileCMD;}
  bool getTakeOffMobileCMD() {return takeOffMobileCMD;}
  bool getLandingMobileCMD() {return landingMobileCMD;}
  bool getGoHomeMobileCMD() {return goHomeMobileCMD;}
  bool getTakePhotoMobileCMD() {return takePhotoMobileCMD;}
  bool getStartVideoMobileCMD() {return startVideoMobileCMD;}
  bool getStopVideoMobileCMD() {return stopVideoMobileCMD;}

  /** Custom missions - getters */
  /** 获取自定义任务  **/
  bool getDrawCirMobileCMD() {return drawCirMobileCMD;}
  bool getDrawSqrMobileCMD() {return drawSqrMobileCMD;}
  bool getAttiCtrlMobileCMD() {return attiCtrlMobileCMD;}
  bool getGimbalCtrlMobileCMD() {return gimbalCtrlMobileCMD;}
  bool getWayPointTestMobileCMD() {return wayPointTestMobileCMD;}
  bool getLocalNavTestMobileCMD() {return localNavTestMobileCMD;}
  bool getGlobalNavTestMobileCMD() {return globalNavTestMobileCMD;}
  bool getVRCTestMobileCMD() {return VRCTestMobileCMD;}
  bool getLocalMissionPlanCMD() {return localMissionPlanCMD;}

  /** Core functions - setters */
  /** 设置核心函数setXXX(...){XXX = ...} **/

  void setObtainControlMobileCMD(bool userInput) {obtainControlMobileCMD = userInput;}
  void setReleaseControlMobileCMD(bool userInput) {releaseControlMobileCMD= userInput;}
  void setActivateMobileCMD(bool userInput) {activateMobileCMD= userInput;}
  void setArmMobileCMD(bool userInput) {armMobileCMD= userInput;}
  void setDisArmMobileCMD(bool userInput) {disArmMobileCMD= userInput;}
  void setTakeOffMobileCMD(bool userInput) {takeOffMobileCMD= userInput;}
  void setLandingMobileCMD(bool userInput) {landingMobileCMD= userInput;}
  void setGoHomeMobileCMD(bool userInput) {goHomeMobileCMD= userInput;}
  void setTakePhotoMobileCMD(bool userInput) {takePhotoMobileCMD= userInput;}
  void setStartVideoMobileCMD(bool userInput) {startVideoMobileCMD= userInput;}
  void setStopVideoMobileCMD(bool userInput) {stopVideoMobileCMD= userInput;}

  /** Custom missions - setters */
  /** 设置自定义任务 **/
  void setDrawCirMobileCMD(bool userInput) {drawCirMobileCMD = userInput;}
  void setDrawSqrMobileCMD(bool userInput) {drawSqrMobileCMD = userInput;}
  void setAttiCtrlMobileCMD(bool userInput) {attiCtrlMobileCMD = userInput;}
  void setGimbalCtrlMobileCMD(bool userInput) {gimbalCtrlMobileCMD = userInput;}
  void setWayPointTestMobileCMD(bool userInput) {wayPointTestMobileCMD = userInput;}
  void setLocalNavTestMobileCMD(bool userInput) {localNavTestMobileCMD = userInput;}
  void setGlobalNavTestMobileCMD(bool userInput) {globalNavTestMobileCMD = userInput;}
  void setVRCTestMobileCMD(bool userInput) {VRCTestMobileCMD = userInput;}
  void setLocalMissionPlanCMD(bool userInput) {localMissionPlanCMD = userInput;}
  
  /**  域的声明  **/
  private:
  BroadcastData broadcastData;
  uint32_t ackFrameStatus;
  bool broadcastFrameStatus;
  unsigned char encodeSendData[BUFFER_SIZE];
  unsigned char encodeACK[ACK_SIZE];

  //! Mobile Data Transparent Transmission - callbacks
  CallBackHandler fromMobileCallback;
  CallBackHandler broadcastCallback;
  CallBackHandler hotPointCallback;
  CallBackHandler wayPointCallback;
  CallBackHandler wayPointEventCallback;
  CallBackHandler followCallback;
  CallBackHandler missionCallback;
  CallBackHandler recvCallback;

  CallBackHandler obtainControlMobileCallback;
  CallBackHandler releaseControlMobileCallback;
  CallBackHandler activateMobileCallback;
  CallBackHandler armMobileCallback;
  CallBackHandler disArmMobileCallback;
  CallBackHandler takeOffMobileCallback;
  CallBackHandler landingMobileCallback;
  CallBackHandler goHomeMobileCallback;
  CallBackHandler takePhotoMobileCallback;
  CallBackHandler startVideoMobileCallback;
  CallBackHandler stopVideoMobileCallback;

  //! Mobile Data Transparent Transmission - flags

  bool obtainControlMobileCMD;
  bool releaseControlMobileCMD;
  bool activateMobileCMD;
  bool armMobileCMD;
  bool disArmMobileCMD;
  bool takeOffMobileCMD;
  bool landingMobileCMD;
  bool goHomeMobileCMD;
  bool takePhotoMobileCMD;
  bool startVideoMobileCMD;
  bool stopVideoMobileCMD;

  bool drawCirMobileCMD;
  bool drawSqrMobileCMD;
  bool attiCtrlMobileCMD;
  bool gimbalCtrlMobileCMD;
  bool wayPointTestMobileCMD;
  bool localNavTestMobileCMD;
  bool globalNavTestMobileCMD;
  bool VRCTestMobileCMD;
  bool localMissionPlanCMD;

  VersionData versionData;
  ActivateData accountData;

  unsigned short seq_num;

  SDKFilter filter;

  /// Serial Device Initialization
  //串口初始化
  void init(HardDriver *Driver, CallBackHandler userRecvCallback, bool userCallbackThread,
      Version SDKVersion);
  void recvReqData(Header *protocolHeader);
  void appHandler(Header *protocolHeader);
  void broadcast(Header *protocolHeader);

  int sendInterface(Command *parameter);
  int ackInterface(Ack *parameter);
  void sendData(unsigned char *buf);
  void setup(void);
  void setupMMU(void);
  void setupSession(void);

  MMU_Tab *allocMemory(unsigned short size);

  void freeSession(CMDSession *session);
  CMDSession *allocSession(unsigned short session_id, unsigned short size);

  void freeACK(ACKSession *session);
  ACKSession *allocACK(unsigned short session_id, unsigned short size);
  MMU_Tab MMU[MMU_TABLE_NUM];
  CMDSession CMDSessionTab[SESSION_TABLE_NUM];
  ACKSession ACKSessionTab[SESSION_TABLE_NUM - 1];
  unsigned char memory[MEMORY_SIZE];
  unsigned short encrypt(unsigned char *pdest, const unsigned char *psrc,
      unsigned short w_len, unsigned char is_ack, unsigned char is_enc,
      unsigned char session_id, unsigned short seq_num);

  void streamHandler(SDKFilter *p_filter, unsigned char in_data);
  void checkStream(SDKFilter *p_filter);
  void verifyHead(SDKFilter *p_filter);
  void verifyData(SDKFilter *p_filter);
  void callApp(SDKFilter *p_filter);
  void storeData(SDKFilter *p_filter, unsigned char in_data);
public:
  HardDriver *serialDevice;
private:
  bool callbackThread;
  bool hotPointData;
  bool wayPointData;
  bool followData;

#ifdef API_BUFFER_DATA
  public:
  void setTotalRead(const size_t &value) { totalRead = value; }
  void setOnceRead(const size_t &value) { onceRead = value; }

  size_t getTotalRead() const { return totalRead; }
  size_t getOnceRead() const { return onceRead; }

  private:
  size_t onceRead;
  size_t totalRead;
#endif // API_BUFFER_DATA
};

其实对于我一白纸来说,一上来本应该从最简单的helloworld开始的却不想要去理解那么复杂的东西,先不说理解代码里些什么,就光是理解文件结构弄明白每个格式的文件什么作用怎么用怎么写已经够难的了,再者还要在SDK原有的文件上构建工程,虽然这些在大疆的文档里都给出了方法,但是还是挺难的。

前面谢了那么多,但都只是CoreAPI类的声明,它的实现在/osdk-core/DJI_API.cpp文件:

标签: DJISDK C++
共有 人打赏支持
粉丝 10
博文 15
码字总数 25205
×
风见尘
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: