OTA Update working

This commit is contained in:
Bertrand Songis
2019-05-09 08:18:19 +02:00
parent 0f8688edab
commit 713d94ed65
4 changed files with 34 additions and 20 deletions
+29 -16
View File
@@ -393,17 +393,34 @@ bool Pxx2OtaUpdate::waitStep(uint8_t step, uint8_t timeout)
return true; return true;
} }
const char * Pxx2OtaUpdate::nextStep(uint8_t step, const char * rxName, uint32_t address, const uint8_t * buffer)
{
OtaUpdateInformation * destination = moduleState[module].otaUpdateInformation;
destination->step = step;
destination->address = address;
for (uint8_t retry = 0;; retry++) {
extmodulePulsesData.pxx2.sendOtaUpdate(module, rxName, address, (const char *) buffer);
if (waitStep(step + 1, 10)) {
return nullptr;
}
else if (retry == 100) {
return "Transfer failed";
}
}
}
const char * Pxx2OtaUpdate::doFlashFirmware(const char * filename) const char * Pxx2OtaUpdate::doFlashFirmware(const char * filename)
{ {
FIL file; FIL file;
uint8_t buffer[32]; uint8_t buffer[32];
UINT count; UINT count;
OtaUpdateInformation * destination = moduleState[module].otaUpdateInformation; const char * result;
destination->step = OTA_UPDATE_START; result = nextStep(OTA_UPDATE_START, rxName, 0, nullptr);
extmodulePulsesData.pxx2.sendOtaUpdate(module, rxName, 0, nullptr); if (result) {
if (!waitStep(OTA_UPDATE_START_ACK, 10)) { return result;
return "Transfer failed";
} }
if (f_open(&file, filename, FA_READ) != FR_OK) { if (f_open(&file, filename, FA_READ) != FR_OK) {
@@ -418,25 +435,21 @@ const char * Pxx2OtaUpdate::doFlashFirmware(const char * filename)
f_close(&file); f_close(&file);
return "Read file failed"; return "Read file failed";
} }
destination->step = OTA_UPDATE_TRANSFER;
extmodulePulsesData.pxx2.sendOtaUpdate(module, nullptr, done, (char *)buffer); result = nextStep(OTA_UPDATE_TRANSFER, nullptr, done, buffer);
if (!waitStep(OTA_UPDATE_TRANSFER_ACK, 10)) { if (result) {
return "Transfer failed"; return result;
} }
if (count < sizeof(buffer)) { if (count < sizeof(buffer)) {
f_close(&file); f_close(&file);
break; break;
} }
done += count; done += count;
} }
destination->step = OTA_UPDATE_EOF; return nextStep(OTA_UPDATE_EOF, nullptr, done, nullptr);
extmodulePulsesData.pxx2.sendOtaUpdate(module, nullptr, done, nullptr);
if (!waitStep(OTA_UPDATE_END, 10)) {
return "Transfer failed";
}
return nullptr;
} }
void Pxx2OtaUpdate::flashFirmware(const char * filename) void Pxx2OtaUpdate::flashFirmware(const char * filename)
+2 -1
View File
@@ -137,7 +137,7 @@ enum PXX2OtaUpdateSteps {
OTA_UPDATE_TRANSFER, OTA_UPDATE_TRANSFER,
OTA_UPDATE_TRANSFER_ACK, OTA_UPDATE_TRANSFER_ACK,
OTA_UPDATE_EOF, OTA_UPDATE_EOF,
OTA_UPDATE_END OTA_UPDATE_EOF_ACK
}; };
enum PXX2ReceiverStatus { enum PXX2ReceiverStatus {
@@ -295,6 +295,7 @@ class Pxx2OtaUpdate {
const char * doFlashFirmware(const char * filename); const char * doFlashFirmware(const char * filename);
bool waitStep(uint8_t step, uint8_t timeout); bool waitStep(uint8_t step, uint8_t timeout);
const char * nextStep(uint8_t step, const char * rxName, uint32_t address, const uint8_t * buffer);
}; };
#endif #endif
+2 -2
View File
@@ -248,7 +248,7 @@ void processOtaUpdateFrame(uint8_t module, uint8_t * frame)
OtaUpdateInformation * destination = moduleState[module].otaUpdateInformation; OtaUpdateInformation * destination = moduleState[module].otaUpdateInformation;
if (destination->step == OTA_UPDATE_START) { if (destination->step == OTA_UPDATE_START) {
if (frame[3] == 0x00 && memcmp(&destination->candidateReceiversNames[destination->selectedReceiverIndex], &frame[4], PXX2_LEN_RX_NAME) == 0) { if (frame[3] == 0x00 && memcmp(destination->candidateReceiversNames[destination->selectedReceiverIndex], &frame[4], PXX2_LEN_RX_NAME) == 0) {
destination->step = OTA_UPDATE_START_ACK; destination->step = OTA_UPDATE_START_ACK;
} }
} }
@@ -260,7 +260,7 @@ void processOtaUpdateFrame(uint8_t module, uint8_t * frame)
} }
else if (destination->step == OTA_UPDATE_EOF) { else if (destination->step == OTA_UPDATE_EOF) {
if (frame[3] == 0x02) { if (frame[3] == 0x02) {
destination->step = OTA_UPDATE_END; destination->step = OTA_UPDATE_EOF_ACK;
} }
} }
} }
+1 -1
View File
@@ -930,7 +930,7 @@
#define TR_FLASH_EXTERNAL_DEVICE TR("Flash S.Port", "Flash S.Port device") #define TR_FLASH_EXTERNAL_DEVICE TR("Flash S.Port", "Flash S.Port device")
#define TR_FLASH_RECEIVER_OTA "Flash receiver OTA" #define TR_FLASH_RECEIVER_OTA "Flash receiver OTA"
#define TR_FLASH_BLUETOOTH_MODULE TR("Flash BT module", "Flash Bluetooth module") #define TR_FLASH_BLUETOOTH_MODULE TR("Flash BT module", "Flash Bluetooth module")
#define TR_CURRENT_VERSION TR("Current vers. ", "Current version: ") #define TR_CURRENT_VERSION TR("Curr Vers: ", "Current version: ")
#define TR_FLASH_INTERNAL_MODULE TR("Flash int. module", "Flash internal module") #define TR_FLASH_INTERNAL_MODULE TR("Flash int. module", "Flash internal module")
#define TR_FLASH_EXTERNAL_MODULE TR("Flash ext. module", "Flash external module") #define TR_FLASH_EXTERNAL_MODULE TR("Flash ext. module", "Flash external module")
#define TR_FIRMWARE_UPDATE_ERROR TR("FW update error", "Firmware update error") #define TR_FIRMWARE_UPDATE_ERROR TR("FW update error", "Firmware update error")