Cellular: release resources in state machine. Made sure that athandler does not try process urc's after switch to data mode.

pull/6962/head
Teppo Järvelin 2018-05-21 15:33:39 +03:00
parent ed9a1f1327
commit d9a99b0a45
5 changed files with 31 additions and 3 deletions

View File

@ -402,6 +402,8 @@ void CellularConnectionFSM::device_ready()
_event_status_cb((nsapi_event_t)CellularDeviceReady, 0);
}
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularConnectionFSM::ready_urc_cb));
_cellularDevice->close_power();
_power = NULL;
}
void CellularConnectionFSM::state_device_ready()
@ -434,7 +436,8 @@ void CellularConnectionFSM::state_sim_pin()
retry_state_or_fail();
return;
}
_cellularDevice->close_sim();
_sim = NULL;
if (_plmn) {
enter_to_state(STATE_MANUAL_REGISTERING_NETWORK);
} else {

View File

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

View File

@ -72,6 +72,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char
_fh_sigio_set(false),
_processing(false),
_ref_count(1),
_is_fh_usable(true),
_stop_tag(NULL),
_delimiter(DEFAULT_DELIMITER),
_prefix_matched(false),
@ -151,6 +152,11 @@ void ATHandler::set_file_handle(FileHandle *fh)
_fileHandle = fh;
}
void ATHandler::set_is_filehandle_usable(bool usable)
{
_is_fh_usable = usable;
}
nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback<void()> callback)
{
if (find_urc_handler(prefix, callback)) {
@ -269,6 +275,10 @@ void ATHandler::restore_at_timeout()
void ATHandler::process_oob()
{
if (!_is_fh_usable) {
tr_debug("process_oob, filehandle is not usable, return...");
return;
}
lock();
tr_debug("process_oob readable=%d, pos=%u, len=%u", _fileHandle->readable(), _recv_pos, _recv_len);
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {

View File

@ -175,6 +175,13 @@ public:
*/
void set_file_handle(FileHandle *fh);
/** Set is file handle usable. Some situations like after going to data mode, file handle is not usable anymore.
* Any items in queue are not to be processed.
*
* @param usable true for usable filehandle
*/
void set_is_filehandle_usable(bool usable);
protected:
void event();
#ifdef AT_HANDLER_MUTEX
@ -209,6 +216,7 @@ private:
bool _processing;
int32_t _ref_count;
bool _is_fh_usable;
//*************************************
public:

View File

@ -351,8 +351,12 @@ nsapi_error_t AT_CellularNetwork::open_data_channel()
_at.resp_start("CONNECT", true);
if (_at.get_last_error()) {
tr_warn("Failed to CONNECT");
tr_error("Failed to CONNECT");
return _at.get_last_error();
}
_at.set_is_filehandle_usable(false);
/* Initialize PPP
* If blocking: mbed_ppp_init() is a blocking call, it will block until
connected, or timeout after 30 seconds*/
@ -376,6 +380,7 @@ nsapi_error_t AT_CellularNetwork::disconnect()
// will set the correct sigio and nonblocking
_at.lock();
_at.set_file_handle(_at.get_file_handle());
_at.set_is_filehandle_usable(true);
_at.unlock();
return err;
#else