Skip to content

Commit 98705da

Browse files
committed
Merge branch 'release_candidate' into Fix_#362
2 parents 6b9bfe8 + fba06ff commit 98705da

22 files changed

+342
-189
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ void beginBoard()
324324

325325
// In the fullness of time, pin_Cellular_PWR_ON will (probably) be controlled by the Cellular Library
326326
DMW_if systemPrintf("pin_Cellular_PWR_ON: %d\r\n", pin_Cellular_PWR_ON);
327-
digitalWrite(pin_Cellular_PWR_ON, LOW);
328327
pinMode(pin_Cellular_PWR_ON, OUTPUT);
329328
digitalWrite(pin_Cellular_PWR_ON, LOW);
330329

@@ -483,6 +482,19 @@ void beginVersion()
483482
}
484483
}
485484

485+
void beginSPI(bool force) // Call after beginBoard
486+
{
487+
static bool started = false;
488+
489+
bool spiNeeded = present.ethernet_ws5500 || present.microSd;
490+
491+
if (force || (spiNeeded && !started))
492+
{
493+
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
494+
started = true;
495+
}
496+
}
497+
486498
void beginSD()
487499
{
488500
if (present.microSd == false)
@@ -624,7 +636,7 @@ void resetSPI()
624636
sdDeselectCard();
625637

626638
// Flush SPI interface
627-
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
639+
beginSPI(true);
628640
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
629641
for (int x = 0; x < 10; x++)
630642
SPI.transfer(0XFF);
@@ -634,7 +646,7 @@ void resetSPI()
634646
sdSelectCard();
635647

636648
// Flush SD interface
637-
SPI.begin(pin_SCK, pin_POCI, pin_PICO);
649+
beginSPI(true);
638650
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
639651
for (int x = 0; x < 10; x++)
640652
SPI.transfer(0XFF);

Firmware/RTK_Everywhere/Developer.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
void menuEthernet() {systemPrintln("**Ethernet not compiled**");}
1313
void ethernetBegin() {}
1414
IPAddress ethernetGetIpAddress() {return IPAddress((uint32_t)0);}
15+
IPAddress ethernetGetSubnetMask() {return IPAddress((uint32_t)0);}
1516
void ethernetUpdate() {}
1617
void ethernetVerifyTables() {}
1718

@@ -152,14 +153,17 @@ void discardTcpServerBytes(RING_BUFFER_OFFSET previousTail, RING_BUFFER_OFFSET n
152153

153154
void menuWiFi() {systemPrintln("**WiFi not compiled**");}
154155
bool wifiConnect(unsigned long timeout) {return false;}
156+
bool wifiConnect(unsigned long timeout, bool useAPSTAMode, bool *wasInAPmode) {return false;}
155157
IPAddress wifiGetGatewayIpAddress() {return IPAddress((uint32_t)0);}
156158
IPAddress wifiGetIpAddress() {return IPAddress((uint32_t)0);}
159+
IPAddress wifiGetSubnetMask() {return IPAddress((uint32_t)0);}
157160
int wifiGetRssi() {return -999;}
158161
String wifiGetSsid() {return "**WiFi Not compiled**";}
159162
bool wifiIsConnected() {return false;}
160163
bool wifiIsNeeded() {return false;}
161164
int wifiNetworkCount() {return 0;}
162165
void wifiPrintNetworkInfo() {}
166+
void wifiSetApMode() {}
163167
void wifiStart() {}
164168
void wifiStop() {}
165169
void wifiUpdate() {}

Firmware/RTK_Everywhere/Display.ino

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,17 +1470,12 @@ void displayBatteryVsEthernet(std::vector<iconPropertyBlinking> *iconList)
14701470
paintBatteryLevel(iconList);
14711471
else // if (present.ethernet_ws5500 == true)
14721472
{
1473-
if (online.ethernetStatus == ETH_NOT_STARTED)
1474-
return; // If Ethernet has not stated because not needed, don't display the icon
1473+
if (online.ethernetStatus != ETH_CONNECTED)
1474+
return; // Only display the Ethernet icon if we are successfully connected (no blinking)
14751475

14761476
iconPropertyBlinking prop;
14771477
prop.icon = EthernetIconProperties.iconDisplay[present.display_type];
1478-
1479-
if (online.ethernetStatus == ETH_CONNECTED)
1480-
prop.duty = 0b11111111;
1481-
else
1482-
prop.duty = 0b01010101;
1483-
1478+
prop.duty = 0b11111111;
14841479
iconList->push_back(prop);
14851480
}
14861481
}
@@ -2812,7 +2807,7 @@ void paintGettingKeys()
28122807

28132808
void paintGettingEthernetIP()
28142809
{
2815-
displayMessage("Getting IP", 0);
2810+
displayMessage("Getting IP", 1000);
28162811
}
28172812

28182813
// If an L-Band is indoors without reception, we have a ~2s wait for the RTC to come online

Firmware/RTK_Everywhere/Ethernet.ino

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ void menuEthernet()
3535
systemPrintln(settings.ethernetSubnet.toString().c_str());
3636
}
3737

