Cellular: Added shutdown()

pull/9472/head
Ari Parkkila 2018-11-29 00:54:27 -08:00
parent bdddb445a6
commit c7486b2a0d
14 changed files with 94 additions and 7 deletions

View File

@ -246,6 +246,13 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_reset)
EXPECT_EQ(dev.reset(), NSAPI_ERROR_OK);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_shutdown)
{
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
EXPECT_EQ(dev.shutdown(), NSAPI_ERROR_OK);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready)
{
EventQueue que;

View File

@ -228,3 +228,15 @@ TEST_F(TestCellularDevice, test_cellular_callback)
delete dev;
}
TEST_F(TestCellularDevice, test_shutdown)
{
FileHandle_stub fh1;
CellularDevice *dev = new myCellularDevice(&fh1);
EXPECT_TRUE(dev);
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
ASSERT_EQ(dev->shutdown(), NSAPI_ERROR_OK);
delete dev;
}

View File

@ -176,6 +176,11 @@ nsapi_error_t AT_CellularDevice::reset()
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularDevice::shutdown()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
{
return NSAPI_ERROR_OK;

View File

@ -97,3 +97,9 @@ nsapi_error_t CellularDevice::get_sim_state(SimState &state)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t CellularDevice::shutdown()
{
return NSAPI_ERROR_OK;
}

View File

@ -119,6 +119,11 @@ public:
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t shutdown()
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t is_ready()
{
return NSAPI_ERROR_OK;

View File

@ -107,6 +107,15 @@ static void other_methods()
TEST_ASSERT_EQUAL_INT(device->init_module(), NSAPI_ERROR_OK);
}
static void shutdown_reset()
{
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
TEST_ASSERT(device->shutdown() == NSAPI_ERROR_OK);
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
TEST_ASSERT(device->reset() == NSAPI_ERROR_OK);
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
}
static void delete_device()
{
// delete will close all opened interfaces
@ -206,6 +215,8 @@ static Case cases[] = {
Case("CellularDevice sim ready", continue_to_sim_ready_state, greentea_failure_handler),
Case("CellularDevice register", continue_to_register_state, greentea_failure_handler),
Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler)
Case("CellularDevice shutdown/reset", shutdown_reset, greentea_failure_handler),
Case("CellularDevice delete device", delete_device, greentea_failure_handler)
};
static utest::v1::status_t test_setup(const size_t number_of_cases)

View File

@ -50,14 +50,10 @@ static void trace_open()
mbed_cellular_trace::mutex_wait_function_set(trace_wait);
mbed_cellular_trace::mutex_release_function_set(trace_release);
greentea_serial->set_trace_mutex(&trace_mutex);
}
static void trace_close()
{
greentea_serial->set_trace_mutex(NULL);
mbed_cellular_trace::mutex_wait_function_set(NULL);
mbed_cellular_trace::mutex_release_function_set(NULL);

View File

@ -31,7 +31,7 @@
#endif
#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
//#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
#endif
#include "greentea-client/test_env.h"

View File

@ -18,7 +18,6 @@
#ifndef CELLULAR_DEVICE_H_
#define CELLULAR_DEVICE_H_
#include "CellularUtil.h"
#include "CellularTargets.h"
#include "CellularStateMachine.h"
#include "Callback.h"
@ -263,12 +262,21 @@ public:
virtual nsapi_error_t init() = 0;
/** Reset and wake-up cellular device.
*
* @remark reset calls shutdown implicitly.
*
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_DEVICE_ERROR on failure
*/
virtual nsapi_error_t reset() = 0;
/** Shutdown cellular device to minimum functionality.
*
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_DEVICE_ERROR on failure
*/
virtual nsapi_error_t shutdown();
/** Check whether the device is ready to accept commands.
*
* @return NSAPI_ERROR_OK on success

View File

@ -15,6 +15,7 @@
* limitations under the License.
*/
#include "CellularUtil.h"
#include "AT_CellularDevice.h"
#include "AT_CellularInformation.h"
#include "AT_CellularNetwork.h"
@ -375,16 +376,30 @@ nsapi_error_t AT_CellularDevice::init()
_at->cmd_start("AT+CMEE=1"); // verbose responses
_at->cmd_stop_read_resp();
_at->cmd_start("AT+CFUN=1"); // set full functionality
_at->cmd_stop_read_resp();
return _at->unlock_return_error();
}
nsapi_error_t AT_CellularDevice::reset()
{
_at->lock();
shutdown();
_at->cmd_start("AT+CFUN=1,1");// reset to full functionality
_at->cmd_stop_read_resp();
return _at->unlock_return_error();
}
nsapi_error_t AT_CellularDevice::shutdown()
{
_at->lock();
if (_state_machine) {
_state_machine->reset();
}
_at->cmd_start("AT+CFUN=1,1");// reset to full power levels
CellularDevice::shutdown();
_at->cmd_start("AT+CFUN=0");// set to minimum functionality
_at->cmd_stop_read_resp();
return _at->unlock_return_error();
}

View File

@ -74,6 +74,8 @@ public:
virtual nsapi_error_t reset();
virtual nsapi_error_t shutdown();
virtual nsapi_error_t is_ready();
virtual nsapi_error_t set_ready_cb(Callback<void()> callback);

View File

@ -211,4 +211,14 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
}
}
nsapi_error_t CellularDevice::shutdown()
{
CellularContext *curr = get_context_list();
while (curr) {
curr->cellular_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
curr = (CellularContext *)curr->_next;
}
return NSAPI_ERROR_OK;
}
} // namespace mbed

View File

@ -97,6 +97,7 @@ nsapi_error_t QUECTEL_BC95::init()
nsapi_error_t QUECTEL_BC95::reset()
{
_at->lock();
AT_CellularDevice::shutdown();
_at->cmd_start("AT+NRB"); // reset to full power levels
_at->cmd_stop();
_at->resp_start("REBOOTING", true);

View File

@ -61,3 +61,12 @@ AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char
return new QUECTEL_BG96_CellularContext(at, this, apn);
}
AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at)
{
return new QUECTEL_BG96_CellularInformation(at);
}
nsapi_error_t QUECTEL_BG96::set_ready_cb(Callback<void()> callback)
{
return _at->set_urc_handler(DEVICE_READY_URC, callback);
}