Skip to content

Commit d09ee0d

Browse files
author
Ari Parkkila
committed
Cellular: Added shutdown()
1 parent 65da29d commit d09ee0d

File tree

15 files changed

+94
-10
lines changed

15 files changed

+94
-10
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_reset)
236236
EXPECT_EQ(dev.reset(), NSAPI_ERROR_OK);
237237
}
238238

239+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_shutdown)
240+
{
241+
FileHandle_stub fh1;
242+
AT_CellularDevice dev(&fh1);
243+
EXPECT_EQ(dev.shutdown(), NSAPI_ERROR_OK);
244+
}
245+
239246
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready)
240247
{
241248
EventQueue que;

UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,15 @@ TEST_F(TestCellularDevice, test_cellular_callback)
228228

229229
delete dev;
230230
}
231+
232+
TEST_F(TestCellularDevice, test_shutdown)
233+
{
234+
FileHandle_stub fh1;
235+
CellularDevice *dev = new myCellularDevice(&fh1);
236+
EXPECT_TRUE(dev);
237+
238+
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
239+
ASSERT_EQ(dev->shutdown(), NSAPI_ERROR_OK);
240+
241+
delete dev;
242+
}

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ nsapi_error_t AT_CellularDevice::reset()
169169
return NSAPI_ERROR_OK;
170170
}
171171

172+
nsapi_error_t AT_CellularDevice::shutdown()
173+
{
174+
return NSAPI_ERROR_OK;
175+
}
176+
172177
nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
173178
{
174179
return NSAPI_ERROR_OK;

UNITTESTS/stubs/CellularDevice_stub.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ nsapi_error_t CellularDevice::get_sim_state(SimState &state)
9797
{
9898
return NSAPI_ERROR_OK;
9999
}
100+
101+
nsapi_error_t CellularDevice::shutdown()
102+
{
103+
return NSAPI_ERROR_OK;
104+
}
105+

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ class myCellularDevice : public CellularDevice {
119119
return NSAPI_ERROR_OK;
120120
}
121121

122+
virtual nsapi_error_t shutdown()
123+
{
124+
return NSAPI_ERROR_OK;
125+
}
126+
122127
virtual nsapi_error_t is_ready()
123128
{
124129
return NSAPI_ERROR_OK;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ static void other_methods()
107107
TEST_ASSERT_EQUAL_INT(device->init_module(), NSAPI_ERROR_OK);
108108
}
109109

110+
static void shutdown_reset()
111+
{
112+
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
113+
TEST_ASSERT(device->shutdown() == NSAPI_ERROR_OK);
114+
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
115+
TEST_ASSERT(device->reset() == NSAPI_ERROR_OK);
116+
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
117+
}
118+
110119
static void delete_device()
111120
{
112121
// delete will close all opened interfaces
@@ -206,6 +215,8 @@ static Case cases[] = {
206215
Case("CellularDevice sim ready", continue_to_sim_ready_state, greentea_failure_handler),
207216
Case("CellularDevice register", continue_to_register_state, greentea_failure_handler),
208217
Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler)
218+
Case("CellularDevice shutdown/reset", shutdown_reset, greentea_failure_handler),
219+
Case("CellularDevice delete device", delete_device, greentea_failure_handler)
209220
};
210221

211222
static utest::v1::status_t test_setup(const size_t number_of_cases)

features/cellular/TESTS/cellular_tests_common.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,10 @@ static void trace_open()
5050

5151
mbed_cellular_trace::mutex_wait_function_set(trace_wait);
5252
mbed_cellular_trace::mutex_release_function_set(trace_release);
53-
54-
greentea_serial->set_trace_mutex(&trace_mutex);
5553
}
5654

