Skip to content

Commit e49f90f

Browse files
author
Ari Parkkila
committed
Cellular: Move device_ready from power to device
1 parent 38f79a9 commit e49f90f

File tree

13 files changed

+47
-42
lines changed

13 files changed

+47
-42
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
232232
dev.close_sms();
233233
}
234234

235+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready)
236+
{
237+
EventQueue que;
238+
FileHandle_stub fh1;
239+
ATHandler at(&fh1, que, 0, ",");
240+
241+
AT_CellularDevice dev(&fh1);
242+
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
243+
EXPECT_TRUE(NSAPI_ERROR_OK == dev.is_ready());
244+
}
245+
235246
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_power_save_mode)
236247
{
237248
EventQueue que;

UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset)
123123
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
124124
}
125125

126-
TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready)
127-
{
128-
EventQueue que;
129-
FileHandle_stub fh1;
130-
ATHandler at(&fh1, que, 0, ",");
131-
132-
AT_CellularPower pow(at);
133-
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
134-
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready());
135-
}
136-
137126
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb)
138127
{
139128
EventQueue que;

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ void AT_CellularDevice::modem_debug_on(bool on)
151151

152152
}
153153

154+
nsapi_error_t AT_CellularDevice::is_ready()
155+
{
156+
return NSAPI_ERROR_OK;
157+
}
158+
154159
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
155160
{
156161
return NSAPI_ERROR_OK;

UNITTESTS/stubs/AT_CellularPower_stub.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,3 @@ void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callbac
6464
{
6565

6666
}
67-
68-
nsapi_error_t AT_CellularPower::is_device_ready()
69-
{
70-
return NSAPI_ERROR_OK;
71-
}

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ class myCellularDevice : public CellularDevice {
109109

110110
virtual void modem_debug_on(bool on) {}
111111

112+
virtual nsapi_error_t is_ready()
113+
{
114+
return NSAPI_ERROR_OK;
115+
}
116+
112117
nsapi_error_t set_power_save_mode(int periodic_time, int active_time)
113118
{
114119
return NSAPI_ERROR_OK;

features/cellular/TESTS/api/cellular_power/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void wait_for_power(CellularPower *pwr)
6464
err = pwr->set_at_mode();
6565
}
6666

67-
TEST_ASSERT(pwr->is_device_ready() == NSAPI_ERROR_OK);
67+
TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK);
6868

6969
pwr->remove_device_ready_urc_cb(&urc_callback);
7070
}

features/cellular/framework/API/CellularDevice.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ class CellularDevice {
250250
*/
251251
virtual void modem_debug_on(bool on) = 0;
252252

253+
/** Check whether the device is ready to accept commands.
254+
*
255+
* @return NSAPI_ERROR_OK on success
256+
* NSAPI_ERROR_DEVICE_ERROR on failure
257+
*/
258+
virtual nsapi_error_t is_ready() = 0;
259+
253260
/** Set power save mode
254261
*
255262
* @remark See 3GPP TS 27.007 PSM for details

features/cellular/framework/API/CellularPower.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ class CellularPower {
9393
*/
9494
virtual nsapi_error_t reset() = 0;
9595

96-
/** Check whether the device is ready to accept commands.
97-
*
98-
* @return NSAPI_ERROR_OK on success
99-
* NSAPI_ERROR_DEVICE_ERROR on failure
100-
*/
101-
virtual nsapi_error_t is_device_ready() = 0;
102-
10396
/** Set URC callback function for device specific ready urc. URC is defined in device specific
10497
* power API. Used in startup sequence to listen when device is ready
10598
* for using at commands and possible sim.

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,21 @@ void AT_CellularDevice::modem_debug_on(bool on)
366366
ATHandler::set_debug_list(_modem_debug_on);
367367
}
368368

369+
nsapi_error_t AT_CellularDevice::is_ready()
370+
{
371+
_at->lock();
372+
_at->cmd_start("AT");
373+
_at->cmd_stop_read_resp();
374+
375+
// we need to do this twice because for example after data mode the first 'AT' command will give modem a
376+
// stimulus that we are back to command mode.
377+
_at->clear_error();
378+
_at->cmd_start("AT");
379+
_at->cmd_stop_read_resp();
380+
381+
return _at->unlock_return_error();
382+
}
383+
369384
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
370385
{
371386
_at->lock();

features/cellular/framework/AT/AT_CellularDevice.h

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

7171
virtual void modem_debug_on(bool on);
7272

73+
virtual nsapi_error_t is_ready();
74+
7375
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
7476

7577
virtual nsapi_error_t init_module();

0 commit comments

Comments
 (0)