@@ -45,6 +45,16 @@ bool EasyCellularConnection::cellular_status(int state, int next_state)
45
45
(void )_cellularSemaphore.release ();
46
46
return false ; // return false -> state machine is halted
47
47
}
48
+
49
+ // only in case of an error or when connected is reached state and next_state can be the same.
50
+ // Release semaphore to return application instead of waiting for semaphore to complete.
51
+ if (state == next_state) {
52
+ tr_error (" cellular_status: state and next_state are same, release semaphore as this is an error in state machine" );
53
+ _stm_error = true ;
54
+ (void )_cellularSemaphore.release ();
55
+ return false ; // return false -> state machine is halted
56
+ }
57
+
48
58
return true ;
49
59
}
50
60
@@ -63,9 +73,10 @@ void EasyCellularConnection::network_callback(nsapi_event_t ev, intptr_t ptr)
63
73
}
64
74
65
75
EasyCellularConnection::EasyCellularConnection (bool debug) :
66
- _is_connected (false ), _is_initialized(false ), _target_state(CellularConnectionFSM::STATE_POWER_ON), _cellularSerial(
67
- MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE), _cellularSemaphore(0 ), _cellularConnectionFSM(0 ), _credentials_err(
68
- NSAPI_ERROR_OK), _status_cb(0 )
76
+ _is_connected (false ), _is_initialized(false ), _stm_error(false ),
77
+ _target_state (CellularConnectionFSM::STATE_POWER_ON),
78
+ _cellularSerial (MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE), _cellularSemaphore(0 ),
79
+ _cellularConnectionFSM (0 ), _credentials_err(NSAPI_ERROR_OK), _status_cb(0 )
69
80
{
70
81
tr_info (" EasyCellularConnection()" );
71
82
#if USE_APN_LOOKUP
@@ -86,6 +97,7 @@ EasyCellularConnection::~EasyCellularConnection()
86
97
nsapi_error_t EasyCellularConnection::init ()
87
98
{
88
99
nsapi_error_t err = NSAPI_ERROR_OK;
100
+ _stm_error = false ;
89
101
if (!_is_initialized) {
90
102
#if defined (MDMRTS) && defined (MDMCTS)
91
103
_cellularSerial.set_flow_control (SerialBase::RTSCTS, MDMRTS, MDMCTS);
@@ -156,7 +168,7 @@ nsapi_error_t EasyCellularConnection::connect(const char *sim_pin, const char *a
156
168
}
157
169
158
170
if (sim_pin) {
159
- this -> set_sim_pin (sim_pin);
171
+ set_sim_pin (sim_pin);
160
172
}
161
173
162
174
return connect ();
@@ -193,7 +205,7 @@ nsapi_error_t EasyCellularConnection::connect()
193
205
err = _cellularConnectionFSM->continue_to_state (_target_state);
194
206
if (err == NSAPI_ERROR_OK) {
195
207
int sim_wait = _cellularSemaphore.wait (60 * 1000 ); // reserve 60 seconds to access to SIM
196
- if (sim_wait != 1 ) {
208
+ if (sim_wait != 1 || _stm_error ) {
197
209
tr_error (" NO SIM ACCESS" );
198
210
err = NSAPI_ERROR_NO_CONNECTION;
199
211
} else {
@@ -223,7 +235,7 @@ nsapi_error_t EasyCellularConnection::connect()
223
235
err = _cellularConnectionFSM->continue_to_state (_target_state);
224
236
if (err == NSAPI_ERROR_OK) {
225
237
int ret_wait = _cellularSemaphore.wait (10 * 60 * 1000 ); // cellular network searching may take several minutes
226
- if (ret_wait != 1 ) {
238
+ if (ret_wait != 1 || _stm_error ) {
227
239
tr_info (" No cellular connection" );
228
240
err = NSAPI_ERROR_NO_CONNECTION;
229
241
}
@@ -237,6 +249,7 @@ nsapi_error_t EasyCellularConnection::disconnect()
237
249
_credentials_err = NSAPI_ERROR_OK;
238
250
_is_connected = false ;
239
251
_is_initialized = false ;
252
+ _stm_error = false ;
240
253
#if USE_APN_LOOKUP
241
254
_credentials_set = false ;
242
255
#endif // #if USE_APN_LOOKUP
0 commit comments