Skip to content

Commit 11ac6f5

Browse files
committed
Add full command types JSON support
1 parent c6d423f commit 11ac6f5

File tree

1 file changed

+122
-31
lines changed

1 file changed

+122
-31
lines changed

Firmware/RTK_Everywhere/menuCommands.ino

Lines changed: 122 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,25 @@ void commandSendResponse(const char *innerBuffer)
504504
commandSendAllInterfaces(responseBuffer);
505505
}
506506

507+
// Given an inner buffer, send response sentence with checksum and <CR><LR>
508+
// Ex: SPGET,elvMask,0.25 = $SPGET,elvMask,0.25*07
509+
void commandSendResponseUnbuffered(const char *prefix, const char *innerBuffer)
510+
{
511+
uint8_t calculatedChecksum = 0; // XOR chars between '$' and '*'
512+
for (int x = 1; x < strlen(prefix); x++)
513+
calculatedChecksum = calculatedChecksum ^ prefix[x];
514+
for (int x = 0; x < strlen(innerBuffer); x++)
515+
calculatedChecksum = calculatedChecksum ^ innerBuffer[x];
516+
517+
char suffix[6];
518+
sprintf(suffix, "*%02X\r\n", calculatedChecksum);
519+
520+
// CLI interactions may come from BLE or serial, respond to all interfaces
521+
commandSendAllInterfaces((char *)prefix);
522+
commandSendAllInterfaces((char *)innerBuffer);
523+
commandSendAllInterfaces(suffix);
524+
}
525+
507526
// Pass a command string to the all interfaces
508527
void commandSendAllInterfaces(char *rxData)
509528
{
@@ -1183,7 +1202,24 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
11831202
int stream;
11841203
if (sscanf(suffix, "%d", &stream) == 1)
11851204
{
1186-
settings.mosaicStreamIntervalsNMEA[stream] = settingValue;
1205+
double settingValue_d;
1206+
int x;
1207+
1208+
// Check if stream interval settingValue is text format ("10ms" etc.)
1209+
for (x = 0; x < MAX_MOSAIC_MSG_RATES; x++)
1210+
{
1211+
if (strcmp(settingValueStr, mosaicMsgRates[x].humanName) == 0)
1212+
{
1213+
settingValue_d = x;
1214+
break;
1215+
}
1216+
}
1217+
1218+
// If stream interval is not text, x will be MAX_MOSAIC_MSG_RATES
1219+
if (x == MAX_MOSAIC_MSG_RATES)
1220+
settingValue_d = settingValue;
1221+
1222+
settings.mosaicStreamIntervalsNMEA[stream] = settingValue_d;
11871223
knownSetting = true;
11881224
break;
11891225
}
@@ -3315,7 +3351,7 @@ void commandList(bool inCommands, int i)
33153351
settings.ubxConstellations[x].textName);
33163352

33173353
getSettingValue(inCommands, settingName, settingValue);
3318-
commandSendExecuteListResponse(settingName, "bool", settingValue);
3354+
commandSendExecuteListResponse(settingName, "tUbxConst", settingValue);
33193355
}
33203356
}
33213357
break;
@@ -3326,7 +3362,7 @@ void commandList(bool inCommands, int i)
33263362
snprintf(settingName, sizeof(settingName), "%s%s", rtkSettingsEntries[i].name, ubxMessages[x].msgTextName);
33273363

33283364
getSettingValue(inCommands, settingName, settingValue);
3329-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3365+
commandSendExecuteListResponse(settingName, "tUbxMsgRt", settingValue);
33303366
}
33313367
}
33323368
break;
@@ -3341,7 +3377,7 @@ void commandList(bool inCommands, int i)
33413377
ubxMessages[firstRTCMRecord + x].msgTextName);
33423378

33433379
getSettingValue(inCommands, settingName, settingValue);
3344-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3380+
commandSendExecuteListResponse(settingName, "tUbMsgRtb", settingValue);
33453381
}
33463382
}
33473383
break;
@@ -3452,7 +3488,7 @@ void commandList(bool inCommands, int i)
34523488
umMessagesNMEA[x].msgTextName);
34533489

34543490
getSettingValue(inCommands, settingName, settingValue);
3455-
commandSendExecuteListResponse(settingName, "float", settingValue);
3491+
commandSendExecuteListResponse(settingName, "tUmMRNmea", settingValue);
34563492
}
34573493
}
34583494
break;
@@ -3464,7 +3500,7 @@ void commandList(bool inCommands, int i)
34643500
umMessagesRTCM[x].msgTextName);
34653501

