Cellular: Fixed improper AT handler setup through virtual calls in constructor

Added AT handler setup method to be used for initialisation routines
that are virtual and therefore cannot be called from constructor.
pull/11201/head
Mirela Chirica 2019-08-12 11:19:37 +03:00
parent f8dc035ae4
commit 75c823c1a3
13 changed files with 72 additions and 10 deletions

View File

@ -405,3 +405,7 @@ void ATHandler::set_debug_list(bool debug_on)
ATHandler_stub::debug_on = debug_on; ATHandler_stub::debug_on = debug_on;
} }
void ATHandler::set_send_delay(uint16_t send_delay)
{
}

View File

@ -252,3 +252,7 @@ nsapi_error_t AT_CellularDevice::soft_power_off()
void AT_CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx) void AT_CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx)
{ {
} }
void AT_CellularDevice::set_at_urcs_impl()
{
}

View File

@ -1544,3 +1544,8 @@ bool ATHandler::sync(int timeout_ms)
unlock(); unlock();
return false; return false;
} }
void ATHandler::set_send_delay(uint16_t send_delay)
{
_at_send_delay = send_delay;
}

View File

@ -210,6 +210,12 @@ public:
*/ */
bool sync(int timeout_ms); bool sync(int timeout_ms);
/** Sets the delay to be applied before sending any AT command.
*
* @param send_delay the minimum delay in ms between the end of last response and the beginning of a new command
*/
void set_send_delay(uint16_t send_delay);
protected: protected:
void event(); void event();
#ifdef AT_HANDLER_MUTEX #ifdef AT_HANDLER_MUTEX

View File

