Skip to content

Commit 0e290d3

Browse files
author
Antti Kauppila
committed
New ATHandler functions taken into use
1 parent f92faa6 commit 0e290d3

15 files changed

+87
-167
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,10 +1292,14 @@ nsapi_error_t ATHandler::at_cmd_str(const char *cmd, const char *cmd_chr, char *
12921292

12931293
cmd_stop();
12941294

1295-
memcpy(_cmd_buffer, cmd, strlen(cmd));
1296-
_cmd_buffer[strlen(cmd)] = ':';
1297-
_cmd_buffer[strlen(cmd) + 1] = '\0';
1298-
resp_start(_cmd_buffer);
1295+
if (cmd && strlen(cmd) > 0) {
1296+
memcpy(_cmd_buffer, cmd, strlen(cmd));
1297+
_cmd_buffer[strlen(cmd)] = ':';
1298+
_cmd_buffer[strlen(cmd) + 1] = '\0';
1299+
resp_start(_cmd_buffer);
1300+
} else {
1301+
resp_start();
1302+
}
12991303

13001304
resp_buf[0] = '\0';
13011305
read_string(resp_buf, buf_size);

features/cellular/framework/AT/AT_CellularInformation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size)
8383
return NSAPI_ERROR_PARAMETER;
8484
}
8585
_at.lock();
86-
_at.cmd_start("AT+CIMI");
87-
_at.cmd_stop();
86+
_at.cmd_start_stop("+CIMI", "");
8887
_at.resp_start();
8988
_at.read_string(imsi, MAX_IMSI_LENGTH + 1);
9089
_at.resp_stop();

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,16 @@ nsapi_error_t QUECTEL_BC95::get_sim_state(SimState &state)
5555
{
5656
_at->lock();
5757
_at->flush();
58-
_at->cmd_start("AT+NCCID?");
59-
_at->cmd_stop();
60-
_at->resp_start("+NCCID:");
61-
if (_at->info_resp()) {
62-
state = SimStateReady;
63-
} else {
58+
nsapi_error_t err = _at->at_cmd_discard("+NCCID", "?");
59+
_at->unlock();
60+
61+
state = SimStateReady;
62+
if (err != NSAPI_ERROR_OK) {
6463
tr_warn("SIM not readable.");
65-
state = SimStateUnknown; // SIM may not be ready yet
64+
state = SimStateUnknown;
6665
}
67-
_at->resp_stop();
68-
return _at->unlock_return_error();
66+
67+
return err;
6968
}
7069

7170
AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at)
@@ -87,12 +86,9 @@ nsapi_error_t QUECTEL_BC95::init()
8786
{
8887
_at->lock();
8988
_at->flush();
90-
_at->cmd_start("AT");
91-
_at->cmd_stop_read_resp();
89+
_at->at_cmd_discard("", ""); //Send AT
9290

93-
_at->cmd_start("AT+CMEE="); // verbose responses
94-
_at->write_int(1);
95-
_at->cmd_stop_read_resp();
91+
_at->at_cmd_discard("+CMEE", "=1"); // verbose responses
9692

9793
return _at->unlock_return_error();
9894
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_recvfrom_impl(CellularS
227227
int port;
228228
char ip_address[NSAPI_IP_SIZE];
229229

230-
_at.cmd_start_stop("AT+NSORF", "=", "%d%d", socket->id, size < PACKET_SIZE_MAX ? size : PACKET_SIZE_MAX);
230+
_at.cmd_start_stop("+NSORF", "=", "%d%d", socket->id, size < PACKET_SIZE_MAX ? size : PACKET_SIZE_MAX);
231+
231232
_at.resp_start();
232233
// receiving socket id
233234
_at.skip_param();

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ nsapi_error_t QUECTEL_BG96::soft_power_on()
136136
// check if modem was silently powered on
137137
_at->clear_error();
138138
_at->set_at_timeout(100);
139-
_at->cmd_start("AT");
140-
_at->cmd_stop_read_resp();
139+
_at->at_cmd_discard("", ""); //Send AT
141140
_at->restore_at_timeout();
142141
}
143142
return _at->unlock_return_error();
@@ -161,20 +160,17 @@ nsapi_error_t QUECTEL_BG96::init()
161160

162161
_at->lock();
163162
_at->flush();
164-
_at->cmd_start("ATE0"); // echo off
165-
_at->cmd_stop_read_resp();
163+
_at->at_cmd_discard("E0", ""); // echo off
166164

167-
_at->cmd_start("AT+CMEE=1"); // verbose responses
168-
_at->cmd_stop_read_resp();
165+
_at->at_cmd_discard("+CMEE", "=1"); // verbose responses
169166

170167
if (_at->get_last_error() != NSAPI_ERROR_OK) {
171168
return _at->unlock_return_error();
172169
}
173170

174171
do {
175172
_at->clear_error();
176-
_at->cmd_start("AT+CFUN=1"); // set full functionality
177-
_at->cmd_stop_read_resp();
173+
_at->at_cmd_discard("+CFUN", "=1"); // set full functionality
178174
if (_at->get_last_error() == NSAPI_ERROR_OK) {
179175
break;
180176
}

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,28 @@ nsapi_error_t QUECTEL_M26::get_sim_state(SimState &state)
5252
char buf[13];
5353

5454
_at->lock();
55-
_at->cmd_start("AT+CPIN?");
56-
_at->cmd_stop();
57-
_at->resp_start("+CPIN:");
58-
if (_at->info_resp()) {
59-
_at->read_string(buf, 13);
60-
tr_debug("CPIN: %s", buf);
61-
62-
if (memcmp(buf, "READY", 5) == 0) {
63-
state = SimStateReady;
64-
} else if (memcmp(buf, "SIM PIN", 7) == 0) {
65-
state = SimStatePinNeeded;
66-
} else if (memcmp(buf, "SIM PUK", 7) == 0) {
67-
state = SimStatePukNeeded;
68-
} else if (memcmp(buf, "PH_SIM PIN", 10) == 0) {
69-
state = SimStatePinNeeded;
70-
} else if (memcmp(buf, "PH_SIM PUK", 10) == 0) {
71-
state = SimStatePukNeeded;
72-
} else if (memcmp(buf, "SIM PIN2", 8) == 0) {
73-
state = SimStatePinNeeded;
74-
} else if (memcmp(buf, "SIM PUK2", 8) == 0) {
75-
state = SimStatePukNeeded;
76-
} else {
77-
state = SimStateUnknown; // SIM may not be ready yet
78-
}
55+
nsapi_error_t err = _at->at_cmd_str("+CPIN", "?", buf, 13);
56+
tr_debug("CPIN: %s", buf);
7957

58+
if (memcmp(buf, "READY", 5) == 0) {
59+
state = SimStateReady;
60+
} else if (memcmp(buf, "SIM PIN", 7) == 0) {
61+
state = SimStatePinNeeded;
62+
} else if (memcmp(buf, "SIM PUK", 7) == 0) {
63+
state = SimStatePukNeeded;
64+
} else if (memcmp(buf, "PH_SIM PIN", 10) == 0) {
65+
state = SimStatePinNeeded;
66+
} else if (memcmp(buf, "PH_SIM PUK", 10) == 0) {
67+
state = SimStatePukNeeded;
68+
} else if (memcmp(buf, "SIM PIN2", 8) == 0) {
69+
state = SimStatePinNeeded;
70+
} else if (memcmp(buf, "SIM PUK2", 8) == 0) {
71+
state = SimStatePukNeeded;
72+
} else {
73+
state = SimStateUnknown; // SIM may not be ready yet
8074
}
81-
_at->resp_stop();
82-
return _at->unlock_return_error();
75+
76+
return err;
8377
}
8478

8579
AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
@@ -89,13 +83,7 @@ AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *
8983

9084
nsapi_error_t QUECTEL_M26::shutdown()
9185
{
92-
_at->lock();
93-
_at->cmd_start("AT+QPOWD=0");
94-
_at->cmd_stop();
95-
_at->resp_start();
96-
_at->resp_stop();
97-
98-
return _at->unlock_return_error();;
86+
return _at->at_cmd_discard("+QPOWD", "=0");
9987
}
10088

10189

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init()
159159
}
160160

161161
/*AT+QIMODE=0 Set transparent mode*/
162-
_at.cmd_start_stop("AT+QIMODE", "?");
162+
_at.cmd_start_stop("+QIMODE", "?");
163163

164164
_at.resp_start("+QIMODE:");
165165
if (_at.info_resp()) {
@@ -176,7 +176,7 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init()
176176
}
177177

178178
/*AT+QIMUX=1*/
179-
_at.cmd_start_stop("AT+QIMUX", "?");
179+
_at.cmd_start_stop("+QIMUX", "?");
180180

181181
_at.resp_start("+QIMUX:");
182182
if (_at.info_resp()) {

features/cellular/framework/targets/RiotMicro/AT/RM1000_AT.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,14 @@ nsapi_error_t RM1000_AT::init()
7171

7272
_at->lock();
7373
_at->flush();
74-
_at->cmd_start("ATE0"); // echo off
75-
_at->cmd_stop_read_resp();
74+
_at->at_cmd_discard("E0", ""); // echo off
7675

77-
_at->cmd_start("AT+SIM=physical");
78-
_at->cmd_stop_read_resp();
76+
_at->at_cmd_discard("+SIM", "=physical");
7977

8078
_at->set_at_timeout(5000);
81-
_at->cmd_start("AT+CFUN=1"); // set full functionality
82-
_at->cmd_stop_read_resp();
79+
_at->at_cmd_discard("+CFUN", "=1"); // set full functionality
8380

84-
_at->cmd_start("AT+VERBOSE=0"); // verbose responses
85-
_at->cmd_stop_read_resp();
81+
_at->at_cmd_discard("+VERBOSE", "=0"); // verbose responses
8682

8783
return _at->unlock_return_error();
8884
}

features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ nsapi_size_or_error_t RM1000_AT_CellularStack::socket_recvfrom_impl(CellularSock
246246
read_blk = size;
247247
}
248248
if (socket->pending_bytes > 0) {
249-
_at.cmd_start_stop("AT+RSORCV", "=", "%d%d", socket->id, read_blk);
249+
_at.cmd_start_stop("+RSORCV", "=", "%d%d", socket->id, read_blk);
250250

251251
_at.resp_start("+RSORCV:");
252252
_at.skip_param(); // receiving socket id

features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ nsapi_error_t TELIT_HE910::init()
5555
if (err != NSAPI_ERROR_OK) {
5656
return err;
5757
}
58-
_at->lock();
59-
_at->cmd_start("AT&K0;&C1;&D0");
60-
_at->cmd_stop_read_resp();
61-
62-
return _at->unlock_return_error();
58+
return _at->at_cmd_discard("&K0;&C1;&D0", "");
6359
}
6460

6561
#if MBED_CONF_TELIT_HE910_PROVIDE_DEFAULT

features/cellular/framework/targets/TELIT/ME910/TELIT_ME910.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ nsapi_error_t TELIT_ME910::init()
8989
}
9090
_at->lock();
9191
#if defined (MBED_CONF_TELIT_ME910_RTS) && defined (MBED_CONF_TELIT_ME910_CTS)
92-
_at->cmd_start("AT&K3;&C1;&D0");
92+
_at->at_cmd_discard("&K3;&C1;&D0", "");
9393
#else
94-
_at->cmd_start("AT&K0;&C1;&D0");
94+
_at->at_cmd_discard("&K0;&C1;&D0", "");
9595
#endif
96-
_at->cmd_stop_read_resp();
9796