34663502
getSettingValue(inCommands, settingName, settingValue);
3467-
commandSendExecuteListResponse(settingName, "float", settingValue);
3503+
commandSendExecuteListResponse(settingName, "tUmMRRvRT", settingValue);
34683504
}
34693505
}
34703506
break;
@@ -3476,7 +3512,7 @@ void commandList(bool inCommands, int i)
34763512
umMessagesRTCM[x].msgTextName);
34773513

34783514
getSettingValue(inCommands, settingName, settingValue);
3479-
commandSendExecuteListResponse(settingName, "float", settingValue);
3515+
commandSendExecuteListResponse(settingName, "tUmMRBaRT", settingValue);
34803516
}
34813517
}
34823518
break;
@@ -3488,7 +3524,7 @@ void commandList(bool inCommands, int i)
34883524
um980ConstellationCommands[x].textName);
34893525

34903526
getSettingValue(inCommands, settingName, settingValue);
3491-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3527+
commandSendExecuteListResponse(settingName, "tUmConst", settingValue);
34923528
}
34933529
}
34943530
break;
@@ -3526,7 +3562,7 @@ void commandList(bool inCommands, int i)
35263562
mosaicSignalConstellations[x].configName);
35273563

35283564
getSettingValue(inCommands, settingName, settingValue);
3529-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3565+
commandSendExecuteListResponse(settingName, "tMosaicConst", settingValue);
35303566
}
35313567
}
35323568
break;
@@ -3538,7 +3574,7 @@ void commandList(bool inCommands, int i)
35383574
mosaicMessagesNMEA[x].msgTextName);
35393575

35403576
getSettingValue(inCommands, settingName, settingValue);
3541-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3577+
commandSendExecuteListResponse(settingName, "tMosaicMSNmea", settingValue);
35423578
}
35433579
}
35443580
break;
@@ -3549,7 +3585,7 @@ void commandList(bool inCommands, int i)
35493585
snprintf(settingName, sizeof(settingName), "%s%d", rtkSettingsEntries[i].name, x);
35503586

35513587
getSettingValue(inCommands, settingName, settingValue);
3552-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3588+
commandSendExecuteListResponse(settingName, "tMosaicSINmea", mosaicMsgRates[atoi(settingValue)].humanName);
35533589
}
35543590
}
35553591
break;
@@ -3561,7 +3597,7 @@ void commandList(bool inCommands, int i)
35613597
mosaicRTCMv3MsgIntervalGroups[x].name);
35623598

35633599
getSettingValue(inCommands, settingName, settingValue);
3564-
commandSendExecuteListResponse(settingName, "float", settingValue);
3600+
commandSendExecuteListResponse(settingName, "tMosaicMIRvRT", settingValue);
35653601
}
35663602
}
35673603
break;
@@ -3573,7 +3609,7 @@ void commandList(bool inCommands, int i)
35733609
mosaicRTCMv3MsgIntervalGroups[x].name);
35743610

35753611
getSettingValue(inCommands, settingName, settingValue);
3576-
commandSendExecuteListResponse(settingName, "float", settingValue);
3612+
commandSendExecuteListResponse(settingName, "tMosaicMIBaRT", settingValue);
35773613
}
35783614
}
35793615
break;
@@ -3585,7 +3621,7 @@ void commandList(bool inCommands, int i)
35853621
mosaicMessagesRTCMv3[x].name);
35863622

35873623
getSettingValue(inCommands, settingName, settingValue);
3588-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3624+
commandSendExecuteListResponse(settingName, "tMosaicMERvRT", settingValue);
35893625
}
35903626
}
35913627
break;
@@ -3597,7 +3633,7 @@ void commandList(bool inCommands, int i)
35973633
mosaicMessagesRTCMv3[x].name);
35983634

35993635
getSettingValue(inCommands, settingName, settingValue);
3600-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3636+
commandSendExecuteListResponse(settingName, "tMosaicMEBaRT", settingValue);
36013637
}
36023638
}
36033639
break;
@@ -3612,7 +3648,7 @@ void commandList(bool inCommands, int i)
36123648
lgMessagesNMEA[x].msgTextName);
36133649

