Skip to content

Commit bddaeb1

Browse files
committed
Merge branch 'dev' into leeUpdates
2 parents 2d56fc4 + 9ddadb8 commit bddaeb1

10 files changed

Lines changed: 327 additions & 109 deletions

Firmware/RTK_Everywhere/Device_Firmware_Update.ino

Lines changed: 96 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const int dfuStateNameCount = sizeof(dfuStateName) / sizeof(dfuStateName[0]);
4848
const char * dfuEqualSigns = "==================================================";
4949

5050
//----------------------------------------
51-
// Constants
51+
// Locals
5252
//----------------------------------------
5353

5454
static bool dfuLoopInUpdate; // Loop in deviceFirmwareUpdate while set
@@ -60,7 +60,7 @@ void deviceFirmwareActionMenu(DEVICE_FIRMWARE_CTX * ctx)
6060
{
6161
if (ctx->_doAll == false)
6262
{
63-
inMainMenu = true;
63+
// inMainMenu = true;
6464
systemPrintf("\r\nAction:\r\n");
6565

6666
// Display the menu
@@ -74,7 +74,7 @@ void deviceFirmwareActionMenu(DEVICE_FIRMWARE_CTX * ctx)
7474
systemPrintf("x) Exit\r\n");
7575

7676
// Discard the input
77-
serialInputClear();
77+
serialInputClear(&Serial);
7878

7979
// Output the prompt
8080
systemPrintf("Select an action: ");
@@ -114,11 +114,15 @@ bool deviceFirmwareBufferAllocate(DEVICE_FIRMWARE_CTX * ctx)
114114
}
115115

116116
// Return buffer allocation status
117-
return (dfuFirmwareData._address && dfuFirmwareFileNamesNet._address
117+
return (dfuFirmwareData._address
118+
&& dfuFirmwareFileNamesNet._address
118119
&& ((ctx->_doAll == true)
119120
|| (dfuFirmwareFileNamesNvm._address
120121
&& ((present.microSd == false)
121-
|| dfuFirmwareFileNamesSd._address))));
122+
|| dfuFirmwareFileNamesSd._address)
123+
)
124+
)
125+
);
122126
}
123127

124128
//----------------------------------------
@@ -220,7 +224,7 @@ void deviceFirmwareCleanup(DEVICE_FIRMWARE_CTX * ctx)
220224
systemPrintf("Freeing device firmware update context, %d bytes\r\n", sizeof(*ctx));
221225
rtkFree(ctx, "Device firmware context");
222226
dfuContext = nullptr;
223-
inMainMenu = false;
227+
// inMainMenu = false;
224228
}
225229

226230
//----------------------------------------
@@ -267,7 +271,7 @@ void deviceFirmwareClose(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec)
267271

268272
// Programming a device
269273
else
270-
deviceFirmwareStateSet(ctx, ctx->_reboot ? DFUS_REBOOT : DFUS_DONE);
274+
deviceFirmwareStateSet(ctx, ctx->_reboot ? DFUS_REBOOT : DFUS_NEXT_DEVICE);
271275
}
272276
}
273277

