Skip to content

Commit be76df6

Browse files
committed
Using table for check interval times instead of member variable
1 parent 80ab4d8 commit be76df6

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/Arduino_LoRaConnectionHandler.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@
2727
CONSTANTS
2828
******************************************************************************/
2929

30-
static const unsigned long NETWORK_CONNECTION_INTERVAL = 30000; /* NOT USED */
30+
static unsigned int const CHECK_INTERVAL_TABLE[] =
31+
{
32+
/* INIT */ 100,
33+
/* CONNECTING */ 500,
34+
/* CONNECTED */ 10000,
35+
/* GETTIME */ 100,
36+
/* DISCONNECTING */ 100,
37+
/* DISCONNECTED */ 1000,
38+
/* CLOSED */ 1000,
39+
/* ERROR */ 1000
40+
};
3141

3242
/******************************************************************************
3343
CTOR/DTOR
@@ -39,7 +49,6 @@ LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * a
3949
, _band(band)
4050
, _device_class(device_class)
4151
, _lastConnectionTickTime(millis())
42-
, _connectionTickTimeInterval(CHECK_INTERVAL_IDLE)
4352
, _keep_alive(false)
4453
{
4554

@@ -101,11 +110,14 @@ bool LoRaConnectionHandler::available() {
101110
NetworkConnectionState LoRaConnectionHandler::check() {
102111

103112
unsigned long const now = millis();
104-
int networkStatus = 0;
105-
if (now - _lastConnectionTickTime > _connectionTickTimeInterval) { /* time bracket */
113+
unsigned int const connectionTickTimeInterval = CHECK_INTERVAL_TABLE[static_cast<unsigned int>(netConnectionState)];
106114

115+
if((now - _lastConnectionTickTime) > connectionTickTimeInterval)
116+
{
107117
_lastConnectionTickTime = now;
108-
switch (netConnectionState) {
118+
119+
switch (netConnectionState)
120+
{
109121
case NetworkConnectionState::INIT: netConnectionState = update_handleInit(); break;
110122
case NetworkConnectionState::CONNECTING: netConnectionState = update_handleConnecting(); break;
111123
case NetworkConnectionState::CONNECTED: netConnectionState = update_handleConnected(); break;
@@ -148,7 +160,6 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() {
148160
_modem.configureClass(_device_class);
149161
delay(100);
150162
Debug.print(DBG_INFO, "Connecting to the network");
151-
_connectionTickTimeInterval = CHECK_INTERVAL_CONNECTING;
152163
return NetworkConnectionState::CONNECTING;
153164
}
154165

@@ -162,7 +173,6 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() {
162173
}
163174

164175
Debug.print(DBG_INFO, "Connected to the network");
165-
_connectionTickTimeInterval = CHECK_INTERVAL_CONNECTED;
166176
execCallback(NetworkConnectionEvent::CONNECTED, 0);
167177
return NetworkConnectionState::CONNECTED;
168178
}
@@ -178,7 +188,6 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() {
178188
if (_keep_alive) {
179189
Debug.print(DBG_ERROR, "Attempting reconnection");
180190
}
181-
_connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
182191
return NetworkConnectionState::DISCONNECTED;
183192
}
184193
Debug.print(DBG_VERBOSE, "Connected to the network");
@@ -193,20 +202,17 @@ NetworkConnectionState LoRaConnectionHandler::update_handleDisconnecting() {
193202
if (_keep_alive) {
194203
Debug.print(DBG_ERROR, "Attempting reconnection");
195204
}
196-
_connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
197205
return NetworkConnectionState::DISCONNECTED;
198206
}
199207

200208
NetworkConnectionState LoRaConnectionHandler::update_handleDisconnected() {
201209
if (_keep_alive) {
202210
Debug.print(DBG_VERBOSE, "CHANGING STATE TO ::INIT");
203-
_connectionTickTimeInterval = CHECK_INTERVAL_INIT;
204211
return NetworkConnectionState::INIT;
205212
} else {
206213
Debug.print(DBG_VERBOSE, "Connection to the network terminated");
207214
return NetworkConnectionState::CLOSED;
208215
}
209-
210216
}
211217

212218
#endif

src/Arduino_LoRaConnectionHandler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class LoRaConnectionHandler : public ConnectionHandler {
6969
_lora_band _band;
7070
_lora_class _device_class;
7171
unsigned long _lastConnectionTickTime;
72-
int _connectionTickTimeInterval;
7372
bool _keep_alive;
7473
LoRaModem _modem;
7574

src/Arduino_WiFiConnectionHandler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
#ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */
2525

26+
/******************************************************************************
27+
CONSTANTS
28+
******************************************************************************/
29+
2630
static unsigned int const CHECK_INTERVAL_TABLE[] =
2731
{
2832
/* INIT */ 100,

0 commit comments

Comments
 (0)