5755
static void trace_close()
5856
{
59-
greentea_serial->set_trace_mutex(NULL);
60-
6157
mbed_cellular_trace::mutex_wait_function_set(NULL);
6258
mbed_cellular_trace::mutex_release_function_set(NULL);
6359

features/cellular/TESTS/socket/udp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#endif
3232

3333
#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
34-
//#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
34+
#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
3535
#endif
3636

3737
#include "greentea-client/test_env.h"

features/cellular/framework/API/CellularDevice.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#ifndef CELLULAR_DEVICE_H_
1919
#define CELLULAR_DEVICE_H_
2020

21-
#include "CellularUtil.h"
2221
#include "CellularTargets.h"
2322
#include "CellularStateMachine.h"
2423
#include "Callback.h"
@@ -261,12 +260,21 @@ class CellularDevice {
261260
virtual nsapi_error_t init() = 0;
262261

263262
/** Reset and wake-up cellular device.
263+
*
264+
* @remark reset calls shutdown implicitly.
264265
*
265266
* @return NSAPI_ERROR_OK on success
266267
* NSAPI_ERROR_DEVICE_ERROR on failure
267268
*/
268269
virtual nsapi_error_t reset() = 0;
269270

271+
/** Shutdown cellular device to minimum functionality.
272+
*
273+
* @return NSAPI_ERROR_OK on success
274+
* NSAPI_ERROR_DEVICE_ERROR on failure
275+
*/
276+
virtual nsapi_error_t shutdown();
277+
270278
/** Check whether the device is ready to accept commands.
271279
*
272280
* @return NSAPI_ERROR_OK on success

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include "CellularUtil.h"
1819
#include "AT_CellularDevice.h"
1920
#include "AT_CellularInformation.h"
2021
#include "AT_CellularNetwork.h"
@@ -409,16 +410,30 @@ nsapi_error_t AT_CellularDevice::init()
409410

410411
_at->cmd_start("AT+CMEE=1"); // verbose responses
411412
_at->cmd_stop_read_resp();
413+
414+
_at->cmd_start("AT+CFUN=1"); // set full functionality
415+
_at->cmd_stop_read_resp();
416+
412417
return _at->unlock_return_error();
413418
}
414419

415420
nsapi_error_t AT_CellularDevice::reset()
421+
{
422+
_at->lock();
423+
shutdown();
424+
_at->cmd_start("AT+CFUN=1,1");// reset to full functionality
425+
_at->cmd_stop_read_resp();
426+
return _at->unlock_return_error();
427+
}
428+
429+
nsapi_error_t AT_CellularDevice::shutdown()
416430
{
417431
_at->lock();
418432
if (_state_machine) {
419433
_state_machine->reset();
420434
}
421-
_at->cmd_start("AT+CFUN=1,1");// reset to full power levels
435+
CellularDevice::shutdown();
436+
_at->cmd_start("AT+CFUN=0");// set to minimum functionality
422437
_at->cmd_stop_read_resp();
423438
return _at->unlock_return_error();
424439
}

features/cellular/framework/AT/AT_CellularDevice.h

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

7575
virtual nsapi_error_t reset();
7676

77+
virtual nsapi_error_t shutdown();
78+
7779
virtual nsapi_error_t is_ready();
7880

7981
virtual nsapi_error_t set_ready_cb(Callback<void()> callback);

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,14 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
211211
}
212212
}
213213

214+
nsapi_error_t CellularDevice::shutdown()
215+
{
216+
CellularContext *curr = get_context_list();
217+
while (curr) {
218+
curr->cellular_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
219+
curr = (CellularContext *)curr->_next;
220+
}
221+
return NSAPI_ERROR_OK;
222+
}
223+
214224
} // namespace mbed

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,6 @@ void CellularStateMachine::state_power_on()
364364
bool CellularStateMachine::device_ready()
365365
{
366366
tr_info("Modem ready");
367-
if (_cellularDevice.init_module() != NSAPI_ERROR_OK) {
368-
return false;
369-
}
370367

371368
if (!_network) {
372369
_network = _cellularDevice.open_network();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ nsapi_error_t QUECTEL_BC95::init()
9797
nsapi_error_t QUECTEL_BC95::reset()
9898
{
9999
_at->lock();
100+
AT_CellularDevice::shutdown();
100101
_at->cmd_start("AT+NRB"); // reset to full power levels
101102
_at->cmd_stop();
102103
_at->resp_start("REBOOTING", true);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@ AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char
6060
return new QUECTEL_BG96_CellularContext(at, this, apn);
6161
}
6262

63+
AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at)
64+
{
65+
return new QUECTEL_BG96_CellularInformation(at);
66+
}
67+
68+
nsapi_error_t QUECTEL_BG96::set_ready_cb(Callback<void()> callback)
69+
{
70+
return _at->set_urc_handler(DEVICE_READY_URC, callback);
71+
}

0 commit comments

Comments
 (0)