Skip to content

Commit b849bc1

Browse files
authored
Merge pull request #11201 from mirelachirica/bug_virtual_in_constructor
Cellular: Fixed improper AT handler setup through virtual calls in co…
2 parents e2fef54 + 75c823c commit b849bc1

File tree

13 files changed

+72
-10
lines changed

13 files changed

+72
-10
lines changed

UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,7 @@ void ATHandler::set_debug_list(bool debug_on)
405405
ATHandler_stub::debug_on = debug_on;
406406
}
407407

408+
void ATHandler::set_send_delay(uint16_t send_delay)
409+
{
410+
}
411+

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,7 @@ nsapi_error_t AT_CellularDevice::soft_power_off()
252252
void AT_CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx)
253253
{
254254
}
255+
256+
void AT_CellularDevice::set_at_urcs_impl()
257+
{
258+
}

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,3 +1545,8 @@ bool ATHandler::sync(int timeout_ms)
15451545
unlock();
15461546
return false;
15471547
}
1548+
1549+
void ATHandler::set_send_delay(uint16_t send_delay)
1550+
{
1551+
_at_send_delay = send_delay;
1552+
}

features/cellular/framework/AT/ATHandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ class ATHandler {
210210
*/
211211
bool sync(int timeout_ms);
212212

213+
/** Sets the delay to be applied before sending any AT command.
214+
*
215+
* @param send_delay the minimum delay in ms between the end of last response and the beginning of a new command
216+
*/
217+
void set_send_delay(uint16_t send_delay);
218+
213219
protected:
214220
void event();
215221
#ifdef AT_HANDLER_MUTEX

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _netw
4444
MBED_ASSERT(fh);
4545
_at = get_at_handler(fh);
4646
MBED_ASSERT(_at);
47-
48-
if (AT_CellularBase::get_property(AT_CellularBase::PROPERTY_AT_CGEREP)) {
49-
_at->set_urc_handler("+CGEV: NW DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
50-
_at->set_urc_handler("+CGEV: ME DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
51-
_at->set_urc_handler("+CGEV: NW PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
52-
_at->set_urc_handler("+CGEV: ME PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
53-
}
5447
}
5548

5649
AT_CellularDevice::~AT_CellularDevice()
@@ -84,6 +77,29 @@ AT_CellularDevice::~AT_CellularDevice()
8477
release_at_handler(_at);
8578
}
8679

80+
void AT_CellularDevice::set_at_urcs_impl()
81+
{
82+
}
83+
84+
void AT_CellularDevice::set_at_urcs()
85+
{
86+
if (AT_CellularBase::get_property(AT_CellularBase::PROPERTY_AT_CGEREP)) {
87+
_at->set_urc_handler("+CGEV: NW DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
88+
_at->set_urc_handler("+CGEV: ME DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
89+
_at->set_urc_handler("+CGEV: NW PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
90+
_at->set_urc_handler("+CGEV: ME PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
91+
}
92+
93+
set_at_urcs_impl();
94+
}
95+
96+
void AT_CellularDevice::setup_at_handler()
97+
{
98+
set_at_urcs();
99+
100+
_at->set_send_delay(get_send_delay());
101+
}
102+
87103
void AT_CellularDevice::urc_nw_deact()
88104
{
89105
// The network has forced a context deactivation
@@ -424,6 +440,8 @@ void AT_CellularDevice::modem_debug_on(bool on)
424440

425441
nsapi_error_t AT_CellularDevice::init()
426442
{
443+
setup_at_handler();
444+
427445
_at->lock();
428446
_at->flush();
429447
_at->at_cmd_discard("E0", "");

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ class AT_CellularDevice : public CellularDevice {
144144
protected:
145145
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
146146
void send_disconnect_to_context(int cid);
147+
// Sets commonly used URCs
148+
void set_at_urcs();
149+
// To be used for setting target specific URCs
150+
virtual void set_at_urcs_impl();
151+
// Sets up parameters for AT handler, for now only the send delay and URCs.
152+
// This kind of routine is needed for initialisation routines that are virtual and therefore cannot be called from constructor.
153+
void setup_at_handler();
147154

148155
private:
149156
void urc_nw_deact();

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ nsapi_error_t GEMALTO_CINTERION::init()
7878
}
7979
tr_info("Cinterion model %s (%d)", model, _module);
8080

81+
set_at_urcs();
82+
8183
return NSAPI_ERROR_OK;
8284
}
8385

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at)
8585

8686
nsapi_error_t QUECTEL_BC95::init()
8787
{
88+
setup_at_handler();
89+
8890
_at->lock();
8991
_at->flush();
9092
_at->cmd_start("AT");

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh, PinName pwr, bool active_high, PinNam
6969
_pwr(pwr, !_active_high),
7070
_rst(rst, !_active_high)
7171
{
72-
_at->set_urc_handler("+QIURC: \"pdpde", mbed::Callback<void()>(this, &QUECTEL_BG96::urc_pdpdeact));
73-
7472
AT_CellularBase::set_cellular_properties(cellular_properties);
7573
}
7674

75+
void QUECTEL_BG96::set_at_urcs_impl()
76+
{
77+
_at->set_urc_handler("+QIURC: \"pdpde", mbed::Callback<void()>(this, &QUECTEL_BG96::urc_pdpdeact));
78+
}
7779

7880
AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at)
7981
{
@@ -157,6 +159,8 @@ nsapi_error_t QUECTEL_BG96::hard_power_off()
157159

158160
nsapi_error_t QUECTEL_BG96::init()
159161
{
162+
setup_at_handler();
163+
160164
int retry = 0;
161165

162166
_at->lock();

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class QUECTEL_BG96 : public AT_CellularDevice {
4545
virtual nsapi_error_t hard_power_off();
4646
virtual nsapi_error_t soft_power_on();
4747
virtual nsapi_error_t init();
48+
virtual void set_at_urcs_impl();
4849

4950
public:
5051
void handle_urc(FileHandle *fh);

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ CellularDevice *CellularDevice::get_default_instance()
9090

9191
nsapi_error_t UBLOX_AT::init()
9292
{
93+
setup_at_handler();
94+
9395
_at->lock();
9496
_at->flush();
9597
_at->cmd_start("AT");

features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
3939
UBLOX_N2XX::UBLOX_N2XX(FileHandle *fh): AT_CellularDevice(fh)
4040
{
4141
AT_CellularBase::set_cellular_properties(cellular_properties);
42-
_at->set_urc_handler("+NPIN:", mbed::Callback<void()>(this, &UBLOX_N2XX::NPIN_URC));
4342
memset(simstr, 0, sizeof(simstr));
4443
}
4544

45+
void UBLOX_N2XX::set_at_urcs_impl()
46+
{
47+
_at->set_urc_handler("+NPIN:", mbed::Callback<void()>(this, &UBLOX_N2XX::NPIN_URC));
48+
}
49+
4650
UBLOX_N2XX::~UBLOX_N2XX()
4751
{
4852
_at->set_urc_handler("+NPIN:", NULL);
@@ -66,6 +70,8 @@ AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at)
6670

6771
nsapi_error_t UBLOX_N2XX::init()
6872
{
73+
setup_at_handler();
74+
6975
_at->lock();
7076
_at->flush();
7177
_at->cmd_start("AT");

features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class UBLOX_N2XX : public AT_CellularDevice {
5252

5353
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
5454
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
55+
virtual void set_at_urcs_impl();
5556

5657
public: // NetworkInterface
5758

0 commit comments

Comments
 (0)