mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Unify set_at_mode and init_module into init()
parent
2dde5a4376
commit
0813b969f7
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<void()> 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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -28,8 +28,6 @@ public:
|
|||
virtual ~QUECTEL_BC95_CellularPower();
|
||||
|
||||
public: //from CellularPower
|
||||
virtual nsapi_error_t set_at_mode();
|
||||
|
||||
virtual nsapi_error_t reset();
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue