Skip to content

Commit 69904ea

Browse files
author
Cruz Monrreal
authored
Merge pull request #8313 from kivaisan/reduce_memory_footprint
Reduce cellular memory footprint
2 parents ba23fef + 963bf81 commit 69904ea

16 files changed

+105
-232
lines changed

UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ void ATHandler::cmd_stop()
283283
{
284284
}
285285

286+
void ATHandler::cmd_stop_read_resp()
287+
{
288+
cmd_stop();
289+
resp_start();
290+
resp_stop();
291+
}
292+
286293
device_err_t ATHandler::get_last_device_error() const
287294
{
288295
return ATHandler_stub::device_err_value;

features/cellular/UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ void ATHandler::cmd_stop()
279279
{
280280
}
281281

282+
void ATHandler::cmd_stop_read_resp()
283+
{
284+
cmd_stop();
285+
resp_start();
286+
resp_stop();
287+
}
288+
282289
device_err_t ATHandler::get_last_device_error() const
283290
{
284291
return ATHandler_stub::device_err_value;

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,13 @@ void ATHandler::cmd_stop()
11001100
(void)write(_output_delimiter, strlen(_output_delimiter));
11011101
}
11021102

1103+
void ATHandler::cmd_stop_read_resp()
1104+
{
1105+
cmd_stop();
1106+
resp_start();
1107+
resp_stop();
1108+
}
1109+
11031110
size_t ATHandler::write_bytes(const uint8_t *data, size_t len)
11041111
{
11051112
if (_last_err != NSAPI_ERROR_OK) {

features/cellular/framework/AT/ATHandler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ class ATHandler {
248248
*/
249249
void cmd_stop();
250250

251+
/** Stops the AT command by writing command-line terminator CR to mark command as finished and reads the OK/ERROR response.
252+
*
253+
*/
254+
void cmd_stop_read_resp();
255+
251256
/** Write bytes without any subparameter delimiters, such as comma.
252257
* In case of failure when writing, the last error is set to NSAPI_ERROR_DEVICE_ERROR.
253258
*

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ nsapi_error_t AT_CellularNetwork::delete_current_context()
262262
_at.clear_error();
263263
_at.cmd_start("AT+CGDCONT=");
264264
_at.write_int(_cid);
265-
_at.cmd_stop();
266-
_at.resp_start();
267-
_at.resp_stop();
265+
_at.cmd_stop_read_resp();
268266

269267
if (_at.get_last_error() == NSAPI_ERROR_OK) {
270268
_cid = -1;
@@ -324,9 +322,7 @@ nsapi_error_t AT_CellularNetwork::activate_context()
324322
tr_info("Activate PDP context %d", _cid);
325323
_at.cmd_start("AT+CGACT=1,");
326324
_at.write_int(_cid);
327-
_at.cmd_stop();
328-
_at.resp_start();
329-
_at.resp_stop();
325+
_at.cmd_stop_read_resp();
330326
}
331327

332328
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
@@ -371,9 +367,7 @@ nsapi_error_t AT_CellularNetwork::connect()
371367
if (err == NSAPI_ERROR_OK) {
372368
_at.lock();
373369
_at.cmd_start("AT+CGEREP=1");
374-
_at.cmd_stop();
375-
_at.resp_start();
376-
_at.resp_stop();
370+
_at.cmd_stop_read_resp();
377371
_at.unlock();
378372
}
379373

@@ -457,9 +451,7 @@ nsapi_error_t AT_CellularNetwork::disconnect()
457451
if (_is_context_active && (_reg_params._act < RAT_E_UTRAN || active_contexts_count > 1)) {
458452
_at.cmd_start("AT+CGACT=0,");
459453
_at.write_int(_cid);
460-
_at.cmd_stop();
461-
_at.resp_start();
462-
_at.resp_stop();
454+
_at.cmd_stop_read_resp();
463455
}
464456

465457
_at.restore_at_timeout();
@@ -523,9 +515,7 @@ nsapi_error_t AT_CellularNetwork::do_user_authentication()
523515
_at.write_int(_authentication_type);
524516
_at.write_string(_uname);
525517
_at.write_string(_pwd);
526-
_at.cmd_stop();
527-
_at.resp_start();
528-
_at.resp_stop();
518+
_at.cmd_stop_read_resp();
529519
if (_at.get_last_error() != NSAPI_ERROR_OK) {
530520
return NSAPI_ERROR_AUTH_FAILURE;
531521
}
@@ -573,9 +563,7 @@ bool AT_CellularNetwork::set_new_context(int cid)
573563
_at.write_int(cid);
574564
_at.write_string(pdp_type);
575565
_at.write_string(_apn);
576-
_at.cmd_stop();
577-
_at.resp_start();
578-
_at.resp_stop();
566+
_at.cmd_stop_read_resp();
579567
success = (_at.get_last_error() == NSAPI_ERROR_OK);
580568

581569
// Fall back to ipv4
@@ -586,9 +574,7 @@ bool AT_CellularNetwork::set_new_context(int cid)
586574
_at.write_int(cid);
587575
_at.write_string("IP");
588576
_at.write_string(_apn);
589-
_at.cmd_stop();
590-
_at.resp_start();
591-
_at.resp_stop();
577+
_at.cmd_stop_read_resp();
592578
success = (_at.get_last_error() == NSAPI_ERROR_OK);
593579
}
594580

@@ -730,15 +716,12 @@ nsapi_error_t AT_CellularNetwork::set_registration_urc(RegistrationType type, bo
730716
const uint8_t ch_eq = '=';
731717
_at.write_bytes(&ch_eq, 1);
732718
_at.write_int((int)mode);
733-
_at.cmd_stop();
734719
} else {
735720
_at.cmd_start(at_reg[index].cmd);
736721
_at.write_string("=0", false);
737-
_at.cmd_stop();
738722
}
739723

740-
_at.resp_start();
741-
_at.resp_stop();
724+
_at.cmd_stop_read_resp();
742725
return _at.unlock_return_error();
743726
}
744727
}
@@ -769,17 +752,13 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
769752
if (mode != 0) {
770753
_at.clear_error();
771754
_at.cmd_start("AT+COPS=0");
772-
_at.cmd_stop();
773-
_at.resp_start();
774-
_at.resp_stop();
755+
_at.cmd_stop_read_resp();
775756
}
776757
} else {
777758
tr_debug("Manual network registration to %s", plmn);
778759
_at.cmd_start("AT+COPS=4,2,");
779760
_at.write_string(plmn);
780-
_at.cmd_stop();
781-
_at.resp_start();
782-
_at.resp_stop();
761+
_at.cmd_stop_read_resp();
783762
}
784763

785764
return _at.unlock_return_error();
@@ -846,9 +825,7 @@ nsapi_error_t AT_CellularNetwork::set_attach(int /*timeout*/)
846825
if (attached_state != 1) {
847826
tr_debug("Network attach");
848827
_at.cmd_start("AT+CGATT=1");
849-
_at.cmd_stop();
850-
_at.resp_start();
851-
_at.resp_stop();
828+
_at.cmd_stop_read_resp();
852829
}
853830

854831
return _at.unlock_return_error();
@@ -877,9 +854,7 @@ nsapi_error_t AT_CellularNetwork::detach()
877854

878855
tr_debug("Network detach");
879856
_at.cmd_start("AT+CGATT=0");
880-
_at.cmd_stop();
881-
_at.resp_start();
882-
_at.resp_stop();
857+
_at.cmd_stop_read_resp();
883858

884859
call_network_cb(NSAPI_STATUS_DISCONNECTED);
885860

@@ -1030,10 +1005,7 @@ nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt
10301005
_at.write_int(_cid);
10311006
_at.write_int(supported_opt);
10321007
_at.write_int(preferred_opt);
1033-
_at.cmd_stop();
1034-
1035-
_at.resp_start();
1036-
_at.resp_stop();
1008+
_at.cmd_stop_read_resp();
10371009

10381010
return _at.unlock_return_error();
10391011
}

features/cellular/framework/AT/AT_CellularPower.cpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,10 @@ nsapi_error_t AT_CellularPower::set_at_mode()
4949
_at.lock();
5050
_at.flush();
5151
_at.cmd_start("ATE0"); // echo off
52-
_at.cmd_stop();
53-
_at.resp_start();
54-
_at.resp_stop();
52+
_at.cmd_stop_read_resp();
5553

5654
_at.cmd_start("AT+CMEE=1"); // verbose responses
57-
_at.cmd_stop();
58-
_at.resp_start();
59-
_at.resp_stop();
55+
_at.cmd_stop_read_resp();
6056
return _at.unlock_return_error();
6157
}
6258

@@ -66,9 +62,7 @@ nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset)
6662
_at.cmd_start("AT+CFUN=");
6763
_at.write_int(func_level);
6864
_at.write_int(do_reset);
69-
_at.cmd_stop();
70-
_at.resp_start();
71-
_at.resp_stop();
65+
_at.cmd_stop_read_resp();
7266
return _at.unlock_return_error();
7367
}
7468

