Skip to content

Commit d8c6821

Browse files
committed
CLI: Add error for sets on read only settings
1 parent 9569999 commit d8c6821

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

Firmware/RTK_Everywhere/NVM.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ bool parseLine(char *str)
10981098
};
10991099
const int tableEntries = sizeof(table) / sizeof(table[0]);
11001100

1101-
knownSetting = commandCheckForUnknownVariable(settingName, table, tableEntries);
1101+
knownSetting = commandCheckListForVariable(settingName, table, tableEntries);
11021102
}
11031103

11041104
if (knownSetting == false)

Firmware/RTK_Everywhere/menuCommands.ino

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ t_cliResult processCommand(char *cmdBuffer)
218218
value); // Wrap the string setting in quotes in the response, add OK
219219
return (CLI_OK);
220220
}
221+
else if (response == SETTING_KNOWN_READ_ONLY)
222+
{
223+
commandSendErrorResponse(tokens[0], field, (char *)"Setting is read only");
224+
return (CLI_SETTING_READ_ONLY);
225+
}
221226
else
222227
{
223228
commandSendErrorResponse(tokens[0], field, (char *)"Unknown setting");
@@ -604,7 +609,7 @@ int commandLookupSettingNameSelective(bool inCommands, const char *settingName,
604609
}
605610

606611
// Check for unknown variables
607-
bool commandCheckForUnknownVariable(const char *settingName, const char **entry, int tableEntries)
612+
bool commandCheckListForVariable(const char *settingName, const char **entry, int tableEntries)
608613
{
609614
const char **tableEnd;
610615

@@ -1341,8 +1346,8 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
13411346

13421347
ESP.restart();
13431348
}
1344-
1345-
//setProfile was used in the original Web Config interface
1349+
1350+
// setProfile was used in the original Web Config interface
13461351
else if (strcmp(settingName, "setProfile") == 0)
13471352
{
13481353
// Change to new profile
@@ -1368,7 +1373,7 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
13681373
knownSetting = true;
13691374
}
13701375

1371-
//profileNumber is used in the newer CLI with get/set capabilities
1376+
// profileNumber is used in the newer CLI with get/set capabilities
13721377
else if (strcmp(settingName, "profileNumber") == 0)
13731378
{
13741379
// Change to new profile
@@ -1405,10 +1410,11 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
14051410
sendStringToWebsocket(settingsCSV);
14061411
knownSetting = true;
14071412
}
1408-
1413+
14091414
// Is this a profile name change request? ie, 'profile2Name'
14101415
// Search by first letter first to speed up search
1411-
else if ((settingName[0] == 'p') && (strstr(settingName, "profile") != nullptr) && (strcmp(&settingName[8], "Name") == 0))
1416+
else if ((settingName[0] == 'p') && (strstr(settingName, "profile") != nullptr) &&
1417+
(strcmp(&settingName[8], "Name") == 0))
14121418
{
14131419
int profileNumber = settingName[7] - '0';
14141420
if (profileNumber >= 0 && profileNumber <= MAX_PROFILE_COUNT)
@@ -1475,7 +1481,7 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
14751481
knownSetting = true;
14761482
}
14771483

1478-
// Unused variables - read to avoid errors
1484+
// Unused variables from the Web Config interface - read to avoid errors
14791485
else
14801486
{
14811487
const char *table[] = {
@@ -1495,7 +1501,27 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
14951501
};
14961502
const int tableEntries = sizeof(table) / sizeof(table[0]);
14971503

1498-
knownSetting = commandCheckForUnknownVariable(settingName, table, tableEntries);
1504+
knownSetting = commandCheckListForVariable(settingName, table, tableEntries);
1505+
}
1506+
1507+
// Check if this setting is read only
1508+
if(knownSetting == false)
1509+
{
1510+
const char *table[] = {
1511+
"batteryLevelPercent",
1512+
"batteryVoltage",
1513+
"batteryChargingPercentPerHour",
1514+
"bluetoothId",
1515+
"deviceId",
1516+
"deviceName",
1517+
"gnssModuleInfo",
1518+
"rtkFirmwareVersion",
1519+
"rtkRemoteFirmwareVersion",
1520+
};
1521+
const int tableEntries = sizeof(table) / sizeof(table[0]);
1522+
1523+
if(commandCheckListForVariable(settingName, table, tableEntries))
1524+
return (SETTING_KNOWN_READ_ONLY);
14991525
}
15001526

15011527
// If we've received a setting update for a setting that is not valid to this platform,
@@ -1539,7 +1565,7 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
15391565
}
15401566

15411567
if (rtkIndex >= numRtkSettingsEntries)
1542-
systemPrintf("ERROR: Unknown '%s': %0.3lf\r\n", settingName, settingValue);
1568+
systemPrintf("updateSettingWithValue: Unknown '%s': %0.3lf\r\n", settingName, settingValue);
15431569
else
15441570
{
15451571
// Display the warning
@@ -2960,7 +2986,8 @@ SettingValueResponse getSettingValue(bool inCommands, const char *settingName, c
29602986

29612987
// Is this a profile name request? profile2Name
29622988
// Search by first letter first to speed up search
2963-
if ((settingName[0] == 'p') && (strstr(settingName, "profile") != nullptr) && (strcmp(&settingName[8], "Name") == 0))
2989+
if ((settingName[0] == 'p') && (strstr(settingName, "profile") != nullptr) &&
2990+
(strcmp(&settingName[8], "Name") == 0))
29642991
{
29652992
int profileNumber = settingName[7] - '0';
29662993
if (profileNumber >= 0 && profileNumber <= MAX_PROFILE_COUNT)
@@ -3079,7 +3106,7 @@ SettingValueResponse getSettingValue(bool inCommands, const char *settingName, c
30793106
};
30803107
const int tableEntries = sizeof(table) / sizeof(table[0]);
30813108

3082-
knownSetting = commandCheckForUnknownVariable(settingName, table, tableEntries);
3109+
knownSetting = commandCheckListForVariable(settingName, table, tableEntries);
30833110
}
30843111

30853112
if (knownSetting == false)
@@ -3894,7 +3921,7 @@ void printAvailableSettings()
38943921
commandSendExecuteListResponse("enableRCFirmware", "bool", "false");
38953922
}
38963923

3897-
// Display the current RTK Firmware version
3924+
// Display the GNSS receiver info
38983925
else if (commandIndex[i] == COMMAND_GNSS_MODULE_INFO)
38993926
{
39003927
// Create the settingType based on the length of the firmware version

Firmware/RTK_Everywhere/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ typedef enum
549549
SETTING_UNKNOWN = 0,
550550
SETTING_KNOWN,
551551
SETTING_KNOWN_STRING,
552+
SETTING_KNOWN_READ_ONLY,
552553
} SettingValueResponse;
553554

554555
#define INCHES_IN_A_METER 39.37007874
@@ -1230,6 +1231,7 @@ typedef enum
12301231
CLI_OK, // 2
12311232
CLI_BAD_FORMAT,
12321233
CLI_UNKNOWN_SETTING,
1234+
CLI_SETTING_READ_ONLY,
12331235
CLI_UNKNOWN_COMMAND,
12341236
CLI_EXIT,
12351237
CLI_LIST,

0 commit comments

Comments
 (0)