Skip to content

Commit d9a99b0

Browse files
author
Teppo Järvelin
committed
Cellular: release resources in state machine. Made sure that athandler does not try process urc's after switch to data mode.
1 parent ed9a1f1 commit d9a99b0

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ void CellularConnectionFSM::device_ready()
402402
_event_status_cb((nsapi_event_t)CellularDeviceReady, 0);
403403
}
404404
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularConnectionFSM::ready_urc_cb));
405+
_cellularDevice->close_power();
406+
_power = NULL;
405407
}
406408

407409
void CellularConnectionFSM::state_device_ready()
@@ -434,7 +436,8 @@ void CellularConnectionFSM::state_sim_pin()
434436
retry_state_or_fail();
435437
return;
436438
}
437-
439+
_cellularDevice->close_sim();
440+
_sim = NULL;
438441
if (_plmn) {
439442
enter_to_state(STATE_MANUAL_REGISTERING_NETWORK);
440443
} else {

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ class CellularConnectionFSM
117117
*/
118118
CellularDevice *get_device();
119119

120-
/** Get cellular sim interface
120+
/** Get cellular sim interface. SIM interface is released after SIM is open and ready for use (moving from STATE_SIM_PIN to next state).
121+
* After SIM interface is closed this method will return NULL. SIM interface can be created again via CellularDevice
122+
* which you can get with the method get_device().
121123
* @return sim interface, NULL on failure
122124
*/
123125
CellularSIM *get_sim();

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char
7272
_fh_sigio_set(false),
7373
_processing(false),
7474
_ref_count(1),
75+
_is_fh_usable(true),
7576
_stop_tag(NULL),
7677
_delimiter(DEFAULT_DELIMITER),
7778
_prefix_matched(false),
@@ -151,6 +152,11 @@ void ATHandler::set_file_handle(FileHandle *fh)
151152
_fileHandle = fh;
152153
}
153154

155+
void ATHandler::set_is_filehandle_usable(bool usable)
156+
{
157+
_is_fh_usable = usable;
158+
}
159+
154160
nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback<void()> callback)
155161
{
156162
if (find_urc_handler(prefix, callback)) {
@@ -269,6 +275,10 @@ void ATHandler::restore_at_timeout()
269275

270276
void ATHandler::process_oob()
271277
{
278+
if (!_is_fh_usable) {
279+
tr_debug("process_oob, filehandle is not usable, return...");
280+
return;
281+
}
272282
lock();
273283
tr_debug("process_oob readable=%d, pos=%u, len=%u", _fileHandle->readable(), _recv_pos, _recv_len);
274284
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {

features/cellular/framework/AT/ATHandler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ class ATHandler {
175175
*/
176176
void set_file_handle(FileHandle *fh);
177177

178+
/** Set is file handle usable. Some situations like after going to data mode, file handle is not usable anymore.
179+
* Any items in queue are not to be processed.
180+
*
181+
* @param usable true for usable filehandle
182+
*/
183+
void set_is_filehandle_usable(bool usable);
184+
178185
protected:
179186
void event();
180187
#ifdef AT_HANDLER_MUTEX
@@ -209,6 +216,7 @@ class ATHandler {
209216

210217
bool _processing;
211218
int32_t _ref_count;
219+
bool _is_fh_usable;
212220

213221
//*************************************
214222
public:

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,12 @@ nsapi_error_t AT_CellularNetwork::open_data_channel()
351351

352352
_at.resp_start("CONNECT", true);
353353
if (_at.get_last_error()) {
354-
tr_warn("Failed to CONNECT");
354+
tr_error("Failed to CONNECT");
355+
return _at.get_last_error();
355356
}
357+
358+
_at.set_is_filehandle_usable(false);
359+
356360
/* Initialize PPP
357361
* If blocking: mbed_ppp_init() is a blocking call, it will block until
358362
connected, or timeout after 30 seconds*/
@@ -376,6 +380,7 @@ nsapi_error_t AT_CellularNetwork::disconnect()
376380
// will set the correct sigio and nonblocking
377381
_at.lock();
378382
_at.set_file_handle(_at.get_file_handle());
383+
_at.set_is_filehandle_usable(true);
379384
_at.unlock();
380385
return err;
381386
#else

0 commit comments

Comments
 (0)