From 08bd651ae4666420c38ff497c480788ea181918d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Wed, 28 Nov 2018 11:00:25 +0200 Subject: [PATCH 01/41] Cellular: Fixed CellularStateMachine to stop on all target states. --- .../framework/device/CellularStateMachine.cpp | 32 ++++++++++++++++--- .../framework/device/CellularStateMachine.h | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index f84d41fcdb..0e76f5406c 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -644,7 +644,7 @@ void CellularStateMachine::event() break; } - if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) { + if (check_is_target_reached()) { _event_id = -1; return; } @@ -687,6 +687,18 @@ void CellularStateMachine::set_cellular_callback(mbed::Callbackset_at_mode() == NSAPI_ERROR_OK) { tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next"); _queue.cancel(_event_id); + _event_id = -1; if (device_ready()) { - continue_from_state(STATE_SIM_PIN); + _is_retry = false; + if (!check_is_target_reached()) { + continue_from_state(STATE_SIM_PIN); + } } else { continue_from_state(STATE_DEVICE_READY); } diff --git a/features/cellular/framework/device/CellularStateMachine.h b/features/cellular/framework/device/CellularStateMachine.h index 386b39dcc4..eea4603c6e 100644 --- a/features/cellular/framework/device/CellularStateMachine.h +++ b/features/cellular/framework/device/CellularStateMachine.h @@ -157,6 +157,7 @@ private: void event(); void ready_urc_cb(); void pre_event(CellularState state); + bool check_is_target_reached(); CellularDevice &_cellularDevice; CellularState _state; From 235c2bc00d7ede2b947331e246ec4a1efe6132e7 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Fri, 30 Nov 2018 00:57:05 -0800 Subject: [PATCH 02/41] Cellular: Removed get_extended_signal_quality and changed get_signal_quality --- .../at_cellularnetworktest.cpp | 25 ++-------- UNITTESTS/stubs/AT_CellularNetwork_stub.cpp | 7 +-- .../TESTS/api/cellular_network/main.cpp | 22 +-------- .../cellular/framework/API/CellularNetwork.h | 22 +++------ .../framework/AT/AT_CellularNetwork.cpp | 46 +++++++------------ .../framework/AT/AT_CellularNetwork.h | 4 +- .../framework/device/CellularStateMachine.cpp | 5 +- 7 files changed, 32 insertions(+), 99 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp index 9609ab3935..18491eefae 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -529,24 +529,6 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_ciot_optimization_con EXPECT_TRUE(pref == CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE); } -TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_extended_signal_quality) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - int rx = -1, be = -1, rs = -1, ec = -1, rsrq = -1, rsrp = -1; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_extended_signal_quality(rx, be, rs, ec, rsrq, rsrp)); - EXPECT_TRUE(rx == -1 && be == -1 && rs == -1 && ec == -1 && rsrq == -1 && rsrp == -1); - - ATHandler_stub::int_value = 5; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_extended_signal_quality(rx, be, rs, ec, rsrq, rsrp)); - EXPECT_TRUE(rx == 5 && be == 5 && rs == 5 && ec == 5 && rsrq == 5 && rsrp == 5); -} - TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_signal_quality) { EventQueue que; @@ -556,13 +538,14 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_signal_quality) AT_CellularNetwork cn(at); int rs = -1, ber = -1; ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_signal_quality(rs, ber)); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_signal_quality(rs, &ber)); EXPECT_TRUE(rs == -1 && ber == -1); ATHandler_stub::int_value = 1; ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_signal_quality(rs, ber)); - EXPECT_TRUE(rs == -111 && ber == 1); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_signal_quality(rs, &ber)); + EXPECT_EQ(rs, -111); + EXPECT_EQ(ber, 1); } TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_3gpp_error) diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp index 60d42e8e76..9c50a45a6f 100644 --- a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -120,12 +120,7 @@ nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularNetwork::get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int &ber) +nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int *ber) { return NSAPI_ERROR_OK; } diff --git a/features/cellular/TESTS/api/cellular_network/main.cpp b/features/cellular/TESTS/api/cellular_network/main.cpp index a4988f90e1..c0279f9709 100644 --- a/features/cellular/TESTS/api/cellular_network/main.cpp +++ b/features/cellular/TESTS/api/cellular_network/main.cpp @@ -180,32 +180,14 @@ static void test_other() TEST_ASSERT(nw->scan_plmn(operators, uplinkRate) == NSAPI_ERROR_OK); device->set_timeout(10 * 1000); - int rxlev = -1, ber = -1, rscp = -1, ecno = -1, rsrq = -1, rsrp = -1; - err = nw->get_extended_signal_quality(rxlev, ber, rscp, ecno, rsrq, rsrp); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); - if (err == NSAPI_ERROR_DEVICE_ERROR) { - if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "TELIT_HE910") != 0) {// QUECTEL_BG96 does not give any specific reason for device error - TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem - ((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem - (((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands - } - } else { - // we should have some values which are not optional - TEST_ASSERT(rxlev >= 0 && ber >= 0 && rscp >= 0 && ecno >= 0 && rsrq >= 0 && rsrp >= 0); - } - int rssi = -1; - ber = -1; - err = nw->get_signal_quality(rssi, ber); + int ber = -1; + err = nw->get_signal_quality(rssi, &ber); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); if (err == NSAPI_ERROR_DEVICE_ERROR) { TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem ((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem (((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands - } else { - // test for values - TEST_ASSERT(rssi >= 0); - TEST_ASSERT(ber >= 0); } CellularNetwork::registration_params_t reg_params; diff --git a/features/cellular/framework/API/CellularNetwork.h b/features/cellular/framework/API/CellularNetwork.h index eecf365f68..26c386cdf6 100644 --- a/features/cellular/framework/API/CellularNetwork.h +++ b/features/cellular/framework/API/CellularNetwork.h @@ -275,27 +275,17 @@ public: virtual nsapi_error_t get_ciot_optimization_config(Supported_UE_Opt &supported_opt, Preferred_UE_Opt &preferred_opt) = 0; - /** Get extended signal quality parameters. - * - * @param rxlev signal strength level - * @param ber bit error rate - * @param rscp signal code power - * @param ecno ratio of the received energy per PN chip to the total received power spectral density - * @param rsrq signal received quality - * @param rsrp signal received power - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on other failures - */ - virtual nsapi_error_t get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp) = 0; - /** Get signal quality parameters. * - * @param rssi signal strength level - * @param ber bit error rate + * @param rssi signal strength level as defined in 3GPP TS 27.007, range -113..-51 dBm or SignalQualityUnknown + * @param ber bit error rate as RXQUAL as defined in 3GPP TS 45.008, range 0..7 or SignalQualityUnknown * @return NSAPI_ERROR_OK on success * NSAPI_ERROR_DEVICE_ERROR on other failures */ - virtual nsapi_error_t get_signal_quality(int &rssi, int &ber) = 0; + enum SignalQuality { + SignalQualityUnknown = 99 + }; + virtual nsapi_error_t get_signal_quality(int &rssi, int *ber = NULL) = 0; /** Get the last 3GPP error code * @return see 3GPP TS 27.007 error codes diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index d04de64d09..4cf2c91dd9 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -468,30 +468,7 @@ nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt return _at.unlock_return_error(); } -nsapi_error_t AT_CellularNetwork::get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp) -{ - _at.lock(); - - _at.cmd_start("AT+CESQ"); - _at.cmd_stop(); - - _at.resp_start("+CESQ:"); - rxlev = _at.read_int(); - ber = _at.read_int(); - rscp = _at.read_int(); - ecno = _at.read_int(); - rsrq = _at.read_int(); - rsrp = _at.read_int(); - _at.resp_stop(); - if (rxlev < 0 || ber < 0 || rscp < 0 || ecno < 0 || rsrq < 0 || rsrp < 0) { - _at.unlock(); - return NSAPI_ERROR_DEVICE_ERROR; - } - - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int &ber) +nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int *ber) { _at.lock(); @@ -499,18 +476,27 @@ nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int &ber) _at.cmd_stop(); _at.resp_start("+CSQ:"); - rssi = _at.read_int(); - ber = _at.read_int(); + int t_rssi = _at.read_int(); + int t_ber = _at.read_int(); _at.resp_stop(); - if (rssi < 0 || ber < 0) { + if (t_rssi < 0 || t_ber < 0) { _at.unlock(); return NSAPI_ERROR_DEVICE_ERROR; } - if (rssi == 99) { - rssi = 0; + // RSSI value is returned in dBm with range from -51 to -113 dBm, see 3GPP TS 27.007 + if (t_rssi == 99) { + rssi = SignalQualityUnknown; } else { - rssi = -113 + 2 * rssi; + rssi = -113 + 2 * t_rssi; + } + + if (ber) { + if (t_ber == 99) { + *ber = SignalQualityUnknown; + } else { + *ber = t_ber; + } } return _at.unlock_return_error(); diff --git a/features/cellular/framework/AT/AT_CellularNetwork.h b/features/cellular/framework/AT/AT_CellularNetwork.h index 21b30546a2..b454893e9e 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.h +++ b/features/cellular/framework/AT/AT_CellularNetwork.h @@ -69,9 +69,7 @@ public: // CellularNetwork virtual nsapi_error_t get_ciot_optimization_config(Supported_UE_Opt &supported_opt, Preferred_UE_Opt &preferred_opt); - virtual nsapi_error_t get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp); - - virtual nsapi_error_t get_signal_quality(int &rssi, int &ber); + virtual nsapi_error_t get_signal_quality(int &rssi, int *ber = NULL); virtual int get_3gpp_error(); diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index 0e76f5406c..fcf2ffab9a 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -596,9 +596,8 @@ void CellularStateMachine::event() #if MBED_CONF_MBED_TRACE_ENABLE if (_network) { int rssi; - int ber; - if (_network->get_signal_quality(rssi, ber) == NSAPI_ERROR_OK) { - if (rssi == 0) { + if (_network->get_signal_quality(rssi) == NSAPI_ERROR_OK) { + if (rssi == CellularNetwork::SignalQualityUnknown) { tr_info("RSSI unknown"); } else { tr_info("RSSI %d dBm", rssi); From 22d9105318714906d0dfc3fbf88b4d44ad8ed3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Wed, 28 Nov 2018 11:04:13 +0200 Subject: [PATCH 03/41] Removed CellularSIM interface. Moved methods to classes CellularDevice and CellularInformation. SIM interface was removed to simplify cellular usage and methods better suite new classes. Updated greentea and unit tests. --- .../at_cellularcontexttest.cpp | 3 +- .../at_cellulardevicetest.cpp | 112 ++++++---- .../AT/at_cellulardevice/unittest.cmake | 1 - .../at_cellularinformationtest.cpp | 61 ++++++ .../AT/at_cellularsim/at_cellularsimtest.cpp | 204 ------------------ .../AT/at_cellularsim/unittest.cmake | 29 --- .../cellulardevice/cellulardevicetest.cpp | 3 +- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 29 +-- .../stubs/AT_CellularInformation_stub.cpp | 10 + UNITTESTS/stubs/AT_CellularSIM_stub.cpp | 59 ----- UNITTESTS/stubs/CellularDevice_stub.cpp | 12 +- UNITTESTS/target_h/myCellularDevice.h | 19 +- .../TESTS/api/cellular_device/main.cpp | 121 ++++++++++- .../TESTS/api/cellular_information/main.cpp | 6 + .../cellular/TESTS/api/cellular_sim/main.cpp | 128 ----------- .../socket/udp/template_mbed_app.json.txt | 5 +- .../cellular/framework/API/CellularDevice.h | 47 ++-- .../framework/API/CellularInformation.h | 32 ++- features/cellular/framework/API/CellularSIM.h | 110 ---------- .../framework/AT/AT_CellularContext.cpp | 10 +- .../framework/AT/AT_CellularDevice.cpp | 108 ++++++---- .../cellular/framework/AT/AT_CellularDevice.h | 19 +- .../framework/AT/AT_CellularInformation.cpp | 40 +++- .../framework/AT/AT_CellularInformation.h | 3 + .../cellular/framework/AT/AT_CellularSIM.cpp | 155 ------------- .../cellular/framework/AT/AT_CellularSIM.h | 53 ----- .../framework/device/CellularDevice.cpp | 5 +- .../framework/device/CellularStateMachine.cpp | 31 +-- .../framework/device/CellularStateMachine.h | 2 - .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 31 ++- .../targets/QUECTEL/BC95/QUECTEL_BC95.h | 5 +- .../BC95/QUECTEL_BC95_CellularInformation.cpp | 41 ++++ .../QUECTEL_BC95_CellularInformation.h} | 19 +- .../QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp | 70 ------ .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 11 +- .../targets/QUECTEL/BG96/QUECTEL_BG96.h | 2 +- ...p => QUECTEL_BG96_CellularInformation.cpp} | 16 +- .../QUECTEL_BG96_CellularInformation.h} | 24 +-- 38 files changed, 593 insertions(+), 1043 deletions(-) delete mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp delete mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake delete mode 100644 UNITTESTS/stubs/AT_CellularSIM_stub.cpp delete mode 100644 features/cellular/TESTS/api/cellular_sim/main.cpp delete mode 100644 features/cellular/framework/API/CellularSIM.h delete mode 100644 features/cellular/framework/AT/AT_CellularSIM.cpp delete mode 100644 features/cellular/framework/AT/AT_CellularSIM.h create mode 100644 features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp rename features/cellular/framework/targets/QUECTEL/{BG96/QUECTEL_BG96_CellularSIM.h => BC95/QUECTEL_BC95_CellularInformation.h} (66%) delete mode 100644 features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp rename features/cellular/framework/targets/QUECTEL/BG96/{QUECTEL_BG96_CellularSIM.cpp => QUECTEL_BG96_CellularInformation.cpp} (72%) rename features/cellular/framework/targets/QUECTEL/{BC95/QUECTEL_BC95_CellularSIM.h => BG96/QUECTEL_BG96_CellularInformation.h} (53%) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp index 4d7b80cb98..df7a5bbfb6 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp @@ -27,7 +27,6 @@ #include "Semaphore_stub.h" #include "CellularDevice_stub.h" #include "equeue_stub.h" -#include "CellularSIM.h" using namespace mbed; using namespace events; @@ -528,7 +527,7 @@ TEST_F(TestAT_CellularContext, set_sim_ready) cell_callback_data_t data; data.error = NSAPI_ERROR_OK; ctx.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data); - data.status_data = CellularSIM::SimStateReady; + data.status_data = CellularDevice::SimStateReady; ctx.cellular_callback((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&data); } diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 622844aecb..6c14c61c58 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -56,7 +56,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler) EXPECT_TRUE(dev.open_network(&fh1)); EXPECT_TRUE(dev.open_sms(&fh2)); AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - EXPECT_TRUE(dev.open_sim(&fh3)); + EXPECT_TRUE(dev.open_information(&fh3)); ATHandler_stub::fh_value = &fh1; EXPECT_TRUE(dev.open_power(&fh1)); @@ -112,19 +112,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power) EXPECT_TRUE(pwr1 == pwr); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - - CellularSIM *sim = dev.open_sim(NULL); - CellularSIM *sim1 = dev.open_sim(&fh1); - - EXPECT_TRUE(sim); - EXPECT_TRUE(sim1); - EXPECT_TRUE(sim1 == sim); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information) { FileHandle_stub fh1; @@ -180,26 +167,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - ATHandler_stub::ref_count = 0; - int ana = 0; - - EXPECT_TRUE(dev.open_sim(&fh1)); - AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - - ana = ATHandler_stub::ref_count; - - dev.close_sms(); // this should not affect to refcount as it's not opened - EXPECT_TRUE(ATHandler_stub::ref_count == 1); - ana = ATHandler_stub::ref_count; - - dev.close_sim(); - EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) { FileHandle_stub fh1; @@ -233,19 +200,18 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout) ATHandler_stub::timeout = 0; ATHandler_stub::default_timeout = false; - // no interfaces open so settings timeout should not change anything dev.set_timeout(5000); - EXPECT_TRUE(ATHandler_stub::timeout == 0); - EXPECT_TRUE(ATHandler_stub::default_timeout == false); + EXPECT_TRUE(ATHandler_stub::timeout == 5000); + EXPECT_TRUE(ATHandler_stub::default_timeout == true); - EXPECT_TRUE(dev.open_sim(&fh1)); + EXPECT_TRUE(dev.open_sms(&fh1)); EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.set_timeout(5000); EXPECT_TRUE(ATHandler_stub::timeout == 5000); EXPECT_TRUE(ATHandler_stub::default_timeout == true); - dev.close_sim(); + dev.close_sms(); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) @@ -254,17 +220,16 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) AT_CellularDevice dev(&fh1); ATHandler_stub::debug_on = false; - // no interfaces open so debug toggling should not affect dev.modem_debug_on(true); - EXPECT_TRUE(ATHandler_stub::debug_on == false); + EXPECT_TRUE(ATHandler_stub::debug_on == true); - EXPECT_TRUE(dev.open_sim(&fh1)); + EXPECT_TRUE(dev.open_sms(&fh1)); EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.modem_debug_on(true); EXPECT_TRUE(ATHandler_stub::debug_on == true); - dev.close_sim(); + dev.close_sms(); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay) @@ -333,3 +298,64 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context) delete dev; } + +TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_set_pin) +{ + FileHandle_stub fh1; + AT_CellularDevice *dev = new AT_CellularDevice(&fh1); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ASSERT_EQ(NSAPI_ERROR_OK, dev->set_pin("12")); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, dev->set_pin("12")); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"SIM PIN"; + ATHandler_stub::ssize_value = 7; + ASSERT_EQ(NSAPI_ERROR_PARAMETER, dev->set_pin(NULL)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"READY"; + ATHandler_stub::ssize_value = 5; + ASSERT_EQ(NSAPI_ERROR_OK, dev->set_pin("12")); + + ASSERT_EQ(NSAPI_ERROR_OK, dev->set_pin(NULL)); + + delete dev; +} + +TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_get_sim_state) +{ + FileHandle_stub fh1; + AT_CellularDevice *dev = new AT_CellularDevice(&fh1); + + CellularDevice::SimState state; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::ssize_value = -1; + ATHandler_stub::read_string_value = NULL; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStateUnknown, state); + + ATHandler_stub::read_string_value = (char *)"READY"; + ATHandler_stub::ssize_value = 5; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStateReady, state); + + ATHandler_stub::read_string_value = (char *)"SIM PIN"; + ATHandler_stub::ssize_value = 7; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStatePinNeeded, state); + + ATHandler_stub::read_string_value = (char *)"SIM PUK"; + ATHandler_stub::ssize_value = 7; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStatePukNeeded, state); + + ATHandler_stub::read_string_value = (char *)"SOME CRAP"; + ATHandler_stub::ssize_value = 9; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStateUnknown, state); + + delete dev; +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake index 5ce257eab7..92af9005b6 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake @@ -27,7 +27,6 @@ set(unittest-test-sources stubs/AT_CellularNetwork_stub.cpp stubs/ATHandler_stub.cpp stubs/AT_CellularSMS_stub.cpp - stubs/AT_CellularSIM_stub.cpp stubs/AT_CellularPower_stub.cpp stubs/AT_CellularInformation_stub.cpp stubs/CellularUtil_stub.cpp diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp index 0a6d649e74..883bffd00c 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp @@ -34,6 +34,10 @@ protected: void SetUp() { + ATHandler_stub::read_string_index = kRead_string_table_size; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = 0; } void TearDown() @@ -118,6 +122,8 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_revision) EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8)); EXPECT_TRUE(strlen(buf) == 0); + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci->get_revision(NULL, 8)); + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci->get_revision(buf, 0)); delete aci; } @@ -152,4 +158,59 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number AT_CellularBase_stub::supported_bool = true; EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI)); EXPECT_TRUE(strcmp("1234567", buf) == 0); + + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci.get_serial_number(NULL, 8, CellularInformation::IMEI)); + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci.get_serial_number(buf, 0, CellularInformation::IMEI)); +} + +TEST_F(TestAT_CellularInformation, TestAT_CellularInformation_get_imsi) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation aci(ah); + + char imsi[16]; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"123456789012345"; + ATHandler_stub::ssize_value = 15; + ASSERT_EQ(NSAPI_ERROR_OK, aci.get_imsi(imsi, sizeof(imsi))); + ASSERT_STREQ(ATHandler_stub::read_string_value, imsi); + + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = -1; + ATHandler_stub::read_string_index = -1; + imsi[0] = 0; + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, aci.get_imsi(imsi, sizeof(imsi))); + ASSERT_EQ(strlen(imsi), 0); + + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_imsi(NULL, sizeof(imsi))); + + char imsi2[5]; + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_imsi(imsi2, sizeof(imsi2))); +} + +TEST_F(TestAT_CellularInformation, TestAT_CellularInformation_get_iccid) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation aci(ah); + + char buf[16]; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"123456789012345"; + ATHandler_stub::ssize_value = 15; + ASSERT_EQ(NSAPI_ERROR_OK, aci.get_iccid(buf, 16)); + ASSERT_STREQ(ATHandler_stub::read_string_value, buf); + + buf[0] = 0; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = -1; + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, aci.get_iccid(buf, 16)); + ASSERT_EQ(strlen(buf), 0); + + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_iccid(buf, 0)); + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_iccid(NULL, 16)); } diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp deleted file mode 100644 index e4fe6a1ce1..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "gtest/gtest.h" -#include "ATHandler_stub.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularSIM.h" -#include "FileHandle_stub.h" -#include "CellularLog.h" -#include "ATHandler_stub.h" - -using namespace mbed; -using namespace events; - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -class TestAT_CellularSIM : public testing::Test { -protected: - - void SetUp() - { - ATHandler_stub::read_string_index = kRead_string_table_size; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = 0; - } - - void TearDown() - { - } -}; -// *INDENT-ON* - -TEST_F(TestAT_CellularSIM, Create) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM *sim = new AT_CellularSIM(at); - - EXPECT_TRUE(sim != NULL); - delete sim; -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12")); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin("12")); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = (char *)"READY"; - ATHandler_stub::ssize_value = 5; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12")); - - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin(NULL)); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_change_pin) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", "34")); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, "34")); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", NULL)); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, NULL)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34")); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin_query) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", true)); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, true)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", false)); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, false)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false)); - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true)); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_sim_state) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - CellularSIM::SimState state; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::ssize_value = -1; - ATHandler_stub::read_string_value = NULL; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStateUnknown == state); - - ATHandler_stub::read_string_value = (char *)"READY"; - ATHandler_stub::ssize_value = 5; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStateReady == state); - - ATHandler_stub::read_string_value = (char *)"SIM PIN"; - ATHandler_stub::ssize_value = 7; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStatePinNeeded == state); - - ATHandler_stub::read_string_value = (char *)"SIM PUK"; - ATHandler_stub::ssize_value = 7; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStatePukNeeded == state); - - ATHandler_stub::read_string_value = (char *)"SOME CRAP"; - ATHandler_stub::ssize_value = 9; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStateUnknown == state); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_imsi) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - char imsi[16]; - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = (char *)"123456789012345"; - ATHandler_stub::ssize_value = 15; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_imsi(imsi)); - EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, imsi) == 0); - - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = -1; - ATHandler_stub::read_string_index = -1; - imsi[0] = 0; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi)); - EXPECT_TRUE(strlen(imsi) == 0); - - EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL)); - - // this would fail as get_imsi should take another param which is the size of the buffer which we could use for validation. - // Now we have improved documentation that that the given imsi buffer size must be over 15. - //char imsi2[5]; - //EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2)); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_iccid) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - char buf[16]; - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = (char *)"123456789012345"; - ATHandler_stub::ssize_value = 15; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_iccid(buf, 16)); - EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, buf) == 0); - - buf[0] = 0; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = -1; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16)); - EXPECT_TRUE(strlen(buf) == 0); -} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake deleted file mode 100644 index 7adbfef871..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake +++ /dev/null @@ -1,29 +0,0 @@ - -#################### -# UNIT TESTS -#################### - -# Add test specific include paths -set(unittest-includes ${unittest-includes} - features/cellular/framework/common/util - ../features/cellular/framework/common - ../features/cellular/framework/AT - ../features/frameworks/mbed-client-randlib/mbed-client-randlib -) - -# Source files -set(unittest-sources - ../features/cellular/framework/AT/AT_CellularSIM.cpp -) - -# Test files -set(unittest-test-sources - features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp - stubs/ATHandler_stub.cpp - stubs/AT_CellularBase_stub.cpp - stubs/EventQueue_stub.cpp - stubs/FileHandle_stub.cpp - stubs/CellularUtil_stub.cpp - stubs/us_ticker_stub.cpp - stubs/mbed_assert_stub.c -) diff --git a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp index 4eb5e3d6e6..d615f592f7 100644 --- a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp @@ -21,7 +21,6 @@ #include "FileHandle_stub.h" #include "myCellularDevice.h" #include "CellularStateMachine_stub.h" -#include "CellularSIM.h" using namespace mbed; @@ -221,7 +220,7 @@ TEST_F(TestCellularDevice, test_cellular_callback) dev->cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data); dev->set_sim_pin("1234"); - data.status_data = CellularSIM::SimStatePinNeeded; + data.status_data = CellularDevice::SimStatePinNeeded; dev->cellular_callback((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&data); CellularContext *ctx = dev->create_context(); diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 7ef169e736..169929df30 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -24,7 +24,7 @@ const int DEFAULT_AT_TIMEOUT = 1000; using namespace mbed; AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), - _sim(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), + _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) { } @@ -54,12 +54,10 @@ nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler) CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) { - } void delete_context(CellularContext *context) { - } CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) @@ -72,11 +70,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) return NULL; } -CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh) -{ - return NULL; -} - CellularPower *AT_CellularDevice::open_power(FileHandle *fh) { return NULL; @@ -99,10 +92,6 @@ void AT_CellularDevice::close_power() { } -void AT_CellularDevice::close_sim() -{ -} - void AT_CellularDevice::close_information() { } @@ -124,7 +113,6 @@ AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const void AT_CellularDevice::delete_context(CellularContext *context) { - } AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at) @@ -142,11 +130,6 @@ AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at) return NULL; } -AT_CellularSIM *AT_CellularDevice::open_sim_impl(ATHandler &at) -{ - return NULL; -} - AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) { return NULL; @@ -172,3 +155,13 @@ nsapi_error_t AT_CellularDevice::init_module() { return NSAPI_ERROR_OK; } + +nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularInformation_stub.cpp b/UNITTESTS/stubs/AT_CellularInformation_stub.cpp index ae35f29bde..832c038433 100644 --- a/UNITTESTS/stubs/AT_CellularInformation_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularInformation_stub.cpp @@ -47,3 +47,13 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si { return NSAPI_ERROR_OK; } + +nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularSIM_stub.cpp b/UNITTESTS/stubs/AT_CellularSIM_stub.cpp deleted file mode 100644 index afab1012bd..0000000000 --- a/UNITTESTS/stubs/AT_CellularSIM_stub.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) , Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AT_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularSIM::~AT_CellularSIM() -{ -} - -nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::get_imsi(char *imsi) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - return NSAPI_ERROR_OK; -} diff --git a/UNITTESTS/stubs/CellularDevice_stub.cpp b/UNITTESTS/stubs/CellularDevice_stub.cpp index e64118f0f6..24141cfb99 100644 --- a/UNITTESTS/stubs/CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/CellularDevice_stub.cpp @@ -30,7 +30,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance() return NULL; } -CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0), +CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0) { } @@ -87,3 +87,13 @@ nsapi_error_t CellularDevice::attach_to_network() return NSAPI_ERROR_OK; } + +nsapi_error_t CellularDevice::set_pin(const char *sim_pin) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t CellularDevice::get_sim_state(SimState &state) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 28dfb8a1ac..7190f8f6f9 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -29,7 +29,6 @@ namespace mbed { class CellularPower; class CellularSMS; -class CellularSIM; class CellularInformation; class CellularContext; class FileHandle; @@ -42,6 +41,17 @@ public: delete _context_list; delete _network; } + + virtual nsapi_error_t set_pin(const char *sim_pin) + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t get_sim_state(SimState &state) + { + return NSAPI_ERROR_OK; + } + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) { EventQueue que; @@ -74,11 +84,6 @@ public: return NULL; } - virtual CellularSIM *open_sim(FileHandle *fh = NULL) - { - return NULL; - } - virtual CellularInformation *open_information(FileHandle *fh = NULL) { return NULL; @@ -93,8 +98,6 @@ public: virtual void close_power() {} - virtual void close_sim() {} - virtual void close_information() {} virtual void set_timeout(int timeout) {} diff --git a/features/cellular/TESTS/api/cellular_device/main.cpp b/features/cellular/TESTS/api/cellular_device/main.cpp index 9246e3e112..df8fb467f8 100644 --- a/features/cellular/TESTS/api/cellular_device/main.cpp +++ b/features/cellular/TESTS/api/cellular_device/main.cpp @@ -15,7 +15,6 @@ * limitations under the License. */ - #if !defined(MBED_CONF_NSAPI_PRESENT) #error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. #endif @@ -27,6 +26,10 @@ #error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined #endif +#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN +#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. +#endif + #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" @@ -36,9 +39,24 @@ #include "CellularLog.h" #include "CellularDevice.h" #include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) +#include "Semaphore.h" +#include "../../cellular_tests_common.h" static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); static CellularDevice *device; +static rtos::Semaphore semaphore; + + +const int TIME_OUT_DEVICE_READY = 5 * 60 * 1000; // 5 minutes +const int TIME_OUT_REGISTER = 10 * 60 * 1000; // 10 minutes + +enum CurrentOp { + OP_DEVICE_READY, + OP_SIM_READY, + OP_REGISTER, + OP_ATTACH +}; +static CurrentOp op; static void create_device() { @@ -52,10 +70,6 @@ static void open_close_interfaces() TEST_ASSERT(nw != NULL); device->close_network(); - CellularSIM *sim = device->open_sim(&cellular_serial); - TEST_ASSERT(sim != NULL); - device->close_sim(); - CellularInformation *info = device->open_information(&cellular_serial); TEST_ASSERT(info != NULL); device->close_information(); @@ -70,6 +84,7 @@ static void open_close_interfaces() CellularContext *ctx = device->create_context(); TEST_ASSERT(ctx != NULL); + TEST_ASSERT(device->get_context_list() == ctx); device->delete_context(ctx); } @@ -83,10 +98,13 @@ static void other_methods() CellularNetwork *nw = device->open_network(&cellular_serial); TEST_ASSERT(nw != NULL); - // then test witj open interface which is called + // then test with open interface which is called device->set_timeout(5000); device->modem_debug_on(true); device->modem_debug_on(false); + + TEST_ASSERT(device->get_queue() != NULL); + TEST_ASSERT_EQUAL_INT(device->init_module(), NSAPI_ERROR_OK); } static void delete_device() @@ -96,10 +114,85 @@ static void delete_device() device = NULL; } +static void callback_func(nsapi_event_t ev, intptr_t ptr) +{ + if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) { + cell_callback_data_t *ptr_data = (cell_callback_data_t *)ptr; + cellular_connection_status_t cell_ev = (cellular_connection_status_t)ev; + if (cell_ev == CellularDeviceReady && ptr_data->error == NSAPI_ERROR_OK && op == OP_DEVICE_READY) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK && + ptr_data->status_data == CellularDevice::SimStateReady && op == OP_SIM_READY) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } else if (cell_ev == CellularRegistrationStatusChanged && + (ptr_data->status_data == CellularNetwork::RegisteredHomeNetwork || + ptr_data->status_data == CellularNetwork::RegisteredRoaming || + ptr_data->status_data == CellularNetwork::AlreadyRegistered) && + ptr_data->error == NSAPI_ERROR_OK && + op == OP_REGISTER) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } else if (cell_ev == CellularAttachNetwork && ptr_data->status_data == CellularNetwork::Attached && + ptr_data->error == NSAPI_ERROR_OK && op == OP_ATTACH) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } + } +} + +static void init_to_device_ready_state() +{ + device = CellularDevice::get_default_instance(); + TEST_ASSERT(device != NULL); + +#ifdef MBED_CONF_APP_CELLULAR_SIM_PIN + device->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN); +#endif +#ifdef MBED_CONF_APP_CELLULAR_PLMN + device->set_plmn(MBED_CONF_APP_CELLULAR_PLMN); +#endif + device->attach(&callback_func); + + op = OP_DEVICE_READY; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init_module()); + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->set_device_ready()); + + int sema_err = semaphore.wait(TIME_OUT_DEVICE_READY); + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + +static void continue_to_sim_ready_state() +{ + op = OP_SIM_READY; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->set_sim_ready()); + + int sema_err = semaphore.wait(TIME_OUT_DEVICE_READY); + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + +static void continue_to_register_state() +{ + op = OP_REGISTER; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->register_to_network()); + + int sema_err = semaphore.wait(TIME_OUT_REGISTER); // cellular network searching may take several minutes + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + +static void continue_to_attach_state() +{ + op = OP_ATTACH; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->attach_to_network()); + + int sema_err = semaphore.wait(TIME_OUT_REGISTER); // cellular network attach may take several minutes + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + using namespace utest::v1; static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { +#if MBED_CONF_MBED_TRACE_ENABLE + trace_close(); +#endif greentea_case_failure_abort_handler(source, reason); return STATUS_ABORT; } @@ -108,7 +201,11 @@ static Case cases[] = { Case("CellularDevice create device", create_device, greentea_failure_handler), Case("CellularDevice Open and close interfaces", open_close_interfaces, greentea_failure_handler), Case("CellularDevice other methods", other_methods, greentea_failure_handler), - Case("CellularDevice delete device", delete_device, greentea_failure_handler) + Case("CellularDevice delete device", delete_device, greentea_failure_handler), + Case("CellularDevice init to device ready", init_to_device_ready_state, greentea_failure_handler), + 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) }; static utest::v1::status_t test_setup(const size_t number_of_cases) @@ -121,8 +218,14 @@ static Specification specification(test_setup, cases); int main() { - mbed_trace_init(); +#if MBED_CONF_MBED_TRACE_ENABLE + trace_open(); +#endif - return Harness::run(specification); + int ret = Harness::run(specification); +#if MBED_CONF_MBED_TRACE_ENABLE + trace_close(); +#endif + return ret; } diff --git a/features/cellular/TESTS/api/cellular_information/main.cpp b/features/cellular/TESTS/api/cellular_information/main.cpp index 942da3177f..bf18c553e2 100644 --- a/features/cellular/TESTS/api/cellular_information/main.cpp +++ b/features/cellular/TESTS/api/cellular_information/main.cpp @@ -80,6 +80,12 @@ static void test_information_interface() err = info->get_serial_number(buf, kbuf_size, CellularInformation::SVN); TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK); + err = info->get_imsi(buf, kbuf_size); + TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK); + + err = info->get_iccid(buf, kbuf_size); + TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK); + dev->close_information(); delete [] buf; diff --git a/features/cellular/TESTS/api/cellular_sim/main.cpp b/features/cellular/TESTS/api/cellular_sim/main.cpp deleted file mode 100644 index 3da5b951bb..0000000000 --- a/features/cellular/TESTS/api/cellular_sim/main.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#if !defined(MBED_CONF_NSAPI_PRESENT) -#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. -#endif - -#include "CellularUtil.h" // for CELLULAR_ helper macros -#include "CellularTargets.h" - -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - -#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN -#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. -#endif - -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" - -#include "mbed.h" - -#include "CellularContext.h" -#include "CellularDevice.h" -#include "CellularSIM.h" -#include "../../cellular_tests_common.h" -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) - -#define NETWORK_TIMEOUT (180*1000) - -static CellularContext *ctx; -static CellularDevice *device; - -static void init_to_device_ready_state() -{ - ctx = CellularContext::get_default_instance(); - TEST_ASSERT(ctx != NULL); - TEST_ASSERT(ctx->set_device_ready() == NSAPI_ERROR_OK); - - device = CellularDevice::get_default_instance(); - TEST_ASSERT(device != NULL); -} - -static void test_sim_interface() -{ - CellularSIM *sim = device->open_sim(); - TEST_ASSERT(sim != NULL); - - // set SIM at time out to 9000 - device->set_timeout(9000); - wait(4); // we need to wait for some time so that SIM interface is working in all modules. - // 1. test set_pin - nsapi_error_t err = sim->set_pin(MBED_CONF_APP_CELLULAR_SIM_PIN); - MBED_ASSERT(err == NSAPI_ERROR_OK); - - // 2. test set_pin_query - wait(1); - err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); - - wait(1); - err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, true); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); - - wait(1); - // 3. test get_sim_state - CellularSIM::SimState state; - err = sim->get_sim_state(state); - TEST_ASSERT(err == NSAPI_ERROR_OK); - TEST_ASSERT(state == CellularSIM::SimStateReady); - - wait(1); - // 4. test get_imsi - char imsi[16] = {0}; - err = sim->get_imsi(imsi); - TEST_ASSERT(err == NSAPI_ERROR_OK); - TEST_ASSERT(strlen(imsi) > 0); -} - -using namespace utest::v1; - -static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) -{ - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - -static Case cases[] = { - Case("CellularSIM init", init_to_device_ready_state, greentea_failure_handler), - Case("CellularSIM test interface", test_sim_interface, greentea_failure_handler) -}; - -static utest::v1::status_t test_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(10 * 60, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -static Specification specification(test_setup, cases); - -int main() -{ -#if MBED_CONF_MBED_TRACE_ENABLE - trace_open(); -#endif - int ret = Harness::run(specification); -#if MBED_CONF_MBED_TRACE_ENABLE - trace_close(); -#endif - return ret; -} diff --git a/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt b/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt index be58e16e68..983fd68dd9 100644 --- a/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt +++ b/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt @@ -4,6 +4,10 @@ "help": "PIN code", "value": "\"1234\"" }, + "cellular_plmn": { + "help": "plmn to select manual registration", + "value": 0 + }, "apn": { "help": "The APN string to use for this SIM/network, set to 0 if none", "value": 0 @@ -27,7 +31,6 @@ "nsapi.dns-response-wait-time": 30000, "ppp-cell-iface.apn-lookup": false, "cellular.use-apn-lookup": false, - "target.features_add": ["LWIP"], "mbed-trace.enable": false, "lwip.ipv4-enabled": true, "lwip.ipv6-enabled": true, diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index a494114023..12ddb7315a 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -27,7 +27,6 @@ namespace mbed { class CellularPower; class CellularSMS; -class CellularSIM; class CellularInformation; class CellularNetwork; class CellularContext; @@ -35,6 +34,7 @@ class FileHandle; const int MAX_PIN_SIZE = 8; const int MAX_PLMN_SIZE = 16; +const int MAX_SIM_READY_WAITING_TIME = 30; /** * @addtogroup cellular @@ -49,6 +49,13 @@ const int MAX_PLMN_SIZE = 16; */ class CellularDevice { public: + /* enumeration for possible SIM states */ + enum SimState { + SimStateReady = 0, + SimStatePinNeeded, + SimStatePukNeeded, + SimStateUnknown + }; /** Returns singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not * defined, then it returns NULL. Implementation is marked as weak. @@ -67,6 +74,23 @@ public: */ virtual ~CellularDevice(); + /** Open the SIM card by setting the pin code for SIM. + * + * @param sim_pin PIN for the SIM card + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if sim_pin is null and sim is not ready + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t set_pin(const char *sim_pin) = 0; + + /** Get SIM card's state + * + * @param state current state of SIM + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t get_sim_state(SimState &state) = 0; + /** Creates a new CellularContext interface. * * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default @@ -154,11 +178,11 @@ public: /** Register callback for status reporting. * - * The specified status callback function is called on the network, and the cellular device status changes. - * The parameters on the callback are the event type and event type dependent reason parameter. + * The specified status callback function will be called on the network and cellular device status changes. + * The parameters on the callback are the event type and event-type dependent reason parameter. * - * @remark deleting CellularDevice/CellularContext in callback is not allowed. - * @remark application should not attach to this function if it uses CellularContext::attach because it contains the + * @remark deleting CellularDevice/CellularContext in callback not allowed. + * @remark application should not attach to this function if using CellularContext::attach as it will contain the * same information. * * @param status_cb The callback for status changes. @@ -189,14 +213,6 @@ public: */ virtual CellularPower *open_power(FileHandle *fh = NULL) = 0; - /** Create new CellularSIM interface. - * - * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default - * file handle is used. - * @return New instance of interface CellularSIM. - */ - virtual CellularSIM *open_sim(FileHandle *fh = NULL) = 0; - /** Create new CellularInformation interface. * * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default @@ -217,10 +233,6 @@ public: */ virtual void close_power() = 0; - /** Closes the opened CellularSIM by deleting the CellularSIM instance. - */ - virtual void close_sim() = 0; - /** Closes the opened CellularInformation by deleting the CellularInformation instance. */ virtual void close_information() = 0; @@ -283,7 +295,6 @@ protected: int _network_ref_count; int _sms_ref_count; int _power_ref_count; - int _sim_ref_count; int _info_ref_count; FileHandle *_fh; events::EventQueue _queue; diff --git a/features/cellular/framework/API/CellularInformation.h b/features/cellular/framework/API/CellularInformation.h index 9ab79d6e92..689e78f673 100644 --- a/features/cellular/framework/API/CellularInformation.h +++ b/features/cellular/framework/API/CellularInformation.h @@ -21,6 +21,9 @@ #include #include "nsapi_types.h" +const int MAX_IMSI_LENGTH = 15; +const int MAX_ICCID_LENGTH = 20 + 1; // +1 for zero termination + namespace mbed { /** @@ -48,6 +51,7 @@ public: * @param buf manufacturer identification as zero terminated string * @param buf_size max length of manufacturer identification is 2048 characters * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_manufacturer(char *buf, size_t buf_size) = 0; @@ -57,6 +61,7 @@ public: * @param buf model identification as zero terminated string * @param buf_size max length of model identification is 2048 characters * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_model(char *buf, size_t buf_size) = 0; @@ -66,6 +71,7 @@ public: * @param buf revision identification as zero terminated string * @param buf_size max length of revision identification is 2048 characters * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_revision(char *buf, size_t buf_size) = 0; @@ -76,6 +82,7 @@ public: * @param buf_size max length of serial number is 2048 characters * @param type serial number type to read * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_UNSUPPORTED if the modem does not support SerialNumberType * NSAPI_ERROR_DEVICE_ERROR on other failures */ @@ -85,7 +92,30 @@ public: IMEISV = 2, // IMEI and Software Version number SVN = 3 // Software Version Number }; - virtual nsapi_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type = SN) = 0; + virtual nsapi_size_or_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type = SN) = 0; + + /** Get IMSI from the sim card + * + * @remark Given imsi buffer length must be 16 or more as imsi max length is 15! + * + * @param imsi preallocated char* which after successful request contains imsi + * @param buf_size size of imsi buffer + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if imsi is null or buf_size is zero or buf_size is smaller than + * MAX_IMSI_LENGTH + 1 + * NSAPI_ERROR_DEVICE_ERROR on other failures + */ + virtual nsapi_error_t get_imsi(char *imsi, size_t buf_size) = 0; + + /** Get serial number from the SIM card + * + * @param buf SIM ICCID as zero terminated string + * @param buf_size max length of SIM ICCID is MAX_ICCID_LENGTH + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t get_iccid(char *buf, size_t buf_size) = 0; }; /** diff --git a/features/cellular/framework/API/CellularSIM.h b/features/cellular/framework/API/CellularSIM.h deleted file mode 100644 index 13ff7d3700..0000000000 --- a/features/cellular/framework/API/CellularSIM.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CELLULAR_SIM_H_ -#define CELLULAR_SIM_H_ - -#include - -#include "nsapi_types.h" - -namespace mbed { - -const int MAX_SIM_READY_WAITING_TIME = 30; -const int MAX_IMSI_LENGTH = 15; -const int MAX_ICCID_LENGTH = 20 + 1; // +1 for zero termination -/** - * Class CellularSIM - * - * An abstract interface for SIM card handling. - */ -class CellularSIM { -protected: - // friend of CellularDevice so that it's the only way to close/delete this class. - friend class CellularDevice; - - /** - * virtual Destructor - */ - virtual ~CellularSIM() {}; - -public: - /* enumeration for possible SIM states */ - enum SimState { - SimStateReady = 0, - SimStatePinNeeded, - SimStatePukNeeded, - SimStateUnknown - }; - - /** Open the SIM card by setting the pin code for SIM. - * - * @param sim_pin PIN for the SIM card - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t set_pin(const char *sim_pin) = 0; - - /** Change SIM pin code. - * - * @param sim_pin Current PIN for SIM - * @param new_pin New PIN for SIM - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin) = 0; - - /** Change is pin query needed after boot - * - * @param sim_pin Valid PIN for SIM card - * @param query_pin False if PIN query not needed, True if PIN query needed after boot. - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin) = 0; - - /** Get SIM card's state - * - * @param state current state of SIM - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t get_sim_state(SimState &state) = 0; - - /** Get IMSI from the sim card - * @remark Given imsi buffer length must be 16 or more as imsi max length is 15! - * - * @param imsi preallocated char* which after successful request contains imsi - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_PARAMETER if imsi if null - * NSAPI_ERROR_DEVICE_ERROR on other failures - */ - virtual nsapi_error_t get_imsi(char *imsi) = 0; - - /** Get serial number from the SIM card - * - * @param buf SIM ICCID as zero terminated string - * @param buf_size max length of SIM ICCID is MAX_ICCID_LENGTH - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t get_iccid(char *buf, size_t buf_size) = 0; -}; - -} // namespace mbed - -#endif // CELLULAR_SIM_H_ diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 1cb280318f..a2a7ddd1fa 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -20,7 +20,6 @@ #include "AT_CellularStack.h" #include "CellularLog.h" #include "CellularUtil.h" -#include "CellularSIM.h" #include "UARTSerial.h" #include "mbed_wait_api.h" @@ -35,6 +34,7 @@ #define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP)) #if USE_APN_LOOKUP +#include "CellularInformation.h" #include "APN_db.h" #endif //USE_APN_LOOKUP @@ -835,12 +835,12 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) _cb_data.error = data->error; tr_debug("CellularContext: event %d, err %d, data %d", ev, data->error, data->status_data); #if USE_APN_LOOKUP - if (st == CellularSIMStatusChanged && data->status_data == CellularSIM::SimStateReady && + if (st == CellularSIMStatusChanged && data->status_data == CellularDevice::SimStateReady && _cb_data.error == NSAPI_ERROR_OK) { if (!_apn) { char imsi[MAX_IMSI_LENGTH + 1]; wait(1); // need to wait to access SIM in some modems - _cb_data.error = _device->open_sim()->get_imsi(imsi); + _cb_data.error = _device->open_information()->get_imsi(imsi, sizeof(imsi)); if (_cb_data.error == NSAPI_ERROR_OK) { const char *apn_config = apnconfig(imsi); if (apn_config) { @@ -858,7 +858,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) _semaphore.release(); } } - _device->close_sim(); + _device->close_information(); } } #endif // USE_APN_LOOKUP @@ -874,7 +874,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) } else { if ((st == CellularDeviceReady && _current_op == OP_DEVICE_READY) || (st == CellularSIMStatusChanged && _current_op == OP_SIM_READY && - data->status_data == CellularSIM::SimStateReady)) { + data->status_data == CellularDevice::SimStateReady)) { // target reached, release semaphore _semaphore.release(); } else if (st == CellularRegistrationStatusChanged && (data->status_data == CellularNetwork::RegisteredHomeNetwork || diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 0ab15c60bf..8d8b3de1a4 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -19,7 +19,6 @@ #include "AT_CellularInformation.h" #include "AT_CellularNetwork.h" #include "AT_CellularPower.h" -#include "AT_CellularSIM.h" #include "AT_CellularSMS.h" #include "AT_CellularContext.h" #include "AT_CellularStack.h" @@ -32,11 +31,15 @@ using namespace events; using namespace mbed; #define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds +const int MAX_SIM_RESPONSE_LENGTH = 16; AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), - _sim(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), + _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) { + MBED_ASSERT(fh); + _at = get_at_handler(fh); + MBED_ASSERT(_at); } AT_CellularDevice::~AT_CellularDevice() @@ -47,13 +50,11 @@ AT_CellularDevice::~AT_CellularDevice() _network_ref_count = 1; _sms_ref_count = 1; _power_ref_count = 1; - _sim_ref_count = 1; _info_ref_count = 1; close_network(); close_sms(); close_power(); - close_sim(); close_information(); AT_CellularContext *curr = _context_list; @@ -92,6 +93,73 @@ nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler) } } +nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) +{ + char simstr[MAX_SIM_RESPONSE_LENGTH]; + _at->lock(); + _at->flush(); + _at->cmd_start("AT+CPIN?"); + _at->cmd_stop(); + _at->resp_start("+CPIN:"); + ssize_t len = _at->read_string(simstr, sizeof(simstr)); + if (len != -1) { + if (len >= 5 && memcmp(simstr, "READY", 5) == 0) { + state = SimStateReady; + } else if (len >= 7 && memcmp(simstr, "SIM PIN", 7) == 0) { + state = SimStatePinNeeded; + } else if (len >= 7 && memcmp(simstr, "SIM PUK", 7) == 0) { + state = SimStatePukNeeded; + } else { + simstr[len] = '\0'; + tr_error("Unknown SIM state %s", simstr); + state = SimStateUnknown; + } + } else { + tr_warn("SIM not readable."); + state = SimStateUnknown; // SIM may not be ready yet or +CPIN may be unsupported command + } + _at->resp_stop(); + nsapi_error_t error = _at->get_last_error(); + _at->unlock(); +#if MBED_CONF_MBED_TRACE_ENABLE + switch (state) { + case SimStatePinNeeded: + tr_info("SIM PIN required"); + break; + case SimStatePukNeeded: + tr_error("SIM PUK required"); + break; + case SimStateUnknown: + tr_warn("SIM state unknown"); + break; + default: + tr_info("SIM is ready"); + break; + } +#endif + return error; +} + +nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin) +{ + // if SIM is already in ready state then settings the PIN + // will return error so let's check the state before settings the pin. + SimState state; + if (get_sim_state(state) == NSAPI_ERROR_OK && state == SimStateReady) { + return NSAPI_ERROR_OK; + } + + if (sim_pin == NULL) { + return NSAPI_ERROR_PARAMETER; + } + + _at->lock(); + _at->cmd_start("AT+CPIN="); + _at->write_string(sim_pin); + _at->cmd_stop_read_resp(); + return _at->unlock_return_error(); +} + CellularContext *AT_CellularDevice::get_context_list() const { return _context_list; @@ -178,20 +246,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) return _sms; } -CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh) -{ - if (!_sim) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _sim = open_sim_impl(*atHandler); - } - } - if (_sim) { - _sim_ref_count++; - } - return _sim; -} - CellularPower *AT_CellularDevice::open_power(FileHandle *fh) { if (!_power) { @@ -235,11 +289,6 @@ AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at) return new AT_CellularPower(at); } -AT_CellularSIM *AT_CellularDevice::open_sim_impl(ATHandler &at) -{ - return new AT_CellularSIM(at); -} - AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) { return new AT_CellularInformation(at); @@ -284,19 +333,6 @@ void AT_CellularDevice::close_power() } } -void AT_CellularDevice::close_sim() -{ - if (_sim) { - _sim_ref_count--; - if (_sim_ref_count == 0) { - ATHandler *atHandler = &_sim->get_at_handler(); - delete _sim; - _sim = NULL; - release_at_handler(atHandler); - } - } -} - void AT_CellularDevice::close_information() { if (_information) { diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 9b171a724b..2068417dba 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -26,7 +26,6 @@ class ATHandler; class AT_CellularInformation; class AT_CellularNetwork; class AT_CellularPower; -class AT_CellularSIM; class AT_CellularSMS; class AT_CellularContext; @@ -41,7 +40,12 @@ public: AT_CellularDevice(FileHandle *fh); virtual ~AT_CellularDevice(); + virtual nsapi_error_t set_pin(const char *sim_pin); + + virtual nsapi_error_t get_sim_state(SimState &state); + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL); + virtual void delete_context(CellularContext *context); virtual CellularNetwork *open_network(FileHandle *fh = NULL); @@ -50,8 +54,6 @@ public: virtual CellularPower *open_power(FileHandle *fh = NULL); - virtual CellularSIM *open_sim(FileHandle *fh = NULL); - virtual CellularInformation *open_information(FileHandle *fh = NULL); virtual void close_network(); @@ -60,8 +62,6 @@ public: virtual void close_power(); - virtual void close_sim(); - virtual void close_information(); virtual void set_timeout(int timeout); @@ -113,13 +113,6 @@ public: */ virtual AT_CellularPower *open_power_impl(ATHandler &at); - /** Create new instance of AT_CellularSIM or if overridden, modem specific implementation. - * - * @param at ATHandler reference for communication with the modem. - * @return new instance of class AT_CellularSIM - */ - virtual AT_CellularSIM *open_sim_impl(ATHandler &at); - /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation. * * @param at ATHandler reference for communication with the modem. @@ -131,12 +124,12 @@ public: AT_CellularNetwork *_network; AT_CellularSMS *_sms; - AT_CellularSIM *_sim; AT_CellularPower *_power; AT_CellularInformation *_information; AT_CellularContext *_context_list; int _default_timeout; bool _modem_debug_on; + ATHandler *_at; }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularInformation.cpp b/features/cellular/framework/AT/AT_CellularInformation.cpp index 73a49f4fe0..585cd211e8 100644 --- a/features/cellular/framework/AT/AT_CellularInformation.cpp +++ b/features/cellular/framework/AT/AT_CellularInformation.cpp @@ -46,6 +46,10 @@ nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size) nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type) { + if (buf == NULL || buf_size == 0) { + return NSAPI_ERROR_PARAMETER; + } + if (type == SN) { return get_info("AT+CGSN", buf, buf_size); } @@ -66,8 +70,10 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_t buf_size) { + if (buf == NULL || buf_size == 0) { + return NSAPI_ERROR_PARAMETER; + } _at.lock(); - _at.cmd_start(cmd); _at.cmd_stop(); _at.set_delimiter(0); @@ -75,6 +81,36 @@ nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_ _at.read_string(buf, buf_size - 1); _at.resp_stop(); _at.set_default_delimiter(); - + return _at.unlock_return_error(); +} + +nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size) +{ + if (imsi == NULL || buf_size == 0 || buf_size < MAX_IMSI_LENGTH + 1) { + return NSAPI_ERROR_PARAMETER; + } + _at.lock(); + _at.cmd_start("AT+CIMI"); + _at.cmd_stop(); + _at.resp_start(); + int len = _at.read_string(imsi, MAX_IMSI_LENGTH); + if (len > 0) { + imsi[len] = '\0'; + } + _at.resp_stop(); + return _at.unlock_return_error(); +} + +nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + if (buf == NULL || buf_size == 0) { + return NSAPI_ERROR_PARAMETER; + } + _at.lock(); + _at.cmd_start("AT+CCID?"); + _at.cmd_stop(); + _at.resp_start("+CCID:"); + _at.read_string(buf, buf_size); + _at.resp_stop(); return _at.unlock_return_error(); } diff --git a/features/cellular/framework/AT/AT_CellularInformation.h b/features/cellular/framework/AT/AT_CellularInformation.h index d9679d3f25..6e7e6f8cad 100644 --- a/features/cellular/framework/AT/AT_CellularInformation.h +++ b/features/cellular/framework/AT/AT_CellularInformation.h @@ -42,6 +42,9 @@ public: virtual nsapi_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type); + virtual nsapi_error_t get_imsi(char *imsi, size_t buf_size); + + virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); protected: /** Request information text from cellular device * diff --git a/features/cellular/framework/AT/AT_CellularSIM.cpp b/features/cellular/framework/AT/AT_CellularSIM.cpp deleted file mode 100644 index 86425a852a..0000000000 --- a/features/cellular/framework/AT/AT_CellularSIM.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AT_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -const int MAX_SIM_RESPONSE_LENGTH = 16; - -AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularSIM::~AT_CellularSIM() -{ -} - -nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state) -{ - char simstr[MAX_SIM_RESPONSE_LENGTH]; - _at.lock(); - _at.flush(); - _at.cmd_start("AT+CPIN?"); - _at.cmd_stop(); - _at.resp_start("+CPIN:"); - ssize_t len = _at.read_string(simstr, sizeof(simstr)); - if (len != -1) { - if (len >= 5 && memcmp(simstr, "READY", 5) == 0) { - state = SimStateReady; - } else if (len >= 6 && memcmp(simstr, "SIM PIN", 6) == 0) { - state = SimStatePinNeeded; - } else if (len >= 6 && memcmp(simstr, "SIM PUK", 6) == 0) { - state = SimStatePukNeeded; - } else { - simstr[len] = '\0'; - tr_error("Unknown SIM state %s", simstr); - state = SimStateUnknown; - } - } else { - tr_warn("SIM not readable."); - state = SimStateUnknown; // SIM may not be ready yet or +CPIN may be unsupported command - } - _at.resp_stop(); - nsapi_error_t error = _at.get_last_error(); - _at.unlock(); -#if MBED_CONF_MBED_TRACE_ENABLE - switch (state) { - case SimStatePinNeeded: - tr_info("SIM PIN required"); - break; - case SimStatePukNeeded: - tr_error("SIM PUK required"); - break; - case SimStateUnknown: - tr_warn("SIM state unknown"); - break; - default: - tr_info("SIM is ready"); - break; - } -#endif - return error; -} - - -nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin) -{ - // if SIM is already in ready state then settings the PIN - // will return error so let's check the state before settings the pin. - SimState state; - if (get_sim_state(state) == NSAPI_ERROR_OK && state == SimStateReady) { - return NSAPI_ERROR_OK; - } - - _at.lock(); - _at.cmd_start("AT+CPIN="); - _at.write_string(sim_pin); - _at.cmd_stop_read_resp(); - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - _at.lock(); - _at.cmd_start("AT+CPWD="); - _at.write_string("SC"); - _at.write_string(sim_pin); - _at.write_string(new_pin); - _at.cmd_stop_read_resp(); - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - _at.lock(); - if (query_pin) { - /* use the SIM locked */ - _at.cmd_start("AT+CLCK="); - _at.write_string("SC"); - _at.write_int(1); - _at.write_string(sim_pin); - _at.cmd_stop_read_resp(); - } else { - /* use the SIM unlocked */ - _at.cmd_start("AT+CLCK="); - _at.write_string("SC"); - _at.write_int(0); - _at.write_string(sim_pin); - _at.cmd_stop_read_resp(); - } - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::get_imsi(char *imsi) -{ - if (imsi == NULL) { - return NSAPI_ERROR_PARAMETER; - } - _at.lock(); - _at.cmd_start("AT+CIMI"); - _at.cmd_stop(); - _at.resp_start(); - int len = _at.read_string(imsi, MAX_IMSI_LENGTH); - if (len > 0) { - imsi[len] = '\0'; - } - _at.resp_stop(); - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - _at.lock(); - _at.cmd_start("AT+CCID?"); - _at.cmd_stop(); - _at.resp_start("+CCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); -} diff --git a/features/cellular/framework/AT/AT_CellularSIM.h b/features/cellular/framework/AT/AT_CellularSIM.h deleted file mode 100644 index 379de706bc..0000000000 --- a/features/cellular/framework/AT/AT_CellularSIM.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AT_CELLULAR_SIM_H_ -#define AT_CELLULAR_SIM_H_ - -#include "CellularSIM.h" -#include "AT_CellularBase.h" - -namespace mbed { - -/** - * Class AT_CellularSIM - * - * Class for SIM card handling. - */ -class AT_CellularSIM : public CellularSIM, public AT_CellularBase { - -public: - AT_CellularSIM(ATHandler &atHandler); - virtual ~AT_CellularSIM(); - -public: - virtual nsapi_error_t set_pin(const char *sim_pin); - - virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin); - - virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin); - - virtual nsapi_error_t get_sim_state(SimState &state); - - virtual nsapi_error_t get_imsi(char *imsi); - - virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); -}; - -} // namespace mbed - -#endif // AT_CELLULAR_SIM_H_ diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index bb623fe501..d0b48ce8c9 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -17,7 +17,6 @@ #include "CellularDevice.h" #include "CellularContext.h" -#include "CellularSIM.h" #include "CellularUtil.h" #include "CellularLog.h" #include "CellularTargets.h" @@ -50,7 +49,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance() } #endif // CELLULAR_DEVICE -CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0), +CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0) { set_sim_pin(NULL); @@ -184,7 +183,7 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr) _state_machine->set_plmn(_plmn); } } else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK && - ptr_data->status_data == CellularSIM::SimStatePinNeeded) { + ptr_data->status_data == SimStatePinNeeded) { if (strlen(_sim_pin)) { _state_machine->set_sim_pin(_sim_pin); } diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index fcf2ffab9a..2fb57a22c9 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -18,7 +18,6 @@ #include "CellularStateMachine.h" #include "CellularDevice.h" #include "CellularPower.h" -#include "CellularSIM.h" #include "CellularLog.h" #include "Thread.h" #include "UARTSerial.h" @@ -47,7 +46,7 @@ namespace mbed { CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) : _cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state), - _event_status_cb(0), _network(0), _power(0), _sim(0), _queue(queue), _queue_thread(0), _sim_pin(0), + _event_status_cb(0), _network(0), _power(0), _queue(queue), _queue_thread(0), _sim_pin(0), _retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false), _plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE), _network_status(0) @@ -106,11 +105,6 @@ void CellularStateMachine::stop() _power = NULL; } - if (_sim) { - _cellularDevice.close_sim(); - _sim = NULL; - } - if (_network) { _cellularDevice.close_network(); _network = NULL; @@ -143,15 +137,10 @@ void CellularStateMachine::set_plmn(const char *plmn) bool CellularStateMachine::open_sim() { - if (!_sim) { - // can only fail with allocation with new and then it's critical error - _sim = _cellularDevice.open_sim(); - } - - CellularSIM::SimState state = CellularSIM::SimStateUnknown; + CellularDevice::SimState state = CellularDevice::SimStateUnknown; // wait until SIM is readable // here you could add wait(secs) if you know start delay of your SIM - _cb_data.error = _sim->get_sim_state(state); + _cb_data.error = _cellularDevice.get_sim_state(state); if (_cb_data.error != NSAPI_ERROR_OK) { tr_info("Waiting for SIM (err while reading)..."); return false; @@ -163,10 +152,10 @@ bool CellularStateMachine::open_sim() _event_status_cb((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&_cb_data); } - if (state == CellularSIM::SimStatePinNeeded) { + if (state == CellularDevice::SimStatePinNeeded) { if (strlen(_sim_pin)) { - tr_info("Entering PIN to open SIM."); - _cb_data.error = _sim->set_pin(_sim_pin); + tr_info("Entering PIN to open SIM"); + _cb_data.error = _cellularDevice.set_pin(_sim_pin); if (_cb_data.error) { tr_error("Failed to set PIN: error %d", _cb_data.error); } @@ -178,7 +167,7 @@ bool CellularStateMachine::open_sim() } } - return state == CellularSIM::SimStateReady; + return state == CellularDevice::SimStateReady; } bool CellularStateMachine::is_registered() @@ -512,8 +501,6 @@ void CellularStateMachine::state_attaching() _cb_data.error = _network->set_attach(); } if (_cb_data.error == NSAPI_ERROR_OK) { - _cellularDevice.close_sim(); - _sim = NULL; if (_event_status_cb) { _cb_data.status_data = CellularNetwork::Attached; _event_status_cb(_current_event, (intptr_t)&_cb_data); @@ -688,10 +675,8 @@ void CellularStateMachine::set_cellular_callback(mbed::Callbacklock(); + _at->flush(); + _at->cmd_start("AT+NCCID?"); + _at->cmd_stop(); + _at->resp_start("+NCCID:"); + if (_at->info_resp()) { + state = SimStateReady; + } else { + tr_warn("SIM not readable."); + state = SimStateUnknown; // SIM may not be ready yet + } + _at->resp_stop(); + return _at->unlock_return_error(); +} + AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at) { return new QUECTEL_BC95_CellularNetwork(at); @@ -55,12 +73,13 @@ AT_CellularPower *QUECTEL_BC95::open_power_impl(ATHandler &at) return new QUECTEL_BC95_CellularPower(at); } -AT_CellularSIM *QUECTEL_BC95::open_sim_impl(ATHandler &at) -{ - return new QUECTEL_BC95_CellularSIM(at); -} - AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn) { return new QUECTEL_BC95_CellularContext(at, this, apn); } + +AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at) +{ + return new QUECTEL_BC95_CellularInformation(at); +} + diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index 7dd9937f4c..1df0f2d05f 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -27,11 +27,14 @@ public: QUECTEL_BC95(FileHandle *fh); virtual ~QUECTEL_BC95(); +public: // AT_CellularDevice + virtual nsapi_error_t get_sim_state(SimState &state); + protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularSIM *open_sim_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularInformation *open_information_impl(ATHandler &at); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp new file mode 100644 index 0000000000..8bc51c5aef --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "QUECTEL_BC95_CellularInformation.h" + +namespace mbed { + +QUECTEL_BC95_CellularInformation::QUECTEL_BC95_CellularInformation(ATHandler &at) : AT_CellularInformation(at) +{ +} + +QUECTEL_BC95_CellularInformation::~QUECTEL_BC95_CellularInformation() +{ +} + +// According to BC95_AT_Commands_Manual_V1.9 +nsapi_error_t QUECTEL_BC95_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + _at.lock(); + _at.cmd_start("AT+NCCID?"); + _at.cmd_stop(); + _at.resp_start("+NCCID:"); + _at.read_string(buf, buf_size); + _at.resp_stop(); + return _at.unlock_return_error(); +} + +} /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.h similarity index 66% rename from features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.h rename to features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.h index efbcf5b3ed..833649eee9 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.h @@ -14,23 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef QUECTEL_BC95_CELLULARINFORMATION_H_ +#define QUECTEL_BC95_CELLULARINFORMATION_H_ -#ifndef QUECTEL_BG96_CELLULAR_SIM_H_ -#define QUECTEL_BG96_CELLULAR_SIM_H_ - -#include "AT_CellularSIM.h" +#include "AT_CellularInformation.h" namespace mbed { -class QUECTEL_BG96_CellularSIM : public AT_CellularSIM { +class QUECTEL_BC95_CellularInformation : public AT_CellularInformation { public: - QUECTEL_BG96_CellularSIM(ATHandler &atHandler); - virtual ~QUECTEL_BG96_CellularSIM(); + QUECTEL_BC95_CellularInformation(ATHandler &at); + virtual ~QUECTEL_BC95_CellularInformation(); -public: //from CellularSIM +public: virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); }; -} // namespace mbed +} /* namespace mbed */ -#endif // QUECTEL_BG96_CELLULAR_SIM_H_ +#endif /* QUECTEL_BC95_CELLULARINFORMATION_H_ */ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp deleted file mode 100644 index 6da7e5f554..0000000000 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_BC95_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -QUECTEL_BC95_CellularSIM::QUECTEL_BC95_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler) -{ - -} - -QUECTEL_BC95_CellularSIM::~QUECTEL_BC95_CellularSIM() -{ - -} - -nsapi_error_t QUECTEL_BC95_CellularSIM::get_sim_state(SimState &state) -{ - _at.lock(); - _at.flush(); - _at.cmd_start("AT+NCCID?"); - _at.cmd_stop(); - _at.resp_start("+NCCID:"); - if (_at.info_resp()) { - state = SimStateReady; - } else { - tr_warn("SIM not readable."); - state = SimStateUnknown; // SIM may not be ready yet - } - _at.resp_stop(); - return _at.unlock_return_error(); -} - -// According to BC95_AT_Commands_Manual_V1.9 -nsapi_error_t QUECTEL_BC95_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - _at.lock(); - _at.cmd_start("AT+NCCID?"); - _at.cmd_stop(); - _at.resp_start("+NCCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); -} - -nsapi_error_t QUECTEL_BC95_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t QUECTEL_BC95_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index e07b7001c0..55e673acfd 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -18,7 +18,7 @@ #include "QUECTEL_BG96.h" #include "QUECTEL_BG96_CellularNetwork.h" #include "QUECTEL_BG96_CellularStack.h" -#include "QUECTEL_BG96_CellularSIM.h" +#include "QUECTEL_BG96_CellularInformation.h" #include "QUECTEL_BG96_CellularPower.h" #include "QUECTEL_BG96_CellularContext.h" @@ -52,11 +52,6 @@ AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) return new QUECTEL_BG96_CellularNetwork(at); } -AT_CellularSIM *QUECTEL_BG96::open_sim_impl(ATHandler &at) -{ - return new QUECTEL_BG96_CellularSIM(at); -} - AT_CellularPower *QUECTEL_BG96::open_power_impl(ATHandler &at) { return new QUECTEL_BG96_CellularPower(at); @@ -67,3 +62,7 @@ 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); +} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 86eb63bd4c..1cc8b4a892 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -29,9 +29,9 @@ public: protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularSIM *open_sim_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularInformation *open_information_impl(ATHandler &at); public: void handle_urc(FileHandle *fh); }; diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.cpp similarity index 72% rename from features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.cpp rename to features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.cpp index 80cae03db5..c8f4319ce6 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.cpp @@ -14,24 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "QUECTEL_BG96_CellularInformation.h" -#include "QUECTEL_BG96_CellularSIM.h" -#include "CellularLog.h" +namespace mbed { -using namespace mbed; - -QUECTEL_BG96_CellularSIM::QUECTEL_BG96_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler) +QUECTEL_BG96_CellularInformation::QUECTEL_BG96_CellularInformation(ATHandler &at) : AT_CellularInformation(at) { - } -QUECTEL_BG96_CellularSIM::~QUECTEL_BG96_CellularSIM() +QUECTEL_BG96_CellularInformation::~QUECTEL_BG96_CellularInformation() { - } // According to BG96_AT_Commands_Manual_V2.0 -nsapi_error_t QUECTEL_BG96_CellularSIM::get_iccid(char *buf, size_t buf_size) +nsapi_error_t QUECTEL_BG96_CellularInformation::get_iccid(char *buf, size_t buf_size) { _at.lock(); _at.cmd_start("AT+QCCID"); @@ -41,3 +37,5 @@ nsapi_error_t QUECTEL_BG96_CellularSIM::get_iccid(char *buf, size_t buf_size) _at.resp_stop(); return _at.unlock_return_error(); } + +} /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.h similarity index 53% rename from features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.h rename to features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.h index 498be76817..c952eac33e 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Arm Limited and affiliates. + * Copyright (c) 2018, Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,26 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef QUECTEL_BG96_CELLULARINFORMATION_H_ +#define QUECTEL_BG96_CELLULARINFORMATION_H_ -#ifndef QUECTEL_BC95_CELLULAR_SIM_H_ -#define QUECTEL_BC95_CELLULAR_SIM_H_ - -#include "AT_CellularSIM.h" +#include "AT_CellularInformation.h" namespace mbed { -class QUECTEL_BC95_CellularSIM : public AT_CellularSIM { +class QUECTEL_BG96_CellularInformation: public AT_CellularInformation { public: - QUECTEL_BC95_CellularSIM(ATHandler &atHandler); - virtual ~QUECTEL_BC95_CellularSIM(); + QUECTEL_BG96_CellularInformation(ATHandler &at); + virtual ~QUECTEL_BG96_CellularInformation(); -public: //from CellularSIM - virtual nsapi_error_t get_sim_state(SimState &state); +public: // AT_CellularInformation virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); - virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin); - virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin); }; -} // namespace mbed +} /* namespace mbed */ -#endif // QUECTEL_BC95_CELLULAR_SIM_H_ +#endif /* QUECTEL_BG96_CELLULARINFORMATION_H_ */ From f94117559bcd0f2d10888a518797a2f0e2e9df6d Mon Sep 17 00:00:00 2001 From: Teemu Kultala Date: Fri, 9 Nov 2018 15:18:14 +0200 Subject: [PATCH 04/41] cellular: eps ciot optimization network support check -added an API for checking network eps ciot optimization support -renamed the API for getting the UE parameters -the API for setting the UE parameters includes now a callback, which will be called once network support for eps ciot optimization is known --- .../at_cellularnetworktest.cpp | 34 ++++++++++++----- UNITTESTS/stubs/AT_CellularNetwork_stub.cpp | 14 +++++-- .../TESTS/api/cellular_network/main.cpp | 10 ++--- .../cellular/framework/API/CellularNetwork.h | 38 ++++++++++++------- .../framework/AT/AT_CellularNetwork.cpp | 36 +++++++++++++----- .../framework/AT/AT_CellularNetwork.h | 15 ++++++-- 6 files changed, 102 insertions(+), 45 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp index 18491eefae..8a590560f7 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -498,37 +498,51 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_ciot_optimization_con AT_CellularNetwork cn(at); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_ciot_optimization_config(CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_ciot_optimization_config(CellularNetwork::CIOT_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE, NULL)); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_ciot_optimization_config(CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE)); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_ciot_optimization_config(CellularNetwork::CIOT_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE, NULL)); } -TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_ciot_optimization_config) +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_ciot_ue_optimization_config) { EventQueue que; FileHandle_stub fh1; ATHandler at(&fh1, que, 0, ","); AT_CellularNetwork cn(at); - CellularNetwork::Supported_UE_Opt sup = CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT; - CellularNetwork::Preferred_UE_Opt pref = CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE; + CellularNetwork::CIoT_Supported_Opt sup = CellularNetwork::CIOT_OPT_NO_SUPPORT; + CellularNetwork::CIoT_Preferred_UE_Opt pref = CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE; ATHandler_stub::int_value = 1; ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_ciot_optimization_config(sup, pref)); - EXPECT_TRUE(sup == CellularNetwork::SUPPORTED_UE_OPT_CONTROL_PLANE); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_ciot_ue_optimization_config(sup, pref)); + EXPECT_TRUE(sup == CellularNetwork::CIOT_OPT_CONTROL_PLANE); EXPECT_TRUE(pref == CellularNetwork::PREFERRED_UE_OPT_CONTROL_PLANE); - sup = CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT; + sup = CellularNetwork::CIOT_OPT_NO_SUPPORT; pref = CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE; ATHandler_stub::int_value = 1; ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; ATHandler_stub::nsapi_error_ok_counter = 0; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_ciot_optimization_config(sup, pref)); - EXPECT_TRUE(sup == CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_ciot_ue_optimization_config(sup, pref)); + EXPECT_TRUE(sup == CellularNetwork::CIOT_OPT_NO_SUPPORT); EXPECT_TRUE(pref == CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE); } +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_ciot_network_optimization_config) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + CellularNetwork::CIoT_Supported_Opt sup = CellularNetwork::CIOT_OPT_NO_SUPPORT; + ATHandler_stub::int_value = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_ciot_network_optimization_config(sup)); + EXPECT_TRUE(sup == CellularNetwork::CIOT_OPT_MAX); +} + TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_signal_quality) { EventQueue que; diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp index 9c50a45a6f..e2ca22eabd 100644 --- a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -108,14 +108,20 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt supported_opt, - Preferred_UE_Opt preferred_opt) +nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(CIoT_Supported_Opt supported_opt, + CIoT_Preferred_UE_Opt preferred_opt, + Callback network_support_cb) { return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt &supported_opt, - Preferred_UE_Opt &preferred_opt) +nsapi_error_t AT_CellularNetwork::get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, + CIoT_Preferred_UE_Opt &preferred_opt) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_opt) { return NSAPI_ERROR_OK; } diff --git a/features/cellular/TESTS/api/cellular_network/main.cpp b/features/cellular/TESTS/api/cellular_network/main.cpp index c0279f9709..b918f8df1a 100644 --- a/features/cellular/TESTS/api/cellular_network/main.cpp +++ b/features/cellular/TESTS/api/cellular_network/main.cpp @@ -224,9 +224,9 @@ static void test_other() #endif // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command - CellularNetwork::Supported_UE_Opt supported_opt = CellularNetwork::SUPPORTED_UE_OPT_MAX; - CellularNetwork::Preferred_UE_Opt preferred_opt = CellularNetwork::PREFERRED_UE_OPT_MAX; - err = nw->get_ciot_optimization_config(supported_opt, preferred_opt); + CellularNetwork::CIoT_Supported_Opt supported_opt = CellularNetwork::CIOT_OPT_MAX; + CellularNetwork::CIoT_Preferred_UE_Opt preferred_opt = CellularNetwork::PREFERRED_UE_OPT_MAX; + err = nw->get_ciot_ue_optimization_config(supported_opt, preferred_opt); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); if (err == NSAPI_ERROR_DEVICE_ERROR) { // if device error then we must check was that really device error or that modem/network does not support the commands @@ -236,11 +236,11 @@ static void test_other() (((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands } } else { - TEST_ASSERT(supported_opt != CellularNetwork::SUPPORTED_UE_OPT_MAX); + TEST_ASSERT(supported_opt != CellularNetwork::CIOT_OPT_MAX); TEST_ASSERT(preferred_opt != CellularNetwork::PREFERRED_UE_OPT_MAX); } - err = nw->set_ciot_optimization_config(supported_opt, preferred_opt); + err = nw->set_ciot_optimization_config(supported_opt, preferred_opt, NULL); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); if (err == NSAPI_ERROR_DEVICE_ERROR) { // if device error then we must check was that really device error or that modem/network does not support the commands diff --git a/features/cellular/framework/API/CellularNetwork.h b/features/cellular/framework/API/CellularNetwork.h index 26c386cdf6..13610fedfa 100644 --- a/features/cellular/framework/API/CellularNetwork.h +++ b/features/cellular/framework/API/CellularNetwork.h @@ -45,17 +45,17 @@ protected: public: /* Definition for Supported CIoT EPS optimizations type. */ - enum Supported_UE_Opt { - SUPPORTED_UE_OPT_NO_SUPPORT = 0, /* No support. */ - SUPPORTED_UE_OPT_CONTROL_PLANE, /* Support for control plane CIoT EPS optimization. */ - SUPPORTED_UE_OPT_USER_PLANE, /* Support for user plane CIoT EPS optimization. */ - SUPPORTED_UE_OPT_BOTH, /* Support for both control plane CIoT EPS optimization and user plane CIoT EPS + enum CIoT_Supported_Opt { + CIOT_OPT_NO_SUPPORT = 0, /* No support. */ + CIOT_OPT_CONTROL_PLANE, /* Support for control plane CIoT EPS optimization. */ + CIOT_OPT_USER_PLANE, /* Support for user plane CIoT EPS optimization. */ + CIOT_OPT_BOTH, /* Support for both control plane CIoT EPS optimization and user plane CIoT EPS optimization. */ - SUPPORTED_UE_OPT_MAX + CIOT_OPT_MAX }; /* Definition for Preferred CIoT EPS optimizations type. */ - enum Preferred_UE_Opt { + enum CIoT_Preferred_UE_Opt { PREFERRED_UE_OPT_NO_PREFERENCE = 0, /* No preference. */ PREFERRED_UE_OPT_CONTROL_PLANE, /* Preference for control plane CIoT EPS optimization. */ PREFERRED_UE_OPT_USER_PLANE, /* Preference for user plane CIoT EPS optimization. */ @@ -257,23 +257,35 @@ public: /** Set CIoT optimizations. * - * @param supported_opt Supported CIoT EPS optimizations. + * @param supported_opt Supported CIoT EPS optimizations + * (the HW support can be checked with get_ciot_ue_optimization_config). * @param preferred_opt Preferred CIoT EPS optimizations. + * @param network_support_cb This callback will be called when CIoT network optimisation support is known * @return NSAPI_ERROR_OK on success * NSAPI_ERROR_DEVICE_ERROR on failure */ - virtual nsapi_error_t set_ciot_optimization_config(Supported_UE_Opt supported_opt, - Preferred_UE_Opt preferred_opt) = 0; + virtual nsapi_error_t set_ciot_optimization_config(CIoT_Supported_Opt supported_opt, + CIoT_Preferred_UE_Opt preferred_opt, + Callback network_support_cb) = 0; - /** Get CIoT optimizations. + /** Get UE CIoT optimizations. * * @param supported_opt Supported CIoT EPS optimizations. * @param preferred_opt Preferred CIoT EPS optimizations. * @return NSAPI_ERROR_OK on success * NSAPI_ERROR_DEVICE_ERROR on failure */ - virtual nsapi_error_t get_ciot_optimization_config(Supported_UE_Opt &supported_opt, - Preferred_UE_Opt &preferred_opt) = 0; + virtual nsapi_error_t get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, + CIoT_Preferred_UE_Opt &preferred_opt) = 0; + + /** Get Network CIoT optimizations. + * + * @param supported_network_opt Supported CIoT EPS optimizations. CIOT_OPT_MAX will be returned, + * if the support is not known + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_network_opt) = 0; /** Get signal quality parameters. * diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index 4cf2c91dd9..80bbb63d97 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -71,7 +71,8 @@ static const char *const rat_str[AT_CellularNetwork::RAT_MAX] = { AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler), - _connection_status_cb(NULL), _op_act(RAT_UNKNOWN), _connect_status(NSAPI_STATUS_DISCONNECTED) + _connection_status_cb(NULL), _op_act(RAT_UNKNOWN), _connect_status(NSAPI_STATUS_DISCONNECTED), + _ciotopt_network_support_cb(NULL), _supported_network_opt(CIOT_OPT_MAX) { _urc_funcs[C_EREG] = callback(this, &AT_CellularNetwork::urc_cereg); @@ -87,6 +88,7 @@ AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(a _at.set_urc_handler("NO CARRIER", callback(this, &AT_CellularNetwork::urc_no_carrier)); // additional urc to get better disconnect info for application. Not critical. _at.set_urc_handler("+CGEV:", callback(this, &AT_CellularNetwork::urc_cgev)); + _at.set_urc_handler("+CCIOTOPTI:", callback(this, &AT_CellularNetwork::urc_cciotopti)); _at.lock(); _at.cmd_start("AT+CGEREP=1");// discard unsolicited result codes when MT TE link is reserved (e.g. in on line data mode); otherwise forward them directly to the TE _at.cmd_stop_read_resp(); @@ -433,14 +435,15 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount return _at.unlock_return_error(); } -nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt supported_opt, - Preferred_UE_Opt preferred_opt) +nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(CIoT_Supported_Opt supported_opt, + CIoT_Preferred_UE_Opt preferred_opt, + Callback network_support_cb) { - + _ciotopt_network_support_cb = network_support_cb; _at.lock(); _at.cmd_start("AT+CCIOTOPT="); - _at.write_int(0); // disable urc + _at.write_int(1); //enable CCIOTOPTI URC _at.write_int(supported_opt); _at.write_int(preferred_opt); _at.cmd_stop_read_resp(); @@ -448,8 +451,17 @@ nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt return _at.unlock_return_error(); } -nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt &supported_opt, - Preferred_UE_Opt &preferred_opt) +void AT_CellularNetwork::urc_cciotopti() +{ + _supported_network_opt = (CIoT_Supported_Opt)_at.read_int(); + + if (_ciotopt_network_support_cb) { + _ciotopt_network_support_cb(_supported_network_opt); + } +} + +nsapi_error_t AT_CellularNetwork::get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, + CIoT_Preferred_UE_Opt &preferred_opt) { _at.lock(); @@ -459,8 +471,8 @@ nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt _at.resp_start("+CCIOTOPT:"); _at.read_int(); if (_at.get_last_error() == NSAPI_ERROR_OK) { - supported_opt = (Supported_UE_Opt)_at.read_int(); - preferred_opt = (Preferred_UE_Opt)_at.read_int(); + supported_opt = (CIoT_Supported_Opt)_at.read_int(); + preferred_opt = (CIoT_Preferred_UE_Opt)_at.read_int(); } _at.resp_stop(); @@ -468,6 +480,12 @@ nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt return _at.unlock_return_error(); } +nsapi_error_t AT_CellularNetwork::get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_network_opt) +{ + supported_network_opt = _supported_network_opt; + return NSAPI_ERROR_OK; +} + nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int *ber) { _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularNetwork.h b/features/cellular/framework/AT/AT_CellularNetwork.h index b454893e9e..c774b0a32a 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.h +++ b/features/cellular/framework/AT/AT_CellularNetwork.h @@ -63,11 +63,14 @@ public: // CellularNetwork virtual nsapi_error_t scan_plmn(operList_t &operators, int &ops_count); - virtual nsapi_error_t set_ciot_optimization_config(Supported_UE_Opt supported_opt, - Preferred_UE_Opt preferred_opt); + virtual nsapi_error_t set_ciot_optimization_config(CIoT_Supported_Opt supported_opt, + CIoT_Preferred_UE_Opt preferred_opt, + Callback network_support_cb); - virtual nsapi_error_t get_ciot_optimization_config(Supported_UE_Opt &supported_opt, - Preferred_UE_Opt &preferred_opt); + virtual nsapi_error_t get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, + CIoT_Preferred_UE_Opt &preferred_opt); + + virtual nsapi_error_t get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_network_opt); virtual nsapi_error_t get_signal_quality(int &rssi, int *ber = NULL); @@ -113,6 +116,7 @@ private: void urc_cereg(); void urc_cgreg(); void urc_cgev(); + void urc_cciotopti(); void read_reg_params_and_compare(RegistrationType type); void read_reg_params(RegistrationType type, registration_params_t ®_params); @@ -128,8 +132,11 @@ private: protected: Callback _connection_status_cb; + Callback _ciotopt_network_support_cb; RadioAccessTechnology _op_act; nsapi_connection_status_t _connect_status; + CIoT_Supported_Opt _supported_network_opt; + registration_params_t _reg_params; mbed::Callback _urc_funcs[C_MAX]; }; From 22a536a78a92de66fa9bbb80718feb9ac86e3757 Mon Sep 17 00:00:00 2001 From: Teemu Kultala Date: Mon, 12 Nov 2018 12:40:40 +0200 Subject: [PATCH 05/41] cellular: eps ciot optimization network support check astyle fix --- UNITTESTS/stubs/AT_CellularNetwork_stub.cpp | 2 +- features/cellular/framework/API/CellularNetwork.h | 2 +- features/cellular/framework/AT/AT_CellularNetwork.cpp | 2 +- features/cellular/framework/AT/AT_CellularNetwork.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp index e2ca22eabd..89720306d9 100644 --- a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -116,7 +116,7 @@ nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(CIoT_Supported_Op } nsapi_error_t AT_CellularNetwork::get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, - CIoT_Preferred_UE_Opt &preferred_opt) + CIoT_Preferred_UE_Opt &preferred_opt) { return NSAPI_ERROR_OK; } diff --git a/features/cellular/framework/API/CellularNetwork.h b/features/cellular/framework/API/CellularNetwork.h index 13610fedfa..bc94267447 100644 --- a/features/cellular/framework/API/CellularNetwork.h +++ b/features/cellular/framework/API/CellularNetwork.h @@ -276,7 +276,7 @@ public: * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, - CIoT_Preferred_UE_Opt &preferred_opt) = 0; + CIoT_Preferred_UE_Opt &preferred_opt) = 0; /** Get Network CIoT optimizations. * diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index 80bbb63d97..ab6d90ee17 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -461,7 +461,7 @@ void AT_CellularNetwork::urc_cciotopti() } nsapi_error_t AT_CellularNetwork::get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, - CIoT_Preferred_UE_Opt &preferred_opt) + CIoT_Preferred_UE_Opt &preferred_opt) { _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularNetwork.h b/features/cellular/framework/AT/AT_CellularNetwork.h index c774b0a32a..0f7f0c97d7 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.h +++ b/features/cellular/framework/AT/AT_CellularNetwork.h @@ -68,7 +68,7 @@ public: // CellularNetwork Callback network_support_cb); virtual nsapi_error_t get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, - CIoT_Preferred_UE_Opt &preferred_opt); + CIoT_Preferred_UE_Opt &preferred_opt); virtual nsapi_error_t get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_network_opt); From 36292a4f14a9b5bd32287bbf32a6a16aa9d82a03 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Tue, 27 Nov 2018 02:13:56 -0800 Subject: [PATCH 06/41] Cellular: Move eDRX setting from power to network --- .../at_cellularnetworktest.cpp | 13 +++++++++++ .../at_cellularpower/at_cellularpowertest.cpp | 14 ------------ UNITTESTS/stubs/AT_CellularNetwork_stub.cpp | 5 +++++ UNITTESTS/stubs/AT_CellularPower_stub.cpp | 5 ----- .../TESTS/api/cellular_power/main.cpp | 10 --------- .../cellular/TESTS/cellular_tests_common.h | 4 ++++ features/cellular/TESTS/socket/udp/main.cpp | 2 +- .../cellular/framework/API/CellularNetwork.h | 21 ++++++++++++++++++ .../cellular/framework/API/CellularPower.h | 22 ------------------- .../framework/AT/AT_CellularNetwork.cpp | 17 ++++++++++++++ .../framework/AT/AT_CellularNetwork.h | 3 +++ .../framework/AT/AT_CellularPower.cpp | 17 -------------- .../cellular/framework/AT/AT_CellularPower.h | 2 -- 13 files changed, 64 insertions(+), 71 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp index 8a590560f7..70d0d5435b 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -681,3 +681,16 @@ TEST_F(TestAT_CellularNetwork, test_get_connection_status) EXPECT_TRUE(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); } +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_receive_period) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_receive_period(1, CellularNetwork::EDRXUTRAN_Iu_mode, 3)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_receive_period(1, CellularNetwork::EDRXUTRAN_Iu_mode, 3)); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index 48b67abd2f..ac4d9cf1b4 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -151,20 +151,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_power_save_mode) EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0)); } -TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_receive_period) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3)); -} - TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready) { EventQueue que; diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp index 89720306d9..066710215e 100644 --- a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -150,3 +150,8 @@ bool AT_CellularNetwork::is_active_context() { return true; } + +nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index 56d8a4ca87..4b2a0f0ecd 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -60,11 +60,6 @@ nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int activ return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) -{ - return NSAPI_ERROR_OK; -} - nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) { return NSAPI_ERROR_OK; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index 70d2ccba6d..fb32d1144b 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -97,16 +97,6 @@ static void test_power_interface() } } - wait(1); - err = pwr->opt_receive_period(0, CellularPower::EDRXEUTRAN_NB_S1_mode, 3); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); - if (err == NSAPI_ERROR_DEVICE_ERROR) { - if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0)) { // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command - TEST_ASSERT(((AT_CellularPower *)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem - ((AT_CellularPower *)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem - } - } - err = pwr->off(); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); diff --git a/features/cellular/TESTS/cellular_tests_common.h b/features/cellular/TESTS/cellular_tests_common.h index 0303552412..95c740f088 100644 --- a/features/cellular/TESTS/cellular_tests_common.h +++ b/features/cellular/TESTS/cellular_tests_common.h @@ -50,10 +50,14 @@ 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); diff --git a/features/cellular/TESTS/socket/udp/main.cpp b/features/cellular/TESTS/socket/udp/main.cpp index f89afe9310..22073d5b59 100644 --- a/features/cellular/TESTS/socket/udp/main.cpp +++ b/features/cellular/TESTS/socket/udp/main.cpp @@ -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" diff --git a/features/cellular/framework/API/CellularNetwork.h b/features/cellular/framework/API/CellularNetwork.h index bc94267447..11f6fb90ab 100644 --- a/features/cellular/framework/API/CellularNetwork.h +++ b/features/cellular/framework/API/CellularNetwork.h @@ -363,6 +363,27 @@ public: * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_registration_params(RegistrationType type, registration_params_t ®_params) = 0; + + /** Set discontinuous reception time on cellular device. + * + * @remark See 3GPP TS 27.007 eDRX for details. + * + * @param mode disable or enable the use of eDRX + * @param act_type type of access technology + * @param edrx_value requested edxr value. Extended DRX parameters information element. + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + enum EDRXAccessTechnology { + EDRXGSM_EC_GSM_IoT_mode = 1, + EDRXGSM_A_Gb_mode, + EDRXUTRAN_Iu_mode, + EDRXEUTRAN_WB_S1_mode, + EDRXEUTRAN_NB_S1_mode + }; + virtual nsapi_error_t set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0; + }; /** diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index 8fea860fd4..881a934232 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -38,15 +38,6 @@ protected: virtual ~CellularPower() {} public: - /* Access technology used in method opt_receive_period */ - enum EDRXAccessTechnology { - EDRXGSM_EC_GSM_IoT_mode = 1, - EDRXGSM_A_Gb_mode, - EDRXUTRAN_Iu_mode, - EDRXEUTRAN_WB_S1_mode, - EDRXEUTRAN_NB_S1_mode - }; - /** Set cellular device power on. Default implementation is empty. * Device power on/off is modem/board specific behavior and must be done on inherited class if needed. * Power on is done by toggling power pin/button. @@ -114,19 +105,6 @@ public: */ virtual nsapi_error_t opt_power_save_mode(int periodic_time, int active_time) = 0; - /** Opt for discontinuous reception on cellular device. - * - * @remark See 3GPP TS 27.007 eDRX for details. - * - * @param mode disable or enable the use of eDRX - * @param act_type type of access technology - * @param edrx_value requested edxr value. Extended DRX parameters information element. - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0; - /** Check whether the device is ready to accept commands. * * @return NSAPI_ERROR_OK on success diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index ab6d90ee17..4f0d49a8a1 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -684,3 +684,20 @@ int AT_CellularNetwork::calculate_periodic_tau(const char *periodic_tau_string, return 0; } } + +nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) +{ + char edrx[5]; + uint_to_binary_str(edrx_value, edrx, 5, 4); + edrx[4] = '\0'; + + _at.lock(); + + _at.cmd_start("AT+CEDRXS="); + _at.write_int(mode); + _at.write_int(act_type); + _at.write_string(edrx); + _at.cmd_stop_read_resp(); + + return _at.unlock_return_error(); +} diff --git a/features/cellular/framework/AT/AT_CellularNetwork.h b/features/cellular/framework/AT/AT_CellularNetwork.h index 0f7f0c97d7..d889ac9aa5 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.h +++ b/features/cellular/framework/AT/AT_CellularNetwork.h @@ -87,6 +87,9 @@ public: // CellularNetwork virtual nsapi_error_t get_registration_params(registration_params_t ®_params); virtual nsapi_error_t get_registration_params(RegistrationType type, registration_params_t ®_params); + + virtual nsapi_error_t set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value); + protected: /** Check if modem supports given registration type. diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index 29b9045df4..152723e21e 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -202,23 +202,6 @@ nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int activ return _at.unlock_return_error(); } -nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) -{ - char edrx[5]; - uint_to_binary_str(edrx_value, edrx, 5, 4); - edrx[4] = '\0'; - - _at.lock(); - - _at.cmd_start("AT+CEDRXS="); - _at.write_int(mode); - _at.write_int(act_type); - _at.write_string(edrx); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); -} - nsapi_error_t AT_CellularPower::is_device_ready() { _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index 4e27abe5b4..6a4cc77e8c 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -46,8 +46,6 @@ public: virtual nsapi_error_t opt_power_save_mode(int periodic_time, int active_time); - virtual nsapi_error_t opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value); - virtual nsapi_error_t is_device_ready(); virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback callback); From 38f79a9b65a82b6d1c29e323b330bdff2acf3ebe Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Wed, 28 Nov 2018 00:57:11 -0800 Subject: [PATCH 07/41] Cellular: Move PSM setting from power to device --- .../at_cellulardevicetest.cpp | 28 ++++ .../at_cellularpower/at_cellularpowertest.cpp | 28 ---- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 5 + UNITTESTS/stubs/AT_CellularPower_stub.cpp | 5 - UNITTESTS/target_h/myCellularDevice.h | 5 + .../TESTS/api/cellular_power/main.cpp | 10 -- .../cellular/framework/API/CellularDevice.h | 13 ++ .../cellular/framework/API/CellularPower.h | 12 -- .../framework/AT/AT_CellularDevice.cpp | 129 ++++++++++++++++++ .../cellular/framework/AT/AT_CellularDevice.h | 2 + .../framework/AT/AT_CellularPower.cpp | 128 ----------------- .../cellular/framework/AT/AT_CellularPower.h | 2 - 12 files changed, 182 insertions(+), 185 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 6c14c61c58..17f1807e16 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -232,6 +232,34 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) dev.close_sms(); } +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_power_save_mode) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularDevice dev(&fh1); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(0, 0)); + + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(10, 0)); + + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(912, 0)); + + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(1834, 1834)); + + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(18345, 18345)); + + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(101234, 101234)); + + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(1012345, 1012345)); + + EXPECT_TRUE(NSAPI_ERROR_OK == dev.set_power_save_mode(39612345, 39612345)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == dev.set_power_save_mode(0)); +} + TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay) { FileHandle_stub fh1; diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index ac4d9cf1b4..35c05f5541 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -123,34 +123,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset) EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset()); } -TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_power_save_mode) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0)); - - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0)); - - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0)); - - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834)); - - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345)); - - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234)); - - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345)); - - EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345, 39612345)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0)); -} - TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready) { EventQueue que; diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 169929df30..4d2f7363a5 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -151,6 +151,11 @@ void AT_CellularDevice::modem_debug_on(bool on) } +nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) +{ + return NSAPI_ERROR_OK; +} + nsapi_error_t AT_CellularDevice::init_module() { return NSAPI_ERROR_OK; diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index 4b2a0f0ecd..d5a383456e 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -55,11 +55,6 @@ nsapi_error_t AT_CellularPower::reset() return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int active_time) -{ - return NSAPI_ERROR_OK; -} - nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) { return NSAPI_ERROR_OK; diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 7190f8f6f9..1e5e4c8078 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -109,6 +109,11 @@ public: virtual void modem_debug_on(bool on) {} + nsapi_error_t set_power_save_mode(int periodic_time, int active_time) + { + return NSAPI_ERROR_OK; + } + virtual nsapi_error_t init_module() { return 0; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index fb32d1144b..cb7b0378a0 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -87,16 +87,6 @@ static void test_power_interface() TEST_ASSERT(err == NSAPI_ERROR_OK); wait_for_power(pwr); - wait(1); - err = pwr->opt_power_save_mode(0, 0); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); - if (err == NSAPI_ERROR_DEVICE_ERROR) { - if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0)) { // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command - TEST_ASSERT(((AT_CellularPower *)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem - ((AT_CellularPower *)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem - } - } - err = pwr->off(); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 12ddb7315a..d79a250e6b 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -18,6 +18,7 @@ #ifndef CELLULAR_DEVICE_H_ #define CELLULAR_DEVICE_H_ +#include "CellularUtil.h" #include "CellularTargets.h" #include "CellularStateMachine.h" #include "Callback.h" @@ -249,6 +250,18 @@ public: */ virtual void modem_debug_on(bool on) = 0; + /** Set power save mode + * + * @remark See 3GPP TS 27.007 PSM for details + * + * @param periodic_time in seconds to enable power save, or zero to disable + * @param active_time in seconds to wait before entering power save mode + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0) = 0; + /** Initialize cellular module must be called right after module is ready. * For example, when multiple modules are supported in a single AT driver this function detects * and adapts to an actual module at runtime. diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index 881a934232..61246df5ed 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -93,18 +93,6 @@ public: */ virtual nsapi_error_t reset() = 0; - /** Opt for power save setting on cellular device. If both parameters are zero, this disables PSM. - * - * @remark See 3GPP TS 27.007 PSM for details - * - * @param periodic_time Timeout in seconds IoT subsystem is not expecting messaging - * @param active_time Timeout in seconds IoT subsystem waits for response - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t opt_power_save_mode(int periodic_time, int active_time) = 0; - /** Check whether the device is ready to accept commands. * * @return NSAPI_ERROR_OK on success diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 8d8b3de1a4..1c987cc200 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -27,6 +27,7 @@ #include "UARTSerial.h" #include "FileHandle.h" +using namespace mbed_cellular_util; using namespace events; using namespace mbed; @@ -365,6 +366,134 @@ void AT_CellularDevice::modem_debug_on(bool on) ATHandler::set_debug_list(_modem_debug_on); } +nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) +{ + _at->lock(); + + if (periodic_time == 0 && active_time == 0) { + // disable PSM + _at->cmd_start("AT+CPSMS="); + _at->write_int(0); + _at->cmd_stop_read_resp(); + } else { + const int PSMTimerBits = 5; + + /** + Table 10.5.163a/3GPP TS 24.008: GPRS Timer 3 information element + + Bits 5 to 1 represent the binary coded timer value. + + Bits 6 to 8 defines the timer value unit for the GPRS timer as follows: + 8 7 6 + 0 0 0 value is incremented in multiples of 10 minutes + 0 0 1 value is incremented in multiples of 1 hour + 0 1 0 value is incremented in multiples of 10 hours + 0 1 1 value is incremented in multiples of 2 seconds + 1 0 0 value is incremented in multiples of 30 seconds + 1 0 1 value is incremented in multiples of 1 minute + 1 1 0 value is incremented in multiples of 320 hours (NOTE 1) + 1 1 1 value indicates that the timer is deactivated (NOTE 2). + */ + char pt[8 + 1]; // timer value encoded as 3GPP IE + const int ie_value_max = 0x1f; + uint32_t periodic_timer = 0; + if (periodic_time <= 2 * ie_value_max) { // multiples of 2 seconds + periodic_timer = periodic_time / 2; + strcpy(pt, "01100000"); + } else { + if (periodic_time <= 30 * ie_value_max) { // multiples of 30 seconds + periodic_timer = periodic_time / 30; + strcpy(pt, "10000000"); + } else { + if (periodic_time <= 60 * ie_value_max) { // multiples of 1 minute + periodic_timer = periodic_time / 60; + strcpy(pt, "10100000"); + } else { + if (periodic_time <= 10 * 60 * ie_value_max) { // multiples of 10 minutes + periodic_timer = periodic_time / (10 * 60); + strcpy(pt, "00000000"); + } else { + if (periodic_time <= 60 * 60 * ie_value_max) { // multiples of 1 hour + periodic_timer = periodic_time / (60 * 60); + strcpy(pt, "00100000"); + } else { + if (periodic_time <= 10 * 60 * 60 * ie_value_max) { // multiples of 10 hours + periodic_timer = periodic_time / (10 * 60 * 60); + strcpy(pt, "01000000"); + } else { // multiples of 320 hours + int t = periodic_time / (320 * 60 * 60); + if (t > ie_value_max) { + t = ie_value_max; + } + periodic_timer = t; + strcpy(pt, "11000000"); + } + } + } + } + } + } + + uint_to_binary_str(periodic_timer, &pt[3], sizeof(pt) - 3, PSMTimerBits); + pt[8] = '\0'; + + /** + Table 10.5.172/3GPP TS 24.008: GPRS Timer information element + + Bits 5 to 1 represent the binary coded timer value. + + Bits 6 to 8 defines the timer value unit for the GPRS timer as follows: + + 8 7 6 + 0 0 0 value is incremented in multiples of 2 seconds + 0 0 1 value is incremented in multiples of 1 minute + 0 1 0 value is incremented in multiples of decihours + 1 1 1 value indicates that the timer is deactivated. + + Other values shall be interpreted as multiples of 1 minute in this version of the protocol. + */ + char at[8 + 1]; + uint32_t active_timer; // timer value encoded as 3GPP IE + if (active_time <= 2 * ie_value_max) { // multiples of 2 seconds + active_timer = active_time / 2; + strcpy(at, "00000000"); + } else { + if (active_time <= 60 * ie_value_max) { // multiples of 1 minute + active_timer = (1 << 5) | (active_time / 60); + strcpy(at, "00100000"); + } else { // multiples of decihours + int t = active_time / (6 * 60); + if (t > ie_value_max) { + t = ie_value_max; + } + active_timer = t; + strcpy(at, "01000000"); + } + } + + uint_to_binary_str(active_timer, &at[3], sizeof(at) - 3, PSMTimerBits); + at[8] = '\0'; + + // request for both GPRS and LTE + _at->cmd_start("AT+CPSMS="); + _at->write_int(1); + _at->write_string(pt); + _at->write_string(at); + _at->write_string(pt); + _at->write_string(at); + _at->cmd_stop_read_resp(); + + if (_at->get_last_error() != NSAPI_ERROR_OK) { + tr_warn("Power save mode not enabled!"); + } else { + // network may not agree with power save options but + // that should be fine as timeout is not longer than requested + } + } + + return _at->unlock_return_error(); +} + nsapi_error_t AT_CellularDevice::init_module() { #if MBED_CONF_MBED_TRACE_ENABLE diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 2068417dba..90808303c7 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -70,6 +70,8 @@ public: virtual void modem_debug_on(bool on); + virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); + virtual nsapi_error_t init_module(); virtual ATHandler *get_at_handler(FileHandle *fh); diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index 152723e21e..5889b1e900 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -21,8 +21,6 @@ #include "CellularTargets.h" #include "nsapi_types.h" -static const int PSMTimerBits = 5; - using namespace mbed_cellular_util; using namespace mbed; @@ -76,132 +74,6 @@ nsapi_error_t AT_CellularPower::reset() return _at.unlock_return_error(); } -nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int active_time) -{ - _at.lock(); - - if (periodic_time == 0 && active_time == 0) { - // disable PSM - _at.cmd_start("AT+CPSMS="); - _at.write_int(0); - _at.cmd_stop_read_resp(); - } else { - /** - Table 10.5.163a/3GPP TS 24.008: GPRS Timer 3 information element - - Bits 5 to 1 represent the binary coded timer value. - - Bits 6 to 8 defines the timer value unit for the GPRS timer as follows: - 8 7 6 - 0 0 0 value is incremented in multiples of 10 minutes - 0 0 1 value is incremented in multiples of 1 hour - 0 1 0 value is incremented in multiples of 10 hours - 0 1 1 value is incremented in multiples of 2 seconds - 1 0 0 value is incremented in multiples of 30 seconds - 1 0 1 value is incremented in multiples of 1 minute - 1 1 0 value is incremented in multiples of 320 hours (NOTE 1) - 1 1 1 value indicates that the timer is deactivated (NOTE 2). - */ - char pt[8 + 1]; // timer value encoded as 3GPP IE - const int ie_value_max = 0x1f; - uint32_t periodic_timer = 0; - if (periodic_time <= 2 * ie_value_max) { // multiples of 2 seconds - periodic_timer = periodic_time / 2; - strcpy(pt, "01100000"); - } else { - if (periodic_time <= 30 * ie_value_max) { // multiples of 30 seconds - periodic_timer = periodic_time / 30; - strcpy(pt, "10000000"); - } else { - if (periodic_time <= 60 * ie_value_max) { // multiples of 1 minute - periodic_timer = periodic_time / 60; - strcpy(pt, "10100000"); - } else { - if (periodic_time <= 10 * 60 * ie_value_max) { // multiples of 10 minutes - periodic_timer = periodic_time / (10 * 60); - strcpy(pt, "00000000"); - } else { - if (periodic_time <= 60 * 60 * ie_value_max) { // multiples of 1 hour - periodic_timer = periodic_time / (60 * 60); - strcpy(pt, "00100000"); - } else { - if (periodic_time <= 10 * 60 * 60 * ie_value_max) { // multiples of 10 hours - periodic_timer = periodic_time / (10 * 60 * 60); - strcpy(pt, "01000000"); - } else { // multiples of 320 hours - int t = periodic_time / (320 * 60 * 60); - if (t > ie_value_max) { - t = ie_value_max; - } - periodic_timer = t; - strcpy(pt, "11000000"); - } - } - } - } - } - } - - uint_to_binary_str(periodic_timer, &pt[3], sizeof(pt) - 3, PSMTimerBits); - pt[8] = '\0'; - - /** - Table 10.5.172/3GPP TS 24.008: GPRS Timer information element - - Bits 5 to 1 represent the binary coded timer value. - - Bits 6 to 8 defines the timer value unit for the GPRS timer as follows: - - 8 7 6 - 0 0 0 value is incremented in multiples of 2 seconds - 0 0 1 value is incremented in multiples of 1 minute - 0 1 0 value is incremented in multiples of decihours - 1 1 1 value indicates that the timer is deactivated. - - Other values shall be interpreted as multiples of 1 minute in this version of the protocol. - */ - char at[8 + 1]; - uint32_t active_timer; // timer value encoded as 3GPP IE - if (active_time <= 2 * ie_value_max) { // multiples of 2 seconds - active_timer = active_time / 2; - strcpy(at, "00000000"); - } else { - if (active_time <= 60 * ie_value_max) { // multiples of 1 minute - active_timer = (1 << 5) | (active_time / 60); - strcpy(at, "00100000"); - } else { // multiples of decihours - int t = active_time / (6 * 60); - if (t > ie_value_max) { - t = ie_value_max; - } - active_timer = t; - strcpy(at, "01000000"); - } - } - - uint_to_binary_str(active_timer, &at[3], sizeof(at) - 3, PSMTimerBits); - at[8] = '\0'; - - // request for both GPRS and LTE - _at.cmd_start("AT+CPSMS="); - _at.write_int(1); - _at.write_string(pt); - _at.write_string(at); - _at.write_string(pt); - _at.write_string(at); - _at.cmd_stop_read_resp(); - - if (_at.get_last_error() != NSAPI_ERROR_OK) { - tr_warn("Power save mode not enabled!"); - } else { - // network may not agree with power save options but - // that should be fine as timeout is not longer than requested - } - } - - return _at.unlock_return_error(); -} - nsapi_error_t AT_CellularPower::is_device_ready() { _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index 6a4cc77e8c..bc34586934 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -44,8 +44,6 @@ public: virtual nsapi_error_t reset(); - virtual nsapi_error_t opt_power_save_mode(int periodic_time, int active_time); - virtual nsapi_error_t is_device_ready(); virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback callback); From e49f90fb0b9b89bb3df6eda0c5181cb522ead564 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Wed, 28 Nov 2018 02:36:46 -0800 Subject: [PATCH 08/41] Cellular: Move device_ready from power to device --- .../at_cellulardevice/at_cellulardevicetest.cpp | 11 +++++++++++ .../AT/at_cellularpower/at_cellularpowertest.cpp | 11 ----------- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 5 +++++ UNITTESTS/stubs/AT_CellularPower_stub.cpp | 5 ----- UNITTESTS/target_h/myCellularDevice.h | 5 +++++ .../cellular/TESTS/api/cellular_power/main.cpp | 2 +- features/cellular/framework/API/CellularDevice.h | 7 +++++++ features/cellular/framework/API/CellularPower.h | 7 ------- .../cellular/framework/AT/AT_CellularDevice.cpp | 15 +++++++++++++++ .../cellular/framework/AT/AT_CellularDevice.h | 2 ++ .../cellular/framework/AT/AT_CellularPower.cpp | 15 --------------- features/cellular/framework/AT/AT_CellularPower.h | 2 -- .../framework/device/CellularStateMachine.cpp | 2 +- 13 files changed, 47 insertions(+), 42 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 17f1807e16..16219255df 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -232,6 +232,17 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) dev.close_sms(); } +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularDevice dev(&fh1); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == dev.is_ready()); +} + TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_power_save_mode) { EventQueue que; diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index 35c05f5541..560196788e 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -123,17 +123,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset) EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset()); } -TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready()); -} - TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb) { EventQueue que; diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 4d2f7363a5..6303dcdc0a 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -151,6 +151,11 @@ void AT_CellularDevice::modem_debug_on(bool on) } +nsapi_error_t AT_CellularDevice::is_ready() +{ + return NSAPI_ERROR_OK; +} + nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) { return NSAPI_ERROR_OK; diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index d5a383456e..1a2918be3b 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -64,8 +64,3 @@ void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback callbac { } - -nsapi_error_t AT_CellularPower::is_device_ready() -{ - return NSAPI_ERROR_OK; -} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 1e5e4c8078..8a7cb9199a 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -109,6 +109,11 @@ public: virtual void modem_debug_on(bool on) {} + virtual nsapi_error_t is_ready() + { + return NSAPI_ERROR_OK; + } + nsapi_error_t set_power_save_mode(int periodic_time, int active_time) { return NSAPI_ERROR_OK; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index cb7b0378a0..1a24939bb7 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -64,7 +64,7 @@ static void wait_for_power(CellularPower *pwr) err = pwr->set_at_mode(); } - TEST_ASSERT(pwr->is_device_ready() == NSAPI_ERROR_OK); + TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK); pwr->remove_device_ready_urc_cb(&urc_callback); } diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index d79a250e6b..9461e7a28c 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -250,6 +250,13 @@ public: */ virtual void modem_debug_on(bool on) = 0; + /** Check whether the device is ready to accept commands. + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t is_ready() = 0; + /** Set power save mode * * @remark See 3GPP TS 27.007 PSM for details diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index 61246df5ed..c3293be4de 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -93,13 +93,6 @@ public: */ virtual nsapi_error_t reset() = 0; - /** Check whether the device is ready to accept commands. - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t is_device_ready() = 0; - /** Set URC callback function for device specific ready urc. URC is defined in device specific * power API. Used in startup sequence to listen when device is ready * for using at commands and possible sim. diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 1c987cc200..49195f9016 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -366,6 +366,21 @@ void AT_CellularDevice::modem_debug_on(bool on) ATHandler::set_debug_list(_modem_debug_on); } +nsapi_error_t AT_CellularDevice::is_ready() +{ + _at->lock(); + _at->cmd_start("AT"); + _at->cmd_stop_read_resp(); + + // we need to do this twice because for example after data mode the first 'AT' command will give modem a + // stimulus that we are back to command mode. + _at->clear_error(); + _at->cmd_start("AT"); + _at->cmd_stop_read_resp(); + + return _at->unlock_return_error(); +} + nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) { _at->lock(); diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 90808303c7..33c373054d 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -70,6 +70,8 @@ public: virtual void modem_debug_on(bool on); + virtual nsapi_error_t is_ready(); + virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); virtual nsapi_error_t init_module(); diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index 5889b1e900..a6216c36fc 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -74,21 +74,6 @@ nsapi_error_t AT_CellularPower::reset() return _at.unlock_return_error(); } -nsapi_error_t AT_CellularPower::is_device_ready() -{ - _at.lock(); - _at.cmd_start("AT"); - _at.cmd_stop_read_resp(); - - // we need to do this twice because for example after data mode the first 'AT' command will give modem a - // stimulus that we are back to command mode. - _at.clear_error(); - _at.cmd_start("AT"); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); -} - nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) { return NSAPI_ERROR_UNSUPPORTED; diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index bc34586934..6a261d82e9 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -44,8 +44,6 @@ public: virtual nsapi_error_t reset(); - virtual nsapi_error_t is_device_ready(); - virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback callback); virtual void remove_device_ready_urc_cb(mbed::Callback callback); diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index 2fb57a22c9..b0a2b94e1e 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -339,7 +339,7 @@ void CellularStateMachine::state_init() if (!_power) { _power = _cellularDevice.open_power(); } - _cb_data.error = _power->is_device_ready(); + _cb_data.error = _cellularDevice.is_ready(); if (_cb_data.error != NSAPI_ERROR_OK) { _event_timeout = _start_time; if (_start_time > 0) { From 19b24946df339f7c90922a156a23c600092a5104 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Wed, 28 Nov 2018 03:30:24 -0800 Subject: [PATCH 09/41] Cellular: AT remove_urc_handler changed to set_urc_handler(prefix, 0) --- .../framework/AT/athandler/athandlertest.cpp | 7 +++--- features/cellular/framework/AT/ATHandler.cpp | 9 ++++++-- features/cellular/framework/AT/ATHandler.h | 22 +++++++++---------- .../framework/AT/AT_CellularNetwork.cpp | 6 ++--- .../GEMALTO_CINTERION_CellularStack.cpp | 6 ++--- .../BG96/QUECTEL_BG96_CellularPower.cpp | 2 +- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp index 211f80cc18..fb06161bb7 100644 --- a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp @@ -174,8 +174,7 @@ TEST_F(TestATHandler, test_ATHandler_remove_urc_handler) mbed::Callback cb(&urc_callback); at.set_urc_handler(ch, cb); - //This does nothing!!! - at.remove_urc_handler(ch); + at.set_urc_handler(ch, 0); } TEST_F(TestATHandler, test_ATHandler_get_last_error) @@ -996,10 +995,10 @@ TEST_F(TestATHandler, test_ATHandler_resp_start) filehandle_stub_table = table9; filehandle_stub_table_pos = 0; + at.set_urc_handler("urc: ", &urc_callback); at.set_urc_handler("urc: ", NULL); at.resp_start(); - // Match URC consumes to CRLF -> nothing to read after that -> ERROR - EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR); + EXPECT_EQ(at.get_last_error(), NSAPI_ERROR_OK); char table10[] = "urc: info\r\ngarbage\r\nprefix: info\r\nOK\r\n\0"; at.flush(); diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index 6da6dc9c56..93ff0a9e6e 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -160,8 +160,13 @@ void ATHandler::set_is_filehandle_usable(bool usable) _is_fh_usable = usable; } -nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback callback) +nsapi_error_t ATHandler::set_urc_handler(const char *prefix, Callback callback) { + if (!callback) { + remove_urc_handler(prefix); + return NSAPI_ERROR_OK; + } + if (find_urc_handler(prefix)) { tr_warn("URC already added with prefix: %s", prefix); return NSAPI_ERROR_OK; @@ -311,7 +316,7 @@ void ATHandler::process_oob() void ATHandler::set_filehandle_sigio() { - _fileHandle->sigio(mbed::Callback(this, &ATHandler::event)); + _fileHandle->sigio(Callback(this, &ATHandler::event)); } void ATHandler::reset_buffer() diff --git a/features/cellular/framework/AT/ATHandler.h b/features/cellular/framework/AT/ATHandler.h index c5757d2f87..dd76b98ba8 100644 --- a/features/cellular/framework/AT/ATHandler.h +++ b/features/cellular/framework/AT/ATHandler.h @@ -120,20 +120,13 @@ public: */ nsapi_error_t unlock_return_error(); - /** Set the urc callback for urc. If urc is found when parsing AT responses, then call if called. - * If urc is already set then it's not set twice. + /** Set callback function for URC * - * @param prefix Register urc prefix for callback. Urc could be for example "+CMTI: " - * @param callback Callback, which is called if urc is found in AT response + * @param prefix URC text to look for, e.g. "+CMTI:" + * @param callback function to call on prefix, or 0 to remove callback * @return NSAPI_ERROR_OK or NSAPI_ERROR_NO_MEMORY if no memory */ - nsapi_error_t set_urc_handler(const char *prefix, mbed::Callback callback); - - /** Remove urc handler from linked list of urc's - * - * @param prefix Register urc prefix for callback. Urc could be for example "+CMTI: " - */ - void remove_urc_handler(const char *prefix); + nsapi_error_t set_urc_handler(const char *prefix, Callback callback); ATHandler *_nextATHandler; // linked list @@ -229,6 +222,11 @@ protected: #endif FileHandle *_fileHandle; private: + /** Remove urc handler from linked list of urc's + * + * @param prefix Register urc prefix for callback. Urc could be for example "+CMTI: " + */ + void remove_urc_handler(const char *prefix); void set_error(nsapi_error_t err); @@ -242,7 +240,7 @@ private: struct oob_t { const char *prefix; int prefix_len; - mbed::Callback cb; + Callback cb; oob_t *next; }; oob_t *_oobs; diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index 4f0d49a8a1..5a66c77d80 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -104,12 +104,12 @@ AT_CellularNetwork::~AT_CellularNetwork() for (int type = 0; type < CellularNetwork::C_MAX; type++) { if (has_registration((RegistrationType)type) != RegistrationModeDisable) { - _at.remove_urc_handler(at_reg[type].urc_prefix); + _at.set_urc_handler(at_reg[type].urc_prefix, 0); } } - _at.remove_urc_handler("NO CARRIER"); - _at.remove_urc_handler("+CGEV:"); + _at.set_urc_handler("NO CARRIER", 0); + _at.set_urc_handler("+CGEV:", 0); } void AT_CellularNetwork::urc_no_carrier() diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp index 14fb6543fc..b8f508b354 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp @@ -39,9 +39,9 @@ GEMALTO_CINTERION_CellularStack::GEMALTO_CINTERION_CellularStack(ATHandler &atHa GEMALTO_CINTERION_CellularStack::~GEMALTO_CINTERION_CellularStack() { - _at.remove_urc_handler("^SIS:"); - _at.remove_urc_handler("^SISW:"); - _at.remove_urc_handler("^SISR:"); + _at.set_urc_handler("^SIS:", 0); + _at.set_urc_handler("^SISW:", 0); + _at.set_urc_handler("^SISR:", 0); } GEMALTO_CINTERION_CellularStack::CellularSocket *GEMALTO_CINTERION_CellularStack::find_socket(int sock_id) diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp index f6e35196a0..4ab4e07037 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp @@ -32,5 +32,5 @@ nsapi_error_t QUECTEL_BG96_CellularPower::set_device_ready_urc_cb(mbed::Callback void QUECTEL_BG96_CellularPower::remove_device_ready_urc_cb(mbed::Callback callback) { - _at.remove_urc_handler(DEVICE_READY_URC); + _at.set_urc_handler(DEVICE_READY_URC, 0); } From 2dde5a4376fc334b8720508fc5426108e2b46d30 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Wed, 28 Nov 2018 05:00:35 -0800 Subject: [PATCH 10/41] Cellular: Move ready_cb from power to device --- .../at_cellulardevicetest.cpp | 14 ++++++++++ .../at_cellularpower/at_cellularpowertest.cpp | 28 ------------------- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 7 ++++- UNITTESTS/stubs/AT_CellularPower_stub.cpp | 10 ------- UNITTESTS/target_h/myCellularDevice.h | 5 ++++ .../TESTS/api/cellular_power/main.cpp | 4 +-- .../cellular/framework/API/CellularDevice.h | 10 +++++++ .../cellular/framework/API/CellularPower.h | 18 ------------ .../framework/AT/AT_CellularDevice.cpp | 5 ++++ .../cellular/framework/AT/AT_CellularDevice.h | 2 ++ .../framework/AT/AT_CellularPower.cpp | 9 ------ .../cellular/framework/AT/AT_CellularPower.h | 4 --- .../framework/device/CellularStateMachine.cpp | 5 ++-- .../framework/device/CellularStateMachine.h | 2 +- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 6 ++-- .../targets/QUECTEL/BG96/QUECTEL_BG96.h | 2 ++ .../BG96/QUECTEL_BG96_CellularPower.cpp | 10 ------- .../QUECTEL/BG96/QUECTEL_BG96_CellularPower.h | 4 --- 18 files changed, 51 insertions(+), 94 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 16219255df..58447ea155 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -398,3 +398,17 @@ TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_get_sim_state) delete dev; } + +static void device_ready_cb() +{ +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_ready_cb) +{ + EventQueue que; + FileHandle_stub fh1; + AT_CellularDevice *dev = new AT_CellularDevice(&fh1); + + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(&device_ready_cb)); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(0)); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index 560196788e..f2d8ee9f9e 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -41,10 +41,6 @@ protected: // *INDENT-ON* -static void device_ready_cb() -{ -} - TEST_F(TestAT_CellularPower, Create) { @@ -122,27 +118,3 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset()); } - -TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb)); - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL)); -} - -TEST_F(TestAT_CellularPower, test_AT_CellularPower_remove_device_ready_urc_cb) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb)); - - pow.remove_device_ready_urc_cb(NULL); - pow.remove_device_ready_urc_cb(&device_ready_cb); -} diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 6303dcdc0a..90c347fd10 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -156,9 +156,14 @@ nsapi_error_t AT_CellularDevice::is_ready() return NSAPI_ERROR_OK; } +nsapi_error_t AT_CellularDevice::set_ready_cb(mbed::Callback callback) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) { - return NSAPI_ERROR_OK; + return NSAPI_ERROR_UNSUPPORTED; } nsapi_error_t AT_CellularDevice::init_module() diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index 1a2918be3b..420878aa57 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -54,13 +54,3 @@ nsapi_error_t AT_CellularPower::reset() { return NSAPI_ERROR_OK; } - -nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) -{ - return NSAPI_ERROR_OK; -} - -void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback callback) -{ - -} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 8a7cb9199a..628a0d7bbb 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -114,6 +114,11 @@ public: return NSAPI_ERROR_OK; } + virtual nsapi_error_t set_ready_cb(Callback callback) + { + return NSAPI_ERROR_UNSUPPORTED; + } + nsapi_error_t set_power_save_mode(int periodic_time, int active_time) { return NSAPI_ERROR_OK; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index 1a24939bb7..0b221be541 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -52,7 +52,7 @@ static void urc_callback() static void wait_for_power(CellularPower *pwr) { - nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback); + nsapi_error_t err = cellular_device->set_ready_cb(&urc_callback); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); int sanity_count = 0; @@ -66,7 +66,7 @@ static void wait_for_power(CellularPower *pwr) TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK); - pwr->remove_device_ready_urc_cb(&urc_callback); + TEST_ASSERT(cellular_device->set_ready_cb(0) == NSAPI_ERROR_OK); } static void test_power_interface() diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 9461e7a28c..8c748ef053 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -257,6 +257,16 @@ public: */ virtual nsapi_error_t is_ready() = 0; + /** Set callback function to listen when device is ready. + * + * @param callback function to call on device ready, or NULL to remove callback. + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_NO_MEMORY on memory failure + * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem + */ + virtual nsapi_error_t set_ready_cb(Callback callback) = 0; + /** Set power save mode * * @remark See 3GPP TS 27.007 PSM for details diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index c3293be4de..b523850c42 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -92,24 +92,6 @@ public: * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t reset() = 0; - - /** Set URC callback function for device specific ready urc. URC is defined in device specific - * power API. Used in startup sequence to listen when device is ready - * for using at commands and possible sim. - * - * @param callback Callback function called when urc received - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_NO_MEMORY on memory failure - * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem - */ - virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback callback) = 0; - - /** Removes the device ready urc from the list of urc's. - * - * @param callback callback to remove from the list of urc's - */ - virtual void remove_device_ready_urc_cb(mbed::Callback callback) = 0; }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 49195f9016..4f0bfc0b6c 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -381,6 +381,11 @@ nsapi_error_t AT_CellularDevice::is_ready() return _at->unlock_return_error(); } +nsapi_error_t AT_CellularDevice::set_ready_cb(Callback callback) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) { _at->lock(); diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 33c373054d..814ae8350f 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -72,6 +72,8 @@ public: virtual nsapi_error_t is_ready(); + virtual nsapi_error_t set_ready_cb(Callback callback); + virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); virtual nsapi_error_t init_module(); diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index a6216c36fc..c4b4b8b4f6 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -73,12 +73,3 @@ nsapi_error_t AT_CellularPower::reset() _at.cmd_stop_read_resp(); return _at.unlock_return_error(); } - -nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback callback) -{ -} diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index 6a261d82e9..b31653f473 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -43,10 +43,6 @@ public: virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0); virtual nsapi_error_t reset(); - - virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback callback); - - virtual void remove_device_ready_urc_cb(mbed::Callback callback); }; } // namespace mbed diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index b0a2b94e1e..ecd3a6e2a8 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -387,8 +387,7 @@ bool CellularStateMachine::device_ready() if (_event_status_cb) { _event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t)&_cb_data); } - - _power->remove_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb)); + _cellularDevice.set_ready_cb(0); _cellularDevice.close_power(); _power = NULL; return true; @@ -406,7 +405,7 @@ void CellularStateMachine::state_device_ready() } } else { if (_retry_count == 0) { - _power->set_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb)); + _cellularDevice.set_ready_cb(callback(this, &CellularStateMachine::device_ready_cb)); } retry_state_or_fail(); } diff --git a/features/cellular/framework/device/CellularStateMachine.h b/features/cellular/framework/device/CellularStateMachine.h index 35d3c8dc28..c9d10e9f25 100644 --- a/features/cellular/framework/device/CellularStateMachine.h +++ b/features/cellular/framework/device/CellularStateMachine.h @@ -154,7 +154,7 @@ private: bool is_registered_to_plmn(); void report_failure(const char *msg); void event(); - void ready_urc_cb(); + void device_ready_cb(); void pre_event(CellularState state); bool check_is_target_reached(); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 55e673acfd..a5c9c9d8f2 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -32,6 +32,8 @@ using namespace events; #define MAX_STARTUP_TRIALS 5 #define MAX_RESET_TRIALS 5 +#define DEVICE_READY_URC "CPIN:" + static const AT_CellularBase::SupportedFeature unsupported_features[] = { AT_CellularBase::AT_CGSN_WITH_TYPE, AT_CellularBase::AT_CGDATA, @@ -62,7 +64,3 @@ 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); -} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 1cc8b4a892..956803edf4 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -32,6 +32,8 @@ protected: // AT_CellularDevice virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual AT_CellularInformation *open_information_impl(ATHandler &at); + virtual nsapi_error_t set_ready_cb(Callback callback); + public: void handle_urc(FileHandle *fh); }; diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp index 4ab4e07037..6ef1917c12 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp @@ -24,13 +24,3 @@ using namespace mbed; QUECTEL_BG96_CellularPower::QUECTEL_BG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) { } - -nsapi_error_t QUECTEL_BG96_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) -{ - return _at.set_urc_handler(DEVICE_READY_URC, callback); -} - -void QUECTEL_BG96_CellularPower::remove_device_ready_urc_cb(mbed::Callback callback) -{ - _at.set_urc_handler(DEVICE_READY_URC, 0); -} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h index ec7368cbfe..6d3f4077d3 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h @@ -25,10 +25,6 @@ namespace mbed { class QUECTEL_BG96_CellularPower : public AT_CellularPower { public: QUECTEL_BG96_CellularPower(ATHandler &atHandler); - -public: //from CellularPower - virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback callback); - virtual void remove_device_ready_urc_cb(mbed::Callback callback); }; } // namespace mbed From 0813b969f773b45774427413c43ff2221193165d Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Wed, 28 Nov 2018 23:17:34 -0800 Subject: [PATCH 11/41] Cellular: Unify set_at_mode and init_module into init() --- .../at_cellulardevicetest.cpp | 15 +++++----- .../at_cellularpower/at_cellularpowertest.cpp | 14 --------- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 2 +- UNITTESTS/stubs/AT_CellularPower_stub.cpp | 5 ---- UNITTESTS/target_h/myCellularDevice.h | 10 +++---- .../TESTS/api/cellular_power/main.cpp | 4 +-- .../cellular/framework/API/CellularDevice.h | 24 +++++++-------- .../cellular/framework/API/CellularPower.h | 11 +------ .../framework/AT/AT_CellularDevice.cpp | 29 ++++++++----------- .../cellular/framework/AT/AT_CellularDevice.h | 3 +- .../framework/AT/AT_CellularPower.cpp | 12 -------- .../cellular/framework/AT/AT_CellularPower.h | 2 -- .../framework/device/CellularStateMachine.cpp | 11 +++---- .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 7 ++++- .../GEMALTO/CINTERION/GEMALTO_CINTERION.h | 14 ++++----- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 14 +++++++++ .../targets/QUECTEL/BC95/QUECTEL_BC95.h | 1 + .../BC95/QUECTEL_BC95_CellularPower.cpp | 14 --------- .../QUECTEL/BC95/QUECTEL_BC95_CellularPower.h | 2 -- .../targets/TELIT/HE910/TELIT_HE910.cpp | 12 ++++++++ .../targets/TELIT/HE910/TELIT_HE910.h | 3 +- .../TELIT/HE910/TELIT_HE910_CellularPower.cpp | 18 ------------ .../TELIT/HE910/TELIT_HE910_CellularPower.h | 2 -- 23 files changed, 88 insertions(+), 141 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 58447ea155..7a74a72c36 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -232,6 +232,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) dev.close_sms(); } +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init) +{ + FileHandle_stub fh1; + AT_CellularDevice dev(&fh1); + EXPECT_EQ(dev.init(), NSAPI_ERROR_OK); +} + + TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready) { EventQueue que; @@ -278,13 +286,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay) EXPECT_TRUE(0 == dev.get_send_delay()); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module()); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context) { FileHandle_stub fh1; diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index f2d8ee9f9e..eae2eb16b8 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -75,20 +75,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_off) EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off()); } -TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_at_mode) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_at_mode()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode()); -} - TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level) { EventQueue que; diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 90c347fd10..ad741d8c7c 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -166,7 +166,7 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti return NSAPI_ERROR_UNSUPPORTED; } -nsapi_error_t AT_CellularDevice::init_module() +nsapi_error_t AT_CellularDevice::init() { return NSAPI_ERROR_OK; } diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index 420878aa57..6b544ff407 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -40,11 +40,6 @@ nsapi_error_t AT_CellularPower::off() return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularPower::set_at_mode() -{ - return NSAPI_ERROR_OK; -} - nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset) { return NSAPI_ERROR_OK; diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 628a0d7bbb..077cf4ec6a 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -109,6 +109,11 @@ public: virtual void modem_debug_on(bool on) {} + virtual nsapi_error_t init() + { + return NSAPI_ERROR_OK; + } + virtual nsapi_error_t is_ready() { return NSAPI_ERROR_OK; @@ -124,11 +129,6 @@ public: return NSAPI_ERROR_OK; } - virtual nsapi_error_t init_module() - { - return 0; - } - virtual CellularContext *get_context_list() const { return _context_list; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index 0b221be541..a043479c06 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -56,12 +56,12 @@ static void wait_for_power(CellularPower *pwr) TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); int sanity_count = 0; - err = pwr->set_at_mode(); + err = cellular_device->init(); while (err != NSAPI_ERROR_OK) { sanity_count++; wait(1); TEST_ASSERT(sanity_count < 40); - err = pwr->set_at_mode(); + err = cellular_device->init(); } TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK); diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 8c748ef053..d3f228a505 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -250,6 +250,18 @@ public: */ virtual void modem_debug_on(bool on) = 0; + /** Initialize cellular device must be called right after module is ready. + * For example, when multiple cellular modules are supported in a single driver this function + * detects and adapts to an actual module at runtime. + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_NO_MEMORY on case of memory failure + * NSAPI_ERROR_UNSUPPORTED if current model is not detected + * NSAPI_ERROR_DEVICE_ERROR if model information could not be read + * + */ + virtual nsapi_error_t init() = 0; + /** Check whether the device is ready to accept commands. * * @return NSAPI_ERROR_OK on success @@ -279,18 +291,6 @@ public: */ virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0) = 0; - /** Initialize cellular module must be called right after module is ready. - * For example, when multiple modules are supported in a single AT driver this function detects - * and adapts to an actual module at runtime. - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_NO_MEMORY on case of memory failure - * NSAPI_ERROR_UNSUPPORTED if current model is not detected - * NSAPI_ERROR_DEVICE_ERROR if model information could not be read - * - */ - virtual nsapi_error_t init_module() = 0; - /** Get the linked list of CellularContext instances * * @return Pointer to first item in linked list diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index b523850c42..32420bee88 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -42,7 +42,7 @@ public: * Device power on/off is modem/board specific behavior and must be done on inherited class if needed. * Power on is done by toggling power pin/button. * - * @remark set_at_mode must be called to initialise modem + * @remark init must be called to initialize cellular device * * @return NSAPI_ERROR_OK on success * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem @@ -58,15 +58,6 @@ public: */ virtual nsapi_error_t off() = 0; - /** Set AT command mode. Blocking until success or failure. - * - * @remark must be called after power on to prepare correct AT mode - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t set_at_mode() = 0; - /** Set cellular device power level by enabling/disabling functionality. * * @param func_level: diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 4f0bfc0b6c..3a2cc64715 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -366,6 +366,18 @@ void AT_CellularDevice::modem_debug_on(bool on) ATHandler::set_debug_list(_modem_debug_on); } +nsapi_error_t AT_CellularDevice::init() +{ + _at->lock(); + _at->flush(); + _at->cmd_start("ATE0"); // echo off + _at->cmd_stop_read_resp(); + + _at->cmd_start("AT+CMEE=1"); // verbose responses + _at->cmd_stop_read_resp(); + return _at->unlock_return_error(); +} + nsapi_error_t AT_CellularDevice::is_ready() { _at->lock(); @@ -513,20 +525,3 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti return _at->unlock_return_error(); } - -nsapi_error_t AT_CellularDevice::init_module() -{ -#if MBED_CONF_MBED_TRACE_ENABLE - CellularInformation *information = open_information(); - if (information) { - char *pbuf = new char[100]; - nsapi_error_t ret = information->get_model(pbuf, sizeof(*pbuf)); - close_information(); - if (ret == NSAPI_ERROR_OK) { - tr_info("Model %s", pbuf); - } - delete[] pbuf; - } -#endif - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 814ae8350f..42d4f82988 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -70,13 +70,14 @@ public: virtual void modem_debug_on(bool on); + virtual nsapi_error_t init(); + virtual nsapi_error_t is_ready(); virtual nsapi_error_t set_ready_cb(Callback callback); virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); - virtual nsapi_error_t init_module(); virtual ATHandler *get_at_handler(FileHandle *fh); diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index c4b4b8b4f6..af0feb9c16 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -42,18 +42,6 @@ nsapi_error_t AT_CellularPower::off() return NSAPI_ERROR_UNSUPPORTED; } -nsapi_error_t AT_CellularPower::set_at_mode() -{ - _at.lock(); - _at.flush(); - _at.cmd_start("ATE0"); // echo off - _at.cmd_stop_read_resp(); - - _at.cmd_start("AT+CMEE=1"); // verbose responses - _at.cmd_stop_read_resp(); - return _at.unlock_return_error(); -} - nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset) { _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index b31653f473..e88dfa6280 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -38,8 +38,6 @@ public: virtual nsapi_error_t off(); - virtual nsapi_error_t set_at_mode(); - virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0); virtual nsapi_error_t reset(); diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index ecd3a6e2a8..25988de447 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -366,9 +366,6 @@ void CellularStateMachine::state_power_on() bool CellularStateMachine::device_ready() { tr_info("Modem ready"); - if (_cellularDevice.init_module() != NSAPI_ERROR_OK) { - return false; - } if (!_network) { _network = _cellularDevice.open_network(); @@ -396,7 +393,7 @@ bool CellularStateMachine::device_ready() void CellularStateMachine::state_device_ready() { _cellularDevice.set_timeout(TIMEOUT_POWER_ON); - _cb_data.error = _power->set_at_mode(); + _cb_data.error = _cellularDevice.init(); if (_cb_data.error == NSAPI_ERROR_OK) { if (device_ready()) { enter_to_state(STATE_SIM_PIN); @@ -713,10 +710,10 @@ void CellularStateMachine::cellular_event_changed(nsapi_event_t ev, intptr_t ptr } } -void CellularStateMachine::ready_urc_cb() +void CellularStateMachine::device_ready_cb() { - tr_debug("Device ready URC func called"); - if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) { + tr_debug("Device ready callback"); + if (_state == STATE_DEVICE_READY && _cellularDevice.init() == NSAPI_ERROR_OK) { tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next"); _queue.cancel(_event_id); _event_id = -1; diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 1dd1e58cf9..fc4b62e015 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -47,8 +47,13 @@ AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const return new GEMALTO_CINTERION_CellularContext(at, this, apn); } -nsapi_error_t GEMALTO_CINTERION::init_module() +nsapi_error_t GEMALTO_CINTERION::init() { + nsapi_error_t err = AT_CellularDevice::init(); + if (err != NSAPI_ERROR_OK) { + return err; + } + CellularInformation *information = open_information(); if (!information) { return NSAPI_ERROR_NO_MEMORY; diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h index 2a58da242b..4d79202c2e 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h @@ -28,13 +28,6 @@ public: GEMALTO_CINTERION(FileHandle *fh); virtual ~GEMALTO_CINTERION(); -protected: // AT_CellularDevice - virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); -public: - virtual nsapi_error_t init_module(); - virtual uint16_t get_send_delay() const; - /** Actual model of cellular module is needed to make AT command adaptation at runtime * to support many different models in one cellular driver. */ @@ -46,6 +39,13 @@ public: }; static Module get_module(); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); +protected: + virtual uint16_t get_send_delay() const; + virtual nsapi_error_t init(); + private: static Module _module; void init_module_bgs2(); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 72e2c2974c..0c77a4b3ac 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -83,3 +83,17 @@ AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at) return new QUECTEL_BC95_CellularInformation(at); } +nsapi_error_t QUECTEL_BC95::init() +{ + _at->lock(); + _at->flush(); + _at->cmd_start("AT"); + _at->cmd_stop_read_resp(); + + _at->cmd_start("AT+CMEE="); // verbose responses + _at->write_int(1); + _at->cmd_stop_read_resp(); + + return _at->unlock_return_error(); +} + diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index 1df0f2d05f..da3942240a 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -35,6 +35,7 @@ protected: // AT_CellularDevice virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual AT_CellularInformation *open_information_impl(ATHandler &at); + virtual nsapi_error_t init(); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp index fc27d257e8..73a5086e2d 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp @@ -29,20 +29,6 @@ QUECTEL_BC95_CellularPower::~QUECTEL_BC95_CellularPower() } -nsapi_error_t QUECTEL_BC95_CellularPower::set_at_mode() -{ - _at.lock(); - _at.flush(); - _at.cmd_start("AT"); - _at.cmd_stop_read_resp(); - - _at.cmd_start("AT+CMEE="); // verbose responses - _at.write_int(1); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); -} - nsapi_error_t QUECTEL_BC95_CellularPower::reset() { _at.lock(); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h index a10ab3e5d3..fedb654a23 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h @@ -28,8 +28,6 @@ public: virtual ~QUECTEL_BC95_CellularPower(); public: //from CellularPower - virtual nsapi_error_t set_at_mode(); - virtual nsapi_error_t reset(); }; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index d3feca74d3..21d6b51a61 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -58,3 +58,15 @@ uint16_t TELIT_HE910::get_send_delay() const return DEFAULT_DELAY_BETWEEN_AT_COMMANDS; } +nsapi_error_t TELIT_HE910::init() +{ + nsapi_error_t err = AT_CellularDevice::init(); + if (err != NSAPI_ERROR_OK) { + return err; + } + _at->lock(); + _at->cmd_start("AT&K0;&C1;&D0"); + _at->cmd_stop_read_resp(); + + return _at->unlock_return_error(); +} diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h index b09f525608..0bb7cf07bc 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h @@ -34,9 +34,8 @@ protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); - -public: // from CellularDevice virtual uint16_t get_send_delay() const; + virtual nsapi_error_t init(); }; } // namespace mbed #endif /* CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ */ diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp index 68a397743d..32a33cb8a9 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp @@ -47,21 +47,3 @@ nsapi_error_t TELIT_HE910_CellularPower::off() #endif return NSAPI_ERROR_OK; } - -/** - * Set AT command mode. - * @remark must be called after power on to prepare correct AT mode - * @return blocking until success or failure - */ -nsapi_error_t TELIT_HE910_CellularPower::set_at_mode() -{ - nsapi_error_t err = AT_CellularPower::set_at_mode(); - if (err != NSAPI_ERROR_OK) { - return err; - } - _at.lock(); - _at.cmd_start("AT&K0;&C1;&D0"); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); -} diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h index e60f1620ce..2f3d9be7b2 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h @@ -32,8 +32,6 @@ public: //from CellularPower virtual nsapi_error_t on(); virtual nsapi_error_t off(); - - virtual nsapi_error_t set_at_mode(); }; } // namespace mbed From 1bc84404b29cde2e84bfcac0fe41e0c7f34748ba Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Wed, 28 Nov 2018 23:35:43 -0800 Subject: [PATCH 12/41] Cellular: Removed set_power_level() --- .../at_cellularpower/at_cellularpowertest.cpp | 16 ---------------- UNITTESTS/stubs/AT_CellularPower_stub.cpp | 5 ----- .../TESTS/api/cellular_power/main.cpp | 2 -- .../cellular/framework/API/CellularPower.h | 19 ------------------- .../framework/AT/AT_CellularPower.cpp | 10 ---------- .../cellular/framework/AT/AT_CellularPower.h | 2 -- 6 files changed, 54 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index eae2eb16b8..d92636bb88 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -75,22 +75,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_off) EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off()); } -TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(6)); - EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 1)); - EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 0)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6)); -} - TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset) { EventQueue que; diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index 6b544ff407..a4e9c52b62 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -40,11 +40,6 @@ nsapi_error_t AT_CellularPower::off() return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset) -{ - return NSAPI_ERROR_OK; -} - nsapi_error_t AT_CellularPower::reset() { return NSAPI_ERROR_OK; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index a043479c06..000e4ed480 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -81,8 +81,6 @@ static void test_power_interface() TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); wait_for_power(pwr); - TEST_ASSERT(pwr->set_power_level(1, 0) == NSAPI_ERROR_OK); - err = pwr->reset(); TEST_ASSERT(err == NSAPI_ERROR_OK); wait_for_power(pwr); diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index 32420bee88..59dc83aca7 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -58,25 +58,6 @@ public: */ virtual nsapi_error_t off() = 0; - /** Set cellular device power level by enabling/disabling functionality. - * - * @param func_level: - * 0 minimum functionality - * 1 full functionality. Enable (turn on) the transmit and receive RF circuits for all supported radio access technologies. - * For MTs supporting +CSRA, this equals the RATs indicated by the response of +CSRA=?. Current +CSRA setting is ignored. - * It is not required that the MT transmit and receive RF circuits are in a disabled state for this setting to have effect. - * 2 disable (turn off) MT transmit RF circuits only - * 3 disable (turn off) MT receive RF circuits only - * 4 disable (turn off) both MT transmit and receive RF circuits - * @param do_reset 0 for do not reset, 1 for reset the device when changing the functionality - * - * @remark See 3GPP TS 27.007 CFUN for more details - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0) = 0; - /** Reset and wake-up cellular device. * * @return NSAPI_ERROR_OK on success diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index af0feb9c16..4be451cdea 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -42,16 +42,6 @@ nsapi_error_t AT_CellularPower::off() return NSAPI_ERROR_UNSUPPORTED; } -nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset) -{ - _at.lock(); - _at.cmd_start("AT+CFUN="); - _at.write_int(func_level); - _at.write_int(do_reset); - _at.cmd_stop_read_resp(); - return _at.unlock_return_error(); -} - nsapi_error_t AT_CellularPower::reset() { _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index e88dfa6280..cd7dc21b20 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -38,8 +38,6 @@ public: virtual nsapi_error_t off(); - virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0); - virtual nsapi_error_t reset(); }; From bdddb445a6d990dea78b96b6be50646ec86f705b Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Thu, 29 Nov 2018 00:22:39 -0800 Subject: [PATCH 13/41] Cellular: Moved reset from power to device --- .../AT/at_cellulardevice/at_cellulardevicetest.cpp | 6 ++++++ .../AT/at_cellularpower/at_cellularpowertest.cpp | 14 -------------- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 5 +++++ UNITTESTS/stubs/AT_CellularPower_stub.cpp | 5 ----- UNITTESTS/target_h/myCellularDevice.h | 5 +++++ .../cellular/TESTS/api/cellular_power/main.cpp | 4 ---- features/cellular/framework/API/CellularDevice.h | 7 +++++++ features/cellular/framework/API/CellularPower.h | 7 ------- .../cellular/framework/AT/AT_CellularDevice.cpp | 11 +++++++++++ features/cellular/framework/AT/AT_CellularDevice.h | 2 ++ .../cellular/framework/AT/AT_CellularPower.cpp | 10 ---------- features/cellular/framework/AT/AT_CellularPower.h | 2 -- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 11 ++++++++--- .../framework/targets/QUECTEL/BC95/QUECTEL_BC95.h | 1 + .../QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp | 9 --------- .../QUECTEL/BC95/QUECTEL_BC95_CellularPower.h | 3 --- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 3 --- .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 3 --- 18 files changed, 45 insertions(+), 63 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 7a74a72c36..035ec9e7c3 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -239,6 +239,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init) EXPECT_EQ(dev.init(), NSAPI_ERROR_OK); } +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_reset) +{ + FileHandle_stub fh1; + AT_CellularDevice dev(&fh1); + EXPECT_EQ(dev.reset(), NSAPI_ERROR_OK); +} TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready) { diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp index d92636bb88..257ded8771 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -74,17 +74,3 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_off) AT_CellularPower pow(at); EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off()); } - -TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == pow.reset()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset()); -} diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index ad741d8c7c..06b246c247 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -171,6 +171,11 @@ nsapi_error_t AT_CellularDevice::init() return NSAPI_ERROR_OK; } +nsapi_error_t AT_CellularDevice::reset() +{ + return NSAPI_ERROR_OK; +} + nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin) { return NSAPI_ERROR_OK; diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index a4e9c52b62..0076be2669 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -39,8 +39,3 @@ nsapi_error_t AT_CellularPower::off() { return NSAPI_ERROR_OK; } - -nsapi_error_t AT_CellularPower::reset() -{ - return NSAPI_ERROR_OK; -} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 077cf4ec6a..4caed90c89 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -114,6 +114,11 @@ public: return NSAPI_ERROR_OK; } + virtual nsapi_error_t reset() + { + return NSAPI_ERROR_OK; + } + virtual nsapi_error_t is_ready() { return NSAPI_ERROR_OK; diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index 000e4ed480..ac5ab953d2 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -81,10 +81,6 @@ static void test_power_interface() TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); wait_for_power(pwr); - err = pwr->reset(); - TEST_ASSERT(err == NSAPI_ERROR_OK); - wait_for_power(pwr); - err = pwr->off(); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index d3f228a505..200d7c3da2 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -262,6 +262,13 @@ public: */ virtual nsapi_error_t init() = 0; + /** Reset and wake-up cellular device. + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t reset() = 0; + /** Check whether the device is ready to accept commands. * * @return NSAPI_ERROR_OK on success diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h index 59dc83aca7..5c2ce68f3a 100644 --- a/features/cellular/framework/API/CellularPower.h +++ b/features/cellular/framework/API/CellularPower.h @@ -57,13 +57,6 @@ public: * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem */ virtual nsapi_error_t off() = 0; - - /** Reset and wake-up cellular device. - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t reset() = 0; }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 3a2cc64715..5d6ea818d0 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -378,6 +378,17 @@ nsapi_error_t AT_CellularDevice::init() return _at->unlock_return_error(); } +nsapi_error_t AT_CellularDevice::reset() +{ + _at->lock(); + if (_state_machine) { + _state_machine->reset(); + } + _at->cmd_start("AT+CFUN=1,1");// reset to full power levels + _at->cmd_stop_read_resp(); + return _at->unlock_return_error(); +} + nsapi_error_t AT_CellularDevice::is_ready() { _at->lock(); diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 42d4f82988..cc5f90ec82 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -72,6 +72,8 @@ public: virtual nsapi_error_t init(); + virtual nsapi_error_t reset(); + virtual nsapi_error_t is_ready(); virtual nsapi_error_t set_ready_cb(Callback callback); diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp index 4be451cdea..6ba70733a3 100644 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ b/features/cellular/framework/AT/AT_CellularPower.cpp @@ -41,13 +41,3 @@ nsapi_error_t AT_CellularPower::off() { return NSAPI_ERROR_UNSUPPORTED; } - -nsapi_error_t AT_CellularPower::reset() -{ - _at.lock(); - _at.cmd_start("AT+CFUN=");// reset to full power levels - _at.write_int(1); - _at.write_int(1); - _at.cmd_stop_read_resp(); - return _at.unlock_return_error(); -} diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h index cd7dc21b20..7e4f1c9372 100644 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ b/features/cellular/framework/AT/AT_CellularPower.h @@ -37,8 +37,6 @@ public: virtual nsapi_error_t on(); virtual nsapi_error_t off(); - - virtual nsapi_error_t reset(); }; } // namespace mbed diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 0c77a4b3ac..5ef59fc5ae 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -26,9 +26,6 @@ #define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format #define CONNECT_TIMEOUT 8000 -#define MAX_STARTUP_TRIALS 5 -#define MAX_RESET_TRIALS 5 - using namespace events; using namespace mbed; @@ -97,3 +94,11 @@ nsapi_error_t QUECTEL_BC95::init() return _at->unlock_return_error(); } +nsapi_error_t QUECTEL_BC95::reset() +{ + _at->lock(); + _at->cmd_start("AT+NRB"); // reset to full power levels + _at->cmd_stop(); + _at->resp_start("REBOOTING", true); + return _at->unlock_return_error(); +} diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index da3942240a..ee73b1e0c5 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -36,6 +36,7 @@ protected: // AT_CellularDevice virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual nsapi_error_t init(); + virtual nsapi_error_t reset(); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp index 73a5086e2d..778c8041ff 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp @@ -28,12 +28,3 @@ QUECTEL_BC95_CellularPower::~QUECTEL_BC95_CellularPower() { } - -nsapi_error_t QUECTEL_BC95_CellularPower::reset() -{ - _at.lock(); - _at.cmd_start("AT+NRB"); // reset to full power levels - _at.cmd_stop(); - _at.resp_start("REBOOTING", true); - return _at.unlock_return_error(); -} diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h index fedb654a23..781be8f5c7 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h @@ -26,9 +26,6 @@ class QUECTEL_BC95_CellularPower : public AT_CellularPower { public: QUECTEL_BC95_CellularPower(ATHandler &atHandler); virtual ~QUECTEL_BC95_CellularPower(); - -public: //from CellularPower - virtual nsapi_error_t reset(); }; } // namespace mbed diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index a5c9c9d8f2..dc52e3f3f2 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -29,9 +29,6 @@ using namespace events; #define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format #define CONNECT_TIMEOUT 8000 -#define MAX_STARTUP_TRIALS 5 -#define MAX_RESET_TRIALS 5 - #define DEVICE_READY_URC "CPIN:" static const AT_CellularBase::SupportedFeature unsupported_features[] = { diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 4e69e0a8ed..3571b97158 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -27,9 +27,6 @@ using namespace events; #define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format #define CONNECT_TIMEOUT 8000 -#define MAX_STARTUP_TRIALS 5 -#define MAX_RESET_TRIALS 5 - QUECTEL_UG96::QUECTEL_UG96(FileHandle *fh) : AT_CellularDevice(fh) { } From c7486b2a0d3427a59ae92b0f747dac9e16e3b962 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Thu, 29 Nov 2018 00:54:27 -0800 Subject: [PATCH 14/41] Cellular: Added shutdown() --- .../at_cellulardevice/at_cellulardevicetest.cpp | 7 +++++++ .../cellulardevice/cellulardevicetest.cpp | 12 ++++++++++++ UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 5 +++++ UNITTESTS/stubs/CellularDevice_stub.cpp | 6 ++++++ UNITTESTS/target_h/myCellularDevice.h | 5 +++++ .../cellular/TESTS/api/cellular_device/main.cpp | 11 +++++++++++ features/cellular/TESTS/cellular_tests_common.h | 4 ---- features/cellular/TESTS/socket/udp/main.cpp | 2 +- .../cellular/framework/API/CellularDevice.h | 10 +++++++++- .../cellular/framework/AT/AT_CellularDevice.cpp | 17 ++++++++++++++++- .../cellular/framework/AT/AT_CellularDevice.h | 2 ++ .../framework/device/CellularDevice.cpp | 10 ++++++++++ .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 1 + .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 9 +++++++++ 14 files changed, 94 insertions(+), 7 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 035ec9e7c3..338f975a5c 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -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; diff --git a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp index d615f592f7..94491bd0e8 100644 --- a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp @@ -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; +} diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 06b246c247..9b62965795 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -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; diff --git a/UNITTESTS/stubs/CellularDevice_stub.cpp b/UNITTESTS/stubs/CellularDevice_stub.cpp index 24141cfb99..6d8943382f 100644 --- a/UNITTESTS/stubs/CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/CellularDevice_stub.cpp @@ -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; +} + diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 4caed90c89..ffd5a8819b 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -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; diff --git a/features/cellular/TESTS/api/cellular_device/main.cpp b/features/cellular/TESTS/api/cellular_device/main.cpp index df8fb467f8..294ff10e16 100644 --- a/features/cellular/TESTS/api/cellular_device/main.cpp +++ b/features/cellular/TESTS/api/cellular_device/main.cpp @@ -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) diff --git a/features/cellular/TESTS/cellular_tests_common.h b/features/cellular/TESTS/cellular_tests_common.h index 95c740f088..0303552412 100644 --- a/features/cellular/TESTS/cellular_tests_common.h +++ b/features/cellular/TESTS/cellular_tests_common.h @@ -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); diff --git a/features/cellular/TESTS/socket/udp/main.cpp b/features/cellular/TESTS/socket/udp/main.cpp index 22073d5b59..f89afe9310 100644 --- a/features/cellular/TESTS/socket/udp/main.cpp +++ b/features/cellular/TESTS/socket/udp/main.cpp @@ -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" diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 200d7c3da2..d3b57873b4 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -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 diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 5d6ea818d0..9c504d1eda 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -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(); } diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index cc5f90ec82..64db7a4da5 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -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 callback); diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index d0b48ce8c9..305556d273 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -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 diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 5ef59fc5ae..26cf6891e2 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -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); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index dc52e3f3f2..21d7e99f32 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -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 callback) +{ + return _at->set_urc_handler(DEVICE_READY_URC, callback); +} From 8fcd2e040100c47f23608765ff13240dcd4d794b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Wed, 5 Dec 2018 12:58:30 +0200 Subject: [PATCH 15/41] Cellular: changed support features to CellularProperty array. --- .../at_cellularbase/at_cellularbasetest.cpp | 42 +++++++------------ UNITTESTS/stubs/AT_CellularBase_stub.cpp | 4 +- UNITTESTS/stubs/AT_CellularBase_stub.h | 2 +- .../cellular/framework/AT/AT_CellularBase.cpp | 28 +++++-------- .../cellular/framework/AT/AT_CellularBase.h | 35 ++++++++-------- .../framework/AT/AT_CellularContext.cpp | 4 +- .../framework/AT/AT_CellularInformation.cpp | 2 +- .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 26 +++++++----- .../MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp | 10 ++--- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 9 ++-- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 19 +++------ .../targets/TELIT/HE910/TELIT_HE910.cpp | 10 ++--- .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 9 ++-- .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 9 ++-- 14 files changed, 95 insertions(+), 114 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp index 3537aa9c8a..9390ad1843 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp @@ -33,28 +33,19 @@ public: } bool check_not_supported() { - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK + static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1 // AT_CGAUTH }; - set_unsupported_features(unsupported_features); - return is_supported(AT_CGSN_WITH_TYPE); + + set_cellular_properties(cellular_properties); + return get_property(AT_CGSN_WITH_TYPE); } bool check_supported() { - set_unsupported_features(NULL); - return is_supported(AT_CGSN_WITH_TYPE); - } - - bool check_supported_not_found() - { - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK - }; - set_unsupported_features(unsupported_features); - return is_supported(SUPPORTED_FEATURE_END_MARK); + return get_property(AT_CGDATA); } }; @@ -109,19 +100,19 @@ TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error) ATHandler_stub::device_err_value.errCode = 0; } -TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_unsupported_features) +TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_cellular_properties) { EventQueue eq; FileHandle_stub fh; ATHandler ah(&fh, eq, 0, ","); AT_CellularBase at(ah); - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK + static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1 // AT_CGAUTH }; - - at.set_unsupported_features(unsupported_features); + at.set_cellular_properties(cellular_properties); } TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported) @@ -131,7 +122,6 @@ TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported) ATHandler ah(&fh, eq, 0, ","); my_base my_at(ah); - EXPECT_TRUE(true == my_at.check_supported()); - EXPECT_TRUE(true == my_at.check_supported_not_found()); - EXPECT_TRUE(false == my_at.check_not_supported()); + EXPECT_EQ(true, my_at.check_supported()); + EXPECT_EQ(false, my_at.check_not_supported()); } diff --git a/UNITTESTS/stubs/AT_CellularBase_stub.cpp b/UNITTESTS/stubs/AT_CellularBase_stub.cpp index 1c7f25a4bf..669e608229 100644 --- a/UNITTESTS/stubs/AT_CellularBase_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularBase_stub.cpp @@ -16,10 +16,8 @@ */ #include "nsapi_types.h" -#include "AT_CellularBase.h" #include "AT_CellularBase_stub.h" - using namespace mbed; ATHandler *AT_CellularBase_stub::handler_value = NULL; @@ -43,7 +41,7 @@ device_err_t AT_CellularBase::get_device_error() const return AT_CellularBase_stub::device_err_value; } -bool AT_CellularBase::is_supported(SupportedFeature feature) +intptr_t AT_CellularBase::get_property(CellularProperty key) { return AT_CellularBase_stub::supported_bool; } diff --git a/UNITTESTS/stubs/AT_CellularBase_stub.h b/UNITTESTS/stubs/AT_CellularBase_stub.h index ec32d8eb28..bbf63882fe 100644 --- a/UNITTESTS/stubs/AT_CellularBase_stub.h +++ b/UNITTESTS/stubs/AT_CellularBase_stub.h @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "ATHandler.h" +#include "AT_CellularBase.h" namespace AT_CellularBase_stub { extern mbed::ATHandler *handler_value; diff --git a/features/cellular/framework/AT/AT_CellularBase.cpp b/features/cellular/framework/AT/AT_CellularBase.cpp index f1225fcfa6..8d9ab8e1f8 100644 --- a/features/cellular/framework/AT/AT_CellularBase.cpp +++ b/features/cellular/framework/AT/AT_CellularBase.cpp @@ -34,25 +34,19 @@ device_err_t AT_CellularBase::get_device_error() const return _at.get_last_device_error(); } -AT_CellularBase::SupportedFeature const *AT_CellularBase::_unsupported_features; +const intptr_t *AT_CellularBase::_property_array; -void AT_CellularBase::set_unsupported_features(const SupportedFeature *unsupported_features) +void AT_CellularBase::set_cellular_properties(const intptr_t *property_array) { - _unsupported_features = unsupported_features; -} - -bool AT_CellularBase::is_supported(SupportedFeature feature) -{ - if (!_unsupported_features) { - return true; + if (!property_array) { + tr_warning("trying to set an empty cellular property array"); + return; } - for (int i = 0; _unsupported_features[i] != SUPPORTED_FEATURE_END_MARK; i++) { - if (_unsupported_features[i] == feature) { - tr_debug("Unsupported feature (%d)", (int)feature); - return false; - } - } - - return true; + _property_array = property_array; +} + +intptr_t AT_CellularBase::get_property(CellularProperty key) +{ + return _property_array[key]; } diff --git a/features/cellular/framework/AT/AT_CellularBase.h b/features/cellular/framework/AT/AT_CellularBase.h index 218167c863..c7be9964b2 100644 --- a/features/cellular/framework/AT/AT_CellularBase.h +++ b/features/cellular/framework/AT/AT_CellularBase.h @@ -42,30 +42,31 @@ public: */ device_err_t get_device_error() const; - /** Cellular module need to define an array of unsupported features if any, - * by default all features are supported. - * - * @param features Array of type SupportedFeature with last element FEATURE_END_MARK - */ - enum SupportedFeature { - AT_CGSN_WITH_TYPE, // AT+CGSN without type is likely always supported similar to AT+GSN - AT_CGDATA, // alternative is to support only ATD*99***# - AT_CGAUTH, // APN authentication AT commands supported - SUPPORTED_FEATURE_END_MARK // must be last element in the array of features + enum CellularProperty { + AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. + AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# + AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported + CELLULAR_PROPERTY_MAX }; - static void set_unsupported_features(const SupportedFeature *unsupported_features); + + /** Cellular module need to define an array of cellular properties which defines module supported property values. + * + * @param property_array array of module properties + */ + static void set_cellular_properties(const intptr_t *property_array); protected: + + static const intptr_t *_property_array; + ATHandler &_at; - /** Check if some functionality is supported by a cellular module. For example, - * most of standard AT commands are optional and not implemented by all cellular modules. + /** Get value for the given key. * - * @param feature check for feature to support - * @return true on supported, otherwise false + * @param key key for value to be fetched + * @return property value for the given key. Value type is defined in enum CellularProperty */ - static const SupportedFeature *_unsupported_features; - static bool is_supported(SupportedFeature feature); + static intptr_t get_property(CellularProperty key); }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index a2a7ddd1fa..f751d6e1d9 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -289,7 +289,7 @@ nsapi_error_t AT_CellularContext::do_user_authentication() { // if user has defined user name and password we need to call CGAUTH before activating or modifying context if (_pwd && _uname) { - if (!is_supported(AT_CGAUTH)) { + if (!get_property(AT_CGAUTH)) { return NSAPI_ERROR_UNSUPPORTED; } _at.cmd_start("AT+CGAUTH="); @@ -572,7 +572,7 @@ void AT_CellularContext::do_connect() nsapi_error_t AT_CellularContext::open_data_channel() { tr_info("CellularContext PPP connect"); - if (is_supported(AT_CGDATA)) { + if (get_property(AT_CGDATA)) { _at.cmd_start("AT+CGDATA=\"PPP\","); _at.write_int(_cid); } else { diff --git a/features/cellular/framework/AT/AT_CellularInformation.cpp b/features/cellular/framework/AT/AT_CellularInformation.cpp index 585cd211e8..f536765fe0 100644 --- a/features/cellular/framework/AT/AT_CellularInformation.cpp +++ b/features/cellular/framework/AT/AT_CellularInformation.cpp @@ -54,7 +54,7 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si return get_info("AT+CGSN", buf, buf_size); } - if (!is_supported(AT_CGSN_WITH_TYPE)) { + if (!get_property(AT_CGSN_WITH_TYPE)) { return NSAPI_ERROR_UNSUPPORTED; } diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index fc4b62e015..3350c3d014 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -94,31 +94,35 @@ GEMALTO_CINTERION::Module GEMALTO_CINTERION::get_module() void GEMALTO_CINTERION::init_module_bgs2() { // BGS2-W_ATC_V00.100 - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK + static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH }; - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); _module = ModuleBGS2; } void GEMALTO_CINTERION::init_module_els61() { // ELS61-E2_ATC_V01.000 - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK + static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH }; - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); _module = ModuleELS61; } void GEMALTO_CINTERION::init_module_ems31() { // EMS31-US_ATC_V4.9.5 - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::SUPPORTED_FEATURE_END_MARK + static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 1, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH }; - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); _module = ModuleEMS31; } diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index c91941fc61..deff5ad610 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -23,15 +23,15 @@ using namespace mbed; using namespace events; -static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::AT_CGDATA, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK +static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 0, // AT_CGDATA + 1 // AT_CGAUTH }; SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh) { - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); } SARA4_PPP::~SARA4_PPP() diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 26cf6891e2..5343b23dd4 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -29,14 +29,15 @@ using namespace events; using namespace mbed; -static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGAUTH, // BC95_AT_Commands_Manual_V1.9 - AT_CellularBase::SUPPORTED_FEATURE_END_MARK +static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 1, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 0 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh) { - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); } QUECTEL_BC95::~QUECTEL_BC95() diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 21d7e99f32..89494eb1f2 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -31,15 +31,15 @@ using namespace events; #define DEVICE_READY_URC "CPIN:" -static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::AT_CGDATA, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK +static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh) { - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); } QUECTEL_BG96::~QUECTEL_BG96() @@ -61,12 +61,3 @@ 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 callback) -{ - return _at->set_urc_handler(DEVICE_READY_URC, callback); -} diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 21d6b51a61..75d20cb82c 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -23,15 +23,15 @@ using namespace mbed; using namespace events; -static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, // HE910/UE910/UL865/UE866 AT Commands Reference Guide Rev. 11-2006-10-14 - AT_CellularBase::AT_CGAUTH, // HE910/UE910/UL865/UE866 AT Commands Reference Guide Rev. 11-2006-10-14 - AT_CellularBase::SUPPORTED_FEATURE_END_MARK +static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 0 // AT_CGAUTH }; TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh) { - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); } TELIT_HE910::~TELIT_HE910() diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index 5532b45b93..1c2464375d 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -24,16 +24,17 @@ using namespace mbed; using namespace events; #ifdef TARGET_UBLOX_C030_R41XM -static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK +static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; #endif UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh) { #ifdef TARGET_UBLOX_C030_R41XM - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); #endif } diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index d71c80d63b..b98f4ebf9f 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -24,16 +24,17 @@ using namespace mbed; using namespace events; #ifdef TARGET_UBLOX_C027 -static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK +static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; #endif UBLOX_PPP::UBLOX_PPP(FileHandle *fh) : AT_CellularDevice(fh) { #ifdef TARGET_UBLOX_C027 - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); #endif } From b0d37ebec4438507043e56445378056206127276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Thu, 13 Dec 2018 13:42:44 +0200 Subject: [PATCH 16/41] Cellular: Removed unnecessary checks after new After this change we were able to change methods ATHandler::set_urc_handler and CellularDevice::set_ready_cb to void and simplify error handling. --- .../at_cellulardevicetest.cpp | 4 +- .../AT/at_cellularsms/at_cellularsmstest.cpp | 6 +- .../framework/AT/athandler/athandlertest.cpp | 2 +- UNITTESTS/stubs/ATHandler_stub.cpp | 3 +- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 3 +- UNITTESTS/target_h/myCellularDevice.h | 3 +- .../TESTS/api/cellular_power/main.cpp | 8 +-- .../cellular/framework/API/CellularDevice.h | 6 +- features/cellular/framework/AT/ATHandler.cpp | 38 ++++------ features/cellular/framework/AT/ATHandler.h | 3 +- .../framework/AT/AT_CellularDevice.cpp | 69 ++++++------------- .../cellular/framework/AT/AT_CellularDevice.h | 2 +- .../cellular/framework/AT/AT_CellularSMS.cpp | 19 +---- .../framework/AT/AT_CellularStack.cpp | 5 -- .../cellular/framework/common/CellularList.h | 3 - .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 9 +++ .../targets/QUECTEL/BG96/QUECTEL_BG96.h | 2 +- 17 files changed, 63 insertions(+), 122 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 338f975a5c..d94240b35e 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -423,6 +423,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_ready_cb) FileHandle_stub fh1; AT_CellularDevice *dev = new AT_CellularDevice(&fh1); - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(&device_ready_cb)); - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(0)); + dev->set_ready_cb(&device_ready_cb); + dev->set_ready_cb(0); } diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp index a21b7098de..fb8eeef021 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp @@ -71,14 +71,14 @@ TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_initialize) AT_CellularSMS sms(at); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText)); + EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.initialize(CellularSMS::CellularSMSMmodeText)); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText)); + EXPECT_EQ(NSAPI_ERROR_OK, sms.initialize(CellularSMS::CellularSMSMmodeText)); sms.set_sms_callback(&my_callback); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText)); + EXPECT_EQ(NSAPI_ERROR_OK, sms.initialize(CellularSMS::CellularSMSMmodeText)); ATHandler_stub::call_immediately = false; } diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp index fb06161bb7..a7ee8227bd 100644 --- a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp @@ -160,7 +160,7 @@ TEST_F(TestATHandler, test_ATHandler_set_urc_handler) at.set_urc_handler(ch, cb); //THIS IS NOT same callback in find_urc_handler??? - EXPECT_TRUE(NSAPI_ERROR_OK == at.set_urc_handler(ch, cb)); + at.set_urc_handler(ch, cb); } TEST_F(TestATHandler, test_ATHandler_remove_urc_handler) diff --git a/UNITTESTS/stubs/ATHandler_stub.cpp b/UNITTESTS/stubs/ATHandler_stub.cpp index 5ae5d4fca6..a1ee341604 100644 --- a/UNITTESTS/stubs/ATHandler_stub.cpp +++ b/UNITTESTS/stubs/ATHandler_stub.cpp @@ -121,7 +121,7 @@ void ATHandler::set_file_handle(FileHandle *fh) { } -nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback cb) +void ATHandler::set_urc_handler(const char *urc, mbed::Callback cb) { if (ATHandler_stub::urc_amount < kATHandler_urc_table_max_size) { ATHandler_stub::callback[ATHandler_stub::urc_amount] = cb; @@ -138,7 +138,6 @@ nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback if (ATHandler_stub::call_immediately) { cb(); } - return ATHandler_stub::nsapi_error_value; } void ATHandler::remove_urc_handler(const char *prefix) diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 9b62965795..77dc761dd5 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -156,9 +156,8 @@ nsapi_error_t AT_CellularDevice::is_ready() return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularDevice::set_ready_cb(mbed::Callback callback) +void AT_CellularDevice::set_ready_cb(mbed::Callback callback) { - return NSAPI_ERROR_UNSUPPORTED; } nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index ffd5a8819b..301f2a1466 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -129,9 +129,8 @@ public: return NSAPI_ERROR_OK; } - virtual nsapi_error_t set_ready_cb(Callback callback) + virtual void set_ready_cb(Callback callback) { - return NSAPI_ERROR_UNSUPPORTED; } nsapi_error_t set_power_save_mode(int periodic_time, int active_time) diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp index ac5ab953d2..5990c5200d 100644 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ b/features/cellular/TESTS/api/cellular_power/main.cpp @@ -52,11 +52,10 @@ static void urc_callback() static void wait_for_power(CellularPower *pwr) { - nsapi_error_t err = cellular_device->set_ready_cb(&urc_callback); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); + cellular_device->set_ready_cb(&urc_callback); int sanity_count = 0; - err = cellular_device->init(); + nsapi_error_t err = cellular_device->init(); while (err != NSAPI_ERROR_OK) { sanity_count++; wait(1); @@ -65,8 +64,7 @@ static void wait_for_power(CellularPower *pwr) } TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK); - - TEST_ASSERT(cellular_device->set_ready_cb(0) == NSAPI_ERROR_OK); + cellular_device->set_ready_cb(0); } static void test_power_interface() diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index d3b57873b4..35c46eb27e 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -287,12 +287,8 @@ public: /** Set callback function to listen when device is ready. * * @param callback function to call on device ready, or NULL to remove callback. - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_NO_MEMORY on memory failure - * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem */ - virtual nsapi_error_t set_ready_cb(Callback callback) = 0; + virtual void set_ready_cb(Callback callback) = 0; /** Set power save mode * diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index 93ff0a9e6e..4371f4ddaa 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -90,11 +90,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const if (output_delimiter) { _output_delimiter = new char[strlen(output_delimiter) + 1]; - if (!_output_delimiter) { - MBED_ASSERT(0); - } else { - memcpy(_output_delimiter, output_delimiter, strlen(output_delimiter) + 1); - } + memcpy(_output_delimiter, output_delimiter, strlen(output_delimiter) + 1); } else { _output_delimiter = NULL; } @@ -160,38 +156,32 @@ void ATHandler::set_is_filehandle_usable(bool usable) _is_fh_usable = usable; } -nsapi_error_t ATHandler::set_urc_handler(const char *prefix, Callback callback) +void ATHandler::set_urc_handler(const char *prefix, Callback callback) { if (!callback) { remove_urc_handler(prefix); - return NSAPI_ERROR_OK; + return; } if (find_urc_handler(prefix)) { tr_warn("URC already added with prefix: %s", prefix); - return NSAPI_ERROR_OK; + return; } struct oob_t *oob = new struct oob_t; - if (!oob) { - return NSAPI_ERROR_NO_MEMORY; - } else { - size_t prefix_len = strlen(prefix); - if (prefix_len > _oob_string_max_length) { - _oob_string_max_length = prefix_len; - if (_oob_string_max_length > _max_resp_length) { - _max_resp_length = _oob_string_max_length; - } + size_t prefix_len = strlen(prefix); + if (prefix_len > _oob_string_max_length) { + _oob_string_max_length = prefix_len; + if (_oob_string_max_length > _max_resp_length) { + _max_resp_length = _oob_string_max_length; } - - oob->prefix = prefix; - oob->prefix_len = prefix_len; - oob->cb = callback; - oob->next = _oobs; - _oobs = oob; } - return NSAPI_ERROR_OK; + oob->prefix = prefix; + oob->prefix_len = prefix_len; + oob->cb = callback; + oob->next = _oobs; + _oobs = oob; } void ATHandler::remove_urc_handler(const char *prefix) diff --git a/features/cellular/framework/AT/ATHandler.h b/features/cellular/framework/AT/ATHandler.h index dd76b98ba8..0be1809567 100644 --- a/features/cellular/framework/AT/ATHandler.h +++ b/features/cellular/framework/AT/ATHandler.h @@ -124,9 +124,8 @@ public: * * @param prefix URC text to look for, e.g. "+CMTI:" * @param callback function to call on prefix, or 0 to remove callback - * @return NSAPI_ERROR_OK or NSAPI_ERROR_NO_MEMORY if no memory */ - nsapi_error_t set_urc_handler(const char *prefix, Callback callback); + void set_urc_handler(const char *prefix, Callback callback); ATHandler *_nextATHandler; // linked list diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 9c504d1eda..b60673ae17 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -169,26 +169,22 @@ CellularContext *AT_CellularDevice::get_context_list() const CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - AT_CellularContext *ctx = create_context_impl(*atHandler, apn); - AT_CellularContext *curr = _context_list; + AT_CellularContext *ctx = create_context_impl(*get_at_handler(fh), apn); + AT_CellularContext *curr = _context_list; - if (_context_list == NULL) { - _context_list = ctx; - return ctx; - } - - AT_CellularContext *prev; - while (curr) { - prev = curr; - curr = (AT_CellularContext *)curr->_next; - } - - prev->_next = ctx; + if (_context_list == NULL) { + _context_list = ctx; return ctx; } - return NULL; + + AT_CellularContext *prev; + while (curr) { + prev = curr; + curr = (AT_CellularContext *)curr->_next; + } + + prev->_next = ctx; + return ctx; } AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn) @@ -223,56 +219,36 @@ void AT_CellularDevice::delete_context(CellularContext *context) CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) { if (!_network) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _network = open_network_impl(*atHandler); - } - } - if (_network) { - _network_ref_count++; + _network = open_network_impl(*get_at_handler(fh)); } + _network_ref_count++; return _network; } CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) { if (!_sms) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _sms = open_sms_impl(*atHandler); - } - } - if (_sms) { - _sms_ref_count++; + _sms = open_sms_impl(*get_at_handler(fh)); } + _sms_ref_count++; return _sms; } CellularPower *AT_CellularDevice::open_power(FileHandle *fh) { if (!_power) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _power = open_power_impl(*atHandler); - } - } - if (_power) { - _power_ref_count++; + _power = open_power_impl(*get_at_handler(fh)); } + _power_ref_count++; return _power; } CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) { if (!_information) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _information = open_information_impl(*atHandler); - } - } - if (_information) { - _info_ref_count++; + _information = open_information_impl(*get_at_handler(fh)); } + _info_ref_count++; return _information; } @@ -419,9 +395,8 @@ nsapi_error_t AT_CellularDevice::is_ready() return _at->unlock_return_error(); } -nsapi_error_t AT_CellularDevice::set_ready_cb(Callback callback) +void AT_CellularDevice::set_ready_cb(Callback callback) { - return NSAPI_ERROR_UNSUPPORTED; } nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 64db7a4da5..1412676461 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -78,7 +78,7 @@ public: virtual nsapi_error_t is_ready(); - virtual nsapi_error_t set_ready_cb(Callback callback); + virtual void set_ready_cb(Callback callback); virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index 3dc7125e7e..fe5ff6d7e5 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -248,10 +248,8 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header) nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode) { - if (NSAPI_ERROR_OK != _at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)) || - NSAPI_ERROR_OK != _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc))) { - return NSAPI_ERROR_NO_MEMORY; - } + _at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)); + _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc)); _at.lock(); set_cnmi(); //set new SMS indication @@ -1047,11 +1045,6 @@ nsapi_error_t AT_CellularSMS::list_messages() _at.resp_start("+CMGL:"); while (_at.info_resp()) { info = new sms_info_t(); - if (!info) { - _at.resp_stop(); - return NSAPI_ERROR_NO_MEMORY; - } - if (_mode == CellularSMSMmodePDU) { //+CMGL: ,,[],[ // +CMGL:,,[], @@ -1062,11 +1055,6 @@ nsapi_error_t AT_CellularSMS::list_messages() length = length * 2 + 20; // *2 as it's hex encoded and +20 as service center number is not included in size given by CMGL pdu = new char[length]; memset(pdu, 0, length); - if (!pdu) { - delete info; - _at.resp_stop(); - return NSAPI_ERROR_NO_MEMORY; - } _at.read_string(pdu, length, true); if (_at.get_last_error() == NSAPI_ERROR_OK) { info->msg_size = get_data_from_pdu(pdu, info, &part_number); @@ -1194,9 +1182,6 @@ uint16_t AT_CellularSMS::pack_7_bit_gsm_and_hex(const char *str, uint16_t len, c } // convert to 7bit gsm first char *gsm_str = new char[len]; - if (!gsm_str) { - return 0; - } for (uint16_t y = 0; y < len; y++) { for (int x = 0; x < GSM_TO_ASCII_TABLE_SIZE; x++) { if (gsm_to_ascii[x] == str[y]) { diff --git a/features/cellular/framework/AT/AT_CellularStack.cpp b/features/cellular/framework/AT/AT_CellularStack.cpp index a43e2ebd89..333a88cb84 100644 --- a/features/cellular/framework/AT/AT_CellularStack.cpp +++ b/features/cellular/framework/AT/AT_CellularStack.cpp @@ -116,11 +116,6 @@ nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protoc } _socket = new CellularSocket*[max_socket_count]; - if (!_socket) { - tr_error("No memory to open socket!"); - _socket_mutex.unlock(); - return NSAPI_ERROR_NO_SOCKET; - } _socket_count = max_socket_count; for (int i = 0; i < max_socket_count; i++) { _socket[i] = 0; diff --git a/features/cellular/framework/common/CellularList.h b/features/cellular/framework/common/CellularList.h index d8ee8660fc..37f4177447 100644 --- a/features/cellular/framework/common/CellularList.h +++ b/features/cellular/framework/common/CellularList.h @@ -50,9 +50,6 @@ public: T *add_new() { T *temp = new T; - if (!temp) { - return NULL; - } temp->next = NULL; if (_head == NULL) { _head = temp; diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 89494eb1f2..35007ba96a 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -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); +} + +void QUECTEL_BG96::set_ready_cb(Callback callback) +{ + _at->set_urc_handler(DEVICE_READY_URC, callback); +} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 956803edf4..8bab3b34a2 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -32,7 +32,7 @@ protected: // AT_CellularDevice virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual AT_CellularInformation *open_information_impl(ATHandler &at); - virtual nsapi_error_t set_ready_cb(Callback callback); + virtual void set_ready_cb(Callback callback); public: void handle_urc(FileHandle *fh); From 9a72c221d830bba7309a8d1c64b7e694e244f781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Tue, 11 Dec 2018 16:22:45 +0200 Subject: [PATCH 17/41] Cellular: Change AT_CellularNetwork to use CellularProperties. This change enables removing function has_registration from class AT_CellularNetwork and all targets inheriting AT_CellularNetwork. --- .../at_cellularbase/at_cellularbasetest.cpp | 18 ++- .../at_cellularnetworktest.cpp | 108 ++++++++---------- UNITTESTS/stubs/AT_CellularBase_stub.cpp | 8 +- UNITTESTS/stubs/AT_CellularNetwork_stub.cpp | 5 - .../cellular/framework/AT/AT_CellularBase.h | 11 +- .../framework/AT/AT_CellularContext.cpp | 4 +- .../framework/AT/AT_CellularInformation.cpp | 2 +- .../framework/AT/AT_CellularNetwork.cpp | 14 +-- .../framework/AT/AT_CellularNetwork.h | 18 +-- .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 15 ++- .../GEMALTO_CINTERION_CellularNetwork.cpp | 15 --- .../GEMALTO_CINTERION_CellularNetwork.h | 1 - .../MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp | 7 +- .../PPP/SARA4_PPP_CellularNetwork.cpp | 5 - .../PPP/SARA4_PPP_CellularNetwork.h | 2 - .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 7 +- .../BC95/QUECTEL_BC95_CellularNetwork.cpp | 5 - .../BC95/QUECTEL_BC95_CellularNetwork.h | 1 - .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 7 +- .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 10 ++ .../UG96/QUECTEL_UG96_CellularNetwork.cpp | 5 - .../UG96/QUECTEL_UG96_CellularNetwork.h | 1 - .../targets/TELIT/HE910/TELIT_HE910.cpp | 7 +- .../HE910/TELIT_HE910_CellularNetwork.cpp | 5 - .../TELIT/HE910/TELIT_HE910_CellularNetwork.h | 1 - .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 11 +- .../UBLOX/AT/UBLOX_AT_CellularNetwork.cpp | 5 - .../UBLOX/AT/UBLOX_AT_CellularNetwork.h | 1 - .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 7 +- .../UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp | 5 - .../UBLOX/PPP/UBLOX_PPP_CellularNetwork.h | 1 - 31 files changed, 140 insertions(+), 172 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp index 9390ad1843..e522b6feef 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp @@ -18,7 +18,7 @@ #include "gtest/gtest.h" #include "AT_CellularBase.h" #include "EventQueue.h" -#include "AT_CellularBase.h" +#include "AT_CellularNetwork.h" #include "ATHandler_stub.h" #include "FileHandle_stub.h" #include @@ -33,19 +33,22 @@ public: } bool check_not_supported() { - static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 1 // AT_CGAUTH + 1, // AT_CGAUTH }; set_cellular_properties(cellular_properties); - return get_property(AT_CGSN_WITH_TYPE); + return get_property(PROPERTY_AT_CGSN_WITH_TYPE); } bool check_supported() { - return get_property(AT_CGDATA); + return get_property(PROPERTY_AT_CGDATA); } }; @@ -107,7 +110,10 @@ TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_cellular_properties) ATHandler ah(&fh, eq, 0, ","); AT_CellularBase at(ah); - static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1 // AT_CGAUTH diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp index 70d0d5435b..d6efe72b40 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -52,13 +52,6 @@ class my_AT_CN : public AT_CellularNetwork { public: my_AT_CN(ATHandler &atHandler) : AT_CellularNetwork(atHandler) {} virtual ~my_AT_CN() {} - virtual AT_CellularNetwork::RegistrationMode has_registration(RegistrationType reg_type) - { - if (reg_type == C_GREG) { - return RegistrationModeDisable; - } - return RegistrationModeEnable; - } virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat) { return NSAPI_ERROR_OK; @@ -69,13 +62,6 @@ class my_AT_CNipv6 : public AT_CellularNetwork { public: my_AT_CNipv6(ATHandler &atHandler) : AT_CellularNetwork(atHandler) {} virtual ~my_AT_CNipv6() {} - virtual AT_CellularNetwork::RegistrationMode has_registration(RegistrationType reg_type) - { - if (reg_type == C_GREG) { - return RegistrationModeDisable; - } - return RegistrationModeEnable; - } virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat) { return NSAPI_ERROR_OK; @@ -150,32 +136,32 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_registration_params) ATHandler_stub::read_string_value = NULL; ATHandler_stub::ssize_value = 0; // Check get_registration_params without specifying the registration type - EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_registration_params(reg_params_check)); - EXPECT_TRUE(reg_params_check._status == CellularNetwork::RegistrationDenied); - EXPECT_TRUE(reg_params_check._act == CellularNetwork::RAT_EGPRS); - EXPECT_TRUE(reg_params_check._cell_id == 305463233); - EXPECT_TRUE(reg_params_check._active_time == 240); - EXPECT_TRUE(reg_params_check._periodic_tau == 70 * 60 * 60); + ASSERT_EQ(NSAPI_ERROR_OK, cn.get_registration_params(reg_params_check)); + ASSERT_EQ(reg_params_check._status, CellularNetwork::RegistrationDenied); + ASSERT_EQ(reg_params_check._act, CellularNetwork::RAT_EGPRS); + ASSERT_EQ(reg_params_check._cell_id, 305463233); + ASSERT_EQ(reg_params_check._active_time, 240); + ASSERT_EQ(reg_params_check._periodic_tau, 70 * 60 * 60); reg_params._status = CellularNetwork::NotRegistered; reg_params._act = CellularNetwork::RAT_GSM; reg_params._cell_id = 1; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_registration_params(CellularNetwork::C_GREG, reg_params)); - EXPECT_TRUE(reg_params._status == CellularNetwork::RegistrationDenied); - EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_EGPRS); - EXPECT_TRUE(reg_params._cell_id == -1); + ASSERT_EQ(NSAPI_ERROR_OK, cn.get_registration_params(CellularNetwork::C_REG, reg_params)); + ASSERT_EQ(reg_params._status, CellularNetwork::RegistrationDenied); + ASSERT_EQ(reg_params._act, CellularNetwork::RAT_EGPRS); + ASSERT_EQ(reg_params._cell_id, -1); my_AT_CN nw(at); reg_params._status = CellularNetwork::NotRegistered; reg_params._act = CellularNetwork::RAT_GSM; - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.get_registration_params(CellularNetwork::C_GREG, reg_params)); - EXPECT_TRUE(reg_params._status == CellularNetwork::NotRegistered); - EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_GSM); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, nw.get_registration_params(CellularNetwork::C_GREG, reg_params)); + ASSERT_EQ(reg_params._status, CellularNetwork::NotRegistered); + ASSERT_EQ(reg_params._act, CellularNetwork::RAT_GSM); - EXPECT_TRUE(NSAPI_ERROR_OK == nw.get_registration_params(CellularNetwork::C_EREG, reg_params)); - EXPECT_TRUE(reg_params._status == CellularNetwork::RegistrationDenied); - EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_EGPRS); + ASSERT_EQ(NSAPI_ERROR_OK, nw.get_registration_params(CellularNetwork::C_EREG, reg_params)); + ASSERT_EQ(reg_params._status, CellularNetwork::RegistrationDenied); + ASSERT_EQ(reg_params._act, CellularNetwork::RAT_EGPRS); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; reg_params._status = CellularNetwork::NotRegistered; @@ -184,15 +170,15 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_registration_params) reg_params._active_time = 2; reg_params._periodic_tau = 3; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_params(CellularNetwork::C_EREG, reg_params)); - EXPECT_TRUE(reg_params._status == CellularNetwork::NotRegistered); - EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_UNKNOWN); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, cn.get_registration_params(CellularNetwork::C_EREG, reg_params)); + ASSERT_EQ(reg_params._status, CellularNetwork::NotRegistered); + ASSERT_EQ(reg_params._act, CellularNetwork::RAT_UNKNOWN); EXPECT_TRUE(reg_params._cell_id == -1 && reg_params._active_time == -1 && reg_params._periodic_tau == -1); - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_params(CellularNetwork::C_GREG, reg_params)); - EXPECT_TRUE(reg_params._status == CellularNetwork::NotRegistered); - EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_UNKNOWN); - EXPECT_TRUE(reg_params._cell_id == -1); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, cn.get_registration_params(CellularNetwork::C_REG, reg_params)); + ASSERT_EQ(reg_params._status, CellularNetwork::NotRegistered); + ASSERT_EQ(reg_params._act, CellularNetwork::RAT_UNKNOWN); + ASSERT_EQ(reg_params._cell_id, -1); reg_params._status = CellularNetwork::SearchingNetwork; reg_params._act = CellularNetwork::RAT_GSM; @@ -304,63 +290,63 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_registration_urc) AT_CellularNetwork cn(at); CellularNetwork::RegistrationType type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_OK, cn.set_registration_urc(type, true)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, cn.set_registration_urc(type, true)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_OK, cn.set_registration_urc(type, true)); my_AT_CN nw(at); type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_OK, nw.set_registration_urc(type, true)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, nw.set_registration_urc(type, true)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_OK, nw.set_registration_urc(type, true)); type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_OK, cn.set_registration_urc(type, false)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, cn.set_registration_urc(type, false)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_OK, cn.set_registration_urc(type, false)); type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_OK, nw.set_registration_urc(type, false)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, nw.set_registration_urc(type, false)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_OK, nw.set_registration_urc(type, false)); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, cn.set_registration_urc(type, true)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, cn.set_registration_urc(type, true)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, cn.set_registration_urc(type, true)); type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, nw.set_registration_urc(type, true)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, nw.set_registration_urc(type, true)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, true)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, nw.set_registration_urc(type, true)); type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, cn.set_registration_urc(type, false)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, cn.set_registration_urc(type, false)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, cn.set_registration_urc(type, false)); type = CellularNetwork::C_EREG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, nw.set_registration_urc(type, false)); type = CellularNetwork::C_GREG; - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_UNSUPPORTED, nw.set_registration_urc(type, false)); type = CellularNetwork::C_REG; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, false)); + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, nw.set_registration_urc(type, false)); } TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_attach) diff --git a/UNITTESTS/stubs/AT_CellularBase_stub.cpp b/UNITTESTS/stubs/AT_CellularBase_stub.cpp index 669e608229..ef8c844eaf 100644 --- a/UNITTESTS/stubs/AT_CellularBase_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularBase_stub.cpp @@ -17,7 +17,7 @@ #include "nsapi_types.h" #include "AT_CellularBase_stub.h" - +#include "AT_CellularNetwork.h" using namespace mbed; ATHandler *AT_CellularBase_stub::handler_value = NULL; @@ -43,5 +43,11 @@ device_err_t AT_CellularBase::get_device_error() const intptr_t AT_CellularBase::get_property(CellularProperty key) { + if (key == PROPERTY_C_GREG) { + return AT_CellularNetwork::RegistrationModeDisable; + } else if (key == PROPERTY_C_REG || key == PROPERTY_C_EREG) { + return AT_CellularNetwork::RegistrationModeEnable; + } + return AT_CellularBase_stub::supported_bool; } diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp index 066710215e..2666abde1c 100644 --- a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -68,11 +68,6 @@ nsapi_error_t AT_CellularNetwork::get_registration_params(registration_params_t return NSAPI_ERROR_OK; } -AT_CellularNetwork::RegistrationMode AT_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return RegistrationModeDisable; -} - nsapi_error_t AT_CellularNetwork::set_attach() { return NSAPI_ERROR_OK; diff --git a/features/cellular/framework/AT/AT_CellularBase.h b/features/cellular/framework/AT/AT_CellularBase.h index c7be9964b2..a7c48b7477 100644 --- a/features/cellular/framework/AT/AT_CellularBase.h +++ b/features/cellular/framework/AT/AT_CellularBase.h @@ -43,10 +43,13 @@ public: device_err_t get_device_error() const; enum CellularProperty { - AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. - AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# - AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported - CELLULAR_PROPERTY_MAX + PROPERTY_C_EREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. + PROPERTY_C_GREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. + PROPERTY_C_REG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. + PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. + PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# + PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported + PROPERTY_MAX }; /** Cellular module need to define an array of cellular properties which defines module supported property values. diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index f751d6e1d9..6f16f05ba9 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -289,7 +289,7 @@ nsapi_error_t AT_CellularContext::do_user_authentication() { // if user has defined user name and password we need to call CGAUTH before activating or modifying context if (_pwd && _uname) { - if (!get_property(AT_CGAUTH)) { + if (!get_property(PROPERTY_AT_CGAUTH)) { return NSAPI_ERROR_UNSUPPORTED; } _at.cmd_start("AT+CGAUTH="); @@ -572,7 +572,7 @@ void AT_CellularContext::do_connect() nsapi_error_t AT_CellularContext::open_data_channel() { tr_info("CellularContext PPP connect"); - if (get_property(AT_CGDATA)) { + if (get_property(PROPERTY_AT_CGDATA)) { _at.cmd_start("AT+CGDATA=\"PPP\","); _at.write_int(_cid); } else { diff --git a/features/cellular/framework/AT/AT_CellularInformation.cpp b/features/cellular/framework/AT/AT_CellularInformation.cpp index f536765fe0..5bb965090c 100644 --- a/features/cellular/framework/AT/AT_CellularInformation.cpp +++ b/features/cellular/framework/AT/AT_CellularInformation.cpp @@ -54,7 +54,7 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si return get_info("AT+CGSN", buf, buf_size); } - if (!get_property(AT_CGSN_WITH_TYPE)) { + if (!get_property(PROPERTY_AT_CGSN_WITH_TYPE)) { return NSAPI_ERROR_UNSUPPORTED; } diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index 5a66c77d80..b3f5dab01c 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -80,7 +80,7 @@ AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(a _urc_funcs[C_REG] = callback(this, &AT_CellularNetwork::urc_creg); for (int type = 0; type < CellularNetwork::C_MAX; type++) { - if (has_registration((RegistrationType)type) != RegistrationModeDisable) { + if (get_property((AT_CellularBase::CellularProperty)type) != RegistrationModeDisable) { _at.set_urc_handler(at_reg[type].urc_prefix, _urc_funcs[type]); } } @@ -103,7 +103,7 @@ AT_CellularNetwork::~AT_CellularNetwork() _at.unlock(); for (int type = 0; type < CellularNetwork::C_MAX; type++) { - if (has_registration((RegistrationType)type) != RegistrationModeDisable) { + if (get_property((AT_CellularBase::CellularProperty)type) != RegistrationModeDisable) { _at.set_urc_handler(at_reg[type].urc_prefix, 0); } } @@ -223,7 +223,7 @@ nsapi_error_t AT_CellularNetwork::set_registration_urc(RegistrationType type, bo int index = (int)type; MBED_ASSERT(index >= 0 && index < C_MAX); - RegistrationMode mode = has_registration(type); + RegistrationMode mode = (RegistrationMode)get_property((AT_CellularBase::CellularProperty)type); if (mode == RegistrationModeDisable) { return NSAPI_ERROR_UNSUPPORTED; } else { @@ -322,12 +322,6 @@ void AT_CellularNetwork::read_reg_params(RegistrationType type, registration_par #endif } -AT_CellularNetwork::RegistrationMode AT_CellularNetwork::has_registration(RegistrationType reg_type) -{ - (void)reg_type; - return RegistrationModeLAC; -} - nsapi_error_t AT_CellularNetwork::set_attach() { _at.lock(); @@ -612,7 +606,7 @@ nsapi_error_t AT_CellularNetwork::get_registration_params(RegistrationType type, int i = (int)type; MBED_ASSERT(i >= 0 && i < C_MAX); - if (!has_registration(at_reg[i].type)) { + if (!get_property((AT_CellularBase::CellularProperty)at_reg[i].type)) { return NSAPI_ERROR_UNSUPPORTED; } diff --git a/features/cellular/framework/AT/AT_CellularNetwork.h b/features/cellular/framework/AT/AT_CellularNetwork.h index d889ac9aa5..044bc50c0d 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.h +++ b/features/cellular/framework/AT/AT_CellularNetwork.h @@ -43,6 +43,12 @@ public: // declare friend so it can access stack friend class AT_CellularDevice; + enum RegistrationMode { + RegistrationModeDisable = 0, + RegistrationModeEnable, // + RegistrationModeLAC, // [,<[lac>,]<[ci>],[],[]] + }; + public: // CellularNetwork virtual nsapi_error_t set_registration(const char *plmn = 0); @@ -92,18 +98,6 @@ public: // CellularNetwork protected: - /** Check if modem supports given registration type. - * - * @param reg_type enum RegistrationType - * @return mode supported on given reg_type as per 3GPP TS 27.007, 0 when unsupported - */ - enum RegistrationMode { - RegistrationModeDisable = 0, - RegistrationModeEnable, // - RegistrationModeLAC, // [,<[lac>,]<[ci>],[],[]] - }; - virtual RegistrationMode has_registration(RegistrationType reg_type); - /** Sets access technology to be scanned. Modem specific implementation. * * @param op_rat Access technology diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 3350c3d014..851ed008db 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -94,7 +94,10 @@ GEMALTO_CINTERION::Module GEMALTO_CINTERION::get_module() void GEMALTO_CINTERION::init_module_bgs2() { // BGS2-W_ATC_V00.100 - static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeLAC, // C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH @@ -106,7 +109,10 @@ void GEMALTO_CINTERION::init_module_bgs2() void GEMALTO_CINTERION::init_module_els61() { // ELS61-E2_ATC_V01.000 - static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable, // C_EREG + AT_CellularNetwork::RegistrationModeEnable, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH @@ -118,7 +124,10 @@ void GEMALTO_CINTERION::init_module_els61() void GEMALTO_CINTERION::init_module_ems31() { // EMS31-US_ATC_V4.9.5 - static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { + static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeLAC, // C_EREG + AT_CellularNetwork::RegistrationModeDisable, // C_GREG + AT_CellularNetwork::RegistrationModeDisable, // C_REG 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp index baf4b47be7..b8882e8306 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp @@ -16,7 +16,6 @@ */ #include "GEMALTO_CINTERION_CellularNetwork.h" -#include "GEMALTO_CINTERION.h" using namespace mbed; @@ -28,20 +27,6 @@ GEMALTO_CINTERION_CellularNetwork::~GEMALTO_CINTERION_CellularNetwork() { } -AT_CellularNetwork::RegistrationMode GEMALTO_CINTERION_CellularNetwork::has_registration(RegistrationType reg_type) -{ - if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleEMS31) { - return (reg_type == C_EREG) ? RegistrationModeLAC : RegistrationModeDisable; - } - if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) { - if (reg_type == C_GREG) { - return RegistrationModeEnable; - } - return (reg_type == C_REG) ? RegistrationModeLAC : RegistrationModeDisable; - } - return (reg_type == C_REG || reg_type == C_GREG || reg_type == C_EREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - nsapi_error_t GEMALTO_CINTERION_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opsAct) { _op_act = RAT_UNKNOWN; diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h index e01c7e8187..98ec349906 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h @@ -28,7 +28,6 @@ public: virtual ~GEMALTO_CINTERION_CellularNetwork(); protected: - virtual RegistrationMode has_registration(RegistrationType reg_type); virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opsAct); }; diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index deff5ad610..989398ab89 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -23,10 +23,13 @@ using namespace mbed; using namespace events; -static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 0, // AT_CGDATA - 1 // AT_CGAUTH + 1, // AT_CGAUTH }; SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh) diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.cpp index 5e2c891cb8..a505d6f09c 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.cpp @@ -27,11 +27,6 @@ SARA4_PPP_CellularNetwork::~SARA4_PPP_CellularNetwork() { } -AT_CellularNetwork::RegistrationMode SARA4_PPP_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return (reg_type == C_REG || reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - nsapi_error_t SARA4_PPP_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) { _op_act = RAT_CATM1; diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.h b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.h index 123b15d387..2799bb58e6 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.h +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularNetwork.h @@ -28,8 +28,6 @@ public: virtual ~SARA4_PPP_CellularNetwork(); protected: - virtual RegistrationMode has_registration(RegistrationType rat); - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); }; diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 5343b23dd4..cbcb92c441 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -29,10 +29,13 @@ using namespace events; using namespace mbed; -static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeLAC, // C_EREG + AT_CellularNetwork::RegistrationModeDisable, // C_GREG + AT_CellularNetwork::RegistrationModeDisable, // C_REG 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 0 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 0, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh) diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.cpp index cfceacc291..440c7b519e 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.cpp @@ -28,11 +28,6 @@ QUECTEL_BC95_CellularNetwork::~QUECTEL_BC95_CellularNetwork() { } -AT_CellularNetwork::RegistrationMode QUECTEL_BC95_CellularNetwork::has_registration(RegistrationType reg_tech) -{ - return (reg_tech == C_EREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - nsapi_error_t QUECTEL_BC95_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) { if (opRat != RAT_NB1) { diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.h index 30ab188d64..7058e2af5b 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularNetwork.h @@ -29,7 +29,6 @@ public: protected: virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); - virtual RegistrationMode has_registration(RegistrationType reg_type); }; } // namespace mbed #endif // QUECTEL_BC95_CELLULAR_NETWORK_H_ diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 35007ba96a..ac65e3587d 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -31,10 +31,13 @@ using namespace events; #define DEVICE_READY_URC "CPIN:" -static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeLAC, // C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 1, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh) diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 3571b97158..052fbc2153 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -27,8 +27,18 @@ using namespace events; #define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format #define CONNECT_TIMEOUT 8000 +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG + 1, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH +}; + QUECTEL_UG96::QUECTEL_UG96(FileHandle *fh) : AT_CellularDevice(fh) { + AT_CellularBase::set_cellular_properties(cellular_properties); } QUECTEL_UG96::~QUECTEL_UG96() diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp index 08e7e2fc6d..994dc9d4a5 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp @@ -27,11 +27,6 @@ QUECTEL_UG96_CellularNetwork::~QUECTEL_UG96_CellularNetwork() { } -AT_CellularNetwork::RegistrationMode QUECTEL_UG96_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return (reg_type == C_REG || reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - nsapi_error_t QUECTEL_UG96_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) { _op_act = RAT_UNKNOWN; diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h index e9708f3f49..202529b187 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h @@ -28,7 +28,6 @@ public: virtual ~QUECTEL_UG96_CellularNetwork(); protected: - virtual RegistrationMode has_registration(RegistrationType rat); virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); }; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 75d20cb82c..49a7114af6 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -23,10 +23,13 @@ using namespace mbed; using namespace events; -static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 0 // AT_CGAUTH + 0, // AT_CGAUTH }; TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh) diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp index 5957d26b59..00cf8c0568 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp @@ -27,11 +27,6 @@ TELIT_HE910_CellularNetwork::~TELIT_HE910_CellularNetwork() { } -AT_CellularNetwork::RegistrationMode TELIT_HE910_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return (reg_type == C_REG || reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - nsapi_error_t TELIT_HE910_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) { _op_act = RAT_UNKNOWN; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h index 6cdbba7cd3..034449f851 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h @@ -28,7 +28,6 @@ public: virtual ~TELIT_HE910_CellularNetwork(); protected: - virtual RegistrationMode has_registration(RegistrationType rat); virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); }; diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index 1c2464375d..eb688f0902 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -24,10 +24,13 @@ using namespace mbed; using namespace events; #ifdef TARGET_UBLOX_C030_R41XM -static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { - 0, // AT_CGSN_WITH_TYPE - 1, // AT_CGDATA - 1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; #endif diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp index 1491deee60..89c6dae970 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp @@ -31,11 +31,6 @@ UBLOX_AT_CellularNetwork::~UBLOX_AT_CellularNetwork() } } -AT_CellularNetwork::RegistrationMode UBLOX_AT_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return (reg_type == C_REG || reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) { switch (opRat) { diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.h index ac9ba299f6..b1f49d376c 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.h @@ -29,7 +29,6 @@ public: protected: virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); - virtual RegistrationMode has_registration(RegistrationType rat); }; } // namespace mbed diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index b98f4ebf9f..ab34514e25 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -24,10 +24,13 @@ using namespace mbed; using namespace events; #ifdef TARGET_UBLOX_C027 -static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = { +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 1, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 }; #endif diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp index 9ada418ae3..5119901570 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp @@ -27,11 +27,6 @@ UBLOX_PPP_CellularNetwork::~UBLOX_PPP_CellularNetwork() { } -AT_CellularNetwork::RegistrationMode UBLOX_PPP_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return (reg_type == C_REG || reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - nsapi_error_t UBLOX_PPP_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) { _op_act = RAT_UNKNOWN; diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h index 89ea42efad..c6b5c8e3c8 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h @@ -28,7 +28,6 @@ public: virtual ~UBLOX_PPP_CellularNetwork(); protected: - virtual RegistrationMode has_registration(RegistrationType rat); virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); }; From 7c9f9d47ecf2bd6a4f2db11a5150816b0e2078aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Wed, 12 Dec 2018 15:24:26 +0200 Subject: [PATCH 18/41] Cellular: Remove target files inheriting from AT_CellularNetwork After AT_CellularNetwork::has_registration was replaced with CellularProperties and better AT_CellularNetwork::set_access_technology_impl default implementation we can delete most of the target specific classes that inherit AT_CellularNetwork. --- .../at_cellularnetworktest.cpp | 4 +-- .../framework/AT/AT_CellularNetwork.cpp | 1 + .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 8 +---- .../GEMALTO/CINTERION/GEMALTO_CINTERION.h | 1 - .../GEMALTO_CINTERION_CellularNetwork.cpp | 34 ------------------ .../GEMALTO_CINTERION_CellularNetwork.h | 36 ------------------- .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 7 +--- .../targets/QUECTEL/UG96/QUECTEL_UG96.h | 2 -- .../UG96/QUECTEL_UG96_CellularNetwork.cpp | 34 ------------------ .../UG96/QUECTEL_UG96_CellularNetwork.h | 36 ------------------- .../targets/TELIT/HE910/TELIT_HE910.cpp | 7 +--- .../targets/TELIT/HE910/TELIT_HE910.h | 1 - .../HE910/TELIT_HE910_CellularNetwork.cpp | 34 ------------------ .../TELIT/HE910/TELIT_HE910_CellularNetwork.h | 36 ------------------- .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 7 +--- .../framework/targets/UBLOX/PPP/UBLOX_PPP.h | 1 - .../UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp | 34 ------------------ .../UBLOX/PPP/UBLOX_PPP_CellularNetwork.h | 36 ------------------- 18 files changed, 7 insertions(+), 312 deletions(-) delete mode 100644 features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp delete mode 100644 features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h delete mode 100644 features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp delete mode 100644 features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h delete mode 100644 features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp delete mode 100644 features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h delete mode 100644 features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp delete mode 100644 features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp index d6efe72b40..d79bf9e5e9 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -472,8 +472,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_scan_plmn) ATHandler_stub::bool_value = false; EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::RAT_UTRAN)); EXPECT_TRUE(NSAPI_ERROR_OK == cn.scan_plmn(ops, c)); - EXPECT_TRUE(c == 0); - EXPECT_TRUE(ops.get_head() == NULL); + EXPECT_TRUE(c == 1); + EXPECT_TRUE(ops.get_head() != NULL); } TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_ciot_optimization_config) diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index b3f5dab01c..75e6ff7370 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -375,6 +375,7 @@ nsapi_error_t AT_CellularNetwork::detach() nsapi_error_t AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opsAct) { + _op_act = RAT_UNKNOWN; return NSAPI_ERROR_UNSUPPORTED; } diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 851ed008db..13cbe021d4 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -15,13 +15,12 @@ * limitations under the License. */ -#include "GEMALTO_CINTERION_CellularNetwork.h" #include "GEMALTO_CINTERION_CellularContext.h" #include "GEMALTO_CINTERION.h" +#include "AT_CellularNetwork.h" #include "AT_CellularInformation.h" #include "CellularLog.h" - using namespace mbed; using namespace events; @@ -37,11 +36,6 @@ GEMALTO_CINTERION::~GEMALTO_CINTERION() { } -AT_CellularNetwork *GEMALTO_CINTERION::open_network_impl(ATHandler &at) -{ - return new GEMALTO_CINTERION_CellularNetwork(at); -} - AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn) { return new GEMALTO_CINTERION_CellularContext(at, this, apn); diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h index 4d79202c2e..1818245f38 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h @@ -40,7 +40,6 @@ public: static Module get_module(); protected: // AT_CellularDevice - virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); protected: virtual uint16_t get_send_delay() const; diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp deleted file mode 100644 index b8882e8306..0000000000 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "GEMALTO_CINTERION_CellularNetwork.h" - -using namespace mbed; - -GEMALTO_CINTERION_CellularNetwork::GEMALTO_CINTERION_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler) -{ -} - -GEMALTO_CINTERION_CellularNetwork::~GEMALTO_CINTERION_CellularNetwork() -{ -} - -nsapi_error_t GEMALTO_CINTERION_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opsAct) -{ - _op_act = RAT_UNKNOWN; - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h deleted file mode 100644 index 98ec349906..0000000000 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GEMALTO_CINTERION_CELLULAR_NETWORK_H_ -#define GEMALTO_CINTERION_CELLULAR_NETWORK_H_ - -#include "AT_CellularNetwork.h" - -namespace mbed { - -class GEMALTO_CINTERION_CellularNetwork : public AT_CellularNetwork { -public: - GEMALTO_CINTERION_CellularNetwork(ATHandler &atHandler); - virtual ~GEMALTO_CINTERION_CellularNetwork(); - -protected: - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opsAct); -}; - -} // namespace mbed - -#endif // GEMALTO_CINTERION_CELLULAR_NETWORK_H_ diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 052fbc2153..3670e99799 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -16,9 +16,9 @@ */ #include "QUECTEL_UG96.h" -#include "QUECTEL_UG96_CellularNetwork.h" #include "QUECTEL_UG96_CellularPower.h" #include "QUECTEL_UG96_CellularContext.h" +#include "AT_CellularNetwork.h" using namespace mbed; using namespace events; @@ -45,11 +45,6 @@ QUECTEL_UG96::~QUECTEL_UG96() { } -AT_CellularNetwork *QUECTEL_UG96::open_network_impl(ATHandler &at) -{ - return new QUECTEL_UG96_CellularNetwork(at); -} - AT_CellularPower *QUECTEL_UG96::open_power_impl(ATHandler &at) { return new QUECTEL_UG96_CellularPower(at); diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h index 84ad9a2bfa..d85c0e8a2f 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h @@ -36,13 +36,11 @@ public: virtual ~QUECTEL_UG96(); protected: // AT_CellularDevice - virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); public: // NetworkInterface void handle_urc(FileHandle *fh); - }; } // namespace mbed diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp deleted file mode 100644 index 994dc9d4a5..0000000000 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_UG96_CellularNetwork.h" - -using namespace mbed; - -QUECTEL_UG96_CellularNetwork::QUECTEL_UG96_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler) -{ -} - -QUECTEL_UG96_CellularNetwork::~QUECTEL_UG96_CellularNetwork() -{ -} - -nsapi_error_t QUECTEL_UG96_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) -{ - _op_act = RAT_UNKNOWN; - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h deleted file mode 100644 index 202529b187..0000000000 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef QUECTEL_UG96_CELLULAR_NETWORK_H_ -#define QUECTEL_UG96_CELLULAR_NETWORK_H_ - -#include "AT_CellularNetwork.h" - -namespace mbed { - -class QUECTEL_UG96_CellularNetwork : public AT_CellularNetwork { -public: - QUECTEL_UG96_CellularNetwork(ATHandler &atHandler); - virtual ~QUECTEL_UG96_CellularNetwork(); - -protected: - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); -}; - -} // namespace mbed - -#endif // QUECTEL_UG96_CELLULAR_NETWORK_H_ diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 49a7114af6..c9a796ef96 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -17,8 +17,8 @@ #include "TELIT_HE910.h" #include "TELIT_HE910_CellularPower.h" -#include "TELIT_HE910_CellularNetwork.h" #include "TELIT_HE910_CellularContext.h" +#include "AT_CellularNetwork.h" using namespace mbed; using namespace events; @@ -41,11 +41,6 @@ TELIT_HE910::~TELIT_HE910() { } -AT_CellularNetwork *TELIT_HE910::open_network_impl(ATHandler &at) -{ - return new TELIT_HE910_CellularNetwork(at); -} - AT_CellularPower *TELIT_HE910::open_power_impl(ATHandler &at) { return new TELIT_HE910_CellularPower(at); diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h index 0bb7cf07bc..0158bab9dd 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h @@ -31,7 +31,6 @@ public: virtual ~TELIT_HE910(); protected: // AT_CellularDevice - virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual uint16_t get_send_delay() const; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp deleted file mode 100644 index 00cf8c0568..0000000000 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "TELIT_HE910_CellularNetwork.h" - -using namespace mbed; - -TELIT_HE910_CellularNetwork::TELIT_HE910_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler) -{ -} - -TELIT_HE910_CellularNetwork::~TELIT_HE910_CellularNetwork() -{ -} - -nsapi_error_t TELIT_HE910_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) -{ - _op_act = RAT_UNKNOWN; - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h deleted file mode 100644 index 034449f851..0000000000 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularNetwork.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef TELIT_HE910_CELLULAR_NETWORK_H_ -#define TELIT_HE910_CELLULAR_NETWORK_H_ - -#include "AT_CellularNetwork.h" - -namespace mbed { - -class TELIT_HE910_CellularNetwork : public AT_CellularNetwork { -public: - TELIT_HE910_CellularNetwork(ATHandler &atHandler); - virtual ~TELIT_HE910_CellularNetwork(); - -protected: - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); -}; - -} // namespace mbed - -#endif // TELIT_HE910_CELLULAR_NETWORK_H_ diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index ab34514e25..240ea360af 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -16,9 +16,9 @@ */ #include "UBLOX_PPP.h" -#include "UBLOX_PPP_CellularNetwork.h" #include "UBLOX_PPP_CellularPower.h" #include "UBLOX_PPP_CellularContext.h" +#include "AT_CellularNetwork.h" using namespace mbed; using namespace events; @@ -45,11 +45,6 @@ UBLOX_PPP::~UBLOX_PPP() { } -AT_CellularNetwork *UBLOX_PPP::open_network_impl(ATHandler &at) -{ - return new UBLOX_PPP_CellularNetwork(at); -} - AT_CellularPower *UBLOX_PPP::open_power_impl(ATHandler &at) { return new UBLOX_PPP_CellularPower(at); diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h index 33f8ace12b..1609dba4bd 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h @@ -28,7 +28,6 @@ public: virtual ~UBLOX_PPP(); protected: // AT_CellularDevice - virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); }; diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp deleted file mode 100644 index 5119901570..0000000000 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "UBLOX_PPP_CellularNetwork.h" - -using namespace mbed; - -UBLOX_PPP_CellularNetwork::UBLOX_PPP_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler) -{ -} - -UBLOX_PPP_CellularNetwork::~UBLOX_PPP_CellularNetwork() -{ -} - -nsapi_error_t UBLOX_PPP_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) -{ - _op_act = RAT_UNKNOWN; - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h deleted file mode 100644 index c6b5c8e3c8..0000000000 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularNetwork.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UBLOX_PPP_CELLULAR_NETWORK_H_ -#define UBLOX_PPP_CELLULAR_NETWORK_H_ - -#include "AT_CellularNetwork.h" - -namespace mbed { - -class UBLOX_PPP_CellularNetwork : public AT_CellularNetwork { -public: - UBLOX_PPP_CellularNetwork(ATHandler &atHandler); - virtual ~UBLOX_PPP_CellularNetwork(); - -protected: - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); -}; - -} // namespace mbed - -#endif // UBLOX_PPP_CELLULAR_NETWORK_H_ From 0c9130efeb66f48479e48b09d9701302a6e959df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Thu, 13 Dec 2018 10:32:19 +0200 Subject: [PATCH 19/41] Cellular: change stack_type_supported to get_property Change usage of AT_CellularContext::stack_type_supported to AT_CellularBase::get_property. This way we can rid of targets overriding stack_type_supported and delete unnecessary classes and simplify new targets. --- .../at_cellularbase/at_cellularbasetest.cpp | 8 ++++- .../at_cellularcontexttest.cpp | 9 ++--- UNITTESTS/stubs/AT_CellularBase_stub.cpp | 2 ++ UNITTESTS/stubs/AT_CellularContext_stub.cpp | 10 ++++-- .../cellular/framework/AT/AT_CellularBase.h | 15 ++++---- .../framework/AT/AT_CellularContext.cpp | 31 ++++++++-------- .../framework/AT/AT_CellularContext.h | 7 +--- .../framework/AT/AT_CellularNetwork.cpp | 4 +-- .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 9 +++++ .../GEMALTO_CINTERION_CellularContext.cpp | 9 ----- .../GEMALTO_CINTERION_CellularContext.h | 1 - .../MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp | 8 ++--- .../MultiTech/DragonflyNano/PPP/SARA4_PPP.h | 1 - .../PPP/SARA4_PPP_CellularContext.cpp | 35 ------------------- .../PPP/SARA4_PPP_CellularContext.h | 35 ------------------- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 9 ++--- .../targets/QUECTEL/BC95/QUECTEL_BC95.h | 1 - .../BC95/QUECTEL_BC95_CellularContext.cpp | 5 --- .../BC95/QUECTEL_BC95_CellularContext.h | 1 - .../BC95/QUECTEL_BC95_CellularPower.cpp | 30 ---------------- .../QUECTEL/BC95/QUECTEL_BC95_CellularPower.h | 33 ----------------- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 11 +++--- .../targets/QUECTEL/BG96/QUECTEL_BG96.h | 1 - .../BG96/QUECTEL_BG96_CellularContext.cpp | 8 ----- .../BG96/QUECTEL_BG96_CellularContext.h | 1 - .../BG96/QUECTEL_BG96_CellularPower.cpp | 26 -------------- .../QUECTEL/BG96/QUECTEL_BG96_CellularPower.h | 32 ----------------- .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 3 ++ .../UG96/QUECTEL_UG96_CellularContext.cpp | 5 --- .../UG96/QUECTEL_UG96_CellularContext.h | 1 - .../targets/TELIT/HE910/TELIT_HE910.cpp | 9 ++--- .../targets/TELIT/HE910/TELIT_HE910.h | 1 - .../HE910/TELIT_HE910_CellularContext.cpp | 35 ------------------- .../TELIT/HE910/TELIT_HE910_CellularContext.h | 35 ------------------- .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 22 +++++++++--- .../UBLOX/AT/UBLOX_AT_CellularContext.cpp | 5 --- .../UBLOX/AT/UBLOX_AT_CellularContext.h | 1 - .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 25 ++++++++----- .../framework/targets/UBLOX/PPP/UBLOX_PPP.h | 1 - .../UBLOX/PPP/UBLOX_PPP_CellularContext.cpp | 35 ------------------- .../UBLOX/PPP/UBLOX_PPP_CellularContext.h | 35 ------------------- 41 files changed, 110 insertions(+), 445 deletions(-) delete mode 100644 features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.cpp delete mode 100644 features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.h delete mode 100644 features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h delete mode 100644 features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h delete mode 100644 features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.cpp delete mode 100644 features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.h delete mode 100644 features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.cpp delete mode 100644 features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.h diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp index e522b6feef..3296cde7ab 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp @@ -40,6 +40,9 @@ public: 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; set_cellular_properties(cellular_properties); @@ -116,7 +119,10 @@ TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_cellular_properties) AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 1 // AT_CGAUTH + 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; at.set_cellular_properties(cellular_properties); } diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp index df7a5bbfb6..f592013ab8 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp @@ -27,6 +27,7 @@ #include "Semaphore_stub.h" #include "CellularDevice_stub.h" #include "equeue_stub.h" +#include "AT_CellularBase_stub.h" using namespace mbed; using namespace events; @@ -114,12 +115,12 @@ public: class my_AT_CTX : public AT_CellularContext { public: my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) : - AT_CellularContext(at, device, apn), _st(at) {} - virtual ~my_AT_CTX() {} - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type) + AT_CellularContext(at, device, apn), _st(at) { - return false; + AT_CellularBase_stub::supported_bool = false; } + virtual ~my_AT_CTX() {} + virtual NetworkStack *get_stack() { return &_st; diff --git a/UNITTESTS/stubs/AT_CellularBase_stub.cpp b/UNITTESTS/stubs/AT_CellularBase_stub.cpp index ef8c844eaf..3d7c9265ac 100644 --- a/UNITTESTS/stubs/AT_CellularBase_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularBase_stub.cpp @@ -47,6 +47,8 @@ intptr_t AT_CellularBase::get_property(CellularProperty key) return AT_CellularNetwork::RegistrationModeDisable; } else if (key == PROPERTY_C_REG || key == PROPERTY_C_EREG) { return AT_CellularNetwork::RegistrationModeEnable; + } else if (key == PROPERTY_AT_CGAUTH) { + return true; } return AT_CellularBase_stub::supported_bool; diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index 8e8daba61b..c1f70ad3fb 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -135,9 +135,15 @@ const char *AT_CellularContext::get_gateway() return NULL; } -bool AT_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) +AT_CellularBase::CellularProperty AT_CellularContext::nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack) { - return true; + AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_STACK; + if (stack == IPV6_STACK) { + prop = PROPERTY_IPV6_STACK; + } else if (stack == IPV4V6_STACK) { + prop = PROPERTY_IPV4V6_STACK; + } + return prop; } nsapi_ip_stack_t AT_CellularContext::get_stack_type() diff --git a/features/cellular/framework/AT/AT_CellularBase.h b/features/cellular/framework/AT/AT_CellularBase.h index a7c48b7477..0c4bb94b3f 100644 --- a/features/cellular/framework/AT/AT_CellularBase.h +++ b/features/cellular/framework/AT/AT_CellularBase.h @@ -43,12 +43,15 @@ public: device_err_t get_device_error() const; enum CellularProperty { - PROPERTY_C_EREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. - PROPERTY_C_GREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. - PROPERTY_C_REG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. - PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. - PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# - PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported + PROPERTY_C_EREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. + PROPERTY_C_GREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. + PROPERTY_C_REG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type. + PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. + PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# + PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported + PROPERTY_IPV4_STACK, // 0 = not supported, 1 = supported + PROPERTY_IPV6_STACK, // 0 = not supported, 1 = supported + PROPERTY_IPV4V6_STACK, // 0 = not supported, 1 = supported PROPERTY_MAX }; diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 6f16f05ba9..b2ab6ca8ca 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -239,15 +239,6 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con _pwd = pwd; } -bool AT_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - if (stack_type == _ip_stack_type) { - return true; - } else { - return false; - } -} - nsapi_ip_stack_t AT_CellularContext::get_stack_type() { return _ip_stack_type; @@ -306,6 +297,17 @@ nsapi_error_t AT_CellularContext::do_user_authentication() return NSAPI_ERROR_OK; } +AT_CellularBase::CellularProperty AT_CellularContext::nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack) +{ + AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_STACK; + if (stack == IPV6_STACK) { + prop = PROPERTY_IPV6_STACK; + } else if (stack == IPV4V6_STACK) { + prop = PROPERTY_IPV4V6_STACK; + } + return prop; +} + bool AT_CellularContext::get_context() { _at.cmd_start("AT+CGDCONT?"); @@ -316,8 +318,8 @@ bool AT_CellularContext::get_context() char apn[MAX_ACCESSPOINT_NAME_LENGTH]; int apn_len = 0; - bool modem_supports_ipv6 = stack_type_supported(IPV6_STACK); - bool modem_supports_ipv4 = stack_type_supported(IPV4_STACK); + bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_STACK); + bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_STACK); while (_at.info_resp()) { int cid = _at.read_int(); @@ -334,7 +336,8 @@ bool AT_CellularContext::get_context() } nsapi_ip_stack_t pdp_stack = string_to_stack_type(pdp_type_from_context); // Accept dual PDP context for IPv4/IPv6 only modems - if (pdp_stack != DEFAULT_STACK && (stack_type_supported(pdp_stack) || pdp_stack == IPV4V6_STACK)) { + if (pdp_stack != DEFAULT_STACK && (get_property(nsapi_ip_stack_t_to_cellular_property(pdp_stack)) + || pdp_stack == IPV4V6_STACK)) { if (_ip_stack_type_requested == IPV4_STACK) { if (pdp_stack == IPV4_STACK || pdp_stack == IPV4V6_STACK) { _ip_stack_type = _ip_stack_type_requested; @@ -399,8 +402,8 @@ bool AT_CellularContext::set_new_context(int cid) nsapi_ip_stack_t tmp_stack = _ip_stack_type_requested; if (tmp_stack == DEFAULT_STACK) { - bool modem_supports_ipv6 = stack_type_supported(IPV6_STACK); - bool modem_supports_ipv4 = stack_type_supported(IPV4_STACK); + bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_STACK); + bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_STACK); if (modem_supports_ipv6 && modem_supports_ipv4) { tmp_stack = IPV4V6_STACK; diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index c045c0a3ad..dc59f69c65 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -75,12 +75,6 @@ protected: */ virtual void do_connect(); - /** Check if modem supports the given stack type. Can be overridden by the modem. - * - * @return true if supported - */ - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); - /** Get the operation specific timeout. Used in synchronous mode when setting the maximum * waiting time. Modem specific implementation can override this to provide different timeouts. * @@ -107,6 +101,7 @@ private: nsapi_ip_stack_t string_to_stack_type(const char *pdp_type); nsapi_ip_stack_t get_stack_type(); nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op); + AT_CellularBase::CellularProperty nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack); private: nsapi_ip_stack_t _ip_stack_type_requested; diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index 75e6ff7370..538fb27f81 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -71,8 +71,8 @@ static const char *const rat_str[AT_CellularNetwork::RAT_MAX] = { AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler), - _connection_status_cb(NULL), _op_act(RAT_UNKNOWN), _connect_status(NSAPI_STATUS_DISCONNECTED), - _ciotopt_network_support_cb(NULL), _supported_network_opt(CIOT_OPT_MAX) + _connection_status_cb(NULL), _ciotopt_network_support_cb(NULL), _op_act(RAT_UNKNOWN), + _connect_status(NSAPI_STATUS_DISCONNECTED), _supported_network_opt(CIOT_OPT_MAX) { _urc_funcs[C_EREG] = callback(this, &AT_CellularNetwork::urc_cereg); diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 13cbe021d4..7ab42ce559 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -95,6 +95,9 @@ void GEMALTO_CINTERION::init_module_bgs2() 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; AT_CellularBase::set_cellular_properties(cellular_properties); _module = ModuleBGS2; @@ -110,6 +113,9 @@ void GEMALTO_CINTERION::init_module_els61() 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 1, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; AT_CellularBase::set_cellular_properties(cellular_properties); _module = ModuleELS61; @@ -125,6 +131,9 @@ void GEMALTO_CINTERION::init_module_ems31() 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 1, // PROPERTY_IPV6_STACK + 1, // PROPERTY_IPV4V6_STACK }; AT_CellularBase::set_cellular_properties(cellular_properties); _module = ModuleEMS31; diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp index bce1fb077d..09d42aa81b 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp @@ -16,7 +16,6 @@ */ #include "GEMALTO_CINTERION_CellularContext.h" #include "GEMALTO_CINTERION_CellularStack.h" -#include "GEMALTO_CINTERION.h" namespace mbed { @@ -39,12 +38,4 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack() } #endif // NSAPI_PPP_AVAILABLE -bool GEMALTO_CINTERION_CellularContext::stack_type_supported(nsapi_ip_stack_t requested_stack) -{ - if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) { - return (requested_stack == IPV4_STACK); - } - return (requested_stack == IPV4_STACK || requested_stack == IPV6_STACK); -} - } /* namespace mbed */ diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h index c77c5af703..262fbb2fe3 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h @@ -30,7 +30,6 @@ protected: #if !NSAPI_PPP_AVAILABLE virtual NetworkStack *get_stack(); #endif // NSAPI_PPP_AVAILABLE - virtual bool stack_type_supported(nsapi_ip_stack_t requested_stack); }; } /* namespace mbed */ diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index 989398ab89..a7312cdf05 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -18,7 +18,6 @@ #include "SARA4_PPP.h" #include "SARA4_PPP_CellularNetwork.h" #include "SARA4_PPP_CellularPower.h" -#include "SARA4_PPP_CellularContext.h" using namespace mbed; using namespace events; @@ -30,6 +29,9 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 0, // AT_CGSN_WITH_TYPE 0, // AT_CGDATA 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh) @@ -51,7 +53,3 @@ AT_CellularPower *SARA4_PPP::open_power_impl(ATHandler &at) return new SARA4_PPP_CellularPower(at); } -AT_CellularContext *SARA4_PPP::create_context_impl(ATHandler &at, const char *apn) -{ - return new SARA4_PPP_CellularContext(at, this, apn); -} diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h index 6a9f346d7a..3f4c580994 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h @@ -31,7 +31,6 @@ public: public: // CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); }; } // namespace mbed diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.cpp deleted file mode 100644 index 4616099faf..0000000000 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "SARA4_PPP_CellularContext.h" - -namespace mbed { - -SARA4_PPP_CellularContext::SARA4_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) -{ -} - -SARA4_PPP_CellularContext::~SARA4_PPP_CellularContext() -{ -} - -bool SARA4_PPP_CellularContext::stack_type_supported(nsapi_ip_stack_t requested_stack) -{ - return requested_stack == IPV4_STACK ? true : false; -} - -} /* namespace mbed */ diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.h b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.h deleted file mode 100644 index be4a177912..0000000000 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef SARA4_PPP_CELLULARCONTEXT_H_ -#define SARA4_PPP_CELLULARCONTEXT_H_ - -#include "AT_CellularContext.h" - -namespace mbed { - -class SARA4_PPP_CellularContext: public AT_CellularContext { -public: - SARA4_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); - virtual ~SARA4_PPP_CellularContext(); - -protected: - virtual bool stack_type_supported(nsapi_ip_stack_t requested_stack); -}; - -} /* namespace mbed */ - -#endif // SARA4_PPP_CELLULARCONTEXT_H_ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index cbcb92c441..44c6636690 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -16,7 +16,6 @@ */ #include "QUECTEL_BC95_CellularNetwork.h" -#include "QUECTEL_BC95_CellularPower.h" #include "QUECTEL_BC95_CellularContext.h" #include "QUECTEL_BC95_CellularInformation.h" #include "QUECTEL_BC95.h" @@ -36,6 +35,9 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 0, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh) @@ -69,11 +71,6 @@ AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at) return new QUECTEL_BC95_CellularNetwork(at); } -AT_CellularPower *QUECTEL_BC95::open_power_impl(ATHandler &at) -{ - return new QUECTEL_BC95_CellularPower(at); -} - AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn) { return new QUECTEL_BC95_CellularContext(at, this, apn); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index ee73b1e0c5..f423abe642 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -32,7 +32,6 @@ public: // AT_CellularDevice protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual nsapi_error_t init(); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp index 0f87bac48c..63bc05528c 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp @@ -38,9 +38,4 @@ NetworkStack *QUECTEL_BC95_CellularContext::get_stack() } #endif // #if !NSAPI_PPP_AVAILABLE -bool QUECTEL_BC95_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - return stack_type == IPV4_STACK ? true : false; -} - } /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h index d1421c20b5..d1c526a364 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h @@ -30,7 +30,6 @@ protected: #if !NSAPI_PPP_AVAILABLE virtual NetworkStack *get_stack(); #endif // #if !NSAPI_PPP_AVAILABLE - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); }; } /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp deleted file mode 100644 index 778c8041ff..0000000000 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_BC95_CellularPower.h" - -using namespace mbed; - -QUECTEL_BC95_CellularPower::QUECTEL_BC95_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ - -} - -QUECTEL_BC95_CellularPower::~QUECTEL_BC95_CellularPower() -{ - -} diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h deleted file mode 100644 index 781be8f5c7..0000000000 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef QUECTEL_BC95_CELLULAR_POWER_H_ -#define QUECTEL_BC95_CELLULAR_POWER_H_ - -#include "AT_CellularPower.h" - -namespace mbed { - -class QUECTEL_BC95_CellularPower : public AT_CellularPower { -public: - QUECTEL_BC95_CellularPower(ATHandler &atHandler); - virtual ~QUECTEL_BC95_CellularPower(); -}; - -} // namespace mbed - -#endif // QUECTEL_BC95_CELLULAR_POWER_H_ diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index ac65e3587d..3265929c11 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -19,7 +19,6 @@ #include "QUECTEL_BG96_CellularNetwork.h" #include "QUECTEL_BG96_CellularStack.h" #include "QUECTEL_BG96_CellularInformation.h" -#include "QUECTEL_BG96_CellularPower.h" #include "QUECTEL_BG96_CellularContext.h" using namespace mbed; @@ -37,7 +36,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 1, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh) @@ -54,11 +56,6 @@ AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) return new QUECTEL_BG96_CellularNetwork(at); } -AT_CellularPower *QUECTEL_BG96::open_power_impl(ATHandler &at) -{ - return new QUECTEL_BG96_CellularPower(at); -} - AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char *apn) { return new QUECTEL_BG96_CellularContext(at, this, apn); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 8bab3b34a2..3dfc08ef36 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -29,7 +29,6 @@ public: protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual void set_ready_cb(Callback callback); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp index 73a971df52..badc596392 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp @@ -28,14 +28,6 @@ QUECTEL_BG96_CellularContext::~QUECTEL_BG96_CellularContext() { } -bool QUECTEL_BG96_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - if (stack_type == IPV4_STACK) { - return true; - } - return false; -} - #if !NSAPI_PPP_AVAILABLE NetworkStack *QUECTEL_BG96_CellularContext::get_stack() { diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h index 89d20fc231..bcf019c6bc 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h @@ -27,7 +27,6 @@ public: virtual ~QUECTEL_BG96_CellularContext(); protected: - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); #if !NSAPI_PPP_AVAILABLE virtual NetworkStack *get_stack(); #endif // #if !NSAPI_PPP_AVAILABLE diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp deleted file mode 100644 index 6ef1917c12..0000000000 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_BG96_CellularPower.h" - -#define DEVICE_READY_URC "CPIN:" - -using namespace mbed; - -QUECTEL_BG96_CellularPower::QUECTEL_BG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ -} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h deleted file mode 100644 index 6d3f4077d3..0000000000 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef QUECTEL_BG96_CELLULAR_POWER_H_ -#define QUECTEL_BG96_CELLULAR_POWER_H_ - -#include "AT_CellularPower.h" - -namespace mbed { - -class QUECTEL_BG96_CellularPower : public AT_CellularPower { -public: - QUECTEL_BG96_CellularPower(ATHandler &atHandler); -}; - -} // namespace mbed - -#endif // QUECTEL_BG96_CELLULAR_POWER_H_ diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 3670e99799..9c7188ca15 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -34,6 +34,9 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; QUECTEL_UG96::QUECTEL_UG96(FileHandle *fh) : AT_CellularDevice(fh) diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp index 9f65d78f9a..145dda191c 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp @@ -27,11 +27,6 @@ QUECTEL_UG96_CellularContext::~QUECTEL_UG96_CellularContext() { } -bool QUECTEL_UG96_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - return stack_type == IPV4_STACK ? true : false; -} - nsapi_error_t QUECTEL_UG96_CellularContext::do_user_authentication() { if (_pwd && _uname) { diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h index 0ec4232071..660acad209 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h @@ -27,7 +27,6 @@ public: virtual ~QUECTEL_UG96_CellularContext(); protected: - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); virtual nsapi_error_t do_user_authentication(); }; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index c9a796ef96..0342b2295d 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -17,7 +17,6 @@ #include "TELIT_HE910.h" #include "TELIT_HE910_CellularPower.h" -#include "TELIT_HE910_CellularContext.h" #include "AT_CellularNetwork.h" using namespace mbed; @@ -30,6 +29,9 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 0, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh) @@ -46,11 +48,6 @@ AT_CellularPower *TELIT_HE910::open_power_impl(ATHandler &at) return new TELIT_HE910_CellularPower(at); } -AT_CellularContext *TELIT_HE910::create_context_impl(ATHandler &at, const char *apn) -{ - return new TELIT_HE910_CellularContext(at, this, apn); -} - uint16_t TELIT_HE910::get_send_delay() const { return DEFAULT_DELAY_BETWEEN_AT_COMMANDS; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h index 0158bab9dd..999dff614b 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h @@ -32,7 +32,6 @@ public: protected: // AT_CellularDevice virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); virtual uint16_t get_send_delay() const; virtual nsapi_error_t init(); }; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.cpp deleted file mode 100644 index b9ec13eb06..0000000000 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "TELIT_HE910_CellularContext.h" - -namespace mbed { - -TELIT_HE910_CellularContext::TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) -{ -} - -TELIT_HE910_CellularContext::~TELIT_HE910_CellularContext() -{ -} - -bool TELIT_HE910_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - return stack_type == IPV4_STACK ? true : false; -} - -} /* namespace mbed */ diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.h deleted file mode 100644 index 774fada8c9..0000000000 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularContext.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef TELIT_HE910_CELLULARCONTEXT_H_ -#define TELIT_HE910_CELLULARCONTEXT_H_ - -#include "AT_CellularContext.h" - -namespace mbed { - -class TELIT_HE910_CellularContext: public AT_CellularContext { -public: - TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); - virtual ~TELIT_HE910_CellularContext(); - -protected: - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); -}; - -} /* namespace mbed */ - -#endif // TELIT_HE910_CELLULARCONTEXT_H_ diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index eb688f0902..d714be6f6c 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -28,9 +28,24 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { AT_CellularNetwork::RegistrationModeDisable,// C_EREG AT_CellularNetwork::RegistrationModeLAC, // C_GREG AT_CellularNetwork::RegistrationModeLAC, // C_REG - 0, // AT_CGSN_WITH_TYPE - 1, // AT_CGDATA - 1, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH, + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK +}; +#else +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG + 1, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; #endif @@ -38,7 +53,6 @@ UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh) { #ifdef TARGET_UBLOX_C030_R41XM AT_CellularBase::set_cellular_properties(cellular_properties); -#endif } UBLOX_AT::~UBLOX_AT() diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp index c06cf6d119..3a21e4f0d3 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp @@ -39,11 +39,6 @@ NetworkStack *UBLOX_AT_CellularContext::get_stack() return _stack; } -bool UBLOX_AT_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - return stack_type == IPV4_STACK ? true : false; -} - void UBLOX_AT_CellularContext::do_connect() { _at.lock(); diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h index d6cd4731b1..1986e0aaa9 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h @@ -31,7 +31,6 @@ public: protected: virtual NetworkStack *get_stack(); - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); private: diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index 240ea360af..533c2fbdae 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -17,7 +17,6 @@ #include "UBLOX_PPP.h" #include "UBLOX_PPP_CellularPower.h" -#include "UBLOX_PPP_CellularContext.h" #include "AT_CellularNetwork.h" using namespace mbed; @@ -30,15 +29,28 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 1, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK +}; +#else +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG + 1, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; #endif UBLOX_PPP::UBLOX_PPP(FileHandle *fh) : AT_CellularDevice(fh) { -#ifdef TARGET_UBLOX_C027 AT_CellularBase::set_cellular_properties(cellular_properties); -#endif } UBLOX_PPP::~UBLOX_PPP() @@ -49,8 +61,3 @@ AT_CellularPower *UBLOX_PPP::open_power_impl(ATHandler &at) { return new UBLOX_PPP_CellularPower(at); } - -AT_CellularContext *UBLOX_PPP::create_context_impl(ATHandler &at, const char *apn) -{ - return new UBLOX_PPP_CellularContext(at, this, apn); -} diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h index 1609dba4bd..dc78de14a1 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h @@ -29,7 +29,6 @@ public: protected: // AT_CellularDevice virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); }; } // namespace mbed diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.cpp deleted file mode 100644 index d360df7dfc..0000000000 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "UBLOX_PPP_CellularContext.h" - -namespace mbed { - -UBLOX_PPP_CellularContext::UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) -{ -} - -UBLOX_PPP_CellularContext::~UBLOX_PPP_CellularContext() -{ -} - -bool UBLOX_PPP_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - return stack_type == IPV4_STACK ? true : false; -} - -} /* namespace mbed */ diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.h deleted file mode 100644 index 37ac1bb8ee..0000000000 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularContext.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UBLOX_PPP_CELLULARCONTEXT_H_ -#define UBLOX_PPP_CELLULARCONTEXT_H_ - -#include "AT_CellularContext.h" - -namespace mbed { - -class UBLOX_PPP_CellularContext: public AT_CellularContext { -public: - UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); - virtual ~UBLOX_PPP_CellularContext(); - -protected: - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); -}; - -} /* namespace mbed */ - -#endif // UBLOX_PPP_CELLULARCONTEXT_H_ From fa5d0fc358b3c0a0ccf6ac488c3d26d8417583b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Mon, 17 Dec 2018 09:49:52 +0200 Subject: [PATCH 20/41] Cellular: Added generic cellular modem Generic cellular module (GENERIC_AT3GPP) can by used as a default module when porting new cellular module. It's a good starting point and eases porting of new modules. GENERIC_AT3GPP uses only standard 3GPP AT commands when communicating with the modem. --- .../cellular/framework/AT/AT_CellularBase.h | 6 +-- .../GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp | 43 ++++++++++++++++ .../GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h | 49 +++++++++++++++++++ .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 2 +- 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp create mode 100644 features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h diff --git a/features/cellular/framework/AT/AT_CellularBase.h b/features/cellular/framework/AT/AT_CellularBase.h index 0c4bb94b3f..489949fe06 100644 --- a/features/cellular/framework/AT/AT_CellularBase.h +++ b/features/cellular/framework/AT/AT_CellularBase.h @@ -49,9 +49,9 @@ public: PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported - PROPERTY_IPV4_STACK, // 0 = not supported, 1 = supported - PROPERTY_IPV6_STACK, // 0 = not supported, 1 = supported - PROPERTY_IPV4V6_STACK, // 0 = not supported, 1 = supported + PROPERTY_IPV4_STACK, // 0 = not supported, 1 = supported. Does modem support IPV4? + PROPERTY_IPV6_STACK, // 0 = not supported, 1 = supported. Does modem support IPV6? + PROPERTY_IPV4V6_STACK, // 0 = not supported, 1 = supported. Does modem support dual stack IPV4V6? PROPERTY_MAX }; diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp new file mode 100644 index 0000000000..8a0da4e727 --- /dev/null +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "GENERIC_AT3GPP.h" +#include "AT_CellularNetwork.h" + +using namespace mbed; + +// by default all properties are supported +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeLAC, // C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeLAC, // C_REG + 1, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 1, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 1, // PROPERTY_IPV6_STACK + 1, // PROPERTY_IPV4V6_STACK +}; + +GENERIC_AT3GPP::GENERIC_AT3GPP(FileHandle *fh) : AT_CellularDevice(fh) +{ + AT_CellularBase::set_cellular_properties(cellular_properties); +} + +GENERIC_AT3GPP::~GENERIC_AT3GPP() +{ +} diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h new file mode 100644 index 0000000000..3e631b08a0 --- /dev/null +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GENERIC_AT3GPP_H_ +#define GENERIC_AT3GPP_H_ + +#include "AT_CellularDevice.h" + +namespace mbed { + +/** + * Generic Cellular module which can be used as a default module when porting new cellular module. + * GENERIC_AT3GPP uses standard 3GPP AT commands (3GPP TS 27.007 V14.5.0 (2017-09)) to communicate with the modem. + * + * GENERIC_AT3GPP can be used as a shield for example on top K64F. + * Cellular example can be used for testing: https://github.com/ARMmbed/mbed-os-example-cellular + * Add line to mbed_app.json where you define this class as CELLULAR_DEVICE and the correct pins. In cellular example + * line would be for example just above "target_overrides": {... + * For example: + * "macros": ["CELLULAR_DEVICE=GENERIC_AT3GPP", "MDMRXD=PTC16", "MDMTXD=PTC17","MDMRTS=NC", "MDMCTS=NC"], + * You can define CELLULAR_DEVICE and pins also in ../../../common/CellularTargets.h + * + * If new target don't work with GENERIC_AT3GPP then it needs some customizations. + * First thing to try can be checking/modifying cellular_properties array in GENERIC_AT3GPP.cpp, does the module support + * these commands or not? Modify array and if that's not enough then some AT_xxx classes might need to be created and + * methods overridden. Check help how other modules are done what methods they have overridden. Happy porting! + */ +class GENERIC_AT3GPP : public AT_CellularDevice { +public: + GENERIC_AT3GPP(FileHandle *fh); + virtual ~GENERIC_AT3GPP(); + +}; +} // namespace mbed +#endif // GENERIC_AT3GPP_H_ diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 3265929c11..2a0c9c7eaa 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -35,7 +35,7 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { AT_CellularNetwork::RegistrationModeLAC, // C_GREG AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE - 1, // AT_CGDATA + 0, // AT_CGDATA 1, // AT_CGAUTH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK From 97709f52ec368cf6baa4dfcd8df4c33a6087ca16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Mon, 3 Dec 2018 08:47:01 +0200 Subject: [PATCH 21/41] Cellular: fix possible crash in state machine _sim_pin was changed to pointer from array and length was checked with strlen. If _sim_pin was null it caused crash. Fix by checking _sim_pin against NULL. Power class could have been called without checking if power is NULL. Fix by checking that power class is not null. Fix state machine to return correct states when queried. --- features/cellular/framework/device/CellularStateMachine.cpp | 6 +++--- features/cellular/framework/device/CellularStateMachine.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index 25988de447..d56c7912da 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -153,7 +153,7 @@ bool CellularStateMachine::open_sim() } if (state == CellularDevice::SimStatePinNeeded) { - if (strlen(_sim_pin)) { + if (_sim_pin) { tr_info("Entering PIN to open SIM"); _cb_data.error = _cellularDevice.set_pin(_sim_pin); if (_cb_data.error) { @@ -428,13 +428,13 @@ void CellularStateMachine::state_sim_pin() } if (_network->is_active_context()) { // check if context was already activated - tr_debug("ACTIVE CONTEXT FOUND, skip registering."); + tr_debug("Active context found."); _network_status |= ACTIVE_PDP_CONTEXT; } CellularNetwork::AttachStatus status; // check if modem is already attached to a network if (_network->get_attach(status) == NSAPI_ERROR_OK && status == CellularNetwork::Attached) { _network_status |= ATTACHED_TO_NETWORK; - tr_debug("DEVICE IS ALREADY ATTACHED TO NETWORK, skip registering and attach."); + tr_debug("Cellular already attached."); } if (_plmn) { enter_to_state(STATE_MANUAL_REGISTERING_NETWORK); diff --git a/features/cellular/framework/device/CellularStateMachine.h b/features/cellular/framework/device/CellularStateMachine.h index c9d10e9f25..7b4e7656af 100644 --- a/features/cellular/framework/device/CellularStateMachine.h +++ b/features/cellular/framework/device/CellularStateMachine.h @@ -42,6 +42,7 @@ private: // friend of CellularDevice so that it's the only way to close/delete this class. friend class CellularDevice; friend class AT_CellularDevice; + friend class UT_CellularStateMachine; // for unit tests /** Constructor * * @param device reference to CellularDevice @@ -98,7 +99,7 @@ private: * @param timeout timeout array using seconds * @param array_len length of the array */ - void set_retry_timeout_array(uint16_t timeout[], int array_len); + void set_retry_timeout_array(uint16_t *timeout, int array_len); /** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic * registering is used when registering to a cellular network. Does not start any operations. From 725e14d15f61aa6e9478e4169bd1912bbaef3f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Mon, 3 Dec 2018 08:47:47 +0200 Subject: [PATCH 22/41] Cellular: Add State machine unit tests. --- .../AT/at_cellularcontext/unittest.cmake | 1 + .../cellularstatemachinetest.cpp | 427 ++++++++++++++++++ .../cellularstatemachine/unittest.cmake | 44 ++ UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 60 ++- UNITTESTS/stubs/AT_CellularDevice_stub.h | 32 ++ UNITTESTS/stubs/AT_CellularNetwork_stub.cpp | 21 +- UNITTESTS/stubs/AT_CellularNetwork_stub.h | 30 ++ UNITTESTS/stubs/AT_CellularPower_stub.cpp | 18 +- UNITTESTS/stubs/AT_CellularPower_stub.h | 28 ++ UNITTESTS/stubs/Thread_stub.cpp | 22 +- UNITTESTS/stubs/Thread_stub.h | 26 ++ UNITTESTS/target_h/cmsis_os2.h | 2 +- .../framework/device/CellularStateMachine.cpp | 28 +- .../framework/device/CellularStateMachine.h | 2 +- 14 files changed, 719 insertions(+), 22 deletions(-) create mode 100644 UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp create mode 100644 UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake create mode 100644 UNITTESTS/stubs/AT_CellularDevice_stub.h create mode 100644 UNITTESTS/stubs/AT_CellularNetwork_stub.h create mode 100644 UNITTESTS/stubs/AT_CellularPower_stub.h create mode 100644 UNITTESTS/stubs/Thread_stub.h diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake index f10bf17d26..5d36efe270 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake @@ -26,6 +26,7 @@ set(unittest-test-sources stubs/AT_CellularDevice_stub.cpp stubs/AT_CellularStack_stub.cpp stubs/AT_CellularNetwork_stub.cpp + stubs/AT_CellularPower_stub.cpp stubs/CellularDevice_stub.cpp stubs/CellularStateMachine_stub.cpp stubs/equeue_stub.c diff --git a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp new file mode 100644 index 0000000000..1fb99fed77 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp @@ -0,0 +1,427 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "gtest/gtest.h" +#include + +#include "CellularDevice.h" +#include "AT_CellularDevice_stub.h" +#include "FileHandle_stub.h" +#include "AT_CellularPower_stub.h" +#include "AT_CellularNetwork_stub.h" +#include "myCellularDevice.h" +#include "Thread_stub.h" +#include "cmsis_os2.h" +#include "equeue_stub.h" + +using namespace mbed; + +enum UT_CellularState { + UT_STATE_INIT = 0, + UT_STATE_POWER_ON, + UT_STATE_DEVICE_READY, + UT_STATE_SIM_PIN, + UT_STATE_REGISTERING_NETWORK, + UT_STATE_MANUAL_REGISTERING_NETWORK, + UT_STATE_ATTACHING_NETWORK, + UT_STATE_MAX_FSM_STATE +}; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestCellularStateMachine : public testing::Test { +protected: + + void SetUp() + { + Thread_stub::osStatus_value = osOK; + AT_CellularPower_stub::fail_counter = 0; + } + + void TearDown() + { + } +}; + +static void cellular_callback(nsapi_event_t ev, intptr_t ptr) +{ + +} + +namespace mbed { + +class UT_CellularStateMachine { + +public: + + UT_CellularStateMachine() { + _state_machine = NULL; + } + + ~UT_CellularStateMachine() { + delete _state_machine; + _state_machine = NULL; + } + + CellularStateMachine *create_state_machine(CellularDevice &device, events::EventQueue &queue) + { + _state_machine = new CellularStateMachine(device, queue); + return _state_machine; + } + + void delete_state_machine() { + delete _state_machine; + _state_machine = NULL; + } + + void set_cellular_callback(mbed::Callback status_cb) + { + _state_machine->set_cellular_callback(status_cb); + } + + nsapi_error_t start_dispatch() + { + return _state_machine->start_dispatch(); + } + + nsapi_error_t run_to_power_on() + { + return _state_machine->run_to_state(CellularStateMachine::STATE_POWER_ON); + } + + nsapi_error_t run_to_device_ready() + { + return _state_machine->run_to_state(CellularStateMachine::STATE_DEVICE_READY); + } + + nsapi_error_t run_to_device_sim_ready() + { + return _state_machine->run_to_state(CellularStateMachine::STATE_SIM_PIN); + } + + nsapi_error_t run_to_device_registered() + { + return _state_machine->run_to_state(CellularStateMachine::STATE_REGISTERING_NETWORK); + } + + nsapi_error_t run_to_device_attached() + { + return _state_machine->run_to_state(CellularStateMachine::STATE_ATTACHING_NETWORK); + } + + void stop() + { + _state_machine->stop(); + } + + void set_sim_pin(const char *sim_pin) + { + _state_machine->set_sim_pin(sim_pin); + } + + void set_retry_timeout_array(uint16_t *timeout, int array_len) + { + _state_machine->set_retry_timeout_array(timeout, array_len); + } + + void set_plmn(const char *plmn) + { + _state_machine->set_plmn(plmn); + } + + bool get_current_status(UT_CellularState ¤t_state, UT_CellularState &target_state) + { + return _state_machine->get_current_status((CellularStateMachine::CellularState&)current_state, + (CellularStateMachine::CellularState&)target_state); + } + + void cellular_event_changed(nsapi_event_t ev, intptr_t ptr) + { + _state_machine->cellular_event_changed(ev, ptr); + } + + void reset() + { + _state_machine->reset(); + } + void ready_urc_cb() + { + _state_machine->device_ready_cb(); + } + + CellularStateMachine * _state_machine; +}; +} + +TEST_F(TestCellularStateMachine, test_create_delete) +{ + UT_CellularStateMachine ut; + FileHandle_stub fh1; + + CellularDevice *dev = new myCellularDevice(&fh1); + EXPECT_TRUE(dev); + + CellularStateMachine *stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + ut.delete_state_machine(); + + delete dev; + dev = NULL; +} + +TEST_F(TestCellularStateMachine, test_setters) +{ + UT_CellularStateMachine ut; + FileHandle_stub fh1; + + CellularDevice *dev = new myCellularDevice(&fh1); + EXPECT_TRUE(dev); + + CellularStateMachine *stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + ut.set_cellular_callback(&cellular_callback); + + ut.set_sim_pin(NULL); + ut.set_sim_pin("1234"); + ut.set_plmn(NULL); + ut.set_plmn("12345"); + + uint16_t timeout[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + ut.set_retry_timeout_array(timeout, 10); // test max length + ut.set_retry_timeout_array(timeout, 20); // test too big array + ut.set_retry_timeout_array(0, 10); // null array + + ut.delete_state_machine(); + + delete dev; + dev = NULL; +} + +TEST_F(TestCellularStateMachine, test_start_dispatch) +{ + UT_CellularStateMachine ut; + FileHandle_stub fh1; + + CellularDevice *dev = new myCellularDevice(&fh1); + EXPECT_TRUE(dev); + + CellularStateMachine *stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + nsapi_error_t err = ut.start_dispatch(); + ASSERT_EQ(NSAPI_ERROR_OK, err); + ut.delete_state_machine(); + + Thread_stub::osStatus_value = osErrorNoMemory; + stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + err = ut.start_dispatch(); + ASSERT_EQ(NSAPI_ERROR_NO_MEMORY, err); + ut.delete_state_machine(); + + delete dev; + dev = NULL; +} + +TEST_F(TestCellularStateMachine, test_stop) +{ + UT_CellularStateMachine ut; + FileHandle_stub fh1; + + CellularDevice *dev = new AT_CellularDevice(&fh1); + EXPECT_TRUE(dev); + + CellularStateMachine *stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + + ut.stop(); // nothing created, run through + ut.delete_state_machine(); + + stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + nsapi_error_t err = ut.start_dispatch(); + ASSERT_EQ(NSAPI_ERROR_OK, err); + + ut.stop(); // thread is created, now stop will delete it + ut.delete_state_machine(); + + stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + err = ut.start_dispatch(); + ASSERT_EQ(NSAPI_ERROR_OK, err); + + ut.set_cellular_callback(&cellular_callback); + + struct equeue_event ptr; + equeue_stub.void_ptr = &ptr; + equeue_stub.call_cb_immediately = true; + + AT_CellularPower_stub::fail_counter = 1; + + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_power_on()); + + ut.stop(); // thread and power are created, now stop will delete them + ut.delete_state_machine(); + + stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + err = ut.start_dispatch(); + ASSERT_EQ(NSAPI_ERROR_OK, err); + + ut.set_cellular_callback(&cellular_callback); + AT_CellularPower_stub::fail_counter = 1; + + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); + + ut.stop(); // thread and network are created, now stop will delete them + ut.delete_state_machine(); + + delete dev; + dev = NULL; +} + +TEST_F(TestCellularStateMachine, test_run_to_state) +{ + UT_CellularStateMachine ut; + FileHandle_stub fh1; + + CellularDevice *dev = new AT_CellularDevice(&fh1); + EXPECT_TRUE(dev); + + CellularStateMachine *stm = ut.create_state_machine(*dev, *dev->get_queue()); + EXPECT_TRUE(stm); + + nsapi_error_t err = ut.start_dispatch(); + ASSERT_EQ(NSAPI_ERROR_OK, err); + + struct equeue_event ptr; + equeue_stub.void_ptr = 0; + equeue_stub.call_cb_immediately = false; + ASSERT_EQ(NSAPI_ERROR_NO_MEMORY, ut.run_to_power_on()); + ut.reset(); + + equeue_stub.void_ptr = &ptr; + equeue_stub.call_cb_immediately = true; + + ut.set_cellular_callback(&cellular_callback); + AT_CellularPower_stub::fail_counter = 0; + + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_power_on()); + UT_CellularState current_state; + UT_CellularState target_state; + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_POWER_ON, current_state); + ASSERT_EQ(UT_STATE_POWER_ON, target_state); + ut.reset(); + + AT_CellularPower_stub::set_at_fail_counter = 1; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, target_state); + ut.ready_urc_cb(); + ut.reset(); + + AT_CellularPower_stub::fail_counter = 1; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, target_state); + ut.reset(); + + AT_CellularPower_stub::fail_counter = 2; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, target_state); + ut.reset(); + + AT_CellularPower_stub::fail_counter = 3; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); + ASSERT_EQ(UT_STATE_DEVICE_READY, target_state); + ut.reset(); + + AT_CellularDevice_stub::init_module_failure_count = 1; + AT_CellularPower_stub::fail_counter = 0; + AT_CellularNetwork_stub::set_registration_urc_fail_counter = 4; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_sim_ready()); + (void) ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_SIM_PIN, current_state); + ASSERT_EQ(UT_STATE_SIM_PIN, target_state); + ut.reset(); + + AT_CellularDevice_stub::pin_needed = true; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_sim_ready()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_SIM_PIN, current_state); + ASSERT_EQ(UT_STATE_SIM_PIN, target_state); + ut.reset(); + + ut.set_sim_pin("1234"); + AT_CellularDevice_stub::pin_needed = true; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_sim_ready()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_SIM_PIN, current_state); + ASSERT_EQ(UT_STATE_SIM_PIN, target_state); + ut.reset(); + + ut.set_sim_pin("1234"); + AT_CellularDevice_stub::pin_needed = true; + AT_CellularDevice_stub::set_pin_failure_count = 1; + AT_CellularDevice_stub::get_sim_failure_count = 1; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_sim_ready()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_SIM_PIN, current_state); + ASSERT_EQ(UT_STATE_SIM_PIN, target_state); + ut.reset(); + + cell_callback_data_t data; + data.status_data = CellularNetwork::RegisteredHomeNetwork; + AT_CellularNetwork_stub::get_registration_params_fail_counter = 10; + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_registered()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_REGISTERING_NETWORK, current_state); + ASSERT_EQ(UT_STATE_REGISTERING_NETWORK, target_state); + ut.cellular_event_changed((nsapi_event_t)CellularRegistrationStatusChanged, (intptr_t)&data); + ut.reset(); + + // manual registering + ut.set_plmn("12345"); + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_registered()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_MANUAL_REGISTERING_NETWORK, current_state); + ASSERT_EQ(UT_STATE_MANUAL_REGISTERING_NETWORK, target_state); + ut.cellular_event_changed((nsapi_event_t)CellularRegistrationStatusChanged, (intptr_t)&data); + ut.reset(); + + ut.set_plmn(0); + ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_attached()); + (void)ut.get_current_status(current_state, target_state); + ASSERT_EQ(UT_STATE_ATTACHING_NETWORK, current_state); + ASSERT_EQ(UT_STATE_ATTACHING_NETWORK, target_state); + ut.reset(); + + ut.delete_state_machine(); + + delete dev; + dev = NULL; +} + + + + + diff --git a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake new file mode 100644 index 0000000000..d06dae2cff --- /dev/null +++ b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake @@ -0,0 +1,44 @@ + +#################### +# UNIT TESTS +#################### + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + /features/cellular/framework/device/cellularstatemachine + ../features/cellular/framework/device + ../features/cellular/framework/common +) + +# Source files +set(unittest-sources + ../features/cellular/framework/device/CellularStateMachine.cpp + ../features/cellular/framework/AT/ATHandler_factory.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp + stubs/FileHandle_stub.cpp + stubs/CellularDevice_stub.cpp + stubs/EventQueue_stub.cpp + stubs/mbed_assert_stub.c + stubs/UARTSerial_stub.cpp + stubs/SerialBase_stub.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularNetwork_stub.cpp + stubs/AT_CellularPower_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/AT_CellularContext_stub.cpp + stubs/AT_CellularDevice_stub.cpp + stubs/Semaphore_stub.cpp + stubs/NetworkInterface_stub.cpp + stubs/Thread_stub.cpp + stubs/Mutex_stub.cpp + stubs/EventQueue_stub.cpp + stubs/equeue_stub.c +) + +# defines +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMDMRTS=PTC0 -DMDMCTS=PTC1 -DMDMTXD=NC -DMDMRXD=NC -DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 -DCELLULAR_DEVICE=myCellularDevice -DDEVICE_SERIAL_FC=1") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMDMRTS=PTC0 -DMDMCTS=PTC1 -DMDMTXD=NC -DMDMRXD=NC -DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 -DCELLULAR_DEVICE=myCellularDevice -DDEVICE_SERIAL_FC=1") diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 77dc761dd5..6f17565e84 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -15,14 +15,24 @@ * limitations under the License. */ -#include "AT_CellularDevice.h" +#include "AT_CellularDevice_stub.h" #include "AT_CellularNetwork.h" +#include "AT_CellularPower.h" +#include "AT_CellularContext.h" #include "ATHandler.h" const int DEFAULT_AT_TIMEOUT = 1000; using namespace mbed; + +int AT_CellularDevice_stub::failure_count = 0; +nsapi_error_t AT_CellularDevice_stub::nsapi_error_value = 0; +int AT_CellularDevice_stub::init_module_failure_count = 0; +int AT_CellularDevice_stub::set_pin_failure_count = 0; +int AT_CellularDevice_stub::get_sim_failure_count = 0; +bool AT_CellularDevice_stub::pin_needed = false; + AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) @@ -31,6 +41,8 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _netw AT_CellularDevice::~AT_CellularDevice() { + delete _network; + delete _power; } ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) @@ -72,7 +84,7 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) CellularPower *AT_CellularDevice::open_power(FileHandle *fh) { - return NULL; + return new AT_CellularPower(*ATHandler::get_instance(fh, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on)); } CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) @@ -153,7 +165,11 @@ void AT_CellularDevice::modem_debug_on(bool on) nsapi_error_t AT_CellularDevice::is_ready() { - return NSAPI_ERROR_OK; + if (AT_CellularDevice_stub::init_module_failure_count) { + AT_CellularDevice_stub::init_module_failure_count--; + return NSAPI_ERROR_DEVICE_ERROR; + } + return AT_CellularDevice_stub::nsapi_error_value; } void AT_CellularDevice::set_ready_cb(mbed::Callback callback) @@ -167,25 +183,53 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti nsapi_error_t AT_CellularDevice::init() { - return NSAPI_ERROR_OK; + if (AT_CellularDevice_stub::init_module_failure_count) { + AT_CellularDevice_stub::init_module_failure_count--; + return NSAPI_ERROR_DEVICE_ERROR; + } + return AT_CellularDevice_stub::nsapi_error_value; } nsapi_error_t AT_CellularDevice::reset() { - return NSAPI_ERROR_OK; + if (AT_CellularDevice_stub::init_module_failure_count) { + AT_CellularDevice_stub::init_module_failure_count--; + return NSAPI_ERROR_DEVICE_ERROR; + } + return AT_CellularDevice_stub::nsapi_error_value; } nsapi_error_t AT_CellularDevice::shutdown() { - return NSAPI_ERROR_OK; + if (AT_CellularDevice_stub::init_module_failure_count) { + AT_CellularDevice_stub::init_module_failure_count--; + return NSAPI_ERROR_DEVICE_ERROR; + } + return AT_CellularDevice_stub::nsapi_error_value; } nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin) { - return NSAPI_ERROR_OK; + if (AT_CellularDevice_stub::set_pin_failure_count) { + AT_CellularDevice_stub::set_pin_failure_count--; + return NSAPI_ERROR_DEVICE_ERROR; + } + return AT_CellularDevice_stub::nsapi_error_value; } nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) { - return NSAPI_ERROR_OK; + if (AT_CellularDevice_stub::get_sim_failure_count) { + AT_CellularDevice_stub::get_sim_failure_count--; + return NSAPI_ERROR_DEVICE_ERROR; + } + + if (AT_CellularDevice_stub::pin_needed) { + AT_CellularDevice_stub::pin_needed = false; + state = SimStatePinNeeded; + } else { + state = SimStateReady; + } + + return AT_CellularDevice_stub::nsapi_error_value; } diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.h b/UNITTESTS/stubs/AT_CellularDevice_stub.h new file mode 100644 index 0000000000..696475d0df --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef AT_CELLULARDEVICE_STUB_H_ +#define AT_CELLULARDEVICE_STUB_H_ + +#include "AT_CellularDevice.h" + +namespace AT_CellularDevice_stub { +extern int failure_count; +extern nsapi_error_t nsapi_error_value; +extern int init_module_failure_count; +extern int set_pin_failure_count; +extern int get_sim_failure_count; +extern bool pin_needed; +} + + +#endif /* AT_CELLULARDEVICE_STUB_H_ */ diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp index 2666abde1c..899be2fb4c 100644 --- a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "AT_CellularNetwork.h" +#include "AT_CellularNetwork_stub.h" #include "CellularNetwork.h" #include "CellularUtil.h" #include "CellularLog.h" @@ -25,6 +25,13 @@ using namespace mbed; using namespace mbed_cellular_util; + + +nsapi_error_t AT_CellularNetwork_stub::nsapi_error_value = 0; +int AT_CellularNetwork_stub::fail_counter = 0; +int AT_CellularNetwork_stub::set_registration_urc_fail_counter = 0; +int AT_CellularNetwork_stub::get_registration_params_fail_counter = 0; + AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler) { } @@ -44,6 +51,10 @@ nsapi_connection_status_t AT_CellularNetwork::get_connection_status() const nsapi_error_t AT_CellularNetwork::set_registration_urc(RegistrationType type, bool urc_on) { + if (AT_CellularNetwork_stub::set_registration_urc_fail_counter) { + AT_CellularNetwork_stub::set_registration_urc_fail_counter--; + return NSAPI_ERROR_DEVICE_ERROR; + } return NSAPI_ERROR_OK; } @@ -60,6 +71,12 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn) nsapi_error_t AT_CellularNetwork::get_registration_params(RegistrationType type, registration_params_t ®_params) { + if (AT_CellularNetwork_stub::get_registration_params_fail_counter) { + AT_CellularNetwork_stub::get_registration_params_fail_counter--; + return NSAPI_ERROR_DEVICE_ERROR; + } + + reg_params._status = CellularNetwork::RegisteredHomeNetwork; return NSAPI_ERROR_OK; } @@ -143,7 +160,7 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam bool AT_CellularNetwork::is_active_context() { - return true; + return false; } nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.h b/UNITTESTS/stubs/AT_CellularNetwork_stub.h new file mode 100644 index 0000000000..7f8197c35a --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef AT_CELLULARNETWORK_STUB_H_ +#define AT_CELLULARNETWORK_STUB_H_ + +#include "AT_CellularNetwork.h" + +namespace AT_CellularNetwork_stub { +extern nsapi_error_t nsapi_error_value; +extern int fail_counter; +extern int set_registration_urc_fail_counter; +extern int get_registration_params_fail_counter; +} + + +#endif /* AT_CELLULARNETWORK_STUB_H_ */ diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp index 0076be2669..e599788765 100644 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -15,13 +15,17 @@ * limitations under the License. */ -#include "AT_CellularPower.h" +#include "AT_CellularPower_stub.h" #include "CellularUtil.h" #include "CellularLog.h" using namespace mbed_cellular_util; using namespace mbed; +nsapi_error_t AT_CellularPower_stub::nsapi_error_value = 0; +int AT_CellularPower_stub::fail_counter = 0; +int AT_CellularPower_stub::set_at_fail_counter = 0; + AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at) { } @@ -32,10 +36,18 @@ AT_CellularPower::~AT_CellularPower() nsapi_error_t AT_CellularPower::on() { - return NSAPI_ERROR_OK; + if (AT_CellularPower_stub::fail_counter) { + AT_CellularPower_stub::fail_counter--; + return NSAPI_ERROR_DEVICE_ERROR; + } + return AT_CellularPower_stub::nsapi_error_value; } nsapi_error_t AT_CellularPower::off() { - return NSAPI_ERROR_OK; + if (AT_CellularPower_stub::fail_counter) { + AT_CellularPower_stub::fail_counter--; + return NSAPI_ERROR_DEVICE_ERROR; + } + return AT_CellularPower_stub::nsapi_error_value; } diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.h b/UNITTESTS/stubs/AT_CellularPower_stub.h new file mode 100644 index 0000000000..1ef2def67b --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularPower_stub.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef AT_CELLULARPOWER_STUB_H_ +#define AT_CELLULARPOWER_STUB_H_ + +#include "AT_CellularPower.h" + +namespace AT_CellularPower_stub { +extern nsapi_error_t nsapi_error_value; +extern int fail_counter; +extern int set_at_fail_counter; +} + +#endif /* AT_CELLULARPOWER_STUB_H_ */ diff --git a/UNITTESTS/stubs/Thread_stub.cpp b/UNITTESTS/stubs/Thread_stub.cpp index 8eed1e7f2a..9ab4ebfafd 100644 --- a/UNITTESTS/stubs/Thread_stub.cpp +++ b/UNITTESTS/stubs/Thread_stub.cpp @@ -15,13 +15,31 @@ * limitations under the License. */ -#include "Thread.h" +#include "Thread_stub.h" -namespace rtos { +using namespace rtos; + +osStatus Thread_stub::osStatus_value = osOK; osStatus Thread::wait_until(uint64_t millisec) { return 0; } +osStatus Thread::terminate() +{ + return 0; +} + +osStatus Thread::start(mbed::Callback task) +{ + return Thread_stub::osStatus_value; +} + +void Thread::constructor(osPriority priority, uint32_t stack_size, unsigned char *stack_mem, const char *name) +{ +} + +Thread::~Thread() +{ } diff --git a/UNITTESTS/stubs/Thread_stub.h b/UNITTESTS/stubs/Thread_stub.h new file mode 100644 index 0000000000..be13fb841e --- /dev/null +++ b/UNITTESTS/stubs/Thread_stub.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef THREAD_STUB_H_ +#define THREAD_STUB_H_ + +#include "Thread.h" + +namespace Thread_stub { +extern osStatus osStatus_value; +} + +#endif /* THREAD_STUB_H_ */ diff --git a/UNITTESTS/target_h/cmsis_os2.h b/UNITTESTS/target_h/cmsis_os2.h index c45760f27b..66b1d2f061 100644 --- a/UNITTESTS/target_h/cmsis_os2.h +++ b/UNITTESTS/target_h/cmsis_os2.h @@ -24,7 +24,7 @@ typedef int32_t osStatus; #define osOK 0 - +#define osErrorNoMemory -5 //These are from cmsis_os2.h diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index d56c7912da..4998ad799e 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -85,6 +85,7 @@ void CellularStateMachine::reset() _plmn_network_found = false; _is_retry = false; _network_status = 0; + _target_state = STATE_INIT; enter_to_state(STATE_INIT); } @@ -526,8 +527,13 @@ void CellularStateMachine::continue_from_state(CellularState state) nsapi_error_t CellularStateMachine::run_to_state(CellularStateMachine::CellularState state) { _mutex.lock(); + + CellularState tmp_state = state; + if (_plmn && tmp_state == STATE_REGISTERING_NETWORK) { + tmp_state = STATE_MANUAL_REGISTERING_NETWORK; + } // call pre_event via queue so that it's in same thread and it's safe to decisions - int id = _queue.call_in(0, this, &CellularStateMachine::pre_event, state); + int id = _queue.call_in(0, this, &CellularStateMachine::pre_event, tmp_state); if (!id) { stop(); _mutex.unlock(); @@ -569,7 +575,11 @@ bool CellularStateMachine::get_current_status(CellularStateMachine::CellularStat _mutex.lock(); current_state = _state; target_state = _target_state; - is_running = _event_id != -1; + if (_event_id == -1 || _event_id == STM_STOPPED) { + is_running = false; + } else { + is_running = true; + } _mutex.unlock(); return is_running; } @@ -671,8 +681,12 @@ void CellularStateMachine::set_cellular_callback(mbed::Callback RETRY_ARRAY_SIZE ? RETRY_ARRAY_SIZE : array_len; for (int i = 0; i < _retry_array_length; i++) { diff --git a/features/cellular/framework/device/CellularStateMachine.h b/features/cellular/framework/device/CellularStateMachine.h index 7b4e7656af..9ac914d69a 100644 --- a/features/cellular/framework/device/CellularStateMachine.h +++ b/features/cellular/framework/device/CellularStateMachine.h @@ -99,7 +99,7 @@ private: * @param timeout timeout array using seconds * @param array_len length of the array */ - void set_retry_timeout_array(uint16_t *timeout, int array_len); + void set_retry_timeout_array(const uint16_t timeout[], int array_len); /** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic * registering is used when registering to a cellular network. Does not start any operations. From 84e5013a2d8322c70b19e2e16e55115ab82a57bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Tue, 4 Dec 2018 14:58:59 +0200 Subject: [PATCH 23/41] Cellular: added setting of data carrier support for UART. --- .../AT/at_cellularcontext/unittest.cmake | 2 + UNITTESTS/stubs/AT_CellularContext_stub.cpp | 8 +++ UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 7 ++- UNITTESTS/target_h/myCellularDevice.h | 6 ++ .../cellular/framework/API/CellularContext.h | 21 ++++++- .../cellular/framework/API/CellularDevice.h | 22 ++++++++ features/cellular/framework/AT/ATHandler.cpp | 4 ++ .../framework/AT/AT_CellularContext.cpp | 56 +++++++++++++++---- .../framework/AT/AT_CellularContext.h | 3 + .../framework/AT/AT_CellularDevice.cpp | 11 ++++ .../cellular/framework/AT/AT_CellularDevice.h | 2 + .../framework/device/CellularContext.cpp | 3 + .../framework/device/CellularDevice.cpp | 7 ++- 13 files changed, 137 insertions(+), 15 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake index 5d36efe270..7470c4ecf0 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake @@ -38,4 +38,6 @@ set(unittest-test-sources stubs/randLIB_stub.cpp stubs/Semaphore_stub.cpp stubs/us_ticker_stub.cpp + stubs/UARTSerial_stub.cpp + stubs/SerialBase_stub.cpp ) diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index c1f70ad3fb..38b8dda130 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -42,6 +42,14 @@ AT_CellularContext::~AT_CellularContext() { } +void AT_CellularContext::set_file_handle(UARTSerial *serial, PinName dcd_pin, bool active_high) +{ +} + +void AT_CellularContext::enable_hup(bool enable) +{ +} + void AT_CellularContext::set_file_handle(FileHandle *fh) { } diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 6f17565e84..a203de3703 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -64,7 +64,12 @@ nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler) } } -CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) +CellularContext *AT_CellularDevice::create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin, + bool active_high) +{ +} + +CellularContext *create_context(FileHandle *fh, const char *apn) { } diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 301f2a1466..f0b2e09a01 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -52,6 +52,12 @@ public: return NSAPI_ERROR_OK; } + virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin, + bool active_high) + { + return NULL; + } + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) { EventQueue que; diff --git a/features/cellular/framework/API/CellularContext.h b/features/cellular/framework/API/CellularContext.h index 44bd4ec581..14afdfd145 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -107,7 +107,6 @@ protected: // friend of CellularDevice, so it's the only way to close or delete this class. friend class CellularDevice; virtual ~CellularContext() {} - public: // from NetworkInterface virtual nsapi_error_t set_blocking(bool blocking) = 0; virtual NetworkStack *get_stack() = 0; @@ -227,6 +226,15 @@ public: // from NetworkInterface */ virtual void set_file_handle(FileHandle *fh) = 0; + /** Set the UART serial used to communicate with the modem. Can be used to change default file handle. + * File handle set with this method will use data carrier detect to be able to detect disconnection much faster in PPP mode. + * + * @param serial UARTSerial used in communication to modem. If null then the default file handle is used. + * @param dcd_pin Pin used to set data carrier detect on/off for the given UART + * @param active_high a boolean set to true if DCD polarity is active low + */ + virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false) = 0; + protected: // Device specific implementations might need these so protected enum ContextOperation { OP_INVALID = -1, @@ -245,6 +253,15 @@ protected: // Device specific implementations might need these so protected */ virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr) = 0; + /** Enable or disable hang-up detection + * + * When in PPP data pump mode, it is helpful if the FileHandle will signal hang-up via + * POLLHUP, e.g., if the DCD line is deasserted on a UART. During command mode, this + * signaling is not desired. enable_hup() controls whether this function should be + * active. + */ + virtual void enable_hup(bool enable) = 0; + // member variables needed in target override methods NetworkStack *_stack; // must be pointer because of PPP nsapi_ip_stack_t _ip_stack_type; @@ -259,6 +276,8 @@ protected: // Device specific implementations might need these so protected const char *_apn; const char *_uname; const char *_pwd; + PinName _dcd_pin; + bool _active_high; }; /** diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 35c46eb27e..9d7d5730c8 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -22,6 +22,7 @@ #include "CellularStateMachine.h" #include "Callback.h" #include "ATHandler.h" +#include "UARTSerial.h" namespace mbed { @@ -102,6 +103,21 @@ public: */ virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) = 0; + /** Creates a new CellularContext interface. This API should be used if serial is UART and PPP mode used. + * CellularContext created will use data carrier detect to be able to detect disconnection much faster in PPP mode. + * UARTSerial usually is the same which was given for the CellularDevice. + * + * @param serial UARTSerial used in communication to modem. If null then the default file handle is used. + * @param apn access point to use with context, can be null. + * @param dcd_pin Pin used to set data carrier detect on/off for the given UART + * @param active_high a boolean set to true if DCD polarity is active low + * + * @return new instance of class CellularContext or NULL in case of failure + * + */ + virtual CellularContext *create_context(UARTSerial *serial, const char *apn, PinName dcd_pin = NC, + bool active_high = false) = 0; + /** Deletes the given CellularContext instance * * @param context CellularContext to delete @@ -113,6 +129,12 @@ public: */ void stop(); + /** Get the current FileHandle item used when communicating with the modem. + * + * @return reference to FileHandle + */ + FileHandle &get_file_handle() const; + /** Get event queue that can be chained to main event queue. * @return event queue */ diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index 4371f4ddaa..5144f37757 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -154,6 +154,10 @@ void ATHandler::set_file_handle(FileHandle *fh) void ATHandler::set_is_filehandle_usable(bool usable) { _is_fh_usable = usable; + if (usable) { + // set file handle sigio and blocking mode back + set_file_handle(_fileHandle); + } } void ATHandler::set_urc_handler(const char *prefix, Callback callback) diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index b2ab6ca8ca..46302d38e5 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -59,11 +59,13 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co _cid = -1; _new_context_set = false; _next = NULL; + _dcd_pin = NC; + _active_high = false; } AT_CellularContext::~AT_CellularContext() { - tr_info("Delete CellularContext %s (%p)", _apn ? _apn : "", this); + tr_info("Delete CellularContext with apn: [%s] (%p)", _apn ? _apn : "", this); (void)disconnect(); @@ -79,6 +81,23 @@ void AT_CellularContext::set_file_handle(FileHandle *fh) _at.set_file_handle(_fh); } +void AT_CellularContext::set_file_handle(UARTSerial *serial, PinName dcd_pin, bool active_high) +{ + tr_info("CellularContext serial %p", serial); + _dcd_pin = dcd_pin; + _active_high = active_high; + _fh = serial; + _at.set_file_handle(static_cast(serial)); + enable_hup(false); +} + +void AT_CellularContext::enable_hup(bool enable) +{ + if (_dcd_pin != NC) { + static_cast(_fh)->set_data_carrier_detect(enable ? _dcd_pin : NC, _active_high); + } +} + nsapi_error_t AT_CellularContext::connect() { tr_info("CellularContext connect"); @@ -595,11 +614,16 @@ nsapi_error_t AT_CellularContext::open_data_channel() } _at.set_is_filehandle_usable(false); - + enable_hup(true); /* Initialize PPP * If blocking: mbed_ppp_init() is a blocking call, it will block until connected, or timeout after 30 seconds*/ - return nsapi_ppp_connect(_at.get_file_handle(), callback(this, &AT_CellularContext::ppp_status_cb), _uname, _pwd, _ip_stack_type); + nsapi_error_t err = nsapi_ppp_connect(_at.get_file_handle(), callback(this, &AT_CellularContext::ppp_status_cb), _uname, _pwd, _ip_stack_type); + if (err) { + ppp_disconnected(); + } + + return err; } void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr) @@ -607,6 +631,8 @@ void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr) tr_debug("ppp_status_cb: event %d, ptr %d", ev, ptr); if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) { _is_connected = true; + } else if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) { + ppp_disconnected(); } else { _is_connected = false; } @@ -617,6 +643,20 @@ void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr) _device->cellular_callback(ev, ptr); } +void AT_CellularContext::ppp_disconnected() +{ + enable_hup(false); + + // after ppp disconnect if we wan't to use same at handler we need to set filehandle again to athandler so it + // will set the correct sigio and nonblocking + _at.lock(); + _at.set_is_filehandle_usable(true); + if (!_at.sync(AT_SYNC_TIMEOUT)) { // consume extra characters after ppp disconnect, also it may take a while until modem listens AT commands + tr_error("AT sync failed after PPP Disconnect"); + } + _at.unlock(); +} + #endif //#if NSAPI_PPP_AVAILABLE nsapi_error_t AT_CellularContext::disconnect() @@ -631,15 +671,7 @@ nsapi_error_t AT_CellularContext::disconnect() tr_error("CellularContext disconnect failed!"); // continue even in failure due to ppp disconnect in any case releases filehandle } - // after ppp disconnect if we wan't to use same at handler we need to set filehandle again to athandler so it - // will set the correct sigio and nonblocking - _at.lock(); - _at.set_file_handle(_at.get_file_handle()); - _at.set_is_filehandle_usable(true); - if (!_at.sync(AT_SYNC_TIMEOUT)) { // consume extra characters after ppp disconnect, also it may take a while until modem listens AT commands - tr_error("AT sync failed after PPP Disconnect"); - } - _at.unlock(); + ppp_disconnected(); #endif // NSAPI_PPP_AVAILABLE _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index dc59f69c65..4a671cabe2 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -57,6 +57,8 @@ public: virtual nsapi_error_t register_to_network(); virtual nsapi_error_t attach_to_network(); virtual void set_file_handle(FileHandle *fh); + virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false); + virtual void enable_hup(bool enable); protected: virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr); @@ -93,6 +95,7 @@ private: #if NSAPI_PPP_AVAILABLE nsapi_error_t open_data_channel(); void ppp_status_cb(nsapi_event_t ev, intptr_t ptr); + void ppp_disconnected(); #endif // #if NSAPI_PPP_AVAILABLE nsapi_error_t do_activate_context(); bool set_new_context(int cid); diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index b60673ae17..30b8fbcc2c 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -167,6 +167,17 @@ CellularContext *AT_CellularDevice::get_context_list() const return _context_list; } +CellularContext *AT_CellularDevice::create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin, + bool active_high) +{ + // Call FileHandle base version - explict upcast to avoid recursing into ourselves + CellularContext *ctx = create_context(static_cast(serial), apn); + if (serial) { + ctx->set_file_handle(serial, dcd_pin, active_high); + } + return ctx; +} + CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn) { AT_CellularContext *ctx = create_context_impl(*get_at_handler(fh), apn); diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 1412676461..c2343b47c2 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -46,6 +46,8 @@ public: virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL); + virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin = NC, bool active_high = false); + virtual void delete_context(CellularContext *context); virtual CellularNetwork *open_network(FileHandle *fh = NULL); diff --git a/features/cellular/framework/device/CellularContext.cpp b/features/cellular/framework/device/CellularContext.cpp index 64dfc7f13a..a134e28a17 100644 --- a/features/cellular/framework/device/CellularContext.cpp +++ b/features/cellular/framework/device/CellularContext.cpp @@ -26,6 +26,9 @@ MBED_WEAK CellularContext *CellularContext::get_default_instance() return NULL; } static CellularContext *context = dev->create_context(); +#if defined(MDMDCD) && defined(MDM_PIN_POLARITY) + context->set_file_handle(static_cast(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY); +#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY) return context; } #else diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index 305556d273..a886f5eb3d 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -21,7 +21,6 @@ #include "CellularLog.h" #include "CellularTargets.h" #include "EventQueue.h" -#include "UARTSerial.h" #ifdef CELLULAR_DEVICE #include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) @@ -52,6 +51,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance() CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0) { + MBED_ASSERT(fh); set_sim_pin(NULL); set_plmn(NULL); } @@ -66,6 +66,11 @@ void CellularDevice::stop() _state_machine->stop(); } +FileHandle &CellularDevice::get_file_handle() const +{ + return *_fh; +} + events::EventQueue *CellularDevice::get_queue() { return &_queue; From d301e13610fd6c7429d826615c3906f4be5941a0 Mon Sep 17 00:00:00 2001 From: Mirela Chirica Date: Fri, 16 Nov 2018 09:40:38 +0200 Subject: [PATCH 24/41] Cellular: Non-IP socket and PDP context for EPS control plane data delivery --- .../AT/at_cellularcontext/unittest.cmake | 1 + .../AT/at_cellulardevice/unittest.cmake | 1 + .../device/cellulardevice/unittest.cmake | 1 + .../cellularstatemachine/unittest.cmake | 1 + UNITTESTS/stubs/AT_CellularBase_stub.cpp | 2 + UNITTESTS/stubs/AT_CellularContext_stub.cpp | 59 +++- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 6 +- UNITTESTS/stubs/CellularDevice_stub.cpp | 3 + UNITTESTS/target_h/myCellularDevice.h | 4 +- .../cellular/framework/API/CellularContext.h | 16 +- .../cellular/framework/API/CellularDevice.h | 8 +- .../cellular/framework/AT/AT_CellularBase.h | 7 +- .../framework/AT/AT_CellularContext.cpp | 304 +++++++++++------- .../framework/AT/AT_CellularContext.h | 32 +- .../framework/AT/AT_CellularDevice.cpp | 15 +- .../cellular/framework/AT/AT_CellularDevice.h | 6 +- .../framework/AT/AT_ControlPlane_netif.cpp | 77 +++++ .../framework/AT/AT_ControlPlane_netif.h | 32 ++ .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 4 +- .../GEMALTO/CINTERION/GEMALTO_CINTERION.h | 2 +- .../GEMALTO_CINTERION_CellularContext.cpp | 10 +- .../GEMALTO_CINTERION_CellularContext.h | 2 +- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 4 +- .../targets/QUECTEL/BC95/QUECTEL_BC95.h | 2 +- .../BC95/QUECTEL_BC95_CellularContext.cpp | 12 +- .../BC95/QUECTEL_BC95_CellularContext.h | 2 +- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 5 +- .../targets/QUECTEL/BG96/QUECTEL_BG96.h | 2 +- .../BG96/QUECTEL_BG96_CellularContext.cpp | 143 +++++++- .../BG96/QUECTEL_BG96_CellularContext.h | 12 +- .../BG96/QUECTEL_BG96_ControlPlane_netif.cpp | 68 ++++ .../BG96/QUECTEL_BG96_ControlPlane_netif.h | 36 +++ .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 4 +- .../targets/QUECTEL/UG96/QUECTEL_UG96.h | 2 +- .../UG96/QUECTEL_UG96_CellularContext.cpp | 4 +- .../UG96/QUECTEL_UG96_CellularContext.h | 2 +- .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 4 +- .../framework/targets/UBLOX/AT/UBLOX_AT.h | 2 +- .../UBLOX/AT/UBLOX_AT_CellularContext.cpp | 14 +- .../UBLOX/AT/UBLOX_AT_CellularContext.h | 2 +- .../cellular/CellularNonIPSocket.cpp | 267 +++++++++++++++ .../netsocket/cellular/CellularNonIPSocket.h | 150 +++++++++ .../netsocket/cellular/ControlPlane_netif.h | 78 +++++ 43 files changed, 1212 insertions(+), 196 deletions(-) create mode 100644 features/cellular/framework/AT/AT_ControlPlane_netif.cpp create mode 100644 features/cellular/framework/AT/AT_ControlPlane_netif.h create mode 100644 features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp create mode 100644 features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.h create mode 100644 features/netsocket/cellular/CellularNonIPSocket.cpp create mode 100644 features/netsocket/cellular/CellularNonIPSocket.h create mode 100644 features/netsocket/cellular/ControlPlane_netif.h diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake index 7470c4ecf0..2192536f6e 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake @@ -9,6 +9,7 @@ set(unittest-includes ${unittest-includes} ../features/cellular/framework/common ../features/cellular/framework/AT ../features/cellular/framework/device + ../features/netsocket/cellular ) # Source files diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake index 92af9005b6..e1b50a9eb6 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake @@ -12,6 +12,7 @@ set(unittest-includes ${unittest-includes} ../features/frameworks/mbed-client-randlib/mbed-client-randlib ../drivers ../hal + ../features/netsocket/cellular ) # Source files diff --git a/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake index 7da80e97b1..0e9bb23427 100644 --- a/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake @@ -8,6 +8,7 @@ set(unittest-includes ${unittest-includes} /features/cellular/framework/device/cellulardevice ../features/cellular/framework/device ../features/cellular/framework/common + ../features/netsocket/cellular ) # Source files diff --git a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake index d06dae2cff..00e5674448 100644 --- a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake @@ -8,6 +8,7 @@ set(unittest-includes ${unittest-includes} /features/cellular/framework/device/cellularstatemachine ../features/cellular/framework/device ../features/cellular/framework/common + ../features/netsocket/cellular ) # Source files diff --git a/UNITTESTS/stubs/AT_CellularBase_stub.cpp b/UNITTESTS/stubs/AT_CellularBase_stub.cpp index 3d7c9265ac..d4b1369418 100644 --- a/UNITTESTS/stubs/AT_CellularBase_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularBase_stub.cpp @@ -49,6 +49,8 @@ intptr_t AT_CellularBase::get_property(CellularProperty key) return AT_CellularNetwork::RegistrationModeEnable; } else if (key == PROPERTY_AT_CGAUTH) { return true; + } else if (key == PROPERTY_IPV4_PDP_TYPE) { + return true; } return AT_CellularBase_stub::supported_bool; diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index 38b8dda130..f9ab4d83ca 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -19,12 +19,12 @@ using namespace mbed; -AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true), - _current_op(OP_INVALID), _device(device), _nw(0), _fh(0) +AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : + AT_CellularBase(at), _is_blocking(true), _is_connected(false), + _current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false), _cp_netif(NULL) { _stack = NULL; - _ip_stack_type = DEFAULT_STACK; + _pdp_type = DEFAULT_PDP_TYPE; _authentication_type = CellularContext::CHAP; _connect_status = NSAPI_STATUS_DISCONNECTED; _is_context_active = false; @@ -143,25 +143,23 @@ const char *AT_CellularContext::get_gateway() return NULL; } -AT_CellularBase::CellularProperty AT_CellularContext::nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack) +AT_CellularBase::CellularProperty AT_CellularContext::pdp_type_t_to_cellular_property(pdp_type_t pdp_type) { - AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_STACK; - if (stack == IPV6_STACK) { - prop = PROPERTY_IPV6_STACK; - } else if (stack == IPV4V6_STACK) { - prop = PROPERTY_IPV4V6_STACK; + AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_PDP_TYPE; + if (pdp_type == IPV6_PDP_TYPE) { + prop = PROPERTY_IPV6_PDP_TYPE; + } else if (pdp_type == IPV4V6_PDP_TYPE) { + prop = PROPERTY_IPV4V6_PDP_TYPE; + } else if (pdp_type == NON_IP_PDP_TYPE) { + prop = PROPERTY_NON_IP_PDP_TYPE; } + return prop; } -nsapi_ip_stack_t AT_CellularContext::get_stack_type() +pdp_type_t AT_CellularContext::string_to_pdp_type(const char *pdp_type) { - return IPV4V6_STACK; -} - -nsapi_ip_stack_t AT_CellularContext::string_to_stack_type(const char *pdp_type) -{ - return IPV4V6_STACK; + return IPV4V6_PDP_TYPE; } // PDP Context handling @@ -236,3 +234,30 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) void AT_CellularContext::call_network_cb(nsapi_connection_status_t status) { } + +ControlPlane_netif *AT_CellularContext::get_cp_netif() +{ + return NULL; +} + +nsapi_error_t AT_CellularContext::activate_non_ip_context() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularContext::setup_control_plane_opt() +{ + return NSAPI_ERROR_OK; +} + +void AT_CellularContext::deactivate_ip_context() +{ +} + +void AT_CellularContext::deactivate_non_ip_context() +{ +} + +void AT_CellularContext::set_disconnect() +{ +} diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index a203de3703..e5665199b4 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -65,7 +65,7 @@ nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler) } CellularContext *AT_CellularDevice::create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin, - bool active_high) + bool active_high, bool cp_req, bool nonip_req) { } @@ -118,12 +118,12 @@ CellularContext *AT_CellularDevice::get_context_list() const return NULL; } -CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn) +CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn, bool cp_req, bool nonip_req) { return NULL; } -AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn) +AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { return NULL; } diff --git a/UNITTESTS/stubs/CellularDevice_stub.cpp b/UNITTESTS/stubs/CellularDevice_stub.cpp index 6d8943382f..433dd47b08 100644 --- a/UNITTESTS/stubs/CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/CellularDevice_stub.cpp @@ -103,3 +103,6 @@ nsapi_error_t CellularDevice::shutdown() return NSAPI_ERROR_OK; } +void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr) +{ +} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index f0b2e09a01..6c4292a67d 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -53,12 +53,12 @@ public: } virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin, - bool active_high) + bool active_high, bool cp_req = false, bool nonip_req = false) { return NULL; } - virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false) { EventQueue que; FileHandle_stub fh1; diff --git a/features/cellular/framework/API/CellularContext.h b/features/cellular/framework/API/CellularContext.h index 14afdfd145..6699b8e749 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -19,9 +19,18 @@ #include "CellularBase.h" #include "CellularDevice.h" +#include "ControlPlane_netif.h" namespace mbed { +typedef enum pdp_type { + DEFAULT_PDP_TYPE = DEFAULT_STACK, + IPV4_PDP_TYPE = IPV4_STACK, + IPV6_PDP_TYPE = IPV6_STACK, + IPV4V6_PDP_TYPE = IPV4V6_STACK, + NON_IP_PDP_TYPE +} pdp_type_t; + /** * @addtogroup cellular * @{ @@ -31,6 +40,7 @@ namespace mbed { class CellularContext : public CellularBase { public: + // max simultaneous PDP contexts active static const int PDP_CONTEXT_COUNT = 4; @@ -235,6 +245,10 @@ public: // from NetworkInterface */ virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false) = 0; + /** Returns the control plane AT command interface + */ + virtual ControlPlane_netif *get_cp_netif() = 0; + protected: // Device specific implementations might need these so protected enum ContextOperation { OP_INVALID = -1, @@ -264,7 +278,7 @@ protected: // Device specific implementations might need these so protected // member variables needed in target override methods NetworkStack *_stack; // must be pointer because of PPP - nsapi_ip_stack_t _ip_stack_type; + pdp_type_t _pdp_type; CellularContext::AuthenticationType _authentication_type; nsapi_connection_status_t _connect_status; cell_callback_data_t _cb_data; diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 9d7d5730c8..cb32511fbc 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -97,11 +97,13 @@ public: * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default * file handle is used. * @param apn access point to use with context, can be null. + * @param cp_req flag indicating if EPS control plane optimisation is required + * @param nonip_req flag indicating if this context is required to be Non-IP * * @return new instance of class CellularContext or NULL in case of failure * */ - virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) = 0; + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false) = 0; /** Creates a new CellularContext interface. This API should be used if serial is UART and PPP mode used. * CellularContext created will use data carrier detect to be able to detect disconnection much faster in PPP mode. @@ -111,12 +113,14 @@ public: * @param apn access point to use with context, can be null. * @param dcd_pin Pin used to set data carrier detect on/off for the given UART * @param active_high a boolean set to true if DCD polarity is active low + * @param cp_req Flag indicating if EPS control plane optimisation is required + * @param nonip_req Flag indicating if this context is required to be Non-IP * * @return new instance of class CellularContext or NULL in case of failure * */ virtual CellularContext *create_context(UARTSerial *serial, const char *apn, PinName dcd_pin = NC, - bool active_high = false) = 0; + bool active_high = false, bool cp_req = false, bool nonip_req = false) = 0; /** Deletes the given CellularContext instance * diff --git a/features/cellular/framework/AT/AT_CellularBase.h b/features/cellular/framework/AT/AT_CellularBase.h index 489949fe06..4a993f4066 100644 --- a/features/cellular/framework/AT/AT_CellularBase.h +++ b/features/cellular/framework/AT/AT_CellularBase.h @@ -49,9 +49,10 @@ public: PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported - PROPERTY_IPV4_STACK, // 0 = not supported, 1 = supported. Does modem support IPV4? - PROPERTY_IPV6_STACK, // 0 = not supported, 1 = supported. Does modem support IPV6? - PROPERTY_IPV4V6_STACK, // 0 = not supported, 1 = supported. Does modem support dual stack IPV4V6? + PROPERTY_IPV4_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV4? + PROPERTY_IPV6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV6? + PROPERTY_IPV4V6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support dual stack IPV4V6? + PROPERTY_NON_IP_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support Non-IP? PROPERTY_MAX }; diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 46302d38e5..6947d6bdce 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -25,6 +25,9 @@ #define NETWORK_TIMEOUT 30 * 60 * 1000 // 30 minutes #define DEVICE_TIMEOUT 5 * 60 * 1000 // 5 minutes +// Timeout to wait for URC indicating ciot optimization support from network +#define CP_OPT_NW_REPLY_TIMEOUT 3000 // 3 seconds + #if NSAPI_PPP_AVAILABLE #define AT_SYNC_TIMEOUT 1000 // 1 second timeout @@ -41,13 +44,13 @@ using namespace mbed_cellular_util; using namespace mbed; -AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true), - _current_op(OP_INVALID), _device(device), _nw(0), _fh(0) +AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : + AT_CellularBase(at), _is_connected(false), _is_blocking(true), + _current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false), _cp_netif(NULL) { tr_info("New CellularContext %s (%p)", apn ? apn : "", this); _stack = NULL; - _ip_stack_type = DEFAULT_STACK; + _pdp_type = DEFAULT_PDP_TYPE; _authentication_type = CellularContext::CHAP; _connect_status = NSAPI_STATUS_DISCONNECTED; _is_context_active = false; @@ -258,24 +261,21 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con _pwd = pwd; } -nsapi_ip_stack_t AT_CellularContext::get_stack_type() +pdp_type_t AT_CellularContext::string_to_pdp_type(const char *pdp_type_str) { - return _ip_stack_type; -} + pdp_type_t pdp_type = DEFAULT_PDP_TYPE; + int len = strlen(pdp_type_str); -nsapi_ip_stack_t AT_CellularContext::string_to_stack_type(const char *pdp_type) -{ - nsapi_ip_stack_t stack = DEFAULT_STACK; - int len = strlen(pdp_type); - - if (len == 6 && memcmp(pdp_type, "IPV4V6", len) == 0) { - stack = IPV4V6_STACK; - } else if (len == 4 && memcmp(pdp_type, "IPV6", len) == 0) { - stack = IPV6_STACK; - } else if (len == 2 && memcmp(pdp_type, "IP", len) == 0) { - stack = IPV4_STACK; + if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) { + pdp_type = IPV4V6_PDP_TYPE; + } else if (len == 4 && memcmp(pdp_type_str, "IPV6", len) == 0) { + pdp_type = IPV6_PDP_TYPE; + } else if (len == 2 && memcmp(pdp_type_str, "IP", len) == 0) { + pdp_type = IPV4_PDP_TYPE; + } else if (len == 6 && memcmp(pdp_type_str, "Non-IP", len) == 0) { + pdp_type = NON_IP_PDP_TYPE; } - return stack; + return pdp_type; } // PDP Context handling @@ -316,19 +316,24 @@ nsapi_error_t AT_CellularContext::do_user_authentication() return NSAPI_ERROR_OK; } -AT_CellularBase::CellularProperty AT_CellularContext::nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack) +AT_CellularBase::CellularProperty AT_CellularContext::pdp_type_t_to_cellular_property(pdp_type_t pdp_type) { - AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_STACK; - if (stack == IPV6_STACK) { - prop = PROPERTY_IPV6_STACK; - } else if (stack == IPV4V6_STACK) { - prop = PROPERTY_IPV4V6_STACK; + AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_PDP_TYPE; + if (pdp_type == IPV6_PDP_TYPE) { + prop = PROPERTY_IPV6_PDP_TYPE; + } else if (pdp_type == IPV4V6_PDP_TYPE) { + prop = PROPERTY_IPV4V6_PDP_TYPE; + } else if (pdp_type == NON_IP_PDP_TYPE) { + prop = PROPERTY_NON_IP_PDP_TYPE; } + return prop; } bool AT_CellularContext::get_context() { + bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_PDP_TYPE); + bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_PDP_TYPE); _at.cmd_start("AT+CGDCONT?"); _at.cmd_stop(); _at.resp_start("+CGDCONT:"); @@ -337,9 +342,6 @@ bool AT_CellularContext::get_context() char apn[MAX_ACCESSPOINT_NAME_LENGTH]; int apn_len = 0; - bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_STACK); - bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_STACK); - while (_at.info_resp()) { int cid = _at.read_int(); if (cid > cid_max) { @@ -353,52 +355,20 @@ bool AT_CellularContext::get_context() if (_apn && (strcmp(apn, _apn) != 0)) { continue; } - nsapi_ip_stack_t pdp_stack = string_to_stack_type(pdp_type_from_context); - // Accept dual PDP context for IPv4/IPv6 only modems - if (pdp_stack != DEFAULT_STACK && (get_property(nsapi_ip_stack_t_to_cellular_property(pdp_stack)) - || pdp_stack == IPV4V6_STACK)) { - if (_ip_stack_type_requested == IPV4_STACK) { - if (pdp_stack == IPV4_STACK || pdp_stack == IPV4V6_STACK) { - _ip_stack_type = _ip_stack_type_requested; - _cid = cid; - break; - } - } else if (_ip_stack_type_requested == IPV6_STACK) { - if (pdp_stack == IPV6_STACK || pdp_stack == IPV4V6_STACK) { - _ip_stack_type = _ip_stack_type_requested; - _cid = cid; - break; - } - } else { - // requested dual stack or stack is not specified - // If dual PDP need to check for IPV4 or IPV6 modem support. Prefer IPv6. - if (pdp_stack == IPV4V6_STACK) { - if (modem_supports_ipv6) { - _ip_stack_type = IPV6_STACK; - _cid = cid; - break; - } else if (modem_supports_ipv4) { - _ip_stack_type = IPV4_STACK; - _cid = cid; - break; - } - // If PDP is IPV4 or IPV6 they are already checked if supported - } else { - _ip_stack_type = pdp_stack; - _cid = cid; - if (pdp_stack == IPV6_STACK) { - break; - } - if (pdp_stack == IPV4_STACK && !modem_supports_ipv6) { - break; - } + // APN matched -> Check PDP type + pdp_type_t pdp_type = string_to_pdp_type(pdp_type_from_context); + + // Accept exact matching PDP context type or dual PDP context for IPv4/IPv6 only modems + if (get_property(pdp_type_t_to_cellular_property(pdp_type)) || + ((pdp_type == IPV4V6_PDP_TYPE && (modem_supports_ipv4 || modem_supports_ipv6)) && !_nonip_req)) { + _pdp_type = pdp_type; + _cid = cid; } - } - } - } - } + } + } } + _at.resp_stop(); if (_cid == -1) { // no suitable context was found so create a new one if (!set_new_context(cid_max + 1)) { @@ -418,75 +388,77 @@ bool AT_CellularContext::get_context() bool AT_CellularContext::set_new_context(int cid) { - nsapi_ip_stack_t tmp_stack = _ip_stack_type_requested; + bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_PDP_TYPE); + bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_PDP_TYPE); + bool modem_supports_nonip = get_property(PROPERTY_NON_IP_PDP_TYPE); - if (tmp_stack == DEFAULT_STACK) { - bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_STACK); - bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_STACK); + char pdp_type_str[8 + 1] = {0}; + pdp_type_t pdp_type = IPV4_PDP_TYPE; - if (modem_supports_ipv6 && modem_supports_ipv4) { - tmp_stack = IPV4V6_STACK; + if (_nonip_req && _cp_in_use && modem_supports_nonip) { + strncpy(pdp_type_str, "Non-IP", sizeof(pdp_type_str)); + pdp_type = NON_IP_PDP_TYPE; + } else if (modem_supports_ipv6 && modem_supports_ipv4) { + strncpy(pdp_type_str, "IPV4V6", sizeof(pdp_type_str)); + pdp_type = IPV4V6_PDP_TYPE; } else if (modem_supports_ipv6) { - tmp_stack = IPV6_STACK; + strncpy(pdp_type_str, "IPV6", sizeof(pdp_type_str)); + pdp_type = IPV6_PDP_TYPE; } else if (modem_supports_ipv4) { - tmp_stack = IPV4_STACK; + strncpy(pdp_type_str, "IP", sizeof(pdp_type)); + pdp_type = IPV4_PDP_TYPE; + } else { + return false; } - } - - char pdp_type[8 + 1] = {0}; - - switch (tmp_stack) { - case IPV4_STACK: - strncpy(pdp_type, "IP", sizeof(pdp_type)); - break; - case IPV6_STACK: - strncpy(pdp_type, "IPV6", sizeof(pdp_type)); - break; - case IPV4V6_STACK: - strncpy(pdp_type, "IPV6", sizeof(pdp_type)); // try first IPV6 and then fall-back to IPv4 - break; - default: - break; - } //apn: "If the value is null or omitted, then the subscription value will be requested." bool success = false; _at.cmd_start("AT+CGDCONT="); _at.write_int(cid); - _at.write_string(pdp_type); + _at.write_string(pdp_type_str); _at.write_string(_apn); _at.cmd_stop_read_resp(); success = (_at.get_last_error() == NSAPI_ERROR_OK); - // Fall back to ipv4 - if (!success && tmp_stack == IPV4V6_STACK) { - _at.clear_error(); - tmp_stack = IPV4_STACK; - _at.cmd_start("AT+FCLASS=0;+CGDCONT="); - _at.write_int(cid); - _at.write_string("IP"); - _at.write_string(_apn); - _at.cmd_stop_read_resp(); - success = (_at.get_last_error() == NSAPI_ERROR_OK); - } - if (success) { - _ip_stack_type = tmp_stack; + _pdp_type = pdp_type; _cid = cid; _new_context_set = true; - tr_info("New PDP context %d, stack %s", _cid, pdp_type); + tr_info("New PDP context %d, type %s", _cid, pdp_type); } return success; } nsapi_error_t AT_CellularContext::do_activate_context() +{ + if (_nonip_req && _cp_in_use) { + return activate_non_ip_context(); + } + + // In IP case but also when Non-IP is requested and + // control plane optimisation is not established -> activate ip context + _nonip_req = false; + return activate_ip_context(); +} + +nsapi_error_t AT_CellularContext::activate_ip_context() +{ + return activate_context(); +} + +nsapi_error_t AT_CellularContext::activate_non_ip_context() +{ + return activate_context(); +} + +nsapi_error_t AT_CellularContext::activate_context() { _at.lock(); nsapi_error_t err = NSAPI_ERROR_OK; - // try to find or create context with suitable stack + // try to find or create context of suitable type if (get_context()) { #if NSAPI_PPP_AVAILABLE _at.unlock(); @@ -593,6 +565,12 @@ void AT_CellularContext::do_connect() #if NSAPI_PPP_AVAILABLE nsapi_error_t AT_CellularContext::open_data_channel() { + // If Non-IP in use fail + if (_pdp_type == NON_IP_PDP_TYPE) { + tr_error("Attempt of PPP connect over NON-IP: failed to CONNECT"); + return NSAPI_ERROR_PARAMETER; + } + tr_info("CellularContext PPP connect"); if (get_property(PROPERTY_AT_CGDATA)) { _at.cmd_start("AT+CGDATA=\"PPP\","); @@ -618,7 +596,7 @@ nsapi_error_t AT_CellularContext::open_data_channel() /* Initialize PPP * If blocking: mbed_ppp_init() is a blocking call, it will block until connected, or timeout after 30 seconds*/ - nsapi_error_t err = nsapi_ppp_connect(_at.get_file_handle(), callback(this, &AT_CellularContext::ppp_status_cb), _uname, _pwd, _ip_stack_type); + nsapi_error_t err = nsapi_ppp_connect(_at.get_file_handle(), callback(this, &AT_CellularContext::ppp_status_cb), _uname, _pwd, (nsapi_ip_stack_t)_pdp_type); if (err) { ppp_disconnected(); } @@ -677,6 +655,31 @@ nsapi_error_t AT_CellularContext::disconnect() // deactivate a context only if we have activated if (_is_context_activated) { + if (_nonip_req && _cp_in_use) { + deactivate_non_ip_context(); + } else { + deactivate_ip_context(); + } + } + + _is_connected = false; + call_network_cb(NSAPI_STATUS_DISCONNECTED); + + return _at.unlock_return_error(); +} + +void AT_CellularContext::deactivate_ip_context() +{ + deactivate_context(); +} + +void AT_CellularContext::deactivate_non_ip_context() +{ + deactivate_context(); +} + +void AT_CellularContext::deactivate_context() +{ // CGACT and CGATT commands might take up to 3 minutes to respond. _at.set_at_timeout(180 * 1000); _is_context_active = false; @@ -716,16 +719,11 @@ nsapi_error_t AT_CellularContext::disconnect() _at.write_int(_cid); _at.cmd_stop_read_resp(); } + _at.clear_error(); _at.cmd_start("AT+CGATT=0"); _at.cmd_stop_read_resp(); _at.restore_at_timeout(); - } - - _is_connected = false; - call_network_cb(NSAPI_STATUS_DISCONNECTED); - - return _at.unlock_return_error(); } nsapi_error_t AT_CellularContext::get_apn_backoff_timer(int &backoff_timer) @@ -900,6 +898,16 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) if (!_nw && st == CellularDeviceReady && data->error == NSAPI_ERROR_OK) { _nw = _device->open_network(_fh); + tr_error("OPEN NETWORK"); + } + + if (_cp_req && !_cp_in_use && (data->error == NSAPI_ERROR_OK) && + (st == CellularSIMStatusChanged && data->status_data == CellularDevice::SimStateReady)) { + if (setup_control_plane_opt() != NSAPI_ERROR_OK) { + tr_error("Control plane SETUP failed!"); + } else { + tr_info("Control plane SETUP success!"); + } } if (_is_blocking) { @@ -969,3 +977,61 @@ void AT_CellularContext::call_network_cb(nsapi_connection_status_t status) } } } + +ControlPlane_netif *AT_CellularContext::get_cp_netif() +{ + tr_error("No control plane interface available from base context!"); + return NULL; +} + +nsapi_error_t AT_CellularContext::setup_control_plane_opt() +{ + // check if control plane optimization already set + mbed::CellularNetwork::CIoT_Supported_Opt supported_network_opt; + + if (_nw->get_ciot_network_optimization_config(supported_network_opt)) { + return NSAPI_ERROR_DEVICE_ERROR; + } + + if (supported_network_opt == mbed::CellularNetwork::CIOT_OPT_CONTROL_PLANE || + supported_network_opt == mbed::CellularNetwork::CIOT_OPT_BOTH) { + _cp_in_use = true; + return NSAPI_ERROR_OK; + } + + // ciot optimization not set by app so need to set it now + nsapi_error_t ciot_opt_ret; + ciot_opt_ret = _nw->set_ciot_optimization_config(mbed::CellularNetwork::CIOT_OPT_CONTROL_PLANE, + mbed::CellularNetwork::PREFERRED_UE_OPT_CONTROL_PLANE, + callback(this, &AT_CellularContext::ciot_opt_cb)); + + if (ciot_opt_ret != NSAPI_ERROR_OK) { + return ciot_opt_ret; + } + + //wait for control plane opt call back to release semaphore + _cp_opt_semaphore.wait(CP_OPT_NW_REPLY_TIMEOUT); + + if (_cp_in_use) { + return NSAPI_ERROR_OK; + } + + return NSAPI_ERROR_DEVICE_ERROR; +} + +void AT_CellularContext::ciot_opt_cb(mbed::CellularNetwork::CIoT_Supported_Opt ciot_opt) +{ + if (ciot_opt == mbed::CellularNetwork::CIOT_OPT_CONTROL_PLANE || + ciot_opt == mbed::CellularNetwork::CIOT_OPT_BOTH) { + _cp_in_use = true; + } + _cp_opt_semaphore.release(); +} + +void AT_CellularContext::set_disconnect() +{ + _is_connected = false; + cell_callback_data_t data; + data.error = NSAPI_STATUS_DISCONNECTED; + _device->cellular_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, (intptr_t)&data); +} diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index 4a671cabe2..afcdfc335d 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -27,7 +27,7 @@ namespace mbed { class AT_CellularContext : public CellularContext, public AT_CellularBase { public: - AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0); + AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0, bool cp_req = false, bool nonip_req = false); virtual ~AT_CellularContext(); // from CellularBase/NetworkInterface @@ -60,6 +60,8 @@ public: virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false); virtual void enable_hup(bool enable); + virtual ControlPlane_netif *get_cp_netif(); + protected: virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr); @@ -91,6 +93,11 @@ protected: */ void call_network_cb(nsapi_connection_status_t status); + virtual nsapi_error_t activate_non_ip_context(); + virtual nsapi_error_t setup_control_plane_opt(); + virtual void deactivate_non_ip_context(); + virtual void set_disconnect(); + private: #if NSAPI_PPP_AVAILABLE nsapi_error_t open_data_channel(); @@ -98,16 +105,19 @@ private: void ppp_disconnected(); #endif // #if NSAPI_PPP_AVAILABLE nsapi_error_t do_activate_context(); + nsapi_error_t activate_context(); + nsapi_error_t activate_ip_context(); + void deactivate_context(); + void deactivate_ip_context(); bool set_new_context(int cid); bool get_context(); nsapi_error_t delete_current_context(); - nsapi_ip_stack_t string_to_stack_type(const char *pdp_type); - nsapi_ip_stack_t get_stack_type(); + pdp_type_t string_to_pdp_type(const char *pdp_type); nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op); - AT_CellularBase::CellularProperty nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack); + AT_CellularBase::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type); + void ciot_opt_cb(mbed::CellularNetwork::CIoT_Supported_Opt ciot_opt); private: - nsapi_ip_stack_t _ip_stack_type_requested; bool _is_connected; bool _is_blocking; ContextOperation _current_op; @@ -116,6 +126,18 @@ private: CellularNetwork *_nw; FileHandle *_fh; rtos::Semaphore _semaphore; + rtos::Semaphore _cp_opt_semaphore; + +protected: + // flag indicating if CP was requested to be setup + bool _cp_req; + // flag indicating if Non-IP context was requested to be setup + bool _nonip_req; + + // tells if CCIOTOPTI received green from network for CP optimisation use + bool _cp_in_use; + + ControlPlane_netif *_cp_netif; }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 30b8fbcc2c..1d66328706 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -168,19 +168,19 @@ CellularContext *AT_CellularDevice::get_context_list() const } CellularContext *AT_CellularDevice::create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin, - bool active_high) + bool active_high, bool cp_req, bool nonip_req) { // Call FileHandle base version - explict upcast to avoid recursing into ourselves - CellularContext *ctx = create_context(static_cast(serial), apn); + CellularContext *ctx = create_context(static_cast(serial), apn, cp_req, nonip_req); if (serial) { ctx->set_file_handle(serial, dcd_pin, active_high); } return ctx; } -CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn) +CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn, bool cp_req, bool nonip_req) { - AT_CellularContext *ctx = create_context_impl(*get_at_handler(fh), apn); + AT_CellularContext *ctx = create_context_impl(*get_at_handler(fh), apn, cp_req, nonip_req); AT_CellularContext *curr = _context_list; if (_context_list == NULL) { @@ -198,9 +198,12 @@ CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *a return ctx; } -AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn) +AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { - return new AT_CellularContext(at, this, apn); + if (cp_req) { + + } + return new AT_CellularContext(at, this, apn, cp_req, nonip_req); } void AT_CellularDevice::delete_context(CellularContext *context) diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index c2343b47c2..195cb46157 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -44,9 +44,9 @@ public: virtual nsapi_error_t get_sim_state(SimState &state); - virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL); + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false); - virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin = NC, bool active_high = false); + virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin = NC, bool active_high = false, bool cp_req = false, bool nonip_req = false); virtual void delete_context(CellularContext *context); @@ -103,7 +103,7 @@ public: * @return new instance of class AT_CellularContext * */ - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); /** Create new instance of AT_CellularNetwork or if overridden, modem specific implementation. * diff --git a/features/cellular/framework/AT/AT_ControlPlane_netif.cpp b/features/cellular/framework/AT/AT_ControlPlane_netif.cpp new file mode 100644 index 0000000000..0ed38f5fa0 --- /dev/null +++ b/features/cellular/framework/AT/AT_ControlPlane_netif.cpp @@ -0,0 +1,77 @@ +/*AT_ControlPlane_netif.cpp*/ +#include "AT_ControlPlane_netif.h" + +namespace mbed { + +AT_ControlPlane_netif::AT_ControlPlane_netif(ATHandler &at, int cid) : AT_CellularBase(at), + _cid(cid), _cb(NULL), _data(NULL), _recv_len(0) +{ + _at.set_urc_handler("+CRTDCP:", mbed::Callback(this, &AT_ControlPlane_netif::urc_cp_recv)); +} + +AT_ControlPlane_netif::~AT_ControlPlane_netif() +{} + +void AT_ControlPlane_netif::urc_cp_recv() +{ + //+CRTDCP: ,, + _at.lock(); + int cid = _at.read_int(); + int cpdata_length = _at.read_int(); + int read_len = _at.read_string(_recv_buffer, sizeof(_recv_buffer)); + + _at.unlock(); + + // cid not expected to be different because: one context - one file handle + // so this file handle cannot get urc from different context + if (read_len > 0 && read_len == cpdata_length && cid == _cid) { + _recv_len = read_len; + data_received(); + } +} + +nsapi_size_or_error_t AT_ControlPlane_netif::send(const void *cpdata, nsapi_size_t cpdata_length) +{ + //CSODCP + _at.lock(); + _at.cmd_start("AT+CSODCP="); + _at.write_int(_cid); + _at.write_int(cpdata_length); + _at.write_bytes((uint8_t *)cpdata, cpdata_length); + + return _at.unlock_return_error(); +} + +nsapi_size_or_error_t AT_ControlPlane_netif::recv(void *cpdata, nsapi_size_t cpdata_length) +{ + // If no data received through CRTDCP URC + if (!_recv_len) { + return NSAPI_ERROR_WOULD_BLOCK; + } + + // If too small buffer for data + if (_recv_len > cpdata_length) { + return NSAPI_ERROR_DEVICE_ERROR; + } + + memcpy(cpdata, _recv_buffer, _recv_len); + + return _recv_len = 0; +} + +void AT_ControlPlane_netif::attach(void (*callback)(void *), void *data) +{ + _cb = callback; + _data = data; +} + +void AT_ControlPlane_netif::data_received() +{ + // call socket event + if (!_cb) { + return; + } + _cb(_data); +} + +} //mbed namespace diff --git a/features/cellular/framework/AT/AT_ControlPlane_netif.h b/features/cellular/framework/AT/AT_ControlPlane_netif.h new file mode 100644 index 0000000000..c33d4f3daa --- /dev/null +++ b/features/cellular/framework/AT/AT_ControlPlane_netif.h @@ -0,0 +1,32 @@ +#include "ControlPlane_netif.h" +#include "ATHandler.h" +#include "AT_CellularBase.h" + +namespace mbed { + +class AT_ControlPlane_netif: public ControlPlane_netif, public AT_CellularBase { +public: + AT_ControlPlane_netif(ATHandler &at, int cid); + virtual ~AT_ControlPlane_netif(); + +// ControlPlane_netif + // +CSODCP: 3GPP 27007 10.1.43 + virtual nsapi_size_or_error_t send(const void *cpdata, nsapi_size_t cpdata_length); + // +CRTDCP: 3GPP 27007 10.1.44 + virtual nsapi_size_or_error_t recv(void *cpdata, nsapi_size_t cpdata_length); + virtual void attach(void (*callback)(void *), void *data); + virtual void data_received(); + +protected: + // Id of the PDP context that enables the control plane data connection + int _cid; + +private: + void (*_cb)(void *); + void *_data; + char _recv_buffer[MAX_CP_DATA_RECV_LEN]; + size_t _recv_len; + void urc_cp_recv(); +}; + +} //mbed namespace diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 7ab42ce559..e1fb17f745 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -36,9 +36,9 @@ GEMALTO_CINTERION::~GEMALTO_CINTERION() { } -AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn) +AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { - return new GEMALTO_CINTERION_CellularContext(at, this, apn); + return new GEMALTO_CINTERION_CellularContext(at, this, apn, cp_req, nonip_req); } nsapi_error_t GEMALTO_CINTERION::init() diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h index 1818245f38..fb8d81e78b 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h @@ -40,7 +40,7 @@ public: static Module get_module(); protected: // AT_CellularDevice - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); protected: virtual uint16_t get_send_delay() const; virtual nsapi_error_t init(); diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp index 09d42aa81b..9878e2eb21 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp @@ -16,11 +16,12 @@ */ #include "GEMALTO_CINTERION_CellularContext.h" #include "GEMALTO_CINTERION_CellularStack.h" +#include "CellularLog.h" namespace mbed { GEMALTO_CINTERION_CellularContext::GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device, - const char *apn) : AT_CellularContext(at, device, apn) + const char *apn, bool cp_req, bool nonip_req) : AT_CellularContext(at, device, apn, cp_req, nonip_req) { } @@ -31,8 +32,13 @@ GEMALTO_CINTERION_CellularContext::~GEMALTO_CINTERION_CellularContext() #if !NSAPI_PPP_AVAILABLE NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack() { + if (_pdp_type == NON_IP_PDP_TYPE || _cp_in_use) { + tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()"); + return NULL; + } + if (!_stack) { - _stack = new GEMALTO_CINTERION_CellularStack(_at, _apn, _cid, _ip_stack_type); + _stack = new GEMALTO_CINTERION_CellularStack(_at, _apn, _cid, (nsapi_ip_stack_t)_pdp_type); } return _stack; } diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h index 262fbb2fe3..86209eda59 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h @@ -23,7 +23,7 @@ namespace mbed { class GEMALTO_CINTERION_CellularContext: public AT_CellularContext { public: - GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); + GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false); virtual ~GEMALTO_CINTERION_CellularContext(); protected: diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 44c6636690..c202c96286 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -71,9 +71,9 @@ AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at) return new QUECTEL_BC95_CellularNetwork(at); } -AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn) +AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { - return new QUECTEL_BC95_CellularContext(at, this, apn); + return new QUECTEL_BC95_CellularContext(at, this, apn, cp_req, nonip_req); } AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at) diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index f423abe642..8c49bfe9f1 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -32,7 +32,7 @@ public: // AT_CellularDevice protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual nsapi_error_t init(); virtual nsapi_error_t reset(); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp index 63bc05528c..6dad2a1206 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.cpp @@ -16,11 +16,12 @@ */ #include "QUECTEL_BC95_CellularContext.h" #include "QUECTEL_BC95_CellularStack.h" +#include "CellularLog.h" namespace mbed { -QUECTEL_BC95_CellularContext::QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) +QUECTEL_BC95_CellularContext::QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : + AT_CellularContext(at, device, apn, cp_req, nonip_req) { } @@ -31,8 +32,13 @@ QUECTEL_BC95_CellularContext::~QUECTEL_BC95_CellularContext() #if !NSAPI_PPP_AVAILABLE NetworkStack *QUECTEL_BC95_CellularContext::get_stack() { + if (_pdp_type == NON_IP_PDP_TYPE || _cp_in_use) { + tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()"); + return NULL; + } + if (!_stack) { - _stack = new QUECTEL_BC95_CellularStack(_at, _cid, _ip_stack_type); + _stack = new QUECTEL_BC95_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type); } return _stack; } diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h index d1c526a364..074066124d 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularContext.h @@ -23,7 +23,7 @@ namespace mbed { class QUECTEL_BC95_CellularContext: public AT_CellularContext { public: - QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); + QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false); virtual ~QUECTEL_BC95_CellularContext(); protected: diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 2a0c9c7eaa..0b717b5f02 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -40,6 +40,7 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK + 1, // PROPERTY_NON_IP_PDP_TYPE }; QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh) @@ -56,9 +57,9 @@ AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) return new QUECTEL_BG96_CellularNetwork(at); } -AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char *apn) +AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { - return new QUECTEL_BG96_CellularContext(at, this, apn); + return new QUECTEL_BG96_CellularContext(at, this, apn, cp_req, nonip_req); } AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at) diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 3dfc08ef36..6e2ce5de58 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -29,7 +29,7 @@ public: protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual void set_ready_cb(Callback callback); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp index badc596392..1b48c86330 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp @@ -16,28 +16,57 @@ */ #include "QUECTEL_BG96_CellularContext.h" #include "QUECTEL_BG96_CellularStack.h" +#include "QUECTEL_BG96_ControlPlane_netif.h" +#include "CellularLog.h" + +#include "Semaphore.h" namespace mbed { -QUECTEL_BG96_CellularContext::QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) +// Non-IP context supported only for context id 1 +#define NIDD_PDP_CONTEXT_ID 1 +// Timeout to wait for URC indicating NIDD connection opening +#define NIDD_OPEN_URC_TIMEOUT 3000 + +QUECTEL_BG96_CellularContext::QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : + AT_CellularContext(at, device, apn, cp_req, nonip_req) { + if (_nonip_req) { + _at.set_urc_handler("+QIND:", mbed::Callback(this, &QUECTEL_BG96_CellularContext::urc_nidd)); + } } QUECTEL_BG96_CellularContext::~QUECTEL_BG96_CellularContext() { + if (_nonip_req) { + _at.set_urc_handler("+QIND:", 0); + } } #if !NSAPI_PPP_AVAILABLE NetworkStack *QUECTEL_BG96_CellularContext::get_stack() { - if (!_stack) { - _stack = new QUECTEL_BG96_CellularStack(_at, _cid, _ip_stack_type); + if (_pdp_type == NON_IP_PDP_TYPE || (_nonip_req && _pdp_type != DEFAULT_PDP_TYPE)) { + tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()"); + return NULL; } + + if (!_stack) { + _stack = new QUECTEL_BG96_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type); + } + return _stack; } #endif // #if !NSAPI_PPP_AVAILABLE +ControlPlane_netif *QUECTEL_BG96_CellularContext::get_cp_netif() +{ + if (!_cp_netif) { + _cp_netif = new QUECTEL_BG96_ControlPlane_netif(_at, _cid); + } + return _cp_netif; +} + nsapi_error_t QUECTEL_BG96_CellularContext::do_user_authentication() { if (_pwd && _uname) { @@ -59,4 +88,110 @@ nsapi_error_t QUECTEL_BG96_CellularContext::do_user_authentication() return NSAPI_ERROR_OK; } +nsapi_error_t QUECTEL_BG96_CellularContext::activate_non_ip_context() +{ + _at.lock(); + + // Open the NIDD connection + _at.cmd_start("AT+QCFGEXT=\"nipd\",1"); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + + nsapi_size_or_error_t ret = _at.get_last_error(); + + _at.unlock(); + + if (ret == NSAPI_ERROR_OK) { + _semaphore.wait(NIDD_OPEN_URC_TIMEOUT); + if (_cid == -1) { + return NSAPI_ERROR_NO_CONNECTION; + } + } + + return (ret == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION; +} + +void QUECTEL_BG96_CellularContext::deactivate_non_ip_context() +{ + // Close the NIDD connection + _at.cmd_start("AT+QCFGEXT=\"nipd\",0"); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + +} + +void QUECTEL_BG96_CellularContext::urc_nidd() +{ + char nipd_string[6]; + + // skip "nipd" + _at.skip_param(); + _at.read_string(nipd_string, sizeof(nipd_string)); + + if (!strcmp(nipd_string, "recv")) { + _cp_netif->data_received(); + } else if (!strcmp(nipd_string, "open")) { + urc_nidd_open(); + } else if (!strcmp(nipd_string, "close")) { + urc_nidd_close(); + } +} + +void QUECTEL_BG96_CellularContext::urc_nidd_open() +{ + int err = _at.read_int(); + if (!err) { + _is_context_active = true; + _is_context_activated = true; + _cid = NIDD_PDP_CONTEXT_ID; + } else { + tr_error("NIDD connection open failed with error: %d", err); + } + _semaphore.release(); +} + +void QUECTEL_BG96_CellularContext::urc_nidd_close() +{ + set_disconnect(); +} + +nsapi_error_t QUECTEL_BG96_CellularContext::setup_control_plane_opt() +{ + _at.lock(); + + _at.cmd_start("AT+QCFGEXT=\"pdp_type\","); + _at.write_int(NIDD_PDP_CONTEXT_ID); + _at.write_string("Non-IP"); + _at.write_string(_apn); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + _at.cmd_start("AT+CFUN=0"); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + _at.cmd_start("AT+CFUN=1"); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + + // Configure Non-IP outgoing data type - 0 for no exception data + _at.cmd_start("AT+QCFGEXT=\"nipdcfg\",0,"); + _at.write_string(_apn); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + + if (_at.get_last_error() == NSAPI_ERROR_OK) { + _cp_in_use = true; + if (_nonip_req) { + _pdp_type = NON_IP_PDP_TYPE; + } + } + + return _at.unlock_return_error(); +} + } /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h index bcf019c6bc..032ebf0771 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h @@ -23,14 +23,24 @@ namespace mbed { class QUECTEL_BG96_CellularContext: public AT_CellularContext { public: - QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); + QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false); virtual ~QUECTEL_BG96_CellularContext(); protected: #if !NSAPI_PPP_AVAILABLE virtual NetworkStack *get_stack(); #endif // #if !NSAPI_PPP_AVAILABLE + virtual ControlPlane_netif *get_cp_netif(); virtual nsapi_error_t do_user_authentication(); + virtual nsapi_error_t activate_non_ip_context(); + virtual nsapi_error_t setup_control_plane_opt(); + virtual void deactivate_non_ip_context(); + rtos::Semaphore _semaphore; + +private: + void urc_nidd(); + void urc_nidd_open(); + void urc_nidd_close(); }; } /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp new file mode 100644 index 0000000000..5d2036c76a --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp @@ -0,0 +1,68 @@ +#include "QUECTEL_BG96_ControlPlane_netif.h" + +namespace mbed { + +QUECTEL_BG96_ControlPlane_netif::QUECTEL_BG96_ControlPlane_netif(ATHandler &at, int cid) : AT_ControlPlane_netif(at, cid) +{} + +nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::send(const void *data, nsapi_size_t size) +{ + _at.lock(); + + _at.cmd_start("AT+QCFGEXT=\"nipds\",0,"); + _at.write_string((char *)data); + _at.write_int(size); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + + nsapi_error_t err = _at.get_last_error(); + + _at.unlock(); + + if (err == NSAPI_ERROR_OK) { + return size; + } + + return err; +} + +nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::recv(void *buffer, nsapi_size_t size) +{ + _at.lock(); + + _at.cmd_start("AT+QCFGEXT=\"nipdr\",0"); + _at.cmd_stop(); + _at.resp_start("+QCFGEXT: "); + // skip 3 params: "nipdr",, + _at.skip_param(3); + // get to + int unread_length = _at.read_int(); + _at.resp_stop(); + + if (!unread_length || unread_length == -1) { + _at.unlock(); + return NSAPI_ERROR_WOULD_BLOCK; + } + + _at.cmd_start("AT+QCFGEXT=\"nipdr\","); + _at.write_int(unread_length); + _at.cmd_stop(); + + _at.resp_start("+QCFGEXT:"); + // skip "nipdr" + _at.skip_param(); + int read_length = _at.read_int(); + _at.read_string((char *)buffer, read_length); + _at.resp_stop(); + nsapi_error_t err = _at.get_last_error(); + _at.unlock(); + + if (err == NSAPI_ERROR_OK && read_length) { + return read_length; + } + + return NSAPI_ERROR_WOULD_BLOCK; +} + +} // mbed namespace diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.h new file mode 100644 index 0000000000..917a742808 --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef QUECTEL_BG96_CONTROLPLANE_NETIF_H_ +#define QUECTEL_BG96_CONTROLPLANE_NETIF_H_ + +#include "AT_ControlPlane_netif.h" + +namespace mbed { + +class QUECTEL_BG96_ControlPlane_netif: public AT_ControlPlane_netif { +public: + QUECTEL_BG96_ControlPlane_netif(ATHandler &at, int cid); + virtual ~QUECTEL_BG96_ControlPlane_netif() {}; + +// ControlPlane_netif + nsapi_size_or_error_t send(const void *data, nsapi_size_t size); + nsapi_size_or_error_t recv(void *buffer, nsapi_size_t size); +}; + +} /* namespace mbed */ + +#endif // QUECTEL_BG96_CONTROLPLANE_NETIF_H_ diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 9c7188ca15..a22d17d8b6 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -53,7 +53,7 @@ AT_CellularPower *QUECTEL_UG96::open_power_impl(ATHandler &at) return new QUECTEL_UG96_CellularPower(at); } -AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn) +AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { - return new QUECTEL_UG96_CellularContext(at, this, apn); + return new QUECTEL_UG96_CellularContext(at, this, apn, cp_req, nonip_req); } diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h index d85c0e8a2f..1682e45f4c 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h @@ -37,7 +37,7 @@ public: protected: // AT_CellularDevice virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp index 145dda191c..7c61b6b25b 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp @@ -18,8 +18,8 @@ namespace mbed { -QUECTEL_UG96_CellularContext::QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) +QUECTEL_UG96_CellularContext::QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : + AT_CellularContext(at, device, apn, cp_req, nonip_req) { } diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h index 660acad209..1310fef4da 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.h @@ -23,7 +23,7 @@ namespace mbed { class QUECTEL_UG96_CellularContext: public AT_CellularContext { public: - QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); + QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false); virtual ~QUECTEL_UG96_CellularContext(); protected: diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index d714be6f6c..6ae10d3b55 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -69,7 +69,7 @@ AT_CellularPower *UBLOX_AT::open_power_impl(ATHandler &at) return new UBLOX_AT_CellularPower(at); } -AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn) +AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { - return new UBLOX_AT_CellularContext(at, this, apn); + return new UBLOX_AT_CellularContext(at, this, apn, cp_req, nonip_req); } diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h index 1ee455a8a8..e4b95dbb3e 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h @@ -30,7 +30,7 @@ public: protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); public: // NetworkInterface void handle_urc(FileHandle *fh); }; diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp index 3a21e4f0d3..e7aac03545 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp @@ -17,11 +17,12 @@ #include "UBLOX_AT_CellularContext.h" #include "UBLOX_AT_CellularStack.h" #include "APN_db.h" +#include "CellularLog.h" namespace mbed { -UBLOX_AT_CellularContext::UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) +UBLOX_AT_CellularContext::UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : + AT_CellularContext(at, device, apn, cp_req, nonip_req) { // The authentication to use _auth = NSAPI_SECURITY_UNKNOWN; @@ -33,9 +34,14 @@ UBLOX_AT_CellularContext::~UBLOX_AT_CellularContext() NetworkStack *UBLOX_AT_CellularContext::get_stack() { - if (!_stack) { - _stack = new UBLOX_AT_CellularStack(_at, _cid, _ip_stack_type); + if (_pdp_type == NON_IP_PDP_TYPE || _cp_in_use) { + tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()"); + return NULL; } + if (!_stack) { + _stack = new UBLOX_AT_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type); + } + return _stack; } diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h index 1986e0aaa9..b330abead1 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h @@ -23,7 +23,7 @@ namespace mbed { class UBLOX_AT_CellularContext: public AT_CellularContext { public: - UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); + UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false); virtual ~UBLOX_AT_CellularContext(); virtual void do_connect(); diff --git a/features/netsocket/cellular/CellularNonIPSocket.cpp b/features/netsocket/cellular/CellularNonIPSocket.cpp new file mode 100644 index 0000000000..07abb6af29 --- /dev/null +++ b/features/netsocket/cellular/CellularNonIPSocket.cpp @@ -0,0 +1,267 @@ +/* CellularNonIPSocket +#include + * Copyright (c) 2015 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "platform/Callback.h" +#include "CellularNonIPSocket.h" +#include + +using namespace mbed; + +CellularNonIPSocket::CellularNonIPSocket(CellularContext *cellular_context) + : _timeout(osWaitForever), + _readers(0), _writers(0), _pending(0), + _cp_netif(NULL), + _opened(false) +{ + open(cellular_context); +} + +nsapi_error_t CellularNonIPSocket::open(CellularContext *cellular_context) +{ + return open(cellular_context->get_cp_netif()); +} + +CellularNonIPSocket::~CellularNonIPSocket() +{ + close(); +} + +nsapi_error_t CellularNonIPSocket::open(ControlPlane_netif *cp_netif) +{ + if (_opened) { + return NSAPI_ERROR_OK; + } + + _lock.lock(); + + if (_cp_netif != NULL || cp_netif == NULL) { + _lock.unlock(); + return NSAPI_ERROR_PARAMETER; + } + _cp_netif = cp_netif; + + _event = callback(this, &CellularNonIPSocket::event); + _cp_netif->attach(Callback::thunk, &_event); + _opened = true; + + _lock.unlock(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t CellularNonIPSocket::close() +{ + _lock.lock(); + + nsapi_error_t ret = NSAPI_ERROR_OK; + if (!_opened) { + return NSAPI_ERROR_NO_SOCKET; + } + + // Just in case - tell the stack not to callback any more, then remove this socket. + _cp_netif->attach(0, 0); + _opened = false; + _cp_netif = 0; // Invalidate the cp_netif pointer - otherwise open() fails. + + // Wakeup anything in a blocking operation + // on this socket + event(); + + // Wait until all readers and writers are gone + while (_readers || _writers) { + _lock.unlock(); + _event_flag.wait_any(FINISHED_FLAG, osWaitForever); + _lock.lock(); + } + + _lock.unlock(); + + return ret; +} + +nsapi_size_or_error_t CellularNonIPSocket::send(const void *data, nsapi_size_t size) +{ + _lock.lock(); + nsapi_size_or_error_t ret; + + _writers++; + + while (true) { + if (!_opened) { + ret = NSAPI_ERROR_NO_SOCKET; + break; + } + + _pending = 0; + nsapi_size_or_error_t sent = _cp_netif->send(data, size); + if ((0 == _timeout) || (NSAPI_ERROR_WOULD_BLOCK != sent)) { + ret = sent; + break; + } else { + uint32_t flag; + + // Release lock before blocking so other threads + // accessing this object aren't blocked + _lock.unlock(); + flag = _event_flag.wait_any(WRITE_FLAG, _timeout); + _lock.lock(); + + if (flag & osFlagsError) { + // Timeout break + ret = NSAPI_ERROR_WOULD_BLOCK; + break; + } + } + } + + _writers--; + if (!_opened || !_writers) { + _event_flag.set(FINISHED_FLAG); + } + _lock.unlock(); + return ret; +} + +nsapi_size_or_error_t CellularNonIPSocket::recv(void *buffer, nsapi_size_t size) +{ + _lock.lock(); + nsapi_size_or_error_t ret; + + _readers++; + + while (true) { + if (!_opened) { + ret = NSAPI_ERROR_NO_SOCKET; + break; + } + + _pending = 0; + nsapi_size_or_error_t recv = _cp_netif->recv(buffer, size); + + // Non-blocking sockets always return. Blocking only returns when success or errors other than WOULD_BLOCK + if ((0 == _timeout) || (NSAPI_ERROR_WOULD_BLOCK != recv)) { + ret = recv; + break; + } else { + uint32_t flag; + + // Release lock before blocking so other threads + // accessing this object aren't blocked + _lock.unlock(); + printf("\nWAITWAITWAIT\n"); + flag = _event_flag.wait_any(READ_FLAG, _timeout); + _lock.lock(); + + if (flag & osFlagsError) { + // Timeout break + ret = NSAPI_ERROR_WOULD_BLOCK; + break; + } + } + } + + _readers--; + if (!_opened || !_readers) { + _event_flag.set(FINISHED_FLAG); + } + + _lock.unlock(); + return ret; +} + +void CellularNonIPSocket::set_blocking(bool blocking) +{ + set_timeout(blocking ? -1 : 0); +} + +void CellularNonIPSocket::set_timeout(int timeout) +{ + _lock.lock(); + + if (timeout >= 0) { + _timeout = (uint32_t)timeout; + } else { + _timeout = osWaitForever; + } + + _lock.unlock(); +} + +void CellularNonIPSocket::event() +{ + _event_flag.set(READ_FLAG | WRITE_FLAG); + + _pending += 1; + if (_callback && _pending == 1) { + _callback(); + } +} + +void CellularNonIPSocket::sigio(Callback callback) +{ + _lock.lock(); + _callback = callback; + _lock.unlock(); +} + +nsapi_error_t CellularNonIPSocket::connect(const SocketAddress &address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +Socket *CellularNonIPSocket::accept(nsapi_error_t *error) +{ + if (error) { + *error = NSAPI_ERROR_UNSUPPORTED; + } + return NULL; +} + +nsapi_error_t CellularNonIPSocket::listen(int backlog) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_size_or_error_t CellularNonIPSocket::sendto(const SocketAddress &address, + const void *data, nsapi_size_t size) +{ + return NSAPI_ERROR_UNSUPPORTED; +} +nsapi_size_or_error_t CellularNonIPSocket::recvfrom(SocketAddress *address, + void *data, nsapi_size_t size) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t CellularNonIPSocket::setsockopt(int level, int optname, const void *optval, unsigned optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t CellularNonIPSocket::getsockopt(int level, int optname, void *optval, unsigned *optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t CellularNonIPSocket::getpeername(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t CellularNonIPSocket::bind(const SocketAddress &address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} diff --git a/features/netsocket/cellular/CellularNonIPSocket.h b/features/netsocket/cellular/CellularNonIPSocket.h new file mode 100644 index 0000000000..798bd613ff --- /dev/null +++ b/features/netsocket/cellular/CellularNonIPSocket.h @@ -0,0 +1,150 @@ + +/** \addtogroup netsocket */ +/** @{*/ +/* Socket + * Copyright (c) 2015 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CELLULARNONIPSOCKET_H +#define CELLULARNONIPSOCKET_H + +#include "netsocket/Socket.h" +#include "rtos/Mutex.h" +#include "rtos/EventFlags.h" +#include "Callback.h" +#include "mbed_toolchain.h" +#include "ControlPlane_netif.h" +#include "CellularContext.h" + +//Socket implementation for non ip datagrams over cellular control plane +class CellularNonIPSocket : public Socket { +public: + /** Destroy the socket. + * + * @note Closes socket if it's still open. + */ + virtual ~CellularNonIPSocket(); + + /** Creates and opens a socket on the given cellular context. + * + * @param cellular_context Cellular PDP context over which this socket + * is sending and receiving data. + */ + CellularNonIPSocket(mbed::CellularContext *cellular_context); + + /** Opens a socket on the given cellular context. + * + * @param cellular_context Cellular PDP context over which this socket is sending and + * receiving data. The context has support for providing + * a control plane interface for data delivery. + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER otherwise + */ + nsapi_error_t open(mbed::CellularContext *cellular_context); + + /** Opens a socket that will use the given control plane interface for data delivery. + * Attaches the event as callback to the control plane interface. + * + * @param cp_netif Control plane interface for data delivery. + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER otherwise + * + */ + nsapi_error_t open(mbed::ControlPlane_netif *cp_netif); + + /** Closes socket + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_NO_SOCKET otherwise + */ + + virtual nsapi_error_t close(); + + /** Send data over a control plane cellular context. + * + * By default, send blocks until all data is sent. If socket is set to + * nonblocking or times out, a partial amount can be written. + * NSAPI_ERROR_WOULD_BLOCK is returned if no data was written. + * + * @param data Buffer of data to be sent. + * @param size Size of the buffer in bytes. + * @return Number of sent bytes on success, negative error + * code on failure. + */ + virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size); + + /** Receive data from a socket. + * + * By default, recv blocks until some data is received. If socket is set to + * nonblocking or times out, NSAPI_ERROR_WOULD_BLOCK can be returned to + * indicate no data. + * + * @param data Pointer to buffer for received data. + * @param size Size of the buffer in bytes. + * @return Number of received bytes on success, negative error + * code on failure. + */ + virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size); + + /** @copydoc Socket::set_blocking + */ + virtual void set_blocking(bool blocking); + + /** @copydoc Socket::set_blocking + */ + virtual void set_timeout(int timeout); + + /** @copydoc Socket::sigio + */ + virtual void sigio(mbed::Callback func); + + // NOT SUPPORTED + virtual nsapi_error_t connect(const SocketAddress &address); + virtual Socket *accept(nsapi_error_t *error = NULL); + virtual nsapi_error_t listen(int backlog = 1); + virtual nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen); + virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen); + virtual nsapi_error_t getpeername(SocketAddress *address); + virtual nsapi_size_or_error_t sendto(const SocketAddress &address, + const void *data, nsapi_size_t size); + virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, + void *data, nsapi_size_t size); + virtual nsapi_error_t bind(const SocketAddress &address); + +protected: + CellularNonIPSocket(); + virtual void event(); + + uint32_t _timeout; + mbed::Callback _event; + mbed::Callback _callback; + rtos::EventFlags _event_flag; + rtos::Mutex _lock; + uint8_t _readers; + uint8_t _writers; + volatile unsigned _pending; + + // Event flags + static const int READ_FLAG = 0x1u; + static const int WRITE_FLAG = 0x2u; + static const int FINISHED_FLAG = 0x3u; + + mbed::ControlPlane_netif *_cp_netif; + bool _opened; +}; + +#endif // CELLULARNONIPSOCKET_H + +/** @}*/ diff --git a/features/netsocket/cellular/ControlPlane_netif.h b/features/netsocket/cellular/ControlPlane_netif.h new file mode 100644 index 0000000000..8d1b062f1c --- /dev/null +++ b/features/netsocket/cellular/ControlPlane_netif.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef CONTROLPLANE_NETIF_H_ +#define CONTROLPLANE_NETIF_H_ + +#include "nsapi_types.h" + +namespace mbed { + +/* Length of the buffer storing data received over control plane */ +#define MAX_CP_DATA_RECV_LEN 2048 + +// TODO: need to make this l3ip compatible +class ControlPlane_netif { +public: + ControlPlane_netif() {} + virtual ~ControlPlane_netif() {} + + /** Send data over cellular control plane + * + * @param cpdata Buffer of data to be sent over control plane connection + * @param cpdata_length Length of data in bytes + * @return Number of sent bytes on success, negative error + * code on failure. + */ + virtual nsapi_size_or_error_t send(const void *cpdata, nsapi_size_t cpdata_length) = 0; + + /** Receive data over cellular control plane + * + * @param cpdata Destination buffer for data received from control plane connection + * @param cpdata_length Length of data in bytes + * @return Number of received bytes on success, negative error + * code on failure. + */ + virtual nsapi_size_or_error_t recv(void *cpdata, nsapi_size_t cpdata_length) = 0; + + /** Register a callback on state change of the socket + * + * The specified callback will be called on state changes such as when + * the socket can recv/send successfully and on when an error + * occurs. The callback may also be called spuriously without reason. + * + * The callback may be called in an interrupt context and should not + * perform expensive operations such as recv/send calls. + * + * @param callback Function to call on state change + * @param data Argument to pass to callback + */ + virtual void attach(void (*callback)(void *), void *data) = 0; + + /** Receives data from the control plane PDP context + * + * This function is called by cellular PDP context when data + * is received from network. It will invoke the callback set + * by the above attach. + * + * @param buffer Buffer containing received data + * @param size Size of data in bytes + */ + virtual void data_received() = 0; +}; + +} // mbed namespace +#endif From ba3727b4e83c94cc54a182a52217159357f512e8 Mon Sep 17 00:00:00 2001 From: Mirela Chirica Date: Thu, 27 Dec 2018 16:39:17 +0200 Subject: [PATCH 25/41] Cellular: Unit tests for Non-IP socket --- .../at_cellulardevicetest.cpp | 65 +++-- .../test_CellularNonIPSocket.cpp | 156 ++++++++++++ .../CellularNonIPSocket/unittest.cmake | 21 ++ UNITTESTS/stubs/ATHandler_stub.h | 4 +- UNITTESTS/stubs/AT_CellularContext_stub.cpp | 3 +- UNITTESTS/stubs/CellularContext_stub.h | 224 ++++++++++++++++++ UNITTESTS/stubs/ControlPlane_netif_stub.h | 59 +++++ .../cellular/framework/API/CellularContext.h | 7 + .../framework/AT/AT_CellularContext.cpp | 99 ++++---- .../framework/AT/AT_CellularContext.h | 2 - .../framework/AT/AT_CellularDevice.cpp | 2 + .../framework/AT/AT_ControlPlane_netif.h | 5 +- .../framework/device/CellularContext.cpp | 5 + .../BG96/QUECTEL_BG96_CellularContext.cpp | 2 +- .../cellular/CellularNonIPSocket.cpp | 15 +- .../netsocket/cellular/CellularNonIPSocket.h | 18 +- .../netsocket/cellular/ControlPlane_netif.h | 26 +- 17 files changed, 596 insertions(+), 117 deletions(-) create mode 100644 UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp create mode 100644 UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake create mode 100644 UNITTESTS/stubs/CellularContext_stub.h create mode 100644 UNITTESTS/stubs/ControlPlane_netif_stub.h diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index d94240b35e..cbd03ffec6 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -51,26 +51,26 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler) FileHandle_stub fh1; FileHandle_stub fh2; FileHandle_stub fh3; - AT_CellularDevice dev(&fh1); + AT_CellularDevice dev(&fh1); // AT fh1 ref count 1 - EXPECT_TRUE(dev.open_network(&fh1)); + EXPECT_TRUE(dev.open_network(&fh1)); // AT fh1 ref count 2 EXPECT_TRUE(dev.open_sms(&fh2)); AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; EXPECT_TRUE(dev.open_information(&fh3)); ATHandler_stub::fh_value = &fh1; - EXPECT_TRUE(dev.open_power(&fh1)); + EXPECT_TRUE(dev.open_power(&fh1)); // AT fh1 ref count 3 ATHandler_stub::fh_value = NULL; - AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); - EXPECT_TRUE(dev2->open_information(&fh1)); - ATHandler *at = dev2->get_at_handler(); + AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 4 + EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 5 + ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 6 + EXPECT_TRUE(at->get_ref_count() == 6); + delete dev2; // AT fh1 2 refs deleted -> ref count 4 EXPECT_TRUE(at->get_ref_count() == 4); - delete dev2; - EXPECT_TRUE(at->get_ref_count() == 3); - AT_CellularDevice dev3(&fh1); - EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); - EXPECT_TRUE(ATHandler_stub::ref_count == 2); + AT_CellularDevice dev3(&fh1); // AT fh1 ref count 5 + EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 4 + EXPECT_TRUE(ATHandler_stub::ref_count == 4); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network) @@ -129,42 +129,39 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network) { FileHandle_stub fh1; AT_CellularDevice dev(&fh1); - ATHandler_stub::ref_count = 0; EXPECT_TRUE(dev.open_network(&fh1)); AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - EXPECT_TRUE(ATHandler_stub::ref_count == 1); + EXPECT_TRUE(ATHandler_stub::ref_count == 2); dev.close_network(); - EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); + EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms) { FileHandle_stub fh1; AT_CellularDevice dev(&fh1); - ATHandler_stub::ref_count = 0; EXPECT_TRUE(dev.open_sms(&fh1)); AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - EXPECT_TRUE(ATHandler_stub::ref_count == 1); + EXPECT_TRUE(ATHandler_stub::ref_count == 2); dev.close_sms(); - EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); + EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) { FileHandle_stub fh1; AT_CellularDevice dev(&fh1); - ATHandler_stub::ref_count = 0; EXPECT_TRUE(dev.open_power(&fh1)); AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - EXPECT_TRUE(ATHandler_stub::ref_count == 1); + EXPECT_TRUE(ATHandler_stub::ref_count == 2); dev.close_power(); - EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); + EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) @@ -188,7 +185,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; dev.close_information(); - EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); + EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount); ATHandler_stub::fh_value = NULL; } @@ -205,7 +202,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout) EXPECT_TRUE(ATHandler_stub::default_timeout == true); EXPECT_TRUE(dev.open_sms(&fh1)); - EXPECT_TRUE(ATHandler_stub::ref_count == 1); + EXPECT_TRUE(ATHandler_stub::ref_count == 2); dev.set_timeout(5000); EXPECT_TRUE(ATHandler_stub::timeout == 5000); @@ -224,7 +221,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) EXPECT_TRUE(ATHandler_stub::debug_on == true); EXPECT_TRUE(dev.open_sms(&fh1)); - EXPECT_TRUE(ATHandler_stub::ref_count == 1); + EXPECT_TRUE(ATHandler_stub::ref_count == 2); dev.modem_debug_on(true); EXPECT_TRUE(ATHandler_stub::debug_on == true); @@ -305,7 +302,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context) AT_CellularDevice *dev = new AT_CellularDevice(&fh1); ATHandler *at = dev->get_at_handler(); - EXPECT_TRUE(at->get_ref_count() == 1); + EXPECT_TRUE(at->get_ref_count() == 2); EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK); CellularContext *ctx = dev->create_context(NULL); @@ -313,12 +310,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context) dev = new AT_CellularDevice(&fh1); at = dev->get_at_handler(); - EXPECT_TRUE(at->get_ref_count() == 1); + EXPECT_TRUE(at->get_ref_count() == 2); ctx = dev->create_context(NULL); CellularContext *ctx1 = dev->create_context(&fh1); - EXPECT_TRUE(at->get_ref_count() == 3); - CellularContext *ctx2 = dev->create_context(&fh1); EXPECT_TRUE(at->get_ref_count() == 4); + CellularContext *ctx2 = dev->create_context(&fh1); + EXPECT_TRUE(at->get_ref_count() == 5); EXPECT_TRUE(ctx); EXPECT_TRUE(ctx1); @@ -329,20 +326,20 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context) EXPECT_TRUE(xx); dev->delete_context(ctx); - EXPECT_TRUE(at->get_ref_count() == 3); + EXPECT_TRUE(at->get_ref_count() == 4); dev->delete_context(ctx1); - EXPECT_TRUE(at->get_ref_count() == 2); + EXPECT_TRUE(at->get_ref_count() == 3); dev->delete_context(NULL); - EXPECT_TRUE(at->get_ref_count() == 2); + EXPECT_TRUE(at->get_ref_count() == 3); dev->delete_context(ctx2); - EXPECT_TRUE(at->get_ref_count() == 1); + EXPECT_TRUE(at->get_ref_count() == 2); ctx = dev->create_context(NULL); - EXPECT_TRUE(at->get_ref_count() == 2); - ctx1 = dev->create_context(&fh1); EXPECT_TRUE(at->get_ref_count() == 3); - ctx2 = dev->create_context(&fh1); + ctx1 = dev->create_context(&fh1); EXPECT_TRUE(at->get_ref_count() == 4); + ctx2 = dev->create_context(&fh1); + EXPECT_TRUE(at->get_ref_count() == 5); EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK); EXPECT_TRUE(ctx); EXPECT_TRUE(ctx1); diff --git a/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp b/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp new file mode 100644 index 0000000000..2d6ac4dcea --- /dev/null +++ b/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "features/netsocket/cellular/CellularNonIPSocket.h" +#include "CellularContext_stub.h" + +using namespace mbed; + +// Control the rtos EventFlags stub. See EventFlags_stub.cpp +extern std::list eventFlagsStubNextRetval; + +static bool callback_is_called; +static void my_callback() +{ + callback_is_called = true; +} + +class TestCellularNonIPSocket : public testing::Test { +protected: + CellularNonIPSocket *socket; + ControlPlane_netif_stub *cp_netif; + CellularContext_stub cellular_context; + nsapi_size_t dataSize; + char dataBuf[10]; + + virtual void SetUp() + { + socket = new CellularNonIPSocket(); + cp_netif = NULL; + dataSize = 10; + } + + virtual void TearDown() + { + delete socket; + } +}; + +TEST_F(TestCellularNonIPSocket, open_null_cp_netif) +{ + EXPECT_EQ(socket->open(static_cast(NULL)), NSAPI_ERROR_PARAMETER); +} + +TEST_F(TestCellularNonIPSocket, open_null_context) +{ + EXPECT_EQ(socket->open(static_cast(NULL)), NSAPI_ERROR_PARAMETER); +} + +TEST_F(TestCellularNonIPSocket, open_context) +{ + EXPECT_EQ(socket->open((CellularContext *)&cellular_context), NSAPI_ERROR_OK); +} + +TEST_F(TestCellularNonIPSocket, open_cp_netif) +{ + cp_netif = cellular_context.get_cp_netif(); + EXPECT_EQ(socket->open((ControlPlane_netif *)cp_netif), NSAPI_ERROR_OK); +} + +TEST_F(TestCellularNonIPSocket, open_twice) +{ + EXPECT_EQ(socket->open((CellularContext *)&cellular_context), NSAPI_ERROR_OK); + EXPECT_EQ(socket->open((CellularContext *)&cellular_context), NSAPI_ERROR_PARAMETER); +} + +TEST_F(TestCellularNonIPSocket, close) +{ + socket->open((CellularContext *)&cellular_context); + EXPECT_EQ(socket->close(), NSAPI_ERROR_OK); +} + +TEST_F(TestCellularNonIPSocket, close_no_open) +{ + EXPECT_EQ(socket->close(), NSAPI_ERROR_NO_SOCKET); +} + +TEST_F(TestCellularNonIPSocket, sigio) +{ + callback_is_called = false; + socket->open((CellularContext *)&cellular_context); + socket->sigio(mbed::callback(my_callback)); + socket->close(); // Trigger event; + EXPECT_EQ(callback_is_called, true); +} + +/* send */ + +TEST_F(TestCellularNonIPSocket, send_no_open) +{ + EXPECT_EQ(socket->send((char *)dataBuf, dataSize), NSAPI_ERROR_NO_SOCKET); +} + +TEST_F(TestCellularNonIPSocket, send_error_would_block) +{ + socket->open((CellularContext *)&cellular_context); + cp_netif = cellular_context.get_cp_netif(); + cp_netif->return_value = NSAPI_ERROR_WOULD_BLOCK; + eventFlagsStubNextRetval.push_back(osFlagsError); // Break the wait loop + EXPECT_EQ(socket->send(dataBuf, dataSize), NSAPI_ERROR_WOULD_BLOCK); +} + +TEST_F(TestCellularNonIPSocket, send_error_other) +{ + socket->open((CellularContext *)&cellular_context); + cp_netif = cellular_context.get_cp_netif(); + cp_netif->return_value = NSAPI_ERROR_NO_MEMORY; + EXPECT_EQ(socket->send(dataBuf, dataSize), NSAPI_ERROR_NO_MEMORY); +} + +TEST_F(TestCellularNonIPSocket, send_error_no_timeout) +{ + socket->open((CellularContext *)&cellular_context); + cp_netif = cellular_context.get_cp_netif(); + cp_netif->return_value = NSAPI_ERROR_WOULD_BLOCK; + socket->set_blocking(false); + EXPECT_EQ(socket->send(dataBuf, dataSize), NSAPI_ERROR_WOULD_BLOCK); +} + +TEST_F(TestCellularNonIPSocket, send) +{ + socket->open((CellularContext *)&cellular_context); + cp_netif = cellular_context.get_cp_netif(); + cp_netif->return_value = dataSize; + EXPECT_EQ(socket->send(dataBuf, dataSize), dataSize); +} + +TEST_F(TestCellularNonIPSocket, recv) +{ + EXPECT_EQ(socket->recv(&dataBuf, dataSize), NSAPI_ERROR_NO_SOCKET); + + socket->open((CellularContext *)&cellular_context); + cp_netif = cellular_context.get_cp_netif(); + + cp_netif->return_value = 100; + EXPECT_EQ(socket->recv(&dataBuf, dataSize), 100); + + cp_netif->return_value = NSAPI_ERROR_WOULD_BLOCK; + eventFlagsStubNextRetval.push_back(0); + eventFlagsStubNextRetval.push_back(osFlagsError); // Break the wait loop + EXPECT_EQ(socket->recv(&dataBuf, dataSize), NSAPI_ERROR_WOULD_BLOCK); +} diff --git a/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake b/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake new file mode 100644 index 0000000000..c0b72a7652 --- /dev/null +++ b/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake @@ -0,0 +1,21 @@ + +#################### +# UNIT TESTS +#################### + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + ../features/netsocket/cellular +) + +set(unittest-sources + ../features/netsocket/cellular/CellularNonIPSocket.cpp +) + +set(unittest-test-sources + features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp + stubs/NetworkInterface_stub.cpp + stubs/NetworkStack_stub.cpp + stubs/EventFlags_stub.cpp + stubs/Mutex_stub.cpp +) diff --git a/UNITTESTS/stubs/ATHandler_stub.h b/UNITTESTS/stubs/ATHandler_stub.h index e243e355ba..7b220df467 100644 --- a/UNITTESTS/stubs/ATHandler_stub.h +++ b/UNITTESTS/stubs/ATHandler_stub.h @@ -26,11 +26,13 @@ #ifndef __AT_HANDLER_STUB_H__ #define __AT_HANDLER_STUB_H__ +#define ATHANDLER_REF_COUNT_AT_DESTRUCTOR -909 + static const int kRead_string_table_size = 100; static const int kRead_int_table_size = 100; static const int kResp_stop_count_default = 100; // set reference count to -909 to separate it from zero so we can test that ATHandler is really deleted. -static const int kATHandler_destructor_ref_ount = -909; +static const int kATHandler_destructor_ref_ount = ATHANDLER_REF_COUNT_AT_DESTRUCTOR; static const int kATHandler_urc_table_max_size = 10; static const int kATHandler_urc_string_max_size = 16; diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index f9ab4d83ca..5b37aaadde 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -21,7 +21,7 @@ using namespace mbed; AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : AT_CellularBase(at), _is_blocking(true), _is_connected(false), - _current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false), _cp_netif(NULL) + _current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false) { _stack = NULL; _pdp_type = DEFAULT_PDP_TYPE; @@ -36,6 +36,7 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co _cid = -1; _new_context_set = false; _next = NULL; + _cp_netif = NULL; } AT_CellularContext::~AT_CellularContext() diff --git a/UNITTESTS/stubs/CellularContext_stub.h b/UNITTESTS/stubs/CellularContext_stub.h new file mode 100644 index 0000000000..062f77fdff --- /dev/null +++ b/UNITTESTS/stubs/CellularContext_stub.h @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cellular/framework/API/CellularContext.h" +#include "ControlPlane_netif_stub.h" + +namespace mbed { + +class CellularContext_stub : public CellularContext { +public: + std::list return_values; + nsapi_error_t return_value; + ControlPlane_netif_stub *my_cp_netif; + + CellularContext_stub() + { + return_value = 0; + my_cp_netif = NULL; + } + ~CellularContext_stub() + { + if (my_cp_netif) { + delete my_cp_netif; + my_cp_netif = NULL; + } + } + + void set_file_handle(UARTSerial *serial, PinName dcd_pin, bool active_high) + { + }; + + void enable_hup(bool enable) + { + }; + + void set_file_handle(FileHandle *fh) + { + }; + + nsapi_error_t connect() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t set_device_ready() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t set_sim_ready() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t register_to_network() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t attach_to_network() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op) + { + return NSAPI_ERROR_OK; + }; + + uint32_t get_timeout_for_operation(ContextOperation op) const + { + uint32_t timeout = 10 * 60 * 1000; // default timeout is 10 minutes as registration and attach may take time + return timeout; + }; + + bool is_connected() + { + return true; + }; + + NetworkStack * get_stack() + { + return NULL; + }; + + const char * get_ip_address() + { + return NULL; + }; + + void attach(Callback status_cb) + { + }; + + nsapi_error_t set_blocking(bool blocking) + { + return NSAPI_ERROR_OK; + }; + + void set_plmn(const char *plmn) + { + }; + + void set_sim_pin(const char *sim_pin) + { + }; + + nsapi_error_t connect(const char *sim_pin, const char *apn, const char *uname, + const char *pwd) + { + return NSAPI_ERROR_OK; + }; + + void set_credentials(const char *apn, const char *uname, const char *pwd) + { + + }; + + const char * get_netmask() + { + return NULL; + }; + + const char * get_gateway() + { + return NULL; + }; + + bool get_context() + { + return true; + }; + + bool set_new_context(int cid) + { + return true; + }; + + nsapi_error_t do_activate_context() + { + return NSAPI_ERROR_OK; + }; + + void do_connect() + { + }; + + nsapi_error_t disconnect() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t get_apn_backoff_timer(int &backoff_timer) + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t get_rate_control( + CellularContext::RateControlExceptionReports &reports, + CellularContext::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate) + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t get_pdpcontext_params(pdpContextList_t ¶ms_list) + { + return NSAPI_ERROR_OK; + }; + + // Called by CellularDevice for network and cellular device changes + void cellular_callback(nsapi_event_t ev, intptr_t ptr) + { + }; + + void call_network_cb(nsapi_connection_status_t status) + { + }; + + ControlPlane_netif_stub *get_cp_netif() + { + if (!my_cp_netif) { + my_cp_netif = new ControlPlane_netif_stub(); + } + return my_cp_netif; + }; + + nsapi_error_t activate_non_ip_context() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t setup_control_plane_opt() + { + return NSAPI_ERROR_OK; + }; + + void deactivate_ip_context() + { + }; + + void deactivate_non_ip_context() + { + }; + + void set_disconnect() + { + }; +}; + +} diff --git a/UNITTESTS/stubs/ControlPlane_netif_stub.h b/UNITTESTS/stubs/ControlPlane_netif_stub.h new file mode 100644 index 0000000000..ed4bec917f --- /dev/null +++ b/UNITTESTS/stubs/ControlPlane_netif_stub.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/cellular/ControlPlane_netif.h" +#include + +namespace mbed { + +class ControlPlane_netif_stub : public ControlPlane_netif { +public: + std::list return_values; + nsapi_error_t return_value; + + ControlPlane_netif_stub() + { + return_value = 0; + } + +protected: + virtual nsapi_error_t send(const void *cpdata, nsapi_size_t cpdata_length) + { + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + + virtual nsapi_error_t recv(void *cpdata, nsapi_size_t cpdata_length) + { + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + + virtual void data_received(){}; + + virtual void attach(void (*callback)(void *), void *data) {}; +}; + +} diff --git a/features/cellular/framework/API/CellularContext.h b/features/cellular/framework/API/CellularContext.h index 6699b8e749..6da38128a9 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -276,6 +276,11 @@ protected: // Device specific implementations might need these so protected */ virtual void enable_hup(bool enable) = 0; + /** Triggers control plane's operations needed when control plane data is received, + * like socket event, for example. + */ + void cp_data_received(); + // member variables needed in target override methods NetworkStack *_stack; // must be pointer because of PPP pdp_type_t _pdp_type; @@ -292,6 +297,8 @@ protected: // Device specific implementations might need these so protected const char *_pwd; PinName _dcd_pin; bool _active_high; + + ControlPlane_netif *_cp_netif; }; /** diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 6947d6bdce..91588c2cc1 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -46,7 +46,7 @@ using namespace mbed; AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : AT_CellularBase(at), _is_connected(false), _is_blocking(true), - _current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false), _cp_netif(NULL) + _current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false) { tr_info("New CellularContext %s (%p)", apn ? apn : "", this); _stack = NULL; @@ -64,6 +64,7 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co _next = NULL; _dcd_pin = NC; _active_high = false; + _cp_netif = NULL; } AT_CellularContext::~AT_CellularContext() @@ -75,6 +76,10 @@ AT_CellularContext::~AT_CellularContext() if (_nw) { _device->close_network(); } + + if (_cp_netif) { + delete _cp_netif; + } } void AT_CellularContext::set_file_handle(FileHandle *fh) @@ -363,10 +368,10 @@ bool AT_CellularContext::get_context() if (get_property(pdp_type_t_to_cellular_property(pdp_type)) || ((pdp_type == IPV4V6_PDP_TYPE && (modem_supports_ipv4 || modem_supports_ipv6)) && !_nonip_req)) { _pdp_type = pdp_type; - _cid = cid; - } - } - } + _cid = cid; + } + } + } } _at.resp_stop(); @@ -401,15 +406,15 @@ bool AT_CellularContext::set_new_context(int cid) } else if (modem_supports_ipv6 && modem_supports_ipv4) { strncpy(pdp_type_str, "IPV4V6", sizeof(pdp_type_str)); pdp_type = IPV4V6_PDP_TYPE; - } else if (modem_supports_ipv6) { + } else if (modem_supports_ipv6) { strncpy(pdp_type_str, "IPV6", sizeof(pdp_type_str)); pdp_type = IPV6_PDP_TYPE; - } else if (modem_supports_ipv4) { + } else if (modem_supports_ipv4) { strncpy(pdp_type_str, "IP", sizeof(pdp_type)); pdp_type = IPV4_PDP_TYPE; } else { return false; - } + } //apn: "If the value is null or omitted, then the subscription value will be requested." bool success = false; @@ -680,50 +685,50 @@ void AT_CellularContext::deactivate_non_ip_context() void AT_CellularContext::deactivate_context() { - // CGACT and CGATT commands might take up to 3 minutes to respond. - _at.set_at_timeout(180 * 1000); - _is_context_active = false; - size_t active_contexts_count = 0; - _at.cmd_start("AT+CGACT?"); - _at.cmd_stop(); - _at.resp_start("+CGACT:"); - while (_at.info_resp()) { - int context_id = _at.read_int(); - int context_activation_state = _at.read_int(); - if (context_activation_state == 1) { - active_contexts_count++; - if (context_id == _cid) { - _is_context_active = true; - } + // CGACT and CGATT commands might take up to 3 minutes to respond. + _at.set_at_timeout(180 * 1000); + _is_context_active = false; + size_t active_contexts_count = 0; + _at.cmd_start("AT+CGACT?"); + _at.cmd_stop(); + _at.resp_start("+CGACT:"); + while (_at.info_resp()) { + int context_id = _at.read_int(); + int context_activation_state = _at.read_int(); + if (context_activation_state == 1) { + active_contexts_count++; + if (context_id == _cid) { + _is_context_active = true; } } - _at.resp_stop(); - - CellularNetwork::RadioAccessTechnology rat = CellularNetwork::RAT_GSM; - // always return NSAPI_ERROR_OK - CellularNetwork::registration_params_t reg_params; - _nw->get_registration_params(reg_params); - rat = reg_params._act; - // 3GPP TS 27.007: - // For EPS, if an attempt is made to disconnect the last PDN connection, then the MT responds with ERROR - if (_is_context_active && (rat < CellularNetwork::RAT_E_UTRAN || active_contexts_count > 1)) { - _at.clear_error(); - _at.cmd_start("AT+CGACT=0,"); - _at.write_int(_cid); - _at.cmd_stop_read_resp(); - } - - if (_new_context_set) { - _at.clear_error(); - _at.cmd_start("AT+CGDCONT="); - _at.write_int(_cid); - _at.cmd_stop_read_resp(); - } + } + _at.resp_stop(); + CellularNetwork::RadioAccessTechnology rat = CellularNetwork::RAT_GSM; + // always return NSAPI_ERROR_OK + CellularNetwork::registration_params_t reg_params; + _nw->get_registration_params(reg_params); + rat = reg_params._act; + // 3GPP TS 27.007: + // For EPS, if an attempt is made to disconnect the last PDN connection, then the MT responds with ERROR + if (_is_context_active && (rat < CellularNetwork::RAT_E_UTRAN || active_contexts_count > 1)) { _at.clear_error(); - _at.cmd_start("AT+CGATT=0"); + _at.cmd_start("AT+CGACT=0,"); + _at.write_int(_cid); _at.cmd_stop_read_resp(); - _at.restore_at_timeout(); + } + + if (_new_context_set) { + _at.clear_error(); + _at.cmd_start("AT+CGDCONT="); + _at.write_int(_cid); + _at.cmd_stop_read_resp(); + } + + _at.clear_error(); + _at.cmd_start("AT+CGATT=0"); + _at.cmd_stop_read_resp(); + _at.restore_at_timeout(); } nsapi_error_t AT_CellularContext::get_apn_backoff_timer(int &backoff_timer) diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index afcdfc335d..41f52dd05c 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -136,8 +136,6 @@ protected: // tells if CCIOTOPTI received green from network for CP optimisation use bool _cp_in_use; - - ControlPlane_netif *_cp_netif; }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 1d66328706..91930994c7 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -68,6 +68,8 @@ AT_CellularDevice::~AT_CellularDevice() curr = next; release_at_handler(at); } + + release_at_handler(_at); } // each parser is associated with one filehandle (that is UART) diff --git a/features/cellular/framework/AT/AT_ControlPlane_netif.h b/features/cellular/framework/AT/AT_ControlPlane_netif.h index c33d4f3daa..9c8b1448b7 100644 --- a/features/cellular/framework/AT/AT_ControlPlane_netif.h +++ b/features/cellular/framework/AT/AT_ControlPlane_netif.h @@ -9,15 +9,16 @@ public: AT_ControlPlane_netif(ATHandler &at, int cid); virtual ~AT_ControlPlane_netif(); +protected: + // ControlPlane_netif // +CSODCP: 3GPP 27007 10.1.43 virtual nsapi_size_or_error_t send(const void *cpdata, nsapi_size_t cpdata_length); // +CRTDCP: 3GPP 27007 10.1.44 virtual nsapi_size_or_error_t recv(void *cpdata, nsapi_size_t cpdata_length); - virtual void attach(void (*callback)(void *), void *data); virtual void data_received(); + virtual void attach(void (*callback)(void *), void *data); -protected: // Id of the PDP context that enables the control plane data connection int _cid; diff --git a/features/cellular/framework/device/CellularContext.cpp b/features/cellular/framework/device/CellularContext.cpp index a134e28a17..746953cfd4 100644 --- a/features/cellular/framework/device/CellularContext.cpp +++ b/features/cellular/framework/device/CellularContext.cpp @@ -38,4 +38,9 @@ MBED_WEAK CellularContext *CellularContext::get_default_instance() } #endif // CELLULAR_DEVICE +void CellularContext::cp_data_received() +{ + _cp_netif->data_received(); +} + } // namespace mbed diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp index 1b48c86330..dd3ea30e29 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp @@ -131,7 +131,7 @@ void QUECTEL_BG96_CellularContext::urc_nidd() _at.read_string(nipd_string, sizeof(nipd_string)); if (!strcmp(nipd_string, "recv")) { - _cp_netif->data_received(); + cp_data_received(); } else if (!strcmp(nipd_string, "open")) { urc_nidd_open(); } else if (!strcmp(nipd_string, "close")) { diff --git a/features/netsocket/cellular/CellularNonIPSocket.cpp b/features/netsocket/cellular/CellularNonIPSocket.cpp index 07abb6af29..3806696f19 100644 --- a/features/netsocket/cellular/CellularNonIPSocket.cpp +++ b/features/netsocket/cellular/CellularNonIPSocket.cpp @@ -21,17 +21,19 @@ using namespace mbed; -CellularNonIPSocket::CellularNonIPSocket(CellularContext *cellular_context) +CellularNonIPSocket::CellularNonIPSocket() : _timeout(osWaitForever), _readers(0), _writers(0), _pending(0), _cp_netif(NULL), _opened(false) -{ - open(cellular_context); -} +{} nsapi_error_t CellularNonIPSocket::open(CellularContext *cellular_context) { + if (cellular_context == NULL) { + return NSAPI_ERROR_PARAMETER; + } + return open(cellular_context->get_cp_netif()); } @@ -42,10 +44,6 @@ CellularNonIPSocket::~CellularNonIPSocket() nsapi_error_t CellularNonIPSocket::open(ControlPlane_netif *cp_netif) { - if (_opened) { - return NSAPI_ERROR_OK; - } - _lock.lock(); if (_cp_netif != NULL || cp_netif == NULL) { @@ -161,7 +159,6 @@ nsapi_size_or_error_t CellularNonIPSocket::recv(void *buffer, nsapi_size_t size) // Release lock before blocking so other threads // accessing this object aren't blocked _lock.unlock(); - printf("\nWAITWAITWAIT\n"); flag = _event_flag.wait_any(READ_FLAG, _timeout); _lock.lock(); diff --git a/features/netsocket/cellular/CellularNonIPSocket.h b/features/netsocket/cellular/CellularNonIPSocket.h index 798bd613ff..cbafc4238a 100644 --- a/features/netsocket/cellular/CellularNonIPSocket.h +++ b/features/netsocket/cellular/CellularNonIPSocket.h @@ -28,6 +28,8 @@ #include "ControlPlane_netif.h" #include "CellularContext.h" +namespace mbed { + //Socket implementation for non ip datagrams over cellular control plane class CellularNonIPSocket : public Socket { public: @@ -37,12 +39,9 @@ public: */ virtual ~CellularNonIPSocket(); - /** Creates and opens a socket on the given cellular context. - * - * @param cellular_context Cellular PDP context over which this socket - * is sending and receiving data. + /** Creates a socket. */ - CellularNonIPSocket(mbed::CellularContext *cellular_context); + CellularNonIPSocket(); /** Opens a socket on the given cellular context. * @@ -52,7 +51,7 @@ public: * @return NSAPI_ERROR_OK on success * NSAPI_ERROR_PARAMETER otherwise */ - nsapi_error_t open(mbed::CellularContext *cellular_context); + virtual nsapi_error_t open(mbed::CellularContext *cellular_context); /** Opens a socket that will use the given control plane interface for data delivery. * Attaches the event as callback to the control plane interface. @@ -62,7 +61,7 @@ public: * NSAPI_ERROR_PARAMETER otherwise * */ - nsapi_error_t open(mbed::ControlPlane_netif *cp_netif); + virtual nsapi_error_t open(mbed::ControlPlane_netif *cp_netif); /** Closes socket * @@ -124,7 +123,6 @@ public: virtual nsapi_error_t bind(const SocketAddress &address); protected: - CellularNonIPSocket(); virtual void event(); uint32_t _timeout; @@ -141,10 +139,12 @@ protected: static const int WRITE_FLAG = 0x2u; static const int FINISHED_FLAG = 0x3u; - mbed::ControlPlane_netif *_cp_netif; + ControlPlane_netif *_cp_netif; bool _opened; }; +} // namespace mbed + #endif // CELLULARNONIPSOCKET_H /** @}*/ diff --git a/features/netsocket/cellular/ControlPlane_netif.h b/features/netsocket/cellular/ControlPlane_netif.h index 8d1b062f1c..c0a6585165 100644 --- a/features/netsocket/cellular/ControlPlane_netif.h +++ b/features/netsocket/cellular/ControlPlane_netif.h @@ -30,6 +30,10 @@ public: ControlPlane_netif() {} virtual ~ControlPlane_netif() {} +protected: + friend class CellularNonIPSocket; + friend class CellularContext; + /** Send data over cellular control plane * * @param cpdata Buffer of data to be sent over control plane connection @@ -48,6 +52,17 @@ public: */ virtual nsapi_size_or_error_t recv(void *cpdata, nsapi_size_t cpdata_length) = 0; + /** Receives data from the control plane PDP context + * + * This function is called by cellular PDP context when data + * is received from network. It will invoke the callback set + * by the above attach. + * + * @param buffer Buffer containing received data + * @param size Size of data in bytes + */ + virtual void data_received() = 0; + /** Register a callback on state change of the socket * * The specified callback will be called on state changes such as when @@ -61,17 +76,6 @@ public: * @param data Argument to pass to callback */ virtual void attach(void (*callback)(void *), void *data) = 0; - - /** Receives data from the control plane PDP context - * - * This function is called by cellular PDP context when data - * is received from network. It will invoke the callback set - * by the above attach. - * - * @param buffer Buffer containing received data - * @param size Size of data in bytes - */ - virtual void data_received() = 0; }; } // mbed namespace From 55b54f7c97983014a10ccf2f0adca48e1fbdbc8b Mon Sep 17 00:00:00 2001 From: Mirela Chirica Date: Tue, 15 Jan 2019 17:34:37 +0200 Subject: [PATCH 26/41] Cellular: Added API for setting default parameters to a network interface --- .../AT/at_cellularcontext/unittest.cmake | 1 + .../AT/at_cellulardevice/unittest.cmake | 1 + .../device/cellulardevice/unittest.cmake | 1 + .../cellularstatemachine/unittest.cmake | 1 + .../EthernetInterface/unittest.cmake | 1 + .../netsocket/NetworkInterface/unittest.cmake | 1 + .../CellularNonIPSocket/unittest.cmake | 1 + .../stubs/NetworkInterfaceDefaults_stub.cpp | 62 +++++++++++++++ .../cellular/framework/API/CellularContext.h | 18 +++++ .../framework/device/CellularContext.cpp | 20 ++++- features/cellular/mbed_lib.json | 4 + features/netsocket/CellularBase.h | 11 +++ features/netsocket/NetworkInterface.h | 11 +++ .../netsocket/NetworkInterfaceDefaults.cpp | 77 ++++++++++++------- features/netsocket/WiFiInterface.h | 11 +++ 15 files changed, 191 insertions(+), 30 deletions(-) create mode 100644 UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake index 2192536f6e..051b3785a7 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake @@ -35,6 +35,7 @@ set(unittest-test-sources stubs/FileHandle_stub.cpp stubs/mbed_assert_stub.c stubs/NetworkInterface_stub.cpp + stubs/NetworkInterfaceDefaults_stub.cpp stubs/NetworkStack_stub.cpp stubs/randLIB_stub.cpp stubs/Semaphore_stub.cpp diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake index e1b50a9eb6..c271917135 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake @@ -33,6 +33,7 @@ set(unittest-test-sources stubs/CellularUtil_stub.cpp stubs/AT_CellularBase_stub.cpp stubs/NetworkInterface_stub.cpp + stubs/NetworkInterfaceDefaults_stub.cpp stubs/EventQueue_stub.cpp stubs/FileHandle_stub.cpp stubs/mbed_assert_stub.c diff --git a/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake index 0e9bb23427..43888121ca 100644 --- a/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake @@ -31,6 +31,7 @@ set(unittest-test-sources stubs/AT_CellularContext_stub.cpp stubs/Semaphore_stub.cpp stubs/NetworkInterface_stub.cpp + stubs/NetworkInterfaceDefaults_stub.cpp ) # defines diff --git a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake index 00e5674448..49d24d3523 100644 --- a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake @@ -34,6 +34,7 @@ set(unittest-test-sources stubs/AT_CellularDevice_stub.cpp stubs/Semaphore_stub.cpp stubs/NetworkInterface_stub.cpp + stubs/NetworkInterfaceDefaults_stub.cpp stubs/Thread_stub.cpp stubs/Mutex_stub.cpp stubs/EventQueue_stub.cpp diff --git a/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake b/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake index 472d5f0a26..605c5ea470 100644 --- a/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake +++ b/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake @@ -33,5 +33,6 @@ set(unittest-test-sources stubs/stoip4_stub.c stubs/ip4tos_stub.c stubs/NetworkStack_stub.cpp + stubs/NetworkInterfaceDefaults_stub.cpp stubs/SocketStats_Stub.cpp ) diff --git a/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake b/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake index fd21980983..3a7cf8be83 100644 --- a/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake +++ b/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake @@ -25,5 +25,6 @@ set(unittest-test-sources stubs/nsapi_dns_stub.cpp stubs/EventFlags_stub.cpp features/netsocket/NetworkInterface/test_NetworkInterface.cpp + stubs/NetworkInterfaceDefaults_stub.cpp stubs/SocketStats_Stub.cpp ) diff --git a/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake b/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake index c0b72a7652..2dd69cad71 100644 --- a/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake @@ -15,6 +15,7 @@ set(unittest-sources set(unittest-test-sources features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp stubs/NetworkInterface_stub.cpp + stubs/NetworkInterfaceDefaults_stub.cpp stubs/NetworkStack_stub.cpp stubs/EventFlags_stub.cpp stubs/Mutex_stub.cpp diff --git a/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp b/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp new file mode 100644 index 0000000000..1275e1169e --- /dev/null +++ b/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "netsocket/NetworkInterface.h" +#include "WiFiInterface.h" +#include "CellularBase.h" +#include "MeshInterface.h" + +MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance() +{ + return NULL; +} + +MBED_WEAK MeshInterface *MeshInterface::get_default_instance() +{ + return NULL; +} + +MBED_WEAK CellularBase *CellularBase::get_default_instance() +{ + return NULL; +} + +MBED_WEAK WiFiInterface *WiFiInterface::get_target_default_instance() +{ + return NULL; +} + +MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance() +{ + return NULL; +} + +void NetworkInterface::set_default_parameters() +{ +} + +void WiFiInterface::set_default_parameters() +{ +} + +void CellularBase::set_default_parameters() +{ +} + +MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance() +{ + return NULL; +} diff --git a/features/cellular/framework/API/CellularContext.h b/features/cellular/framework/API/CellularContext.h index 6da38128a9..95abecb76d 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -144,9 +144,27 @@ public: // from NetworkInterface virtual const char *get_netmask() = 0; virtual const char *get_gateway() = 0; virtual bool is_connected() = 0; + + /** Same as NetworkInterface::get_default_instance() + * + * @note not to be used if get_default_nonip_instance() was already used + * + */ static CellularContext *get_default_instance(); + /** Instantiates a default Non-IP cellular interface + * + * This function creates a new Non-IP PDP context. + * + * @note not to be used if get_default_instance() was already used + * + * @return A Non-IP cellular PDP context + * + */ + static CellularContext *get_default_nonip_instance(); + + // Operations, can be sync/async. Also Connect() is this kind of operation, inherited from NetworkInterface above. /** Start the interface diff --git a/features/cellular/framework/device/CellularContext.cpp b/features/cellular/framework/device/CellularContext.cpp index 746953cfd4..993dfe230f 100644 --- a/features/cellular/framework/device/CellularContext.cpp +++ b/features/cellular/framework/device/CellularContext.cpp @@ -21,11 +21,27 @@ namespace mbed { MBED_WEAK CellularContext *CellularContext::get_default_instance() { // Uses default APN, uname, password from mbed_app.json - static CellularDevice *dev = CellularDevice::get_default_instance(); + CellularDevice *dev = CellularDevice::get_default_instance(); if (!dev) { return NULL; } - static CellularContext *context = dev->create_context(); + + static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT); +#if defined(MDMDCD) && defined(MDM_PIN_POLARITY) + context->set_file_handle(static_cast(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY); +#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY) + return context; +} + +MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance() +{ + // Uses default APN, uname, password from mbed_app.json + CellularDevice *dev = CellularDevice::get_default_instance(); + if (!dev) { + return NULL; + } + + static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT, true); #if defined(MDMDCD) && defined(MDM_PIN_POLARITY) context->set_file_handle(static_cast(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY); #endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY) diff --git a/features/cellular/mbed_lib.json b/features/cellular/mbed_lib.json index cc41f2dbe4..1c13e4f4c7 100644 --- a/features/cellular/mbed_lib.json +++ b/features/cellular/mbed_lib.json @@ -16,6 +16,10 @@ "radio-access-technology": { "help": "Radio access technology to use. Value in integer: GSM=0, GSM_COMPACT=1, UTRAN=2, EGPRS=3, HSDPA=4, HSUPA=5, HSDPA_HSUPA=6, E_UTRAN=7, CATM1=8 ,NB1=9", "value": null + }, + "control-plane-opt": { + "help": "Enables control plane CIoT EPS optimisation", + "value": false } } } diff --git a/features/netsocket/CellularBase.h b/features/netsocket/CellularBase.h index e430653abb..ac4c8cea6a 100644 --- a/features/netsocket/CellularBase.h +++ b/features/netsocket/CellularBase.h @@ -39,6 +39,17 @@ public: */ static CellularBase *get_default_instance(); + /** Set default parameters on a cellular interface. + * + * A cellular interface instantiated directly or using + * CellularBase::get_default_instance() is initially unconfigured. + * This call can be used to set the default parameters that would + * have been set if the interface had been requested using + * NetworkInterface::get_default_instance() (see nsapi JSON + * configuration). + */ + virtual void set_default_parameters(); + /** Set the cellular network credentials. * * Please check documentation of connect() for default behavior of APN settings. diff --git a/features/netsocket/NetworkInterface.h b/features/netsocket/NetworkInterface.h index 5cc74aa41f..87e198a6c7 100644 --- a/features/netsocket/NetworkInterface.h +++ b/features/netsocket/NetworkInterface.h @@ -84,6 +84,17 @@ public: */ static NetworkInterface *get_default_instance(); + /** Set default parameters on an interface. + * + * A network interface instantiated directly or using calls such as + * WiFiInterface::get_default_instance() is initially unconfigured. + * This call can be used to set the default parameters that would + * have been set if the interface had been requested using + * NetworkInterface::get_default_instance() (see nsapi JSON + * configuration). + */ + virtual void set_default_parameters(); + /** Get the local MAC address. * * Provided MAC address is intended for info or debug purposes and diff --git a/features/netsocket/NetworkInterfaceDefaults.cpp b/features/netsocket/NetworkInterfaceDefaults.cpp index fb29ce88f4..33780254cd 100644 --- a/features/netsocket/NetworkInterfaceDefaults.cpp +++ b/features/netsocket/NetworkInterfaceDefaults.cpp @@ -62,6 +62,53 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance() return get_target_default_instance(); } + +/* Helpers to set default parameters - used by NetworkInterface::get_default_instance, + * but exposed for apps which want to get these defaults after requesting a specific type. + */ +void NetworkInterface::set_default_parameters() +{ + +} + +void WiFiInterface::set_default_parameters() +{ +#ifdef MBED_CONF_NSAPI_DEFAULT_WIFI_SSID +#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD +#define MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD NULL +#endif +#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY +#define MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY NONE +#endif +#define concat_(x,y) x##y +#define concat(x,y) concat_(x,y) +#define SECURITY concat(NSAPI_SECURITY_,MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY) + set_credentials(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD, SECURITY); +#endif +} + +void CellularBase::set_default_parameters() +{ + /* CellularBase is expected to attempt to work without any parameters - we + * will try, at least. + */ +#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN +#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME +#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME NULL +#endif +#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD +#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD NULL +#endif + set_credentials(MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME, MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD); +#endif +#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN + set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN); +#endif +#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN + set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN); +#endif +} + /* Finally the dispatch from the JSON default interface type to the specific * subclasses. It's our job to configure - the default NetworkInterface is * preconfigured - the specific subtypes' defaults are not (necessarily). @@ -87,16 +134,7 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance() if (!wifi) { return NULL; } -#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD -#define MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD NULL -#endif -#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY -#define MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY NONE -#endif -#define concat_(x,y) x##y -#define concat(x,y) concat_(x,y) -#define SECURITY concat(NSAPI_SECURITY_,MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY) - wifi->set_credentials(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD, SECURITY); + wifi->set_default_parameters(); return wifi; #else return NULL; @@ -114,24 +152,7 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance() if (!cellular) { return NULL; } - /* CellularBase is expected to attempt to work without any parameters - we - * will try, at least. - */ -#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN -#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME -#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME NULL -#endif -#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD -#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD NULL -#endif - cellular->set_credentials(MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME, MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD); -#endif -#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN - cellular->set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN); -#endif -#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN - cellular->set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN); -#endif + cellular->set_default_parameters(); return cellular; } #elif defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) diff --git a/features/netsocket/WiFiInterface.h b/features/netsocket/WiFiInterface.h index a96a742695..ea976803ff 100644 --- a/features/netsocket/WiFiInterface.h +++ b/features/netsocket/WiFiInterface.h @@ -40,6 +40,17 @@ public: */ static WiFiInterface *get_default_instance(); + /** Set default parameters on a Wi-Fi interface. + * + * A Wi-Fi interface instantiated directly or using + * WiFiInterface::get_default_instance() is initially unconfigured. + * This call can be used to set the default parameters that would + * have been set if the interface had been requested using + * NetworkInterface::get_default_instance() (see nsapi JSON + * configuration). + */ + virtual void set_default_parameters(); + /** Set the Wi-Fi network credentials. * * @param ssid Name of the network to connect to. From 139d506a24d4272784c3e1fbb9237293da1e9105 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Tue, 18 Dec 2018 06:11:52 -0800 Subject: [PATCH 27/41] Cellular: Move power on/off to device and remove CellularPower --- .../AT/at_cellularcontext/unittest.cmake | 1 - .../at_cellulardevicetest.cpp | 45 ++----- .../AT/at_cellulardevice/unittest.cmake | 1 - .../at_cellularpower/at_cellularpowertest.cpp | 76 ------------ .../AT/at_cellularpower/unittest.cmake | 28 ----- .../cellularstatemachinetest.cpp | 11 -- .../cellularstatemachine/unittest.cmake | 1 - UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 28 ++--- UNITTESTS/stubs/AT_CellularPower_stub.cpp | 53 -------- UNITTESTS/stubs/AT_CellularPower_stub.h | 28 ----- UNITTESTS/stubs/CellularDevice_stub.cpp | 2 +- UNITTESTS/target_h/myCellularDevice.h | 14 ++- .../TESTS/api/cellular_device/main.cpp | 4 - .../TESTS/api/cellular_power/main.cpp | 117 ------------------ .../cellular/framework/API/CellularContext.h | 4 +- .../cellular/framework/API/CellularDevice.h | 34 ++--- .../cellular/framework/API/CellularPower.h | 64 ---------- .../framework/AT/AT_CellularDevice.cpp | 42 ++----- .../cellular/framework/AT/AT_CellularDevice.h | 17 +-- .../framework/AT/AT_CellularPower.cpp | 43 ------- .../cellular/framework/AT/AT_CellularPower.h | 44 ------- .../framework/device/CellularDevice.cpp | 2 +- .../framework/device/CellularStateMachine.cpp | 16 +-- .../framework/device/CellularStateMachine.h | 2 - .../MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp | 18 ++- .../MultiTech/DragonflyNano/PPP/SARA4_PPP.h | 3 +- .../PPP/SARA4_PPP_CellularPower.cpp | 49 -------- .../PPP/SARA4_PPP_CellularPower.h | 39 ------ .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 18 ++- .../targets/QUECTEL/UG96/QUECTEL_UG96.h | 3 +- .../UG96/QUECTEL_UG96_CellularPower.cpp | 49 -------- .../QUECTEL/UG96/QUECTEL_UG96_CellularPower.h | 39 ------ .../targets/TELIT/HE910/TELIT_HE910.cpp | 18 ++- .../targets/TELIT/HE910/TELIT_HE910.h | 3 +- .../TELIT/HE910/TELIT_HE910_CellularPower.cpp | 49 -------- .../TELIT/HE910/TELIT_HE910_CellularPower.h | 39 ------ .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 18 ++- .../framework/targets/UBLOX/AT/UBLOX_AT.h | 3 +- .../UBLOX/AT/UBLOX_AT_CellularPower.cpp | 47 ------- .../targets/UBLOX/AT/UBLOX_AT_CellularPower.h | 39 ------ .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 18 ++- .../framework/targets/UBLOX/PPP/UBLOX_PPP.h | 3 +- .../UBLOX/PPP/UBLOX_PPP_CellularPower.cpp | 49 -------- .../UBLOX/PPP/UBLOX_PPP_CellularPower.h | 39 ------ 44 files changed, 154 insertions(+), 1066 deletions(-) delete mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp delete mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake delete mode 100644 UNITTESTS/stubs/AT_CellularPower_stub.cpp delete mode 100644 UNITTESTS/stubs/AT_CellularPower_stub.h delete mode 100644 features/cellular/TESTS/api/cellular_power/main.cpp delete mode 100644 features/cellular/framework/API/CellularPower.h delete mode 100644 features/cellular/framework/AT/AT_CellularPower.cpp delete mode 100644 features/cellular/framework/AT/AT_CellularPower.h delete mode 100644 features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.h delete mode 100644 features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.h delete mode 100644 features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h delete mode 100644 features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.h delete mode 100644 features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.h diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake index 051b3785a7..d5b4bf77ac 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake @@ -27,7 +27,6 @@ set(unittest-test-sources stubs/AT_CellularDevice_stub.cpp stubs/AT_CellularStack_stub.cpp stubs/AT_CellularNetwork_stub.cpp - stubs/AT_CellularPower_stub.cpp stubs/CellularDevice_stub.cpp stubs/CellularStateMachine_stub.cpp stubs/equeue_stub.c diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index cbd03ffec6..abdc0164b5 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -58,19 +58,18 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler) AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; EXPECT_TRUE(dev.open_information(&fh3)); ATHandler_stub::fh_value = &fh1; - EXPECT_TRUE(dev.open_power(&fh1)); // AT fh1 ref count 3 ATHandler_stub::fh_value = NULL; - AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 4 - EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 5 - ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 6 - EXPECT_TRUE(at->get_ref_count() == 6); - delete dev2; // AT fh1 2 refs deleted -> ref count 4 - EXPECT_TRUE(at->get_ref_count() == 4); - AT_CellularDevice dev3(&fh1); // AT fh1 ref count 5 - EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 4 - EXPECT_TRUE(ATHandler_stub::ref_count == 4); + AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3 + EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4 + ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5 + EXPECT_TRUE(at->get_ref_count() == 5); + delete dev2; // AT fh1 2 refs deleted -> ref count 3 + EXPECT_TRUE(at->get_ref_count() == 3); + AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4 + EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3 + EXPECT_TRUE(ATHandler_stub::ref_count == 3); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network) @@ -99,19 +98,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms) EXPECT_TRUE(sms1 == sms); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - - CellularPower *pwr = dev.open_power(NULL); - CellularPower *pwr1 = dev.open_power(&fh1); - - EXPECT_TRUE(pwr); - EXPECT_TRUE(pwr1); - EXPECT_TRUE(pwr1 == pwr); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information) { FileHandle_stub fh1; @@ -151,19 +137,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms) EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - - EXPECT_TRUE(dev.open_power(&fh1)); - AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - EXPECT_TRUE(ATHandler_stub::ref_count == 2); - - dev.close_power(); - EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) { FileHandle_stub fh1; diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake index c271917135..2619045d07 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake @@ -28,7 +28,6 @@ set(unittest-test-sources stubs/AT_CellularNetwork_stub.cpp stubs/ATHandler_stub.cpp stubs/AT_CellularSMS_stub.cpp - stubs/AT_CellularPower_stub.cpp stubs/AT_CellularInformation_stub.cpp stubs/CellularUtil_stub.cpp stubs/AT_CellularBase_stub.cpp diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp deleted file mode 100644 index 257ded8771..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "gtest/gtest.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularPower.h" -#include "FileHandle_stub.h" -#include "ATHandler_stub.h" - -using namespace mbed; -using namespace events; - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -class TestAT_CellularPower : public testing::Test { -protected: - - void SetUp() { - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - } - - void TearDown() { - } -}; -// *INDENT-ON* - - -TEST_F(TestAT_CellularPower, Create) -{ - - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower *pow = new AT_CellularPower(at); - - EXPECT_TRUE(pow != NULL); - - delete pow; -} - -TEST_F(TestAT_CellularPower, test_AT_CellularPower_on) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.on()); -} - -TEST_F(TestAT_CellularPower, test_AT_CellularPower_off) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off()); -} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake deleted file mode 100644 index 82dc0e9b38..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake +++ /dev/null @@ -1,28 +0,0 @@ - -#################### -# UNIT TESTS -#################### - -# Add test specific include paths -set(unittest-includes ${unittest-includes} - features/cellular/framework/common/util - ../features/cellular/framework/common - ../features/cellular/framework/AT - ../features/frameworks/mbed-client-randlib/mbed-client-randlib -) - -# Source files -set(unittest-sources - ../features/cellular/framework/AT/AT_CellularPower.cpp -) - -# Test files -set(unittest-test-sources - features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp - stubs/ATHandler_stub.cpp - stubs/AT_CellularBase_stub.cpp - stubs/EventQueue_stub.cpp - stubs/FileHandle_stub.cpp - stubs/CellularUtil_stub.cpp - stubs/mbed_assert_stub.c -) diff --git a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp index 1fb99fed77..5466b72ae6 100644 --- a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/cellularstatemachinetest.cpp @@ -20,7 +20,6 @@ #include "CellularDevice.h" #include "AT_CellularDevice_stub.h" #include "FileHandle_stub.h" -#include "AT_CellularPower_stub.h" #include "AT_CellularNetwork_stub.h" #include "myCellularDevice.h" #include "Thread_stub.h" @@ -48,7 +47,6 @@ protected: void SetUp() { Thread_stub::osStatus_value = osOK; - AT_CellularPower_stub::fail_counter = 0; } void TearDown() @@ -268,8 +266,6 @@ TEST_F(TestCellularStateMachine, test_stop) equeue_stub.void_ptr = &ptr; equeue_stub.call_cb_immediately = true; - AT_CellularPower_stub::fail_counter = 1; - ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_power_on()); ut.stop(); // thread and power are created, now stop will delete them @@ -281,7 +277,6 @@ TEST_F(TestCellularStateMachine, test_stop) ASSERT_EQ(NSAPI_ERROR_OK, err); ut.set_cellular_callback(&cellular_callback); - AT_CellularPower_stub::fail_counter = 1; ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); @@ -316,7 +311,6 @@ TEST_F(TestCellularStateMachine, test_run_to_state) equeue_stub.call_cb_immediately = true; ut.set_cellular_callback(&cellular_callback); - AT_CellularPower_stub::fail_counter = 0; ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_power_on()); UT_CellularState current_state; @@ -326,7 +320,6 @@ TEST_F(TestCellularStateMachine, test_run_to_state) ASSERT_EQ(UT_STATE_POWER_ON, target_state); ut.reset(); - AT_CellularPower_stub::set_at_fail_counter = 1; ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); (void)ut.get_current_status(current_state, target_state); ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); @@ -334,21 +327,18 @@ TEST_F(TestCellularStateMachine, test_run_to_state) ut.ready_urc_cb(); ut.reset(); - AT_CellularPower_stub::fail_counter = 1; ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); (void)ut.get_current_status(current_state, target_state); ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); ASSERT_EQ(UT_STATE_DEVICE_READY, target_state); ut.reset(); - AT_CellularPower_stub::fail_counter = 2; ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); (void)ut.get_current_status(current_state, target_state); ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); ASSERT_EQ(UT_STATE_DEVICE_READY, target_state); ut.reset(); - AT_CellularPower_stub::fail_counter = 3; ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready()); (void)ut.get_current_status(current_state, target_state); ASSERT_EQ(UT_STATE_DEVICE_READY, current_state); @@ -356,7 +346,6 @@ TEST_F(TestCellularStateMachine, test_run_to_state) ut.reset(); AT_CellularDevice_stub::init_module_failure_count = 1; - AT_CellularPower_stub::fail_counter = 0; AT_CellularNetwork_stub::set_registration_urc_fail_counter = 4; ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_sim_ready()); (void) ut.get_current_status(current_state, target_state); diff --git a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake index 49d24d3523..ac5fcfee74 100644 --- a/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake @@ -28,7 +28,6 @@ set(unittest-test-sources stubs/SerialBase_stub.cpp stubs/ATHandler_stub.cpp stubs/AT_CellularNetwork_stub.cpp - stubs/AT_CellularPower_stub.cpp stubs/AT_CellularBase_stub.cpp stubs/AT_CellularContext_stub.cpp stubs/AT_CellularDevice_stub.cpp diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index e5665199b4..9cf37d3a1a 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -17,7 +17,6 @@ #include "AT_CellularDevice_stub.h" #include "AT_CellularNetwork.h" -#include "AT_CellularPower.h" #include "AT_CellularContext.h" #include "ATHandler.h" @@ -34,7 +33,7 @@ int AT_CellularDevice_stub::get_sim_failure_count = 0; bool AT_CellularDevice_stub::pin_needed = false; AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), - _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), + _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) { } @@ -42,7 +41,16 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _netw AT_CellularDevice::~AT_CellularDevice() { delete _network; - delete _power; +} + +nsapi_error_t AT_CellularDevice::power_on() +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t AT_CellularDevice::power_off() +{ + return NSAPI_ERROR_UNSUPPORTED; } ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) @@ -87,11 +95,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) return NULL; } -CellularPower *AT_CellularDevice::open_power(FileHandle *fh) -{ - return new AT_CellularPower(*ATHandler::get_instance(fh, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on)); -} - CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) { return NULL; @@ -105,10 +108,6 @@ void AT_CellularDevice::close_sms() { } -void AT_CellularDevice::close_power() -{ -} - void AT_CellularDevice::close_information() { } @@ -142,11 +141,6 @@ AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at) return NULL; } -AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at) -{ - return NULL; -} - AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) { return NULL; diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp deleted file mode 100644 index e599788765..0000000000 --- a/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) , Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AT_CellularPower_stub.h" -#include "CellularUtil.h" -#include "CellularLog.h" - -using namespace mbed_cellular_util; -using namespace mbed; - -nsapi_error_t AT_CellularPower_stub::nsapi_error_value = 0; -int AT_CellularPower_stub::fail_counter = 0; -int AT_CellularPower_stub::set_at_fail_counter = 0; - -AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularPower::~AT_CellularPower() -{ -} - -nsapi_error_t AT_CellularPower::on() -{ - if (AT_CellularPower_stub::fail_counter) { - AT_CellularPower_stub::fail_counter--; - return NSAPI_ERROR_DEVICE_ERROR; - } - return AT_CellularPower_stub::nsapi_error_value; -} - -nsapi_error_t AT_CellularPower::off() -{ - if (AT_CellularPower_stub::fail_counter) { - AT_CellularPower_stub::fail_counter--; - return NSAPI_ERROR_DEVICE_ERROR; - } - return AT_CellularPower_stub::nsapi_error_value; -} diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.h b/UNITTESTS/stubs/AT_CellularPower_stub.h deleted file mode 100644 index 1ef2def67b..0000000000 --- a/UNITTESTS/stubs/AT_CellularPower_stub.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef AT_CELLULARPOWER_STUB_H_ -#define AT_CELLULARPOWER_STUB_H_ - -#include "AT_CellularPower.h" - -namespace AT_CellularPower_stub { -extern nsapi_error_t nsapi_error_value; -extern int fail_counter; -extern int set_at_fail_counter; -} - -#endif /* AT_CELLULARPOWER_STUB_H_ */ diff --git a/UNITTESTS/stubs/CellularDevice_stub.cpp b/UNITTESTS/stubs/CellularDevice_stub.cpp index 433dd47b08..7309837f06 100644 --- a/UNITTESTS/stubs/CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/CellularDevice_stub.cpp @@ -30,7 +30,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance() return NULL; } -CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), +CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0) { } diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 6c4292a67d..229641f4c6 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -27,7 +27,6 @@ using namespace events; namespace mbed { -class CellularPower; class CellularSMS; class CellularInformation; class CellularContext; @@ -80,12 +79,17 @@ public: return _network; } - virtual CellularSMS *open_sms(FileHandle *fh = NULL) + nsapi_error_t power_on() { - return NULL; + return NSAPI_ERROR_UNSUPPORTED; } - virtual CellularPower *open_power(FileHandle *fh = NULL) + nsapi_error_t power_off() + { + return NSAPI_ERROR_UNSUPPORTED; + } + + virtual CellularSMS *open_sms(FileHandle *fh = NULL) { return NULL; } @@ -102,8 +106,6 @@ public: virtual void close_sms() {} - virtual void close_power() {} - virtual void close_information() {} virtual void set_timeout(int timeout) {} diff --git a/features/cellular/TESTS/api/cellular_device/main.cpp b/features/cellular/TESTS/api/cellular_device/main.cpp index 294ff10e16..ca1095d7f8 100644 --- a/features/cellular/TESTS/api/cellular_device/main.cpp +++ b/features/cellular/TESTS/api/cellular_device/main.cpp @@ -74,10 +74,6 @@ static void open_close_interfaces() TEST_ASSERT(info != NULL); device->close_information(); - CellularPower *power = device->open_power(&cellular_serial); - TEST_ASSERT(power != NULL); - device->close_power(); - CellularSMS *sms = device->open_sms(&cellular_serial); TEST_ASSERT(sms != NULL); device->close_sms(); diff --git a/features/cellular/TESTS/api/cellular_power/main.cpp b/features/cellular/TESTS/api/cellular_power/main.cpp deleted file mode 100644 index 5990c5200d..0000000000 --- a/features/cellular/TESTS/api/cellular_power/main.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#if !defined(MBED_CONF_NSAPI_PRESENT) -#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. -#endif - -#include "CellularUtil.h" // for CELLULAR_ helper macros -#include "CellularTargets.h" - -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - -#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN -#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. -#endif - -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" - -#include "mbed.h" - -#include "AT_CellularPower.h" -#include "CellularDevice.h" -#include "../../cellular_tests_common.h" -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) - -#define NETWORK_TIMEOUT (180*1000) - -static CellularDevice *cellular_device; - -static void urc_callback() -{ -} - -static void wait_for_power(CellularPower *pwr) -{ - cellular_device->set_ready_cb(&urc_callback); - - int sanity_count = 0; - nsapi_error_t err = cellular_device->init(); - while (err != NSAPI_ERROR_OK) { - sanity_count++; - wait(1); - TEST_ASSERT(sanity_count < 40); - err = cellular_device->init(); - } - - TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK); - cellular_device->set_ready_cb(0); -} - -static void test_power_interface() -{ - const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE); - cellular_device = CellularDevice::get_default_instance(); - cellular_device->set_timeout(9000); - CellularPower *pwr = cellular_device->open_power(); - TEST_ASSERT(pwr != NULL); - - nsapi_error_t err = pwr->on(); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); - wait_for_power(pwr); - - err = pwr->off(); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); - -} - -using namespace utest::v1; - -static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) -{ - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - -static Case cases[] = { - Case("CellularPower test interface", test_power_interface, greentea_failure_handler) -}; - -static utest::v1::status_t test_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(10 * 60, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -static Specification specification(test_setup, cases); - -int main() -{ -#if MBED_CONF_MBED_TRACE_ENABLE - trace_open(); -#endif - int ret = Harness::run(specification); -#if MBED_CONF_MBED_TRACE_ENABLE - trace_close(); -#endif - return ret; -} diff --git a/features/cellular/framework/API/CellularContext.h b/features/cellular/framework/API/CellularContext.h index 95abecb76d..0f02513410 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -169,9 +169,9 @@ public: // from NetworkInterface /** Start the interface * - * Powers on the device and does the initializations for communication with the modem. + * Initializes the modem for communication. * By default, this API is synchronous. API can be set to asynchronous with method set_blocking(...). - * In synchronous and asynchronous mode, the application can get result in from callback, which is set with + * In synchronous and asynchronous mode application can get result in from callback which is set with * attach(...) * * @return NSAPI_ERROR_OK on success diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index cb32511fbc..8946f8cd14 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -26,7 +26,6 @@ namespace mbed { -class CellularPower; class CellularSMS; class CellularInformation; class CellularNetwork; @@ -75,6 +74,24 @@ public: */ virtual ~CellularDevice(); + /** Set cellular device power on. + * + * @post init must be called after power_on to setup module + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_UNSUPPORTED if there is no implementation + */ + virtual nsapi_error_t power_on() = 0; + + /** Set cellular device power off. + * + * @pre shutdown must be called before power_down to quit cellular network + * + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_UNSUPPORTED if there is no implementation + */ + virtual nsapi_error_t power_off() = 0; + /** Open the SIM card by setting the pin code for SIM. * * @param sim_pin PIN for the SIM card @@ -160,7 +177,7 @@ public: /** Start the interface * - * Powers on the device and does the initializations for communication with the modem. + * Initializes the modem for communication. * API is asynchronous. Application can get results from CellularContext callback, which is set * with attach(...), or callback, which is set by attach(...), in this class. * @@ -231,14 +248,6 @@ public: */ virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0; - /** Create new CellularPower interface. - * - * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default - * file handle is used. - * @return New instance of interface CellularPower. - */ - virtual CellularPower *open_power(FileHandle *fh = NULL) = 0; - /** Create new CellularInformation interface. * * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default @@ -255,10 +264,6 @@ public: */ virtual void close_sms() = 0; - /** Closes the opened CellularPower by deleting the CellularPower instance. - */ - virtual void close_power() = 0; - /** Closes the opened CellularInformation by deleting the CellularInformation instance. */ virtual void close_information() = 0; @@ -361,7 +366,6 @@ protected: int _network_ref_count; int _sms_ref_count; - int _power_ref_count; int _info_ref_count; FileHandle *_fh; events::EventQueue _queue; diff --git a/features/cellular/framework/API/CellularPower.h b/features/cellular/framework/API/CellularPower.h deleted file mode 100644 index 5c2ce68f3a..0000000000 --- a/features/cellular/framework/API/CellularPower.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef CELLULAR_API_CELLULARPOWER_H_ -#define CELLULAR_API_CELLULARPOWER_H_ - -#include "nsapi_types.h" -#include "Callback.h" - -namespace mbed { - -/** - * Class CellularPower - * - * An interface that provides power handling functions for modem/module. - */ -class CellularPower { -protected: - // friend of CellularDevice so that it's the only way to close/delete this class. - friend class CellularDevice; - - /** - * virtual Destructor - */ - virtual ~CellularPower() {} - -public: - /** Set cellular device power on. Default implementation is empty. - * Device power on/off is modem/board specific behavior and must be done on inherited class if needed. - * Power on is done by toggling power pin/button. - * - * @remark init must be called to initialize cellular device - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem - */ - virtual nsapi_error_t on() = 0; - - /** Set cellular device power off. Default implementation is empty. - * Device power on/off is modem/board specific behavior and must be done on inherited class if needed. - * Power off is done by toggling power pin/button. - * - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem - */ - virtual nsapi_error_t off() = 0; -}; - -} // namespace mbed - -#endif /* CELLULAR_API_CELLULARPOWER_H_ */ diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 91930994c7..37c8fe6a28 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -19,7 +19,6 @@ #include "AT_CellularDevice.h" #include "AT_CellularInformation.h" #include "AT_CellularNetwork.h" -#include "AT_CellularPower.h" #include "AT_CellularSMS.h" #include "AT_CellularContext.h" #include "AT_CellularStack.h" @@ -36,7 +35,7 @@ using namespace mbed; const int MAX_SIM_RESPONSE_LENGTH = 16; AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), - _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), + _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) { MBED_ASSERT(fh); @@ -51,12 +50,10 @@ AT_CellularDevice::~AT_CellularDevice() // make sure that all is deleted even if somewhere close was not called and reference counting is messed up. _network_ref_count = 1; _sms_ref_count = 1; - _power_ref_count = 1; _info_ref_count = 1; close_network(); close_sms(); - close_power(); close_information(); AT_CellularContext *curr = _context_list; @@ -72,6 +69,16 @@ AT_CellularDevice::~AT_CellularDevice() release_at_handler(_at); } +nsapi_error_t AT_CellularDevice::power_on() +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t AT_CellularDevice::power_off() +{ + return NSAPI_ERROR_UNSUPPORTED; +} + // each parser is associated with one filehandle (that is UART) ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) { @@ -250,15 +257,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) return _sms; } -CellularPower *AT_CellularDevice::open_power(FileHandle *fh) -{ - if (!_power) { - _power = open_power_impl(*get_at_handler(fh)); - } - _power_ref_count++; - return _power; -} - CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) { if (!_information) { @@ -278,11 +276,6 @@ AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at) return new AT_CellularSMS(at); } -AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at) -{ - return new AT_CellularPower(at); -} - AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) { return new AT_CellularInformation(at); @@ -314,19 +307,6 @@ void AT_CellularDevice::close_sms() } } -void AT_CellularDevice::close_power() -{ - if (_power) { - _power_ref_count--; - if (_power_ref_count == 0) { - ATHandler *atHandler = &_power->get_at_handler(); - delete _power; - _power = NULL; - release_at_handler(atHandler); - } - } -} - void AT_CellularDevice::close_information() { if (_information) { diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 195cb46157..5e087cc952 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -25,7 +25,6 @@ namespace mbed { class ATHandler; class AT_CellularInformation; class AT_CellularNetwork; -class AT_CellularPower; class AT_CellularSMS; class AT_CellularContext; @@ -40,6 +39,10 @@ public: AT_CellularDevice(FileHandle *fh); virtual ~AT_CellularDevice(); + virtual nsapi_error_t power_on(); + + virtual nsapi_error_t power_off(); + virtual nsapi_error_t set_pin(const char *sim_pin); virtual nsapi_error_t get_sim_state(SimState &state); @@ -54,16 +57,12 @@ public: virtual CellularSMS *open_sms(FileHandle *fh = NULL); - virtual CellularPower *open_power(FileHandle *fh = NULL); - virtual CellularInformation *open_information(FileHandle *fh = NULL); virtual void close_network(); virtual void close_sms(); - virtual void close_power(); - virtual void close_information(); virtual void set_timeout(int timeout); @@ -119,13 +118,6 @@ public: */ virtual AT_CellularSMS *open_sms_impl(ATHandler &at); - /** Create new instance of AT_CellularPower or if overridden, modem specific implementation. - * - * @param at ATHandler reference for communication with the modem. - * @return new instance of class AT_CellularPower - */ - virtual AT_CellularPower *open_power_impl(ATHandler &at); - /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation. * * @param at ATHandler reference for communication with the modem. @@ -137,7 +129,6 @@ public: AT_CellularNetwork *_network; AT_CellularSMS *_sms; - AT_CellularPower *_power; AT_CellularInformation *_information; AT_CellularContext *_context_list; int _default_timeout; diff --git a/features/cellular/framework/AT/AT_CellularPower.cpp b/features/cellular/framework/AT/AT_CellularPower.cpp deleted file mode 100644 index 6ba70733a3..0000000000 --- a/features/cellular/framework/AT/AT_CellularPower.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AT_CellularPower.h" -#include "CellularUtil.h" -#include "CellularLog.h" -#include "CellularTargets.h" -#include "nsapi_types.h" - -using namespace mbed_cellular_util; -using namespace mbed; - -AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularPower::~AT_CellularPower() -{ -} - -nsapi_error_t AT_CellularPower::on() -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t AT_CellularPower::off() -{ - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/AT/AT_CellularPower.h b/features/cellular/framework/AT/AT_CellularPower.h deleted file mode 100644 index 7e4f1c9372..0000000000 --- a/features/cellular/framework/AT/AT_CellularPower.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AT_CELLULAR_POWER_H_ -#define AT_CELLULAR_POWER_H_ - -#include "CellularPower.h" -#include "AT_CellularBase.h" - -namespace mbed { - -/** - * Class AT_CellularPower - * - * Class that provides power handling functions for modem/module. - */ -class AT_CellularPower : public CellularPower, public AT_CellularBase { -public: - AT_CellularPower(ATHandler &atHandler); - virtual ~AT_CellularPower(); - -public: - virtual nsapi_error_t on(); - - virtual nsapi_error_t off(); -}; - -} // namespace mbed - -#endif /* AT_CELLULAR_POWER_H_ */ diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index a886f5eb3d..2f79e7ab23 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -48,7 +48,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance() } #endif // CELLULAR_DEVICE -CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), +CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0) { MBED_ASSERT(fh); diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index 4998ad799e..59f3cd2d01 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -17,7 +17,6 @@ #include "CellularStateMachine.h" #include "CellularDevice.h" -#include "CellularPower.h" #include "CellularLog.h" #include "Thread.h" #include "UARTSerial.h" @@ -46,7 +45,7 @@ namespace mbed { CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) : _cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state), - _event_status_cb(0), _network(0), _power(0), _queue(queue), _queue_thread(0), _sim_pin(0), + _event_status_cb(0), _network(0), _queue(queue), _queue_thread(0), _sim_pin(0), _retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false), _plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE), _network_status(0) @@ -101,10 +100,6 @@ void CellularStateMachine::stop() reset(); _event_id = STM_STOPPED; - if (_power) { - _cellularDevice.close_power(); - _power = NULL; - } if (_network) { _cellularDevice.close_network(); @@ -114,10 +109,10 @@ void CellularStateMachine::stop() bool CellularStateMachine::power_on() { - _cb_data.error = _power->on(); + _cb_data.error = _cellularDevice.power_on(); if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) { tr_warn("Power on failed. Try to power off/on."); - _cb_data.error = _power->off(); + _cb_data.error = _cellularDevice.power_off(); if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) { tr_error("Power off failed!"); } @@ -337,9 +332,6 @@ void CellularStateMachine::state_init() { _cellularDevice.set_timeout(TIMEOUT_POWER_ON); tr_info("Start connecting (timeout %d s)", TIMEOUT_POWER_ON / 1000); - if (!_power) { - _power = _cellularDevice.open_power(); - } _cb_data.error = _cellularDevice.is_ready(); if (_cb_data.error != NSAPI_ERROR_OK) { _event_timeout = _start_time; @@ -386,8 +378,6 @@ bool CellularStateMachine::device_ready() _event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t)&_cb_data); } _cellularDevice.set_ready_cb(0); - _cellularDevice.close_power(); - _power = NULL; return true; } diff --git a/features/cellular/framework/device/CellularStateMachine.h b/features/cellular/framework/device/CellularStateMachine.h index 9ac914d69a..0989be9c80 100644 --- a/features/cellular/framework/device/CellularStateMachine.h +++ b/features/cellular/framework/device/CellularStateMachine.h @@ -28,7 +28,6 @@ class Thread; namespace mbed { -class CellularPower; class CellularDevice; const int RETRY_ARRAY_SIZE = 10; @@ -167,7 +166,6 @@ private: Callback _event_status_cb; CellularNetwork *_network; - CellularPower *_power; events::EventQueue &_queue; rtos::Thread *_queue_thread; diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index a7312cdf05..b557ca5afa 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -15,9 +15,10 @@ * limitations under the License. */ +#include "onboard_modem_api.h" + #include "SARA4_PPP.h" #include "SARA4_PPP_CellularNetwork.h" -#include "SARA4_PPP_CellularPower.h" using namespace mbed; using namespace events; @@ -48,8 +49,19 @@ AT_CellularNetwork *SARA4_PPP::open_network_impl(ATHandler &at) return new SARA4_PPP_CellularNetwork(at); } -AT_CellularPower *SARA4_PPP::open_power_impl(ATHandler &at) +nsapi_error_t SARA4_PPP::power_on() { - return new SARA4_PPP_CellularPower(at); +#if MODEM_ON_BOARD + ::onboard_modem_init(); + ::onboard_modem_power_up(); +#endif + return NSAPI_ERROR_OK; } +nsapi_error_t SARA4_PPP::power_off() +{ +#if MODEM_ON_BOARD + ::onboard_modem_power_down(); +#endif + return NSAPI_ERROR_OK; +} diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h index 3f4c580994..31892c5c87 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h @@ -30,7 +30,8 @@ public: public: // CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularPower *open_power_impl(ATHandler &at); + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); }; } // namespace mbed diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.cpp deleted file mode 100644 index 7cb1684481..0000000000 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SARA4_PPP_CellularPower.h" - -#include "onboard_modem_api.h" - -using namespace mbed; - -SARA4_PPP_CellularPower::SARA4_PPP_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ - -} - -SARA4_PPP_CellularPower::~SARA4_PPP_CellularPower() -{ - -} - -nsapi_error_t SARA4_PPP_CellularPower::on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t SARA4_PPP_CellularPower::off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.h b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.h deleted file mode 100644 index 39abd60fad..0000000000 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularPower.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SARA4_PPP_CELLULARPOWER_H_ -#define SARA4_PPP_CELLULARPOWER_H_ - -#include "AT_CellularPower.h" - -namespace mbed { - -class SARA4_PPP_CellularPower : public AT_CellularPower { -public: - SARA4_PPP_CellularPower(ATHandler &atHandler); - virtual ~SARA4_PPP_CellularPower(); - -public: //from CellularPower - - virtual nsapi_error_t on(); - - virtual nsapi_error_t off(); -}; - -} // namespace mbed - -#endif // SARA4_PPP_CELLULARPOWER_H_ diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index a22d17d8b6..7e590b15da 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -15,8 +15,8 @@ * limitations under the License. */ +#include "onboard_modem_api.h" #include "QUECTEL_UG96.h" -#include "QUECTEL_UG96_CellularPower.h" #include "QUECTEL_UG96_CellularContext.h" #include "AT_CellularNetwork.h" @@ -48,9 +48,21 @@ QUECTEL_UG96::~QUECTEL_UG96() { } -AT_CellularPower *QUECTEL_UG96::open_power_impl(ATHandler &at) +nsapi_error_t QUECTEL_UG96::power_on() { - return new QUECTEL_UG96_CellularPower(at); +#if MODEM_ON_BOARD + ::onboard_modem_init(); + ::onboard_modem_power_up(); +#endif + return NSAPI_ERROR_OK; +} + +nsapi_error_t QUECTEL_UG96::power_off() +{ +#if MODEM_ON_BOARD + ::onboard_modem_power_down(); +#endif + return NSAPI_ERROR_OK; } AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h index 1682e45f4c..499e877c3f 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h @@ -36,7 +36,8 @@ public: virtual ~QUECTEL_UG96(); protected: // AT_CellularDevice - virtual AT_CellularPower *open_power_impl(ATHandler &at); + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); public: // NetworkInterface diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.cpp deleted file mode 100644 index a7b754cd3c..0000000000 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_UG96_CellularPower.h" - -#include "onboard_modem_api.h" - -using namespace mbed; - -QUECTEL_UG96_CellularPower::QUECTEL_UG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ - -} - -QUECTEL_UG96_CellularPower::~QUECTEL_UG96_CellularPower() -{ - -} - -nsapi_error_t QUECTEL_UG96_CellularPower::on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t QUECTEL_UG96_CellularPower::off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.h deleted file mode 100644 index f28943c97d..0000000000 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularPower.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef QUECTEL_UG96_CELLULARPOWER_H_ -#define QUECTEL_UG96_CELLULARPOWER_H_ - -#include "AT_CellularPower.h" - -namespace mbed { - -class QUECTEL_UG96_CellularPower : public AT_CellularPower { -public: - QUECTEL_UG96_CellularPower(ATHandler &atHandler); - virtual ~QUECTEL_UG96_CellularPower(); - -public: //from CellularPower - - virtual nsapi_error_t on(); - - virtual nsapi_error_t off(); -}; - -} // namespace mbed - -#endif // QUECTEL_UG96_CELLULARPOWER_H_ diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 0342b2295d..93f1a19bd0 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -15,8 +15,8 @@ * limitations under the License. */ +#include "onboard_modem_api.h" #include "TELIT_HE910.h" -#include "TELIT_HE910_CellularPower.h" #include "AT_CellularNetwork.h" using namespace mbed; @@ -43,9 +43,21 @@ TELIT_HE910::~TELIT_HE910() { } -AT_CellularPower *TELIT_HE910::open_power_impl(ATHandler &at) +nsapi_error_t TELIT_HE910::power_on() { - return new TELIT_HE910_CellularPower(at); +#if MODEM_ON_BOARD + ::onboard_modem_init(); + ::onboard_modem_power_up(); +#endif + return NSAPI_ERROR_OK; +} + +nsapi_error_t TELIT_HE910::power_off() +{ +#if MODEM_ON_BOARD + ::onboard_modem_power_down(); +#endif + return NSAPI_ERROR_OK; } uint16_t TELIT_HE910::get_send_delay() const diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h index 999dff614b..eb8945879d 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h @@ -31,7 +31,8 @@ public: virtual ~TELIT_HE910(); protected: // AT_CellularDevice - virtual AT_CellularPower *open_power_impl(ATHandler &at); + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); virtual uint16_t get_send_delay() const; virtual nsapi_error_t init(); }; diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp deleted file mode 100644 index 32a33cb8a9..0000000000 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "TELIT_HE910_CellularPower.h" -// for modem powering up&down -#include "onboard_modem_api.h" - -using namespace mbed; - -TELIT_HE910_CellularPower::TELIT_HE910_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ - -} - -TELIT_HE910_CellularPower::~TELIT_HE910_CellularPower() -{ - -} - -nsapi_error_t TELIT_HE910_CellularPower::on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t TELIT_HE910_CellularPower::off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h deleted file mode 100644 index 2f3d9be7b2..0000000000 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910_CellularPower.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef TELIT_HE910_CELLULAR_POWER_H_ -#define TELIT_HE910_CELLULAR_POWER_H_ - -#include "AT_CellularPower.h" - -namespace mbed { - -class TELIT_HE910_CellularPower : public AT_CellularPower { -public: - TELIT_HE910_CellularPower(ATHandler &atHandler); - virtual ~TELIT_HE910_CellularPower(); - -public: //from CellularPower - - virtual nsapi_error_t on(); - - virtual nsapi_error_t off(); -}; - -} // namespace mbed - -#endif // TELIT_HE910_CELLULAR_POWER_H_ diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index 6ae10d3b55..d925374aec 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -15,9 +15,9 @@ * limitations under the License. */ +#include "onboard_modem_api.h" #include "UBLOX_AT.h" #include "UBLOX_AT_CellularNetwork.h" -#include "UBLOX_AT_CellularPower.h" #include "UBLOX_AT_CellularContext.h" using namespace mbed; @@ -64,9 +64,21 @@ AT_CellularNetwork *UBLOX_AT::open_network_impl(ATHandler &at) return new UBLOX_AT_CellularNetwork(at); } -AT_CellularPower *UBLOX_AT::open_power_impl(ATHandler &at) +nsapi_error_t UBLOX_AT::power_on() { - return new UBLOX_AT_CellularPower(at); +#if MODEM_ON_BOARD + ::onboard_modem_init(); + ::onboard_modem_power_up(); +#endif + return NSAPI_ERROR_OK; +} + +nsapi_error_t UBLOX_AT::power_off() +{ +#if MODEM_ON_BOARD + ::onboard_modem_power_down(); +#endif + return NSAPI_ERROR_OK; } AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h index e4b95dbb3e..4f19ce3ad4 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h @@ -28,8 +28,9 @@ public: virtual ~UBLOX_AT(); protected: // AT_CellularDevice + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.cpp deleted file mode 100644 index aaec18f084..0000000000 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "UBLOX_AT_CellularPower.h" - -#include "onboard_modem_api.h" - -using namespace mbed; - -UBLOX_AT_CellularPower::UBLOX_AT_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ -} - -UBLOX_AT_CellularPower::~UBLOX_AT_CellularPower() -{ -} - -nsapi_error_t UBLOX_AT_CellularPower::on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t UBLOX_AT_CellularPower::off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.h deleted file mode 100644 index b321822506..0000000000 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UBLOX_AT_CELLULARPOWER_H_ -#define UBLOX_AT_CELLULARPOWER_H_ - -#include "AT_CellularPower.h" - -namespace mbed { - -class UBLOX_AT_CellularPower : public AT_CellularPower { -public: - UBLOX_AT_CellularPower(ATHandler &atHandler); - virtual ~UBLOX_AT_CellularPower(); - -public: //from CellularPower - - virtual nsapi_error_t on(); - - virtual nsapi_error_t off(); -}; - -} // namespace mbed - -#endif // UBLOX_AT_CELLULARPOWER_H_ diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index 533c2fbdae..621aa4ffbc 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -15,8 +15,8 @@ * limitations under the License. */ +#include "onboard_modem_api.h" #include "UBLOX_PPP.h" -#include "UBLOX_PPP_CellularPower.h" #include "AT_CellularNetwork.h" using namespace mbed; @@ -57,7 +57,19 @@ UBLOX_PPP::~UBLOX_PPP() { } -AT_CellularPower *UBLOX_PPP::open_power_impl(ATHandler &at) +nsapi_error_t UBLOX_PPP::power_on() { - return new UBLOX_PPP_CellularPower(at); +#if MODEM_ON_BOARD + ::onboard_modem_init(); + ::onboard_modem_power_up(); +#endif + return NSAPI_ERROR_OK; +} + +nsapi_error_t UBLOX_PPP::power_off() +{ +#if MODEM_ON_BOARD + ::onboard_modem_power_down(); +#endif + return NSAPI_ERROR_OK; } diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h index dc78de14a1..4e0f529426 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h @@ -28,7 +28,8 @@ public: virtual ~UBLOX_PPP(); protected: // AT_CellularDevice - virtual AT_CellularPower *open_power_impl(ATHandler &at); + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); }; } // namespace mbed diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.cpp deleted file mode 100644 index 8cb78aab2f..0000000000 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "UBLOX_PPP_CellularPower.h" - -#include "onboard_modem_api.h" - -using namespace mbed; - -UBLOX_PPP_CellularPower::UBLOX_PPP_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ - -} - -UBLOX_PPP_CellularPower::~UBLOX_PPP_CellularPower() -{ - -} - -nsapi_error_t UBLOX_PPP_CellularPower::on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t UBLOX_PPP_CellularPower::off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.h deleted file mode 100644 index c9d701ca64..0000000000 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP_CellularPower.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UBLOX_PPP_CELLULARPOWER_H_ -#define UBLOX_PPP_CELLULARPOWER_H_ - -#include "AT_CellularPower.h" - -namespace mbed { - -class UBLOX_PPP_CellularPower : public AT_CellularPower { -public: - UBLOX_PPP_CellularPower(ATHandler &atHandler); - virtual ~UBLOX_PPP_CellularPower(); - -public: //from CellularPower - - virtual nsapi_error_t on(); - - virtual nsapi_error_t off(); -}; - -} // namespace mbed - -#endif // UBLOX_PPP_CELLULARPOWER_H_ From 59972b66596c0a057ed59e1f391a298ffc95ecbc Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Tue, 18 Dec 2018 23:11:32 -0800 Subject: [PATCH 28/41] Cellular: Remove netsocket/generic_modem_driver --- .../framework/device/CellularContext.cpp | 5 + .../OnboardCellularInterface.cpp | 82 -- .../OnboardCellularInterface.h | 174 ---- .../PPPCellularInterface.cpp | 849 ------------------ .../PPPCellularInterface.h | 414 --------- .../unit_tests/default/gmd_ut_config_header.h | 69 -- .../TESTS/unit_tests/default/main.cpp | 435 --------- .../unit_tests/default/template_mbed_app.txt | 68 -- .../UARTCellularInterface.cpp | 39 - .../UARTCellularInterface.h | 77 -- .../{generic_modem_driver => }/mbed_lib.json | 0 11 files changed, 5 insertions(+), 2207 deletions(-) delete mode 100644 features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.cpp delete mode 100644 features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.h delete mode 100644 features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.cpp delete mode 100644 features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.h delete mode 100644 features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/gmd_ut_config_header.h delete mode 100644 features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/main.cpp delete mode 100644 features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/template_mbed_app.txt delete mode 100644 features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.cpp delete mode 100644 features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.h rename features/netsocket/cellular/{generic_modem_driver => }/mbed_lib.json (100%) diff --git a/features/cellular/framework/device/CellularContext.cpp b/features/cellular/framework/device/CellularContext.cpp index 993dfe230f..2bf78c819d 100644 --- a/features/cellular/framework/device/CellularContext.cpp +++ b/features/cellular/framework/device/CellularContext.cpp @@ -16,6 +16,11 @@ */ #include "CellularContext.h" +MBED_WEAK CellularBase *CellularBase::get_target_default_instance() +{ + return mbed::CellularContext::get_default_instance(); +} + namespace mbed { #ifdef CELLULAR_DEVICE MBED_WEAK CellularContext *CellularContext::get_default_instance() diff --git a/features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.cpp b/features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.cpp deleted file mode 100644 index a1e39a8853..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mbed_toolchain.h" -#include "CellularBase.h" -#include "OnboardCellularInterface.h" - -#ifndef CELLULAR_DEVICE - -#if MODEM_ON_BOARD && MODEM_ON_BOARD_UART && NSAPI_PPP_AVAILABLE - -#include "onboard_modem_api.h" - -/** - * OnboardCellularInterface is an on-board specific implementation. - * - */ - -OnboardCellularInterface::OnboardCellularInterface(bool debug) : - UARTCellularInterface(MDMTXD, MDMRXD, MDMDCD, MDMRTS, - MDMCTS, MDMRI, MDMDTR, MDMDSR, - MBED_CONF_PPP_CELL_IFACE_BAUD_RATE, MDM_PIN_POLARITY, debug) -{ -} - -OnboardCellularInterface::~OnboardCellularInterface() -{ -} - -void OnboardCellularInterface::modem_init() -{ - ::onboard_modem_init(); -} - -void OnboardCellularInterface::modem_deinit() -{ - ::onboard_modem_deinit(); -} - -void OnboardCellularInterface::modem_power_up() -{ - ::onboard_modem_power_up(); -} - -void OnboardCellularInterface::modem_power_down() -{ - ::onboard_modem_power_down(); -} -#endif - -#endif // CELLULAR_DEVICE - -#ifdef CELLULAR_DEVICE -MBED_WEAK CellularBase *CellularBase::get_target_default_instance() -{ - return CellularContext::get_default_instance(); -} -#elif defined ONBOARD_CELLULAR_INTERFACE_AVAILABLE -MBED_WEAK CellularBase *CellularBase::get_target_default_instance() -{ - static OnboardCellularInterface cellular; - - return &cellular; -} -#else -MBED_WEAK CellularBase *CellularBase::get_target_default_instance() -{ - return NULL; -} -#endif diff --git a/features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.h b/features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.h deleted file mode 100644 index 8aa049b261..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.h +++ /dev/null @@ -1,174 +0,0 @@ -/* Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ONBOARD_CELLULAR_INTERFACE_ -#define ONBOARD_CELLULAR_INTERFACE_ - -#include "CellularContext.h" -#ifdef CELLULAR_DEVICE -using namespace mbed; -MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use CellularBase::get_default_instance() instead.") -class OnboardCellularInterface : public CellularBase { -public: - OnboardCellularInterface(bool debug = false) - { - context = CellularContext::get_default_instance(); - MBED_ASSERT(context != NULL); - CellularDevice *dev = CellularDevice::get_default_instance(); - MBED_ASSERT(dev != NULL); - dev->modem_debug_on(debug); - } -public: // from NetworkInterface - virtual nsapi_error_t set_blocking(bool blocking) - { - return context->set_blocking(blocking); - } - virtual NetworkStack *get_stack() - { - return context->get_stack(); - } - virtual const char *get_ip_address() - { - return context->get_ip_address(); - } - virtual void attach(mbed::Callback status_cb) - { - context->attach(status_cb); - } - virtual nsapi_error_t connect() - { - return context->connect(); - } - virtual nsapi_error_t disconnect() - { - return context->disconnect(); - } - - // from CellularBase - virtual void set_plmn(const char *plmn) - { - context->set_plmn(plmn); - } - virtual void set_sim_pin(const char *sim_pin) - { - context->set_sim_pin(sim_pin); - } - virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0, - const char *pwd = 0) - { - return context->connect(sim_pin, apn, uname, pwd); - } - virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) - { - context->set_credentials(apn, uname, pwd); - } - virtual const char *get_netmask() - { - return context->get_netmask(); - } - virtual const char *get_gateway() - { - return context->get_gateway(); - } - virtual bool is_connected() - { - return context->is_connected(); - } - -private: - CellularContext *context; -}; - -#define ONBOARD_CELLULAR_INTERFACE_AVAILABLE -#elif MODEM_ON_BOARD && MODEM_ON_BOARD_UART && NSAPI_PPP_AVAILABLE - -#include "UARTCellularInterface.h" - -/** OnboardCellularInterface class - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/framework/API/CellularPower.h instead. - * - * This interface serves as the controller/driver for an - * onboard modem implementing onboard_modem_api.h. - * - * Depending on the type of on-board modem, OnboardCellularInterface - * could be derived from different implementation classes. - * Portable applications should only rely on it being a CellularBase. - */ - -class OnboardCellularInterface : public UARTCellularInterface { - -public: - - /** Constructor - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/framework/API/CellularPower.h instead. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/framework/API/CellularPower.h instead.") - OnboardCellularInterface(bool debug = false); - - /** Destructor - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/framework/API/CellularPower.h instead. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/framework/API/CellularPower.h instead.") - virtual ~OnboardCellularInterface(); - -protected: - /** Sets the modem up for powering on - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/framework/API/CellularPower.h instead. - * - * modem_init() is equivalent to plugging in the device, for example, attaching power and serial port. - * Uses onboard_modem_api.h where the target provides the implementation of onboard_modem_api. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/framework/API/CellularPower.h instead.") - virtual void modem_init(); - - /** Sets the modem in unplugged state - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/framework/API/CellularPower.h instead. - * - * modem_deinit() will be equivalent to pulling the plug off of the device, in other words, detaching power - * and serial port. This puts the modem in lowest power state. - * Uses onboard_modem_api.h where the target provides the implementation of onboard_modem_api. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/framework/API/CellularPower.h instead.") - virtual void modem_deinit(); - - /** Powers up the modem - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/framework/API/CellularPower.h instead. - * - * modem_power_up() is equivalent to pressing the soft power button. - * The driver may repeat this if the modem is not responsive to AT commands. - * Uses onboard_modem_api.h where the target provides the implementation of onboard_modem_api. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/framework/API/CellularPower.h instead.") - virtual void modem_power_up(); - - /** Powers down the modem - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/framework/API/CellularPower.h instead. - * - * modem_power_down() is equivalent to turning off the modem by button press. - * Uses onboard_modem_api.h where the target provides the implementation of onboard_modem_api. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/framework/API/CellularPower.h instead.") - virtual void modem_power_down(); -}; - -#define ONBOARD_CELLULAR_INTERFACE_AVAILABLE - -#endif //MODEM_ON_BOARD && MODEM_ON_BOARD_UART && NSAPI_PPP_AVAILABLE -#endif //ONBOARD_CELLULAR_INTERFACE_ diff --git a/features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.cpp b/features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.cpp deleted file mode 100644 index c0ebe799a9..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.cpp +++ /dev/null @@ -1,849 +0,0 @@ -/* Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "PPPCellularInterface.h" - -#if NSAPI_PPP_AVAILABLE - -#include -#include "nsapi_ppp.h" -#if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP -#include "APN_db.h" -#endif //MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP -#include "mbed_trace.h" -#define TRACE_GROUP "UCID" - -#include "mbed_wait_api.h" - -using namespace mbed; - -/** - * PDP (packet data profile) Context - */ -#define CTX "1" - -/** - * Output Enter sequence for the modem , default CR - */ -#define OUTPUT_ENTER_KEY "\r" - -#if MBED_CONF_PPP_CELL_IFACE_AT_PARSER_BUFFER_SIZE -#define AT_PARSER_BUFFER_SIZE MBED_CONF_PPP_CELL_IFACE_AT_PARSER_BUFFER_SIZE //bytes -#else -#define AT_PARSER_BUFFER_SIZE 256 //bytes -#endif //MBED_CONF_PPP_CELL_IFACE_AT_PARSER_BUFFER_SIZE - -#if MBED_CONF_PPP_CELL_IFACE_AT_PARSER_TIMEOUT -#define AT_PARSER_TIMEOUT MBED_CONF_PPP_CELL_IFACE_AT_PARSER_TIMEOUT -#else -#define AT_PARSER_TIMEOUT 8*1000 //miliseconds -#endif //MBED_CONF_PPP_CELL_IFACE_AT_PARSER_TIMEOUT - -static bool initialized; -static bool set_sim_pin_check_request; -static bool change_pin; -static device_info dev_info; - -static void parser_abort(ATCmdParser *at) -{ - at->abort(); -} - -static bool get_CCID(ATCmdParser *at) -{ - // Returns the ICCID (Integrated Circuit Card ID) of the SIM-card. - // ICCID is a serial number identifying the SIM. - bool success = at->send("AT+CCID") && at->recv("+CCID: %20[^\n]\nOK\n", dev_info.ccid); - tr_debug("DevInfo: CCID=%s", dev_info.ccid); - return success; -} - -static bool get_IMSI(ATCmdParser *at) -{ - // International mobile subscriber identification - bool success = at->send("AT+CIMI") && at->recv("%15[^\n]\nOK\n", dev_info.imsi); - tr_debug("DevInfo: IMSI=%s", dev_info.imsi); - return success; -} - -static bool get_IMEI(ATCmdParser *at) -{ - // International mobile equipment identifier - bool success = at->send("AT+CGSN") && at->recv("%15[^\n]\nOK\n", dev_info.imei); - tr_debug("DevInfo: IMEI=%s", dev_info.imei); - return success; -} - -static bool get_MEID(ATCmdParser *at) -{ - // Mobile equipment identifier - bool success = at->send("AT+GSN") - && at->recv("%18[^\n]\nOK\n", dev_info.meid); - tr_debug("DevInfo: MEID=%s", dev_info.meid); - return success; -} - -static bool set_CMGF(ATCmdParser *at) -{ - // Preferred message format - // set AT+CMGF=[mode] , 0 PDU mode, 1 text mode - bool success = at->send("AT+CMGF=1") && at->recv("OK"); - return success; -} - -static bool set_CNMI(ATCmdParser *at) -{ - // New SMS indication configuration - // set AT+CMTI=[mode, index] , 0 PDU mode, 1 text mode - // Multiple URCs for SMS, i.e., CMT, CMTI, UCMT, CBMI, CDSI as DTE could be following any of these SMS formats - bool success = at->send("AT+CNMI=2," CTX) && at->recv("OK"); - return success; -} - -static void CMTI_URC(ATCmdParser *at) -{ - // our CMGF = 1, i.e., text mode. So we expect response in this format: - //+CMTI: ,, - at->recv(": %*u,%*u"); - tr_info("New SMS received"); - -} - -static void CMT_URC(ATCmdParser *at) -{ - // our CMGF = 1, i.e., text mode. So we expect response in this format: - //+CMT: ,[],[,, - //,,,,, - //] - // By default detailed SMS header CSDH=0 , so we are not expecting [,, - //,,,, - char sms[50]; - char service_timestamp[15]; - at->recv(": %49[^\"]\",,%14[^\"]\"\n", sms, service_timestamp); - - tr_info("SMS:%s, %s", service_timestamp, sms); - -} - -static bool set_atd(ATCmdParser *at) -{ - bool success = at->send("ATD*99***" CTX "#") && at->recv("CONNECT"); - - return success; -} - -/** - * Enables or disables SIM pin check lock - */ -static nsapi_error_t do_sim_pin_check(ATCmdParser *at, const char *pin) -{ - bool success; - if (set_sim_pin_check_request) { - /* use the SIM locked */ - success = at->send("AT+CLCK=\"SC\",1,\"%s\"", pin) && at->recv("OK"); - } else { - /* use the SIM unlocked */ - success = at->send("AT+CLCK=\"SC\",0,\"%s\"", pin) && at->recv("OK"); - } - - if (success) { - return NSAPI_ERROR_OK; - } - - return NSAPI_ERROR_AUTH_FAILURE; -} - -/** - * Change the pin code for the SIM card - */ -static nsapi_error_t do_change_sim_pin(ATCmdParser *at, const char *old_pin, const char *new_pin) -{ - /* changes the SIM pin */ - bool success = at->send("AT+CPWD=\"SC\",\"%s\",\"%s\"", old_pin, new_pin) && at->recv("OK"); - if (success) { - return NSAPI_ERROR_OK; - } - - return NSAPI_ERROR_AUTH_FAILURE; -} - -static void set_nwk_reg_status_csd(unsigned int status) -{ - switch (status) { - case CSD_NOT_REGISTERED_NOT_SEARCHING: - case CSD_NOT_REGISTERED_SEARCHING: - break; - case CSD_REGISTERED: - case CSD_REGISTERED_ROAMING: - tr_debug("Registered for circuit switched service"); - break; - case CSD_REGISTRATION_DENIED: - tr_debug("Circuit switched service denied"); - break; - case CSD_UNKNOWN_COVERAGE: - tr_debug("Out of circuit switched service coverage"); - break; - case CSD_SMS_ONLY: - tr_debug("SMS service only"); - break; - case CSD_SMS_ONLY_ROAMING: - tr_debug("SMS service only"); - break; - case CSD_CSFB_NOT_PREFERRED: - tr_debug("Registered for circuit switched service with CSFB not preferred"); - break; - default: - tr_debug("Unknown circuit switched service registration status. %u", status); - break; - } - - dev_info.reg_status_csd = static_cast(status); -} - -static void set_nwk_reg_status_psd(unsigned int status) -{ - switch (status) { - case PSD_NOT_REGISTERED_NOT_SEARCHING: - case PSD_NOT_REGISTERED_SEARCHING: - break; - case PSD_REGISTERED: - case PSD_REGISTERED_ROAMING: - tr_debug("Registered for packet switched service"); - break; - case PSD_REGISTRATION_DENIED: - tr_debug("Packet switched service denied"); - break; - case PSD_UNKNOWN_COVERAGE: - tr_debug("Out of packet switched service coverage"); - break; - case PSD_EMERGENCY_SERVICES_ONLY: - tr_debug("Limited access for packet switched service. Emergency use only."); - break; - default: - tr_debug("Unknown packet switched service registration status. %u", status); - break; - } - - dev_info.reg_status_psd = static_cast(status); -} - -static bool is_registered_csd() -{ - return (dev_info.reg_status_csd == CSD_REGISTERED) || - (dev_info.reg_status_csd == CSD_REGISTERED_ROAMING) || - (dev_info.reg_status_csd == CSD_CSFB_NOT_PREFERRED); -} - -static bool is_registered_psd() -{ - return (dev_info.reg_status_psd == PSD_REGISTERED) || - (dev_info.reg_status_psd == PSD_REGISTERED_ROAMING); -} - -PPPCellularInterface::PPPCellularInterface(FileHandle *fh, bool debug) -{ - _new_pin = NULL; - _pin = NULL; - _at = NULL; - _apn = NULL; - _uname = NULL; - _pwd = NULL; - _fh = fh; - _debug_trace_on = debug; - _stack = DEFAULT_STACK; - _connection_status_cb = NULL; - _connect_status = NSAPI_STATUS_DISCONNECTED; - _connect_is_blocking = true; - dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING; - dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING; -} - - -PPPCellularInterface::~PPPCellularInterface() -{ - delete _at; -} - -void PPPCellularInterface::enable_hup(bool) -{ - //meant to be overridden -} - -void PPPCellularInterface::modem_init() -{ - //meant to be overridden -} - -void PPPCellularInterface::modem_deinit() -{ - //meant to be overridden -} - -void PPPCellularInterface::modem_power_up() -{ - //meant to be overridden -} - -void PPPCellularInterface::modem_power_down() -{ - //meant to be overridden -} - -void PPPCellularInterface::modem_debug_on(bool on) -{ - _debug_trace_on = on; -} - -void PPPCellularInterface::ppp_status_cb(nsapi_event_t event, intptr_t parameter) -{ - _connect_status = (nsapi_connection_status_t)parameter; - - if (_connection_status_cb) { - _connection_status_cb(event, parameter); - } -} - -/** - * Public API. Sets up the flag for the driver to enable or disable SIM pin check - * at the next boot. - */ -void PPPCellularInterface::set_sim_pin_check(bool check) -{ - set_sim_pin_check_request = check; -} - -/** - * Public API. Sets up the flag for the driver to change pin code for SIM card - */ -void PPPCellularInterface::set_new_sim_pin(const char *new_pin) -{ - change_pin = true; - _new_pin = new_pin; -} - -bool PPPCellularInterface::nwk_registration(uint8_t nwk_type) -{ - bool success = false; - bool registered = false; - - char str[35]; - int retcode; - int retry_counter = 0; - unsigned int reg_status; - - success = nwk_type == PACKET_SWITCHED ? - _at->send("AT+CGREG=0") : - _at->send("AT+CREG=0") && _at->recv("OK\n"); - - success = _at->send("AT+COPS=0") //initiate auto-registration - && _at->recv("OK"); - if (!success) { - tr_error("Modem not responding."); - return false; - } - - //Network search - //If not registered after 60 attempts, i.e., 30 seconds wait, give up - tr_debug("Searching Network ..."); - - while (!registered) { - - if (retry_counter > 60) { - success = false; - goto give_up; - } - - success = nwk_type == PACKET_SWITCHED ? - _at->send("AT+CGREG?") - && _at->recv("+CGREG: %34[^\n]\n", str) - && _at->recv("OK\n") : - _at->send("AT+CREG?") - && _at->recv("+CREG: %34[^\n]\n", str) - && _at->recv("OK\n"); - - retcode = sscanf(str, "%*u,%u", ®_status); - - if (retcode >= 1) { - if (nwk_type == PACKET_SWITCHED) { - set_nwk_reg_status_psd(reg_status); - if (is_registered_psd()) { - registered = true; - } - } else if (nwk_type == CIRCUIT_SWITCHED) { - set_nwk_reg_status_csd(reg_status); - if (is_registered_csd()) { - registered = true; - } - } - } - - if (registered) { - break; - } else { - wait_ms(500); - } - - retry_counter++; - } - -give_up: - return registered; -} - -bool PPPCellularInterface::is_connected() -{ - return (_connect_status == NSAPI_STATUS_GLOBAL_UP || _connect_status == NSAPI_STATUS_LOCAL_UP); -} - -// Get the SIM card going. -nsapi_error_t PPPCellularInterface::initialize_sim_card() -{ - nsapi_error_t nsapi_error = NSAPI_ERROR_AUTH_FAILURE; - int retry_count = 0; - bool done = false; - - /* SIM initialization may take a significant amount, so an error is - * kind of expected. We should retry 10 times until we succeed or timeout. */ - for (retry_count = 0; !done && (retry_count < 10); retry_count++) { - char pinstr[16]; - - if (_at->send("AT+CPIN?") && _at->recv("+CPIN: %15[^\n]\nOK\n", pinstr)) { - if (strcmp(pinstr, "SIM PIN") == 0) { - if (!_at->send("AT+CPIN=\"%s\"", _pin) || !_at->recv("OK")) { - tr_debug("PIN correct"); - nsapi_error = NSAPI_ERROR_OK; - } - } else if (strcmp(pinstr, "READY") == 0) { - tr_debug("SIM Ready"); - nsapi_error = NSAPI_ERROR_OK; - done = true; - } else { - tr_debug("Unexpected response from SIM: \"%s\"", pinstr); - } - } - - /* wait for a second before retry */ - wait_ms(1000); - } - - if (!done) { - tr_error("SIM not ready."); - } - - return nsapi_error; -} - -void PPPCellularInterface::set_sim_pin(const char *pin) -{ - /* overwrite the default pin by user provided pin */ - _pin = pin; -} - -nsapi_error_t PPPCellularInterface::setup_context_and_credentials() -{ - bool success; - - if (!_apn) { - return NSAPI_ERROR_PARAMETER; - } - -#if NSAPI_PPP_IPV4_AVAILABLE && NSAPI_PPP_IPV6_AVAILABLE - const char ipv4v6_pdp_type[] = {"IPV4V6"}; - const char ipv4_pdp_type[] = {"IP"}; - const char *pdp_type = ipv4v6_pdp_type; - _stack = IPV4V6_STACK; -#elif NSAPI_PPP_IPV6_AVAILABLE - const char pdp_type[] = {"IPV6"}; -#elif NSAPI_PPP_IPV4_AVAILABLE - const char pdp_type[] = {"IP"}; -#endif - const char *auth = _uname && _pwd ? "CHAP:" : ""; - -#if NSAPI_PPP_IPV4_AVAILABLE && NSAPI_PPP_IPV6_AVAILABLE -retry_without_dual_stack: -#endif - success = _at->send("AT" - "+FCLASS=0;" // set to connection (ATD) to data mode - "+CGDCONT=" CTX ",\"%s\",\"%s%s\"", - pdp_type, auth, _apn - ) - && _at->recv("OK"); - -#if NSAPI_PPP_IPV4_AVAILABLE && NSAPI_PPP_IPV6_AVAILABLE - if (_stack == IPV4V6_STACK) { - if (!success) { - // fallback to ipv4 - pdp_type = ipv4_pdp_type; - _stack = IPV4_STACK; - goto retry_without_dual_stack; - } - } -#endif - - if (!success) { - _at->recv("OK"); - } - - return success ? NSAPI_ERROR_OK : NSAPI_ERROR_PARAMETER; - -} - -void PPPCellularInterface::set_credentials(const char *apn, const char *uname, - const char *pwd) -{ - _apn = apn; - _uname = uname; - _pwd = pwd; -} - -void PPPCellularInterface::setup_at_parser() -{ - if (_at) { - return; - } - - _at = new ATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE, AT_PARSER_TIMEOUT, - _debug_trace_on ? true : false); - - /* Error cases, out of band handling */ - _at->oob("ERROR", callback(parser_abort, _at)); - _at->oob("+CME ERROR", callback(parser_abort, _at)); - _at->oob("+CMS ERROR", callback(parser_abort, _at)); - _at->oob("NO CARRIER", callback(parser_abort, _at)); - - /* URCs, handled out of band */ - _at->oob("+CMT", callback(CMT_URC, _at)); - _at->oob("+CMTI", callback(CMTI_URC, _at)); -} - -void PPPCellularInterface::shutdown_at_parser() -{ - delete _at; - _at = NULL; -} - -nsapi_error_t PPPCellularInterface::connect(const char *sim_pin, const char *apn, const char *uname, const char *pwd) -{ - if (!sim_pin) { - return NSAPI_ERROR_PARAMETER; - } - - _pin = sim_pin; - - if (apn) { - if (pwd && !uname) { - return NSAPI_ERROR_PARAMETER; - } - set_credentials(apn, uname, pwd); - } - - return connect(); -} - -nsapi_error_t PPPCellularInterface::connect() -{ - nsapi_error_t retcode; - bool success; - bool did_init = false; - const char *apn_config = NULL; - bool user_specified_apn = false; - - /* If the user has specified the APN then use that or, - * if we are not using the APN database, set _apn to - * "internet" as a best guess - */ - if (_apn) { - user_specified_apn = true; - } else { -#ifndef MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP - _apn = "internet"; - user_specified_apn = true; -#endif - } - - if (is_connected()) { - return NSAPI_ERROR_IS_CONNECTED; - } else if (_connect_status == NSAPI_STATUS_CONNECTING) { - return NSAPI_ERROR_ALREADY; - } - - _connect_status = NSAPI_STATUS_CONNECTING; - if (_connection_status_cb) { - _connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_CONNECTING); - } - - do { -retry_init: - - retcode = NSAPI_ERROR_OK; - - /* setup AT parser */ - setup_at_parser(); - - if (!initialized) { - - /* If we have hangup (eg DCD) detection, we don't want it active - * as long as we are using ATCmdParser. - * As soon as we get into data mode, we will turn it back on. */ - enable_hup(false); - - if (!power_up()) { - retcode = NSAPI_ERROR_DEVICE_ERROR; - break; - } - - retcode = initialize_sim_card(); - if (retcode != NSAPI_ERROR_OK) { - break; - } - - success = nwk_registration(PACKET_SWITCHED) //perform network registration - && get_CCID(_at)//get integrated circuit ID of the SIM - && get_IMSI(_at)//get international mobile subscriber information - && get_IMEI(_at)//get international mobile equipment identifier - && get_MEID(_at)//its same as IMEI - && set_CMGF(_at)//set message format for SMS - && set_CNMI(_at);//set new SMS indication - - if (!success) { - retcode = NSAPI_ERROR_NO_CONNECTION; - break; - } - -#if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP - if (!apn_config) { - apn_config = apnconfig(dev_info.imsi); - } -#endif - - /* Check if user want skip SIM pin checking on boot up */ - if (set_sim_pin_check_request) { - retcode = do_sim_pin_check(_at, _pin); - if (retcode != NSAPI_ERROR_OK) { - break; - } - /* set this request to false, as it is unnecessary to repeat in case of retry */ - set_sim_pin_check_request = false; - } - - /* check if the user requested a sim pin change */ - if (change_pin) { - retcode = do_change_sim_pin(_at, _pin, _new_pin); - if (retcode != NSAPI_ERROR_OK) { - break; - } - /* set this request to false, as it is unnecessary to repeat in case of retry */ - change_pin = false; - } - -#if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP - if (!user_specified_apn && apn_config) { - _apn = _APN_GET(apn_config); - _uname = _APN_GET(apn_config); - _pwd = _APN_GET(apn_config); - tr_info("Looked up APN %s.", _apn); - } -#endif - - //sets up APN and IP protocol for external PDP context - retcode = setup_context_and_credentials(); - if (retcode != NSAPI_ERROR_OK) { - break; - } - - if (!success) { - shutdown_at_parser(); - retcode = NSAPI_ERROR_NO_CONNECTION; - break; - } - - initialized = true; - did_init = true; - } else { - /* If we were already initialized, we expect to receive NO_CARRIER response - * from the modem as we were kicked out of Data mode */ - _at->recv("NO CARRIER"); - success = _at->send("AT") && _at->recv("OK"); - } - - tr_info("The APN being used is %s.\n", _apn); - - /* Attempt to enter data mode */ - success = set_atd(_at); //enter into Data mode with the modem - if (!success) { - power_down(); - initialized = false; - - /* if we were previously initialized , i.e., not in this particular attempt, - * we want to re-initialize */ - if (!did_init) { - goto retry_init; - } - - /* shutdown AT parser before notifying application of the failure */ - shutdown_at_parser(); - - retcode = NSAPI_ERROR_NO_CONNECTION; - break; - } - - /* This is the success case. - * Save RAM, discard AT Parser as we have entered Data mode. */ - shutdown_at_parser(); - - /* We now want hangup (e.g., DCD) detection if available */ - enable_hup(true); - - /* Initialize PPP - * mbed_ppp_init() is a blocking call, it will block until - * connected, or timeout after 30 seconds*/ - retcode = nsapi_ppp_connect(_fh, callback(this, &PPPCellularInterface::ppp_status_cb), _uname, _pwd, _stack); - if (retcode == NSAPI_ERROR_OK && _connect_is_blocking) { - _connect_status = NSAPI_STATUS_GLOBAL_UP; - } - } while ((_connect_status == NSAPI_STATUS_CONNECTING && _connect_is_blocking) && - apn_config && *apn_config); - - - if (retcode != NSAPI_ERROR_OK) { - _connect_status = NSAPI_STATUS_DISCONNECTED; - if (_connection_status_cb) { - _connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED); - } - } - - - return retcode; -} - -/** - * User initiated disconnect - * - * Disconnects from PPP connection only and brings down the underlying network - * interface - */ -nsapi_error_t PPPCellularInterface::disconnect() -{ - return nsapi_ppp_disconnect(_fh); -} - -const char *PPPCellularInterface::get_ip_address() -{ - return nsapi_ppp_get_ip_addr(_fh); -} - -const char *PPPCellularInterface::get_netmask() -{ - return nsapi_ppp_get_netmask(_fh); -} - -const char *PPPCellularInterface::get_gateway() -{ - return nsapi_ppp_get_gw_addr(_fh); -} - -/** Power down modem - * Uses AT command to do it */ -void PPPCellularInterface::power_down() -{ - modem_power_down(); - modem_deinit(); -} - -/** - * Powers up the modem - * - * Enables the GPIO lines to the modem and then wriggles the power line in short pulses. - */ -bool PPPCellularInterface::power_up() -{ - /* Initialize GPIO lines */ - modem_init(); - /* Give modem a little time to settle down */ - wait(0.25); - - bool success = false; - - int retry_count = 0; - while (true) { - modem_power_up(); - /* Modem tends to spit out noise during power up - don't confuse the parser */ - _at->flush(); - /* It is mandatory to avoid sending data to the serial port during the first 200 ms - * of the module startup. Telit_xE910 Global form factor App note. - * Not necessary for all types of modems however. Let's wait just to be on the safe side */ - wait_ms(200); - _at->set_timeout(1000); - if (_at->send("AT") && _at->recv("OK")) { - tr_info("Modem Ready."); - break; - } - - if (++retry_count > 10) { - goto failure; - } - } - - _at->set_timeout(8000); - - /*For more details regarding DCD and DTR circuitry, please refer to Modem AT manual */ - success = _at->send("AT" - "E0;" //turn off modem echoing - "+CMEE=2;"//turn on verbose responses - "&K0"//turn off RTC/CTS handshaking - "+IPR=115200;"//setup baud rate - "&C1;"//set DCD circuit(109), changes in accordance with the carrier detect status - "&D0")//set DTR circuit, we ignore the state change of DTR - && _at->recv("OK"); - - if (!success) { - goto failure; - } - - /* If everything alright, return from here with success*/ - return success; - -failure: - tr_error("Preliminary modem setup failed."); - return false; -} - -/** - * Get a pointer to the underlying network stack - */ -NetworkStack *PPPCellularInterface::get_stack() -{ - return nsapi_ppp_get_stack(); -} - - -void PPPCellularInterface::attach( - Callback status_cb) -{ - _connection_status_cb = status_cb; -} - -nsapi_connection_status_t PPPCellularInterface::get_connection_status() const -{ - return _connect_status; -} - -nsapi_error_t PPPCellularInterface::set_blocking(bool blocking) -{ - return nsapi_ppp_set_blocking(blocking); -} - - - -#endif // NSAPI_PPP_AVAILABLE diff --git a/features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.h b/features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.h deleted file mode 100644 index b0658c77dd..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.h +++ /dev/null @@ -1,414 +0,0 @@ -/* Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PPP_CELLULAR_INTERFACE_ -#define PPP_CELLULAR_INTERFACE_ - -#include "CellularBase.h" -#include "platform/ATCmdParser.h" -#include "ATCmdParser.h" -#include "FileHandle.h" -#include "Callback.h" - -#if NSAPI_PPP_AVAILABLE - -// Forward declaration -class NetworkStack; - -/** - * Network registration status - * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5) - */ -typedef enum { - GSM = 0, - COMPACT_GSM = 1, - UTRAN = 2, - EDGE = 3, - HSDPA = 4, - HSUPA = 5, - HSDPA_HSUPA = 6, - LTE = 7 -} radio_access_nwk_type; - -/** - * Used in registration process to tell which type of network - * to connect. - */ -typedef enum { - CIRCUIT_SWITCHED = 0, - PACKET_SWITCHED -} nwk_type; - -/** - * Circuit Switched network registration status (CREG Usage) - * UBX-13001820 - AT Commands Example Application Note (Section 7.10.3) - */ -typedef enum { - CSD_NOT_REGISTERED_NOT_SEARCHING = 0, - CSD_REGISTERED = 1, - CSD_NOT_REGISTERED_SEARCHING = 2, - CSD_REGISTRATION_DENIED = 3, - CSD_UNKNOWN_COVERAGE = 4, - CSD_REGISTERED_ROAMING = 5, - CSD_SMS_ONLY = 6, - CSD_SMS_ONLY_ROAMING = 7, - CSD_CSFB_NOT_PREFERRED = 9 -} nwk_registration_status_csd; - -/** - * Packet Switched network registration status (CGREG Usage) - * UBX-13001820 - AT Commands Example Application Note (Section 18.27.3) - */ -typedef enum { - PSD_NOT_REGISTERED_NOT_SEARCHING = 0, - PSD_REGISTERED = 1, - PSD_NOT_REGISTERED_SEARCHING = 2, - PSD_REGISTRATION_DENIED = 3, - PSD_UNKNOWN_COVERAGE = 4, - PSD_REGISTERED_ROAMING = 5, - PSD_EMERGENCY_SERVICES_ONLY = 8 -} nwk_registration_status_psd; - -typedef struct { - char ccid[20 + 1]; //!< Integrated Circuit Card ID - char imsi[15 + 1]; //!< International Mobile Station Identity - char imei[15 + 1]; //!< International Mobile Equipment Identity - char meid[18 + 1]; //!< Mobile Equipment IDentifier - int flags; - radio_access_nwk_type rat; - nwk_registration_status_csd reg_status_csd; - nwk_registration_status_psd reg_status_psd; -} device_info; - -/** PPPCellularInterface class - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * This interface serves as the controller/driver for the Cellular - * modems (tested with UBLOX_C027 and MTS_DRAGONFLY_F411RE). - * - * The driver will work with any generic FileHandle, and can be - * derived from in order to provide forms for specific interfaces, as well as - * adding extra power and reset controls alongside the FileHandle. - */ - -class PPPCellularInterface : public CellularBase { - -public: - - /** Constructor for a generic modem, using a single FileHandle for commands and PPP data. - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * The file handle pointer is not accessed within the constructor, only recorded for later - * use - this permits a derived class to pass a pointer to a not-yet-constructed member object. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - PPPCellularInterface(mbed::FileHandle *fh, bool debug = false); - - /** Destructor - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual ~PPPCellularInterface(); - - /** Set the Cellular network credentials - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * Please check documentation of connect() for default behavior of APN settings. - * - * @param apn Access point name - * @param uname optionally, Username - * @param pwd optionally, password - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual void set_credentials(const char *apn, const char *uname = 0, - const char *pwd = 0); - - /** Set the pin code for SIM card - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @param sim_pin PIN for the SIM card - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual void set_sim_pin(const char *sim_pin); - - /** Start the interface - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * Attempts to connect to a Cellular network. - * This driver is written mainly for data network connections as CellularBase - * is NetworkInterface. That's why connect() call internally calls nwk_registration() - * method with parameter PACKET_SWITCHED network. Circuit switched hook and registration - * process is implemented and left in the driver for future extension/subclass support,e.g., - * an SMS or GPS extension. - * - * @param sim_pin PIN for the SIM card - * @param apn optionally, access point name - * @param uname optionally, Username - * @param pwd optionally, password - * @return NSAPI_ERROR_OK on success, or negative error code on failure - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, - const char *uname = 0, const char *pwd = 0); - - /** Attempt to connect to the Cellular network - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * Brings up the network interface. Connects to the Cellular Radio - * network and then brings up the underlying network stack to be used - * by the cellular modem over PPP interface. - * - * If the SIM requires a PIN, and it is not set/invalid, NSAPI_ERROR_AUTH_ERROR is returned. - * For APN setup, default behavior is to use 'internet' as APN string and assuming no authentication - * is required, i.e., username and password are not set. Optionally, a database lookup can be requested - * by turning on the APN database lookup feature. In order to do so, add 'MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP' - * in your mbed_app.json. APN database is by no means exhaustive. It contains a short list of some public - * APNs with publicly available usernames and passwords (if required) in some particular countries only. - * Lookup is done using IMSI (International mobile subscriber identifier). - * Please note that even if 'MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP' config option is set, 'set_credentials()' api still - * gets the precedence. If the aforementioned API is not used and the config option is set but no match is found in - * the lookup table then the driver tries to resort to default APN settings. - * - * Preferred method is to setup APN using 'set_credentials()' API. - * @return 0 on success, negative error code on failure - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual nsapi_error_t connect(); - - /** Attempt to disconnect from the network - * - * Brings down the network interface. Shuts down the PPP interface - * of the underlying network stack. Does not bring down the Radio network - * - * @return 0 on success, negative error code on failure - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual nsapi_error_t disconnect(); - - /** Adds or removes a SIM facility lock - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * Can be used to enable or disable SIM pin check at device startup. - * This API sets up flags for the driver which would either enable or disable - * SIM pin checking depending upon the user provided argument while establishing - * connection. It doesn't do anything immediately other than setting up flags. - * - * @param set can be set to true if the SIM pin check is supposed to be enabled - * and false if not. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - void set_sim_pin_check(bool set); - - /** Change the pin for the SIM card - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * Provide the new pin for your SIM card with this API. Old pin code will be assumed to - * be set using set_SIM_pin() API. This API have no immediate effect. While establishing - * connection, driver will change the SIM pin for the next boot. - * - * @param new_pin new pin to be used in string format - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - void set_new_sim_pin(const char *new_pin); - - /** Check if the connection is currently established or not - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @return true/false If the cellular module have successfully acquired a carrier and is - * connected to an external packet data network using PPP, isConnected() - * API returns true and false otherwise. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual bool is_connected(); - - /** Get the local IP address - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @return Null-terminated representation of the local IP address - * or null if no IP address has been received - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual const char *get_ip_address(); - - /** Get the local network mask - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @return Null-terminated representation of the local network mask - * or null if no network mask has been received - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual const char *get_netmask(); - - /** Get the local gateways - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @return Null-terminated representation of the local gateway - * or null if no network mask has been received - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual const char *get_gateway(); - - - /** Turn modem debug traces on - * - * @param on set true to enable debug traces - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - void modem_debug_on(bool on); - - /** Register callback for status reporting - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @param status_cb The callback for status changes - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual void attach(mbed::Callback status_cb); - - /** Get the connection status - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @return The connection status according to nsapi_connection_status_t - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual nsapi_connection_status_t get_connection_status() const; - - /** Set blocking status of connect() which by default should be blocking - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * @param blocking true if connect is blocking - * @return 0 on success, negative error code on failure - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual nsapi_error_t set_blocking(bool blocking); - -private: - mbed::FileHandle *_fh; - mbed::ATCmdParser *_at; - const char *_new_pin; - const char *_pin; - const char *_apn; - const char *_uname; - const char *_pwd; - bool _debug_trace_on; - nsapi_ip_stack_t _stack; - mbed::Callback _connection_status_cb; - nsapi_connection_status_t _connect_status; - bool _connect_is_blocking; - void base_initialization(); - void setup_at_parser(); - void shutdown_at_parser(); - nsapi_error_t initialize_sim_card(); - nsapi_error_t setup_context_and_credentials(); - bool power_up(); - void power_down(); - void ppp_status_cb(nsapi_event_t, intptr_t); - -protected: - /** Enable or disable hang-up detection - * - * When in PPP data pump mode, it is helpful if the FileHandle will signal hang-up via - * POLLHUP, e.g., if the DCD line is deasserted on a UART. During command mode, this - * signaling is not desired. enable_hup() controls whether this function should be - * active. - * - * Meant to be overridden. - */ - virtual void enable_hup(bool enable); - - /** Sets the modem up for powering on - * - * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port. - * It is meant to be overridden. - * If the modem is on-board, an implementation of onboard_modem_api.h - * will override this. - * If the the modem is a plugged-in device (i.e., a shield type component), the driver deriving from this - * class will override. - */ - virtual void modem_init(); - - /** Sets the modem in unplugged state - * - * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power - * and serial port. This puts the modem in lowest power state. - * It is meant to be overridden. - * If the modem is on-board, an implementation of onboard_modem_api.h - * will override this. - * If the the modem is a plugged-in device (i.e., a shield type component), the driver deriving from this - * class will override. - */ - virtual void modem_deinit(); - - /** Powers up the modem - * - * modem_power_up() is equivalent to pressing the soft power button. - * The driver may repeat this if the modem is not responsive to AT commands. - * It is meant to be overridden. - * If the modem is on-board, an implementation of onboard_modem_api.h - * will override this. - * If the the modem is a plugged-in device (i.e., a shield type component), the driver deriving from this - * class will override. - */ - virtual void modem_power_up(); - - /** Powers down the modem - * - * modem_power_down() is equivalent to turning off the modem by button press. - * It is meant to be overridden. - * If the modem is on-board, an implementation of onboard_modem_api.h - * will override this. - * If the the modem is a plugged-in device (i.e., a shield type component), the driver deriving from this - * class will override. - */ - virtual void modem_power_down(); - - /** Provide access to the underlying stack - * - * @return The underlying network stack - */ - virtual NetworkStack *get_stack(); - - /** Starts network registration process. - * - * Potential users could be subclasses who are not network interface - * but would like to use CellularBase infrastructure to register - * with a cellular network, e.g., an SMS extension to CellularBase. - * - * @param nwk_type type of network to connect, defaults to packet switched network - * - * @return true if registration is successful - */ - bool nwk_registration(uint8_t nwk_type = PACKET_SWITCHED); - -}; - -#endif //NSAPI_PPP_AVAILABLE - -#endif //PPP_CELLULAR_INTERFACE_ diff --git a/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/gmd_ut_config_header.h b/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/gmd_ut_config_header.h deleted file mode 100644 index b59901c553..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/gmd_ut_config_header.h +++ /dev/null @@ -1,69 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MBED_OS_GMD_UT_CONFIG_HEADER_H_ -#define MBED_OS_GMD_UT_CONFIG_HEADER_H_ - -// The number of retries for UDP exchanges -#define NUM_UDP_RETRIES 5 - -// How long to wait for stuff to travel in the async echo tests -#define ASYNC_TEST_WAIT_TIME 10000 - -#define TEST_DATA "_____0000:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0100:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0200:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0300:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0400:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0500:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0600:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0700:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0800:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____0900:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1000:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1100:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1200:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1300:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1400:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1500:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1600:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1700:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1800:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____1900:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789" \ - "_____2000:0123456789012345678901234567890123456789" \ - "01234567890123456789012345678901234567890123456789"; - -#endif /* MBED_OS_GMD_UT_CONFIG_HEADER_H_ */ diff --git a/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/main.cpp b/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/main.cpp deleted file mode 100644 index 437d8e2e4a..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/main.cpp +++ /dev/null @@ -1,435 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if !MODEM_ON_BOARD -#error [NOT_SUPPORTED] MODEM_ON_BOARD should be set for this test to be functional -#endif - -#include "mbed.h" -#include "gmd_ut_config_header.h" -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -//Add your driver's header file here -#include "OnboardCellularInterface.h" -#include "UDPSocket.h" -#include "TCPSocket.h" -#include "mbed_trace.h" -#define TRACE_GROUP "TEST" - -using namespace utest::v1; - -#if !defined(MBED_CONF_APP_DEFAULT_PIN) -#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. -#endif - -/** How to run port verification tests - * - * i) Copy this file in your implementation directory - * e.g., netsocket/cellular/YOUR_IMPLEMENTATION/TESTS/unit_tests/default/ - * ii) Rename OnboardCellularInterface everywhere in this file with your Class - * iii) Make an empty test application with the fork of mbed-os where your implementation resides - * iv) Create a json file in the root directory of your application and copy the contents of - * template_mbed_app.txt into it - * v) Now from the root of your application, enter this command: - * mbed test --compile-list - * Look for the name of of your test suite matching to the directory path - * vi) Run tests with the command: - * mbed test -n YOUR_TEST_SUITE_NAME - * - * For more information on mbed-greentea testing suite, please visit: - * https://docs.mbed.com/docs/mbed-os-handbook/en/latest/advanced/greentea/ - */ - -// Lock for debug prints -static Mutex mtx; - -// An instance of the cellular driver -// change this with the name of your driver -static OnboardCellularInterface driver(true); - -// Test data -static const char test_data[] = TEST_DATA; - -//Private Function prototypes -static nsapi_error_t do_connect(OnboardCellularInterface *iface); -static int fix(int size, int limit); -static void do_udp_echo(UDPSocket *sock, SocketAddress *host_address, int size); -static int send_all(TCPSocket *sock, const char *data, int size); -static void async_cb(bool *callback_triggered); -static void do_tcp_echo_async(TCPSocket *sock, int size, bool *callback_triggered); -static void use_connection(OnboardCellularInterface *driver); -static void drop_connection(OnboardCellularInterface *driver); -static void lock(); -static void unlock(); - -/* - * Verification tests for a successful porting - * These tests must pass: - * - * test_udp_echo() - * test_tcp_echo_async - * test_connect_credentials - * test_connect_preset_credentials - */ - -/** - * Test UDP data exchange - */ -void test_udp_echo() -{ - UDPSocket sock; - SocketAddress host_address; - int x; - int size; - - driver.disconnect(); - TEST_ASSERT(do_connect(&driver) == 0); - - TEST_ASSERT(driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); - host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT); - - tr_debug("UDP: Server %s address: %s on port %d.", - MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(), - host_address.get_port()); - - TEST_ASSERT(sock.open(&driver) == 0) - - sock.set_timeout(10000); - - // Test min, max, and some random sizes in-between - do_udp_echo(&sock, &host_address, 1); - do_udp_echo(&sock, &host_address, MBED_CONF_APP_UDP_MAX_PACKET_SIZE); - for (x = 0; x < 10; x++) { - size = (rand() % MBED_CONF_APP_UDP_MAX_PACKET_SIZE) + 1; - size = fix(size, MBED_CONF_APP_UDP_MAX_PACKET_SIZE + 1); - do_udp_echo(&sock, &host_address, size); - } - - sock.close(); - - drop_connection(&driver); - - tr_debug("%d UDP packets of size up to %d byte(s) echoed successfully.", x, - MBED_CONF_APP_UDP_MAX_PACKET_SIZE); -} - -/** - * Test TCP data exchange via the asynchronous sigio() mechanism - */ -void test_tcp_echo_async() -{ - TCPSocket sock; - SocketAddress host_address; - bool callback_triggered = false; - int x; - int size; - - driver.disconnect(); - TEST_ASSERT(do_connect(&driver) == 0); - - TEST_ASSERT( - driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); - host_address.set_port(MBED_CONF_APP_ECHO_TCP_PORT); - - tr_debug("TCP: Server %s address: %s on port %d.", - MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(), - host_address.get_port()); - - TEST_ASSERT(sock.open(&driver) == 0) - - // Set up the async callback and set the timeout to zero - sock.sigio(callback(async_cb, &callback_triggered)); - sock.set_timeout(0); - - TEST_ASSERT(sock.connect(host_address) == 0); - // Test min, max, and some random sizes in-between - do_tcp_echo_async(&sock, 1, &callback_triggered); - do_tcp_echo_async(&sock, MBED_CONF_APP_TCP_MAX_PACKET_SIZE, - &callback_triggered); - - sock.close(); - - drop_connection(&driver); - - tr_debug("TCP packets of size up to %d byte(s) echoed asynchronously and successfully.", - MBED_CONF_APP_TCP_MAX_PACKET_SIZE); -} - -/** - * Connect with credentials included in the connect request - */ -void test_connect_credentials() -{ - - driver.disconnect(); - - TEST_ASSERT(do_connect(&driver) == 0); - use_connection(&driver); - drop_connection(&driver); -} - -/** - * Test with credentials preset - */ -void test_connect_preset_credentials() -{ - driver.disconnect(); - driver.set_sim_pin(MBED_CONF_APP_DEFAULT_PIN); - driver.set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, - MBED_CONF_APP_PASSWORD); - int num_retries = 0; - nsapi_error_t err = NSAPI_ERROR_OK; - while (!driver.is_connected()) { - err = driver.connect(); - if (err == NSAPI_ERROR_OK || num_retries > MBED_CONF_APP_MAX_RETRIES) { - break; - } - } - - TEST_ASSERT(err == 0); - use_connection(&driver); - drop_connection(&driver); -} - -/** - * Setup Test Environment - */ -utest::v1::status_t test_setup(const size_t number_of_cases) -{ - // Setup Greentea with a timeout - GREENTEA_SETUP(600, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -/** - * Array defining test cases - */ -Case cases[] = { Case("UDP echo test", test_udp_echo), -#if MBED_CONF_LWIP_TCP_ENABLED - Case("TCP async echo test", test_tcp_echo_async), -#endif - Case("Connect with credentials", test_connect_credentials), - Case("Connect with preset credentials", test_connect_preset_credentials) - }; - -Specification specification(test_setup, cases); - -/** - * main test harness - */ -int main() -{ - mbed_trace_init(); - - mbed_trace_mutex_wait_function_set(lock); - mbed_trace_mutex_release_function_set(unlock); - - // Run tests - return !Harness::run(specification); -} -/** - * connect to the network - */ -static nsapi_error_t do_connect(OnboardCellularInterface *iface) -{ - int num_retries = 0; - nsapi_error_t err = NSAPI_ERROR_OK; - while (!iface->is_connected()) { - err = driver.connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, - MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD); - if (err == NSAPI_ERROR_OK || num_retries > MBED_CONF_APP_MAX_RETRIES) { - break; - } - num_retries++; - } - - return err; -} - -/** - * Get a random size for the test packet - */ -static int fix(int size, int limit) -{ - if (size <= 0) { - size = limit / 2; - } else if (size > limit) { - size = limit; - } - return size; -} - -/** - * Do a UDP socket echo test to a given host of a given packet size - */ -static void do_udp_echo(UDPSocket *sock, SocketAddress *host_address, int size) -{ - bool success = false; - void *recv_data = malloc(size); - TEST_ASSERT(recv_data != NULL); - - // Retry this a few times, don't want to fail due to a flaky link - for (int x = 0; !success && (x < NUM_UDP_RETRIES); x++) { - tr_debug("Echo testing UDP packet size %d byte(s), try %d.", size, x + 1); - if ((sock->sendto(*host_address, (void *) test_data, size) == size) - && (sock->recvfrom(host_address, recv_data, size) == size)) { - TEST_ASSERT(memcmp(test_data, recv_data, size) == 0); - success = true; - } - } - TEST_ASSERT(success); - - free(recv_data); -} - -/** - * Send an entire TCP data buffer until done - */ -static int send_all(TCPSocket *sock, const char *data, int size) -{ - int x; - int count = 0; - Timer timer; - - timer.start(); - while ((count < size) && (timer.read_ms() < ASYNC_TEST_WAIT_TIME)) { - x = sock->send(data + count, size - count); - if (x > 0) { - count += x; - tr_debug("%d byte(s) sent, %d left to send.", count, size - count); - } - wait_ms(10); - } - timer.stop(); - - return count; -} - -/** - * The asynchronous callback - */ -static void async_cb(bool *callback_triggered) -{ - - TEST_ASSERT(callback_triggered != NULL); - *callback_triggered = true; -} - -/** - * Do a TCP echo using the asynchronous driver - */ -static void do_tcp_echo_async(TCPSocket *sock, int size, - bool *callback_triggered) -{ - void *recv_data = malloc(size); - int recv_size = 0; - int remaining_size; - int x, y; - Timer timer; - TEST_ASSERT(recv_data != NULL); - - *callback_triggered = false; - tr_debug("Echo testing TCP packet size %d byte(s) async.", size); - TEST_ASSERT(send_all(sock, test_data, size) == size); - // Wait for all the echoed data to arrive - timer.start(); - remaining_size = size; - while ((recv_size < size) && (timer.read_ms() < ASYNC_TEST_WAIT_TIME)) { - if (*callback_triggered) { - *callback_triggered = false; - x = sock->recv((char *) recv_data + recv_size, remaining_size); - if (x > 0) { - recv_size += x; - remaining_size = size - recv_size; - tr_debug("%d byte(s) echoed back so far, %d to go.", recv_size, - remaining_size); - } - } - wait_ms(10); - } - TEST_ASSERT(recv_size == size); - y = memcmp(test_data, recv_data, size); - if (y != 0) { - tr_debug("Sent %d, |%*.*s|", size, size, size, test_data); - tr_debug("Rcvd %d, |%*.*s|", size, size, size, (char *) recv_data); - // We do not assert a failure here because ublox TCP echo server doesn't send - // back original data. It actually constructs a ublox message string. They need to fix it as - // at the minute in case of TCP, their server is not behaving like a echo TCP server. - //TEST_ASSERT(false); - } - timer.stop(); - free(recv_data); -} - -/** - * Use a connection, checking that it is good - * Checks via doing an NTP transaction - */ -static void use_connection(OnboardCellularInterface *driver) -{ - const char *ip_address = driver->get_ip_address(); - const char *net_mask = driver->get_netmask(); - const char *gateway = driver->get_gateway(); - - TEST_ASSERT(driver->is_connected()); - - TEST_ASSERT(ip_address != NULL); - tr_debug("IP address %s.", ip_address); - TEST_ASSERT(net_mask != NULL); - tr_debug("Net mask %s.", net_mask); - TEST_ASSERT(gateway != NULL); - tr_debug("Gateway %s.", gateway); - - UDPSocket sock; - SocketAddress host_address; - - TEST_ASSERT(driver->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); - host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT); - - tr_debug("UDP: Server %s address: %s on port %d.", - MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(), - host_address.get_port()); - - TEST_ASSERT(sock.open(driver) == 0) - - sock.set_timeout(10000); - do_udp_echo(&sock, &host_address, 1); - - sock.close(); -} - -/** - * Drop a connection and check that it has dropped - */ -static void drop_connection(OnboardCellularInterface *driver) -{ - TEST_ASSERT(driver->disconnect() == 0); - TEST_ASSERT(!driver->is_connected()); -} - -/** - * Locks for debug prints - */ -static void lock() -{ - mtx.lock(); -} - -static void unlock() -{ - mtx.unlock(); -} diff --git a/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/template_mbed_app.txt b/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/template_mbed_app.txt deleted file mode 100644 index e41a425910..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/TESTS/unit_tests/default/template_mbed_app.txt +++ /dev/null @@ -1,68 +0,0 @@ -{ - "config": { - "platform": { - "help": "The platform for the cellular feature, e.g. UBLOX or MTS_DRAGONFLY", - "value": "UBLOX" - }, - "max-retries": { - "help": "Network can be intermittent, number of retries before giving up", - "value": 3 - }, - "default-pin": { - "help": "The current value of the SIM PIN as a string", - "value": "\"1234\"" - }, - "apn": { - "help": "The APN string to use for this SIM/network, set to 0 if none", - "value": "\"internet\"" - }, - "username": { - "help": "The user name string to use for this APN, set to zero if none", - "value": 0 - }, - "password": { - "help": "The password string to use for this APN, set to 0 if none", - "value": 0 - }, - "echo-server": { - "help": "The URL string of the UDP/TCP echo server to use during testing", - "value": "\"echo.u-blox.com\"" - }, - "echo-udp-port": { - "help": "The port to connect to on echo-server for UDP testing", - "value": 7 - }, - "echo-tcp-port": { - "help": "The port to connect to on echo-server for TCP testing", - "value": 7 - }, - "ntp-server": { - "help": "The URL string of the NTP server to use during testing", - "value": "\"2.pool.ntp.org\"" - }, - "ntp-port": { - "help": "The port to connect to on ntp-server", - "value": 123 - }, - "udp-max-packet-size": { - "help": "The maximum UDP packet size to use", - "value": 508 - }, - "tcp-max-packet-size": { - "help": "The maximum TCP packet size to use", - "value": 1500 - } - }, - "target_overrides": { - "*": { - "lwip.ipv4-enabled": true, - "lwip.ethernet-enabled": false, - "lwip.ppp-enabled": true, - "lwip.tcp-enabled": true, - "platform.stdio-convert-newlines": true, - "platform.stdio-baud-rate": 115200, - "platform.default-serial-baud-rate": 115200, - "mbed-trace.enable": 1 - } - } -} diff --git a/features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.cpp b/features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.cpp deleted file mode 100644 index 17cf64206f..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "UARTCellularInterface.h" - - -#if NSAPI_PPP_AVAILABLE - -UARTCellularInterface::UARTCellularInterface(PinName txd, PinName rxd, PinName dcd, PinName rts, PinName cts, PinName ri, - PinName dtr, PinName dsr, int baud, bool active_high, bool debug) : - PPPCellularInterface(&_serial, debug), - _serial(txd, rxd, baud) -{ - _dcd_pin = dcd; - _active_high = active_high; -} - -UARTCellularInterface::~UARTCellularInterface() -{ - //do nothing -} - -void UARTCellularInterface::enable_hup(bool enable) -{ - _serial.set_data_carrier_detect(enable ? _dcd_pin : NC, _active_high); -} - -#endif // NSAPI_PPP_AVAILABLE diff --git a/features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.h b/features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.h deleted file mode 100644 index e1d2745902..0000000000 --- a/features/netsocket/cellular/generic_modem_driver/UARTCellularInterface.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UART_CELLULAR_INTERFACE_ -#define UART_CELLULAR_INTERFACE_ - -#include "PPPCellularInterface.h" -#include "UARTSerial.h" - -#if NSAPI_PPP_AVAILABLE - -/** UARTCellularInterface class - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * This interface serves as the controller/driver for Cellular - * modems attached via a UART (tested with UBLOX_C027 and MTS_DRAGONFLY_F411RE). - * - * It constructs a FileHandle and passes it back to its base class as well as overrides - * enable_hup() in the base class. - */ - -class UARTCellularInterface : public PPPCellularInterface { - -public: - - /** Constructor - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - UARTCellularInterface(PinName tx, PinName rx, PinName dcd = NC, PinName rts = NC, PinName cts = NC, PinName ri = NC, - PinName dtr = NC, PinName dsr = NC, int baud = MBED_CONF_PPP_CELL_IFACE_BAUD_RATE, - bool active_high = false, - bool debug = false); - - /** Destructor - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual ~UARTCellularInterface(); - -private: - mbed::UARTSerial _serial; - PinName _dcd_pin; - bool _active_high; - -protected: - /** Enable or disable hang-up detection - * - * @deprecated This API will be deprecated in mbed-os-5.9. Use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead. - * - * When in PPP data pump mode, it is helpful if the FileHandle will signal hang-up via - * POLLHUP, e.g., if the DCD line is deasserted on a UART. During command mode, this - * signaling is not desired. enable_hup() controls whether this function should be - * active. - */ - MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.") - virtual void enable_hup(bool enable); -}; - -#endif //NSAPI_PPP_AVAILABLE - -#endif //UART_CELLULAR_INTERFACE_ diff --git a/features/netsocket/cellular/generic_modem_driver/mbed_lib.json b/features/netsocket/cellular/mbed_lib.json similarity index 100% rename from features/netsocket/cellular/generic_modem_driver/mbed_lib.json rename to features/netsocket/cellular/mbed_lib.json From 75caa75a965c014af618826afba0e4004305d565 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Thu, 20 Dec 2018 05:48:31 -0800 Subject: [PATCH 29/41] Cellular: Add get_target_default_instance in CellularDevice --- .../cellulardevice/cellulardevicetest.cpp | 2 +- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 20 +++---- UNITTESTS/target_h/myCellularDevice.h | 20 +++---- .../cellular/framework/API/CellularDevice.h | 14 ++++- .../framework/device/CellularContext.cpp | 9 +-- .../framework/device/CellularDevice.cpp | 20 +------ .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 18 ++++-- .../GEMALTO/CINTERION/GEMALTO_CINTERION.h | 1 - .../targets/GEMALTO/CINTERION/mbed_lib.json | 35 ++++++++++++ .../GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h | 6 +- .../MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp | 23 +++----- .../MultiTech/DragonflyNano/PPP/SARA4_PPP.h | 2 - .../MultiTech/DragonflyNano/PPP/mbed_lib.json | 29 ++++++++++ .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 14 +++++ .../targets/QUECTEL/BC95/mbed_lib.json | 29 ++++++++++ .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 14 +++++ .../targets/QUECTEL/BG96/mbed_lib.json | 35 ++++++++++++ .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 32 +++++------ .../targets/QUECTEL/UG96/mbed_lib.json | 29 ++++++++++ .../targets/TELIT/HE910/TELIT_HE910.cpp | 32 +++++------ .../targets/TELIT/HE910/TELIT_HE910.h | 2 - .../targets/TELIT/HE910/mbed_lib.json | 30 ++++++++++ .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 33 +++++------ .../framework/targets/UBLOX/AT/mbed_lib.json | 29 ++++++++++ .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 27 ++++----- .../framework/targets/UBLOX/PPP/UBLOX_PPP.h | 5 -- .../framework/targets/UBLOX/PPP/mbed_lib.json | 29 ++++++++++ .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp | 53 +++++++++++++++++ .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h | 33 +++++++++++ .../ONBOARD_TELIT_HE910.cpp | 50 ++++++++++++++++ .../ONBOARD_TELIT_HE910.h | 35 ++++++++++++ .../ONBOARD_TELIT_HE910.cpp | 53 +++++++++++++++++ .../ONBOARD_TELIT_HE910.h | 34 +++++++++++ .../TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp | 33 +++++++++++ .../TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp | 38 +++++++++++++ .../TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h | 34 +++++++++++ .../TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp | 38 +++++++++++++ .../TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h | 33 +++++++++++ .../TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp | 51 +++++++++++++++++ .../TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h | 35 ++++++++++++ .../TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp | 47 +++++++++++++++ .../TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h | 34 +++++++++++ .../ONBOARD_SARA4_PPP.cpp | 57 +++++++++++++++++++ .../ONBOARD_SARA4_PPP.h | 35 ++++++++++++ .../ONBOARD_QUECTEL_BC95.cpp | 54 ++++++++++++++++++ .../ONBOARD_QUECTEL_BC95.h | 34 +++++++++++ 46 files changed, 1171 insertions(+), 149 deletions(-) create mode 100644 features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json create mode 100644 features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json create mode 100644 features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json create mode 100644 features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json create mode 100644 features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json create mode 100644 features/cellular/framework/targets/TELIT/HE910/mbed_lib.json create mode 100644 features/cellular/framework/targets/UBLOX/AT/mbed_lib.json create mode 100644 features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json create mode 100644 targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp create mode 100644 targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h create mode 100644 targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h create mode 100644 targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp create mode 100644 targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h diff --git a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp index 94491bd0e8..79d490bbec 100644 --- a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp @@ -53,7 +53,7 @@ TEST_F(TestCellularDevice, test_create_delete) dev = NULL; CellularDevice *dev1 = CellularDevice::get_default_instance(); - EXPECT_TRUE(dev1); + EXPECT_FALSE(dev1); } TEST_F(TestCellularDevice, test_set_sim_pin) diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 9cf37d3a1a..447301f608 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -43,16 +43,6 @@ AT_CellularDevice::~AT_CellularDevice() delete _network; } -nsapi_error_t AT_CellularDevice::power_on() -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t AT_CellularDevice::power_off() -{ - return NSAPI_ERROR_UNSUPPORTED; -} - ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) { return ATHandler::get_instance(fileHandle, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on); @@ -232,3 +222,13 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) return AT_CellularDevice_stub::nsapi_error_value; } + +nsapi_error_t AT_CellularDevice::power_on() +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t AT_CellularDevice::power_off() +{ + return NSAPI_ERROR_UNSUPPORTED; +} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 229641f4c6..679eeab440 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -79,16 +79,6 @@ public: return _network; } - nsapi_error_t power_on() - { - return NSAPI_ERROR_UNSUPPORTED; - } - - nsapi_error_t power_off() - { - return NSAPI_ERROR_UNSUPPORTED; - } - virtual CellularSMS *open_sms(FileHandle *fh = NULL) { return NULL; @@ -137,6 +127,16 @@ public: return NSAPI_ERROR_OK; } + virtual nsapi_error_t power_on() + { + return NSAPI_ERROR_UNSUPPORTED; + } + + virtual nsapi_error_t power_off() + { + return NSAPI_ERROR_UNSUPPORTED; + } + virtual void set_ready_cb(Callback callback) { } diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 8946f8cd14..920842af6d 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -58,12 +58,22 @@ public: }; /** Returns singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not - * defined, then it returns NULL. Implementation is marked as weak. + * defined, then it returns NULL. See NetworkInterface::get_default_instance for details. * - * @return CellularDevice* instance if any + * @remark Application may override this (non-weak) default implementation. + * + * @return default CellularDevice, NULL if not defined */ static CellularDevice *get_default_instance(); + /** Return target onboard instance of CellularDevice + * + * @remark Mbed OS target shall override (non-weak) this function for an onboard modem. + * + * @return CellularDevice* instance, NULL if not defined + */ + static CellularDevice *get_target_default_instance(); + /** Default constructor * * @param fh File handle used in communication with the modem. diff --git a/features/cellular/framework/device/CellularContext.cpp b/features/cellular/framework/device/CellularContext.cpp index 2bf78c819d..a3ed551cf4 100644 --- a/features/cellular/framework/device/CellularContext.cpp +++ b/features/cellular/framework/device/CellularContext.cpp @@ -22,10 +22,9 @@ MBED_WEAK CellularBase *CellularBase::get_target_default_instance() } namespace mbed { -#ifdef CELLULAR_DEVICE + MBED_WEAK CellularContext *CellularContext::get_default_instance() { - // Uses default APN, uname, password from mbed_app.json CellularDevice *dev = CellularDevice::get_default_instance(); if (!dev) { return NULL; @@ -52,12 +51,6 @@ MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance() #endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY) return context; } -#else -MBED_WEAK CellularContext *CellularContext::get_default_instance() -{ - return NULL; -} -#endif // CELLULAR_DEVICE void CellularContext::cp_data_received() { diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index 2f79e7ab23..a8ad05e00f 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -22,31 +22,17 @@ #include "CellularTargets.h" #include "EventQueue.h" -#ifdef CELLULAR_DEVICE -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) -#endif // CELLULAR_DEVICE - namespace mbed { -#ifdef CELLULAR_DEVICE MBED_WEAK CellularDevice *CellularDevice::get_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); -#if DEVICE_SERIAL_FC - if (MDMRTS != NC && MDMCTS != NC) { - tr_info("_USING flow control, MDMRTS: %d MDMCTS: %d", MDMRTS, MDMCTS); - serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); - } -#endif - static CELLULAR_DEVICE device(&serial); - return &device; + return get_target_default_instance(); } -#else -MBED_WEAK CellularDevice *CellularDevice::get_default_instance() + +MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance() { return NULL; } -#endif // CELLULAR_DEVICE CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0) diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index e1fb17f745..eb74e01957 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -32,10 +32,6 @@ GEMALTO_CINTERION::GEMALTO_CINTERION(FileHandle *fh) : AT_CellularDevice(fh) { } -GEMALTO_CINTERION::~GEMALTO_CINTERION() -{ -} - AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { return new GEMALTO_CINTERION_CellularContext(at, this, apn, cp_req, nonip_req); @@ -138,3 +134,17 @@ void GEMALTO_CINTERION::init_module_ems31() AT_CellularBase::set_cellular_properties(cellular_properties); _module = ModuleEMS31; } + +#if MBED_CONF_GEMALTO_CINTERION_DEFAULT_CELLULAR_DEVICE +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() +{ + static UARTSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, MBED_CONF_GEMALTO_CINTERION_BAUDRATE); +#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) + tr_info("GEMALTO_CINTERION flow control: RTS %d CTS %d", MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS); +#endif + static GEMALTO_CINTERION device(&serial); + return &device; +} +#endif diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h index fb8d81e78b..70ec38a0fd 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h @@ -26,7 +26,6 @@ class GEMALTO_CINTERION : public AT_CellularDevice { public: GEMALTO_CINTERION(FileHandle *fh); - virtual ~GEMALTO_CINTERION(); /** Actual model of cellular module is needed to make AT command adaptation at runtime * to support many different models in one cellular driver. diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json b/features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json new file mode 100644 index 0000000000..16332a1a73 --- /dev/null +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json @@ -0,0 +1,35 @@ +{ + "name": "GEMALTO_CINTERION", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + }, + "target_overrides": { + "K64F": { + "rx": "D0", + "tx": "D1" + } + } +} diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h index 3e631b08a0..f1d563ffc2 100644 --- a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h @@ -28,11 +28,7 @@ namespace mbed { * * GENERIC_AT3GPP can be used as a shield for example on top K64F. * Cellular example can be used for testing: https://github.com/ARMmbed/mbed-os-example-cellular - * Add line to mbed_app.json where you define this class as CELLULAR_DEVICE and the correct pins. In cellular example - * line would be for example just above "target_overrides": {... - * For example: - * "macros": ["CELLULAR_DEVICE=GENERIC_AT3GPP", "MDMRXD=PTC16", "MDMTXD=PTC17","MDMRTS=NC", "MDMCTS=NC"], - * You can define CELLULAR_DEVICE and pins also in ../../../common/CellularTargets.h + * Define in mbed_app.json "target_overrides" correct pins and other setup for your modem. * * If new target don't work with GENERIC_AT3GPP then it needs some customizations. * First thing to try can be checking/modifying cellular_properties array in GENERIC_AT3GPP.cpp, does the module support diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index b557ca5afa..059c7bc530 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -15,8 +15,6 @@ * limitations under the License. */ -#include "onboard_modem_api.h" - #include "SARA4_PPP.h" #include "SARA4_PPP_CellularNetwork.h" @@ -49,19 +47,16 @@ AT_CellularNetwork *SARA4_PPP::open_network_impl(ATHandler &at) return new SARA4_PPP_CellularNetwork(at); } -nsapi_error_t SARA4_PPP::power_on() +#if MBED_CONF_SARA4_PPP_DEFAULT_CELLULAR_DEVICE +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() { -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); + static UARTSerial serial(MBED_CONF_SARA4_PPP_TX, MBED_CONF_SARA4_PPP_RX, MBED_CONF_SARA4_PPP_BAUDRATE); +#if defined (MBED_CONF_SARA4_PPP_RTS) && defined (MBED_CONF_SARA4_PPP_CTS) + tr_info("SARA4_PPP flow control: RTS %d CTS %d", MBED_CONF_SARA4_PPP_RTS, MBED_CONF_SARA4_PPP_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_SARA4_PPP_RTS, MBED_CONF_SARA4_PPP_CTS); #endif - return NSAPI_ERROR_OK; + static SARA4_PPP device(&serial); + return &device; } - -nsapi_error_t SARA4_PPP::power_off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); #endif - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h index 31892c5c87..651c73c791 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h @@ -30,8 +30,6 @@ public: public: // CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); }; } // namespace mbed diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json new file mode 100644 index 0000000000..299a3789a3 --- /dev/null +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "SARA4_PPP", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index c202c96286..c5a985bbd5 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -104,3 +104,17 @@ nsapi_error_t QUECTEL_BC95::reset() _at->resp_start("REBOOTING", true); return _at->unlock_return_error(); } + +#if MBED_CONF_QUECTEL_BC95_DEFAULT_CELLULAR_DEVICE +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() +{ + static UARTSerial serial(MBED_CONF_QUECTEL_BC95_TX, MBED_CONF_QUECTEL_BC95_RX, MBED_CONF_QUECTEL_BC95_BAUDRATE); +#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) + tr_info("QUECTEL_BC95 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS); +#endif + static QUECTEL_BC95 device(&serial); + return &device; +} +#endif diff --git a/features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json new file mode 100644 index 0000000000..fb395795e2 --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "QUECTEL_BC95", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 9600 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 0b717b5f02..4ecbc6833e 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -71,3 +71,17 @@ void QUECTEL_BG96::set_ready_cb(Callback callback) { _at->set_urc_handler(DEVICE_READY_URC, callback); } + +#if MBED_CONF_QUECTEL_BG96_DEFAULT_CELLULAR_DEVICE +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() +{ + static UARTSerial serial(MBED_CONF_QUECTEL_BG96_TX, MBED_CONF_QUECTEL_BG96_RX, MBED_CONF_QUECTEL_BG96_BAUDRATE); +#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) + tr_info("QUECTEL_BG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS); +#endif + static QUECTEL_BG96 device(&serial); + return &device; +} +#endif diff --git a/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json new file mode 100644 index 0000000000..cc42172d83 --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json @@ -0,0 +1,35 @@ +{ + "name": "QUECTEL_BB96", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + }, + "target_overrides": { + "K64F": { + "rx": "PTC16", + "tx": "PTC17" + } + } +} diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 7e590b15da..0269671876 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -48,24 +48,22 @@ QUECTEL_UG96::~QUECTEL_UG96() { } -nsapi_error_t QUECTEL_UG96::power_on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t QUECTEL_UG96::power_off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} - AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { return new QUECTEL_UG96_CellularContext(at, this, apn, cp_req, nonip_req); } + +#if MBED_CONF_QUECTEL_UG96_DEFAULT_CELLULAR_DEVICE +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() +{ + static UARTSerial serial(MBED_CONF_QUECTEL_UG96_TX, MBED_CONF_QUECTEL_UG96_RX, MBED_CONF_QUECTEL_UG96_BAUDRATE); +#if defined (MBED_CONF_QUECTEL_UG96_RTS) && defined (MBED_CONF_QUECTEL_UG96_CTS) + tr_info("QUECTEL_UG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_UG96_RTS, MBED_CONF_QUECTEL_UG96_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_UG96_RTS, MBED_CONF_QUECTEL_UG96_CTS); +#endif + static QUECTEL_UG96 device(&serial); + return &device; +} +#endif + diff --git a/features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json new file mode 100644 index 0000000000..68e91aef75 --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "QUECTEL_UB96", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 93f1a19bd0..e9f9ae8176 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -15,7 +15,6 @@ * limitations under the License. */ -#include "onboard_modem_api.h" #include "TELIT_HE910.h" #include "AT_CellularNetwork.h" @@ -43,23 +42,6 @@ TELIT_HE910::~TELIT_HE910() { } -nsapi_error_t TELIT_HE910::power_on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t TELIT_HE910::power_off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} - uint16_t TELIT_HE910::get_send_delay() const { return DEFAULT_DELAY_BETWEEN_AT_COMMANDS; @@ -77,3 +59,17 @@ nsapi_error_t TELIT_HE910::init() return _at->unlock_return_error(); } + +#if MBED_CONF_TELIT_HE910_DEFAULT_CELLULAR_DEVICE +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() +{ + static UARTSerial serial(MBED_CONF_TELIT_HE910_TX, MBED_CONF_TELIT_HE910_RX, MBED_CONF_TELIT_HE910_BAUDRATE); +#if defined (MBED_CONF_TELIT_HE910_RTS) && defined (MBED_CONF_TELIT_HE910_CTS) + tr_info("TELIT_HE910 flow control: RTS %d CTS %d", MBED_CONF_TELIT_HE910_RTS, MBED_CONF_TELIT_HE910_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_TELIT_HE910_RTS, MBED_CONF_TELIT_HE910_CTS); +#endif + static TELIT_HE910 device(&serial); + return &device; +} +#endif diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h index eb8945879d..04ef7bf5de 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h @@ -31,8 +31,6 @@ public: virtual ~TELIT_HE910(); protected: // AT_CellularDevice - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); virtual uint16_t get_send_delay() const; virtual nsapi_error_t init(); }; diff --git a/features/cellular/framework/targets/TELIT/HE910/mbed_lib.json b/features/cellular/framework/targets/TELIT/HE910/mbed_lib.json new file mode 100644 index 0000000000..ad1e59ef5e --- /dev/null +++ b/features/cellular/framework/targets/TELIT/HE910/mbed_lib.json @@ -0,0 +1,30 @@ +{ + "name": "TELIT_HE910", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} + diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index d925374aec..8554dceca8 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -15,7 +15,6 @@ * limitations under the License. */ -#include "onboard_modem_api.h" #include "UBLOX_AT.h" #include "UBLOX_AT_CellularNetwork.h" #include "UBLOX_AT_CellularContext.h" @@ -64,24 +63,22 @@ AT_CellularNetwork *UBLOX_AT::open_network_impl(ATHandler &at) return new UBLOX_AT_CellularNetwork(at); } -nsapi_error_t UBLOX_AT::power_on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); -#endif - return NSAPI_ERROR_OK; -} - -nsapi_error_t UBLOX_AT::power_off() -{ -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); -#endif - return NSAPI_ERROR_OK; -} - AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { return new UBLOX_AT_CellularContext(at, this, apn, cp_req, nonip_req); } + +#if MBED_CONF_UBLOX_AT_DEFAULT_CELLULAR_DEVICE +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() +{ + static UARTSerial serial(MBED_CONF_UBLOX_AT_TX, MBED_CONF_UBLOX_AT_RX, MBED_CONF_UBLOX_AT_BAUDRATE); +#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) + tr_info("UBLOX_AT flow control: RTS %d CTS %d", MBED_CONF_UBLOX_AT_RTS, MBED_CONF_UBLOX_AT_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_UBLOX_AT_RTS, MBED_CONF_UBLOX_AT_CTS); +#endif + static UBLOX_AT device(&serial); + return &device; +} +#endif + diff --git a/features/cellular/framework/targets/UBLOX/AT/mbed_lib.json b/features/cellular/framework/targets/UBLOX/AT/mbed_lib.json new file mode 100644 index 0000000000..02b5a79c77 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/AT/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "UBLOX_AT", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index 621aa4ffbc..7667491194 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -15,7 +15,6 @@ * limitations under the License. */ -#include "onboard_modem_api.h" #include "UBLOX_PPP.h" #include "AT_CellularNetwork.h" @@ -53,23 +52,21 @@ UBLOX_PPP::UBLOX_PPP(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -UBLOX_PPP::~UBLOX_PPP() -{ -} +#if MBED_CONF_UBLOX_PPP_DEFAULT_CELLULAR_DEVICE -nsapi_error_t UBLOX_PPP::power_on() -{ -#if MODEM_ON_BOARD - ::onboard_modem_init(); - ::onboard_modem_power_up(); +#if !NSAPI_PPP_AVAILABLE +#error Must define lwip.ppp-enabled #endif - return NSAPI_ERROR_OK; -} -nsapi_error_t UBLOX_PPP::power_off() +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() { -#if MODEM_ON_BOARD - ::onboard_modem_power_down(); + static UARTSerial serial(MBED_CONF_UBLOX_PPP_TX, MBED_CONF_UBLOX_PPP_RX, MBED_CONF_UBLOX_PPP_BAUDRATE); +#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) + tr_info("UBLOX_PPP flow control: RTS %d CTS %d", MBED_CONF_UBLOX_PPP_RTS, MBED_CONF_UBLOX_PPP_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_UBLOX_PPP_RTS, MBED_CONF_UBLOX_PPP_CTS); #endif - return NSAPI_ERROR_OK; + static UBLOX_PPP device(&serial); + return &device; } +#endif diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h index 4e0f529426..48e050516f 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h @@ -25,11 +25,6 @@ namespace mbed { class UBLOX_PPP : public AT_CellularDevice { public: UBLOX_PPP(FileHandle *fh); - virtual ~UBLOX_PPP(); - -protected: // AT_CellularDevice - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); }; } // namespace mbed diff --git a/features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json b/features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json new file mode 100644 index 0000000000..4611f64566 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "UBLOX_PPP", + "config": { + "tx": { + "help": "TX pin for serial connection", + "value": null + }, + "rx": { + "help": "RX pin for serial connection", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "default-cellular-device": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp new file mode 100644 index 0000000000..1cfd4e67e6 --- /dev/null +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp @@ -0,0 +1,53 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_UBLOX_PPP.h" +#include "cellular/onboard_modem_api.h" +#include "UARTSerial.h" +#include "CellularLog.h" + +using namespace mbed; + +ONBOARD_UBLOX_PPP::ONBOARD_UBLOX_PPP(FileHandle *fh) : UBLOX_PPP(fh) +{ +} + +nsapi_error_t ONBOARD_UBLOX_PPP::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_PPP::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +CellularDevice *CellularDevice::get_target_default_instance() +{ + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_UBLOX_PPP_BAUDRATE); +#if DEVICE_SERIAL_FC + if (MDMRTS != NC && MDMCTS != NC) { + tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); + } +#endif + static ONBOARD_UBLOX_PPP device(&serial); + return &device; +} diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h new file mode 100644 index 0000000000..c8e66cc1ed --- /dev/null +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h @@ -0,0 +1,33 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_UBLOX_PPP_ +#define ONBOARD_UBLOX_PPP_ + +#include "UBLOX_PPP.h" + +namespace mbed { + +class ONBOARD_UBLOX_PPP : public UBLOX_PPP { +public: + ONBOARD_UBLOX_PPP(FileHandle *fh); + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_UBLOX_PPP_ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp new file mode 100644 index 0000000000..0f6b29e1a6 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp @@ -0,0 +1,50 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cellular/onboard_modem_api.h" +#include "UARTSerial.h" +#include "ONBOARD_TELIT_HE910.h" + +using namespace mbed; + +ONBOARD_TELIT_HE910::ONBOARD_TELIT_HE910(FileHandle *fh) : TELIT_HE910(fh) +{ +} + +ONBOARD_TELIT_HE910::~ONBOARD_TELIT_HE910() +{ +} + +nsapi_error_t ONBOARD_TELIT_HE910::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_TELIT_HE910::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +CellularDevice *CellularDevice::get_target_default_instance() +{ + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_TELIT_HE910_BAUDRATE); + static ONBOARD_TELIT_HE910 device(&serial); + return &device; +} diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h new file mode 100644 index 0000000000..8dcf893ce4 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h @@ -0,0 +1,35 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_TELIT_HE910_ +#define ONBOARD_TELIT_HE910_ + +#include "TELIT_HE910.h" + +namespace mbed { + +class ONBOARD_TELIT_HE910 : public TELIT_HE910 { +public: + ONBOARD_TELIT_HE910(FileHandle *fh); + virtual ~ONBOARD_TELIT_HE910(); + + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_TELIT_HE910_ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp new file mode 100644 index 0000000000..64b8de875d --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp @@ -0,0 +1,53 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cellular/onboard_modem_api.h" +#include "UARTSerial.h" +#include "ONBOARD_TELIT_HE910.h" +#include "CellularLog.h" + +using namespace mbed; + +ONBOARD_TELIT_HE910::ONBOARD_TELIT_HE910(FileHandle *fh) : TELIT_HE910(fh) +{ +} + +nsapi_error_t ONBOARD_TELIT_HE910::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_TELIT_HE910::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +CellularDevice *CellularDevice::get_target_default_instance() +{ + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_SARA4_PPP_BAUDRATE); +#if DEVICE_SERIAL_FC + if (MDMRTS != NC && MDMCTS != NC) { + tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); + } +#endif + static ONBOARD_TELIT_HE910 device(&serial); + return &device; +} diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h new file mode 100644 index 0000000000..acf1d79269 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h @@ -0,0 +1,34 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_TELIT_HE910_ +#define ONBOARD_TELIT_HE910_ + +#include "TELIT_HE910.h" + +namespace mbed { + +class ONBOARD_TELIT_HE910 : public TELIT_HE910 { +public: + ONBOARD_TELIT_HE910(FileHandle *fh); + + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_TELIT_HE910_ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp new file mode 100644 index 0000000000..834acd6c36 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp @@ -0,0 +1,33 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_UBLOX_AT.h" +#include "ONBOARD_UBLOX_PPP.h" +#include "UARTSerial.h" + +using namespace mbed; + +CellularDevice *CellularDevice::get_target_default_instance() +{ +#if defined(TARGET_UBLOX_C030_N211) || defined(TARGET_UBLOX_C030_R410M) + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_UBLOX_AT_BAUDRATE); + static ONBOARD_UBLOX_AT device(&serial); +#else + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_UBLOX_PPP_BAUDRATE); + static ONBOARD_UBLOX_PPP device(&serial); +#endif + return &device; +} diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp new file mode 100644 index 0000000000..3f9f5442c0 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp @@ -0,0 +1,38 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_UBLOX_AT.h" +#include "cellular/onboard_modem_api.h" + +using namespace mbed; + +ONBOARD_UBLOX_AT::ONBOARD_UBLOX_AT(FileHandle *fh) : UBLOX_AT(fh) +{ +} + +nsapi_error_t ONBOARD_UBLOX_AT::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_AT::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h new file mode 100644 index 0000000000..c6b0ae13eb --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h @@ -0,0 +1,34 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_UBLOX_AT_ +#define ONBOARD_UBLOX_AT_ + +#include "UBLOX_AT.h" + +namespace mbed { + +class ONBOARD_UBLOX_AT : public UBLOX_AT { +public: + ONBOARD_UBLOX_AT(FileHandle *fh); + + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_UBLOX_AT_ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp new file mode 100644 index 0000000000..00f0da84a4 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp @@ -0,0 +1,38 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_UBLOX_PPP.h" +#include "cellular/onboard_modem_api.h" + +using namespace mbed; + +ONBOARD_UBLOX_PPP::ONBOARD_UBLOX_PPP(FileHandle *fh) : UBLOX_PPP(fh) +{ +} + +nsapi_error_t ONBOARD_UBLOX_PPP::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_PPP::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h new file mode 100644 index 0000000000..c8e66cc1ed --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h @@ -0,0 +1,33 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_UBLOX_PPP_ +#define ONBOARD_UBLOX_PPP_ + +#include "UBLOX_PPP.h" + +namespace mbed { + +class ONBOARD_UBLOX_PPP : public UBLOX_PPP { +public: + ONBOARD_UBLOX_PPP(FileHandle *fh); + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_UBLOX_PPP_ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp new file mode 100644 index 0000000000..f359527aef --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp @@ -0,0 +1,51 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_QUECTEL_BG96.h" + +#include "cellular/onboard_modem_api.h" +#include "UARTSerial.h" + +using namespace mbed; + +ONBOARD_QUECTEL_BG96::ONBOARD_QUECTEL_BG96(FileHandle *fh) : QUECTEL_BG96(fh) +{ +} + +ONBOARD_QUECTEL_BG96::~ONBOARD_QUECTEL_BG96() +{ +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +CellularDevice *CellularDevice::get_target_default_instance() +{ + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_QUECTEL_BG96_BAUDRATE); + static ONBOARD_QUECTEL_BG96 device(&serial); + return &device; +} diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h new file mode 100644 index 0000000000..a910aa2cbb --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h @@ -0,0 +1,35 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_QUECTEL_BG96_ +#define ONBOARD_QUECTEL_BG96_ + +#include "QUECTEL_BG96.h" + +namespace mbed { + +class ONBOARD_QUECTEL_BG96 : public QUECTEL_BG96 { +public: + ONBOARD_QUECTEL_BG96(FileHandle *fh); + virtual ~ONBOARD_QUECTEL_BG96(); + + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_QUECTEL_BG96_ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp new file mode 100644 index 0000000000..e7b10bdc72 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp @@ -0,0 +1,47 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_QUECTEL_BG96.h" + +#include "cellular/onboard_modem_api.h" +#include "UARTSerial.h" + +using namespace mbed; + +ONBOARD_QUECTEL_BG96::ONBOARD_QUECTEL_BG96(FileHandle *fh) : QUECTEL_BG96(fh) +{ +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +CellularDevice *CellularDevice::get_target_default_instance() +{ + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_QUECTEL_BG96_BAUDRATE); + static ONBOARD_QUECTEL_BG96 device(&serial); + return &device; +} diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h new file mode 100644 index 0000000000..a9d0aec89f --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h @@ -0,0 +1,34 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_QUECTEL_BG96_ +#define ONBOARD_QUECTEL_BG96_ + +#include "QUECTEL_BG96.h" + +namespace mbed { + +class ONBOARD_QUECTEL_BG96 : public QUECTEL_BG96 { +public: + ONBOARD_QUECTEL_BG96(FileHandle *fh); + + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_QUECTEL_BG96_ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp new file mode 100644 index 0000000000..9a52959fc8 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp @@ -0,0 +1,57 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_SARA4_PPP.h" +#include "cellular/onboard_modem_api.h" +#include "UARTSerial.h" +#include "CellularLog.h" + +using namespace mbed; + +ONBOARD_SARA4_PPP::ONBOARD_SARA4_PPP(FileHandle *fh) : SARA4_PPP(fh) +{ +} + +ONBOARD_SARA4_PPP::~ONBOARD_SARA4_PPP() +{ +} + +nsapi_error_t ONBOARD_SARA4_PPP::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_SARA4_PPP::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +CellularDevice *CellularDevice::get_target_default_instance() +{ + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_SARA4_PPP_BAUDRATE); +#if DEVICE_SERIAL_FC + if (MDMRTS != NC && MDMCTS != NC) { + tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); + } +#endif + static ONBOARD_SARA4_PPP device(&serial); + return &device; +} diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h new file mode 100644 index 0000000000..867f244b82 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h @@ -0,0 +1,35 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_SARA4_PPP_ +#define ONBOARD_SARA4_PPP_ + +#include "SARA4_PPP.h" + +namespace mbed { + +class ONBOARD_SARA4_PPP : public SARA4_PPP { +public: + ONBOARD_SARA4_PPP(FileHandle *fh); + virtual ~ONBOARD_SARA4_PPP(); + + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_SARA4_PPP_ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp new file mode 100644 index 0000000000..c4397c1f9c --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp @@ -0,0 +1,54 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ONBOARD_QUECTEL_BC95.h" + +#include "cellular/onboard_modem_api.h" +#include "UARTSerial.h" +#include "CellularLog.h" + +using namespace mbed; + +ONBOARD_QUECTEL_BC95::ONBOARD_QUECTEL_BC95(FileHandle *fh) : QUECTEL_BC95(fh) +{ +} + +nsapi_error_t ONBOARD_QUECTEL_BC95::power_on() +{ + ::onboard_modem_init(); + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BC95::power_off() +{ + ::onboard_modem_power_down(); + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +CellularDevice *CellularDevice::get_target_default_instance() +{ + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_QUECTEL_BC95_BAUDRATE); +#if DEVICE_SERIAL_FC + if (MDMRTS != NC && MDMCTS != NC) { + tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); + } +#endif + static ONBOARD_QUECTEL_BC95 device(&serial); + return &device; +} diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h new file mode 100644 index 0000000000..725202c7fc --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h @@ -0,0 +1,34 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_QUECTEL_BC95_ +#define ONBOARD_QUECTEL_BC95_ + +#include "QUECTEL_BC95.h" + +namespace mbed { + +class ONBOARD_QUECTEL_BC95 : public QUECTEL_BC95 { +public: + ONBOARD_QUECTEL_BC95(FileHandle *fh); + + virtual nsapi_error_t power_on(); + virtual nsapi_error_t power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_QUECTEL_BC95_ From 269d151b123aaa822baf06521cf048a404a6e1a8 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Mon, 14 Jan 2019 22:55:19 -0800 Subject: [PATCH 30/41] Cellular: Default modem drivers with FF_ARDUINO --- .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 2 +- .../GEMALTO/CINTERION/GEMALTO_CINTERION.h | 10 ++++++- .../targets/GEMALTO/CINTERION/mbed_lib.json | 12 ++------ .../GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp | 12 +++++++- .../GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h | 11 +++++-- .../GENERIC/GENERIC_AT3GPP/mbed_lib.json | 29 +++++++++++++++++++ .../MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp | 6 +--- .../MultiTech/DragonflyNano/PPP/SARA4_PPP.h | 10 ++++++- .../MultiTech/DragonflyNano/PPP/mbed_lib.json | 6 ++-- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 6 +--- .../targets/QUECTEL/BC95/QUECTEL_BC95.h | 10 ++++++- .../targets/QUECTEL/BC95/mbed_lib.json | 6 ++-- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 6 +--- .../targets/QUECTEL/BG96/QUECTEL_BG96.h | 10 ++++++- .../targets/QUECTEL/BG96/mbed_lib.json | 14 +++------ .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 6 +--- .../targets/QUECTEL/UG96/QUECTEL_UG96.h | 10 ++++++- .../targets/QUECTEL/UG96/mbed_lib.json | 8 ++--- .../targets/TELIT/HE910/TELIT_HE910.cpp | 6 +--- .../targets/TELIT/HE910/TELIT_HE910.h | 10 ++++++- .../targets/TELIT/HE910/mbed_lib.json | 6 ++-- .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 6 +--- .../framework/targets/UBLOX/AT/UBLOX_AT.h | 10 ++++++- .../framework/targets/UBLOX/AT/mbed_lib.json | 6 ++-- .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 2 +- .../framework/targets/UBLOX/PPP/UBLOX_PPP.h | 9 ++++++ .../framework/targets/UBLOX/PPP/mbed_lib.json | 6 ++-- .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp | 2 +- .../ONBOARD_TELIT_HE910.cpp | 6 +--- .../ONBOARD_TELIT_HE910.h | 1 - .../ONBOARD_TELIT_HE910.cpp | 2 +- .../TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp | 4 +-- .../TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp | 2 +- .../TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp | 2 +- .../ONBOARD_SARA4_PPP.cpp | 6 +--- .../ONBOARD_SARA4_PPP.h | 1 - .../ONBOARD_QUECTEL_BC95.cpp | 2 +- 37 files changed, 164 insertions(+), 99 deletions(-) create mode 100644 features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/mbed_lib.json diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index eb74e01957..85683fbdc6 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -135,7 +135,7 @@ void GEMALTO_CINTERION::init_module_ems31() _module = ModuleEMS31; } -#if MBED_CONF_GEMALTO_CINTERION_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_GEMALTO_CINTERION_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() { diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h index 70ec38a0fd..522602de2c 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h @@ -18,13 +18,21 @@ #ifndef GEMALTO_CINTERION_H_ #define GEMALTO_CINTERION_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_GEMALTO_CINTERION_TX +#define MBED_CONF_GEMALTO_CINTERION_TX D1 +#endif +#ifndef MBED_CONF_GEMALTO_CINTERION_RX +#define MBED_CONF_GEMALTO_CINTERION_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { class GEMALTO_CINTERION : public AT_CellularDevice { public: - GEMALTO_CINTERION(FileHandle *fh); /** Actual model of cellular module is needed to make AT command adaptation at runtime diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json b/features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json index 16332a1a73..132526d15c 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/mbed_lib.json @@ -2,11 +2,11 @@ "name": "GEMALTO_CINTERION", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,15 +21,9 @@ "help": "Serial connection baud rate", "value": 115200 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } - }, - "target_overrides": { - "K64F": { - "rx": "D0", - "tx": "D1" - } } } diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp index 8a0da4e727..a76f386f24 100644 --- a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp @@ -38,6 +38,16 @@ GENERIC_AT3GPP::GENERIC_AT3GPP(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -GENERIC_AT3GPP::~GENERIC_AT3GPP() +#if MBED_CONF_GENERIC_AT3GPP_PROVIDE_DEFAULT +#include "UARTSerial.h" +CellularDevice *CellularDevice::get_default_instance() { + static UARTSerial serial(MBED_CONF_GENERIC_AT3GPP_TX, MBED_CONF_GENERIC_AT3GPP_RX, MBED_CONF_GENERIC_AT3GPP_BAUDRATE); +#if defined (MBED_CONF_GENERIC_AT3GPP_RTS) && defined(MBED_CONF_GENERIC_AT3GPP_CTS) + tr_info("GENERIC_AT3GPP flow control: RTS %d CTS %d", MBED_CONF_GENERIC_AT3GPP_RTS, MBED_CONF_GENERIC_AT3GPP_CTS); + serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_GENERIC_AT3GPP_RTS, MBED_CONF_GENERIC_AT3GPP_CTS); +#endif + static GENERIC_AT3GPP device(&serial); + return &device; } +#endif diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h index f1d563ffc2..692f735ed3 100644 --- a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h @@ -18,6 +18,15 @@ #ifndef GENERIC_AT3GPP_H_ #define GENERIC_AT3GPP_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_GENERIC_AT3GPP_TX +#define MBED_CONF_GENERIC_AT3GPP_TX D1 +#endif +#ifndef MBED_CONF_GENERIC_AT3GPP_RX +#define MBED_CONF_GENERIC_AT3GPP_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { @@ -38,8 +47,6 @@ namespace mbed { class GENERIC_AT3GPP : public AT_CellularDevice { public: GENERIC_AT3GPP(FileHandle *fh); - virtual ~GENERIC_AT3GPP(); - }; } // namespace mbed #endif // GENERIC_AT3GPP_H_ diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/mbed_lib.json b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/mbed_lib.json new file mode 100644 index 0000000000..ed4b9173ff --- /dev/null +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "GENERIC_AT3GPP", + "config": { + "tx": { + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", + "value": null + }, + "rx": { + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "provide-default": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index 059c7bc530..e2ad58b0b7 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -38,16 +38,12 @@ SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -SARA4_PPP::~SARA4_PPP() -{ -} - AT_CellularNetwork *SARA4_PPP::open_network_impl(ATHandler &at) { return new SARA4_PPP_CellularNetwork(at); } -#if MBED_CONF_SARA4_PPP_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_SARA4_PPP_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() { diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h index 651c73c791..e4f49e3085 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h @@ -18,6 +18,15 @@ #ifndef SARA4_PPP_H_ #define SARA4_PPP_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_SARA4_PPP_TX +#define MBED_CONF_SARA4_PPP_TX D1 +#endif +#ifndef MBED_CONF_SARA4_PPP_RX +#define MBED_CONF_SARA4_PPP_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { @@ -26,7 +35,6 @@ class SARA4_PPP : public AT_CellularDevice { public: SARA4_PPP(FileHandle *fh); - virtual ~SARA4_PPP(); public: // CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json index 299a3789a3..8ebfad7a3e 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/mbed_lib.json @@ -2,11 +2,11 @@ "name": "SARA4_PPP", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,7 +21,7 @@ "help": "Serial connection baud rate", "value": 115200 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index c5a985bbd5..ac66f8fdba 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -45,10 +45,6 @@ QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -QUECTEL_BC95::~QUECTEL_BC95() -{ -} - nsapi_error_t QUECTEL_BC95::get_sim_state(SimState &state) { _at->lock(); @@ -105,7 +101,7 @@ nsapi_error_t QUECTEL_BC95::reset() return _at->unlock_return_error(); } -#if MBED_CONF_QUECTEL_BC95_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_QUECTEL_BC95_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() { diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index 8c49bfe9f1..10368772fa 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -18,6 +18,15 @@ #ifndef QUECTEL_BC95_H_ #define QUECTEL_BC95_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_QUECTEL_BC95_TX +#define MBED_CONF_QUECTEL_BC95_TX D1 +#endif +#ifndef MBED_CONF_QUECTEL_BC95_RX +#define MBED_CONF_QUECTEL_BC95_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { @@ -25,7 +34,6 @@ namespace mbed { class QUECTEL_BC95 : public AT_CellularDevice { public: QUECTEL_BC95(FileHandle *fh); - virtual ~QUECTEL_BC95(); public: // AT_CellularDevice virtual nsapi_error_t get_sim_state(SimState &state); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json index fb395795e2..d435e5e085 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json +++ b/features/cellular/framework/targets/QUECTEL/BC95/mbed_lib.json @@ -2,11 +2,11 @@ "name": "QUECTEL_BC95", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,7 +21,7 @@ "help": "Serial connection baud rate", "value": 9600 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 4ecbc6833e..1f3bb1c4ee 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -48,10 +48,6 @@ QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -QUECTEL_BG96::~QUECTEL_BG96() -{ -} - AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) { return new QUECTEL_BG96_CellularNetwork(at); @@ -72,7 +68,7 @@ void QUECTEL_BG96::set_ready_cb(Callback callback) _at->set_urc_handler(DEVICE_READY_URC, callback); } -#if MBED_CONF_QUECTEL_BG96_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() { diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 6e2ce5de58..324de491c8 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -18,6 +18,15 @@ #ifndef QUECTEL_BG96_H_ #define QUECTEL_BG96_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_QUECTEL_BG96_TX +#define MBED_CONF_QUECTEL_BG96_TX D1 +#endif +#ifndef MBED_CONF_QUECTEL_BG96_RX +#define MBED_CONF_QUECTEL_BG96_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { @@ -25,7 +34,6 @@ namespace mbed { class QUECTEL_BG96 : public AT_CellularDevice { public: QUECTEL_BG96(FileHandle *fh); - virtual ~QUECTEL_BG96(); protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json index cc42172d83..9ad92a2ee6 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json +++ b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json @@ -1,12 +1,12 @@ { - "name": "QUECTEL_BB96", + "name": "QUECTEL_BG96", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,15 +21,9 @@ "help": "Serial connection baud rate", "value": 115200 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } - }, - "target_overrides": { - "K64F": { - "rx": "PTC16", - "tx": "PTC17" - } } } diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 0269671876..ef8f89f3cc 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -44,16 +44,12 @@ QUECTEL_UG96::QUECTEL_UG96(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -QUECTEL_UG96::~QUECTEL_UG96() -{ -} - AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { return new QUECTEL_UG96_CellularContext(at, this, apn, cp_req, nonip_req); } -#if MBED_CONF_QUECTEL_UG96_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_QUECTEL_UG96_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() { diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h index 499e877c3f..9752ca6d8e 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h @@ -18,6 +18,15 @@ #ifndef QUECTEL_UG96_H_ #define QUECTEL_UG96_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_QUECTEL_UG96_TX +#define MBED_CONF_QUECTEL_UG96_TX D1 +#endif +#ifndef MBED_CONF_QUECTEL_UG96_RX +#define MBED_CONF_QUECTEL_UG96_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { @@ -33,7 +42,6 @@ namespace mbed { class QUECTEL_UG96 : public AT_CellularDevice { public: QUECTEL_UG96(FileHandle *fh); - virtual ~QUECTEL_UG96(); protected: // AT_CellularDevice virtual nsapi_error_t power_on(); diff --git a/features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json index 68e91aef75..143d761a91 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json +++ b/features/cellular/framework/targets/QUECTEL/UG96/mbed_lib.json @@ -1,12 +1,12 @@ { - "name": "QUECTEL_UB96", + "name": "QUECTEL_UG96", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,7 +21,7 @@ "help": "Serial connection baud rate", "value": 115200 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index e9f9ae8176..31ff705ce3 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -38,10 +38,6 @@ TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -TELIT_HE910::~TELIT_HE910() -{ -} - uint16_t TELIT_HE910::get_send_delay() const { return DEFAULT_DELAY_BETWEEN_AT_COMMANDS; @@ -60,7 +56,7 @@ nsapi_error_t TELIT_HE910::init() return _at->unlock_return_error(); } -#if MBED_CONF_TELIT_HE910_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_TELIT_HE910_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() { diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h index 04ef7bf5de..4f34637a42 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h @@ -18,6 +18,15 @@ #ifndef CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ #define CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_TELIT_HE910_TX +#define MBED_CONF_TELIT_HE910_TX D1 +#endif +#ifndef MBED_CONF_TELIT_HE910_RX +#define MBED_CONF_TELIT_HE910_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" //the delay between sending AT commands @@ -28,7 +37,6 @@ namespace mbed { class TELIT_HE910 : public AT_CellularDevice { public: TELIT_HE910(FileHandle *fh); - virtual ~TELIT_HE910(); protected: // AT_CellularDevice virtual uint16_t get_send_delay() const; diff --git a/features/cellular/framework/targets/TELIT/HE910/mbed_lib.json b/features/cellular/framework/targets/TELIT/HE910/mbed_lib.json index ad1e59ef5e..f5c8498ef2 100644 --- a/features/cellular/framework/targets/TELIT/HE910/mbed_lib.json +++ b/features/cellular/framework/targets/TELIT/HE910/mbed_lib.json @@ -2,11 +2,11 @@ "name": "TELIT_HE910", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,7 +21,7 @@ "help": "Serial connection baud rate", "value": 115200 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index 8554dceca8..58e04d1d71 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -54,10 +54,6 @@ UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -UBLOX_AT::~UBLOX_AT() -{ -} - AT_CellularNetwork *UBLOX_AT::open_network_impl(ATHandler &at) { return new UBLOX_AT_CellularNetwork(at); @@ -68,7 +64,7 @@ AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn return new UBLOX_AT_CellularContext(at, this, apn, cp_req, nonip_req); } -#if MBED_CONF_UBLOX_AT_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_UBLOX_AT_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() { diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h index 4f19ce3ad4..c91d58deb0 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h @@ -18,6 +18,15 @@ #ifndef UBLOX_AT_H_ #define UBLOX_AT_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_UBLOX_AT_TX +#define MBED_CONF_UBLOX_AT_TX D1 +#endif +#ifndef MBED_CONF_UBLOX_AT_RX +#define MBED_CONF_UBLOX_AT_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { @@ -25,7 +34,6 @@ namespace mbed { class UBLOX_AT : public AT_CellularDevice { public: UBLOX_AT(FileHandle *fh); - virtual ~UBLOX_AT(); protected: // AT_CellularDevice virtual nsapi_error_t power_on(); diff --git a/features/cellular/framework/targets/UBLOX/AT/mbed_lib.json b/features/cellular/framework/targets/UBLOX/AT/mbed_lib.json index 02b5a79c77..4db0d2f28e 100644 --- a/features/cellular/framework/targets/UBLOX/AT/mbed_lib.json +++ b/features/cellular/framework/targets/UBLOX/AT/mbed_lib.json @@ -2,11 +2,11 @@ "name": "UBLOX_AT", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,7 +21,7 @@ "help": "Serial connection baud rate", "value": 115200 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index 7667491194..61536997cf 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -52,7 +52,7 @@ UBLOX_PPP::UBLOX_PPP(FileHandle *fh) : AT_CellularDevice(fh) AT_CellularBase::set_cellular_properties(cellular_properties); } -#if MBED_CONF_UBLOX_PPP_DEFAULT_CELLULAR_DEVICE +#if MBED_CONF_UBLOX_PPP_PROVIDE_DEFAULT #if !NSAPI_PPP_AVAILABLE #error Must define lwip.ppp-enabled diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h index 48e050516f..882d3066ab 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h @@ -18,6 +18,15 @@ #ifndef UBLOX_PPP_H_ #define UBLOX_PPP_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_UBLOX_PPP_TX +#define MBED_CONF_UBLOX_PPP_TX D1 +#endif +#ifndef MBED_CONF_UBLOX_PPP_RX +#define MBED_CONF_UBLOX_PPP_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { diff --git a/features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json b/features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json index 4611f64566..7c8bae1438 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json +++ b/features/cellular/framework/targets/UBLOX/PPP/mbed_lib.json @@ -2,11 +2,11 @@ "name": "UBLOX_PPP", "config": { "tx": { - "help": "TX pin for serial connection", + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rx": { - "help": "RX pin for serial connection", + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", "value": null }, "rts": { @@ -21,7 +21,7 @@ "help": "Serial connection baud rate", "value": 115200 }, - "default-cellular-device": { + "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false } diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp index 1cfd4e67e6..6419ac17a9 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp @@ -41,7 +41,7 @@ nsapi_error_t ONBOARD_UBLOX_PPP::power_off() CellularDevice *CellularDevice::get_target_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_UBLOX_PPP_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp index 0f6b29e1a6..7d6c68c143 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp @@ -24,10 +24,6 @@ ONBOARD_TELIT_HE910::ONBOARD_TELIT_HE910(FileHandle *fh) : TELIT_HE910(fh) { } -ONBOARD_TELIT_HE910::~ONBOARD_TELIT_HE910() -{ -} - nsapi_error_t ONBOARD_TELIT_HE910::power_on() { ::onboard_modem_init(); @@ -44,7 +40,7 @@ nsapi_error_t ONBOARD_TELIT_HE910::power_off() CellularDevice *CellularDevice::get_target_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_TELIT_HE910_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); static ONBOARD_TELIT_HE910 device(&serial); return &device; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h index 8dcf893ce4..acf1d79269 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h @@ -24,7 +24,6 @@ namespace mbed { class ONBOARD_TELIT_HE910 : public TELIT_HE910 { public: ONBOARD_TELIT_HE910(FileHandle *fh); - virtual ~ONBOARD_TELIT_HE910(); virtual nsapi_error_t power_on(); virtual nsapi_error_t power_off(); diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp index 64b8de875d..6b4f30dc58 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp @@ -41,7 +41,7 @@ nsapi_error_t ONBOARD_TELIT_HE910::power_off() CellularDevice *CellularDevice::get_target_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_SARA4_PPP_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp index 834acd6c36..cd6b922311 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp @@ -23,10 +23,10 @@ using namespace mbed; CellularDevice *CellularDevice::get_target_default_instance() { #if defined(TARGET_UBLOX_C030_N211) || defined(TARGET_UBLOX_C030_R410M) - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_UBLOX_AT_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); static ONBOARD_UBLOX_AT device(&serial); #else - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_UBLOX_PPP_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); static ONBOARD_UBLOX_PPP device(&serial); #endif return &device; diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp index f359527aef..92712a1d8a 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp @@ -45,7 +45,7 @@ nsapi_error_t ONBOARD_QUECTEL_BG96::power_off() CellularDevice *CellularDevice::get_target_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_QUECTEL_BG96_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); static ONBOARD_QUECTEL_BG96 device(&serial); return &device; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp index e7b10bdc72..77a5e678f7 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp @@ -41,7 +41,7 @@ nsapi_error_t ONBOARD_QUECTEL_BG96::power_off() CellularDevice *CellularDevice::get_target_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_QUECTEL_BG96_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); static ONBOARD_QUECTEL_BG96 device(&serial); return &device; } diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp index 9a52959fc8..b66ce4a47a 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp @@ -25,10 +25,6 @@ ONBOARD_SARA4_PPP::ONBOARD_SARA4_PPP(FileHandle *fh) : SARA4_PPP(fh) { } -ONBOARD_SARA4_PPP::~ONBOARD_SARA4_PPP() -{ -} - nsapi_error_t ONBOARD_SARA4_PPP::power_on() { ::onboard_modem_init(); @@ -45,7 +41,7 @@ nsapi_error_t ONBOARD_SARA4_PPP::power_off() CellularDevice *CellularDevice::get_target_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_SARA4_PPP_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 115200); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h index 867f244b82..13a9717f0e 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h @@ -24,7 +24,6 @@ namespace mbed { class ONBOARD_SARA4_PPP : public SARA4_PPP { public: ONBOARD_SARA4_PPP(FileHandle *fh); - virtual ~ONBOARD_SARA4_PPP(); virtual nsapi_error_t power_on(); virtual nsapi_error_t power_off(); diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp index c4397c1f9c..ef4fa87830 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp @@ -42,7 +42,7 @@ nsapi_error_t ONBOARD_QUECTEL_BC95::power_off() CellularDevice *CellularDevice::get_target_default_instance() { - static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_QUECTEL_BC95_BAUDRATE); + static UARTSerial serial(MDMTXD, MDMRXD, 9600); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); From c4de2f2f0ea88fdf7859f699b9c9f625de9feeef Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Tue, 15 Jan 2019 02:57:58 -0800 Subject: [PATCH 31/41] Cellular: Power API updated to match onboard_modem_api --- .../at_cellulardevicetest.cpp | 7 --- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 27 ++++----- UNITTESTS/target_h/myCellularDevice.h | 23 +++++--- .../TESTS/api/cellular_device/main.cpp | 2 - .../cellular/framework/API/CellularDevice.h | 55 +++++++++++++------ .../framework/AT/AT_CellularDevice.cpp | 27 ++++----- .../cellular/framework/AT/AT_CellularDevice.h | 10 ++-- .../framework/device/CellularStateMachine.cpp | 24 ++++---- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 10 ---- .../targets/QUECTEL/BC95/QUECTEL_BC95.h | 1 - .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp | 16 +++++- .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h | 7 ++- .../ONBOARD_TELIT_HE910.cpp | 16 +++++- .../ONBOARD_TELIT_HE910.h | 6 +- .../ONBOARD_TELIT_HE910.cpp | 16 +++++- .../ONBOARD_TELIT_HE910.h | 6 +- .../TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp | 16 +++++- .../TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h | 6 +- .../TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp | 16 +++++- .../TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h | 7 ++- .../TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp | 16 +++++- .../TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h | 6 +- .../TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp | 16 +++++- .../TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h | 6 +- .../ONBOARD_SARA4_PPP.cpp | 16 +++++- .../ONBOARD_SARA4_PPP.h | 6 +- .../ONBOARD_QUECTEL_BC95.cpp | 16 +++++- .../ONBOARD_QUECTEL_BC95.h | 6 +- 28 files changed, 251 insertions(+), 135 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index abdc0164b5..1a45cb490a 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -209,13 +209,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init) EXPECT_EQ(dev.init(), NSAPI_ERROR_OK); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_reset) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - EXPECT_EQ(dev.reset(), NSAPI_ERROR_OK); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_shutdown) { FileHandle_stub fh1; diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 447301f608..a0fc3178c0 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -179,15 +179,6 @@ nsapi_error_t AT_CellularDevice::init() return AT_CellularDevice_stub::nsapi_error_value; } -nsapi_error_t AT_CellularDevice::reset() -{ - if (AT_CellularDevice_stub::init_module_failure_count) { - AT_CellularDevice_stub::init_module_failure_count--; - return NSAPI_ERROR_DEVICE_ERROR; - } - return AT_CellularDevice_stub::nsapi_error_value; -} - nsapi_error_t AT_CellularDevice::shutdown() { if (AT_CellularDevice_stub::init_module_failure_count) { @@ -223,12 +214,22 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) return AT_CellularDevice_stub::nsapi_error_value; } -nsapi_error_t AT_CellularDevice::power_on() +nsapi_error_t AT_CellularDevice::hard_power_on() { - return NSAPI_ERROR_UNSUPPORTED; + return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularDevice::power_off() +nsapi_error_t AT_CellularDevice::hard_power_off() { - return NSAPI_ERROR_UNSUPPORTED; + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularDevice::soft_power_on() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularDevice::soft_power_off() +{ + return NSAPI_ERROR_OK; } diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 679eeab440..521b3c839f 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -112,11 +112,6 @@ public: return NSAPI_ERROR_OK; } - virtual nsapi_error_t reset() - { - return NSAPI_ERROR_OK; - } - virtual nsapi_error_t shutdown() { return NSAPI_ERROR_OK; @@ -127,14 +122,24 @@ public: return NSAPI_ERROR_OK; } - virtual nsapi_error_t power_on() + virtual nsapi_error_t hard_power_on() { - return NSAPI_ERROR_UNSUPPORTED; + return NSAPI_ERROR_OK; } - virtual nsapi_error_t power_off() + virtual nsapi_error_t hard_power_off() { - return NSAPI_ERROR_UNSUPPORTED; + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t soft_power_on() + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t soft_power_off() + { + return NSAPI_ERROR_OK; } virtual void set_ready_cb(Callback callback) diff --git a/features/cellular/TESTS/api/cellular_device/main.cpp b/features/cellular/TESTS/api/cellular_device/main.cpp index ca1095d7f8..c2a7861f30 100644 --- a/features/cellular/TESTS/api/cellular_device/main.cpp +++ b/features/cellular/TESTS/api/cellular_device/main.cpp @@ -108,8 +108,6 @@ 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() diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 920842af6d..c3adfc6a10 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -84,23 +84,42 @@ public: */ virtual ~CellularDevice(); - /** Set cellular device power on. + /** Set cellular device power supply on. * - * @post init must be called after power_on to setup module + * CellularStateMachine calls hard_power_on, soft_power_on and init when requested to connect + * if the modem is not responding. + * + * @post You must call soft_power_on to power on the modem after calling hard_power_on. * * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_UNSUPPORTED if there is no implementation */ - virtual nsapi_error_t power_on() = 0; + virtual nsapi_error_t hard_power_on() = 0; + + /** Set cellular device power supply off. + * + * CellularStateMachine disconnect does not shutdown or power off the modem. + * + * @pre You must call soft_power_off to power off the modem before calling hard_power_off. + * + * @return NSAPI_ERROR_OK on success + */ + virtual nsapi_error_t hard_power_off() = 0; + + /** Set cellular device power on, i.e. start the modem. + * + * @post You must call init to setup the modem. + * + * @return NSAPI_ERROR_OK on success + */ + virtual nsapi_error_t soft_power_on() = 0; /** Set cellular device power off. * - * @pre shutdown must be called before power_down to quit cellular network + * @pre You must call shutdown to prepare the modem for power off. * * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_UNSUPPORTED if there is no implementation */ - virtual nsapi_error_t power_off() = 0; + virtual nsapi_error_t soft_power_off() = 0; /** Open the SIM card by setting the pin code for SIM. * @@ -290,28 +309,28 @@ public: */ virtual void modem_debug_on(bool on) = 0; - /** Initialize cellular device must be called right after module is ready. + /** Initialize cellular device must be called right after the module is ready. + * * For example, when multiple cellular modules are supported in a single driver this function * detects and adapts to an actual module at runtime. * + * CellularStateMachine calls soft_power_on and init repeatedly when starting to connect + * until the modem responds. + * * @return NSAPI_ERROR_OK on success * NSAPI_ERROR_NO_MEMORY on case of memory failure - * NSAPI_ERROR_UNSUPPORTED if current model is not detected + * NSAPI_ERROR_UNSUPPORTED if current cellular module type is not detected * NSAPI_ERROR_DEVICE_ERROR if model information could not be read * */ 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. + * + * Actual functionality is modem specific, for example UART may is not be responsive without + * explicit wakeup signal (such as RTS) after shutdown. + * + * @remark You must call shutdown before power off to prepare the modem and to quit cellular network. * * @return NSAPI_ERROR_OK on success * NSAPI_ERROR_DEVICE_ERROR on failure diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 37c8fe6a28..8251056328 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -69,14 +69,24 @@ AT_CellularDevice::~AT_CellularDevice() release_at_handler(_at); } -nsapi_error_t AT_CellularDevice::power_on() +nsapi_error_t AT_CellularDevice::hard_power_on() { - return NSAPI_ERROR_UNSUPPORTED; + return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularDevice::power_off() +nsapi_error_t AT_CellularDevice::hard_power_off() { - return NSAPI_ERROR_UNSUPPORTED; + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularDevice::soft_power_on() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularDevice::soft_power_off() +{ + return NSAPI_ERROR_OK; } // each parser is associated with one filehandle (that is UART) @@ -355,15 +365,6 @@ nsapi_error_t AT_CellularDevice::init() 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(); diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 5e087cc952..1e90a3261a 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -39,9 +39,13 @@ public: AT_CellularDevice(FileHandle *fh); virtual ~AT_CellularDevice(); - virtual nsapi_error_t power_on(); + virtual nsapi_error_t hard_power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_off(); + + virtual nsapi_error_t soft_power_on(); + + virtual nsapi_error_t soft_power_off(); virtual nsapi_error_t set_pin(const char *sim_pin); @@ -73,8 +77,6 @@ public: virtual nsapi_error_t init(); - virtual nsapi_error_t reset(); - virtual nsapi_error_t shutdown(); virtual nsapi_error_t is_ready(); diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index 59f3cd2d01..104c898682 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -109,13 +109,9 @@ void CellularStateMachine::stop() bool CellularStateMachine::power_on() { - _cb_data.error = _cellularDevice.power_on(); - if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) { - tr_warn("Power on failed. Try to power off/on."); - _cb_data.error = _cellularDevice.power_off(); - if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) { - tr_error("Power off failed!"); - } + _cb_data.error = _cellularDevice.hard_power_on(); + if (_cb_data.error != NSAPI_ERROR_OK) { + tr_warn("Power on failed."); return false; } return true; @@ -384,14 +380,16 @@ bool CellularStateMachine::device_ready() void CellularStateMachine::state_device_ready() { _cellularDevice.set_timeout(TIMEOUT_POWER_ON); - _cb_data.error = _cellularDevice.init(); + _cb_data.error = _cellularDevice.soft_power_on(); if (_cb_data.error == NSAPI_ERROR_OK) { - if (device_ready()) { - enter_to_state(STATE_SIM_PIN); - } else { - retry_state_or_fail(); + _cb_data.error = _cellularDevice.init(); + if (_cb_data.error == NSAPI_ERROR_OK) { + if (device_ready()) { + enter_to_state(STATE_SIM_PIN); + } } - } else { + } + if (_cb_data.error != NSAPI_ERROR_OK) { if (_retry_count == 0) { _cellularDevice.set_ready_cb(callback(this, &CellularStateMachine::device_ready_cb)); } diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index ac66f8fdba..2ec7a8c5ec 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -91,16 +91,6 @@ nsapi_error_t QUECTEL_BC95::init() return _at->unlock_return_error(); } -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); - return _at->unlock_return_error(); -} - #if MBED_CONF_QUECTEL_BC95_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index 10368772fa..84a017ca6f 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -43,7 +43,6 @@ protected: // AT_CellularDevice virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual nsapi_error_t init(); - virtual nsapi_error_t reset(); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp index 6419ac17a9..8e96d3cdf5 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp @@ -25,17 +25,27 @@ ONBOARD_UBLOX_PPP::ONBOARD_UBLOX_PPP(FileHandle *fh) : UBLOX_PPP(fh) { } -nsapi_error_t ONBOARD_UBLOX_PPP::power_on() +nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_UBLOX_PPP::power_off() +nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h index c8e66cc1ed..f95f2228c3 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h @@ -24,8 +24,11 @@ namespace mbed { class ONBOARD_UBLOX_PPP : public UBLOX_PPP { public: ONBOARD_UBLOX_PPP(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp index 7d6c68c143..d77f21e46c 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp @@ -24,17 +24,27 @@ ONBOARD_TELIT_HE910::ONBOARD_TELIT_HE910(FileHandle *fh) : TELIT_HE910(fh) { } -nsapi_error_t ONBOARD_TELIT_HE910::power_on() +nsapi_error_t ONBOARD_TELIT_HE910::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_TELIT_HE910::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_TELIT_HE910::power_off() +nsapi_error_t ONBOARD_TELIT_HE910::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h index acf1d79269..9e08961411 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.h @@ -25,8 +25,10 @@ class ONBOARD_TELIT_HE910 : public TELIT_HE910 { public: ONBOARD_TELIT_HE910(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp index 6b4f30dc58..80a7583695 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp @@ -25,17 +25,27 @@ ONBOARD_TELIT_HE910::ONBOARD_TELIT_HE910(FileHandle *fh) : TELIT_HE910(fh) { } -nsapi_error_t ONBOARD_TELIT_HE910::power_on() +nsapi_error_t ONBOARD_TELIT_HE910::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_TELIT_HE910::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_TELIT_HE910::power_off() +nsapi_error_t ONBOARD_TELIT_HE910::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h index acf1d79269..9e08961411 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.h @@ -25,8 +25,10 @@ class ONBOARD_TELIT_HE910 : public TELIT_HE910 { public: ONBOARD_TELIT_HE910(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp index 3f9f5442c0..137f9d9630 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp @@ -23,16 +23,26 @@ ONBOARD_UBLOX_AT::ONBOARD_UBLOX_AT(FileHandle *fh) : UBLOX_AT(fh) { } -nsapi_error_t ONBOARD_UBLOX_AT::power_on() +nsapi_error_t ONBOARD_UBLOX_AT::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_AT::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_AT::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_UBLOX_AT::power_off() +nsapi_error_t ONBOARD_UBLOX_AT::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h index c6b0ae13eb..43a76ecbac 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.h @@ -25,8 +25,10 @@ class ONBOARD_UBLOX_AT : public UBLOX_AT { public: ONBOARD_UBLOX_AT(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp index 00f0da84a4..f3f18a5219 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp @@ -23,16 +23,26 @@ ONBOARD_UBLOX_PPP::ONBOARD_UBLOX_PPP(FileHandle *fh) : UBLOX_PPP(fh) { } -nsapi_error_t ONBOARD_UBLOX_PPP::power_on() +nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_UBLOX_PPP::power_off() +nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h index c8e66cc1ed..f95f2228c3 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.h @@ -24,8 +24,11 @@ namespace mbed { class ONBOARD_UBLOX_PPP : public UBLOX_PPP { public: ONBOARD_UBLOX_PPP(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp index 92712a1d8a..1d83eb9425 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp @@ -29,17 +29,27 @@ ONBOARD_QUECTEL_BG96::~ONBOARD_QUECTEL_BG96() { } -nsapi_error_t ONBOARD_QUECTEL_BG96::power_on() +nsapi_error_t ONBOARD_QUECTEL_BG96::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_QUECTEL_BG96::power_off() +nsapi_error_t ONBOARD_QUECTEL_BG96::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h index a910aa2cbb..ccfc83383f 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h @@ -26,8 +26,10 @@ public: ONBOARD_QUECTEL_BG96(FileHandle *fh); virtual ~ONBOARD_QUECTEL_BG96(); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp index 77a5e678f7..cd2a74cd9a 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp @@ -25,17 +25,27 @@ ONBOARD_QUECTEL_BG96::ONBOARD_QUECTEL_BG96(FileHandle *fh) : QUECTEL_BG96(fh) { } -nsapi_error_t ONBOARD_QUECTEL_BG96::power_on() +nsapi_error_t ONBOARD_QUECTEL_BG96::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BG96::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_QUECTEL_BG96::power_off() +nsapi_error_t ONBOARD_QUECTEL_BG96::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h index a9d0aec89f..1416660ec7 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.h @@ -25,8 +25,10 @@ class ONBOARD_QUECTEL_BG96 : public QUECTEL_BG96 { public: ONBOARD_QUECTEL_BG96(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp index b66ce4a47a..c06578a3a6 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp @@ -25,17 +25,27 @@ ONBOARD_SARA4_PPP::ONBOARD_SARA4_PPP(FileHandle *fh) : SARA4_PPP(fh) { } -nsapi_error_t ONBOARD_SARA4_PPP::power_on() +nsapi_error_t ONBOARD_SARA4_PPP::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_SARA4_PPP::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_SARA4_PPP::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_SARA4_PPP::power_off() +nsapi_error_t ONBOARD_SARA4_PPP::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h index 13a9717f0e..ef20272bbd 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.h @@ -25,8 +25,10 @@ class ONBOARD_SARA4_PPP : public SARA4_PPP { public: ONBOARD_SARA4_PPP(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp index ef4fa87830..5cbdff81e2 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp @@ -26,17 +26,27 @@ ONBOARD_QUECTEL_BC95::ONBOARD_QUECTEL_BC95(FileHandle *fh) : QUECTEL_BC95(fh) { } -nsapi_error_t ONBOARD_QUECTEL_BC95::power_on() +nsapi_error_t ONBOARD_QUECTEL_BC95::hard_power_on() { ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BC95::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_QUECTEL_BC95::soft_power_on() +{ ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } -nsapi_error_t ONBOARD_QUECTEL_BC95::power_off() +nsapi_error_t ONBOARD_QUECTEL_BC95::soft_power_off() { ::onboard_modem_power_down(); - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h index 725202c7fc..9d91504727 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.h @@ -25,8 +25,10 @@ class ONBOARD_QUECTEL_BC95 : public QUECTEL_BC95 { public: ONBOARD_QUECTEL_BC95(FileHandle *fh); - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); }; } // namespace mbed From af0d2cf61dfe2bd83a106b1cba45d1c1b8c39b78 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Tue, 15 Jan 2019 06:15:54 -0800 Subject: [PATCH 32/41] Cellular: Update API description to match better onboard_modem_api --- .../cellular/framework/API/CellularDevice.h | 41 +++++++++++++++---- .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 2 +- .../GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp | 2 +- .../MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp | 2 +- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 2 +- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 2 +- .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 2 +- .../targets/TELIT/HE910/TELIT_HE910.cpp | 2 +- .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 2 +- .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 2 +- .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp | 2 +- .../ONBOARD_TELIT_HE910.cpp | 2 +- .../TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp | 4 -- .../TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h | 1 - .../ONBOARD_SARA4_PPP.cpp | 2 +- .../ONBOARD_QUECTEL_BC95.cpp | 2 +- 16 files changed, 46 insertions(+), 26 deletions(-) diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index c3adfc6a10..f6059ac64b 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -84,10 +84,16 @@ public: */ virtual ~CellularDevice(); - /** Set cellular device power supply on. + /** Sets the modem up for powering on + * This is equivalent to plugging in the device, i.e., attaching power and serial port. + * In general, hard_power_on and soft_power_on provides a simple hardware abstraction layer + * on top of the modem drivers written for Mbed OS; they can be overridden + * in a derived class to perform custom power controls in a particular board configuration. + * In many boards this will be a no-op if there is no separate power supply control circuitry. * - * CellularStateMachine calls hard_power_on, soft_power_on and init when requested to connect - * if the modem is not responding. + * @remark CellularStateMachine calls hard_power_on at first until successful, + * then soft_power_on and init until the modem responds. + * If you are not using CellularStateMachine then you need to call these functions yourself. * * @post You must call soft_power_on to power on the modem after calling hard_power_on. * @@ -95,9 +101,15 @@ public: */ virtual nsapi_error_t hard_power_on() = 0; - /** Set cellular device power supply off. + /** Sets the modem in unplugged state * - * CellularStateMachine disconnect does not shutdown or power off the modem. + * This is equivalent to pulling the plug off of the device, i.e., + * detaching power and serial port. + * + * This puts the modem in the lowest power state. + * + * @remark CellularStateMachine disconnect or destruct does not shutdown or power off the modem, + * but you need to do that yourself. * * @pre You must call soft_power_off to power off the modem before calling hard_power_off. * @@ -105,7 +117,15 @@ public: */ virtual nsapi_error_t hard_power_off() = 0; - /** Set cellular device power on, i.e. start the modem. + /** Powers up the modem + * + * This is equivalent to pressing the "power button" to activate or reset the modem + * and usually implemented as a short pulse on a dedicated GPIO signal. + * It is expected to be present to make it possible to reset the modem. + * The driver may repeat this if the modem is not responsive to AT commands. + * + * @remark CellularStateMachine calls this when requested to connect. + * If you are not using CellularStateMachine then you need to call this function yourself. * * @post You must call init to setup the modem. * @@ -113,7 +133,12 @@ public: */ virtual nsapi_error_t soft_power_on() = 0; - /** Set cellular device power off. + /** Powers down the modem + * + * This is equivalent to turning off the modem by button press. + * + * @remark CellularStateMachine disconnect or destruct does not shutdown or power off the modem, + * but you need to do that yourself. * * @pre You must call shutdown to prepare the modem for power off. * @@ -314,7 +339,7 @@ public: * For example, when multiple cellular modules are supported in a single driver this function * detects and adapts to an actual module at runtime. * - * CellularStateMachine calls soft_power_on and init repeatedly when starting to connect + * @remark CellularStateMachine calls soft_power_on and init repeatedly when starting to connect * until the modem responds. * * @return NSAPI_ERROR_OK on success diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 85683fbdc6..8bc75b85b4 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -141,7 +141,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, MBED_CONF_GEMALTO_CINTERION_BAUDRATE); #if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) - tr_info("GEMALTO_CINTERION flow control: RTS %d CTS %d", MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS); + tr_debug("GEMALTO_CINTERION flow control: RTS %d CTS %d", MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS); #endif static GEMALTO_CINTERION device(&serial); diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp index a76f386f24..a7203fb0c4 100644 --- a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp @@ -44,7 +44,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_GENERIC_AT3GPP_TX, MBED_CONF_GENERIC_AT3GPP_RX, MBED_CONF_GENERIC_AT3GPP_BAUDRATE); #if defined (MBED_CONF_GENERIC_AT3GPP_RTS) && defined(MBED_CONF_GENERIC_AT3GPP_CTS) - tr_info("GENERIC_AT3GPP flow control: RTS %d CTS %d", MBED_CONF_GENERIC_AT3GPP_RTS, MBED_CONF_GENERIC_AT3GPP_CTS); + tr_debug("GENERIC_AT3GPP flow control: RTS %d CTS %d", MBED_CONF_GENERIC_AT3GPP_RTS, MBED_CONF_GENERIC_AT3GPP_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_GENERIC_AT3GPP_RTS, MBED_CONF_GENERIC_AT3GPP_CTS); #endif static GENERIC_AT3GPP device(&serial); diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index e2ad58b0b7..55fe2df1de 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -49,7 +49,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_SARA4_PPP_TX, MBED_CONF_SARA4_PPP_RX, MBED_CONF_SARA4_PPP_BAUDRATE); #if defined (MBED_CONF_SARA4_PPP_RTS) && defined (MBED_CONF_SARA4_PPP_CTS) - tr_info("SARA4_PPP flow control: RTS %d CTS %d", MBED_CONF_SARA4_PPP_RTS, MBED_CONF_SARA4_PPP_CTS); + tr_debug("SARA4_PPP flow control: RTS %d CTS %d", MBED_CONF_SARA4_PPP_RTS, MBED_CONF_SARA4_PPP_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_SARA4_PPP_RTS, MBED_CONF_SARA4_PPP_CTS); #endif static SARA4_PPP device(&serial); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 2ec7a8c5ec..a76aedccb9 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -97,7 +97,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_QUECTEL_BC95_TX, MBED_CONF_QUECTEL_BC95_RX, MBED_CONF_QUECTEL_BC95_BAUDRATE); #if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) - tr_info("QUECTEL_BC95 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS); + tr_debug("QUECTEL_BC95 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS); #endif static QUECTEL_BC95 device(&serial); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 1f3bb1c4ee..84ca203e2c 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -74,7 +74,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_QUECTEL_BG96_TX, MBED_CONF_QUECTEL_BG96_RX, MBED_CONF_QUECTEL_BG96_BAUDRATE); #if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) - tr_info("QUECTEL_BG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS); + tr_debug("QUECTEL_BG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS); #endif static QUECTEL_BG96 device(&serial); diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index ef8f89f3cc..695ce9f502 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -55,7 +55,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_QUECTEL_UG96_TX, MBED_CONF_QUECTEL_UG96_RX, MBED_CONF_QUECTEL_UG96_BAUDRATE); #if defined (MBED_CONF_QUECTEL_UG96_RTS) && defined (MBED_CONF_QUECTEL_UG96_CTS) - tr_info("QUECTEL_UG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_UG96_RTS, MBED_CONF_QUECTEL_UG96_CTS); + tr_debug("QUECTEL_UG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_UG96_RTS, MBED_CONF_QUECTEL_UG96_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_UG96_RTS, MBED_CONF_QUECTEL_UG96_CTS); #endif static QUECTEL_UG96 device(&serial); diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 31ff705ce3..cd25409d82 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -62,7 +62,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_TELIT_HE910_TX, MBED_CONF_TELIT_HE910_RX, MBED_CONF_TELIT_HE910_BAUDRATE); #if defined (MBED_CONF_TELIT_HE910_RTS) && defined (MBED_CONF_TELIT_HE910_CTS) - tr_info("TELIT_HE910 flow control: RTS %d CTS %d", MBED_CONF_TELIT_HE910_RTS, MBED_CONF_TELIT_HE910_CTS); + tr_debug("TELIT_HE910 flow control: RTS %d CTS %d", MBED_CONF_TELIT_HE910_RTS, MBED_CONF_TELIT_HE910_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_TELIT_HE910_RTS, MBED_CONF_TELIT_HE910_CTS); #endif static TELIT_HE910 device(&serial); diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index 58e04d1d71..c47d9779d1 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -70,7 +70,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_UBLOX_AT_TX, MBED_CONF_UBLOX_AT_RX, MBED_CONF_UBLOX_AT_BAUDRATE); #if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) - tr_info("UBLOX_AT flow control: RTS %d CTS %d", MBED_CONF_UBLOX_AT_RTS, MBED_CONF_UBLOX_AT_CTS); + tr_debug("UBLOX_AT flow control: RTS %d CTS %d", MBED_CONF_UBLOX_AT_RTS, MBED_CONF_UBLOX_AT_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_UBLOX_AT_RTS, MBED_CONF_UBLOX_AT_CTS); #endif static UBLOX_AT device(&serial); diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index 61536997cf..0acc86b7c5 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -63,7 +63,7 @@ CellularDevice *CellularDevice::get_default_instance() { static UARTSerial serial(MBED_CONF_UBLOX_PPP_TX, MBED_CONF_UBLOX_PPP_RX, MBED_CONF_UBLOX_PPP_BAUDRATE); #if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS) - tr_info("UBLOX_PPP flow control: RTS %d CTS %d", MBED_CONF_UBLOX_PPP_RTS, MBED_CONF_UBLOX_PPP_CTS); + tr_debug("UBLOX_PPP flow control: RTS %d CTS %d", MBED_CONF_UBLOX_PPP_RTS, MBED_CONF_UBLOX_PPP_CTS); serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_UBLOX_PPP_RTS, MBED_CONF_UBLOX_PPP_CTS); #endif static UBLOX_PPP device(&serial); diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp index 8e96d3cdf5..614f07289e 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp @@ -54,7 +54,7 @@ CellularDevice *CellularDevice::get_target_default_instance() static UARTSerial serial(MDMTXD, MDMRXD, 115200); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { - tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); } #endif diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp index 80a7583695..082ac9097f 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp @@ -54,7 +54,7 @@ CellularDevice *CellularDevice::get_target_default_instance() static UARTSerial serial(MDMTXD, MDMRXD, 115200); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { - tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); } #endif diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp index 1d83eb9425..cd2a74cd9a 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp @@ -25,10 +25,6 @@ ONBOARD_QUECTEL_BG96::ONBOARD_QUECTEL_BG96(FileHandle *fh) : QUECTEL_BG96(fh) { } -ONBOARD_QUECTEL_BG96::~ONBOARD_QUECTEL_BG96() -{ -} - nsapi_error_t ONBOARD_QUECTEL_BG96::hard_power_on() { ::onboard_modem_init(); diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h index ccfc83383f..1416660ec7 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.h @@ -24,7 +24,6 @@ namespace mbed { class ONBOARD_QUECTEL_BG96 : public QUECTEL_BG96 { public: ONBOARD_QUECTEL_BG96(FileHandle *fh); - virtual ~ONBOARD_QUECTEL_BG96(); virtual nsapi_error_t hard_power_on(); virtual nsapi_error_t hard_power_off(); diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp index c06578a3a6..029b2569af 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp @@ -54,7 +54,7 @@ CellularDevice *CellularDevice::get_target_default_instance() static UARTSerial serial(MDMTXD, MDMRXD, 115200); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { - tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); } #endif diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp index 5cbdff81e2..4bce3631b0 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp @@ -55,7 +55,7 @@ CellularDevice *CellularDevice::get_target_default_instance() static UARTSerial serial(MDMTXD, MDMRXD, 9600); #if DEVICE_SERIAL_FC if (MDMRTS != NC && MDMCTS != NC) { - tr_info("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); + tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); } #endif From 007caa0235df6e79c50ec96ac4f420fb92e02e21 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Tue, 22 Jan 2019 02:22:21 -0800 Subject: [PATCH 33/41] Cellular: Update modem drivers with get_default and other new APIs --- .../at_cellularcontexttest.cpp | 4 - features/cellular/TESTS/socket/udp/main.cpp | 4 - .../targets/QUECTEL/M26/QUECTEL_M26.cpp | 91 +++++++++++++------ .../targets/QUECTEL/M26/QUECTEL_M26.h | 18 +++- .../M26/QUECTEL_M26_CellularContext.cpp | 15 +-- .../QUECTEL/M26/QUECTEL_M26_CellularContext.h | 4 +- ....h => QUECTEL_M26_CellularInformation.cpp} | 30 +++--- ...er.h => QUECTEL_M26_CellularInformation.h} | 21 ++--- .../M26/QUECTEL_M26_CellularNetwork.cpp | 45 --------- .../QUECTEL/M26/QUECTEL_M26_CellularPower.cpp | 60 ------------ .../QUECTEL/M26/QUECTEL_M26_CellularSIM.cpp | 88 ------------------ .../QUECTEL/M26/QUECTEL_M26_CellularSIM.h | 39 -------- .../targets/QUECTEL/M26/mbed_lib.json | 29 ++++++ .../targets/QUECTEL/UG96/QUECTEL_UG96.h | 2 - .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 1 - .../framework/targets/UBLOX/AT/UBLOX_AT.h | 2 - 16 files changed, 134 insertions(+), 319 deletions(-) rename features/cellular/framework/targets/QUECTEL/M26/{QUECTEL_M26_CellularNetwork.h => QUECTEL_M26_CellularInformation.cpp} (55%) rename features/cellular/framework/targets/QUECTEL/M26/{QUECTEL_M26_CellularPower.h => QUECTEL_M26_CellularInformation.h} (61%) delete mode 100644 features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.cpp delete mode 100644 features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.cpp delete mode 100644 features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.cpp delete mode 100644 features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.h create mode 100644 features/cellular/framework/targets/QUECTEL/M26/mbed_lib.json diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp index f592013ab8..100ac9753a 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp @@ -142,10 +142,6 @@ public: my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) : AT_CellularContext(at, device, apn), _st(at) {} virtual ~my_AT_CTXIPV6() {} - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type) - { - return true; - } virtual NetworkStack *get_stack() { return &_st; diff --git a/features/cellular/TESTS/socket/udp/main.cpp b/features/cellular/TESTS/socket/udp/main.cpp index f89afe9310..c5b856c9e0 100644 --- a/features/cellular/TESTS/socket/udp/main.cpp +++ b/features/cellular/TESTS/socket/udp/main.cpp @@ -22,10 +22,6 @@ #include "CellularUtil.h" // for CELLULAR_ helper macros #include "CellularTargets.h" -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - #ifndef MBED_CONF_APP_CELLULAR_SIM_PIN #error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. #endif diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp index a5efe042d9..6264a78e2c 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp @@ -1,4 +1,5 @@ /* +#include * Copyright (c) 2018, Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * @@ -15,53 +16,89 @@ * limitations under the License. */ -#include "QUECTEL_M26_CellularNetwork.h" -#include "QUECTEL_M26_CellularPower.h" -#include "QUECTEL_M26_CellularSIM.h" +#include "AT_CellularNetwork.h" #include "QUECTEL_M26_CellularContext.h" #include "QUECTEL_M26.h" -using namespace events; +#include "CellularLog.h" + using namespace mbed; -#define CONNECT_DELIM "\r\n" -#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format -#define CONNECT_TIMEOUT 8000 - -#define MAX_STARTUP_TRIALS 5 -#define MAX_RESET_TRIALS 5 - -static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::AT_CGAUTH, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeDisable,// C_EREG + AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeDisable,// C_REG + 0, // AT_CGSN_WITH_TYPE + 1, // AT_CGDATA + 0, // AT_CGAUTH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK }; QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh) { - AT_CellularBase::set_unsupported_features(unsupported_features); + AT_CellularBase::set_cellular_properties(cellular_properties); } -QUECTEL_M26::~QUECTEL_M26() +nsapi_error_t QUECTEL_M26::get_sim_state(SimState &state) { + char buf[13]; + + _at->lock(); + _at->cmd_start("AT+CPIN?"); + _at->cmd_stop(); + _at->resp_start("+CPIN:"); + if (_at->info_resp()) { + _at->read_string(buf, 13); + tr_debug("CPIN: %s", buf); + + if (memcmp(buf, "READY", 5) == 0) { + state = SimStateReady; + } else if (memcmp(buf, "SIM PIN", 7) == 0) { + state = SimStatePinNeeded; + } else if (memcmp(buf, "SIM PUK", 7) == 0) { + state = SimStatePukNeeded; + } else if (memcmp(buf, "PH_SIM PIN", 10) == 0) { + state = SimStatePinNeeded; + } else if (memcmp(buf, "PH_SIM PUK", 10) == 0) { + state = SimStatePukNeeded; + } else if (memcmp(buf, "SIM PIN2", 8) == 0) { + state = SimStatePinNeeded; + } else if (memcmp(buf, "SIM PUK2", 8) == 0) { + state = SimStatePukNeeded; + } else { + state = SimStateUnknown; // SIM may not be ready yet + } + + } + _at->resp_stop(); + return _at->unlock_return_error(); } -AT_CellularNetwork *QUECTEL_M26::open_network_impl(ATHandler &at) +AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { - return new QUECTEL_M26_CellularNetwork(at); + return new QUECTEL_M26_CellularContext(at, this, apn, cp_req, nonip_req); } -AT_CellularPower *QUECTEL_M26::open_power_impl(ATHandler &at) +nsapi_error_t QUECTEL_M26::init() { - return new QUECTEL_M26_CellularPower(at); + _at->lock(); + _at->cmd_start("AT"); + _at->cmd_stop_read_resp(); + _at->cmd_start("AT+CMEE="); // verbose responses + _at->write_int(1); + _at->cmd_stop_read_resp(); + return _at->unlock_return_error(); } -AT_CellularSIM *QUECTEL_M26::open_sim_impl(ATHandler &at) +nsapi_error_t QUECTEL_M26::shutdown() { - return new QUECTEL_M26_CellularSIM(at); -} + _at->lock(); + _at->cmd_start("AT+QPOWD=0"); + _at->cmd_stop(); + _at->resp_start(); + _at->resp_stop(); -AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn) -{ - return new QUECTEL_M26_CellularContext(at, this, apn); + return _at->unlock_return_error();; } diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.h b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.h index 05053e0308..6819822e85 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.h +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.h @@ -18,6 +18,15 @@ #ifndef QUECTEL_M26_H_ #define QUECTEL_M26_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_QUECTEL_M26_TX +#define MBED_CONF_QUECTEL_M26_TX D1 +#endif +#ifndef MBED_CONF_QUECTEL_M26_RX +#define MBED_CONF_QUECTEL_M26_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "AT_CellularDevice.h" namespace mbed { @@ -25,13 +34,12 @@ namespace mbed { class QUECTEL_M26 : public AT_CellularDevice { public: QUECTEL_M26(FileHandle *fh); - virtual ~QUECTEL_M26(); protected: // AT_CellularDevice - virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularSIM *open_sim_impl(ATHandler &at); - virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual nsapi_error_t get_sim_state(SimState &state); + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); + virtual nsapi_error_t init(); + virtual nsapi_error_t shutdown(); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp index 04d0cb21ee..852f2c437b 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp @@ -19,25 +19,16 @@ namespace mbed { -QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) : - AT_CellularContext(at, device, apn) +QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : + AT_CellularContext(at, device, apn, cp_req, nonip_req) { } -QUECTEL_M26_CellularContext::~QUECTEL_M26_CellularContext() -{ -} - -bool QUECTEL_M26_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type) -{ - return stack_type == IPV4_STACK ? true : false; -} - #if !NSAPI_PPP_AVAILABLE NetworkStack *QUECTEL_M26_CellularContext::get_stack() { if (!_stack) { - _stack = new QUECTEL_M26_CellularStack(_at, _cid, _ip_stack_type); + _stack = new QUECTEL_M26_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type); } return _stack; } diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.h b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.h index ae66b9fd31..ba27bc5983 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.h +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.h @@ -23,11 +23,9 @@ namespace mbed { class QUECTEL_M26_CellularContext: public AT_CellularContext { public: - QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn); - virtual ~QUECTEL_M26_CellularContext(); + QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false); protected: - virtual bool stack_type_supported(nsapi_ip_stack_t stack_type); #if !NSAPI_PPP_AVAILABLE virtual NetworkStack *get_stack(); #endif // #if !NSAPI_PPP_AVAILABLE diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.h b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp similarity index 55% rename from features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.h rename to features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp index 0aff1e3e36..f55edcc961 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.h +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp @@ -15,21 +15,23 @@ * limitations under the License. */ -#ifndef QUECTEL_M26_CELLULAR_NETWORK_H_ -#define QUECTEL_M26_CELLULAR_NETWORK_H_ +#include "QUECTEL_M26_CellularInformation.h" -#include "AT_CellularNetwork.h" +using namespace mbed; -namespace mbed { +QUECTEL_M26_CellularInformation::QUECTEL_M26_CellularInformation(ATHandler &atHandler) : AT_CellularInformation(atHandler) +{ -class QUECTEL_M26_CellularNetwork : public AT_CellularNetwork { -public: - QUECTEL_M26_CellularNetwork(ATHandler &atHandler); - virtual ~QUECTEL_M26_CellularNetwork(); +} -protected: - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); - virtual RegistrationMode has_registration(RegistrationType reg_type); -}; -} // namespace mbed -#endif // QUECTEL_M26_CELLULAR_NETWORK_H_ +// According to M26_AT_Commands_Manual_V1.9 +nsapi_error_t QUECTEL_M26_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + _at.lock(); + _at.cmd_start("AT+CCID"); + _at.cmd_stop(); + _at.resp_start("+CCID:"); + _at.read_string(buf, buf_size); + _at.resp_stop(); + return _at.unlock_return_error(); +} diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.h b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.h similarity index 61% rename from features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.h rename to features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.h index c62a7f5be8..a1a48a6f23 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.h +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.h @@ -15,26 +15,21 @@ * limitations under the License. */ -#ifndef QUECTEL_M26_CELLULAR_POWER_H_ -#define QUECTEL_M26_CELLULAR_POWER_H_ +#ifndef QUECTEL_M26_CELLULAR_INFORMATION_H_ +#define QUECTEL_M26_CELLULAR_INFORMATION_H_ -#include "AT_CellularPower.h" +#include "AT_CellularInformation.h" namespace mbed { -class QUECTEL_M26_CellularPower : public AT_CellularPower { +class QUECTEL_M26_CellularInformation : public AT_CellularInformation { public: - QUECTEL_M26_CellularPower(ATHandler &atHandler); - virtual ~QUECTEL_M26_CellularPower(); + QUECTEL_M26_CellularInformation(ATHandler &atHandler); -public: //from CellularPower - virtual nsapi_error_t set_at_mode(); - - virtual nsapi_error_t on(); - - virtual nsapi_error_t off(); +public: //from CellularInformation + virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); }; } // namespace mbed -#endif // QUECTEL_M26_CELLULAR_POWER_H_ +#endif // QUECTEL_M26_CELLULAR_INFORMATION_H_ diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.cpp deleted file mode 100644 index 0ee5464fd8..0000000000 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_M26_CellularNetwork.h" - -using namespace mbed; - -QUECTEL_M26_CellularNetwork::QUECTEL_M26_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler) -{ - _op_act = RAT_EGPRS; -} - -QUECTEL_M26_CellularNetwork::~QUECTEL_M26_CellularNetwork() -{ -} - -AT_CellularNetwork::RegistrationMode QUECTEL_M26_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return (reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable; -} - -nsapi_error_t QUECTEL_M26_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) -{ - if (opRat != RAT_EGPRS) { - // only GPRS support in the driver. - _op_act = RAT_EGPRS; - return NSAPI_ERROR_UNSUPPORTED; - } - - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.cpp deleted file mode 100644 index 2ab2b9a1dd..0000000000 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_M26_CellularPower.h" - -using namespace mbed; - -QUECTEL_M26_CellularPower::QUECTEL_M26_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler) -{ - -} - -QUECTEL_M26_CellularPower::~QUECTEL_M26_CellularPower() -{ - -} - -nsapi_error_t QUECTEL_M26_CellularPower::set_at_mode() -{ - _at.lock(); - _at.cmd_start("AT"); - _at.cmd_stop_read_resp(); - - _at.cmd_start("AT+CMEE="); // verbose responses - _at.write_int(1); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); -} - -nsapi_error_t QUECTEL_M26_CellularPower::on() -{ - - return NSAPI_ERROR_OK; -} - -nsapi_error_t QUECTEL_M26_CellularPower::off() -{ - _at.lock(); - _at.cmd_start("AT+QPOWD=0"); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - - return _at.unlock_return_error();; -} diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.cpp deleted file mode 100644 index 0b4fa84659..0000000000 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "QUECTEL_M26_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -QUECTEL_M26_CellularSIM::QUECTEL_M26_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler) -{ - -} - -QUECTEL_M26_CellularSIM::~QUECTEL_M26_CellularSIM() -{ - -} - -nsapi_error_t QUECTEL_M26_CellularSIM::get_sim_state(SimState &state) -{ - char buf[13]; - - _at.lock(); - _at.cmd_start("AT+CPIN?"); - _at.cmd_stop(); - _at.resp_start("+CPIN:"); - if (_at.info_resp()) { - _at.read_string(buf, 13); - tr_debug("CPIN: %s", buf); - - if (memcmp(buf, "READY", 5) == 0) { - state = SimStateReady; - } else if (memcmp(buf, "SIM PIN", 7) == 0) { - state = SimStatePinNeeded; - } else if (memcmp(buf, "SIM PUK", 7) == 0) { - state = SimStatePukNeeded; - } else if (memcmp(buf, "PH_SIM PIN", 10) == 0) { - state = SimStatePinNeeded; - } else if (memcmp(buf, "PH_SIM PUK", 10) == 0) { - state = SimStatePukNeeded; - } else if (memcmp(buf, "SIM PIN2", 8) == 0) { - state = SimStatePinNeeded; - } else if (memcmp(buf, "SIM PUK2", 8) == 0) { - state = SimStatePukNeeded; - } else { - state = SimStateUnknown; // SIM may not be ready yet - } - - } - _at.resp_stop(); - return _at.unlock_return_error(); -} - -// According to M26_AT_Commands_Manual_V1.9 -nsapi_error_t QUECTEL_M26_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - _at.lock(); - _at.cmd_start("AT+CCID"); - _at.cmd_stop(); - _at.resp_start("+CCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); -} - -nsapi_error_t QUECTEL_M26_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t QUECTEL_M26_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.h b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.h deleted file mode 100644 index 8cf227a70c..0000000000 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularSIM.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef QUECTEL_M26_CELLULAR_SIM_H_ -#define QUECTEL_M26_CELLULAR_SIM_H_ - -#include "AT_CellularSIM.h" - -namespace mbed { - -class QUECTEL_M26_CellularSIM : public AT_CellularSIM { -public: - QUECTEL_M26_CellularSIM(ATHandler &atHandler); - virtual ~QUECTEL_M26_CellularSIM(); - -public: //from CellularSIM - virtual nsapi_error_t get_sim_state(SimState &state); - virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); - virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin); - virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin); -}; - -} // namespace mbed - -#endif // QUECTEL_M26_CELLULAR_SIM_H_ diff --git a/features/cellular/framework/targets/QUECTEL/M26/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/M26/mbed_lib.json new file mode 100644 index 0000000000..656c9e1306 --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/M26/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "QUECTEL_M26", + "config": { + "tx": { + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", + "value": null + }, + "rx": { + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 115200 + }, + "provide-default": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h index 9752ca6d8e..fbd47a6e34 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h @@ -44,8 +44,6 @@ public: QUECTEL_UG96(FileHandle *fh); protected: // AT_CellularDevice - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); public: // NetworkInterface diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index c47d9779d1..b4bb6cbfb3 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -50,7 +50,6 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh) { -#ifdef TARGET_UBLOX_C030_R41XM AT_CellularBase::set_cellular_properties(cellular_properties); } diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h index c91d58deb0..01950cb482 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h @@ -36,8 +36,6 @@ public: UBLOX_AT(FileHandle *fh); protected: // AT_CellularDevice - virtual nsapi_error_t power_on(); - virtual nsapi_error_t power_off(); virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); public: // NetworkInterface From b16d8dbf3bf1a2a7ff27e3a71a450d3b20b39001 Mon Sep 17 00:00:00 2001 From: Jari Poyhonen Date: Tue, 22 Jan 2019 10:31:17 +0200 Subject: [PATCH 34/41] cellular unit test updates due valgrind run --- .../framework/common/util/utiltest.cpp | 3 +-- .../cellulardevice/cellulardevicetest.cpp | 2 +- UNITTESTS/stubs/ATHandler_stub.cpp | 4 ++-- UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 19 ++++++++++++++----- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp index 09f87c87e1..a2b5b4dcc9 100644 --- a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp +++ b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp @@ -138,8 +138,7 @@ TEST_F(Testutil, prefer_ipv6) TEST_F(Testutil, separate_ip_addresses) { - char *s = (char *)malloc(128); - + char s[128] = {'\0'}; char ip[64] = {0}; char subnet[64] = {0}; diff --git a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp index 79d490bbec..d73ea9ff0e 100644 --- a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp @@ -184,11 +184,11 @@ TEST_F(TestCellularDevice, test_get_context_list) CellularContext *ctx = dev->create_context(); EXPECT_TRUE(dev->get_context_list()); delete dev; - dev = NULL; dev = new myCellularDevice(&fh1); EXPECT_TRUE(dev); EXPECT_FALSE(dev->get_context_list()); + delete dev; } TEST_F(TestCellularDevice, test_stop) diff --git a/UNITTESTS/stubs/ATHandler_stub.cpp b/UNITTESTS/stubs/ATHandler_stub.cpp index a1ee341604..ed27564dcc 100644 --- a/UNITTESTS/stubs/ATHandler_stub.cpp +++ b/UNITTESTS/stubs/ATHandler_stub.cpp @@ -51,11 +51,11 @@ int ATHandler_stub::int_count = kRead_int_table_size; bool ATHandler_stub::process_oob_urc = false; int ATHandler_stub::read_string_index = kRead_string_table_size; -const char *ATHandler_stub::read_string_table[kRead_string_table_size]; +const char *ATHandler_stub::read_string_table[kRead_string_table_size] = {'\0'}; int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; int ATHandler_stub::urc_amount = 0; mbed::Callback ATHandler_stub::callback[kATHandler_urc_table_max_size]; -char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size]; +char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {'\0'}; ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) : _nextATHandler(0), diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index a0fc3178c0..69e8df2f98 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -24,7 +24,6 @@ const int DEFAULT_AT_TIMEOUT = 1000; using namespace mbed; - int AT_CellularDevice_stub::failure_count = 0; nsapi_error_t AT_CellularDevice_stub::nsapi_error_value = 0; int AT_CellularDevice_stub::init_module_failure_count = 0; @@ -33,8 +32,7 @@ int AT_CellularDevice_stub::get_sim_failure_count = 0; bool AT_CellularDevice_stub::pin_needed = false; AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), - _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), - _modem_debug_on(false) + _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) { } @@ -77,7 +75,13 @@ void delete_context(CellularContext *context) CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) { - return new AT_CellularNetwork(*ATHandler::get_instance(fh, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on)); + _network = new AT_CellularNetwork(*ATHandler::get_instance(fh, + _queue, + _default_timeout, + "\r", + get_send_delay(), + _modem_debug_on)); + return _network; } CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) @@ -92,6 +96,9 @@ CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) void AT_CellularDevice::close_network() { + delete _network; + + _network = NULL; } void AT_CellularDevice::close_sms() @@ -123,7 +130,9 @@ void AT_CellularDevice::delete_context(CellularContext *context) AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at) { - return new AT_CellularNetwork(at); + _network = new AT_CellularNetwork(at); + + return _network; } AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at) From 84536bd09ecd1dfa9cfe91479a2f62b125cb3da1 Mon Sep 17 00:00:00 2001 From: Jari Poyhonen Date: Tue, 22 Jan 2019 10:31:57 +0200 Subject: [PATCH 35/41] cellular ATHandler update due valgrind run --- features/cellular/framework/AT/ATHandler.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index 5144f37757..4066d42901 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -599,13 +599,11 @@ int32_t ATHandler::read_int() } char buff[BUFF_SIZE]; - char *first_no_digit; - - if (read_string(buff, (size_t)sizeof(buff)) == 0) { + if (read_string(buff, sizeof(buff)) == 0) { return -1; } - return std::strtol(buff, &first_no_digit, 10); + return std::strtol(buff, NULL, 10); } void ATHandler::set_delimiter(char delimiter) @@ -1211,8 +1209,9 @@ void ATHandler::debug_print(const char *p, int len) #if MBED_CONF_MBED_TRACE_ENABLE mbed_cellular_trace::mutex_wait(); #endif + char c; for (ssize_t i = 0; i < len; i++) { - char c = *p++; + c = *p++; if (!isprint(c)) { if (c == '\r') { debug("\n"); From 626935f33176bad41f8e1c7ea32b1079127474ef Mon Sep 17 00:00:00 2001 From: Jari Poyhonen Date: Tue, 22 Jan 2019 12:53:33 +0200 Subject: [PATCH 36/41] Fix valgrind error in cellular athandler unit test --- .../features/cellular/framework/AT/athandler/athandlertest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp index a7ee8227bd..34615e3de1 100644 --- a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp @@ -112,7 +112,6 @@ TEST_F(TestATHandler, test_ATHandler_list) EXPECT_TRUE(at1->close() == NSAPI_ERROR_OK); EXPECT_TRUE(at2->get_ref_count() == 1); EXPECT_TRUE(at2->close() == NSAPI_ERROR_OK); - EXPECT_TRUE(at1->close() == NSAPI_ERROR_PARAMETER); ATHandler::set_at_timeout_list(1000, false); ATHandler::set_debug_list(false); From 9f9fce4974de5e45059a1b702b934e9a74cf8f8c Mon Sep 17 00:00:00 2001 From: Jari Poyhonen Date: Wed, 23 Jan 2019 12:22:12 +0200 Subject: [PATCH 37/41] Add word to ignore.en.pws file --- tools/test/travis-ci/doxy-spellchecker/ignore.en.pws | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws b/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws index 7030a5dce5..dd25563c2a 100644 --- a/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws +++ b/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws @@ -1,5 +1,6 @@ personal_ws-1.1 en 1600 utf-8 _code_ +unconfigured mbed rtos malloc From 95839662c695c6b998fce8ea0bcc408090f29239 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Wed, 23 Jan 2019 05:38:28 -0800 Subject: [PATCH 38/41] Cellular: Fix cellular specific Greentea tests --- .../TESTS/api/cellular_device/main.cpp | 47 +++++++---------- .../TESTS/api/cellular_information/main.cpp | 4 -- .../TESTS/api/cellular_network/main.cpp | 51 ------------------- .../cellular/TESTS/api/cellular_sms/main.cpp | 29 ++++------- features/cellular/TESTS/socket/udp/main.cpp | 4 -- .../framework/AT/AT_CellularContext.cpp | 5 +- .../framework/device/CellularDevice.cpp | 2 + .../framework/device/CellularStateMachine.cpp | 3 ++ .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 14 +++-- .../GEMALTO/CINTERION/GEMALTO_CINTERION.h | 2 + .../GEMALTO_CINTERION_CellularInformation.cpp | 37 ++++++++++++++ .../GEMALTO_CINTERION_CellularInformation.h | 35 +++++++++++++ .../ONBOARD_QUECTEL_BC95.cpp | 5 -- .../travis-ci/doxy-spellchecker/ignore.en.pws | 1 + 14 files changed, 119 insertions(+), 120 deletions(-) create mode 100644 features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp create mode 100644 features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.h diff --git a/features/cellular/TESTS/api/cellular_device/main.cpp b/features/cellular/TESTS/api/cellular_device/main.cpp index c2a7861f30..f300fa677a 100644 --- a/features/cellular/TESTS/api/cellular_device/main.cpp +++ b/features/cellular/TESTS/api/cellular_device/main.cpp @@ -19,13 +19,6 @@ #error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. #endif -#include "CellularUtil.h" // for CELLULAR_ helper macros -#include "CellularTargets.h" - -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - #ifndef MBED_CONF_APP_CELLULAR_SIM_PIN #error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. #endif @@ -38,11 +31,9 @@ #include "CellularLog.h" #include "CellularDevice.h" -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) #include "Semaphore.h" #include "../../cellular_tests_common.h" -static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); static CellularDevice *device; static rtos::Semaphore semaphore; @@ -60,21 +51,21 @@ static CurrentOp op; static void create_device() { - device = new CELLULAR_DEVICE(&cellular_serial); + device = CellularDevice::get_default_instance(); TEST_ASSERT(device != NULL); } static void open_close_interfaces() { - CellularNetwork *nw = device->open_network(&cellular_serial); + CellularNetwork *nw = device->open_network(); TEST_ASSERT(nw != NULL); device->close_network(); - CellularInformation *info = device->open_information(&cellular_serial); + CellularInformation *info = device->open_information(); TEST_ASSERT(info != NULL); device->close_information(); - CellularSMS *sms = device->open_sms(&cellular_serial); + CellularSMS *sms = device->open_sms(); TEST_ASSERT(sms != NULL); device->close_sms(); @@ -91,7 +82,7 @@ static void other_methods() device->modem_debug_on(true); device->modem_debug_on(false); - CellularNetwork *nw = device->open_network(&cellular_serial); + CellularNetwork *nw = device->open_network(); TEST_ASSERT(nw != NULL); // then test with open interface which is called @@ -100,21 +91,17 @@ static void other_methods() device->modem_debug_on(false); TEST_ASSERT(device->get_queue() != NULL); - TEST_ASSERT_EQUAL_INT(device->init_module(), NSAPI_ERROR_OK); + TEST_ASSERT(device->hard_power_on() == NSAPI_ERROR_OK); + TEST_ASSERT(device->soft_power_on() == NSAPI_ERROR_OK); + wait(5); + TEST_ASSERT_EQUAL_INT(device->init(), NSAPI_ERROR_OK); } -static void shutdown_reset() +static void shutdown() { - 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); -} - -static void delete_device() -{ - // delete will close all opened interfaces - delete device; - device = NULL; + TEST_ASSERT(device->soft_power_off() == NSAPI_ERROR_OK); + TEST_ASSERT(device->hard_power_off() == NSAPI_ERROR_OK); } static void callback_func(nsapi_event_t ev, intptr_t ptr) @@ -155,7 +142,9 @@ static void init_to_device_ready_state() device->attach(&callback_func); op = OP_DEVICE_READY; - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init_module()); + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->hard_power_on()); + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->soft_power_on()); + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init()); TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->set_device_ready()); int sema_err = semaphore.wait(TIME_OUT_DEVICE_READY); @@ -204,13 +193,11 @@ static Case cases[] = { Case("CellularDevice create device", create_device, greentea_failure_handler), Case("CellularDevice Open and close interfaces", open_close_interfaces, greentea_failure_handler), Case("CellularDevice other methods", other_methods, greentea_failure_handler), - Case("CellularDevice delete device", delete_device, greentea_failure_handler), Case("CellularDevice init to device ready", init_to_device_ready_state, greentea_failure_handler), 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) + Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler), + Case("CellularDevice shutdown", shutdown, greentea_failure_handler), }; static utest::v1::status_t test_setup(const size_t number_of_cases) diff --git a/features/cellular/TESTS/api/cellular_information/main.cpp b/features/cellular/TESTS/api/cellular_information/main.cpp index bf18c553e2..8865bc920f 100644 --- a/features/cellular/TESTS/api/cellular_information/main.cpp +++ b/features/cellular/TESTS/api/cellular_information/main.cpp @@ -23,10 +23,6 @@ #include "CellularUtil.h" // for CELLULAR_ helper macros #include "CellularTargets.h" -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - #ifndef MBED_CONF_APP_CELLULAR_SIM_PIN #error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. #endif diff --git a/features/cellular/TESTS/api/cellular_network/main.cpp b/features/cellular/TESTS/api/cellular_network/main.cpp index b918f8df1a..73930b1013 100644 --- a/features/cellular/TESTS/api/cellular_network/main.cpp +++ b/features/cellular/TESTS/api/cellular_network/main.cpp @@ -20,21 +20,10 @@ #error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. #endif -#include "CellularUtil.h" // for CELLULAR_ helper macros -#include "CellularTargets.h" - -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - #ifndef MBED_CONF_APP_CELLULAR_SIM_PIN #error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. #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 -#endif - #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" @@ -45,7 +34,6 @@ #include "CellularContext.h" #include "CellularDevice.h" #include "../../cellular_tests_common.h" -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) #define NETWORK_TIMEOUT (180*1000) @@ -165,7 +153,6 @@ static void test_attach() static void test_other() { - const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE); TEST_ASSERT(nw->get_3gpp_error() == 0); nsapi_error_t err = nw->set_access_technology(CellularNetwork::RAT_GSM); @@ -204,52 +191,14 @@ static void test_other() nsapi_connection_status_t st = nw->get_connection_status(); TEST_ASSERT(st == NSAPI_STATUS_DISCONNECTED); -#ifndef TARGET_UBLOX_C027 // AT command is supported, but excluded as it runs out of memory easily (there can be very many operator names) - if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "SARA4_PPP") != 0) { - // QUECTEL_BG96 timeouts with this one, tested with 3 minute timeout - CellularNetwork::operator_names_list op_names; - err = nw->get_operator_names(op_names); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); - if (err == NSAPI_ERROR_DEVICE_ERROR) { - // if device error then we must check was that really device error or that modem/network does not support the commands - TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem - ((((AT_CellularNetwork *)nw)->get_device_error().errCode == 4) || // 4 == NOT SUPPORTED BY THE MODEM - (((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands - } else { - CellularNetwork::operator_names_t *opn = op_names.get_head(); - TEST_ASSERT(strlen(opn->numeric) > 0); - TEST_ASSERT(strlen(opn->alpha) > 0); - } - } -#endif - // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command CellularNetwork::CIoT_Supported_Opt supported_opt = CellularNetwork::CIOT_OPT_MAX; CellularNetwork::CIoT_Preferred_UE_Opt preferred_opt = CellularNetwork::PREFERRED_UE_OPT_MAX; err = nw->get_ciot_ue_optimization_config(supported_opt, preferred_opt); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); - if (err == NSAPI_ERROR_DEVICE_ERROR) { - // if device error then we must check was that really device error or that modem/network does not support the commands - if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0 || strcmp(devi, "SARA4_PPP") == 0)) { - TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem - ((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem - (((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands - } - } else { - TEST_ASSERT(supported_opt != CellularNetwork::CIOT_OPT_MAX); - TEST_ASSERT(preferred_opt != CellularNetwork::PREFERRED_UE_OPT_MAX); - } err = nw->set_ciot_optimization_config(supported_opt, preferred_opt, NULL); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR); - if (err == NSAPI_ERROR_DEVICE_ERROR) { - // if device error then we must check was that really device error or that modem/network does not support the commands - if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0 || strcmp(devi, "SARA4_PPP") == 0)) { - TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem - ((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem - (((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands - } - } } static void test_detach() diff --git a/features/cellular/TESTS/api/cellular_sms/main.cpp b/features/cellular/TESTS/api/cellular_sms/main.cpp index e4912a7a57..1c770c44ca 100644 --- a/features/cellular/TESTS/api/cellular_sms/main.cpp +++ b/features/cellular/TESTS/api/cellular_sms/main.cpp @@ -20,13 +20,6 @@ #error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. #endif -#include "CellularUtil.h" // for CELLULAR_ helper macros -#include "CellularTargets.h" - -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - #ifndef MBED_CONF_APP_CELLULAR_SIM_PIN #error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. #endif @@ -45,12 +38,10 @@ #include "CellularContext.h" #include "CellularDevice.h" #include "../../cellular_tests_common.h" -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) #define NETWORK_TIMEOUT (600*1000) #define SIM_BUSY 314 -static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); -static EventQueue queue(8 * EVENTS_EVENT_SIZE); + static CellularContext *ctx; static CellularDevice *device; static CellularSMS *sms; @@ -59,10 +50,10 @@ static int service_address_type; static void create_context() { - device = new CELLULAR_DEVICE(&cellular_serial); + device = CellularDevice::get_default_instance(); TEST_ASSERT(device != NULL); device->set_timeout(9000); - ctx = device->create_context(); + ctx = CellularContext::get_default_instance(); TEST_ASSERT(ctx != NULL); ctx->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN); #ifdef MBED_CONF_APP_APN @@ -75,12 +66,12 @@ static void store_service_center_address() // First we need to go SIM_PIN state to make sure that we can get service address and device ready to accept AT commands create_context(); TEST_ASSERT(ctx->set_sim_ready() == NSAPI_ERROR_OK); - wait(1); - delete device; // will also delete context - wait(3); // some modems needs more time access sim + wait(5); // some modems needs more time access sim - ATHandler *at_init = new ATHandler(&cellular_serial, queue, 30000, "\r"); + ATHandler *at_init = device->get_at_handler(); + at_init->lock(); + at_init->set_at_timeout(30 * 1000); at_init->cmd_start("AT+CSCA?"); at_init->cmd_stop(); @@ -90,10 +81,10 @@ static void store_service_center_address() at_init->read_string(service_center_address, sizeof(service_center_address)); service_address_type = at_init->read_int(); at_init->resp_stop(); - TEST_ASSERT(at_init->get_last_error() == NSAPI_ERROR_OK); - delete at_init; + at_init->unlock(); + device->release_at_handler(at_init); } static void init() @@ -103,7 +94,7 @@ static void init() create_context(); TEST_ASSERT(ctx->register_to_network() == NSAPI_ERROR_OK); - sms = device->open_sms(&cellular_serial); + sms = device->open_sms(); TEST_ASSERT(sms != NULL); wait(3); // some modems needs more time access sim } diff --git a/features/cellular/TESTS/socket/udp/main.cpp b/features/cellular/TESTS/socket/udp/main.cpp index c5b856c9e0..6abd42f7eb 100644 --- a/features/cellular/TESTS/socket/udp/main.cpp +++ b/features/cellular/TESTS/socket/udp/main.cpp @@ -26,10 +26,6 @@ #error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. #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 -#endif - #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 91588c2cc1..5234e03e76 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -429,7 +429,7 @@ bool AT_CellularContext::set_new_context(int cid) _pdp_type = pdp_type; _cid = cid; _new_context_set = true; - tr_info("New PDP context %d, type %s", _cid, pdp_type); + tr_info("New PDP context %d, type %d", _cid, pdp_type); } return success; @@ -871,7 +871,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) cell_callback_data_t *data = (cell_callback_data_t *)ptr; cellular_connection_status_t st = (cellular_connection_status_t)ev; _cb_data.error = data->error; - tr_debug("CellularContext: event %d, err %d, data %d", ev, data->error, data->status_data); #if USE_APN_LOOKUP if (st == CellularSIMStatusChanged && data->status_data == CellularDevice::SimStateReady && _cb_data.error == NSAPI_ERROR_OK) { @@ -903,7 +902,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) if (!_nw && st == CellularDeviceReady && data->error == NSAPI_ERROR_OK) { _nw = _device->open_network(_fh); - tr_error("OPEN NETWORK"); } if (_cp_req && !_cp_in_use && (data->error == NSAPI_ERROR_OK) && @@ -948,7 +946,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) } } } else { - tr_debug("CellularContext: event %d, ptr %d", ev, ptr); #if NSAPI_PPP_AVAILABLE if (_is_blocking) { if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) { diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index a8ad05e00f..b14175e3a8 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -44,6 +44,7 @@ CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref CellularDevice::~CellularDevice() { + tr_debug("CellularDevice destruct"); } void CellularDevice::stop() @@ -115,6 +116,7 @@ nsapi_error_t CellularDevice::create_state_machine() _state_machine->set_cellular_callback(callback(this, &CellularDevice::cellular_callback)); err = _state_machine->start_dispatch(); if (err) { + tr_error("Start state machine failed."); delete _state_machine; _state_machine = NULL; } diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index 104c898682..ad5783b25a 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -73,6 +73,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event CellularStateMachine::~CellularStateMachine() { + tr_debug("CellularStateMachine destruct"); stop(); } @@ -523,6 +524,7 @@ nsapi_error_t CellularStateMachine::run_to_state(CellularStateMachine::CellularS // call pre_event via queue so that it's in same thread and it's safe to decisions int id = _queue.call_in(0, this, &CellularStateMachine::pre_event, tmp_state); if (!id) { + report_failure("Failed to call queue."); stop(); _mutex.unlock(); return NSAPI_ERROR_NO_MEMORY; @@ -655,6 +657,7 @@ nsapi_error_t CellularStateMachine::start_dispatch() _queue_thread = new rtos::Thread(osPriorityNormal, 2048, NULL, "stm_queue"); if (_queue_thread->start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) { + report_failure("Failed to start thread."); stop(); return NSAPI_ERROR_NO_MEMORY; } diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 8bc75b85b4..26d7feb9f1 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -16,9 +16,9 @@ */ #include "GEMALTO_CINTERION_CellularContext.h" +#include "GEMALTO_CINTERION_CellularInformation.h" #include "GEMALTO_CINTERION.h" #include "AT_CellularNetwork.h" -#include "AT_CellularInformation.h" #include "CellularLog.h" using namespace mbed; @@ -37,6 +37,14 @@ AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const return new GEMALTO_CINTERION_CellularContext(at, this, apn, cp_req, nonip_req); } +AT_CellularInformation *GEMALTO_CINTERION::open_information_impl(ATHandler &at) +{ + if (_module == ModuleBGS2) { + return new GEMALTO_CINTERION_CellularInformation(at); + } + return AT_CellularDevice::open_information_impl(at); +} + nsapi_error_t GEMALTO_CINTERION::init() { nsapi_error_t err = AT_CellularDevice::init(); @@ -85,8 +93,8 @@ void GEMALTO_CINTERION::init_module_bgs2() { // BGS2-W_ATC_V00.100 static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { - AT_CellularNetwork::RegistrationModeLAC, // C_EREG - AT_CellularNetwork::RegistrationModeLAC, // C_GREG + AT_CellularNetwork::RegistrationModeDisable, // C_EREG + AT_CellularNetwork::RegistrationModeEnable, // C_GREG AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h index 522602de2c..d02fbf102f 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h @@ -48,6 +48,8 @@ public: protected: // AT_CellularDevice virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); + virtual AT_CellularInformation *open_information_impl(ATHandler &at); + protected: virtual uint16_t get_send_delay() const; virtual nsapi_error_t init(); diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp new file mode 100644 index 0000000000..3f81221401 --- /dev/null +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "GEMALTO_CINTERION_CellularInformation.h" + +namespace mbed { + +GEMALTO_CINTERION_CellularInformation::GEMALTO_CINTERION_CellularInformation(ATHandler &at) : AT_CellularInformation(at) +{ +} + +nsapi_error_t GEMALTO_CINTERION_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + _at.lock(); + _at.cmd_start("AT^SCID"); + _at.cmd_stop(); + _at.resp_start("^SCID:"); + _at.read_string(buf, buf_size); + _at.resp_stop(); + return _at.unlock_return_error(); +} + +} /* namespace mbed */ diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.h new file mode 100644 index 0000000000..ef9fabc37b --- /dev/null +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GEMALTO_CINTERION_CELLULARINFORMATION_H_ +#define GEMALTO_CINTERION_CELLULARINFORMATION_H_ + +#include "AT_CellularInformation.h" + +namespace mbed { + +class GEMALTO_CINTERION_CellularInformation: public AT_CellularInformation { +public: + GEMALTO_CINTERION_CellularInformation(ATHandler &at); + +public: // AT_CellularInformation + virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); +}; + +} /* namespace mbed */ + +#endif /* GEMALTO_CINTERION_CELLULARINFORMATION_H_ */ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp index 4bce3631b0..14b1673434 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp @@ -16,7 +16,6 @@ #include "ONBOARD_QUECTEL_BC95.h" -#include "cellular/onboard_modem_api.h" #include "UARTSerial.h" #include "CellularLog.h" @@ -28,25 +27,21 @@ ONBOARD_QUECTEL_BC95::ONBOARD_QUECTEL_BC95(FileHandle *fh) : QUECTEL_BC95(fh) nsapi_error_t ONBOARD_QUECTEL_BC95::hard_power_on() { - ::onboard_modem_init(); return NSAPI_ERROR_OK; } nsapi_error_t ONBOARD_QUECTEL_BC95::hard_power_off() { - ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } nsapi_error_t ONBOARD_QUECTEL_BC95::soft_power_on() { - ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } nsapi_error_t ONBOARD_QUECTEL_BC95::soft_power_off() { - ::onboard_modem_power_down(); return NSAPI_ERROR_OK; } diff --git a/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws b/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws index 7030a5dce5..dd25563c2a 100644 --- a/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws +++ b/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws @@ -1,5 +1,6 @@ personal_ws-1.1 en 1600 utf-8 _code_ +unconfigured mbed rtos malloc From 52ee61e1aefcd0ea009bd8475e0daefeb36272ee Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Mon, 28 Jan 2019 03:27:10 -0800 Subject: [PATCH 39/41] Fix NetworkInterface::set_default_parameters binary compatibility --- features/netsocket/CellularBase.h | 23 ++++++++++++----------- features/netsocket/NetworkInterface.h | 23 ++++++++++++----------- features/netsocket/WiFiInterface.h | 23 ++++++++++++----------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/features/netsocket/CellularBase.h b/features/netsocket/CellularBase.h index ac4c8cea6a..565d0918b0 100644 --- a/features/netsocket/CellularBase.h +++ b/features/netsocket/CellularBase.h @@ -39,17 +39,6 @@ public: */ static CellularBase *get_default_instance(); - /** Set default parameters on a cellular interface. - * - * A cellular interface instantiated directly or using - * CellularBase::get_default_instance() is initially unconfigured. - * This call can be used to set the default parameters that would - * have been set if the interface had been requested using - * NetworkInterface::get_default_instance() (see nsapi JSON - * configuration). - */ - virtual void set_default_parameters(); - /** Set the cellular network credentials. * * Please check documentation of connect() for default behavior of APN settings. @@ -148,6 +137,18 @@ protected: static CellularBase *get_target_default_instance(); #endif //!defined(DOXYGEN_ONLY) + +public: + /** Set default parameters on a cellular interface. + * + * A cellular interface instantiated directly or using + * CellularBase::get_default_instance() is initially unconfigured. + * This call can be used to set the default parameters that would + * have been set if the interface had been requested using + * NetworkInterface::get_default_instance() (see nsapi JSON + * configuration). + */ + virtual void set_default_parameters(); }; #endif //CELLULAR_BASE_H diff --git a/features/netsocket/NetworkInterface.h b/features/netsocket/NetworkInterface.h index 87e198a6c7..aeb7874b4b 100644 --- a/features/netsocket/NetworkInterface.h +++ b/features/netsocket/NetworkInterface.h @@ -84,17 +84,6 @@ public: */ static NetworkInterface *get_default_instance(); - /** Set default parameters on an interface. - * - * A network interface instantiated directly or using calls such as - * WiFiInterface::get_default_instance() is initially unconfigured. - * This call can be used to set the default parameters that would - * have been set if the interface had been requested using - * NetworkInterface::get_default_instance() (see nsapi JSON - * configuration). - */ - virtual void set_default_parameters(); - /** Get the local MAC address. * * Provided MAC address is intended for info or debug purposes and @@ -359,6 +348,18 @@ protected: */ static NetworkInterface *get_target_default_instance(); #endif //!defined(DOXYGEN_ONLY) + +public: + /** Set default parameters on an interface. + * + * A network interface instantiated directly or using calls such as + * WiFiInterface::get_default_instance() is initially unconfigured. + * This call can be used to set the default parameters that would + * have been set if the interface had been requested using + * NetworkInterface::get_default_instance() (see nsapi JSON + * configuration). + */ + virtual void set_default_parameters(); }; #endif diff --git a/features/netsocket/WiFiInterface.h b/features/netsocket/WiFiInterface.h index ea976803ff..4a3ed9cea6 100644 --- a/features/netsocket/WiFiInterface.h +++ b/features/netsocket/WiFiInterface.h @@ -40,17 +40,6 @@ public: */ static WiFiInterface *get_default_instance(); - /** Set default parameters on a Wi-Fi interface. - * - * A Wi-Fi interface instantiated directly or using - * WiFiInterface::get_default_instance() is initially unconfigured. - * This call can be used to set the default parameters that would - * have been set if the interface had been requested using - * NetworkInterface::get_default_instance() (see nsapi JSON - * configuration). - */ - virtual void set_default_parameters(); - /** Set the Wi-Fi network credentials. * * @param ssid Name of the network to connect to. @@ -134,6 +123,18 @@ protected: */ static WiFiInterface *get_target_default_instance(); #endif //!defined(DOXYGEN_ONLY) + +public: + /** Set default parameters on a Wi-Fi interface. + * + * A Wi-Fi interface instantiated directly or using + * WiFiInterface::get_default_instance() is initially unconfigured. + * This call can be used to set the default parameters that would + * have been set if the interface had been requested using + * NetworkInterface::get_default_instance() (see nsapi JSON + * configuration). + */ + virtual void set_default_parameters(); }; #endif From 7578d5b1740ed3c16191a42d2eb1153a5f129eb9 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Tue, 29 Jan 2019 01:08:17 -0800 Subject: [PATCH 40/41] Cellular: Fix mbed2-build of onboard-modems --- .../TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp | 4 ++++ .../TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp | 4 ++++ .../TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp | 4 ++++ .../TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp | 4 ++++ .../TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp | 4 ++++ .../TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp | 4 ++++ .../TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp | 4 ++++ .../TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp | 4 ++++ .../TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp | 4 ++++ .../TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp | 4 ++++ 10 files changed, 40 insertions(+) diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp index 614f07289e..28f1dfd934 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_UBLOX_PPP.h" #include "cellular/onboard_modem_api.h" #include "UARTSerial.h" @@ -61,3 +63,5 @@ CellularDevice *CellularDevice::get_target_default_instance() static ONBOARD_UBLOX_PPP device(&serial); return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp index d77f21e46c..ca763548b6 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "cellular/onboard_modem_api.h" #include "UARTSerial.h" #include "ONBOARD_TELIT_HE910.h" @@ -54,3 +56,5 @@ CellularDevice *CellularDevice::get_target_default_instance() static ONBOARD_TELIT_HE910 device(&serial); return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp index 082ac9097f..8e524abdb7 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "cellular/onboard_modem_api.h" #include "UARTSerial.h" #include "ONBOARD_TELIT_HE910.h" @@ -61,3 +63,5 @@ CellularDevice *CellularDevice::get_target_default_instance() static ONBOARD_TELIT_HE910 device(&serial); return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp index cd6b922311..a9a32913c5 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_UBLOX_AT.h" #include "ONBOARD_UBLOX_PPP.h" #include "UARTSerial.h" @@ -31,3 +33,5 @@ CellularDevice *CellularDevice::get_target_default_instance() #endif return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp index 137f9d9630..221d617fc4 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_AT.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_UBLOX_AT.h" #include "cellular/onboard_modem_api.h" @@ -46,3 +48,5 @@ nsapi_error_t ONBOARD_UBLOX_AT::soft_power_off() ::onboard_modem_power_down(); return NSAPI_ERROR_OK; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp index f3f18a5219..33b105f3a3 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_PPP.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_UBLOX_PPP.h" #include "cellular/onboard_modem_api.h" @@ -46,3 +48,5 @@ nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_off() ::onboard_modem_power_down(); return NSAPI_ERROR_OK; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp index cd2a74cd9a..f218a8204e 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/ONBOARD_QUECTEL_BG96.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_QUECTEL_BG96.h" #include "cellular/onboard_modem_api.h" @@ -55,3 +57,5 @@ CellularDevice *CellularDevice::get_target_default_instance() static ONBOARD_QUECTEL_BG96 device(&serial); return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp index cd2a74cd9a..f218a8204e 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_BG96/ONBOARD_QUECTEL_BG96.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_QUECTEL_BG96.h" #include "cellular/onboard_modem_api.h" @@ -55,3 +57,5 @@ CellularDevice *CellularDevice::get_target_default_instance() static ONBOARD_QUECTEL_BG96 device(&serial); return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp index 029b2569af..de20f6c6ff 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/ONBOARD_SARA4_PPP.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_SARA4_PPP.h" #include "cellular/onboard_modem_api.h" #include "UARTSerial.h" @@ -61,3 +63,5 @@ CellularDevice *CellularDevice::get_target_default_instance() static ONBOARD_SARA4_PPP device(&serial); return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp index 14b1673434..684b0db47c 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/ONBOARD_QUECTEL_BC95.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#if MBED_CONF_NSAPI_PRESENT + #include "ONBOARD_QUECTEL_BC95.h" #include "UARTSerial.h" @@ -57,3 +59,5 @@ CellularDevice *CellularDevice::get_target_default_instance() static ONBOARD_QUECTEL_BC95 device(&serial); return &device; } + +#endif // MBED_CONF_NSAPI_PRESENT From 47a8f24b1e237e83ff4bd2c22d2a8f0a73fe8cc4 Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Thu, 31 Jan 2019 04:15:01 -0800 Subject: [PATCH 41/41] Cellular: Fix astyle --- UNITTESTS/stubs/CellularContext_stub.h | 10 +++++----- UNITTESTS/stubs/ControlPlane_netif_stub.h | 4 ++-- UNITTESTS/target_h/myCellularDevice.h | 2 +- features/netsocket/cellular/CellularNonIPSocket.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/UNITTESTS/stubs/CellularContext_stub.h b/UNITTESTS/stubs/CellularContext_stub.h index 062f77fdff..e90f405434 100644 --- a/UNITTESTS/stubs/CellularContext_stub.h +++ b/UNITTESTS/stubs/CellularContext_stub.h @@ -92,12 +92,12 @@ public: return true; }; - NetworkStack * get_stack() + NetworkStack *get_stack() { return NULL; }; - const char * get_ip_address() + const char *get_ip_address() { return NULL; }; @@ -120,7 +120,7 @@ public: }; nsapi_error_t connect(const char *sim_pin, const char *apn, const char *uname, - const char *pwd) + const char *pwd) { return NSAPI_ERROR_OK; }; @@ -130,12 +130,12 @@ public: }; - const char * get_netmask() + const char *get_netmask() { return NULL; }; - const char * get_gateway() + const char *get_gateway() { return NULL; }; diff --git a/UNITTESTS/stubs/ControlPlane_netif_stub.h b/UNITTESTS/stubs/ControlPlane_netif_stub.h index ed4bec917f..52661c52b8 100644 --- a/UNITTESTS/stubs/ControlPlane_netif_stub.h +++ b/UNITTESTS/stubs/ControlPlane_netif_stub.h @@ -43,7 +43,7 @@ protected: virtual nsapi_error_t recv(void *cpdata, nsapi_size_t cpdata_length) { - if (!return_values.empty()) { + if (!return_values.empty()) { nsapi_error_t ret = return_values.front(); return_values.pop_front(); return ret; @@ -51,7 +51,7 @@ protected: return return_value; }; - virtual void data_received(){}; + virtual void data_received() {}; virtual void attach(void (*callback)(void *), void *data) {}; }; diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 521b3c839f..71097c4a03 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -52,7 +52,7 @@ public: } virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin, - bool active_high, bool cp_req = false, bool nonip_req = false) + bool active_high, bool cp_req = false, bool nonip_req = false) { return NULL; } diff --git a/features/netsocket/cellular/CellularNonIPSocket.cpp b/features/netsocket/cellular/CellularNonIPSocket.cpp index 3806696f19..30bda5390b 100644 --- a/features/netsocket/cellular/CellularNonIPSocket.cpp +++ b/features/netsocket/cellular/CellularNonIPSocket.cpp @@ -233,12 +233,12 @@ nsapi_error_t CellularNonIPSocket::listen(int backlog) } nsapi_size_or_error_t CellularNonIPSocket::sendto(const SocketAddress &address, - const void *data, nsapi_size_t size) + const void *data, nsapi_size_t size) { return NSAPI_ERROR_UNSUPPORTED; } nsapi_size_or_error_t CellularNonIPSocket::recvfrom(SocketAddress *address, - void *data, nsapi_size_t size) + void *data, nsapi_size_t size) { return NSAPI_ERROR_UNSUPPORTED; }