37
37
38
38
namespace mbed {
39
39
40
- static events::EventQueue at_queue (8 * EVENTS_EVENT_SIZE);
41
- static CELLULAR_DEVICE cellularDevice (at_queue);
42
-
43
40
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)
47
43
{
48
44
memset (_sim_pin, 0 , sizeof (_sim_pin));
49
45
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
@@ -64,6 +60,8 @@ CellularConnectionFSM::CellularConnectionFSM() :
64
60
_retry_timeout_array[8 ] = 600 ;
65
61
_retry_timeout_array[9 ] = TIMEOUT_NETWORK_MAX;
66
62
_retry_array_length = MAX_RETRY_ARRAY_SIZE;
63
+
64
+ _cellularDevice = new CELLULAR_DEVICE (_at_queue);
67
65
}
68
66
69
67
CellularConnectionFSM::~CellularConnectionFSM ()
@@ -90,7 +88,7 @@ nsapi_error_t CellularConnectionFSM::init()
90
88
return NSAPI_ERROR_NO_MEMORY;
91
89
}
92
90
93
- at_queue .chain (&_queue);
91
+ _at_queue .chain (&_queue);
94
92
95
93
tr_info (" init done..." );
96
94
return NSAPI_ERROR_OK;
@@ -282,7 +280,7 @@ void CellularConnectionFSM::event()
282
280
_next_state = STATE_POWER_ON;
283
281
break ;
284
282
case STATE_POWER_ON:
285
- cellularDevice. set_timeout (TIMEOUT_POWER_ON);
283
+ _cellularDevice-> set_timeout (TIMEOUT_POWER_ON);
286
284
tr_info (" Cellular power ON (timeout %d ms)" , TIMEOUT_POWER_ON);
287
285
if (open_power (_serial)) {
288
286
_next_state = STATE_DEVICE_READY;
@@ -298,7 +296,7 @@ void CellularConnectionFSM::event()
298
296
}
299
297
break ;
300
298
case STATE_DEVICE_READY:
301
- cellularDevice. set_timeout (TIMEOUT_POWER_ON);
299
+ _cellularDevice-> set_timeout (TIMEOUT_POWER_ON);
302
300
if (_power->set_at_mode () == NSAPI_ERROR_OK) {
303
301
tr_info (" Cellular device ready" );
304
302
_next_state = STATE_SIM_PIN;
@@ -316,7 +314,7 @@ void CellularConnectionFSM::event()
316
314
}
317
315
break ;
318
316
case STATE_SIM_PIN:
319
- cellularDevice. set_timeout (TIMEOUT_SIM_PIN);
317
+ _cellularDevice-> set_timeout (TIMEOUT_SIM_PIN);
320
318
tr_info (" Start cellular (timeout %d ms)" , TIMEOUT_SIM_PIN);
321
319
if (open_sim ()) {
322
320
_next_state = STATE_REGISTERING_NETWORK;
@@ -334,7 +332,7 @@ void CellularConnectionFSM::event()
334
332
}
335
333
break ;
336
334
case STATE_REGISTERING_NETWORK:
337
- cellularDevice. set_timeout (TIMEOUT_NETWORK);
335
+ _cellularDevice-> set_timeout (TIMEOUT_NETWORK);
338
336
CellularNetwork::RegistrationStatus status;
339
337
bool is_registered;
340
338
_next_state = STATE_REGISTER_NETWORK;
@@ -369,7 +367,7 @@ void CellularConnectionFSM::event()
369
367
}
370
368
break ;
371
369
case STATE_REGISTER_NETWORK:
372
- cellularDevice. set_timeout (TIMEOUT_REGISTRATION);
370
+ _cellularDevice-> set_timeout (TIMEOUT_REGISTRATION);
373
371
tr_info (" Register to cellular network (timeout %d ms)" , TIMEOUT_REGISTRATION);
374
372
if (set_network_registration ()) {
375
373
_next_state = STATE_REGISTERING_NETWORK;
@@ -390,7 +388,7 @@ void CellularConnectionFSM::event()
390
388
}
391
389
break ;
392
390
case STATE_ATTACHING_NETWORK:
393
- cellularDevice. set_timeout (TIMEOUT_NETWORK);
391
+ _cellularDevice-> set_timeout (TIMEOUT_NETWORK);
394
392
CellularNetwork::AttachStatus attach_status;
395
393
if (get_attach_network (attach_status)) {
396
394
if (attach_status == CellularNetwork::Attached) {
@@ -410,7 +408,7 @@ void CellularConnectionFSM::event()
410
408
}
411
409
break ;
412
410
case STATE_ATTACH_NETWORK:
413
- cellularDevice. set_timeout (TIMEOUT_NETWORK);
411
+ _cellularDevice-> set_timeout (TIMEOUT_NETWORK);
414
412
tr_info (" Attach to cellular network (timeout %d ms)" , TIMEOUT_NETWORK);
415
413
if (set_attach_network ()) {
416
414
_next_state = STATE_ATTACHING_NETWORK;
@@ -432,7 +430,7 @@ void CellularConnectionFSM::event()
432
430
}
433
431
break ;
434
432
case STATE_CONNECT_NETWORK:
435
- cellularDevice. set_timeout (TIMEOUT_NETWORK);
433
+ _cellularDevice-> set_timeout (TIMEOUT_NETWORK);
436
434
tr_info (" Connect to cellular network (timeout %d ms)" , TIMEOUT_NETWORK);
437
435
err = _network->connect ();
438
436
if (!err) {
@@ -448,7 +446,7 @@ void CellularConnectionFSM::event()
448
446
}
449
447
break ;
450
448
case STATE_CONNECTED:
451
- cellularDevice. set_timeout (TIMEOUT_NETWORK);
449
+ _cellularDevice-> set_timeout (TIMEOUT_NETWORK);
452
450
tr_debug (" Cellular ready! (timeout %d ms)" , TIMEOUT_NETWORK);
453
451
if (_status_callback) {
454
452
if (!_status_callback (_state, _next_state)) {
0 commit comments