Skip to content

Commit b7ebc84

Browse files
authored
Merge pull request #672 from LeeLeahy2/network
Network: Add new routines
2 parents c66a4f9 + 09bf091 commit b7ebc84

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

Firmware/RTK_Everywhere/HTTP_Client.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ void httpClientUpdate()
356356
// Connect to the HTTP server
357357
case HTTP_CLIENT_CONNECTING_2_SERVER: {
358358
// Allocate the httpSecureClient structure
359+
networkUseDefaultInterface();
359360
httpSecureClient = new NetworkClientSecure();
360361
if (!httpSecureClient)
361362
{

Firmware/RTK_Everywhere/MQTT_Client.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ void mqttClientUpdate()
876876
// Connect to the MQTT broker
877877
case MQTT_CLIENT_CONNECTING_2_BROKER: {
878878
// Allocate the mqttSecureClient structure
879+
networkUseDefaultInterface();
879880
mqttSecureClient = new NetworkClientSecure();
880881
if (!mqttSecureClient)
881882
{

Firmware/RTK_Everywhere/Network.ino

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,37 @@ void networkInterfaceInternetConnectionAvailable(NetIndex_t index)
12691269
networkMulticastDNSStart(previousIndex);
12701270
}
12711271

1272+
/*
1273+
Network Loss Handling:
1274+
1275+
Arduino IP lost event
1276+
|
1277+
|
1278+
V
1279+
networkInterfaceEventInternetLost
1280+
|
1281+
| Set internet lost event flag
1282+
V
1283+
networkUpdate
1284+
|
1285+
| Clear internet lost event flag
1286+
V
1287+
+<------- Fake connection loss
1288+
|
1289+
V
1290+
networkInterfaceInternetConnectionLost
1291+
|
1292+
| Notify Interface of connection loss
1293+
V
1294+
.----------------+----------------.
1295+
| |
1296+
| |
1297+
V V
1298+
networkInterfaceRunning Interface stop sequence
1299+
called by xxxUpdate
1300+
or xxxEnabled
1301+
*/
1302+
12721303
//----------------------------------------
12731304
// Mark network interface as having NO access to the internet
12741305
//----------------------------------------
@@ -1377,6 +1408,35 @@ void networkInterfaceInternetConnectionLost(NetIndex_t index)
13771408
}
13781409
}
13791410

1411+
//----------------------------------------
1412+
// Get the interface priority
1413+
//----------------------------------------
1414+
NetPriority_t networkInterfacePriority(NetIndex_t index)
1415+
{
1416+
NetPriority_t priority;
1417+
1418+
// Validate the index
1419+
networkValidateIndex(index);
1420+
1421+
// Get the interface priority
1422+
priority = networkIndexTable[index];
1423+
return priority;
1424+
}
1425+
1426+
//----------------------------------------
1427+
// Determine if the interface should be running
1428+
//----------------------------------------
1429+
NetPriority_t networkInterfaceRunning(NetIndex_t index)
1430+
{
1431+
NetPriority_t priority;
1432+
1433+
// Get the interface priority
1434+
priority = networkInterfacePriority(index);
1435+
1436+
// Return the running status
1437+
return (networkPriority >= priority);
1438+
}
1439+
13801440
//----------------------------------------
13811441
// Determine if the specified network interface is higher priority than
13821442
// the current network interface
@@ -2434,6 +2494,25 @@ void networkUpdate()
24342494
}
24352495
}
24362496

2497+
//----------------------------------------
2498+
// Set the default network interface
2499+
//----------------------------------------
2500+
void networkUseDefaultInterface()
2501+
{
2502+
NetIndex_t index;
2503+
bool isDefault;
2504+
2505+
// Get the network index
2506+
index = networkGetCurrentInterfaceIndex();
2507+
if (index < NETWORK_OFFLINE)
2508+
{
2509+
// Get the default network interface
2510+
isDefault = networkInterfaceTable[index].netif->isDefault();
2511+
if (!isDefault)
2512+
networkInterfaceTable[index].netif->setDefault();
2513+
}
2514+
}
2515+
24372516
//----------------------------------------
24382517
// Add a network user
24392518
//----------------------------------------

Firmware/RTK_Everywhere/NtripClient.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ void ntripClientUpdate()
656656
if (connected)
657657
{
658658
// Allocate the ntripClient structure
659+
networkUseDefaultInterface();
659660
ntripClient = new NetworkClient();
660661
if (!ntripClient)
661662
{

Firmware/RTK_Everywhere/TcpClient.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ bool tcpClientStart()
306306
NetworkClient *client;
307307

308308
// Allocate the TCP client
309+
networkUseDefaultInterface();
309310
client = new NetworkClient();
310311
if (client)
311312
{

0 commit comments

Comments
 (0)