Skip to content

Commit c4de2f2

Browse files
author
Ari Parkkila
committed
Cellular: Power API updated to match onboard_modem_api
1 parent 269d151 commit c4de2f2

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
@@ -209,13 +209,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init)
209209
EXPECT_EQ(dev.init(), NSAPI_ERROR_OK);
210210
}
211211

212-
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_reset)
213-
{
214-
FileHandle_stub fh1;
215-
AT_CellularDevice dev(&fh1);
216-
EXPECT_EQ(dev.reset(), NSAPI_ERROR_OK);
217-
}
218-
219212
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_shutdown)
220213
{
221214
FileHandle_stub fh1;

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,6 @@ nsapi_error_t AT_CellularDevice::init()
179179
return AT_CellularDevice_stub::nsapi_error_value;
180180
}
181181

182-
nsapi_error_t AT_CellularDevice::reset()
183-
{
184-
if (AT_CellularDevice_stub::init_module_failure_count) {
185-
AT_CellularDevice_stub::init_module_failure_count--;
186-
return NSAPI_ERROR_DEVICE_ERROR;
187-
}
188-
return AT_CellularDevice_stub::nsapi_error_value;
189-
}
190-
191182
nsapi_error_t AT_CellularDevice::shutdown()
192183
{
193184
if (AT_CellularDevice_stub::init_module_failure_count) {
@@ -223,12 +214,22 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
223214
return AT_CellularDevice_stub::nsapi_error_value;
224215
}
225216

226-
nsapi_error_t AT_CellularDevice::power_on()
217+
nsapi_error_t AT_CellularDevice::hard_power_on()
227218
{
228-
return NSAPI_ERROR_UNSUPPORTED;
219+
return NSAPI_ERROR_OK;
229220
}
230221

231-
nsapi_error_t AT_CellularDevice::power_off()
222+
nsapi_error_t AT_CellularDevice::hard_power_off()
232223
{
233-
return NSAPI_ERROR_UNSUPPORTED;
224+
return NSAPI_ERROR_OK;
225+
}
226+
227+
nsapi_error_t AT_CellularDevice::soft_power_on()
228+
{
229+
return NSAPI_ERROR_OK;
230+
}
231+
232+
nsapi_error_t AT_CellularDevice::soft_power_off()
233+
{
234+
return NSAPI_ERROR_OK;
234235
}

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
@@ -84,23 +84,42 @@ class CellularDevice {
8484
*/
8585
virtual ~CellularDevice();
8686

87-
/** Set cellular device power on.
87+
/** Set cellular device power supply on.
8888
*
89-
* @post init must be called after power_on to setup module
89+
* CellularStateMachine calls hard_power_on, soft_power_on and init when requested to connect
90+
* if the modem is not responding.
91+
*
92+
* @post You must call soft_power_on to power on the modem after calling hard_power_on.
93+
*
94+
* @return NSAPI_ERROR_OK on success
95+
*/
96+
virtual nsapi_error_t hard_power_on() = 0;
97+
98+
/** Set cellular device power supply off.
99+
*
100+
* CellularStateMachine disconnect does not shutdown or power off the modem.
101+
*
102+
* @pre You must call soft_power_off to power off the modem before calling hard_power_off.
103+
*
104+
* @return NSAPI_ERROR_OK on success
105+
*/
106+
virtual nsapi_error_t hard_power_off() = 0;
107+
108+
/** Set cellular device power on, i.e. start the modem.
109+
*
110+
* @post You must call init to setup the modem.
90111
*
91112
* @return NSAPI_ERROR_OK on success
92-
* NSAPI_ERROR_UNSUPPORTED if there is no implementation
93113
*/
94-
virtual nsapi_error_t power_on() = 0;
114+
virtual nsapi_error_t soft_power_on() = 0;
95115

96116
/** Set cellular device power off.
97117
*
98-
* @pre shutdown must be called before power_down to quit cellular network
118+
* @pre You must call shutdown to prepare the modem for power off.
99119
*
100120
* @return NSAPI_ERROR_OK on success
101-
* NSAPI_ERROR_UNSUPPORTED if there is no implementation
102121
*/
103-
virtual nsapi_error_t power_off() = 0;
122+
virtual nsapi_error_t soft_power_off() = 0;
104123

105124
/** Open the SIM card by setting the pin code for SIM.
106125
*
@@ -290,28 +309,28 @@ class CellularDevice {
290309
*/
291310
virtual void modem_debug_on(bool on) = 0;
292311

293-
/** Initialize cellular device must be called right after module is ready.
312+
/** Initialize cellular device must be called right after the module is ready.
313+
*
294314
* For example, when multiple cellular modules are supported in a single driver this function
295315
* detects and adapts to an actual module at runtime.
296316
*
317+
* CellularStateMachine calls soft_power_on and init repeatedly when starting to connect
318+
* until the modem responds.
319+
*
297320
* @return NSAPI_ERROR_OK on success
298321
* NSAPI_ERROR_NO_MEMORY on case of memory failure
299-
* NSAPI_ERROR_UNSUPPORTED if current model is not detected
322+
* NSAPI_ERROR_UNSUPPORTED if current cellular module type is not detected
300323
* NSAPI_ERROR_DEVICE_ERROR if model information could not be read
301324
*
302325
*/
303326
virtual nsapi_error_t init() = 0;
304327

305-
/** Reset and wake-up cellular device.
328+
/** Shutdown cellular device to minimum functionality.
306329
*
307-
* @remark reset calls shutdown implicitly.
330+
* Actual functionality is modem specific, for example UART may is not be responsive without
331+
* explicit wakeup signal (such as RTS) after shutdown.
308332
*
309-
* @return NSAPI_ERROR_OK on success
310-
* NSAPI_ERROR_DEVICE_ERROR on failure
311-
*/
312-
virtual nsapi_error_t reset() = 0;
313-
314-
/** Shutdown cellular device to minimum functionality.
333+
* @remark You must call shutdown before power off to prepare the modem and to quit cellular network.
315334
*
316335
* @return NSAPI_ERROR_OK on success
317336
* 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
@@ -69,14 +69,24 @@ AT_CellularDevice::~AT_CellularDevice()
6969
release_at_handler(_at);
7070
}
7171

72-
nsapi_error_t AT_CellularDevice::power_on()
72+
nsapi_error_t AT_CellularDevice::hard_power_on()
7373
{
74-
return NSAPI_ERROR_UNSUPPORTED;
74+
return NSAPI_ERROR_OK;
7575
}
7676

77-
nsapi_error_t AT_CellularDevice::power_off()
77+
nsapi_error_t AT_CellularDevice::hard_power_off()
7878
{
79-
return NSAPI_ERROR_UNSUPPORTED;
79+
return NSAPI_ERROR_OK;
80+
}
81+
82+
nsapi_error_t AT_CellularDevice::soft_power_on()
83+
{
84+
return NSAPI_ERROR_OK;
85+
}
86+
87+
nsapi_error_t AT_CellularDevice::soft_power_off()
88+
{
89+
return NSAPI_ERROR_OK;
8090
}
8191

8292
// each parser is associated with one filehandle (that is UART)
@@ -355,15 +365,6 @@ nsapi_error_t AT_CellularDevice::init()
355365
return _at->unlock_return_error();
356366
}
357367

358-
nsapi_error_t AT_CellularDevice::reset()
359-
{
360-
_at->lock();
361-
shutdown();
362-
_at->cmd_start("AT+CFUN=1,1");// reset to full functionality
363-
_at->cmd_stop_read_resp();
364-
return _at->unlock_return_error();
365-
}
366-
367368
nsapi_error_t AT_CellularDevice::shutdown()
368369
{
369370
_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
@@ -109,13 +109,9 @@ void CellularStateMachine::stop()
109109

110110
bool CellularStateMachine::power_on()
111111
{
112-
_cb_data.error = _cellularDevice.power_on();
113-
if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) {
114-
tr_warn("Power on failed. Try to power off/on.");
115-
_cb_data.error = _cellularDevice.power_off();
116-
if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) {
117-
tr_error("Power off failed!");
118-
}
112+
_cb_data.error = _cellularDevice.hard_power_on();
113+
if (_cb_data.error != NSAPI_ERROR_OK) {
114+
tr_warn("Power on failed.");
119115
return false;
120116
}
121117
return true;
@@ -384,14 +380,16 @@ bool CellularStateMachine::device_ready()
384380
void CellularStateMachine::state_device_ready()
385381
{
386382
_cellularDevice.set_timeout(TIMEOUT_POWER_ON);
387-
_cb_data.error = _cellularDevice.init();
383+
_cb_data.error = _cellularDevice.soft_power_on();
388384
if (_cb_data.error == NSAPI_ERROR_OK) {
389-
if (device_ready()) {
390-
enter_to_state(STATE_SIM_PIN);
391-
} else {
392-
retry_state_or_fail();
385+
_cb_data.error = _cellularDevice.init();
386+
if (_cb_data.error == NSAPI_ERROR_OK) {
387+
if (device_ready()) {
388+
enter_to_state(STATE_SIM_PIN);
389+
}
393390
}
394-
} else {
391+
}
392+
if (_cb_data.error != NSAPI_ERROR_OK) {
395393
if (_retry_count == 0) {
396394
_cellularDevice.set_ready_cb(callback(this, &CellularStateMachine::device_ready_cb));
397395
}

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)