Skip to content

Commit 7f7ffbe

Browse files
author
Ari Parkkila
committed
Cellular: Move ready_cb from power to device
1 parent 6ec5f79 commit 7f7ffbe

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
@@ -372,3 +372,17 @@ TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_get_sim_state)
372372

373373
delete dev;
374374
}
375+
376+
static void device_ready_cb()
377+
{
378+
}
379+
380+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_ready_cb)
381+
{
382+
EventQueue que;
383+
FileHandle_stub fh1;
384+
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
385+
386+
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(&device_ready_cb));
387+
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(0));
388+
}

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
@@ -149,9 +149,14 @@ nsapi_error_t AT_CellularDevice::is_ready()
149149
return NSAPI_ERROR_OK;
150150
}
151151

152+
nsapi_error_t AT_CellularDevice::set_ready_cb(mbed::Callback<void()> callback)
153+
{
154+
return NSAPI_ERROR_UNSUPPORTED;
155+
}
156+
152157
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
153158
{
154-
return NSAPI_ERROR_OK;
159+
return NSAPI_ERROR_UNSUPPORTED;
155160
}
156161

157162
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
@@ -255,6 +255,16 @@ class CellularDevice {
255255
*/
256256
virtual nsapi_error_t is_ready() = 0;
257257

258+
/** Set callback function to listen when device is ready.
259+
*
260+
* @param callback function to call on device ready, or NULL to remove callback.
261+
*
262+
* @return NSAPI_ERROR_OK on success
263+
* NSAPI_ERROR_NO_MEMORY on memory failure
264+
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
265+
*/
266+
virtual nsapi_error_t set_ready_cb(Callback<void()> callback) = 0;
267+
258268
/** Set power save mode
259269
*
260270
* @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
@@ -415,6 +415,11 @@ nsapi_error_t AT_CellularDevice::is_ready()
415415
return _at->unlock_return_error();
416416
}
417417

418+
nsapi_error_t AT_CellularDevice::set_ready_cb(Callback<void()> callback)
419+
{
420+
return NSAPI_ERROR_UNSUPPORTED;
421+
}
422+
418423
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
419424
{
420425
_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();

features/cellular/framework/AT/AT_CellularPower.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,3 @@ nsapi_error_t AT_CellularPower::reset()
7373
_at.cmd_stop_read_resp();
7474
return _at.unlock_return_error();
7575
}
76-
77-
nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
78-
{
79-
return NSAPI_ERROR_UNSUPPORTED;
80-
}
81-
82-
void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
83-
{
84-
}

features/cellular/framework/AT/AT_CellularPower.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ class AT_CellularPower : public CellularPower, public AT_CellularBase {
4343
virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0);
4444

4545
virtual nsapi_error_t reset();
46-
47-
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback);
48-
49-
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback);
5046
};
5147

5248
} // namespace mbed

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ bool CellularStateMachine::device_ready()
385385
if (_event_status_cb) {
386386
_event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t)&_cb_data);
387387
}
388-
389-
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb));
388+
_cellularDevice.set_ready_cb(0);
390389
_cellularDevice.close_power();
391390
_power = NULL;
392391
return true;
@@ -404,7 +403,7 @@ void CellularStateMachine::state_device_ready()
404403
}
405404
} else {
406405
if (_retry_count == 0) {
407-
_power->set_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb));
406+
_cellularDevice.set_ready_cb(callback(this, &CellularStateMachine::device_ready_cb));
408407
}
409408
retry_state_or_fail();
410409
}

features/cellular/framework/device/CellularStateMachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class CellularStateMachine {
154154
bool is_registered_to_plmn();
155155
void report_failure(const char *msg);
156156
void event();
157-
void ready_urc_cb();
157+
void device_ready_cb();
158158
void pre_event(CellularState state);
159159
bool check_is_target_reached();
160160

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ using namespace events;
3232
#define MAX_STARTUP_TRIALS 5
3333
#define MAX_RESET_TRIALS 5
3434

35+
#define DEVICE_READY_URC "CPIN:"
36+
3537
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
3638
AT_CellularBase::AT_CGSN_WITH_TYPE,
3739
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
@@ -61,7 +63,3 @@ AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char
6163
return new QUECTEL_BG96_CellularContext(at, this, apn);
6264
}
6365

64-
AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at)
65-
{
66-
return new QUECTEL_BG96_CellularInformation(at);
67-
}

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class QUECTEL_BG96 : public AT_CellularDevice {
3232
virtual AT_CellularPower *open_power_impl(ATHandler &at);
3333
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
3434
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
35+
virtual nsapi_error_t set_ready_cb(Callback<void()> callback);
36+
3537
public:
3638
void handle_urc(FileHandle *fh);
3739
};

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,3 @@ using namespace mbed;
2424
QUECTEL_BG96_CellularPower::QUECTEL_BG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
2525
{
2626
}
27-
28-
nsapi_error_t QUECTEL_BG96_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
29-
{
30-
return _at.set_urc_handler(DEVICE_READY_URC, callback);
31-
}
32-
33-
void QUECTEL_BG96_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
34-
{
35-
_at.set_urc_handler(DEVICE_READY_URC, 0);
36-
}

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ namespace mbed {
2525
class QUECTEL_BG96_CellularPower : public AT_CellularPower {
2626
public:
2727
QUECTEL_BG96_CellularPower(ATHandler &atHandler);
28-
29-
public: //from CellularPower
30-
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback);
31-
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback);
3228
};
3329

3430
} // namespace mbed

0 commit comments

Comments
 (0)