Skip to content

Commit 185fda9

Browse files
fixup! readapting ConnectionHandler implementation to use setting struct
1 parent ee059d7 commit 185fda9

8 files changed

+104
-79
lines changed

src/CatM1ConnectionHandler.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@
2828
CTOR/DTOR
2929
******************************************************************************/
3030

31-
CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive)
31+
CatM1ConnectionHandler::CatM1ConnectionHandler()
32+
: ConnectionHandler(false, NetworkAdapter::CATM1) { }
33+
34+
CatM1ConnectionHandler::CatM1ConnectionHandler(
35+
const char * pin, const char * apn, const char * login, const char * pass,
36+
RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive)
3237
: ConnectionHandler{keep_alive, NetworkAdapter::CATM1}
3338
{
3439
_settings.type = NetworkAdapter::CATM1;
35-
strcpy(_settings.values.catm1.pin, pin);
36-
strcpy(_settings.values.catm1.apn, apn);
37-
strcpy(_settings.values.catm1.login, login);
38-
strcpy(_settings.values.catm1.pass, pass);
39-
_settings.values.catm1.rat = rat
40-
_settings.values.catm1.band = band;
40+
strcpy(_settings.catm1.pin, pin);
41+
strcpy(_settings.catm1.apn, apn);
42+
strcpy(_settings.catm1.login, login);
43+
strcpy(_settings.catm1.pass, pass);
44+
_settings.catm1.rat = static_cast<int>(rat);
45+
_settings.catm1.band = band;
4146
}
4247

4348
/******************************************************************************
@@ -65,12 +70,12 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit()
6570
NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting()
6671
{
6772
if(!GSM.begin(
68-
_settings.values.catm1.pin,
69-
_settings.values.catm1.apn,
70-
_settings.values.catm1.login,
71-
_settings.values.catm1.pass,
72-
_settings.values.catm1.rat,
73-
_settings.values.catm1.band))
73+
_settings.catm1.pin,
74+
_settings.catm1.apn,
75+
_settings.catm1.login,
76+
_settings.catm1.pass,
77+
static_cast<RadioAccessTechnologyType>(_settings.catm1.rat) ,
78+
_settings.catm1.band))
7479
{
7580
Debug.print(DBG_ERROR, F("The board was not able to register to the network..."));
7681
return NetworkConnectionState::ERROR;

src/CellularConnectionHandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/******************************************************************************
2222
CTOR/DTOR
2323
******************************************************************************/
24+
CellularConnectionHandler::CellularConnectionHandler()
25+
: ConnectionHandler(false, NetworkAdapter::CELL) {}
2426

2527
CellularConnectionHandler::CellularConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive)
2628
: ConnectionHandler{keep_alive, NetworkAdapter::CELL}

src/EthernetConnectionHandler.cpp

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,52 @@
2525
CTOR/DTOR
2626
******************************************************************************/
2727

