00001
00012 #include "DJI_API.h"
00013 #include "DJI_Mission.h"
00014 #include <string.h>
00015
00016 namespace DJI
00017 {
00018 namespace onboardSDK
00019 {
00020
00021 MissionACKMap missionACKMAP[] = {
00023 { 0x00, " 0x00 Success" },
00024 { 0x01, " 0x01 Wrong WayPoint Index" },
00025 { 0xD0, " 0xD0 Not At Mode F" },
00026 { 0xD1, " 0xD1 Need obtain control" },
00027 { 0xD2, " 0xD2 Need close IOC mode" },
00028 { 0xD3, " 0xD3 Mission not inited" },
00029 { 0xD4, " 0xD4 Mission not running" },
00030 { 0xD5, " 0xD5 Mission already running" },
00031 { 0xD6, " 0xD6 Too consuming of time" },
00032 { 0xD7, " 0xD7 Other mission running" },
00033 { 0xD8, " 0xD8 Bad GPS" },
00034 { 0xD9, " 0xD9 Low battery" },
00035 { 0xDA, " 0xDA UAV did not take off" },
00036 { 0xDB, " 0xDB Wrong patameters" },
00037 { 0xDC, " 0xDC Conditions not satisfied" },
00038 { 0xDD, " 0xDD Crossing No-Fly zone" },
00039 { 0xDE, " 0xDE Unrecorded Home" },
00040 { 0xDF, " 0xDF Already at No-Fly zone" },
00041 { 0xC0, " 0xC0 Too High" },
00042 { 0xC1, " 0xC1 Too Low" },
00043 { 0xC7, " 0xC7 Too Far from Home" },
00044 { 0xC8, " 0xC8 Mission not supported" },
00045 { 0xC9, " 0xC9 Too far from current position" },
00046 { 0xCA, " 0xCA Novice Mode not support missions" },
00047 { 0xF0, " 0xF0 Taking off" },
00048 { 0xF1, " 0xF1 Landing" },
00049 { 0xF2, " 0xF2 Returning Home" },
00050 { 0xF3, " 0xF3 Starting motors" },
00051 { 0xF4, " 0xF4 Wrong command" },
00052 { 0xFF, " 0xFF Unknown Error" },
00054 { 0xB0, " 0xB0 too far from your position, lack of Radio connection" },
00055 { 0xB1, " 0xB1 Cutoff time overflow" },
00056 { 0xB2, " 0xB2 Too Large Gimbal pitch angle" },
00058 { 0xC2, " 0xC2 Invalid Radius" },
00059 { 0xC3, " 0xC3 Too large yawRate" },
00060 { 0xC4, " 0xC4 Invalid vision" },
00061 { 0xC5, " 0xC5 Invalid Yaw mode" },
00062 { 0xC6, " 0xC6 Too far from HotPoint" },
00063 { 0xA2, " 0xA2 Invalid HotPoint Parameter" },
00064 { 0xA3, " 0xA3 Invalid latitude or longtitude" },
00065 { 0xA6, " 0xA6 Invalid direction" },
00066 { 0xA9, " 0xA9 HotPoint already paused" },
00067 { 0xAA, " 0xAA HotPoint did not paused" },
00069 { 0xE0, " 0xE0 Invalid waypoint mission data" },
00070 { 0xE1, " 0xE1 Invalid waypoint point data" },
00071 { 0xE2, " 0xE2 Too long waypoint distance" },
00072 { 0xE3, " 0xE3 Too long waypoint mission" },
00073 { 0xE4, " 0xE4 Too much points" },
00074 { 0xE5, " 0xE5 Points too close" },
00075 { 0xE6, " 0xE6 Points too far" },
00076 { 0xE7, " 0xE7 Check faild" },
00077 { 0xE8, " 0xE8 Invalid action" },
00078 { 0xE9, " 0xE9 Point data not enough" },
00079 { 0xEA, " 0xEA Waypoint Mission data not enough" },
00080 { 0xEB, " 0xEB WayPoints not enough" },
00081 { 0xEC, " 0xEC WayPoint already running" },
00082 { 0xED, " 0xED WayPoint not running" },
00083 { 0xEE, " 0xEE Invaild velocity" },
00085 { 0xA0, " 0xA0 Too near from home" },
00086 { 0xA1, " 0xA1 Unknown IOC type" }
00087 };
00088
00089 bool CoreAPI::decodeMissionStatus(uint8_t ack)
00090 {
00091 for (uint8_t i = 0; i < sizeof(missionACKMAP); ++i)
00092 if (missionACKMAP[i].code == ack)
00093 {
00095 API_LOG(serialDevice, STATUS_LOG, "0x%X %s\n", missionACKMAP[i].code, missionACKMAP[i].meaning);
00096 return true;
00097 }
00098 return false;
00099 }
00100
00101 void missionCallback(CoreAPI *api, Header *protocolHeader, UserData userdata __UNUSED)
00102 {
00103 MissionACK ack;
00104 if (protocolHeader->length - EXC_DATA_SIZE <= sizeof(ack))
00105 {
00106 memcpy((unsigned char *)&ack, (unsigned char *)protocolHeader + sizeof(Header),
00107 (protocolHeader->length - EXC_DATA_SIZE));
00108 if (!api->decodeMissionStatus(ack))
00109 API_LOG(api->getDriver(), ERROR_LOG, "Decode ACK error 0x%X\n", ack);
00110 }
00111 else
00112 {
00113 API_LOG(api->getDriver(), ERROR_LOG, "ACK is exception,session id %d,sequence %d\n",
00114 protocolHeader->sessionID, protocolHeader->sequenceNumber);
00115 }
00116 }
00117
00118 void CoreAPI::setWayPointEventCallback(CallBackHandler callback)
00119 {
00120 wayPointEventCallback = callback;
00121 }
00122
00123 void CoreAPI::setMisssionCallback(CallBack handler, UserData userData)
00124 {
00125 missionCallback.callback = handler;
00126 missionCallback.userData = userData;
00127 }
00128
00129 void CoreAPI::setHotPointCallback(CallBack handler, UserData userData)
00130 {
00131 hotPointCallback.callback = handler;
00132 hotPointCallback.userData = userData;
00133 }
00134
00135 void CoreAPI::setWayPointCallback(CallBack handler, UserData userData)
00136 {
00137 wayPointCallback.callback = handler;
00138 wayPointCallback.userData = userData;
00139 }
00140
00141 void CoreAPI::setFollowCallback(CallBack handler, UserData userData)
00142 {
00143 followCallback.callback = handler;
00144 followCallback.userData = userData;
00145 }
00146
00147 void CoreAPI::setWayPointEventCallback(CallBack handler, UserData userData)
00148 {
00149 wayPointEventCallback.callback = handler;
00150 wayPointEventCallback.userData = userData;
00151 }
00152
00153
00154
00155 }
00156 }