Cellular: Unify set_at_mode and init_module into init()

pull/9472/head
Ari Parkkila 2018-11-28 23:17:34 -08:00
parent 2dde5a4376
commit 0813b969f7
23 changed files with 88 additions and 141 deletions

View File

@ -232,6 +232,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
dev.close_sms(); 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) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready)
{ {
EventQueue que; EventQueue que;
@ -278,13 +286,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
EXPECT_TRUE(0 == dev.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) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
{ {
FileHandle_stub fh1; FileHandle_stub fh1;

View File

@ -75,20 +75,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_off)
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.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) TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level)
{ {
EventQueue que; EventQueue que;

View File

@ -166,7 +166,7 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
} }
nsapi_error_t AT_CellularDevice::init_module() nsapi_error_t AT_CellularDevice::init()
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }

View File

@ -40,11 +40,6 @@ nsapi_error_t AT_CellularPower::off()
return NSAPI_ERROR_OK; 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) nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset)
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;

View File

@ -109,6 +109,11 @@ public:
virtual void modem_debug_on(bool on) {} virtual void modem_debug_on(bool on) {}
virtual nsapi_error_t init()
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t is_ready() virtual nsapi_error_t is_ready()
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
@ -124,11 +129,6 @@ public:
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }
virtual nsapi_error_t init_module()
{
return 0;
}
virtual CellularContext *get_context_list() const virtual CellularContext *get_context_list() const
{ {
return _context_list; return _context_list;

View File

@ -56,12 +56,12 @@ static void wait_for_power(CellularPower *pwr)
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
int sanity_count = 0; int sanity_count = 0;
err = pwr->set_at_mode(); err = cellular_device->init();
while (err != NSAPI_ERROR_OK) { while (err != NSAPI_ERROR_OK) {
sanity_count++; sanity_count++;
wait(1); wait(1);
TEST_ASSERT(sanity_count < 40); TEST_ASSERT(sanity_count < 40);
err = pwr->set_at_mode(); err = cellular_device->init();
} }
TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK); TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK);

View File

@ -250,6 +250,18 @@ public:
*/ */
virtual void modem_debug_on(bool on) = 0; 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. /** Check whether the device is ready to accept commands.
* *
* @return NSAPI_ERROR_OK on success * @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; 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 /** Get the linked list of CellularContext instances
* *
* @return Pointer to first item in linked list * @return Pointer to first item in linked list

View File

@ -42,7 +42,7 @@ public:
* Device power on/off is modem/board specific behavior and must be done on inherited class if needed. * 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. * 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 * @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
@ -58,15 +58,6 @@ public:
*/ */
virtual nsapi_error_t off() = 0; 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. /** Set cellular device power level by enabling/disabling functionality.
* *
* @param func_level: * @param func_level:

View File

@ -366,6 +366,18 @@ void AT_CellularDevice::modem_debug_on(bool on)
ATHandler::set_debug_list(_modem_debug_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() nsapi_error_t AT_CellularDevice::is_ready()
{ {
_at->lock(); _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(); 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;
}

View File

@ -70,13 +70,14 @@ public:
virtual void modem_debug_on(bool on); virtual void modem_debug_on(bool on);
virtual nsapi_error_t init();
virtual nsapi_error_t is_ready(); virtual nsapi_error_t is_ready();
virtual nsapi_error_t set_ready_cb(Callback<void()> callback); virtual nsapi_error_t set_ready_cb(Callback<void()> callback);
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); 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); virtual ATHandler *get_at_handler(FileHandle *fh);

View File

@ -42,18 +42,6 @@ nsapi_error_t AT_CellularPower::off()
return NSAPI_ERROR_UNSUPPORTED; 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) nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset)
{ {
_at.lock(); _at.lock();

View File

@ -38,8 +38,6 @@ public:
virtual nsapi_error_t off(); 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 set_power_level(int func_level, int do_reset = 0);
virtual nsapi_error_t reset(); virtual nsapi_error_t reset();

View File

@ -366,9 +366,6 @@ void CellularStateMachine::state_power_on()
bool CellularStateMachine::device_ready() bool CellularStateMachine::device_ready()
{ {
tr_info("Modem ready"); tr_info("Modem ready");
if (_cellularDevice.init_module() != NSAPI_ERROR_OK) {
return false;
}
if (!_network) { if (!_network) {
_network = _cellularDevice.open_network(); _network = _cellularDevice.open_network();
@ -396,7 +393,7 @@ bool CellularStateMachine::device_ready()
void CellularStateMachine::state_device_ready() void CellularStateMachine::state_device_ready()
{ {
_cellularDevice.set_timeout(TIMEOUT_POWER_ON); _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 (_cb_data.error == NSAPI_ERROR_OK) {
if (device_ready()) { if (device_ready()) {
enter_to_state(STATE_SIM_PIN); 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"); tr_debug("Device ready callback");
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) { 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"); tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
_queue.cancel(_event_id); _queue.cancel(_event_id);
_event_id = -1; _event_id = -1;

View File

@ -47,8 +47,13 @@ AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const
return new GEMALTO_CINTERION_CellularContext(at, this, apn); 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(); CellularInformation *information = open_information();
if (!information) { if (!information) {
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;

View File

@ -28,13 +28,6 @@ public:
GEMALTO_CINTERION(FileHandle *fh); GEMALTO_CINTERION(FileHandle *fh);
virtual ~GEMALTO_CINTERION(); 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 /** Actual model of cellular module is needed to make AT command adaptation at runtime
* to support many different models in one cellular driver. * to support many different models in one cellular driver.
*/ */
@ -46,6 +39,13 @@ public:
}; };
static Module get_module(); 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: private:
static Module _module; static Module _module;
void init_module_bgs2(); void init_module_bgs2();