28+
// FIXME
2829
EthernetConnectionHandler::EthernetConnectionHandler(unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
2930
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
30-
,_ip{INADDR_NONE}
31-
,_dns{INADDR_NONE}
32-
,_gateway{INADDR_NONE}
33-
,_netmask{INADDR_NONE}
34-
,_timeout{timeout}
35-
,_response_timeout{responseTimeout}
31+
// ,_ip{INADDR_NONE}
32+
// ,_dns{INADDR_NONE}
33+
// ,_gateway{INADDR_NONE}
34+
// ,_netmask{INADDR_NONE}
35+
// ,_timeout{timeout}
36+
// ,_response_timeout{responseTimeout}
3637
{
3738

3839
}
3940

4041
EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
4142
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
42-
,_ip{ip}
43-
,_dns{dns}
44-
,_gateway{gateway}
45-
,_netmask{netmask}
46-
,_timeout{timeout}
47-
,_response_timeout{responseTimeout}
43+
// ,_ip{ip}
44+
// ,_dns{dns}
45+
// ,_gateway{gateway}
46+
// ,_netmask{netmask}
47+
// ,_timeout{timeout}
48+
// ,_response_timeout{responseTimeout}
4849
{
4950

5051
}
5152

5253
EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
5354
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
54-
,_ip{INADDR_NONE}
55-
,_dns{INADDR_NONE}
56-
,_gateway{INADDR_NONE}
57-
,_netmask{INADDR_NONE}
58-
,_timeout{timeout}
59-
,_response_timeout{responseTimeout}
55+
// ,_ip{INADDR_NONE}
56+
// ,_dns{INADDR_NONE}
57+
// ,_gateway{INADDR_NONE}
58+
// ,_netmask{INADDR_NONE}
59+
// ,_timeout{timeout}
60+
// ,_response_timeout{responseTimeout}
6061
{
61-
if(!_ip.fromString(ip)) {
62-
_ip = INADDR_NONE;
63-
}
64-
if(!_dns.fromString(dns)) {
65-
_dns = INADDR_NONE;
66-
}
67-
if(!_gateway.fromString(gateway)) {
68-
_gateway = INADDR_NONE;
69-
}
70-
if(!_netmask.fromString(netmask)) {
71-
_netmask = INADDR_NONE;
72-
}
62+
// if(!_ip.fromString(ip)) {
63+
// _ip = INADDR_NONE;
64+
// }
65+
// if(!_dns.fromString(dns)) {
66+
// _dns = INADDR_NONE;
67+
// }
68+
// if(!_gateway.fromString(gateway)) {
69+
// _gateway = INADDR_NONE;
70+
// }
71+
// if(!_netmask.fromString(netmask)) {
72+
// _netmask = INADDR_NONE;
73+
// }
7374
}
7475

7576
/******************************************************************************
@@ -87,16 +88,24 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit()
8788

8889
NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
8990
{
90-
if (_ip != INADDR_NONE) {
91-
if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, _timeout, _response_timeout) == 0) {
91+
if (_settings.eth.ip != INADDR_NONE) {
92+
if (Ethernet.begin(nullptr,
93+
_settings.eth.ip,
94+
_settings.eth.dns,
95+
_settings.eth.gateway,
96+
_settings.eth.netmask,
97+
_settings.eth.timeout,
98+
_settings.eth.response_timeout) == 0) {
9299
Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection"));
93-
Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout);
100+
Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d",
101+
_settings.eth.timeout, _settings.eth.response_timeout);
94102
return NetworkConnectionState::CONNECTING;
95103
}
96104
} else {
97-
if (Ethernet.begin(nullptr, _timeout, _response_timeout) == 0) {
105+
if (Ethernet.begin(nullptr, _settings.eth.timeout, _settings.eth.response_timeout) == 0) {
98106
Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection"));
99-
Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout);
107+
Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d",
108+
_settings.eth.timeout, _settings.eth.response_timeout);
100109
return NetworkConnectionState::CONNECTING;
101110
}
102111
}

src/EthernetConnectionHandler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class EthernetConnectionHandler : public ConnectionHandler
4444
{
4545
public:
4646

47-
EthernetConnectionHandler();
4847
EthernetConnectionHandler(unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true);
4948
EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true);
5049
EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true);

src/GSMConnectionHandler.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ __attribute__((weak)) void mkr_gsm_feed_watchdog()
4646
/******************************************************************************
4747
CTOR/DTOR
4848
******************************************************************************/
49+
GSMConnectionHandler::GSMConnectionHandler()
50+
: ConnectionHandler(false, NetworkAdapter::GSM) {}
4951

5052
GSMConnectionHandler::GSMConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive)
5153
: ConnectionHandler{keep_alive, NetworkAdapter::GSM}
5254
{
5355
_settings.type = NetworkAdapter::GSM;
54-
strcpy(_settings.values.gsm.pin, pin);
55-
strcpy(_settings.values.gsm.apn, apn);
56-
strcpy(_settings.values.gsm.login, login);
57-
strcpy(_settings.values.gsm.pass, pass);
56+
strcpy(_settings.gsm.pin, pin);
57+
strcpy(_settings.gsm.apn, apn);
58+
strcpy(_settings.gsm.login, login);
59+
strcpy(_settings.gsm.pass, pass);
5860
}
5961

