Skip to content

Commit 871ee09

Browse files
author
Cruz Monrreal
authored
Merge pull request #7667 from AriParkkila/cellular-detect
Cellular: Add CellularDevice::init_module API to be called at startup
2 parents 3c25b96 + c6ab45b commit 871ee09

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,23 +394,28 @@ void CellularConnectionFSM::state_power_on()
394394
}
395395
}
396396

397-
void CellularConnectionFSM::device_ready()
397+
bool CellularConnectionFSM::device_ready()
398398
{
399+
if (_cellularDevice->init_module(_serial) != NSAPI_ERROR_OK) {
400+
return false;
401+
}
399402
tr_info("Cellular device ready");
400403
if (_event_status_cb) {
401404
_event_status_cb((nsapi_event_t)CellularDeviceReady, 0);
402405
}
403406
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularConnectionFSM::ready_urc_cb));
404407
_cellularDevice->close_power();
405408
_power = NULL;
409+
return true;
406410
}
407411

408412
void CellularConnectionFSM::state_device_ready()
409413
{
410414
_cellularDevice->set_timeout(TIMEOUT_POWER_ON);
411415
if (_power->set_at_mode() == NSAPI_ERROR_OK) {
412-
device_ready();
413-
enter_to_state(STATE_SIM_PIN);
416+
if (device_ready()) {
417+
enter_to_state(STATE_SIM_PIN);
418+
}
414419
} else {
415420
if (_retry_count == 0) {
416421
(void)_power->set_device_ready_urc_cb(mbed::callback(this, &CellularConnectionFSM::ready_urc_cb));
@@ -658,9 +663,10 @@ void CellularConnectionFSM::ready_urc_cb()
658663
tr_debug("Device ready URC func called");
659664
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) {
660665
tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
661-
_queue.cancel(_event_id);
662-
device_ready();
663-
continue_from_state(STATE_SIM_PIN);
666+
if (device_ready()) {
667+
_queue.cancel(_event_id);
668+
continue_from_state(STATE_SIM_PIN);
669+
}
664670
}
665671
}
666672

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class CellularConnectionFSM {
161161
bool open_sim();
162162
bool get_network_registration(CellularNetwork::RegistrationType type, CellularNetwork::RegistrationStatus &status, bool &is_registered);
163163
bool is_registered();
164-
void device_ready();
164+
bool device_ready();
165165

166166
// state functions to keep state machine simple
167167
void state_init();

features/cellular/framework/API/CellularDevice.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ class CellularDevice {
114114
* @return network stack
115115
*/
116116
virtual NetworkStack *get_stack() = 0;
117+
118+
/** Initialize cellular module must be called right after module is ready.
119+
* For example, when multiple modules are supported in a single AT driver this function detects
120+
* and adapts to an actual module at runtime.
121+
*
122+
* @param fh file handle used in communication to modem.
123+
*
124+
* @return 0 on success
125+
*/
126+
virtual nsapi_error_t init_module(FileHandle *fh) = 0;
117127
};
118128

119129
} // namespace mbed

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,8 @@ NetworkStack *AT_CellularDevice::get_stack()
246246
}
247247
return _network->get_stack();
248248
}
249+
250+
nsapi_error_t AT_CellularDevice::init_module(FileHandle *fh)
251+
{
252+
return NSAPI_ERROR_OK;
253+
}

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class AT_CellularDevice : public CellularDevice {
8181

8282
virtual NetworkStack *get_stack();
8383

84+
virtual nsapi_error_t init_module(FileHandle *fh);
85+
8486
protected:
8587
AT_CellularNetwork *_network;
8688
AT_CellularSMS *_sms;

0 commit comments

Comments
 (0)