static BOOL EWMicroRecorderDeclare(PDeviceDescriptor_t d, Declaration_t *decl) { const WAYPOINT *wp; nDeclErrorCode = 0; // Must have at least two, max 12 waypoints if (decl->num_waypoints < 2 || decl->num_waypoints > 12) return FALSE; d->Com->StopRxThread(); d->Com->SetRxTimeout(500); // set RX timeout to 500[ms] if (!EWMicroRecorderTryConnect(d)) { return FALSE; } d->Com->WriteString(TEXT("\x18")); // start to upload file d->Com->WriteString(user_data); EWMicroRecorderPrintf(d, TEXT("%-15s %s\r\n"), TEXT("Pilot Name:"), decl->PilotName); EWMicroRecorderPrintf(d, TEXT("%-15s %s\r\n"), TEXT("Competition ID:"), decl->AircraftRego); EWMicroRecorderPrintf(d, TEXT("%-15s %s\r\n"), TEXT("Aircraft Type:"), decl->AircraftType); d->Com->WriteString(TEXT("Description: Declaration\r\n")); for (int i = 0; i < 11; i++) { wp = decl->waypoint[i]; if (i == 0) { EWMicroRecorderWriteWayPoint(d, wp, TEXT("Take Off LatLong:")); EWMicroRecorderWriteWayPoint(d, wp, TEXT("Start LatLon:")); } else if (i + 1 < decl->num_waypoints) { EWMicroRecorderWriteWayPoint(d, wp, TEXT("TP LatLon:")); } else { EWMicroRecorderPrintf(d, TEXT("%-17s %s\r\n"), TEXT("TP LatLon:"), TEXT("0000000N00000000E TURN POINT\r\n")); } } wp = decl->waypoint[decl->num_waypoints - 1]; EWMicroRecorderWriteWayPoint(d, wp, TEXT("Finish LatLon:")); EWMicroRecorderWriteWayPoint(d, wp, TEXT("Land LatLon:")); d->Com->WriteString(TEXT("\x03")); // finish sending user file if (!ExpectStringWait(d, TEXT("uploaded successfully"))) { // error! nDeclErrorCode = 1; } d->Com->WriteString(TEXT("!!\r\n")); // go back to NMEA mode d->Com->SetRxTimeout(0); // clear timeout d->Com->StartRxThread(); // restart RX thread return(nDeclErrorCode == 0); // return() TRUE on success }
BOOL EWMicroRecorderDeclare(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufferLen, TCHAR errBuffer[]) { const WAYPOINT *wp; nDeclErrorCode = 0; // Must have at least two, max 12 waypoints if(decl->num_waypoints < 2) { // LKTOKEN _@M1412_ = "Not enough waypoints!" _tcsncpy(errBuffer, MsgToken(1412), errBufferLen); return FALSE; } if(decl->num_waypoints > 12) { // LKTOKEN _@M1413_ = "Too many waypoints!" _tcsncpy(errBuffer, MsgToken(1413), errBufferLen); return FALSE; } d->Com->StopRxThread(); d->Com->SetRxTimeout(500); // set RX timeout to 500[ms] const unsigned BUFF_LEN = 128; TCHAR buffer[BUFF_LEN]; // LKTOKEN _@M1400_ = "Task declaration" // LKTOKEN _@M1405_ = "Testing connection" _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1405)); CreateProgressDialog(buffer); if (!EWMicroRecorderTryConnect(d)) { // LKTOKEN _@M1411_ = "Device not connected!" _tcsncpy(errBuffer, MsgToken(1411), errBufferLen); return FALSE; } // LKTOKEN _@M1400_ = "Task declaration" // LKTOKEN _@M1403_ = "Sending declaration" _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1403)); CreateProgressDialog(buffer); d->Com->WriteString(TEXT("\x18")); // start to upload file d->Com->WriteString(user_data); TCHAR EWRecord[128]; _stprintf(EWRecord, TEXT("Pilot Name: %s\r\n"), decl->PilotName); d->Com->WriteString(EWRecord); _stprintf(EWRecord, TEXT("Competition ID: %s\r\n"), decl->CompetitionID); d->Com->WriteString(EWRecord); _stprintf(EWRecord, TEXT("Aircraft Type: %s\r\n"), decl->AircraftType); d->Com->WriteString(EWRecord); _stprintf(EWRecord, TEXT("Aircraft ID: %s\r\n"), decl->AircraftRego); d->Com->WriteString(EWRecord); d->Com->WriteString(TEXT("Description: Declaration\r\n")); for (int i = 0; i < 11; i++) { wp = decl->waypoint[i]; if (i == 0) { EWMicroRecorderWriteWayPoint(d, wp, TEXT("Take Off LatLong: ")); EWMicroRecorderWriteWayPoint(d, wp, TEXT("Start LatLon: ")); } else if (i + 1 < decl->num_waypoints) { EWMicroRecorderWriteWayPoint(d, wp, TEXT("TP LatLon: ")); } else { d->Com->WriteString(TEXT("TP LatLon: 0000000N00000000E TURN POINT\r\n")); } } wp = decl->waypoint[decl->num_waypoints - 1]; EWMicroRecorderWriteWayPoint(d, wp, TEXT("Finish LatLon: ")); EWMicroRecorderWriteWayPoint(d, wp, TEXT("Land LatLon: ")); d->Com->WriteString(TEXT("\x03")); // finish sending user file if (!ExpectStringWait(d, TEXT("uploaded successfully"))) { // error! // LKTOKEN _@M1415_ = "Declaration not accepted!" _tcsncpy(errBuffer, MsgToken(1415), errBufferLen); nDeclErrorCode = 1; } // LKTOKEN _@M1400_ = "Task declaration" // LKTOKEN _@M1402_ = "Disabling declaration mode" _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1402)); CreateProgressDialog(buffer); d->Com->WriteString(TEXT("!!\r\n")); // go back to NMEA mode d->Com->SetRxTimeout(RXTIMEOUT); // clear timeout d->Com->StartRxThread(); // restart RX thread return(nDeclErrorCode == 0); // return() TRUE on success }