Skip to content

Commit c7486b2

Browse files
author
Ari Parkkila
committed
Cellular: Added shutdown()
1 parent bdddb44 commit c7486b2

File tree

14 files changed

+94
-7
lines changed

14 files changed

+94
-7
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
@@ -246,6 +246,13 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_reset)
246246
EXPECT_EQ(dev.reset(), NSAPI_ERROR_OK);
247247
}
248248

249+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_shutdown)
250+
{
251+
FileHandle_stub fh1;
252+
AT_CellularDevice dev(&fh1);
253+
EXPECT_EQ(dev.shutdown(), NSAPI_ERROR_OK);
254+
}
255+
249256
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready)
250257
{
251258
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
@@ -176,6 +176,11 @@ nsapi_error_t AT_CellularDevice::reset()
176176
return NSAPI_ERROR_OK;
177177
}
178178

179+
nsapi_error_t AT_CellularDevice::shutdown()
180+
{
181+
return NSAPI_ERROR_OK;
182+
}
183+
179184
nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
180185
{
181186
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"
@@ -263,12 +262,21 @@ class CellularDevice {
263262
virtual nsapi_error_t init() = 0;
264263

265264
/** Reset and wake-up cellular device.
265+
*
266+
* @remark reset calls shutdown implicitly.
266267
*
267268
* @return NSAPI_ERROR_OK on success
268269
* NSAPI_ERROR_DEVICE_ERROR on failure
269270
*/
270271
virtual nsapi_error_t reset() = 0;
271272

273+
/** Shutdown cellular device to minimum functionality.
274+
*
275+
* @return NSAPI_ERROR_OK on success
276+
* NSAPI_ERROR_DEVICE_ERROR on failure
277+
*/
278+
virtual nsapi_error_t shutdown();
279+
272280
/** Check whether the device is ready to accept commands.
273281
*
274282
* @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"
@@ -375,16 +376,30 @@ nsapi_error_t AT_CellularDevice::init()
375376

376377
_at->cmd_start("AT+CMEE=1"); // verbose responses
377378
_at->cmd_stop_read_resp();
379+
380+
_at->cmd_start("AT+CFUN=1"); // set full functionality
381+
_at->cmd_stop_read_resp();
382+
378383
return _at->unlock_return_error();
379384
}
380385

381386
nsapi_error_t AT_CellularDevice::reset()
387+
{
388+
_at->lock();
389+
shutdown();
390+
_at->cmd_start("AT+CFUN=1,1");// reset to full functionality
391+
_at->cmd_stop_read_resp();
392+
return _at->unlock_return_error();
393+
}
394+
395+
nsapi_error_t AT_CellularDevice::shutdown()
382396
{
383397
_at->lock();
384398
if (_state_machine) {
385399
_state_machine->reset();
386400
}
387-
_at->cmd_start("AT+CFUN=1,1");// reset to full power levels
401+
CellularDevice::shutdown();
402+
_at->cmd_start("AT+CFUN=0");// set to minimum functionality
388403
_at->cmd_stop_read_resp();
389404
return _at->unlock_return_error();
390405
}

0 commit comments

Comments
 (0)