Skip to content

Commit 2dde5a4

Browse files
author
Ari Parkkila
committed
Cellular: Move ready_cb from power to device
1 parent 19b2494 commit 2dde5a4

File tree

18 files changed

+51
-94
lines changed

18 files changed

+51
-94
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,17 @@ TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_get_sim_state)
398398

399399
delete dev;
400400
}
401+
402+
static void device_ready_cb()
403+
{
404+
}
405+
406+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_ready_cb)
407+
{
408+
EventQueue que;
409+
FileHandle_stub fh1;
410+
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
411+
412+
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(&device_ready_cb));
413+
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(0));
414+
}

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ class TestAT_CellularPower : public testing::Test {
4141
// *INDENT-ON*
4242

4343

44-
static void device_ready_cb()
45-
{
46-
}
47-
4844
TEST_F(TestAT_CellularPower, Create)
4945
{
5046

@@ -122,27 +118,3 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset)
122118
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
123119
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
124120
}
125-
126-
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb)
127-
{
128-
EventQueue que;
129-
FileHandle_stub fh1;
130-
ATHandler at(&fh1, que, 0, ",");
131-
132-
AT_CellularPower pow(at);
133-
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
134-
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL));
135-
}
136-
137-
TEST_F(TestAT_CellularPower, test_AT_CellularPower_remove_device_ready_urc_cb)
138-
{
139-
EventQueue que;
140-
FileHandle_stub fh1;
141-
ATHandler at(&fh1, que, 0, ",");
142-
143-
AT_CellularPower pow(at);
144-
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
145-
146-
pow.remove_device_ready_urc_cb(NULL);
147-
pow.remove_device_ready_urc_cb(&device_ready_cb);
148-
}

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,14 @@ nsapi_error_t AT_CellularDevice::is_ready()
156156
return NSAPI_ERROR_OK;
157157
}
158158

159+
nsapi_error_t AT_CellularDevice::set_ready_cb(mbed::Callback<void()> callback)
160+
{
161+
return NSAPI_ERROR_UNSUPPORTED;
162+
}
163+
159164
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
160165
{
161-
return NSAPI_ERROR_OK;
166+
return NSAPI_ERROR_UNSUPPORTED;
162167
}
163168

164169
nsapi_error_t AT_CellularDevice::init_module()

UNITTESTS/stubs/AT_CellularPower_stub.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,3 @@ nsapi_error_t AT_CellularPower::reset()
5454
{
5555
return NSAPI_ERROR_OK;
5656
}
57-
58-
nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
59-
{
60-
return NSAPI_ERROR_OK;
61-
}
62-
63-
void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
64-
{
65-
66-
}

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class myCellularDevice : public CellularDevice {
114114
return NSAPI_ERROR_OK;
115115
}
116116

117+
virtual nsapi_error_t set_ready_cb(Callback<void()> callback)
118+
{
119+
return NSAPI_ERROR_UNSUPPORTED;
120+
}
121+
117122
nsapi_error_t set_power_save_mode(int periodic_time, int active_time)
118123
{
119124
return NSAPI_ERROR_OK;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void urc_callback()
5252

5353
static void wait_for_power(CellularPower *pwr)
5454
{
55-
nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback);
55+
nsapi_error_t err = cellular_device->set_ready_cb(&urc_callback);
5656
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
5757

5858
int sanity_count = 0;
@@ -66,7 +66,7 @@ static void wait_for_power(CellularPower *pwr)
6666

6767
TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK);
6868

69-
pwr->remove_device_ready_urc_cb(&urc_callback);
69+
TEST_ASSERT(cellular_device->set_ready_cb(0) == NSAPI_ERROR_OK);
7070
}
7171

7272
static void test_power_interface()

features/cellular/framework/API/CellularDevice.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ class CellularDevice {
257257
*/
258258
virtual nsapi_error_t is_ready() = 0;
259259

260+
/** Set callback function to listen when device is ready.
261+
*
262+
* @param callback function to call on device ready, or NULL to remove callback.
263+
*
264+
* @return NSAPI_ERROR_OK on success
265+
* NSAPI_ERROR_NO_MEMORY on memory failure
266+
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
267+
*/
268+
virtual nsapi_error_t set_ready_cb(Callback<void()> callback) = 0;
269+
260270
/** Set power save mode
261271
*
262272
* @remark See 3GPP TS 27.007 PSM for details

features/cellular/framework/API/CellularPower.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,6 @@ class CellularPower {
9292
* NSAPI_ERROR_DEVICE_ERROR on failure
9393
*/
9494
virtual nsapi_error_t reset() = 0;
95-
96-
/** Set URC callback function for device specific ready urc. URC is defined in device specific
97-
* power API. Used in startup sequence to listen when device is ready
98-
* for using at commands and possible sim.
99-
*
100-
* @param callback Callback function called when urc received
101-
*
102-
* @return NSAPI_ERROR_OK on success
103-
* NSAPI_ERROR_NO_MEMORY on memory failure
104-
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
105-
*/
106-
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback) = 0;
107-
108-
/** Removes the device ready urc from the list of urc's.
109-
*
110-
* @param callback callback to remove from the list of urc's
111-
*/
112-
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback) = 0;
11395
};
11496

11597
} // namespace mbed

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ nsapi_error_t AT_CellularDevice::is_ready()
381381
return _at->unlock_return_error();
382382
}
383383

384+
nsapi_error_t AT_CellularDevice::set_ready_cb(Callback<void()> callback)
385+
{
386+
return NSAPI_ERROR_UNSUPPORTED;
387+
}
388+
384389
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
385390
{
386391
_at->lock();

features/cellular/framework/AT/AT_CellularDevice.h

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

7373
virtual nsapi_error_t is_ready();
7474

75+
virtual nsapi_error_t set_ready_cb(Callback<void()> callback);
76+
7577
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
7678

7779
virtual nsapi_error_t init_module();

0 commit comments

Comments
 (0)