mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Added CellularDevice::init_module API to be called at startup
parent
f059fb36bd
commit
c6ab45b6e1
|
@ -394,8 +394,11 @@ void CellularConnectionFSM::state_power_on()
|
|||
}
|
||||
}
|
||||
|
||||
void CellularConnectionFSM::device_ready()
|
||||
bool CellularConnectionFSM::device_ready()
|
||||
{
|
||||
if (_cellularDevice->init_module(_serial) != NSAPI_ERROR_OK) {
|
||||
return false;
|
||||
}
|
||||
tr_info("Cellular device ready");
|
||||
if (_event_status_cb) {
|
||||
_event_status_cb((nsapi_event_t)CellularDeviceReady, 0);
|
||||
|
@ -403,14 +406,16 @@ void CellularConnectionFSM::device_ready()
|
|||
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularConnectionFSM::ready_urc_cb));
|
||||
_cellularDevice->close_power();
|
||||
_power = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CellularConnectionFSM::state_device_ready()
|
||||
{
|
||||
_cellularDevice->set_timeout(TIMEOUT_POWER_ON);
|
||||
if (_power->set_at_mode() == NSAPI_ERROR_OK) {
|
||||
device_ready();
|
||||
enter_to_state(STATE_SIM_PIN);
|
||||
if (device_ready()) {
|
||||
enter_to_state(STATE_SIM_PIN);
|
||||
}
|
||||
} else {
|
||||
if (_retry_count == 0) {
|
||||
(void)_power->set_device_ready_urc_cb(mbed::callback(this, &CellularConnectionFSM::ready_urc_cb));
|
||||
|
@ -658,9 +663,10 @@ void CellularConnectionFSM::ready_urc_cb()
|
|||
tr_debug("Device ready URC func called");
|
||||
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) {
|
||||
tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
|
||||
_queue.cancel(_event_id);
|
||||
device_ready();
|
||||
continue_from_state(STATE_SIM_PIN);
|
||||
if (device_ready()) {
|
||||
_queue.cancel(_event_id);
|
||||
continue_from_state(STATE_SIM_PIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ private:
|
|||
bool open_sim();
|
||||
bool get_network_registration(CellularNetwork::RegistrationType type, CellularNetwork::RegistrationStatus &status, bool &is_registered);
|
||||
bool is_registered();
|
||||
void device_ready();
|
||||
bool device_ready();
|
||||
|
||||
// state functions to keep state machine simple
|
||||
void state_init();
|
||||
|
|
|
@ -114,6 +114,16 @@ public:
|
|||
* @return network stack
|
||||
*/
|
||||
virtual NetworkStack *get_stack() = 0;
|
||||
|
||||
/** Initialize cellular module must be called right after module is ready.
|
||||
* For example, when multiple modules are supported in a single AT driver this function detects
|
||||
* and adapts to an actual module at runtime.
|
||||
*
|
||||
* @param fh file handle used in communication to modem.
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual nsapi_error_t init_module(FileHandle *fh) = 0;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -246,3 +246,8 @@ NetworkStack *AT_CellularDevice::get_stack()
|
|||
}
|
||||
return _network->get_stack();
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularDevice::init_module(FileHandle *fh)
|
||||
{
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,8 @@ public: // CellularDevice
|
|||
|
||||
virtual NetworkStack *get_stack();
|
||||
|
||||
virtual nsapi_error_t init_module(FileHandle *fh);
|
||||
|
||||
protected:
|
||||
AT_CellularNetwork *_network;
|
||||
AT_CellularSMS *_sms;
|
||||
|
|
Loading…
Reference in New Issue