@@ -78,9 +72,7 @@ nsapi_error_t AT_CellularPower::reset()
7872
_at.cmd_start("AT+CFUN=");// reset to full power levels
7973
_at.write_int(1);
8074
_at.write_int(1);
81-
_at.cmd_stop();
82-
_at.resp_start();
83-
_at.resp_stop();
75+
_at.cmd_stop_read_resp();
8476
return _at.unlock_return_error();
8577
}
8678

@@ -92,9 +84,7 @@ nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int activ
9284
// disable PSM
9385
_at.cmd_start("AT+CPSMS=");
9486
_at.write_int(0);
95-
_at.cmd_stop();
96-
_at.resp_start();
97-
_at.resp_stop();
87+
_at.cmd_stop_read_resp();
9888
} else {
9989
/**
10090
Table 10.5.163a/3GPP TS 24.008: GPRS Timer 3 information element
@@ -199,10 +189,7 @@ nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int activ
199189
_at.write_string(at);
200190
_at.write_string(pt);
201191
_at.write_string(at);
202-
_at.cmd_stop();
203-
_at.resp_start();
204-
_at.resp_stop();
205-
192+
_at.cmd_stop_read_resp();
206193

207194
if (_at.get_last_error() != NSAPI_ERROR_OK) {
208195
tr_warn("Power save mode not enabled!");
@@ -227,9 +214,7 @@ nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnolog
227214
_at.write_int(mode);
228215
_at.write_int(act_type);
229216
_at.write_string(edrx);
230-
_at.cmd_stop();
231-
_at.resp_start();
232-
_at.resp_stop();
217+
_at.cmd_stop_read_resp();
233218

234219
return _at.unlock_return_error();
235220
}
@@ -238,17 +223,13 @@ nsapi_error_t AT_CellularPower::is_device_ready()
238223
{
239224
_at.lock();
240225
_at.cmd_start("AT");
241-
_at.cmd_stop();
242-
_at.resp_start();
243-
_at.resp_stop();
226+
_at.cmd_stop_read_resp();
244227

245228
// we need to do this twice because for example after data mode the first 'AT' command will give modem a
246229
// stimulus that we are back to command mode.
247230
_at.clear_error();
248231
_at.cmd_start("AT");
249-
_at.cmd_stop();
250-
_at.resp_start();
251-
_at.resp_stop();
232+
_at.cmd_stop_read_resp();
252233

253234
return _at.unlock_return_error();
254235
}

features/cellular/framework/AT/AT_CellularSIM.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin)
9090
_at.lock();
9191
_at.cmd_start("AT+CPIN=");
9292
_at.write_string(sim_pin);
93-
_at.cmd_stop();
94-
_at.resp_start();
95-
_at.resp_stop();
93+
_at.cmd_stop_read_resp();
9694
return _at.unlock_return_error();
9795
}
9896

@@ -103,9 +101,7 @@ nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pi
103101
_at.write_string("SC");
104102
_at.write_string(sim_pin);
105103
_at.write_string(new_pin);
106-
_at.cmd_stop();
107-
_at.resp_start();
108-
_at.resp_stop();
104+
_at.cmd_stop_read_resp();
109105
return _at.unlock_return_error();
110106
}
111107

@@ -118,18 +114,14 @@ nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin)
118114
_at.write_string("SC");
119115
_at.write_int(1);
120116
_at.write_string(sim_pin);
121-
_at.cmd_stop();
122-
_at.resp_start();
123-
_at.resp_stop();
117+
_at.cmd_stop_read_resp();
124118
} else {
125119
/* use the SIM unlocked */
126120
_at.cmd_start("AT+CLCK=");
127121
_at.write_string("SC");
128122
_at.write_int(0);
129123
_at.write_string(sim_pin);
130-
_at.cmd_stop();
131-
_at.resp_start();
132-
_at.resp_stop();
124+
_at.cmd_stop_read_resp();
133125
}
134126
return _at.unlock_return_error();
135127
}

0 commit comments

Comments
 (0)