Skip to content

Commit c5b98b6

Browse files
committed
CLI: Add rtkRemoteFirmwareVersion and UPDATEFIRMWARE commands
1 parent 6a416c3 commit c5b98b6

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

Firmware/RTK_Everywhere/menuCommands.ino

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
char otaOutcome[21] = {0}; // Modified by otaUpdate(), used to respond to rtkRemoteFirmwareVersion commands
2+
13
void menuCommands()
24
{
35
char cmdBuffer[200];
@@ -270,6 +272,16 @@ t_cliResult processCommand(char *cmdBuffer)
270272
factoryReset(false); // We do not have the SD semaphore
271273
return (CLI_OK); // We should never get this far.
272274
}
275+
else if (strcmp(tokens[1], "UPDATEFIRMWARE") == 0)
276+
{
277+
// Begin a firmware update. WiFi networks and enableRCFirmware should previously be set.
278+
commandSendExecuteOkResponse(tokens[0], tokens[1]);
279+
otaRequestFirmwareUpdate = true;
280+
281+
// Force exit all config menus and/or command modes to allow OTA state machine to run
282+
btPrintEchoExit = true;
283+
return (CLI_EXIT); // Exit the CLI to allow OTA state machine to run
284+
}
273285
else
274286
{
275287
commandSendErrorResponse(tokens[0], tokens[1], (char *)"Unknown command");
@@ -427,6 +439,7 @@ void commandSendErrorResponse(const char *command, const char *settingName, cons
427439
snprintf(innerBuffer, sizeof(innerBuffer), "%s,%s,,ERROR,%s", command, settingName, errorVerbose);
428440
commandSendResponse(innerBuffer);
429441
}
442+
430443
// Given a command, send structured ERROR response
431444
// Response format: $SPxET,,,ERROR,[Verbose error description]*FF<CR><LF>
432445
// Ex: SPGET, 'Incorrect number of arguments' = "$SPGET,ERROR,Incorrect number of arguments*1E"
@@ -2949,6 +2962,17 @@ SettingValueResponse getSettingValue(bool inCommands, const char *settingName, c
29492962
knownSetting = true;
29502963
settingIsString = true;
29512964
}
2965+
else if (strcmp(settingName, "rtkRemoteFirmwareVersion") == 0)
2966+
{
2967+
// otaUpdate() is synchronous and called from loop() so we respond here with OK, then go check the firmware version
2968+
writeToString(settingValueStr, (char *)"OK");
2969+
knownSetting = true;
2970+
2971+
otaRequestFirmwareVersionCheck = true;
2972+
2973+
// Force exit all config menus and/or command modes to allow OTA state machine to run
2974+
btPrintEchoExit = true;
2975+
}
29522976

29532977
// Special actions
29542978
else if (strcmp(settingName, "enableRCFirmware") == 0)
@@ -3532,6 +3556,10 @@ const char *commandGetName(int stringIndex, int rtkIndex)
35323556
else if (rtkIndex == COMMAND_FIRMWARE_VERSION)
35333557
return "rtkFirmwareVersion";
35343558

3559+
// Connect to the internet and retrieve the remote firmware version
3560+
else if (rtkIndex == COMMAND_REMOTE_FIRMWARE_VERSION)
3561+
return "rtkRemoteFirmwareVersion";
3562+
35353563
// Display the device ID - used in PointPerfect
35363564
else if (rtkIndex == COMMAND_DEVICE_ID)
35373565
return "deviceId";
@@ -3777,6 +3805,13 @@ void printAvailableSettings()
37773805
commandSendExecuteListResponse("rtkFirmwareVersion", settingType, printRtkFirmwareVersion());
37783806
}
37793807