@@ -409,7 +413,7 @@ void deviceFirmwareDeviceListMenu(DEVICE_FIRMWARE_CTX * ctx)
409413
{
410414
if (ctx->_doAll == false)
411415
{
412-
inMainMenu = true;
416+
// inMainMenu = true;
413417
systemPrintf("\r\nDevice List:\r\n");
414418

415419
// Walk the list of devices
@@ -426,7 +430,7 @@ void deviceFirmwareDeviceListMenu(DEVICE_FIRMWARE_CTX * ctx)
426430
systemPrintf("x) Exit\r\n");
427431

428432
// Discard the input
429-
serialInputClear();
433+
serialInputClear(&Serial);
430434
ctx->_buffer[0] = 0;
431435
ctx->_validDataBytes = 0;
432436

@@ -465,7 +469,7 @@ void deviceFirmwareFileListMenu(DEVICE_FIRMWARE_CTX * ctx)
465469

466470
if (ctx->_doAll == false)
467471
{
468-
inMainMenu = true;
472+
// inMainMenu = true;
469473

470474
// Display the firmware version
471475
if (ctx->_deviceInfo->_version)
@@ -492,7 +496,7 @@ void deviceFirmwareFileListMenu(DEVICE_FIRMWARE_CTX * ctx)
492496
systemPrintf("x) Exit\r\n");
493497

494498
// Discard the input
495-
serialInputClear();
499+
serialInputClear(&Serial);
496500
ctx->_buffer[0] = 0;
497501
ctx->_validDataBytes = 0;
498502

@@ -828,17 +832,14 @@ void deviceFirmwareOpenOutput(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec)
828832
// Determine if there is an open routine
829833
if (ctx->_deviceInfo->_open)
830834
{
831-
// Yes, prepare the device for firmware updates
832-
if (settings.debugFirmwareUpdate)
833-
systemPrintf("Preparing the %s for firmware update\r\n",
834-
ctx->_deviceInfo->_deviceName);
835835
result = ctx->_deviceInfo->_open(ctx);
836836
if (result)
837837
break;
838838

839839
// Display the error
840840
systemPrintf("ERROR: %s firmware open failed!\r\n",
841841
ctx->_deviceInfo->_deviceName);
842+
rtkTaskList(&Serial);
842843
}
843844
else
844845
{
@@ -1615,60 +1616,59 @@ bool deviceFirmwareUpdate(uint32_t currentMsec)
16151616
bool running;
16161617
const char * stateName;
16171618

1618-
do
1619+
// Get the context instance
1620+
running = false;
1621+
ctx = dfuContext;
1622+
if (ctx)
16191623
{
1620-
running = false;
1621-
1622-
// Get the context instance
1623-
ctx = dfuContext;
1624-
if (ctx == nullptr)
1625-
break;
1626-
1627-
running = true;
1624+
do
1625+
{
1626+
running = true;
16281627

1629-
// Blink the LED
1630-
deviceFirmwareLedBlink(ctx, currentMsec);
1628+
// Blink the LED
1629+
deviceFirmwareLedBlink(ctx, currentMsec);
16311630

1632-
// Perform the firmware update
1633-
switch (ctx->_state)
1634-
{
1635-
case DFUS_INIT: deviceFirmwareInit(ctx, currentMsec); break;
1636-
case DFUS_WAIT_NETWORK: deviceFirmwareWaitForNetwork(ctx, currentMsec); break;
1637-
case DFUS_GET_DEVICE: deviceFirmwareSelectDevice(ctx, currentMsec); break;
1638-
case DFUS_GET_NETWORK_FILES: dfuNetworkFileListBuildUrl(ctx); break;
1639-
case DFUS_GET_HTTP_FILE_LIST_REQ: dfuNetworkFileListHtmlRequest(ctx, currentMsec); break;
1640-
case DFUS_GET_NETWORK_FILE_LIST: dfuNetworkFileListGetFileName(ctx, currentMsec); break;
1641-
case DFUS_GET_NVM_FILE_LIST: dfuNvmGetFiles(ctx, currentMsec); break;
1642-
case DFUS_GET_SD_FILE_LIST: dfuSdGetFiles(ctx, currentMsec); break;
1643-
case DFUS_SELECT_FILE: deviceFirmwareSelectFile(ctx, currentMsec); break;
1644-
case DFUS_SELECT_ACTION: deviceFirmwareSelectAction(ctx, currentMsec); break;
1645-
case DFUS_CRC_OPEN_INPUT: deviceFirmwareCrcOpen(ctx, currentMsec); break;
1646-
case DFUS_CRC_READ_DATA: deviceFirmwareCrcReadData(ctx, currentMsec); break;
1647-
case DFUS_CRC_CLOSE: deviceFirmwareCrcClose(ctx, currentMsec); break;
1648-
case DFUS_DEVICE_OPEN_INPUT: deviceFirmwareOpenFirmwareFile(ctx, currentMsec); break;
1649-
case DFUS_DEVICE_FILL_BUFFER: deviceFirmwareReadFillBuffer(ctx, currentMsec); break;
1650-
case DFUS_DEVICE_RESET: deviceFirmwareReset(ctx, currentMsec); break;
1651-
case DFUS_DEVICE_OPEN_OUTPUT: deviceFirmwareOpenOutput(ctx, currentMsec); break;
1652-
case DFUS_DEVICE_PROGRAM_FIRMWARE: deviceFirmwareWrite(ctx, currentMsec); break;
1653-
case DFUS_READ_FIRMWARE_DATA: deviceFirmwareReadFirmwareData(ctx, currentMsec); break;
1654-
case DFUS_DEVICE_CLOSE: deviceFirmwareClose(ctx, currentMsec); break;
1655-
case DFUS_NEXT_DEVICE: deviceFirmwareNextDevice(ctx, currentMsec); break;
1656-
case DFUS_REBOOT: dfuEsp32Reboot(); break;
1657-
1658-
case DFUS_DONE:
1659-
deviceFirmwareBufferFree(ctx, true);
1660-
deviceFirmwareCleanup(ctx);
1661-
running = false;
1662-
break;
1631+
// Perform the firmware update
1632+
switch (ctx->_state)
1633+
{
1634+
case DFUS_INIT: deviceFirmwareInit(ctx, currentMsec); break;
1635+
case DFUS_WAIT_NETWORK: deviceFirmwareWaitForNetwork(ctx, currentMsec); break;
1636+
case DFUS_GET_DEVICE: deviceFirmwareSelectDevice(ctx, currentMsec); break;
1637+
case DFUS_GET_NETWORK_FILES: dfuNetworkFileListBuildUrl(ctx); break;
1638+
case DFUS_GET_HTTP_FILE_LIST_REQ: dfuNetworkFileListHtmlRequest(ctx, currentMsec); break;
1639+
case DFUS_GET_NETWORK_FILE_LIST: dfuNetworkFileListGetFileName(ctx, currentMsec); break;
1640+
case DFUS_GET_NVM_FILE_LIST: dfuNvmGetFiles(ctx, currentMsec); break;
1641+
case DFUS_GET_SD_FILE_LIST: dfuSdGetFiles(ctx, currentMsec); break;
1642+
case DFUS_SELECT_FILE: deviceFirmwareSelectFile(ctx, currentMsec); break;
1643+
case DFUS_SELECT_ACTION: deviceFirmwareSelectAction(ctx, currentMsec); break;
1644+
case DFUS_CRC_OPEN_INPUT: deviceFirmwareCrcOpen(ctx, currentMsec); break;
1645+
case DFUS_CRC_READ_DATA: deviceFirmwareCrcReadData(ctx, currentMsec); break;
1646+
case DFUS_CRC_CLOSE: deviceFirmwareCrcClose(ctx, currentMsec); break;
1647+
case DFUS_DEVICE_OPEN_INPUT: deviceFirmwareOpenFirmwareFile(ctx, currentMsec); break;
1648+
case DFUS_DEVICE_FILL_BUFFER: deviceFirmwareReadFillBuffer(ctx, currentMsec); break;
1649+
case DFUS_DEVICE_RESET: deviceFirmwareReset(ctx, currentMsec); break;
1650+
case DFUS_DEVICE_OPEN_OUTPUT: deviceFirmwareOpenOutput(ctx, currentMsec); break;
1651+
case DFUS_DEVICE_PROGRAM_FIRMWARE: deviceFirmwareWrite(ctx, currentMsec); break;
1652+
case DFUS_READ_FIRMWARE_DATA: deviceFirmwareReadFirmwareData(ctx, currentMsec); break;
1653+
case DFUS_DEVICE_CLOSE: deviceFirmwareClose(ctx, currentMsec); break;
1654+
case DFUS_NEXT_DEVICE: deviceFirmwareNextDevice(ctx, currentMsec); break;
1655+
case DFUS_REBOOT: dfuEsp32Reboot(); break;
1656+
1657+
case DFUS_DONE:
1658+
deviceFirmwareBufferFree(ctx, true);
1659+
deviceFirmwareCleanup(ctx);
1660+
running = false;
1661+
break;
16631662

1664-
default:
1665-
stateName = deviceFirmwareStateGetName(ctx->_state);
1666-
systemPrintf("Device firmware update state: %d (%s)\r\n", ctx->_state, stateName);
1667-
reportFatalError("Device firmware update state not implemented!");
1668-
deviceFirmwareStateSet(ctx, DFUS_DONE);
1669-
break;
1670-
}
1671-
} while (dfuLoopInUpdate);
1663+
default:
1664+
stateName = deviceFirmwareStateGetName(ctx->_state);
1665+
systemPrintf("Device firmware update state: %d (%s)\r\n", ctx->_state, stateName);
1666+
reportFatalError("Device firmware update state not implemented!");
1667+
deviceFirmwareStateSet(ctx, DFUS_DONE);
1668+
break;
1669+
}
1670+
} while (dfuLoopInUpdate);
1671+
}
16721672
return running;
16731673
}
16741674

@@ -1798,7 +1798,8 @@ bool deviceFirmwareWaitForNetwork(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMse
17981798
void deviceFirmwareWrite(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec)
17991799
{
18001800
size_t bytesToWrite;
1801-
size_t bytesWritten;
1801+
ssize_t bytesWritten;
1802+
bool done;
18021803
int percentage;
18031804
DEVICE_WRITE write;
18041805

@@ -1826,37 +1827,41 @@ void deviceFirmwareWrite(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec)
18261827
bytesWritten = dfuNvmWrite(ctx, ctx->_data, bytesToWrite);
18271828
else if (ctx->_outputDeviceType == DFU_ODT_SD)
18281829
bytesWritten = dfuSdWrite(ctx, ctx->_data, bytesToWrite);
1829-
if (bytesWritten >= 0)
1830+
1831+
// Handle the error case
1832+
if (bytesWritten <= 0)
1833+
break;
1834+
1835+
// Account for the data written
1836+
ctx->_validDataBytes -= bytesWritten;
1837+
ctx->_data += bytesWritten;
1838+
ctx->_bytesWritten += bytesWritten;
1839+
if (ctx->_bytesWritten == ctx->_fileBytes)
1840+
ctx->_complete = true;
1841+
1842+
// Display the number of bytes written
1843+
if (settings.debugFirmwareUpdate && ctx->_debugVerbose)
1844+
systemPrintf("bytesWritten: %d\r\n", bytesWritten);
1845+
1846+
// Display the percentage changes
1847+
percentage = ctx->_bytesWritten * 100 / ctx->_fileBytes;
1848+
if (percentage != ctx->_percentage)
18301849
{
1831-
// Account for the data written
1832-
ctx->_validDataBytes -= bytesWritten;
1833-
ctx->_data += bytesWritten;
1834-
ctx->_bytesWritten += bytesWritten;
1835-
if (ctx->_bytesWritten == ctx->_fileBytes)
1836-
ctx->_complete = true;
1837-
1838-
// Display the number of bytes written
1839-
if (settings.debugFirmwareUpdate && ctx->_debugVerbose)
1840-
systemPrintf("bytesWritten: %d\r\n", bytesWritten);
1850+
ctx->_percentage = percentage;
1851+
displayFirmwareUpdateProgress(percentage);
1852+
systemPrintf("\r[%s %d%%%s",
1853+
&dfuEqualSigns[strlen(dfuEqualSigns) - (percentage >> 1)],
1854+
percentage,
1855+
settings.debugFirmwareUpdate ? "\r\n" : "");
18411856
}
18421857
}
18431858

1844-
// Display the percentage changes
1845-
percentage = ctx->_bytesWritten * 100 / ctx->_fileBytes;
1846-
if (percentage != ctx->_percentage)
1847-
{
1848-
ctx->_percentage = percentage;
1849-
displayFirmwareUpdateProgress(percentage);
1850-
systemPrintf("\r[%s %d%%",
1851-
&dfuEqualSigns[strlen(dfuEqualSigns) - (percentage >> 1)],
1852-
percentage);
1853-
}
1854-
18551859
// Read more data
1856-
if (ctx->_complete || settings.debugFirmwareUpdate)
1860+
done = ctx->_complete || (bytesWritten <= 0);
1861+
if (ctx->_complete && (settings.debugFirmwareUpdate == false))
18571862
systemPrintln();
1858-
deviceFirmwareStateSet(ctx, ctx->_complete ? DFUS_DEVICE_CLOSE
1859-
: DFUS_READ_FIRMWARE_DATA);
1863+
deviceFirmwareStateSet(ctx, done ? DFUS_DEVICE_CLOSE
1864+
: DFUS_READ_FIRMWARE_DATA);
18601865
}
18611866

18621867
#endif // COMPILE_MENU_FIRMWARE

Firmware/RTK_Everywhere/Device_Update.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ typedef void (* DEVICE_CLOSE)(DEVICE_FIRMWARE_CTX * ctx);
190190
typedef bool (* DEVICE_OPEN)(DEVICE_FIRMWARE_CTX * ctx);
191191
typedef bool (* DEVICE_RESET)(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec);
192192
typedef ssize_t (* DEVICE_WRITE)(DEVICE_FIRMWARE_CTX * ctx,
193-
uint8_t * buffer,
193+
const uint8_t * buffer,
194194
size_t bytesToWrite);
195195
typedef String (* GET_FIRMWARE_VERSION)(DEVICE_FIRMWARE_CTX * ctx);
196196
typedef bool (* INIT_DEV_CTX)(DEVICE_FIRMWARE_CTX * ctx);
@@ -212,9 +212,9 @@ typedef struct _DEVICE_FIRMWARE_INFO
212212
DEVICE_WRITE _write; // Perform the firmware writes
213213
DEVICE_CLOSE _close; // Perform firmware write cleanup
214214
INIT_DEV_CTX _initDevCtx; // Initialize the device specific context
215+
size_t _devContextBytes; // Size of device specific context buffer
215216
bool _crcNeeded; // Is file CRC needed to do firmware update
216217
bool _useNvm; // Allow copy to NVM
217-
size_t _devContextBytes; // Size of device specific context buffer
218218
size_t _writeBufferBytes; // Number of bytes needed for the write buffer
219219
size_t _maxWriteBytes; // Maximum write packet size
220220

@@ -278,7 +278,7 @@ const int dfuBufferInfoCount = sizeof(dfuBufferInfo) / sizeof(dfuBufferInfo[0]);
278278
#ifdef COMPILE_LG290P
279279
#define DFU_LG290P_MAX_PAYLOAD_SIZE (5 * 1024)
280280
#define DFU_LG290P_BYTES (1 + 1 + 1 + 2 + 4 + DFU_LG290P_MAX_PAYLOAD_SIZE + 4 + 1)
281-
#endif //COMPILE_LG290P
281+
#endif // COMPILE_LG290P
282282

283283
//----------------------------------------
284284
// Declare the forward device support routines
@@ -297,10 +297,10 @@ bool dfuLg290pOpen(DEVICE_FIRMWARE_CTX * ctx);
297297

298298
// Device write, perform the firmware update
299299
ssize_t dfuEsp32Write(DEVICE_FIRMWARE_CTX * ctx,
300-
uint8_t * buffer,
300+
const uint8_t * buffer,
301301
size_t bytesToWrite);
302302
ssize_t dfuLg290pWrite(DEVICE_FIRMWARE_CTX * ctx,
303-
uint8_t * buffer,
303+
const uint8_t * buffer,
304304
size_t bytesToWrite);
305305

306306
// Device close, finalize the firmware update
@@ -319,13 +319,13 @@ bool deviceFirmwareUpdateBegin(bool doAll,
319319
// Note: Use the JSON based OTA to get a new ESP32 image when the
320320
// parsing fails due to website changes on the servers below!
321321
const DEVICE_FIRMWARE_INFO deviceFirmwareInfo[] =
322-
{// Name present Directory NameData Extension Firmware version Reset Open Write Close InitDevCtx CRC useNvm Context Bytes Buffer Bytes Max Write Bytes Server Branch dPrefix1 dPrefix2 dirEnd nPrefix nameEnd Raw Branch
323-
{"ESP32", nullptr, nullptr, "Firmware_v", ".bin", dfuEsp32GetFirmwareVersion, nullptr, dfuEsp32Open, dfuEsp32Write, dfuEsp32Close, nullptr, false, false, 0, 0, 0, dfuGithub, nullptr, dfuTree, dfuItems, dfuListEnd, dfuName, dfuNameEnd, dfuRawHead},
322+
{// Name present Directory NameData Extension Firmware version Reset Open Write Close InitDevCtx Context Bytes CRC useNvm Buffer Bytes Max Write Bytes Server Branch dPrefix1 dPrefix2 dirEnd nPrefix nameEnd Raw Branch
323+
{"ESP32", nullptr, nullptr, "Firmware_v", ".bin", dfuEsp32GetFirmwareVersion, nullptr, dfuEsp32Open, dfuEsp32Write, dfuEsp32Close, nullptr, 0, false, false, 0, 0, dfuGithub, nullptr, dfuTree, dfuItems, dfuListEnd, dfuName, dfuNameEnd, dfuRawHead},
324324
// ESP32 must be the first entry in the list, p command does list in reverse
325325

326326
// GNSS devices
327327
#ifdef COMPILE_LG290P
328-
{"LG290P", &present.gnss_lg290p, "/gnss/lg290p", "LG290P", ".pkg", dfuGnssGetFirmwareVersion, dfuLg290pReset, dfuLg290pOpen, dfuLg290pWrite, dfuLg290pClose, nullptr, true, false, 0, DFU_LG290P_BYTES, DFU_LG290P_MAX_PAYLOAD_SIZE, dfuGithub, dfuRawHead, dfuFileTree, dfuItems, dfuListEnd, dfuName, dfuNameEnd, dfuRawHead},
328+
{"LG290P", &present.gnss_lg290p, "/gnss/lg290p", "LG290P", ".pkg", dfuGnssGetFirmwareVersion, dfuLg290pReset, dfuLg290pOpen, dfuLg290pWrite, dfuLg290pClose, nullptr, 0, true, false, DFU_LG290P_BYTES, DFU_LG290P_MAX_PAYLOAD_SIZE, dfuGithub, dfuRawHead, dfuFileTree, dfuItems, dfuListEnd, dfuName, dfuNameEnd, dfuRawHead},
329329
#endif // COMPILE_LG290P
330330
};
331331
const int deviceFirmwareInfoCount = sizeof(deviceFirmwareInfo) / sizeof(deviceFirmwareInfo[0]);

Firmware/RTK_Everywhere/Device_Update_ESP32.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ void dfuEsp32Reboot()
9797
// ESP32 firmware write
9898
//----------------------------------------
9999
ssize_t dfuEsp32Write(DEVICE_FIRMWARE_CTX * ctx,
100-
uint8_t * buffer,
100+
const uint8_t * buffer,
101101
size_t bytesToWrite)
102102
{
103-
return Update.write(buffer, bytesToWrite);
103+
return Update.write((uint8_t *)buffer, bytesToWrite);
104104
}

Firmware/RTK_Everywhere/Device_Update_LG290P.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ bool dfuLg290pReset()
431431
// LG290P firmware write
432432
//----------------------------------------
433433
ssize_t dfuLg290pWrite(DEVICE_FIRMWARE_CTX * ctx,
434-
uint8_t * buffer,
434+
const uint8_t * buffer,
435435
size_t bytesToWrite)
436436
{
437437
size_t commandLength;
@@ -479,7 +479,7 @@ ssize_t dfuLg290pWrite(DEVICE_FIRMWARE_CTX * ctx,
479479
}
480480
}
481481
} while (retryCount++ < 3);
482-
return -1;
482+
return 0;
483483
}
484484

485485
#endif // COMPILE_LG290P

0 commit comments

Comments
 (0)