38+
//------------------------------
39+
// Display the network layer menu items
40+
//------------------------------
41+
42+
systemPrint("d) Default network: ");
43+
networkPrintName(settings.defaultNetworkType);
44+
systemPrintln();
45+
46+
systemPrint("f) Ethernet / WiFi Failover: ");
47+
systemPrintf("%s\r\n", settings.enableNetworkFailover ? "Enabled" : "Disabled");
48+
3849
systemPrintln("x) Exit");
3950

4051
byte incoming = getUserInputCharacterNumber();
@@ -96,6 +107,24 @@ void menuEthernet()
96107
else
97108
systemPrint("Error: invalid Subnet Mask");
98109
}
110+
111+
//------------------------------
112+
// Get the network layer parameters
113+
//------------------------------
114+
115+
else if (incoming == 'd')
116+
{
117+
// Toggle the network type
118+
settings.defaultNetworkType += 1;
119+
if (settings.defaultNetworkType > NETWORK_TYPE_USE_DEFAULT)
120+
settings.defaultNetworkType = 0;
121+
}
122+
else if (incoming == 'f')
123+
{
124+
// Toggle failover support
125+
settings.enableNetworkFailover ^= 1;
126+
}
127+
99128
else if (incoming == 'x')
100129
break;
101130
else if (incoming == INPUT_RESPONSE_GETCHARACTERNUMBER_EMPTY)
@@ -133,6 +162,12 @@ IPAddress ethernetGetIpAddress()
133162
return ETH.localIP();
134163
}
135164

165+
// Return the subnet mask for the Ethernet controller
166+
IPAddress ethernetGetSubnetMask()
167+
{
168+
return ETH.subnetMask();
169+
}
170+
136171
// Determine if Ethernet is needed. Saves RAM...
137172
bool ethernetIsNeeded()
138173
{

Firmware/RTK_Everywhere/MQTT_Client.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ static int mqttClientConnectionAttemptsTotal; // Count the number of connection
122122

123123
static volatile uint32_t mqttClientLastDataReceived; // Last time data was received via MQTT
124124

125-
static NetworkSecureWiFiClient *mqttSecureClient;
125+
static char *mqttClientPrivateKeyBuffer; // Buffer for client private key
126+
127+
static RTKNetworkSecureClient *mqttSecureClient;
126128

127129
static volatile uint8_t mqttClientState = MQTT_CLIENT_OFF;
128130

@@ -554,7 +556,7 @@ void mqttClientUpdate()
554556
}
555557

556558
// Allocate the mqttSecureClient structure
557-
mqttSecureClient = new NetworkSecureWiFiClient();
559+
mqttSecureClient = new RTKNetworkSecureClient();
558560
if (!mqttSecureClient)
559561
{
560562
systemPrintln("ERROR: Failed to allocate the mqttSecureClient structure!");

Firmware/RTK_Everywhere/NVM.ino

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void recordSystemSettingsToFile(File *settingsFile)
346346
// Record constellation settings
347347
for (int x = 0; x < rtkSettingsEntries[i].qualifier; x++)
348348
{
349-
char tempString[50]; // ubxConstellation_BeiDou=1
349+
char tempString[50]; // constellation_BeiDou=1
350350
snprintf(tempString, sizeof(tempString), "%s%s=%d", rtkSettingsEntries[i].name,
351351
settings.ubxConstellations[x].textName, settings.ubxConstellations[x].enabled);
352352
settingsFile->println(tempString);
@@ -1424,6 +1424,20 @@ int8_t getProfileNumberFromUnit(uint8_t profileUnit)
14241424
return (-1);
14251425
}
14261426

1427+
// Returns the number of available profiles
1428+
// https://stackoverflow.com/questions/8871204/count-number-of-1s-in-binary-representation
1429+
uint8_t getProfileCount()
1430+
{
1431+
int count = 0;
1432+
uint8_t n = activeProfiles;
1433+
while (n != 0)
1434+
{
1435+
n = n & (n - 1);
1436+
count++;
1437+
}
1438+
return (count);
1439+
}
1440+
14271441
// Record large character blob to file
14281442
void recordFile(const char *fileID, char *fileContents, uint32_t fileSize)
14291443
{

Firmware/RTK_Everywhere/Network.ino

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,6 @@ void menuTcpUdp()
232232
if (settings.enableUdpServer)
233233
systemPrintf("7) UDP Server Port: %ld\r\n", settings.udpServerPort);
234234

235-
if (present.ethernet_ws5500 == true)
236-
{
237-
//------------------------------
238-
// Display the network layer menu items
239-
//------------------------------
240-
241-
systemPrint("d) Default network: ");
242-
networkPrintName(settings.defaultNetworkType);
243-
systemPrintln();
244-
245-
systemPrint("f) Ethernet / WiFi Failover: ");
246-
systemPrintf("%s\r\n", settings.enableNetworkFailover ? "Enabled" : "Disabled");
247-
}
248-
249235
//------------------------------
250236
// Finish the menu and get the input
251237
//------------------------------
@@ -317,23 +303,6 @@ void menuTcpUdp()
317303
getNewSetting("Enter the UDP port to use", 0, 65535, &settings.udpServerPort);
318304
}
319305

320-
//------------------------------
321-
// Get the network layer parameters
322-
//------------------------------
323-
324-
else if ((incoming == 'd') && (present.ethernet_ws5500 == true))
325-
{
326-
// Toggle the network type
327-
settings.defaultNetworkType += 1;
328-
if (settings.defaultNetworkType > NETWORK_TYPE_USE_DEFAULT)
329-
settings.defaultNetworkType = 0;
330-
}
331-
else if ((incoming == 'f') && (present.ethernet_ws5500 == true))
332-
{
333-
// Toggle failover support
334-
settings.enableNetworkFailover ^= 1;
335-
}
336-
337306
//------------------------------
338307
// Handle exit and invalid input
339308
//------------------------------
@@ -464,6 +433,23 @@ NETWORK_DATA *networkGet(uint8_t networkType, bool updateRequestedNetwork)
464433
return network;
465434
}
466435

