Skip to content

Commit 84216a5

Browse files
author
Ari Parkkila
committed
Cellular: Power API updated to match onboard_modem_api
1 parent d3b4caf commit 84216a5

File tree

28 files changed

+248
-132
lines changed

28 files changed

+248
-132
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init)
200200
EXPECT_EQ(dev.init(), NSAPI_ERROR_OK);
201201
}
202202

203-
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_reset)
204-
{
205-
FileHandle_stub fh1;
206-
AT_CellularDevice dev(&fh1);
207-
EXPECT_EQ(dev.reset(), NSAPI_ERROR_OK);
208-
}
209-
210203
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_shutdown)
211204
{
212205
FileHandle_stub fh1;

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,6 @@ nsapi_error_t AT_CellularDevice::init()
173173
return AT_CellularDevice_stub::nsapi_error_value;
174174
}
175175

176-
nsapi_error_t AT_CellularDevice::reset()
177-
{
178-
if (AT_CellularDevice_stub::init_module_failure_count) {
179-
AT_CellularDevice_stub::init_module_failure_count--;
180-
return NSAPI_ERROR_DEVICE_ERROR;
181-
}
182-
return AT_CellularDevice_stub::nsapi_error_value;
183-
}
184-
185176
nsapi_error_t AT_CellularDevice::shutdown()
186177
{
187178
if (AT_CellularDevice_stub::init_module_failure_count) {
@@ -217,12 +208,22 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
217208
return AT_CellularDevice_stub::nsapi_error_value;
218209
}
219210

220-
nsapi_error_t AT_CellularDevice::power_on()
211+
nsapi_error_t AT_CellularDevice::hard_power_on()
221212
{
222-
return NSAPI_ERROR_UNSUPPORTED;
213+
return NSAPI_ERROR_OK;
223214
}
224215

225-
nsapi_error_t AT_CellularDevice::power_off()
216+
nsapi_error_t AT_CellularDevice::hard_power_off()
226217
{
227-
return NSAPI_ERROR_UNSUPPORTED;
218+
return NSAPI_ERROR_OK;
219+
}
220+
221+
nsapi_error_t AT_CellularDevice::soft_power_on()
222+
{
223+
return NSAPI_ERROR_OK;
224+
}
225+
226+
nsapi_error_t AT_CellularDevice::soft_power_off()
227+
{
228+
return NSAPI_ERROR_OK;
228229
}

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,34 @@ class myCellularDevice : public CellularDevice {
112112
return NSAPI_ERROR_OK;
113113
}
114114

115-
virtual nsapi_error_t reset()
115+
virtual nsapi_error_t shutdown()
116116
{
117117
return NSAPI_ERROR_OK;
118118
}
119119

120-
virtual nsapi_error_t shutdown()
120+
virtual nsapi_error_t is_ready()
121121
{
122122
return NSAPI_ERROR_OK;
123123
}
124124

125-
virtual nsapi_error_t is_ready()
125+
virtual nsapi_error_t hard_power_on()
126+
{
127+
return NSAPI_ERROR_OK;
128+
}
129+
130+
virtual nsapi_error_t hard_power_off()
126131
{
127132
return NSAPI_ERROR_OK;
128133
}
129134

130-
virtual nsapi_error_t power_on()
135+
virtual nsapi_error_t soft_power_on()
131136
{
132-
return NSAPI_ERROR_UNSUPPORTED;
137+
return NSAPI_ERROR_OK;
133138
}
134139

135-
virtual nsapi_error_t power_off()
140+
virtual nsapi_error_t soft_power_off()
136141
{
137-
return NSAPI_ERROR_UNSUPPORTED;
142+
return NSAPI_ERROR_OK;
138143
}
139144

140145
virtual void set_ready_cb(Callback<void()> callback)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ static void shutdown_reset()
108108
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
109109
TEST_ASSERT(device->shutdown() == NSAPI_ERROR_OK);
110110
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
111-
TEST_ASSERT(device->reset() == NSAPI_ERROR_OK);
112-
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
113111
}
114112

115113
static void delete_device()