6062
/******************************************************************************
@@ -74,7 +76,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit()
7476
{
7577
mkr_gsm_feed_watchdog();
7678

77-
if (_gsm.begin(_settings.values.gsm.pin) != GSM_READY)
79+
if (_gsm.begin(_settings.gsm.pin) != GSM_READY)
7880
{
7981
Debug.print(DBG_ERROR, F("SIM not present or wrong PIN"));
8082
return NetworkConnectionState::ERROR;
@@ -89,7 +91,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit()
8991
mkr_gsm_feed_watchdog();
9092

9193
GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(
92-
_settings.values.gsm.apn, _settings.values.gsm.login, _settings.values.gsm.pass, true);
94+
_settings.gsm.apn, _settings.gsm.login, _settings.gsm.pass, true);
9395
Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status);
9496
if (network_status == GSM3_NetworkStatus_t::ERROR)
9597
{

src/LoRaConnectionHandler.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * a
4848
: ConnectionHandler{false, NetworkAdapter::LORA}
4949
{
5050
_settings.type = NetworkAdapter::LORA;
51-
strcpy(_settings.values.lora.appeui, appeui);
52-
strcpy(_settings.values.lora.appkey, appkey);
53-
_settings.values.lora.band = band;
54-
strcpy(_settings.values.lora.channelMask, channelMask);
55-
_settings.values.lora.deviceClass = device_class;
51+
strcpy(_settings.lora.appeui, appeui);
52+
strcpy(_settings.lora.appkey, appkey);
53+
_settings.lora.band = band;
54+
strcpy(_settings.lora.channelMask, channelMask);
55+
_settings.lora.deviceClass = device_class;
5656
}
5757

5858
/******************************************************************************
@@ -103,26 +103,26 @@ bool LoRaConnectionHandler::available()
103103

104104
NetworkConnectionState LoRaConnectionHandler::update_handleInit()
105105
{
106-
if (!_modem.begin(_settings.values.lora.band))
106+
if (!_modem.begin(_settings.lora.band))
107107
{
108108
Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry."));
109109
return NetworkConnectionState::ERROR;
110110
}
111111
// Set channelmask based on configuration
112-
if (_settings.values.lora.channelMask) {
113-
_modem.sendMask(_settings.values.lora.channelMask);
112+
if (_settings.lora.channelMask) {
113+
_modem.sendMask(_settings.lora.channelMask);
114114
}
115115
//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
116116
delay(100);
117-
_modem.configureClass(_settings.values.lora.deviceClass);
117+
_modem.configureClass(_settings.lora.deviceClass);
118118
delay(100);
119119
Debug.print(DBG_INFO, F("Connecting to the network"));
120120
return NetworkConnectionState::CONNECTING;
121121
}
122122

123123
NetworkConnectionState LoRaConnectionHandler::update_handleConnecting()
124124
{
125-
bool const network_status = _modem.joinOTAA(_settings.values.lora.appeui, _settings.values.lora.appkey);
125+
bool const network_status = _modem.joinOTAA(_settings.lora.appeui, _settings.lora.appkey);
126126
if (network_status != true)
127127
{
128128
Debug.print(DBG_ERROR, F("Connection to the network failed"));

src/NBConnectionHandler.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ __attribute__((weak)) void mkr_nb_feed_watchdog()
4545
/******************************************************************************
4646
CTOR/DTOR
4747
******************************************************************************/
48+
49+
NBConnectionHandler::NBConnectionHandler()
50+
: ConnectionHandler(false, NetworkAdapter::NB) {}
51+
4852
NBConnectionHandler::NBConnectionHandler(char const * pin, bool const keep_alive)
4953
: NBConnectionHandler(pin, "", keep_alive)
5054
{
@@ -61,10 +65,10 @@ NBConnectionHandler::NBConnectionHandler(char const * pin, char const * apn, cha
6165
: ConnectionHandler{keep_alive, NetworkAdapter::NB}
6266
{
6367
_settings.type = NetworkAdapter::NB;
64-
strcpy(_settings.values.nb.pin, pin);
65-
strcpy(_settings.values.nb.apn, apn);
66-
strcpy(_settings.values.nb.login, login);
67-
strcpy(_settings.values.nb.pass, pass);
68+
strcpy(_settings.nb.pin, pin);
69+
strcpy(_settings.nb.apn, apn);
70+
strcpy(_settings.nb.login, login);
71+
strcpy(_settings.nb.pass, pass);
6872
}
6973

7074
/******************************************************************************
@@ -84,10 +88,10 @@ NetworkConnectionState NBConnectionHandler::update_handleInit()
8488
{
8589
mkr_nb_feed_watchdog();
8690

87-
if (_nb.begin(_settings.values.nb.pin,
88-
_settings.values.nb.apn,
89-
_settings.values.nb.login,
90-
_settings.values.nb.pass) == NB_READY)
91+
if (_nb.begin(_settings.nb.pin,
92+
_settings.nb.apn,
93+
_settings.nb.login,
94+
_settings.nb.pass) == NB_READY)
9195
{
9296
Debug.print(DBG_INFO, F("SIM card ok"));
9397
_nb.setTimeout(NB_TIMEOUT);

src/WiFiConnectionHandler.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ static int const ESP_WIFI_CONNECTION_TIMEOUT = 3000;
3535
CTOR/DTOR
3636
******************************************************************************/
3737

38+
WiFiConnectionHandler::WiFiConnectionHandler()
39+
: ConnectionHandler(false, NetworkAdapter::WIFI) {
40+
}
41+
3842
WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pass, bool const keep_alive)
3943
: ConnectionHandler{keep_alive, NetworkAdapter::WIFI}
4044
{
4145
_settings.type = NetworkAdapter::WIFI;
42-
strcpy(_settings.values.wifi.ssid, ssid);
43-
strcpy(_settings.values.wifi.pwd, pass);
46+
strcpy(_settings.wifi.ssid, ssid);
47+
strcpy(_settings.wifi.pwd, pass);
4448
}
4549

4650
/******************************************************************************
@@ -99,7 +103,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting()
99103
{
100104
if (WiFi.status() != WL_CONNECTED)
101105
{
102-
WiFi.begin(_settings.values.wifi.ssid, _settings.values.wifi.pwd);
106+
WiFi.begin(_settings.wifi.ssid, _settings.wifi.pwd);
103107
#if defined(ARDUINO_ARCH_ESP8266)
104108
/* Wait connection otherwise board won't connect */
105109
unsigned long start = millis();
@@ -113,15 +117,15 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting()
113117
if (WiFi.status() != NETWORK_CONNECTED)
114118
{
115119
#if !defined(__AVR__)
116-
Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _settings.values.wifi.ssid);
120+
Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _settings.wifi.ssid);
117121
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
118122
#endif
119123
return NetworkConnectionState::CONNECTING;
120124
}
121125
else
122126
{
123127
#if !defined(__AVR__)
124-
Debug.print(DBG_INFO, F("Connected to \"%s\""), _settings.values.wifi.ssid);
128+
Debug.print(DBG_INFO, F("Connected to \"%s\""), _settings.wifi.ssid);
125129
#endif
126130
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
127131
configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov");
@@ -136,7 +140,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected()
136140
{
137141
#if !defined(__AVR__)
138142
Debug.print(DBG_VERBOSE, F("WiFi.status(): %d"), WiFi.status());
139-
Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _settings.values.wifi.ssid);
143+
Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _settings.wifi.ssid);
140144
#endif
141145
if (_keep_alive)
142146
{

0 commit comments

Comments
 (0)