Skip to content

Commit 4767daa

Browse files
authored
Merge pull request #728 from sparkfun/pcUpdates
Add support for External Accessory VTG, GSA and GSV
2 parents a5aabfc + f977f88 commit 4767daa

File tree

10 files changed

+92
-25
lines changed

10 files changed

+92
-25
lines changed

.github/workflows/compile-rtk-everywhere.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
"SdFat"@2.1.1
8787
"SparkFun LIS2DH12 Arduino Library"@1.0.3
8888
"SparkFun MAX1704x Fuel Gauge Arduino Library"@1.0.4
89-
"SparkFun u-blox GNSS v3"@3.1.8
89+
"SparkFun u-blox GNSS v3"@3.1.10
9090
"SparkFun Qwiic OLED Arduino Library"@1.0.13
9191
9292
"SparkFun Extensible Message Parser"@1.0.4
@@ -97,7 +97,7 @@ jobs:
9797
"SparkFun UM980 Triband RTK GNSS Arduino Library"@1.0.5
9898
"SparkFun LG290P Quadband RTK GNSS Arduino Library"@1.0.8
9999
"SparkFun I2C Expander Arduino Library"@1.0.1
100-
"SparkFun Apple Accessory Arduino Library"@1.0.1
100+
"SparkFun Apple Accessory Arduino Library"@3.0.7.1
101101
"SparkFun Authentication Coprocessor Arduino Library"@1.0.0
102102
"SparkFun Toolkit"@1.0.6
103103

.github/workflows/non-release-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
"SdFat"@2.1.1
8787
"SparkFun LIS2DH12 Arduino Library"@1.0.3
8888
"SparkFun MAX1704x Fuel Gauge Arduino Library"@1.0.4
89-
"SparkFun u-blox GNSS v3"@3.1.8
89+
"SparkFun u-blox GNSS v3"@3.1.10
9090
"SparkFun Qwiic OLED Arduino Library"@1.0.13
9191
9292
"SparkFun Extensible Message Parser"@1.0.4
@@ -97,7 +97,7 @@ jobs:
9797
"SparkFun UM980 Triband RTK GNSS Arduino Library"@1.0.5
9898
"SparkFun LG290P Quadband RTK GNSS Arduino Library"@1.0.8
9999
"SparkFun I2C Expander Arduino Library"@1.0.1
100-
"SparkFun Apple Accessory Arduino Library"@1.0.1
100+
"SparkFun Apple Accessory Arduino Library"@3.0.7.1
101101
"SparkFun Authentication Coprocessor Arduino Library"@1.0.0
102102
"SparkFun Toolkit"@1.0.6
103103

Firmware/RTK_Everywhere/AuthCoPro.ino

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ void beginAuthCoPro(TwoWire *i2cBus)
5555
latestGPGGA = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
5656
latestGPRMC = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
5757
latestGPGST = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
58-
appleAccessory->setNMEApointers(latestGPGGA, latestGPRMC, latestGPGST);
58+
latestGPVTG = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
59+
appleAccessory->setNMEApointers(latestGPGGA, latestGPRMC, latestGPGST, latestGPVTG);
60+
61+
// Pass the pointer for additional GSA / GSV EA Session data
62+
latestEASessionData = (char *)rtkMalloc(latestEASessionDataMaxLen, "AuthCoPro");
63+
appleAccessory->setEASessionPointer(latestEASessionData);
5964

6065
// Pass the transport connected and disconnect methods into the accessory driver
6166
appleAccessory->setTransportConnectedMethod(&transportConnected);
@@ -89,7 +94,9 @@ void updateAuthCoPro()
8994
appleAccessory->update(); // Update the Accessory driver
9095

9196
// Check for a new device connection
92-
if (bluetoothSerialSpp->aclConnected() == true && bluetoothSerialSpp->connected() == false)
97+
// Note: aclConnected is a one-shot
98+
// The internal flag is automatically cleared when aclConnected returns true
99+
if (bluetoothSerialSpp->aclConnected() == true)
93100
{
94101
// //
95102
// https://github.com/espressif/arduino-esp32/blob/master/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino

Firmware/RTK_Everywhere/Bluetooth.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ void bluetoothStart()
528528
memcpy(record.uuid.uuid.uuid128, UUID_IAP2, sizeof(UUID_IAP2));
529529
record.service_name_length = strlen(sdp_service_name) + 1;
530530
record.service_name = (char *)sdp_service_name;
531+
//record.service_name_length = strlen(deviceName) + 1; // Doesn't seem to help the failed connects
532+
//record.service_name = (char *)deviceName;
533+
//record.rfcomm_channel_number = 1; // Doesn't seem to help the failed connects
531534
esp_sdp_create_record((esp_bluetooth_sdp_record_t *)&record);
532535
}
533536
}

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,9 @@ const size_t latestNmeaMaxLen = 100;
825825
char *latestGPGGA;
826826
char *latestGPRMC;
827827
char *latestGPGST;
828+
char *latestGPVTG;
829+
const size_t latestEASessionDataMaxLen = 4001; // 1000 * 4 plus NULL
830+
char *latestEASessionData;
828831