3808+
// Display the current RTK Firmware version
3809+
else if (commandIndex[i] == COMMAND_REMOTE_FIRMWARE_VERSION)
3810+
{
3811+
// Report the avialable command but without data. That requires the user issue separate SPGET.
3812+
commandSendExecuteListResponse("rtkRemoteFirmwareVersion", "char[21]", "NotYetRetreived");
3813+
}
3814+
37803815
// Display the device ID - used in PointPerfect
37813816
else if (commandIndex[i] == COMMAND_DEVICE_ID)
37823817
{

Firmware/RTK_Everywhere/menuFirmware.ino

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,15 @@ void otaDisplayPercentage(int bytesWritten, int totalLength, bool alwaysDisplay)
581581
if (bytesWritten == totalLength)
582582
systemPrintln("]");
583583

584+
// Display progress on the display
584585
displayFirmwareUpdateProgress(percent);
585586

587+
// Report progress over the BLE Command Channel
588+
char stringPercent[5];
589+
snprintf(stringPercent, sizeof(stringPercent), "%d", percent);
590+
commandSendStringOkResponse((char *)"SPEXE", (char *)"UPDATEPROGRESS", stringPercent);
591+
592+
// Report progress to the Web Config socket
586593
if (apConfigFirmwareUpdateInProcess == true)
587594
{
588595
char myProgress[50];
@@ -819,7 +826,7 @@ void otaUpdate()
819826
otaUpdateStop();
820827
break;
821828

822-
// Wait for a request from a user or from the scheduler
829+
// Wait for a request from a user, the Web Config, CLI, or from the scheduler
823830
case OTA_STATE_OFF:
824831
if (otaRequestFirmwareVersionCheck || otaRequestFirmwareUpdate)
825832
{
@@ -849,14 +856,31 @@ void otaUpdate()
849856

850857
else if ((millis() - connectTimer) > (10 * MILLISECONDS_IN_A_SECOND))
851858
{
852-
// Report failed connection to web client
859+
if (settings.debugFirmwareUpdate)
860+
systemPrintln("Firmware update failed to connect to network");
861+
862+
// If we are connected to the Web Config or BLE CLI, then we assume the user
863+
// is requesting the firmware update via those interfaces, thus we attempt an update
864+
// only once, stopping the state machine on failure
865+
853866
if (websocketConnected)
854867
{
855-
if (settings.debugFirmwareUpdate)
856-
systemPrintln("Firmware update failed to connect to network");
868+
// Report failed connection to web client
857869
sendStringToWebsocket((char *)"newFirmwareVersion,NO_INTERNET,");
858870
otaUpdateStop();
859871
}
872+
873+
if (bluetoothCommandIsConnected())
874+
{
875+
// Report failure to the CLI
876+
if(otaRequestFirmwareUpdate)
877+
commandSendExecuteErrorResponse((char *)"SPEXE", (char *)"UPDATEFIRMWARE", (char *)"No Internet");
878+
else if(otaRequestFirmwareVersionCheck)
879+
commandSendErrorResponse((char *)"SPGET", (char *)"rtkRemoteFirmwareVersion", (char *)"No Internet");
880+
otaUpdateStop();
881+
}
882+
883+
860884
}
861885
break;
862886

@@ -904,6 +928,12 @@ void otaUpdate()
904928
sendStringToWebsocket(newVersionCSV);
905929
}
906930

931+
if (bluetoothCommandIsConnected())
932+
{
933+
// Report value over the CLI
934+
commandSendStringResponse((char *)"SPGET", (char *)"rtkRemoteVersion", otaReportedVersion);
935+
}
936+
907937
otaUpdateStop();
908938
return;
909939
}
@@ -927,6 +957,12 @@ void otaUpdate()
927957
systemPrintln("Failed to get version number from server.");
928958
if (websocketConnected)
929959
sendStringToWebsocket((char *)"newFirmwareVersion,NO_SERVER,");
960+
961+
// Report failure over the CLI
962+
if (bluetoothCommandIsConnected())
963+
commandSendExecuteErrorResponse((char *)"SPGET", (char *)"rtkRemoteFimrwareVersion",
964+
(char *)"No Server");
965+
930966
otaUpdateStop();
931967
}
932968
break;
@@ -940,6 +976,11 @@ void otaUpdate()
940976

941977
if (websocketConnected)
942978
sendStringToWebsocket((char *)"gettingNewFirmware,ERROR,");
979+
980+
// Report failure over the CLI
981+
if (bluetoothCommandIsConnected())
982+
commandSendExecuteErrorResponse((char *)"SPEXE", (char *)"UPDATEFIRMWARE",
983+
(char *)"Connection Error");
943984
}
944985
else
945986
{
@@ -950,6 +991,10 @@ void otaUpdate()
950991
if (websocketConnected)
951992
sendStringToWebsocket((char *)"gettingNewFirmware,ERROR,");
952993

994+
// Report failure over the CLI
995+
if (bluetoothCommandIsConnected())
996+
commandSendExecuteErrorResponse((char *)"SPEXE", (char *)"UPDATEFIRMWARE", (char *)"OTA Error");
997+
953998
otaUpdateStop();
954999
}
9551000
break;

Firmware/RTK_Everywhere/settings.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,12 +1207,13 @@ typedef struct
12071207
const char *name;
12081208
} RTK_Settings_Entry;
12091209

1210-
#define COMMAND_PROFILE_0_INDEX -1
1211-
#define COMMAND_PROFILE_NUMBER (COMMAND_PROFILE_0_INDEX - MAX_PROFILE_COUNT) // -1 - 8 = -9
1212-
#define COMMAND_FIRMWARE_VERSION (COMMAND_PROFILE_NUMBER - 1) // -9 - 1 = -10
1213-
#define COMMAND_DEVICE_ID (COMMAND_FIRMWARE_VERSION - 1) // -10 - 1 = -11
1214-
#define COMMAND_UNKNOWN (COMMAND_DEVICE_ID - 1) // -11 - 1 = -12
1215-
#define COMMAND_COUNT (-(COMMAND_UNKNOWN)) // 12
1210+
#define COMMAND_PROFILE_0_INDEX -1
1211+
#define COMMAND_PROFILE_NUMBER (COMMAND_PROFILE_0_INDEX - MAX_PROFILE_COUNT) // -1 - 8 = -9
1212+
#define COMMAND_FIRMWARE_VERSION (COMMAND_PROFILE_NUMBER - 1) // -9 - 1 = -10
1213+
#define COMMAND_REMOTE_FIRMWARE_VERSION (COMMAND_FIRMWARE_VERSION - 1) // -10 - 1 = -11
1214+
#define COMMAND_DEVICE_ID (COMMAND_REMOTE_FIRMWARE_VERSION - 1) // -11 - 1 = -12
1215+
#define COMMAND_UNKNOWN (COMMAND_DEVICE_ID - 1) // -12 - 1 = -13
1216+
#define COMMAND_COUNT (-(COMMAND_UNKNOWN)) // 13
12161217

12171218
// Exit types for processCommand
12181219
typedef enum

0 commit comments

Comments
 (0)