436+
//----------------------------------------
437+
// Get the broadast IP address
438+
//----------------------------------------
439+
IPAddress networkGetBroadcastIpAddress(uint8_t networkType)
440+
{
441+
IPAddress ip;
442+
IPAddress mask;
443+
IPAddress temp;
444+
445+
// Get the local network address and subnet mask
446+
ip = networkGetIpAddress(networkType);
447+
mask = networkGetSubnetMask(networkType);
448+
449+
// Return the local network broadcast IP address
450+
return IPAddress((uint32_t)ip | (~(uint32_t)mask));
451+
}
452+
467453
//----------------------------------------
468454
// Get the IP address
469455
//----------------------------------------
@@ -476,6 +462,19 @@ IPAddress networkGetIpAddress(uint8_t networkType)
476462
return IPAddress((uint32_t)0);
477463
}
478464

465+
//----------------------------------------
466+
// Get the subnet mask
467+
//----------------------------------------
468+
IPAddress networkGetSubnetMask(uint8_t networkType)
469+
{
470+
// Determine the network address
471+
if (networkType == NETWORK_TYPE_ETHERNET)
472+
return ethernetGetSubnetMask();
473+
else if (networkType == NETWORK_TYPE_WIFI)
474+
return wifiGetSubnetMask();
475+
return IPAddress((uint32_t)0);
476+
}
477+
479478
//----------------------------------------
480479
// Get the network type
481480
//----------------------------------------

Firmware/RTK_Everywhere/RTKNetworkClient.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,21 @@ class RTKNetworkClientType : public RTKNetworkClient
259259
}
260260
};
261261

262-
#ifdef COMPILE_WIFI
263-
class NetworkSecureWiFiClient : public RTKNetworkClient
262+
class RTKNetworkSecureClient : public RTKNetworkClient
264263
{
265264
protected:
266265
NetworkClientSecure _client;
267266

268267
public:
269-
NetworkSecureWiFiClient() : _client{WiFiClientSecure()}, RTKNetworkClient(&_client, NETWORK_TYPE_WIFI)
268+
RTKNetworkSecureClient() : _client{NetworkClientSecure()}, RTKNetworkClient(&_client, NETWORK_TYPE_WIFI)
270269
{
271270
}
272271

273-
NetworkSecureWiFiClient(WiFiClient &client) : _client{client}, RTKNetworkClient(&_client, NETWORK_TYPE_WIFI)
272+
RTKNetworkSecureClient(NetworkClientSecure &client) : _client{client}, RTKNetworkClient(&_client, NETWORK_TYPE_WIFI)
274273
{
275274
}
276275

277-
~NetworkSecureWiFiClient()
276+
~RTKNetworkSecureClient()
278277
{
279278
this->~RTKNetworkClient();
280279
}
@@ -372,6 +371,4 @@ class NetworkSecureWiFiClient : public RTKNetworkClient
372371
}
373372
};
374373

375-
#endif // COMPILE_WIFI
376-
377374
#endif // __NETWORK_CLIENT_H__

0 commit comments

Comments
 (0)