Skip to content

Commit bfed2ba

Browse files
author
Ari Parkkila
committed
Changed cellular device as not static
1 parent e183923 commit bfed2ba

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@
3737

3838
namespace mbed {
3939

40-
static events::EventQueue at_queue(8 * EVENTS_EVENT_SIZE);
41-
static CELLULAR_DEVICE cellularDevice(at_queue);
42-
4340
CellularConnectionFSM::CellularConnectionFSM() :
44-
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _network(0), _power(0), _sim(0), _queue(
45-
8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(&cellularDevice), _retry_count(0), _state_retry_count(
46-
0)
41+
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _network(0), _power(0), _sim(0),
42+
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _retry_count(0), _state_retry_count(0), _at_queue(8 * EVENTS_EVENT_SIZE)
4743
{
4844
memset(_sim_pin, 0, sizeof(_sim_pin));
4945
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
@@ -64,6 +60,8 @@ CellularConnectionFSM::CellularConnectionFSM() :
6460
_retry_timeout_array[8] = 600;
6561
_retry_timeout_array[9] = TIMEOUT_NETWORK_MAX;
6662
_retry_array_length = MAX_RETRY_ARRAY_SIZE;
63+
64+
_cellularDevice = new CELLULAR_DEVICE(_at_queue);
6765
}
6866

6967
CellularConnectionFSM::~CellularConnectionFSM()
@@ -90,7 +88,7 @@ nsapi_error_t CellularConnectionFSM::init()
9088
return NSAPI_ERROR_NO_MEMORY;
9189
}
9290

93-
at_queue.chain(&_queue);
91+
_at_queue.chain(&_queue);
9492

9593
tr_info("init done...");
9694
return NSAPI_ERROR_OK;
@@ -282,7 +280,7 @@ void CellularConnectionFSM::event()
282280
_next_state = STATE_POWER_ON;
283281
break;
284282
case STATE_POWER_ON:
285-
cellularDevice.set_timeout(TIMEOUT_POWER_ON);
283+
_cellularDevice->set_timeout(TIMEOUT_POWER_ON);
286284
tr_info("Cellular power ON (timeout %d ms)", TIMEOUT_POWER_ON);
287285
if (open_power(_serial)) {
288286
_next_state = STATE_DEVICE_READY;
@@ -298,7 +296,7 @@ void CellularConnectionFSM::event()
298296
}
299297
break;
300298
case STATE_DEVICE_READY:
301-
cellularDevice.set_timeout(TIMEOUT_POWER_ON);
299+
_cellularDevice->set_timeout(TIMEOUT_POWER_ON);
302300
if (_power->set_at_mode() == NSAPI_ERROR_OK) {
303301
tr_info("Cellular device ready");
304302
_next_state = STATE_SIM_PIN;
@@ -316,7 +314,7 @@ void CellularConnectionFSM::event()
316314
}
317315
break;
318316
case STATE_SIM_PIN:
319-
cellularDevice.set_timeout(TIMEOUT_SIM_PIN);
317+
_cellularDevice->set_timeout(TIMEOUT_SIM_PIN);
320318
tr_info("Start cellular (timeout %d ms)", TIMEOUT_SIM_PIN);
321319
if (open_sim()) {
322320
_next_state = STATE_REGISTERING_NETWORK;
@@ -334,7 +332,7 @@ void CellularConnectionFSM::event()
334332
}
335333
break;
336334
case STATE_REGISTERING_NETWORK:
337-
cellularDevice.set_timeout(TIMEOUT_NETWORK);
335+
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
338336
CellularNetwork::RegistrationStatus status;
339337
bool is_registered;
340338
_next_state = STATE_REGISTER_NETWORK;
@@ -369,7 +367,7 @@ void CellularConnectionFSM::event()
369367
}
370368
break;
371369
case STATE_REGISTER_NETWORK:
372-
cellularDevice.set_timeout(TIMEOUT_REGISTRATION);
370+
_cellularDevice->set_timeout(TIMEOUT_REGISTRATION);
373371
tr_info("Register to cellular network (timeout %d ms)", TIMEOUT_REGISTRATION);
374372
if (set_network_registration()) {
375373
_next_state = STATE_REGISTERING_NETWORK;
@@ -390,7 +388,7 @@ void CellularConnectionFSM::event()
390388
}
391389
break;
392390
case STATE_ATTACHING_NETWORK:
393-
cellularDevice.set_timeout(TIMEOUT_NETWORK);
391+
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
394392
CellularNetwork::AttachStatus attach_status;
395393
if (get_attach_network(attach_status)) {
396394
if (attach_status == CellularNetwork::Attached) {
@@ -410,7 +408,7 @@ void CellularConnectionFSM::event()
410408
}
411409
break;
412410
case STATE_ATTACH_NETWORK:
413-
cellularDevice.set_timeout(TIMEOUT_NETWORK);
411+
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
414412
tr_info("Attach to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
415413
if (set_attach_network()) {
416414
_next_state = STATE_ATTACHING_NETWORK;
@@ -432,7 +430,7 @@ void CellularConnectionFSM::event()
432430
}
433431
break;
434432
case STATE_CONNECT_NETWORK:
435-
cellularDevice.set_timeout(TIMEOUT_NETWORK);
433+
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
436434
tr_info("Connect to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
437435
err = _network->connect();
438436
if (!err) {
@@ -448,7 +446,7 @@ void CellularConnectionFSM::event()
448446
}
449447
break;
450448
case STATE_CONNECTED:
451-
cellularDevice.set_timeout(TIMEOUT_NETWORK);
449+
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
452450
tr_debug("Cellular ready! (timeout %d ms)", TIMEOUT_NETWORK);
453451
if (_status_callback) {
454452
if (!_status_callback(_state, _next_state)) {

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class CellularConnectionFSM
166166
int _start_time;
167167
uint16_t _retry_timeout_array[MAX_RETRY_ARRAY_SIZE];
168168
int _retry_array_length;
169+
events::EventQueue _at_queue;
169170
};
170171

171172
} // namespace

0 commit comments

Comments
 (0)