Skip to content

Cellular: Fixed improper AT handler setup through virtual calls in co… #11201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,7 @@ void ATHandler::set_debug_list(bool debug_on)
ATHandler_stub::debug_on = debug_on;
}

void ATHandler::set_send_delay(uint16_t send_delay)
{
}

4 changes: 4 additions & 0 deletions UNITTESTS/stubs/AT_CellularDevice_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::set_at_urcs_impl()
{
}
5 changes: 5 additions & 0 deletions features/cellular/framework/AT/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,3 +1544,8 @@ bool ATHandler::sync(int timeout_ms)
unlock();
return false;
}

void ATHandler::set_send_delay(uint16_t send_delay)
{
_at_send_delay = send_delay;
}
6 changes: 6 additions & 0 deletions features/cellular/framework/AT/ATHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ class ATHandler {
*/
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:
void event();
#ifdef AT_HANDLER_MUTEX
Expand Down
32 changes: 25 additions & 7 deletions features/cellular/framework/AT/AT_CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _netw
MBED_ASSERT(fh);
_at = get_at_handler(fh);
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()
Expand Down Expand Up @@ -84,6 +77,29 @@ AT_CellularDevice::~AT_CellularDevice()
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()
{
// The network has forced a context deactivation
Expand Down Expand Up @@ -424,6 +440,8 @@ void AT_CellularDevice::modem_debug_on(bool on)

nsapi_error_t AT_CellularDevice::init()
{
setup_at_handler();

_at->lock();
_at->flush();
_at->at_cmd_discard("E0", "");
Expand Down
7 changes: 7 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class AT_CellularDevice : public CellularDevice {
protected:
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
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:
void urc_nw_deact();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ nsapi_error_t GEMALTO_CINTERION::init()
}
tr_info("Cinterion model %s (%d)", model, _module);

set_at_urcs();

return NSAPI_ERROR_OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at)

nsapi_error_t QUECTEL_BC95::init()
{
setup_at_handler();

_at->lock();
_at->flush();
_at->cmd_start("AT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh, PinName pwr, bool active_high, PinNam
_pwr(pwr, !_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);
}

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)
{
Expand Down Expand Up @@ -157,6 +159,8 @@ nsapi_error_t QUECTEL_BG96::hard_power_off()

nsapi_error_t QUECTEL_BG96::init()
{
setup_at_handler();

int retry = 0;

_at->lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class QUECTEL_BG96 : public AT_CellularDevice {
virtual nsapi_error_t hard_power_off();
virtual nsapi_error_t soft_power_on();
virtual nsapi_error_t init();
virtual void set_at_urcs_impl();

public:
void handle_urc(FileHandle *fh);
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ CellularDevice *CellularDevice::get_default_instance()

nsapi_error_t UBLOX_AT::init()
{
setup_at_handler();

_at->lock();
_at->flush();
_at->cmd_start("AT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
UBLOX_N2XX::UBLOX_N2XX(FileHandle *fh): AT_CellularDevice(fh)
{
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));
}

void UBLOX_N2XX::set_at_urcs_impl()
{
_at->set_urc_handler("+NPIN:", mbed::Callback<void()>(this, &UBLOX_N2XX::NPIN_URC));
}

UBLOX_N2XX::~UBLOX_N2XX()
{
_at->set_urc_handler("+NPIN:", NULL);
Expand All @@ -66,6 +70,8 @@ AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at)

nsapi_error_t UBLOX_N2XX::init()
{
setup_at_handler();

_at->lock();
_at->flush();
_at->cmd_start("AT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class UBLOX_N2XX : public AT_CellularDevice {

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 void set_at_urcs_impl();

public: // NetworkInterface

Expand Down