36143650
getSettingValue(inCommands, settingName, settingValue);
3615-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3651+
commandSendExecuteListResponse(settingName, "tLgMRNmea", settingValue);
36163652
}
36173653
}
36183654
break;
@@ -3624,7 +3660,7 @@ void commandList(bool inCommands, int i)
36243660
lgMessagesRTCM[x].msgTextName);
36253661

36263662
getSettingValue(inCommands, settingName, settingValue);
3627-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3663+
commandSendExecuteListResponse(settingName, "tLgMRRvRT", settingValue);
36283664
}
36293665
}
36303666
break;
@@ -3636,7 +3672,7 @@ void commandList(bool inCommands, int i)
36363672
lgMessagesRTCM[x].msgTextName);
36373673

36383674
getSettingValue(inCommands, settingName, settingValue);
3639-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3675+
commandSendExecuteListResponse(settingName, "tLgMRBaRT", settingValue);
36403676
}
36413677
}
36423678
break;
@@ -3648,7 +3684,7 @@ void commandList(bool inCommands, int i)
36483684
lgMessagesPQTM[x].msgTextName);
36493685

36503686
getSettingValue(inCommands, settingName, settingValue);
3651-
commandSendExecuteListResponse(settingName, "uint8_t", settingValue);
3687+
commandSendExecuteListResponse(settingName, "tLgMRPqtm", settingValue);
36523688
}
36533689
}
36543690
break;
@@ -3659,7 +3695,7 @@ void commandList(bool inCommands, int i)
36593695
snprintf(settingName, sizeof(settingName), "%s%s", rtkSettingsEntries[i].name, lg290pConstellationNames[x]);
36603696

36613697
getSettingValue(inCommands, settingName, settingValue);
3662-
commandSendExecuteListResponse(settingName, "bool", settingValue);
3698+
commandSendExecuteListResponse(settingName, "tLgConst", settingValue);
36633699
}
36643700
}
36653701
break;
@@ -3972,9 +4008,19 @@ bool commandIndexFill(bool usePossibleSettings)
39724008
return true;
39734009
}
39744010

