00001 00012 #include "DJI_HotPoint.h" 00013 #include <string.h> 00014 00015 using namespace DJI; 00016 using namespace DJI::onboardSDK; 00017 00018 HotPoint::HotPoint(CoreAPI *ControlAPI) 00019 { 00020 api = ControlAPI; 00021 00022 initData(); 00023 } 00024 00025 void HotPoint::initData() 00026 { 00027 hotPointData.version = 0; 00028 00029 hotPointData.height = api->getBroadcastData().pos.altitude; 00030 hotPointData.longitude = api->getBroadcastData().pos.longitude; 00031 hotPointData.latitude = api->getBroadcastData().pos.latitude; 00032 00033 hotPointData.radius = 10; 00034 hotPointData.yawRate = 15; 00035 hotPointData.clockwise = 1; 00036 hotPointData.startPoint = HotPoint::VIEW_NEARBY; 00037 hotPointData.yawMode = HotPoint::YAW_INSIDE; 00038 } 00039 00040 void HotPoint::start(CallBack callback, UserData userData) 00041 { 00042 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_START, &hotPointData, sizeof(hotPointData), 500, 2, 00043 callback ? callback : startCallback, userData); 00044 } 00045 00046 HotPointStartACK HotPoint::start(int timeout) 00047 { 00048 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_START, &hotPointData, sizeof(hotPointData), 500, 2, 0, 0); 00049 00050 api->serialDevice->lockACK(); 00051 api->serialDevice->wait(timeout); 00052 api->serialDevice->freeACK(); 00053 00054 return api->missionACKUnion.hotpointStartACK; 00055 } 00056 00057 void HotPoint::stop(CallBack callback, UserData userData) 00058 { 00059 uint8_t zero = 0; 00060 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_STOP, &zero, sizeof(zero), 500, 2, 00061 callback ? callback : missionCallback, userData); 00062 } 00063 00064 MissionACK HotPoint::stop(int timeout) 00065 { 00066 uint8_t zero = 0; 00067 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_STOP, &zero, sizeof(zero), 500, 2, 0, 0); 00068 00069 api->serialDevice->lockACK(); 00070 api->serialDevice->wait(timeout); 00071 api->serialDevice->freeACK(); 00072 00073 return api->missionACKUnion.missionACK; 00074 } 00075 00076 void HotPoint::pause(bool isPause, CallBack callback, UserData userData) 00077 { 00078 uint8_t data = isPause ? 0 : 1; 00079 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_SETPAUSE, &data, sizeof(data), 500, 2, 00080 callback ? callback : missionCallback, userData); 00081 } 00082 00083 MissionACK HotPoint::pause(bool isPause, int timeout) 00084 { 00085 uint8_t data = isPause ? 0 : 1; 00086 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_SETPAUSE, &data, sizeof(data), 500, 2, 0, 0); 00087 00088 api->serialDevice->lockACK(); 00089 api->serialDevice->wait(timeout); 00090 api->serialDevice->freeACK(); 00091 00092 return api->missionACKUnion.missionACK; 00093 } 00094 00095 void HotPoint::updateYawRate(HotPoint::YawRate &Data, CallBack callback, UserData userData) 00096 { 00097 hotPointData.yawRate = Data.yawRate; 00098 hotPointData.clockwise = Data.clockwise ? 1 : 0; 00099 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_YAWRATE, &Data, sizeof(Data), 500, 2, 00100 callback ? callback : missionCallback, userData); 00101 } 00102 00103 MissionACK HotPoint::updateYawRate(HotPoint::YawRate &Data, int timeout) 00104 { 00105 hotPointData.yawRate = Data.yawRate; 00106 hotPointData.clockwise = Data.clockwise ? 1 : 0; 00107 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_YAWRATE, &Data, sizeof(Data), 500, 2, 0, 0); 00108 00109 api->serialDevice->lockACK(); 00110 api->serialDevice->wait(timeout); 00111 api->serialDevice->freeACK(); 00112 00113 return api->missionACKUnion.missionACK; 00114 } 00115 00116 void HotPoint::updateYawRate(float32_t yawRate, bool isClockwise, CallBack callback, 00117 UserData userData) 00118 { 00119 YawRate p; 00120 p.yawRate = yawRate; 00121 p.clockwise = isClockwise ? 1 : 0; 00122 updateYawRate(p, callback, userData); 00123 } 00124 00125 void HotPoint::updateRadius(float32_t meter, CallBack callback, UserData userData) 00126 { 00127 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_RADIUS, &meter, sizeof(meter), 500, 2, 00128 callback ? callback : missionCallback, userData); 00129 } 00130 00131 MissionACK HotPoint::updateRadius(float32_t meter, int timeout) 00132 { 00133 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_RADIUS, &meter, sizeof(meter), 500, 2, 0, 0); 00134 00135 api->serialDevice->lockACK(); 00136 api->serialDevice->wait(timeout); 00137 api->serialDevice->freeACK(); 00138 00139 return api->missionACKUnion.missionACK; 00140 } 00141 00142 void HotPoint::resetYaw(CallBack callback, UserData userData) 00143 { 00144 uint8_t zero = 0; 00145 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_SETYAW, &zero, sizeof(zero), 500, 2, 00146 callback ? callback : missionCallback, userData); 00147 } 00148 00149 MissionACK HotPoint::resetYaw(int timeout) 00150 { 00151 uint8_t zero = 0; 00152 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_SETYAW, &zero, sizeof(zero), 500, 2, 0, 0); 00153 00154 api->serialDevice->lockACK(); 00155 api->serialDevice->wait(timeout); 00156 api->serialDevice->freeACK(); 00157 00158 return api->missionACKUnion.missionACK; 00159 } 00160 00161 void HotPoint::readData(CallBack callback, UserData userData) 00162 { 00163 uint8_t zero = 0; 00164 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_LOAD, &zero, sizeof(zero), 500, 2, 00165 callback ? callback : missionCallback, userData); 00166 } 00167 00168 MissionACK HotPoint::readData(int timeout) 00169 { 00170 uint8_t zero = 0; 00171 api->send(2, encrypt, SET_MISSION, CODE_HOTPOINT_LOAD, &zero, sizeof(zero), 500, 2, 0, 0); 00172 00173 api->serialDevice->lockACK(); 00174 api->serialDevice->wait(timeout); 00175 api->serialDevice->freeACK(); 00176 00177 return api->missionACKUnion.missionACK; 00178 } 00179 00180 void HotPoint::setData(const HotPointData &value) 00181 { 00182 hotPointData = value; 00183 hotPointData.version = 0; 00184 } 00185 00186 void HotPoint::setHotPoint(float64_t longtitude, float64_t latitude, float64_t altitude) 00187 { 00188 hotPointData.longitude = longtitude; 00189 hotPointData.latitude = latitude; 00190 hotPointData.height = altitude; 00191 } 00192 00193 void HotPoint::setHotPoint(GPSPositionData gps) 00194 { 00195 hotPointData.longitude = gps.longitude; 00196 hotPointData.latitude = gps.latitude; 00197 hotPointData.height = gps.altitude; 00198 } 00199 00200 void HotPoint::setRadius(float64_t meter) { hotPointData.radius = meter; } 00201 00202 void HotPoint::setYawRate(float32_t degree) { hotPointData.yawRate = degree; } 00203 00204 void HotPoint::setClockwise(bool isClockwise) { hotPointData.clockwise = isClockwise ? 1 : 0; } 00205 00206 void HotPoint::setCameraView(HotPoint::View view) { hotPointData.startPoint = view; } 00207 00208 void HotPoint::setYawMode(HotPoint::YawMode mode) { hotPointData.yawMode = mode; } 00209 00210 HotPointData HotPoint::getData() const { return hotPointData; } 00211 00212 void HotPoint::startCallback(CoreAPI *api, Header *protocolHeader, UserData userdata __UNUSED) 00213 { 00214 HotPointStartACK ack; 00215 if (protocolHeader->length - EXC_DATA_SIZE <= sizeof(HotPointStartACK)) 00216 { 00217 memcpy((unsigned char *)&ack, (unsigned char *)protocolHeader + sizeof(Header), 00218 (protocolHeader->length - EXC_DATA_SIZE)); 00219 API_LOG(api->getDriver(), STATUS_LOG, "Start ACK has Max radius %f, ACK 0x%X", 00220 ack.maxRadius, ack.ack); 00221 if (!api->decodeMissionStatus(ack.ack)) 00222 API_LOG(api->getDriver(), ERROR_LOG, "Decode ACK error 0x%X", ack.ack); 00223 } 00224 else 00225 { 00226 API_LOG(api->getDriver(), ERROR_LOG, "ACK is exception,session id %d,sequence %d\n", 00227 protocolHeader->sessionID, protocolHeader->sequenceNumber); 00228 } 00229 } 00230 00231 void HotPoint::readCallback(CoreAPI *api, Header *protocolHeader, UserData userdata) 00232 { 00233 HotPoint *hp = (HotPoint *)userdata; 00234 HotPointReadACK ack; 00235 if (protocolHeader->length - EXC_DATA_SIZE <= sizeof(HotPointReadACK)) 00236 { 00237 memcpy((unsigned char *)&ack, (unsigned char *)protocolHeader + sizeof(Header), 00238 (protocolHeader->length - EXC_DATA_SIZE)); 00239 if (!api->decodeMissionStatus(ack.ack)) 00240 API_LOG(api->getDriver(), ERROR_LOG, "Decode ACK error 0x%X", ack.ack); 00241 hp->hotPointData = ack.data; 00242 } 00243 else 00244 { 00245 API_LOG(api->getDriver(), ERROR_LOG, "ACK is exception,session id %d,sequence %d\n", 00246 protocolHeader->sessionID, protocolHeader->sequenceNumber); 00247 } 00248 }