Cellular: Move device_ready from power to device

pull/9472/head
Ari Parkkila 2018-11-28 02:36:46 -08:00
parent 38f79a9b65
commit e49f90fb0b
13 changed files with 47 additions and 42 deletions

View File

@ -232,6 +232,17 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
dev.close_sms(); 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) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_power_save_mode)
{ {
EventQueue que; EventQueue que;

View File

@ -123,17 +123,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset)
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.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) TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb)
{ {
EventQueue que; EventQueue que;

View File

@ -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) nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;

View File

@ -64,8 +64,3 @@ void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callbac
{ {
} }
nsapi_error_t AT_CellularPower::is_device_ready()
{
return NSAPI_ERROR_OK;
}

View File

@ -109,6 +109,11 @@ public:
virtual void modem_debug_on(bool on) {} 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) nsapi_error_t set_power_save_mode(int periodic_time, int active_time)
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;

View File

@ -64,7 +64,7 @@ static void wait_for_power(CellularPower *pwr)
err = pwr->set_at_mode(); 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); pwr->remove_device_ready_urc_cb(&urc_callback);
} }

View File

@ -250,6 +250,13 @@ public:
*/ */
virtual void modem_debug_on(bool on) = 0; 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 /** Set power save mode
* *
* @remark See 3GPP TS 27.007 PSM for details * @remark See 3GPP TS 27.007 PSM for details

View File

@ -93,13 +93,6 @@ public:
*/ */
virtual nsapi_error_t reset() = 0; 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 /** 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 * power API. Used in startup sequence to listen when device is ready
* for using at commands and possible sim. * for using at commands and possible sim.

View File

@ -366,6 +366,21 @@ void AT_CellularDevice::modem_debug_on(bool on)
ATHandler::set_debug_list(_modem_debug_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) nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
{ {
_at->lock(); _at->lock();

View File

@ -70,6 +70,8 @@ public:
virtual void modem_debug_on(bool on); 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 set_power_save_mode(int periodic_time, int active_time = 0);
virtual nsapi_error_t init_module(); virtual nsapi_error_t init_module();

View File

@ -74,21 +74,6 @@ nsapi_error_t AT_CellularPower::reset()
return _at.unlock_return_error(); 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<void()> callback) nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
{ {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;

View File

@ -44,8 +44,6 @@ public:
virtual nsapi_error_t reset(); virtual nsapi_error_t reset();
virtual nsapi_error_t is_device_ready();
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback); virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback);
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback); virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback);

View File

@ -339,7 +339,7 @@ void CellularStateMachine::state_init()
if (!_power) { if (!_power) {
_power = _cellularDevice.open_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) { if (_cb_data.error != NSAPI_ERROR_OK) {
_event_timeout = _start_time; _event_timeout = _start_time;
if (_start_time > 0) { if (_start_time > 0) {