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