Skip to content

Commit f6b9383

Browse files
committed
Add size of list response to the top of the list response.
1 parent df7d5c1 commit f6b9383

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

Firmware/RTK_Everywhere/Bluetooth.ino

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,6 @@ int bluetoothCommandAvailable()
283283
#endif // COMPILE_BT
284284
}
285285

286-
// Pass a command string to the BLE Serial interface
287-
void bluetoothSendCommand(char *rxData)
288-
{
289-
#ifdef COMPILE_BT
290-
// Direct output to Bluetooth Command
291-
PrintEndpoint originalPrintEndpoint = printEndpoint;
292-
293-
printEndpoint = PRINT_ENDPOINT_ALL;
294-
295-
systemPrint(rxData); // Send command output to BLE, SPP, and Serial
296-
printEndpoint = originalPrintEndpoint;
297-
298-
#else // COMPILE_BT
299-
systemPrint(rxData); // Send command output to Serial
300-
#endif // COMPILE_BT
301-
}
302-
303286
// Write data to the Bluetooth device
304287
int bluetoothWrite(const uint8_t *buffer, int length)
305288
{
@@ -407,12 +390,16 @@ void bluetoothFlush()
407390
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE)
408391
{
409392
bluetoothSerialBle->flush();
393+
bluetoothSerialBleCommands->flush(); // Complete any transfers
410394
bluetoothSerialSpp->flush();
411395
}
412396
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
413397
bluetoothSerialSpp->flush();
414398
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
399+
{
415400
bluetoothSerialBle->flush();
401+
bluetoothSerialBleCommands->flush(); // Complete any transfers
402+
}
416403
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE)
417404
bluetoothSerialSpp->flush(); // Needed? Not sure... TODO
418405
#else // COMPILE_BT

Firmware/RTK_Everywhere/menuCommands.ino

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,26 @@ t_cliResult processCommand(char *cmdBuffer)
267267
else if (strcmp(tokens[1], "LIST") == 0)
268268
{
269269
// Respond with a list of variables, types, and current value
270+
271+
// First calculate the size of the LIST response
272+
PrintEndpoint originalPrintEndpoint = printEndpoint;
273+
printEndpoint = PRINT_ENDPOINT_COUNT;
274+
systemWriteLength = 0;
275+
printAvailableSettings();
276+
printEndpoint = originalPrintEndpoint;
277+
278+
// Use log10 to find the number of digits in systemWriteLength
279+
int systemWriteLengthDigits = floor(log10(systemWriteLength)) + 1;
280+
281+
// Adjust systemWriteLength to include the length of the list entry
282+
systemWriteLength = systemWriteLength + sizeof("$SPLST,list,int,*2A") + systemWriteLengthDigits;
283+
284+
// Print the list entry
285+
char settingValue[6]; // 12345
286+
snprintf(settingValue, sizeof(settingValue), "%d", systemWriteLength);
287+
commandSendExecuteListResponse("list", "int", settingValue);
288+
289+
// Now actually print the list
270290
printAvailableSettings();
271291
commandSendExecuteOkResponse(tokens[0], tokens[1]);
272292
return (CLI_OK);
@@ -469,8 +489,22 @@ void commandSendResponse(const char *innerBuffer)
469489

470490
sprintf(responseBuffer, "$%s*%02X\r\n", innerBuffer, calculatedChecksum);
471491

472-
// CLI interactions may come from BLE or serial, respond to both interfaces
473-
bluetoothSendCommand(responseBuffer);
492+
// CLI interactions may come from BLE or serial, respond to all interfaces
493+
commandSendAllInterfaces(responseBuffer);
494+
}
495+
496+
// Pass a command string to the all interfaces
497+
void commandSendAllInterfaces(char *rxData)
498+
{
499+
// Direct output to Bluetooth Command
500+
PrintEndpoint originalPrintEndpoint = printEndpoint;
501+
502+
// Don't re-direct if we're doing a count of the print output
503+
if (printEndpoint != PRINT_ENDPOINT_COUNT)
504+
printEndpoint = PRINT_ENDPOINT_ALL;
505+
506+
systemPrint(rxData); // Send command output to BLE, SPP, and Serial
507+
printEndpoint = originalPrintEndpoint;
474508
}
475509

476510
// Checks structure of command and checksum
@@ -1506,7 +1540,7 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
15061540
}
15071541

15081542
// Check if this setting is read only
1509-
if(knownSetting == false)
1543+
if (knownSetting == false)
15101544
{
15111545
const char *table[] = {
15121546
"batteryLevelPercent",
@@ -1516,12 +1550,13 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
15161550
"deviceId",
15171551
"deviceName",
15181552
"gnssModuleInfo",
1553+
"list",
15191554
"rtkFirmwareVersion",
15201555
"rtkRemoteFirmwareVersion",
15211556
};
15221557
const int tableEntries = sizeof(table) / sizeof(table[0]);
15231558

1524-
if(commandCheckListForVariable(settingName, table, tableEntries))
1559+
if (commandCheckListForVariable(settingName, table, tableEntries))
15251560
return (SETTING_KNOWN_READ_ONLY);
15261561
}
15271562

@@ -3938,7 +3973,7 @@ void printAvailableSettings()
39383973
checkBatteryLevels();
39393974

39403975
// Convert int to string
3941-
char batteryLvlStr[4] = {0}; //104
3976+
char batteryLvlStr[4] = {0}; // 104
39423977
snprintf(batteryLvlStr, sizeof(batteryLvlStr), "%d", batteryLevelPercent);
39433978

39443979
// Create the settingType based on the length of the firmware version
@@ -3964,7 +3999,7 @@ void printAvailableSettings()
39643999
commandSendExecuteListResponse("batteryVoltage", settingType, batteryVoltageStr);
39654000
}
39664001

3967-
// Display the current battery charging percent per hour
4002+
// Display the current battery charging percent per hour
39684003
else if (commandIndex[i] == COMMAND_BATTERY_CHARGING_PERCENT)
39694004
{
39704005
checkBatteryLevels();
@@ -4010,5 +4045,4 @@ void printAvailableSettings()
40104045
commandSendExecuteListResponse("deviceId", settingType, printDeviceId());
40114046
}
40124047
}
4013-
systemPrintln();
40144048
}

0 commit comments

Comments
 (0)