9897
// AT#QSS=1
9998
// Enable the Query SIM Status unsolicited indication in the ME. The format of the
@@ -104,8 +103,7 @@ nsapi_error_t TELIT_ME910::init()
104103
// <status> values:
105104
// - 0: SIM not inserted
106105
// - 1: SIM inserted
107-
_at->cmd_start("AT#QSS=1");
108-
_at->cmd_stop_read_resp();
106+
_at->at_cmd_discard("#QSS", "=1");
109107

110108
// AT#PSNT=1
111109
// Set command enables unsolicited result code for packet service network type (PSNT)
@@ -115,34 +113,30 @@ nsapi_error_t TELIT_ME910::init()
115113
// - 0: GPRS network
116114
// - 4: LTE network
117115
// - 5: unknown or not registered
118-
_at->cmd_start("AT#PSNT=1");
119-
_at->cmd_stop_read_resp();
116+
_at->at_cmd_discard("#PSNT", "=1");
120117

121118
// AT+CMER=2
122119
// Set command enables sending of unsolicited result codes from TA to TE in the case of
123120
// indicator state changes.
124121
// Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is
125122
// reserved (e.g. on-line data mode) and flush them to the TE after
126123
// reservation; otherwise forward them directly to the TE
127-
_at->cmd_start("AT+CMER=2");
128-
_at->cmd_stop_read_resp();
124+
_at->at_cmd_discard("+CMER", "=2");
129125