4011+
void printSettingsCommandTypes()
4012+
{
4013+
String json;
4014+
createCommandTypesJson(json);
4015+
commandSendResponseUnbuffered("$SPCTY,", json.c_str());
4016+
}
4017+
39754018
// List available settings, their type in CSV, and value
39764019
void printAvailableSettings()
39774020
{
4021+
// Print the command types JSON blob
4022+
printSettingsCommandTypes();
4023+
39784024
// Display the commands
39794025
for (int i = 0; i < commandCount; i++)
39804026
{
@@ -4130,6 +4176,7 @@ void createCommandTypesJson(String &output)
41304176

41314177
JsonArray command_types = doc["command types"].to<JsonArray>();
41324178

4179+
#ifdef COMPILE_LG290P
41334180
// LG290P
41344181

41354182
JsonObject command_types_tLgConst = command_types.add<JsonObject>();
@@ -4157,31 +4204,31 @@ void createCommandTypesJson(String &output)
41574204
command_types_tLgMRNmea_values.add("1");
41584205

41594206
JsonObject command_types_tLgMRBaRT = command_types.add<JsonObject>();
4160-
command_types_tLgMRBaRT["Name"] = "tLgMRBaRT";
4207+
command_types_tLgMRBaRT["name"] = "tLgMRBaRT";
41614208
command_types_tLgMRBaRT["description"] = "LG290P RTCM message rates - Base";
41624209
command_types_tLgMRBaRT["instruction"] = "Set the RTCM message interval in seconds for Base (0 = Off)";
41634210
command_types_tLgMRBaRT["prefix"] = "messageRateRTCMBase_";
41644211
JsonArray command_types_tLgMRBaRT_keys = command_types_tLgMRBaRT["keys"].to<JsonArray>();
41654212
for (int x = 0; x < MAX_LG290P_RTCM_MSG; x++)
41664213
command_types_tLgMRBaRT_keys.add(lgMessagesRTCM[x].msgTextName);
4167-
command_types_tLgMRBaRT["type"] = "integer";
4214+
command_types_tLgMRBaRT["type"] = "int";
41684215
command_types_tLgMRBaRT["value min"] = 0;
41694216
command_types_tLgMRBaRT["value max"] = 1200;
41704217

41714218
JsonObject command_types_tLgMRRvRT = command_types.add<JsonObject>();
4172-
command_types_tLgMRRvRT["Name"] = "tLgMRRvRT";
4219+
command_types_tLgMRRvRT["name"] = "tLgMRRvRT";
41734220
command_types_tLgMRRvRT["description"] = "LG290P RTCM message rates - Rover";
41744221
command_types_tLgMRRvRT["instruction"] = "Set the RTCM message interval in seconds for Rover (0 = Off)";
41754222
command_types_tLgMRRvRT["prefix"] = "messageRateRTCMRover_";
41764223
JsonArray command_types_tLgMRRvRT_keys = command_types_tLgMRRvRT["keys"].to<JsonArray>();
41774224
for (int x = 0; x < MAX_LG290P_RTCM_MSG; x++)
41784225
command_types_tLgMRRvRT_keys.add(lgMessagesRTCM[x].msgTextName);
4179-
command_types_tLgMRRvRT["type"] = "integer";
4226+
command_types_tLgMRRvRT["type"] = "int";
41804227
command_types_tLgMRRvRT["value min"] = 0;
41814228
command_types_tLgMRRvRT["value max"] = 1200;
41824229

41834230
JsonObject command_types_tLgMRPqtm = command_types.add<JsonObject>();
4184-
command_types_tLgMRPqtm["Name"] = "tLgMRPqtm";
4231+
command_types_tLgMRPqtm["name"] = "tLgMRPqtm";
41854232
command_types_tLgMRPqtm["description"] = "LG290P PQTM message rates";
41864233
command_types_tLgMRPqtm["instruction"] = "Enable / disable each PQTM message";
41874234
command_types_tLgMRPqtm["prefix"] = "messageRatePQTM_";
@@ -4191,7 +4238,9 @@ void createCommandTypesJson(String &output)
41914238
JsonArray command_types_tLgMRPqtm_values = command_types_tLgMRPqtm["values"].to<JsonArray>();
41924239
command_types_tLgMRPqtm_values.add("0");
41934240
command_types_tLgMRPqtm_values.add("1");
4241+
#endif // COMPILE_LG290P
41944242

4243+
#ifdef COMPILE_MOSAICX5
41954244
// mosaic-X5
41964245

41974246
JsonObject command_types_tMosaicConst = command_types.add<JsonObject>();
@@ -4278,7 +4327,9 @@ void createCommandTypesJson(String &output)
42784327
JsonArray command_types_tMosaicMEBaRT_values = command_types_tMosaicMEBaRT["values"].to<JsonArray>();
42794328
command_types_tMosaicMEBaRT_values.add("0");
42804329
command_types_tMosaicMEBaRT_values.add("1");
4330+
#endif // COMPILE_MOSAICX5
42814331

4332+
#ifdef COMPILE_UM980
42824333
// UM980
42834334

42844335
JsonObject command_types_tUmConst = command_types.add<JsonObject>();
@@ -4306,7 +4357,7 @@ void createCommandTypesJson(String &output)
43064357
command_types_tUmMRNmea["value max"] = 65.0;
43074358

43084359
JsonObject command_types_tUmMRBaRT = command_types.add<JsonObject>();
4309-
command_types_tUmMRBaRT["Name"] = "tUmMRBaRT";
4360+
command_types_tUmMRBaRT["name"] = "tUmMRBaRT";
43104361
command_types_tUmMRBaRT["description"] = "UM980 RTCM message rates - Base";
43114362
command_types_tUmMRBaRT["instruction"] = "Set the RTCM message interval in seconds for Base (0 = Off)";
43124363
command_types_tUmMRBaRT["prefix"] = "messageRateRTCMBase_";
@@ -4318,7 +4369,7 @@ void createCommandTypesJson(String &output)
43184369
command_types_tUmMRBaRT["value max"] = 65.0;
43194370

43204371
JsonObject command_types_tUmMRRvRT = command_types.add<JsonObject>();
4321-
command_types_tUmMRRvRT["Name"] = "tUmMRRvRT";
4372+
command_types_tUmMRRvRT["name"] = "tUmMRRvRT";
43224373
command_types_tUmMRRvRT["description"] = "UM980 RTCM message rates - Rover";
43234374
command_types_tUmMRRvRT["instruction"] = "Set the RTCM message interval in seconds for Rover (0 = Off)";
43244375
command_types_tUmMRRvRT["prefix"] = "messageRateRTCMRover_";
@@ -4328,12 +4379,52 @@ void createCommandTypesJson(String &output)
43284379
command_types_tUmMRRvRT["type"] = "float";
43294380
command_types_tUmMRRvRT["value min"] = 0.0;
43304381
command_types_tUmMRRvRT["value max"] = 65.0;
4382+
#endif // COMPILE_UM980
43314383

4332-
// JsonArray commands = doc["commands"].to<JsonArray>();
4333-
// commands.add("messageStreamNMEA_GGA,tMosaicMSNmea,1");
4334-
// commands.add("streamIntervalNMEA_2,tMosaicMSNmea,sec1");
4384+
#ifdef COMPILE_ZED
4385+
// ublox GNSS Receiver
4386+
4387+
JsonObject command_types_tUbxConst = command_types.add<JsonObject>();
4388+
command_types_tUbxConst["name"] = "tUbxConst";
4389+
command_types_tUbxConst["description"] = "ZED GNSS constellations";
4390+
command_types_tUbxConst["instruction"] = "Enable / disable each GNSS constellation";
4391+
command_types_tUbxConst["prefix"] = "constellation_";
4392+
JsonArray command_types_tUbxConst_keys = command_types_tUbxConst["keys"].to<JsonArray>();
4393+
for (int x = 0; x < MAX_UBX_CONSTELLATIONS; x++)
4394+
command_types_tUbxConst_keys.add(settings.ubxConstellations[x].textName);
4395+
JsonArray command_types_tUbxConst_values = command_types_tUbxConst["values"].to<JsonArray>();
4396+
command_types_tUbxConst_values.add("0");
4397+
command_types_tUbxConst_values.add("1");
4398+
4399+
JsonObject command_types_tUbxMsgRt = command_types.add<JsonObject>();
4400+
command_types_tUbxMsgRt["name"] = "tUbxMsgRt";
4401+
command_types_tUbxMsgRt["description"] = "ZED message rates - Rover";
4402+
command_types_tUbxMsgRt["instruction"] = "Set the message interval in navigation cycles for Rover (0 = Off)";
4403+
command_types_tUbxMsgRt["prefix"] = "ubxMessageRate_";
4404+
JsonArray command_types_tUbxMsgRt_keys = command_types_tUbxMsgRt["keys"].to<JsonArray>();
4405+
for (int x = 0; x < MAX_UBX_MSG; x++)
4406+
command_types_tUbxMsgRt_keys.add(ubxMessages[x].msgTextName);
4407+
command_types_tUbxMsgRt["type"] = "int";
4408+
command_types_tUbxMsgRt["value min"] = 0;
4409+
command_types_tUbxMsgRt["value max"] = 250; // Avoid 254!
4410+
4411+
JsonObject command_types_tUbMsgRtb = command_types.add<JsonObject>();
4412+
command_types_tUbMsgRtb["name"] = "tUbMsgRtb";
4413+
command_types_tUbMsgRtb["description"] = "ZED message rates - Base";
4414+
command_types_tUbMsgRtb["instruction"] = "Set the message interval in navigation cycles for Base (0 = Off)";
4415+
command_types_tUbMsgRtb["prefix"] = "ubxMessageRateBase_";
4416+
JsonArray command_types_tUbMsgRtb_keys = command_types_tUbMsgRtb["keys"].to<JsonArray>();
4417+
GNSS_ZED zed;
4418+
int firstRTCMRecord = zed.getMessageNumberByNameSkipChecks("RTCM_1005");
4419+
for (int x = 0; x < MAX_UBX_MSG_RTCM; x++)
4420+
command_types_tUbMsgRtb_keys.add(ubxMessages[firstRTCMRecord + x].msgTextName);
4421+
command_types_tUbMsgRtb["type"] = "int";
4422+
command_types_tUbMsgRtb["value min"] = 0;
4423+
command_types_tUbMsgRtb["value max"] = 250; // Avoid 254!
4424+
#endif // COMPILE_ZED
43354425

43364426
doc.shrinkToFit(); // optional
43374427

4338-
serializeJsonPretty(doc, output); // TODO - remove the Pretty formatting
4428+
//serializeJsonPretty(doc, output); // Pretty formatting - useful for testing
4429+
serializeJson(doc, output); // Standard JSON format
43394430
}

0 commit comments

Comments
 (0)