Skip to content

Commit 1419ec3

Browse files
committed
Fixing up member variables
1 parent 5ea1655 commit 1419ec3

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

src/Arduino_LoRaConnectionHandler.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ static const unsigned long NETWORK_CONNECTION_INTERVAL = 30000; /* NOT USED
3333
CTOR/DTOR
3434
******************************************************************************/
3535

36-
LoRaConnectionHandler::LoRaConnectionHandler(const char *_appeui, const char *_appkey, _lora_band band, _lora_class deviceClass) :
37-
appeui(_appeui),
38-
appkey(_appkey),
39-
band(band),
40-
deviceClass(deviceClass),
41-
lastConnectionTickTime(millis()),
42-
connectionTickTimeInterval(CHECK_INTERVAL_IDLE),
43-
keepAlive(false)
36+
LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, _lora_class const device_class)
37+
: _appeui(appeui)
38+
, _appkey(appkey)
39+
, _band(band)
40+
, _device_class(device_class)
41+
, _lastConnectionTickTime(millis())
42+
, _connectionTickTimeInterval(CHECK_INTERVAL_IDLE)
43+
, _keep_alive(false)
4444
{
4545

4646
}
@@ -51,9 +51,9 @@ LoRaConnectionHandler::LoRaConnectionHandler(const char *_appeui, const char *_a
5151

5252
int LoRaConnectionHandler::write(const uint8_t *buf, size_t size) {
5353
int err;
54-
modem.beginPacket();
55-
modem.write(buf, size);
56-
err = modem.endPacket(true);
54+
_modem.beginPacket();
55+
_modem.write(buf, size);
56+
err = _modem.endPacket(true);
5757
if (err != size) {
5858
switch (err) {
5959
case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: {
@@ -91,20 +91,20 @@ int LoRaConnectionHandler::write(const uint8_t *buf, size_t size) {
9191
}
9292

9393
int LoRaConnectionHandler::read() {
94-
return modem.read();
94+
return _modem.read();
9595
}
9696

9797
bool LoRaConnectionHandler::available() {
98-
return modem.available();
98+
return _modem.available();
9999
}
100100

101101
NetworkConnectionState LoRaConnectionHandler::check() {
102102

103103
unsigned long const now = millis();
104104
int networkStatus = 0;
105-
if (now - lastConnectionTickTime > connectionTickTimeInterval) { /* time bracket */
105+
if (now - _lastConnectionTickTime > _connectionTickTimeInterval) { /* time bracket */
106106

107-
lastConnectionTickTime = now;
107+
_lastConnectionTickTime = now;
108108
switch (netConnectionState) {
109109
case NetworkConnectionState::INIT: netConnectionState = update_handleInit(); break;
110110
case NetworkConnectionState::CONNECTING: netConnectionState = update_handleConnecting(); break;
@@ -125,47 +125,47 @@ NetworkConnectionState LoRaConnectionHandler::check() {
125125

126126
NetworkConnectionState LoRaConnectionHandler::update_handleInit() {
127127
Debug.print(DBG_VERBOSE, "::INIT");
128-
if (!modem.begin(band)) {
128+
if (!_modem.begin(_band)) {
129129
Debug.print(DBG_VERBOSE, "Failed to start module");
130130
execCallback(NetworkConnectionEvent::ERROR, 0);
131131
Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry.");
132132
};
133-
//A delay is required between modem.begin(band) and modem.joinOTAA(appeui, appkey) in order to let the chip to be correctly initialized before the connection attempt
133+
//A delay is required between _modem.begin(band) and _modem.joinOTAA(appeui, appkey) in order to let the chip to be correctly initialized before the connection attempt
134134
delay(100);
135-
modem.configureClass(deviceClass);
135+
_modem.configureClass(_device_class);
136136
delay(100);
137137
Debug.print(DBG_INFO, "Connecting to the network");
138-
connectionTickTimeInterval = CHECK_INTERVAL_CONNECTING;
138+
_connectionTickTimeInterval = CHECK_INTERVAL_CONNECTING;
139139
return NetworkConnectionState::CONNECTING;
140140
}
141141

142142
NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() {
143143
Debug.print(DBG_VERBOSE, "::CONNECTING");
144-
bool networkStatus = modem.joinOTAA(appeui, appkey);
145-
if (networkStatus != true) {
144+
bool const network_status = _modem.joinOTAA(_appeui, _appkey);
145+
if (network_status != true) {
146146
execCallback(NetworkConnectionEvent::ERROR, 0);
147147
Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry.");
148148
return NetworkConnectionState::ERROR;
149149
}
150150

151151
Debug.print(DBG_INFO, "Connected to the network");
152-
connectionTickTimeInterval = CHECK_INTERVAL_CONNECTED;
152+
_connectionTickTimeInterval = CHECK_INTERVAL_CONNECTED;
153153
execCallback(NetworkConnectionEvent::CONNECTED, 0);
154154
return NetworkConnectionState::CONNECTED;
155155
}
156156

157157
NetworkConnectionState LoRaConnectionHandler::update_handleConnected() {
158158

159-
bool networkStatus = modem.connected();
160-
Debug.print(DBG_VERBOSE, "Connection state: %d", networkStatus);
161-
if (networkStatus != true) {
159+
bool const network_status = _modem.connected();
160+
Debug.print(DBG_VERBOSE, "Connection state: %d", network_status);
161+
if (network_status != true) {
162162
execCallback(NetworkConnectionEvent::DISCONNECTED, 0);
163163

164164
Debug.print(DBG_ERROR, "Connection to the network lost.");
165-
if (keepAlive) {
165+
if (_keep_alive) {
166166
Debug.print(DBG_ERROR, "Attempting reconnection");
167167
}
168-
connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
168+
_connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
169169
return NetworkConnectionState::DISCONNECTED;
170170
}
171171
Debug.print(DBG_VERBOSE, "Connected to the network");
@@ -177,17 +177,17 @@ NetworkConnectionState LoRaConnectionHandler::update_handleDisconnecting() {
177177
execCallback(NetworkConnectionEvent::DISCONNECTED, 0);
178178

179179
Debug.print(DBG_ERROR, "Connection to the network lost.");
180-
if (keepAlive) {
180+
if (_keep_alive) {
181181
Debug.print(DBG_ERROR, "Attempting reconnection");
182182
}
183-
connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
183+
_connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
184184
return NetworkConnectionState::DISCONNECTED;
185185
}
186186

187187
NetworkConnectionState LoRaConnectionHandler::update_handleDisconnected() {
188-
if (keepAlive) {
188+
if (_keep_alive) {
189189
Debug.print(DBG_VERBOSE, "CHANGING STATE TO ::INIT");
190-
connectionTickTimeInterval = CHECK_INTERVAL_INIT;
190+
_connectionTickTimeInterval = CHECK_INTERVAL_INIT;
191191
return NetworkConnectionState::INIT;
192192
} else {
193193
Debug.print(DBG_VERBOSE, "Connection to the network terminated");
@@ -200,8 +200,8 @@ void LoRaConnectionHandler::connect() {
200200
if (netConnectionState == NetworkConnectionState::INIT || netConnectionState == NetworkConnectionState::CONNECTING) {
201201
return;
202202
}
203-
keepAlive = true;
204-
connectionTickTimeInterval = CHECK_INTERVAL_INIT;
203+
_keep_alive = true;
204+
_connectionTickTimeInterval = CHECK_INTERVAL_INIT;
205205
netConnectionState = NetworkConnectionState::INIT;
206206

207207
}

src/Arduino_LoRaConnectionHandler.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef enum {
4242

4343
class LoRaConnectionHandler : public ConnectionHandler {
4444
public:
45-
LoRaConnectionHandler(const char *_appeui, const char *_appkey, _lora_band = _lora_band::EU868, _lora_class = _lora_class::CLASS_A);
45+
LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band = _lora_band::EU868, _lora_class const device_class = _lora_class::CLASS_A);
4646

4747
virtual NetworkConnectionState check();
4848

@@ -64,15 +64,14 @@ class LoRaConnectionHandler : public ConnectionHandler {
6464
const int CHECK_INTERVAL_DISCONNECTED = 1000;
6565
const int CHECK_INTERVAL_ERROR = 500;
6666

67-
LoRaModem modem;
68-
const char *appeui, *appkey;
69-
_lora_band band;
70-
_lora_class deviceClass;
71-
unsigned long lastConnectionTickTime;
72-
73-
int connectionTickTimeInterval;
74-
75-
bool keepAlive;
67+
char const * _appeui;
68+
char const * _appkey;
69+
_lora_band _band;
70+
_lora_class _device_class;
71+
unsigned long _lastConnectionTickTime;
72+
int _connectionTickTimeInterval;
73+
bool _keep_alive;
74+
LoRaModem _modem;
7675

7776
NetworkConnectionState update_handleInit();
7877
NetworkConnectionState update_handleConnecting();

0 commit comments

Comments
 (0)