features/cellular/framework/API/CellularDevice.h

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,42 @@ class CellularDevice {
7676
*/
7777
virtual ~CellularDevice();
7878

79-
/** Set cellular device power on.
79+
/** Set cellular device power supply on.
8080
*
81-
* @post init must be called after power_on to setup module
81+
* CellularStateMachine calls hard_power_on, soft_power_on and init when requested to connect
82+
* if the modem is not responding.
83+
*
84+
* @post You must call soft_power_on to power on the modem after calling hard_power_on.
85+
*
86+
* @return NSAPI_ERROR_OK on success
87+
*/
88+
virtual nsapi_error_t hard_power_on() = 0;
89+
90+
/** Set cellular device power supply off.
91+
*
92+
* CellularStateMachine disconnect does not shutdown or power off the modem.
93+
*
94+
* @pre You must call soft_power_off to power off the modem before calling hard_power_off.
95+
*
96+
* @return NSAPI_ERROR_OK on success
97+
*/
98+
virtual nsapi_error_t hard_power_off() = 0;
99+
100+
/** Set cellular device power on, i.e. start the modem.
101+
*
102+
* @post You must call init to setup the modem.
82103
*
83104
* @return NSAPI_ERROR_OK on success
84-
* NSAPI_ERROR_UNSUPPORTED if there is no implementation
85105
*/
86-
virtual nsapi_error_t power_on() = 0;
106+
virtual nsapi_error_t soft_power_on() = 0;
87107

88108
/** Set cellular device power off.
89109
*
90-
* @pre shutdown must be called before power_down to quit cellular network
110+
* @pre You must call shutdown to prepare the modem for power off.
91111
*
92112
* @return NSAPI_ERROR_OK on success
93-
* NSAPI_ERROR_UNSUPPORTED if there is no implementation
94113
*/
95-
virtual nsapi_error_t power_off() = 0;
114+
virtual nsapi_error_t soft_power_off() = 0;
96115

97116
/** Open the SIM card by setting the pin code for SIM.
98117
*
@@ -286,28 +305,28 @@ class CellularDevice {
286305
*/
287306
virtual void modem_debug_on(bool on) = 0;
288307

289-
/** Initialize cellular device must be called right after module is ready.
308+
/** Initialize cellular device must be called right after the module is ready.
309+
*
290310
* For example, when multiple cellular modules are supported in a single driver this function
291311
* detects and adapts to an actual module at runtime.
292312
*
313+
* CellularStateMachine calls soft_power_on and init repeatedly when starting to connect
314+
* until the modem responds.
315+
*
293316
* @return NSAPI_ERROR_OK on success
294317
* NSAPI_ERROR_NO_MEMORY on case of memory failure
295-
* NSAPI_ERROR_UNSUPPORTED if current model is not detected
318+
* NSAPI_ERROR_UNSUPPORTED if current cellular module type is not detected
296319
* NSAPI_ERROR_DEVICE_ERROR if model information could not be read
297320
*
298321
*/
299322
virtual nsapi_error_t init() = 0;
300323

301-
/** Reset and wake-up cellular device.
324+
/** Shutdown cellular device to minimum functionality.
302325
*
303-
* @remark reset calls shutdown implicitly.
326+
* Actual functionality is modem specific, for example UART may is not be responsive without
327+
* explicit wakeup signal (such as RTS) after shutdown.
304328
*
305-
* @return NSAPI_ERROR_OK on success
306-
* NSAPI_ERROR_DEVICE_ERROR on failure
307-
*/
308-
virtual nsapi_error_t reset() = 0;
309-
310-
/** Shutdown cellular device to minimum functionality.
329+
* @remark You must call shutdown before power off to prepare the modem and to quit cellular network.
311330
*
312331
* @return NSAPI_ERROR_OK on success
313332
* NSAPI_ERROR_DEVICE_ERROR on failure

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,24 @@ AT_CellularDevice::~AT_CellularDevice()
7272
}
7373
}
7474

75-
nsapi_error_t AT_CellularDevice::power_on()
75+
nsapi_error_t AT_CellularDevice::hard_power_on()
7676
{
77-
return NSAPI_ERROR_UNSUPPORTED;
77+
return NSAPI_ERROR_OK;
7878
}
7979

80-
nsapi_error_t AT_CellularDevice::power_off()
80+
nsapi_error_t AT_CellularDevice::hard_power_off()
8181
{
82-
return NSAPI_ERROR_UNSUPPORTED;
82+
return NSAPI_ERROR_OK;
83+
}
84+
85+
nsapi_error_t AT_CellularDevice::soft_power_on()
86+
{
87+
return NSAPI_ERROR_OK;
88+
}
89+
90+
nsapi_error_t AT_CellularDevice::soft_power_off()
91+
{
92+
return NSAPI_ERROR_OK;
8393
}
8494

8595
// each parser is associated with one filehandle (that is UART)
@@ -387,15 +397,6 @@ nsapi_error_t AT_CellularDevice::init()
387397
return _at->unlock_return_error();
388398
}
389399

390-
nsapi_error_t AT_CellularDevice::reset()
391-
{
392-
_at->lock();
393-
shutdown();
394-
_at->cmd_start("AT+CFUN=1,1");// reset to full functionality
395-
_at->cmd_stop_read_resp();
396-
return _at->unlock_return_error();
397-
}
398-
399400
nsapi_error_t AT_CellularDevice::shutdown()
400401
{
401402
_at->lock();

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ class AT_CellularDevice : public CellularDevice {
3939
AT_CellularDevice(FileHandle *fh);
4040
virtual ~AT_CellularDevice();
4141

42-
virtual nsapi_error_t power_on();
42+
virtual nsapi_error_t hard_power_on();
4343

44-
virtual nsapi_error_t power_off();
44+
virtual nsapi_error_t hard_power_off();
45+
46+
virtual nsapi_error_t soft_power_on();
47+
48+
virtual nsapi_error_t soft_power_off();
4549

4650
virtual nsapi_error_t set_pin(const char *sim_pin);
4751

@@ -73,8 +77,6 @@ class AT_CellularDevice : public CellularDevice {
7377

7478
virtual nsapi_error_t init();
7579

76-
virtual nsapi_error_t reset();
77-
7880
virtual nsapi_error_t shutdown();
7981

8082
virtual nsapi_error_t is_ready();

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,9 @@ void CellularStateMachine::stop()
107107

108108
bool CellularStateMachine::power_on()
109109
{
110-
_cb_data.error = _cellularDevice.power_on();
111-
if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) {
112-
tr_warn("Power on failed. Try to power off/on.");
113-
_cb_data.error = _cellularDevice.power_off();
114-
if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) {
115-
tr_error("Power off failed!");
116-
}
110+
_cb_data.error = _cellularDevice.hard_power_on();
111+
if (_cb_data.error != NSAPI_ERROR_OK) {
112+
tr_warn("Power on failed.");
117113
return false;
118114
}
119115
return true;
@@ -382,14 +378,16 @@ bool CellularStateMachine::device_ready()
382378
void CellularStateMachine::state_device_ready()
383379
{
384380
_cellularDevice.set_timeout(TIMEOUT_POWER_ON);
385-
_cb_data.error = _cellularDevice.init();
381+
_cb_data.error = _cellularDevice.soft_power_on();
386382
if (_cb_data.error == NSAPI_ERROR_OK) {
387-
if (device_ready()) {
388-
enter_to_state(STATE_SIM_PIN);
389-
} else {
390-
retry_state_or_fail();
383+
_cb_data.error = _cellularDevice.init();
384+
if (_cb_data.error == NSAPI_ERROR_OK) {
385+
if (device_ready()) {
386+
enter_to_state(STATE_SIM_PIN);
387+
}
391388
}
392-
} else {
389+
}
390+
if (_cb_data.error != NSAPI_ERROR_OK) {
393391
if (_retry_count == 0) {
394392
_cellularDevice.set_ready_cb(callback(this, &CellularStateMachine::device_ready_cb));
395393
}

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,6 @@ nsapi_error_t QUECTEL_BC95::init()
9191
return _at->unlock_return_error();
9292
}
9393

94-
nsapi_error_t QUECTEL_BC95::reset()
95-
{
96-
_at->lock();
97-
AT_CellularDevice::shutdown();
98-
_at->cmd_start("AT+NRB"); // reset to full power levels
99-
_at->cmd_stop();
100-
_at->resp_start("REBOOTING", true);
101-
return _at->unlock_return_error();
102-
}
103-
10494
#if MBED_CONF_QUECTEL_BC95_PROVIDE_DEFAULT
10595
#include "UARTSerial.h"
10696
CellularDevice *CellularDevice::get_default_instance()

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class QUECTEL_BC95 : public AT_CellularDevice {
4343
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
4444
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
4545
virtual nsapi_error_t init();
46-
virtual nsapi_error_t reset();
4746

4847
public: // NetworkInterface
4948
void handle_urc(FileHandle *fh);

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,27 @@ ONBOARD_UBLOX_PPP::ONBOARD_UBLOX_PPP(FileHandle *fh) : UBLOX_PPP(fh)
2525
{
2626
}
2727

28-
nsapi_error_t ONBOARD_UBLOX_PPP::power_on()
28+
nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_on()
2929
{
3030
::onboard_modem_init();
31+
return NSAPI_ERROR_OK;
32+
}
33+
34+
nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_off()
35+
{
36+
::onboard_modem_deinit();
37+
return NSAPI_ERROR_OK;
38+
}
39+
40+
nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_on()
41+
{
3142
::onboard_modem_power_up();
3243
return NSAPI_ERROR_OK;
3344
}
3445

35-
nsapi_error_t ONBOARD_UBLOX_PPP::power_off()
46+
nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_off()
3647
{
3748
::onboard_modem_power_down();
38-
::onboard_modem_deinit();
3949
return NSAPI_ERROR_OK;
4050
}
4151

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ namespace mbed {
2424
class ONBOARD_UBLOX_PPP : public UBLOX_PPP {
2525
public:
2626
ONBOARD_UBLOX_PPP(FileHandle *fh);
27-
virtual nsapi_error_t power_on();
28-
virtual nsapi_error_t power_off();
27+
28+
virtual nsapi_error_t hard_power_on();
29+
virtual nsapi_error_t hard_power_off();
30+
virtual nsapi_error_t soft_power_on();
31+
virtual nsapi_error_t soft_power_off();
2932
};
3033

3134
} // namespace mbed

0 commit comments

Comments
 (0)