829832
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
830833

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,56 @@ void processUart1Message(SEMP_PARSE_STATE *parse, uint16_t type)
813813
else
814814
systemPrintf("Increase latestNmeaMaxLen to > %d\r\n", parse->length);
815815
}
816+
else if (strstr(sempNmeaGetSentenceName(parse), "VTG") != nullptr)
817+
{
818+
if (parse->length < latestNmeaMaxLen)
819+
{
820+
memcpy(latestGPVTG, parse->buffer, parse->length);
821+
latestGPVTG[parse->length] = 0; // NULL terminate
822+
if ((strlen(latestGPVTG) > 10) && (latestGPVTG[strlen(latestGPVTG) - 2] == '\r'))
823+
latestGPVTG[strlen(latestGPVTG) - 2] = 0; // Truncate the \r\n
824+
forceTalkerId("P",latestGPVTG,latestNmeaMaxLen);
825+
}
826+
else
827+
systemPrintf("Increase latestNmeaMaxLen to > %d\r\n", parse->length);
828+
}
829+
else if ((strstr(sempNmeaGetSentenceName(parse), "GSA") != nullptr)
830+
|| (strstr(sempNmeaGetSentenceName(parse), "GSV") != nullptr))
831+
{
832+
// If the Apple Accessory is sending the data to the EA Session,
833+
// discard this GSA / GSV. Bad things would happen if we were to
834+
// manipulate latestEASessionData while appleAccessory is using it.
835+
if (appleAccessory->latestEASessionDataIsBlocking() == false)
836+
{
837+
size_t spaceAvailable = latestEASessionDataMaxLen - strlen(latestEASessionData);
838+
if (spaceAvailable >= 3)
839+
spaceAvailable -= 3; // Leave room for the CR, LF and NULL
840+
while (spaceAvailable < parse->length) // If the buffer is full, delete the oldest message(s)
841+
{
842+
const char *lfPtr = strstr(latestEASessionData, "\n"); // Find the first LF
843+
if (lfPtr == nullptr)
844+
break; // Something has gone badly wrong...
845+
lfPtr++; // Point at the byte after the LF
846+
size_t oldLen = lfPtr - latestEASessionData; // This much data is old
847+
size_t newLen = strlen(latestEASessionData) - oldLen; // This much is new (not old)
848+
for (size_t i = 0; i <= newLen; i++) // Move the new data over the old. Include the NULL
849+
latestEASessionData[i] = latestEASessionData[oldLen + i];
850+
spaceAvailable += oldLen;
851+
}
852+
size_t dataLen = strlen(latestEASessionData);
853+
memcpy(&latestEASessionData[dataLen], parse->buffer, parse->length); // Add the new NMEA data
854+
dataLen += parse->length;
855+
latestEASessionData[dataLen] = 0; // NULL terminate
856+
if (latestEASessionData[dataLen - 1] != '\n')
857+
{
858+
latestEASessionData[dataLen] = '\r'; // Add CR
859+
latestEASessionData[dataLen + 1] = '\n'; // Add LF
860+
latestEASessionData[dataLen + 2] = 0; // NULL terminate
861+
}
862+
}
863+
else if (settings.debugNetworkLayer)
864+
systemPrintf("Discarding %d GSA/GSV bytes - latestEASessionDataIsBlocking\r\n", parse->length);
865+
}
816866
}
817867

818868
// Determine if this message should be processed by the Unicore library

Firmware/RTK_Everywhere/WebServer.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,8 @@ bool webServerAssignResources(int httpPort = 80)
820820
/* https://github.com/espressif/arduino-esp32/blob/master/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino
821821
*/
822822

823+
// Note: MDNS should probably be begun by networkMulticastDNSUpdate, but that doesn't seem to be happening...
824+
// Is the networkInterface aware that AP needs it? Let's start it manually...
823825
if (MDNS.begin(&settings.mdnsHostName[0]) == false)
824826
{
825827
systemPrintln("Error setting up MDNS responder!");

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,9 +1283,10 @@ void wifiVerifyTables()
12831283
// Constructor
12841284
// Inputs:
12851285
// verbose: Set to true to display additional WiFi debug data
1286+
// For AP on RTK Firmware, we set the Gateway to 192.168.4.1, not 0.0.0.0. Let's do the same here.
12861287
RTK_WIFI::RTK_WIFI(bool verbose)
12871288
: _apChannel{0}, _apCount{0}, _apDnsAddress{IPAddress((uint32_t)0)}, _apFirstDhcpAddress{IPAddress("192.168.4.32")},
1288-
_apGatewayAddress{(uint32_t)0}, _apIpAddress{IPAddress("192.168.4.1")}, _apMacAddress{0, 0, 0, 0, 0, 0},
1289+
_apGatewayAddress{IPAddress("192.168.4.1")}, _apIpAddress{IPAddress("192.168.4.1")}, _apMacAddress{0, 0, 0, 0, 0, 0},
12891290
_apSubnetMask{IPAddress("255.255.255.0")}, _espNowChannel{0}, _scanRunning{false},
12901291
_staIpAddress{IPAddress((uint32_t)0)}, _staIpType{0}, _staMacAddress{0, 0, 0, 0, 0, 0}, _staRemoteApSsid{nullptr},
12911292
_staRemoteApPassword{nullptr}, _started{false}, _stationChannel{0}, _usingDefaultChannel{true}, _verbose{verbose}
@@ -2715,7 +2716,8 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
27152716
}
27162717