130126
// AT+CMEE=2
131127
// Set command disables the use of result code +CME ERROR: <err> as an indication of an
132128
// error relating to the +Cxxx command issued. When enabled, device related errors cause the +CME
133129
// ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned
134130
// normally when the error message is related to syntax, invalid parameters or DTE functionality.
135131
// Current setting: enable and use verbose <err> values
136-
_at->cmd_start("AT+CMEE=2");
137-
_at->cmd_stop_read_resp();
132+
_at->at_cmd_discard("+CMEE", "=2");
138133

139134
// AT&W&P
140135
// - AT&W: Execution command stores on profile <n> the complete configuration of the device. If
141136
// parameter is omitted, the command has the same behavior of AT&W0.
142137
// - AT&P: Execution command defines which full profile will be loaded at startup. If parameter
143138
// is omitted, the command has the same behavior as AT&P0
144-
_at->cmd_start("AT&W&P");
145-
_at->cmd_stop_read_resp();
139+
_at->at_cmd_discard("&W&P", "");
146140

147141
return _at->unlock_return_error();
148142
}

features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool TELIT_ME910_CellularContext::get_context()
3737
bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_PDP_TYPE);
3838
bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_PDP_TYPE);
3939

40-
_at.cmd_start_stop("AT+CGDCONT", "?");
40+
_at.cmd_start_stop("+CGDCONT", "?");
4141
_at.resp_start("+CGDCONT:");
4242
_cid = -1;
4343
int cid_max = 0; // needed when creating new context

0 commit comments

Comments
 (0)