View File

@ -83,3 +83,17 @@ AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at)
return new QUECTEL_BC95_CellularInformation(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();
}

View File

@ -35,6 +35,7 @@ protected: // AT_CellularDevice
virtual AT_CellularPower *open_power_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);
virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual AT_CellularInformation *open_information_impl(ATHandler &at);
virtual nsapi_error_t init();
public: // NetworkInterface public: // NetworkInterface
void handle_urc(FileHandle *fh); void handle_urc(FileHandle *fh);

View File

@ -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() nsapi_error_t QUECTEL_BC95_CellularPower::reset()
{ {
_at.lock(); _at.lock();

View File

@ -28,8 +28,6 @@ public:
virtual ~QUECTEL_BC95_CellularPower(); virtual ~QUECTEL_BC95_CellularPower();
public: //from CellularPower public: //from CellularPower
virtual nsapi_error_t set_at_mode();
virtual nsapi_error_t reset(); virtual nsapi_error_t reset();
}; };

View File

@ -58,3 +58,15 @@ uint16_t TELIT_HE910::get_send_delay() const
return DEFAULT_DELAY_BETWEEN_AT_COMMANDS; 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();
}

View File

@ -34,9 +34,8 @@ protected: // AT_CellularDevice
virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularPower *open_power_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);
public: // from CellularDevice
virtual uint16_t get_send_delay() const; virtual uint16_t get_send_delay() const;
virtual nsapi_error_t init();
}; };
} // namespace mbed } // namespace mbed
#endif /* CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ */ #endif /* CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ */

View File

@ -47,21 +47,3 @@ nsapi_error_t TELIT_HE910_CellularPower::off()
#endif #endif
return NSAPI_ERROR_OK; 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();
}

View File

@ -32,8 +32,6 @@ public: //from CellularPower
virtual nsapi_error_t on(); virtual nsapi_error_t on();
virtual nsapi_error_t off(); virtual nsapi_error_t off();
virtual nsapi_error_t set_at_mode();
}; };
} // namespace mbed } // namespace mbed