@ -44,13 +44,6 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _netw
MBED_ASSERT(fh); MBED_ASSERT(fh);
_at = get_at_handler(fh); _at = get_at_handler(fh);
MBED_ASSERT(_at); MBED_ASSERT(_at);
if (AT_CellularBase::get_property(AT_CellularBase::PROPERTY_AT_CGEREP)) {
_at->set_urc_handler("+CGEV: NW DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
_at->set_urc_handler("+CGEV: ME DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
_at->set_urc_handler("+CGEV: NW PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
_at->set_urc_handler("+CGEV: ME PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
}
} }
AT_CellularDevice::~AT_CellularDevice() AT_CellularDevice::~AT_CellularDevice()
@ -84,6 +77,29 @@ AT_CellularDevice::~AT_CellularDevice()
release_at_handler(_at); release_at_handler(_at);
} }
void AT_CellularDevice::set_at_urcs_impl()
{
}
void AT_CellularDevice::set_at_urcs()
{
if (AT_CellularBase::get_property(AT_CellularBase::PROPERTY_AT_CGEREP)) {
_at->set_urc_handler("+CGEV: NW DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
_at->set_urc_handler("+CGEV: ME DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
_at->set_urc_handler("+CGEV: NW PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
_at->set_urc_handler("+CGEV: ME PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
}
set_at_urcs_impl();
}
void AT_CellularDevice::setup_at_handler()
{
set_at_urcs();
_at->set_send_delay(get_send_delay());
}
void AT_CellularDevice::urc_nw_deact() void AT_CellularDevice::urc_nw_deact()
{ {
// The network has forced a context deactivation // The network has forced a context deactivation
@ -424,6 +440,8 @@ void AT_CellularDevice::modem_debug_on(bool on)
nsapi_error_t AT_CellularDevice::init() nsapi_error_t AT_CellularDevice::init()
{ {
setup_at_handler();
_at->lock(); _at->lock();
_at->flush(); _at->flush();
_at->at_cmd_discard("E0", ""); _at->at_cmd_discard("E0", "");

View File

@ -144,6 +144,13 @@ public:
protected: protected:
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL); virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
void send_disconnect_to_context(int cid); void send_disconnect_to_context(int cid);
// Sets commonly used URCs
void set_at_urcs();
// To be used for setting target specific URCs
virtual void set_at_urcs_impl();
// Sets up parameters for AT handler, for now only the send delay and URCs.
// This kind of routine is needed for initialisation routines that are virtual and therefore cannot be called from constructor.
void setup_at_handler();
private: private:
void urc_nw_deact(); void urc_nw_deact();

View File

@ -78,6 +78,8 @@ nsapi_error_t GEMALTO_CINTERION::init()
} }
tr_info("Cinterion model %s (%d)", model, _module); tr_info("Cinterion model %s (%d)", model, _module);
set_at_urcs();
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }

View File

@ -85,6 +85,8 @@ AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at)
nsapi_error_t QUECTEL_BC95::init() nsapi_error_t QUECTEL_BC95::init()
{ {
setup_at_handler();
_at->lock(); _at->lock();
_at->flush(); _at->flush();
_at->cmd_start("AT"); _at->cmd_start("AT");

View File

@ -69,11 +69,13 @@ QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh, PinName pwr, bool active_high, PinNam
_pwr(pwr, !_active_high), _pwr(pwr, !_active_high),
_rst(rst, !_active_high) _rst(rst, !_active_high)
{ {
_at->set_urc_handler("+QIURC: \"pdpde", mbed::Callback<void()>(this, &QUECTEL_BG96::urc_pdpdeact));
AT_CellularBase::set_cellular_properties(cellular_properties); AT_CellularBase::set_cellular_properties(cellular_properties);
} }
void QUECTEL_BG96::set_at_urcs_impl()
{
_at->set_urc_handler("+QIURC: \"pdpde", mbed::Callback<void()>(this, &QUECTEL_BG96::urc_pdpdeact));
}
AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at)
{ {
@ -157,6 +159,8 @@ nsapi_error_t QUECTEL_BG96::hard_power_off()
nsapi_error_t QUECTEL_BG96::init() nsapi_error_t QUECTEL_BG96::init()
{ {
setup_at_handler();
int retry = 0; int retry = 0;
_at->lock(); _at->lock();

View File

@ -45,6 +45,7 @@ protected: // AT_CellularDevice
virtual nsapi_error_t hard_power_off(); virtual nsapi_error_t hard_power_off();
virtual nsapi_error_t soft_power_on(); virtual nsapi_error_t soft_power_on();
virtual nsapi_error_t init(); virtual nsapi_error_t init();
virtual void set_at_urcs_impl();
public: public:
void handle_urc(FileHandle *fh); void handle_urc(FileHandle *fh);

View File

@ -90,6 +90,8 @@ CellularDevice *CellularDevice::get_default_instance()
nsapi_error_t UBLOX_AT::init() nsapi_error_t UBLOX_AT::init()
{ {
setup_at_handler();
_at->lock(); _at->lock();
_at->flush(); _at->flush();
_at->cmd_start("AT"); _at->cmd_start("AT");

View File

@ -39,10 +39,14 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
UBLOX_N2XX::UBLOX_N2XX(FileHandle *fh): AT_CellularDevice(fh) UBLOX_N2XX::UBLOX_N2XX(FileHandle *fh): AT_CellularDevice(fh)
{ {
AT_CellularBase::set_cellular_properties(cellular_properties); AT_CellularBase::set_cellular_properties(cellular_properties);
_at->set_urc_handler("+NPIN:", mbed::Callback<void()>(this, &UBLOX_N2XX::NPIN_URC));
memset(simstr, 0, sizeof(simstr)); memset(simstr, 0, sizeof(simstr));
} }
void UBLOX_N2XX::set_at_urcs_impl()
{
_at->set_urc_handler("+NPIN:", mbed::Callback<void()>(this, &UBLOX_N2XX::NPIN_URC));
}
UBLOX_N2XX::~UBLOX_N2XX() UBLOX_N2XX::~UBLOX_N2XX()
{ {
_at->set_urc_handler("+NPIN:", NULL); _at->set_urc_handler("+NPIN:", NULL);
@ -66,6 +70,8 @@ AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at)
nsapi_error_t UBLOX_N2XX::init() nsapi_error_t UBLOX_N2XX::init()
{ {
setup_at_handler();
_at->lock(); _at->lock();
_at->flush(); _at->flush();
_at->cmd_start("AT"); _at->cmd_start("AT");

View File

@ -52,6 +52,7 @@ protected: // AT_CellularDevice
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
virtual AT_CellularSMS *open_sms_impl(ATHandler &at); virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
virtual void set_at_urcs_impl();
public: // NetworkInterface public: // NetworkInterface