Skip to content

Commit 00413d3

Browse files
committed
Merge branch 'release_candidate' into nsUpdates
2 parents 470e38b + 8889cc7 commit 00413d3

File tree

7 files changed

+110
-34
lines changed

7 files changed

+110
-34
lines changed

Firmware/RTK_Everywhere/Bluetooth.ino

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
static volatile BTState bluetoothState = BT_OFF;
3131

3232
#ifdef COMPILE_BT
33+
34+
#include <BleBatteryService.h>
35+
3336
BTSerialInterface *bluetoothSerialSpp;
3437
BTSerialInterface *bluetoothSerialBle;
3538
BTSerialInterface *bluetoothSerialBleCommands; // Second BLE serial for CLI interface to mobile app
39+
BleBatteryService bluetoothBatteryService;
3640

3741
#define BLE_SERVICE_UUID "6e400001-b5a3-f393-e0a9-e50e24dcca9e"
3842
#define BLE_RX_UUID "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
@@ -283,23 +287,6 @@ int bluetoothCommandAvailable()
283287
#endif // COMPILE_BT
284288
}
285289

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-
303290
// Write data to the Bluetooth device
304291
int bluetoothWrite(const uint8_t *buffer, int length)
305292
{
@@ -407,12 +394,16 @@ void bluetoothFlush()
407394
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE)
408395
{
409396
bluetoothSerialBle->flush();
397+
bluetoothSerialBleCommands->flush(); // Complete any transfers
410398
bluetoothSerialSpp->flush();
411399
}
412400
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
413401
bluetoothSerialSpp->flush();
414402
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
403+
{
415404
bluetoothSerialBle->flush();
405+
bluetoothSerialBleCommands->flush(); // Complete any transfers
406+
}
416407
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE)
417408
bluetoothSerialSpp->flush(); // Needed? Not sure... TODO
418409
#else // COMPILE_BT
@@ -516,6 +507,7 @@ void bluetoothStart()
516507
deviceName, false, false, settings.sppRxQueueSize, settings.sppTxQueueSize, BLE_COMMAND_SERVICE_UUID,
517508
BLE_COMMAND_RX_UUID, BLE_COMMAND_TX_UUID); // localName, isMaster, disableBLE, rxBufferSize,
518509
// txBufferSize, serviceID, rxID, txID
510+
bluetoothBatteryService.begin();
519511
}
520512
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
521513
{
@@ -535,7 +527,9 @@ void bluetoothStart()
535527
beginSuccess &= bluetoothSerialBleCommands->begin(
536528
deviceName, false, false, settings.sppRxQueueSize, settings.sppTxQueueSize, BLE_COMMAND_SERVICE_UUID,
537529
BLE_COMMAND_RX_UUID, BLE_COMMAND_TX_UUID); // localName, isMaster, disableBLE, rxBufferSize,
538-
// txBufferSize, serviceID, rxID, txID
530+
// txBufferSize, serviceID, rxID, txID
531+
532+
bluetoothBatteryService.begin();
539533
}
540534
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE)
541535
{
@@ -763,3 +757,11 @@ void bluetoothPrintStatus()
763757

764758
systemPrintln();
765759
}
760+
761+
// Send over dedicated BLE service
762+
void bluetoothSendBatteryPercent(int batteryLevelPercent)
763+
{
764+
#ifdef COMPILE_BT
765+
bluetoothBatteryService.reportBatteryPercent(batteryLevelPercent);
766+
#endif // COMPILE_BT
767+
}

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
// While we wait for the next hardware revisions, Flex and Torch can be manually enabled:
8282
//#define FLEX_OVERRIDE // Uncomment to force support for Flex
83-
#define TORCH_X2_OVERRIDE // Uncomment to force support for Torch X2
83+
//#define TORCH_X2_OVERRIDE // Uncomment to force support for Torch X2
8484

8585
// To reduce compile times, various parts of the firmware can be disabled/removed if they are not
8686
// needed during development
@@ -812,7 +812,10 @@ SparkFunAppleAccessoryDriver *appleAccessory; // Instantiated by beginAuthCoPro
812812

813813
const char *sdp_service_name = "iAP2";
814814

815+
// UUID: Big-Endian
815816
static const uint8_t UUID_IAP2[] = {0x00, 0x00, 0x00, 0x00, 0xDE, 0xCA, 0xFA, 0xDE, 0xDE, 0xCA, 0xDE, 0xAF, 0xDE, 0xCA, 0xCA, 0xFF};
817+
// UUID: Little-Endian
818+
//static const uint8_t UUID_IAP2[] = {0xFF, 0xCA, 0xCA, 0xDE, 0xAF, 0xDE, 0xCA, 0xDE, 0xDE, 0xFA, 0xCA, 0xDE, 0x00, 0x00, 0x00, 0x00};
816819

817820
#endif
818821

Firmware/RTK_Everywhere/System.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ void updateBattery()
156156

157157
checkBatteryLevels();
158158

159+
bluetoothSendBatteryPercent(batteryLevelPercent); // Send over dedicated BLE service
160+
159161
// Display the battery data
160162
if (settings.enablePrintBatteryMessages)
161163
{
@@ -951,7 +953,7 @@ void gpioExpanderSelectImu()
951953
gpioExpanderSwitches->digitalWrite(gpioExpanderSwitch_S3, LOW);
952954
}
953955

954-
//Connect ESP32 UART2 to LoRa UART2 for configuration and bootloading/firmware updates
956+
// Connect ESP32 UART2 to LoRa UART2 for configuration and bootloading/firmware updates
955957
void gpioExpanderSelectLoraConfigure()
956958
{
957959
if (online.gpioExpanderSwitches == true)
@@ -990,7 +992,7 @@ bool gpioExpanderLoraIsOn()
990992
if (gpioExpanderSwitches->digitalRead(gpioExpanderSwitch_LoraEnable) == HIGH)
991993
return (true);
992994
}
993-
return(false);
995+
return (false);
994996
}
995997
void gpioExpanderLoraBootEnable()
996998
{

Firmware/RTK_Everywhere/form.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// python main_js_zipper.py
2727

2828
static const uint8_t main_js[] PROGMEM = {
29-
0x1F, 0x8B, 0x08, 0x08, 0xA3, 0x68, 0xCC, 0x68, 0x02, 0xFF, 0x6D, 0x61, 0x69, 0x6E, 0x2E, 0x6A,
29+
0x1F, 0x8B, 0x08, 0x08, 0x68, 0xCF, 0xD6, 0x68, 0x02, 0xFF, 0x6D, 0x61, 0x69, 0x6E, 0x2E, 0x6A,
3030
0x73, 0x2E, 0x67, 0x7A, 0x69, 0x70, 0x00, 0xED, 0x7D, 0x7B, 0x5F, 0xDB, 0x48, 0xB2, 0xE8, 0xFF,
3131
0xF9, 0x14, 0xBD, 0xBE, 0x7B, 0xC7, 0x66, 0x31, 0x46, 0x36, 0x8F, 0x40, 0x08, 0x39, 0x97, 0x00,
3232
0x49, 0xB8, 0xCB, 0xEB, 0x62, 0x32, 0x33, 0x99, 0x6C, 0x0E, 0x47, 0x58, 0xC2, 0xE8, 0xC4, 0x96,
@@ -1082,7 +1082,7 @@ static const uint8_t main_js[] PROGMEM = {
10821082
// python index_html_zipper.py
10831083

10841084
static const uint8_t index_html[] PROGMEM = {
1085-
0x1F, 0x8B, 0x08, 0x08, 0xA3, 0x68, 0xCC, 0x68, 0x02, 0xFF, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x2E,
1085+
0x1F, 0x8B, 0x08, 0x08, 0x68, 0xCF, 0xD6, 0x68, 0x02, 0xFF, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x2E,
10861086
0x68, 0x74, 0x6D, 0x6C, 0x2E, 0x67, 0x7A, 0x69, 0x70, 0x00, 0xED, 0x7D, 0x59, 0x76, 0xDB, 0xCA,
10871087
0x92, 0xE0, 0xFF, 0x5D, 0x45, 0x16, 0xAB, 0xBB, 0x2C, 0x57, 0x8B, 0x14, 0x48, 0x4A, 0xB2, 0xAC,
10881088
0x67, 0xEB, 0x1C, 0x6A, 0xB0, 0xAD, 0x7E, 0xB2, 0xCC, 0x12, 0xE5, 0x77, 0x87, 0x3E, 0xDD, 0xF7,

Firmware/RTK_Everywhere/menuCommands.ino

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
char otaOutcome[21] = {0}; // Modified by otaUpdate(), used to respond to rtkRemoteFirmwareVersion commands
2+
int systemWriteLength = 0; // Modified by systemWrite(), used to calculate the size of LIST command for CLI
23

34
void menuCommands()
45
{
@@ -266,6 +267,26 @@ t_cliResult processCommand(char *cmdBuffer)
266267
else if (strcmp(tokens[1], "LIST") == 0)
267268
{
268269
// 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
269290
printAvailableSettings();
270291
commandSendExecuteOkResponse(tokens[0], tokens[1]);
271292
return (CLI_OK);
@@ -468,8 +489,22 @@ void commandSendResponse(const char *innerBuffer)
468489

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

471-
// CLI interactions may come from BLE or serial, respond to both interfaces
472-
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;
473508
}
474509

475510
// Checks structure of command and checksum
@@ -559,8 +594,8 @@ int commandLookupSettingNameSelective(bool inCommands, const char *settingName,
559594
prioritySettingsEnd = findEndOfPrioritySettings();
560595
// If "endOfPrioritySettings" is not found, prioritySettingsEnd will be zero
561596

562-
// Remove one because while rtkSettingsEntries[] contains detectedGnssReceiver, the command table does not
563-
prioritySettingsEnd--;
597+
// Adjust prioritySettingsEnd if needed - depending on platform type
598+
prioritySettingsEnd = adjustEndOfPrioritySettings(prioritySettingsEnd);
564599

565600
// Loop through the valid command entries - starting at prioritySettingsEnd
566601
for (int i = prioritySettingsEnd; i < commandCount; i++)
@@ -1505,7 +1540,7 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
15051540
}
15061541

15071542
// Check if this setting is read only
1508-
if(knownSetting == false)
1543+
if (knownSetting == false)
15091544
{
15101545
const char *table[] = {
15111546
"batteryLevelPercent",
@@ -1515,12 +1550,13 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
15151550
"deviceId",
15161551
"deviceName",
15171552
"gnssModuleInfo",
1553+
"list",
15181554
"rtkFirmwareVersion",
15191555
"rtkRemoteFirmwareVersion",
15201556
};
15211557
const int tableEntries = sizeof(table) / sizeof(table[0]);
15221558

1523-
if(commandCheckListForVariable(settingName, table, tableEntries))
1559+
if (commandCheckListForVariable(settingName, table, tableEntries))
15241560
return (SETTING_KNOWN_READ_ONLY);
15251561
}
15261562

@@ -3747,6 +3783,25 @@ int findEndOfPrioritySettings()
37473783
return prioritySettingsEnd;
37483784
}
37493785

3786+
int adjustEndOfPrioritySettings(int prioritySettingsEnd)
3787+
{
3788+
// If prioritySettingsEnd is zero, don't adjust
3789+
if (prioritySettingsEnd == 0)
3790+
return 0;
3791+
3792+
int adjustedPrioritySettingsEnd = prioritySettingsEnd;
3793+
3794+
// Check which of the priority settings are possible on this platform
3795+
// Deduct the ones which are not
3796+
for (int i = 0; i < prioritySettingsEnd; i++)
3797+
{
3798+
if (!settingPossibleOnPlatform(i))
3799+
adjustedPrioritySettingsEnd--;
3800+
}
3801+
3802+
return adjustedPrioritySettingsEnd;
3803+
}
3804+
37503805
// Allocate and fill the commandIndex table
37513806
bool commandIndexFillPossible()
37523807
{
@@ -3824,6 +3879,9 @@ bool commandIndexFill(bool usePossibleSettings)
38243879
// If "endOfPrioritySettings" is not found, prioritySettingsEnd will be zero
38253880
// and all settings will be sorted. Just like the good old days...
38263881

3882+
// Adjust prioritySettingsEnd if needed - depending on platform type
3883+
prioritySettingsEnd = adjustEndOfPrioritySettings(prioritySettingsEnd);
3884+
38273885
if (settings.debugSettings || settings.debugCLI)
38283886
{
38293887
systemPrintf("commandCount %d\r\n", commandCount);
@@ -3937,7 +3995,7 @@ void printAvailableSettings()
39373995
checkBatteryLevels();
39383996

39393997
// Convert int to string
3940-
char batteryLvlStr[4] = {0}; //104
3998+
char batteryLvlStr[4] = {0}; // 104
39413999
snprintf(batteryLvlStr, sizeof(batteryLvlStr), "%d", batteryLevelPercent);
39424000

39434001
// Create the settingType based on the length of the firmware version
@@ -3963,7 +4021,7 @@ void printAvailableSettings()
39634021
commandSendExecuteListResponse("batteryVoltage", settingType, batteryVoltageStr);
39644022
}
39654023

3966-
// Display the current battery charging percent per hour
4024+
// Display the current battery charging percent per hour
39674025
else if (commandIndex[i] == COMMAND_BATTERY_CHARGING_PERCENT)
39684026
{
39694027
checkBatteryLevels();
@@ -4009,5 +4067,4 @@ void printAvailableSettings()
40094067
commandSendExecuteListResponse("deviceId", settingType, printDeviceId());
40104068
}
40114069
}
4012-
systemPrintln();
40134070
}

Firmware/RTK_Everywhere/settings.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ typedef enum
478478
PRINT_ENDPOINT_BLUETOOTH,
479479
PRINT_ENDPOINT_BLUETOOTH_COMMAND,
480480
PRINT_ENDPOINT_ALL,
481+
PRINT_ENDPOINT_COUNT,
481482
} PrintEndpoint;
482483
PrintEndpoint printEndpoint = PRINT_ENDPOINT_SERIAL; // Controls where the configuration menu gets piped to
483484

@@ -1259,7 +1260,12 @@ const RTK_Settings_Entry rtkSettingsEntries[] =
12591260
// i d i v V i c n r e X
12601261
// g s x k 2 c h d d x 2 Type Qual Variable Name
12611262

1262-
// Detected GNSS Receiver - for Flex. Save / load first so settingAvailableOnPlatform is correct on Flex
1263+
1264+
// =======================================================================================================
1265+
// Priority Settings which are not alphabetized in commandIndex
1266+
// =======================================================================================================
1267+
1268+
// Detected GNSS Receiver - only for Flex. Save / load first so settingAvailableOnPlatform is correct on Flex
12631269
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, ALL, 0, tGnssReceiver, 0, & settings.detectedGnssReceiver, "detectedGnssReceiver", },
12641270

12651271
// Common settings which use the same name on multiple Flex platforms
@@ -1280,6 +1286,7 @@ const RTK_Settings_Entry rtkSettingsEntries[] =
12801286

12811287
// <--- Insert any new essential "priority" (non-sorted) settings above this line --->
12821288

1289+
// endOfPrioritySettings is a special 'null' entry which does not appear in commandIndex
12831290
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, NON, 0, _bool, 0, nullptr, "endOfPrioritySettings", },
12841291

12851292
// =======================================================================================================

Firmware/RTK_Everywhere/support.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ void systemWrite(const uint8_t *buffer, uint16_t length)
6060
{
6161
bluetoothCommandWrite(buffer, length);
6262
}
63+
64+
// We're just adding up the size of the list, don't pass along to serial port
65+
else if (printEndpoint == PRINT_ENDPOINT_COUNT)
66+
{
67+
systemWriteLength += length;
68+
}
6369
}
6470

6571
// Forward GNSS data to the USB serial port
@@ -1202,4 +1208,3 @@ void WeekToWToUnixEpoch(uint64_t *unixEpoch, uint16_t GPSWeek, uint32_t GPSToW)
12021208
*unixEpoch += GPSToW; // 518400
12031209
*unixEpoch += 315964800;
12041210
}
1205-

0 commit comments

Comments
 (0)