27172718
// Stop the DNS server
2718-
if (stopping & _started & WIFI_AP_START_DNS_SERVER)
2719+
// if (stopping & _started & WIFI_AP_START_DNS_SERVER) ???
2720+
if (stopping & WIFI_AP_START_DNS_SERVER)
27192721
{
27202722
if (settings.debugWifiState && _verbose)
27212723
systemPrintf("Calling dnsServer.stop for soft AP\r\n");
@@ -2858,8 +2860,8 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
28582860
// Finish the channel selection
28592861
if (starting & WIFI_SELECT_CHANNEL)
28602862
{
2861-
_started = _started | starting & WIFI_SELECT_CHANNEL;
2862-
if (channel & (starting & WIFI_STA_START_SCAN))
2863+
_started = _started | (starting & WIFI_SELECT_CHANNEL);
2864+
if (channel && (starting & WIFI_STA_START_SCAN))
28632865
{
28642866
if (settings.debugWifiState && _verbose)
28652867
systemPrintf("Channel: %d, determined by remote AP scan\r\n", channel);
@@ -2882,12 +2884,12 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
28822884
// Set the soft AP subnet mask, IP, gateway, DNS, and first DHCP addresses
28832885
if (starting & WIFI_AP_SET_IP_ADDR)
28842886
{
2885-
// if (!softApSetIpAddress(_apIpAddress.toString().c_str(), _apSubnetMask.toString().c_str(),
2886-
// _apGatewayAddress.toString().c_str(), _apDnsAddress.toString().c_str(),
2887-
// _apFirstDhcpAddress.toString().c_str()))
2888-
// {
2889-
// break;
2890-
// }
2887+
if (!softApSetIpAddress(_apIpAddress.toString().c_str(), _apSubnetMask.toString().c_str(),
2888+
_apGatewayAddress.toString().c_str(), _apDnsAddress.toString().c_str(),
2889+
_apFirstDhcpAddress.toString().c_str()))
2890+
{
2891+
break;
2892+
}
28912893
_started = _started | WIFI_AP_SET_IP_ADDR;
28922894
}
28932895

Firmware/RTK_Everywhere/src/BluetoothSerial/BluetoothSerial.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,6 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
381381
log_e("ESP_SPP_CLOSE_EVT failed!, status:%d", param->close.status);
382382
}
383383

384-
//The ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT event can take awhile. Mark ACL disconnected here as well.
385-
memset(_aclAddress, 0, ESP_BD_ADDR_LEN);
386-
_aclConnected = false;
387-
388384
break;
389385

390386
case ESP_SPP_START_EVT: // Enum 28 - When SPP server started
@@ -749,9 +745,6 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
749745
case ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT: // Enum 17 - ACL disconnection complete status event
750746
log_i("ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT ACL disconnection complete status event: reason %d, handle %d",
751747
param->acl_disconn_cmpl_stat.reason, param->acl_disconn_cmpl_stat.handle);
752-
753-
memset(_aclAddress, 0, ESP_BD_ADDR_LEN);
754-
_aclConnected = false;
755748
break;
756749

757750
#if false
@@ -1719,9 +1712,16 @@ void BluetoothSerial::deleteAllBondedDevices()
17191712
}
17201713
}
17211714

1715+
// aclConnected() is a one-shot. __aclConnected is cleared when returning true
17221716
bool BluetoothSerial::aclConnected()
17231717
{
1724-
return (_aclConnected);
1718+
if (_aclConnected)
1719+
{
1720+
_aclConnected = false;
1721+
return true;
1722+
}
1723+
1724+
return false;
17251725
}
17261726

17271727
uint8_t *BluetoothSerial::aclGetAddress()

Firmware/RTK_Everywhere/src/BluetoothSerial/BluetoothSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class BluetoothSerial : public Stream {
114114
bool deleteBondedDevice(uint8_t *remoteAddress);
115115
void deleteAllBondedDevices();
116116

117-
bool aclConnected();
117+
bool aclConnected(); // One-shot
118118
uint8_t *aclGetAddress();
119119

120120
private:

0 commit comments

Comments
 (0)