diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 17f1807e16..16219255df 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -232,6 +232,17 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) dev.close_sms(); } +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularDevice dev(&fh1); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == dev.is_ready()); +} + TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_power_save_mode) { EventQueue que; diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index 35c05f5541..560196788e 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -123,17 +123,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset) EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset()); } -TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready()); -} - TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb) { EventQueue que; diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 4d2f7363a5..6303dcdc0a 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -151,6 +151,11 @@ void AT_CellularDevice::modem_debug_on(bool on) } +nsapi_error_t AT_CellularDevice::is_ready() +{ + return NSAPI_ERROR_OK; +} + nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) { return NSAPI_ERROR_OK; diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index d5a383456e..1a2918be3b 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -64,8 +64,3 @@ void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback callbac { } - -nsapi_error_t AT_CellularPower::is_device_ready() -{ - return NSAPI_ERROR_OK; -} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 1e5e4c8078..8a7cb9199a 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -109,6 +109,11 @@ public: virtual void modem_debug_on(bool on) {} + virtual nsapi_error_t is_ready() + { + return NSAPI_ERROR_OK; + } + nsapi_error_t set_power_save_mode(int periodic_time, int active_time) { return NSAPI_ERROR_OK; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index cb7b0378a0..1a24939bb7 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -64,7 +64,7 @@ static void wait_for_power(CellularPower *pwr) err = pwr->set_at_mode(); } - TEST_ASSERT(pwr->is_device_ready() == NSAPI_ERROR_OK); + TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK); pwr->remove_device_ready_urc_cb(&urc_callback); } diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index d79a250e6b..9461e7a28c 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -250,6 +250,13 @@ public: */ virtual void modem_debug_on(bool on) = 0; + /** Check whether the device is ready to accept commands. + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t is_ready() = 0; + /** Set power save mode * * @remark See 3GPP TS 27.007 PSM for details diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index 61246df5ed..c3293be4de 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -93,13 +93,6 @@ public: */ virtual nsapi_error_t reset() = 0; - /** Check whether the device is ready to accept commands. - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t is_device_ready() = 0; - /** Set URC callback function for device specific ready urc. URC is defined in device specific * power API. Used in startup sequence to listen when device is ready * for using at commands and possible sim. diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 1c987cc200..49195f9016 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -366,6 +366,21 @@ void AT_CellularDevice::modem_debug_on(bool on) ATHandler::set_debug_list(_modem_debug_on); } +nsapi_error_t AT_CellularDevice::is_ready() +{ + _at->lock(); + _at->cmd_start("AT"); + _at->cmd_stop_read_resp(); + + // we need to do this twice because for example after data mode the first 'AT' command will give modem a + // stimulus that we are back to command mode. + _at->clear_error(); + _at->cmd_start("AT"); + _at->cmd_stop_read_resp(); + + return _at->unlock_return_error(); +} + nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) { _at->lock(); diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 90808303c7..33c373054d 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -70,6 +70,8 @@ public: virtual void modem_debug_on(bool on); + virtual nsapi_error_t is_ready(); + virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); virtual nsapi_error_t init_module(); diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index 5889b1e900..a6216c36fc 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -74,21 +74,6 @@ nsapi_error_t AT_CellularPower::reset() return _at.unlock_return_error(); } -nsapi_error_t AT_CellularPower::is_device_ready() -{ - _at.lock(); - _at.cmd_start("AT"); - _at.cmd_stop_read_resp(); - - // we need to do this twice because for example after data mode the first 'AT' command will give modem a - // stimulus that we are back to command mode. - _at.clear_error(); - _at.cmd_start("AT"); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); -} - nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) { return NSAPI_ERROR_UNSUPPORTED; diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index bc34586934..6a261d82e9 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -44,8 +44,6 @@ public: virtual nsapi_error_t reset(); - virtual nsapi_error_t is_device_ready(); - virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback callback); virtual void remove_device_ready_urc_cb(mbed::Callback callback); diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index 2fb57a22c9..b0a2b94e1e 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -339,7 +339,7 @@ void CellularStateMachine::state_init() if (!_power) { _power = _cellularDevice.open_power(); } - _cb_data.error = _power->is_device_ready(); + _cb_data.error = _cellularDevice.is_ready(); if (_cb_data.error != NSAPI_ERROR_OK) { _event_timeout = _start_time; if (_start_time > 0) {