@@ -144,16 +144,11 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_close_impl(int sock_id)
144144
145145 _at.set_at_timeout (FAILURE_TIMEOUT);
146146
147- _at.cmd_start (" AT^SISC=" );
148- _at.write_int (sock_id);
149- _at.cmd_stop_read_resp ();
147+ _at.at_cmd_discard (" ^SISC" , " =" , " %d" , sock_id);
150148
151149 _at.clear_error (); // clear SISS even though SISC fails
152- _at.cmd_start (" AT^SISS=" );
153- _at.write_int (sock_id);
154- _at.write_string (" srvType" );
155- _at.write_string (" none" );
156- _at.cmd_stop_read_resp ();
150+
151+ _at.at_cmd_discard (" ^SISS" , " =" , " %d%s%s" , sock_id, " srvType" , " none" );
157152
158153 _at.restore_at_timeout ();
159154
@@ -170,8 +165,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
170165 int internet_service_id = find_socket_index (socket);
171166 bool foundSrvType = false ;
172167 bool foundConIdType = false ;
173- _at.cmd_start (" AT^SISS?" );
174- _at.cmd_stop ();
168+ _at.cmd_start_stop (" ^SISS" , " ?" );
175169 _at.resp_start (" ^SISS:" );
176170 /*
177171 * Profile is a list of tag-value map:
@@ -211,19 +205,11 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
211205 _at.resp_stop ();
212206
213207 if (!foundSrvType) {
214- _at.cmd_start (" AT^SISS=" );
215- _at.write_int (internet_service_id);
216- _at.write_string (" srvType" );
217- _at.write_string (" Socket" );
218- _at.cmd_stop_read_resp ();
208+ _at.at_cmd_discard (" ^SISS" , " =" , " %d%s%s" , internet_service_id, " srvType" , " Socket" );
219209 }
220210
221211 if (!foundConIdType) {
222- _at.cmd_start (" AT^SISS=" );
223- _at.write_int (internet_service_id);
224- _at.write_string (" conId" );
225- _at.write_int (connection_profile_id);
226- _at.cmd_stop_read_resp ();
212+ _at.at_cmd_discard (" ^SISS" , " =" , " %d%s%d" , internet_service_id, " conId" , connection_profile_id);
227213 }
228214
229215 // host address (IPv4) and local+remote port is needed only for BGS2 which does not support UDP server socket
@@ -249,9 +235,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
249235 _at.write_string (sock_addr);
250236 _at.cmd_stop_read_resp ();
251237
252- _at.cmd_start (" AT^SISO=" );
253- _at.write_int (internet_service_id);
254- _at.cmd_stop_read_resp ();
238+ _at.at_cmd_discard (" ^SISO" , " =" , " %d" , internet_service_id);
255239
256240 if (_at.get_last_error ()) {
257241 tr_error (" Socket %d open failed!" , socket->id );
@@ -337,13 +321,8 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
337321 }
338322
339323 _at.set_at_timeout (FAILURE_TIMEOUT);
340- _at.cmd_start (" AT^SISW=" );
341- _at.write_int (socket->id );
342- _at.write_int (size);
343324
344325 if (GEMALTO_CINTERION::get_module () != GEMALTO_CINTERION::ModuleBGS2) {
345- _at.write_int (0 );
346-
347326 // UDP requires Udp_RemClient
348327 if (socket->proto == NSAPI_UDP) {
349328 char socket_address[NSAPI_IPv6_SIZE + sizeof (" []:12345" ) - 1 + 1 ];
@@ -352,12 +331,14 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
352331 } else {
353332 std::sprintf (socket_address, " [%s]:%u" , address.get_ip_address (), address.get_port ());
354333 }
355- _at.write_string (socket_address);
334+ _at.cmd_start_stop (" ^SISW" , " =" , " %d%d%d%s" , socket->id , size, 0 , socket_address);
335+ } else {
336+ _at.cmd_start_stop (" ^SISW" , " =" , " %d%d%d" , socket->id , size, 0 );
356337 }
338+ } else {
339+ _at.cmd_start_stop (" ^SISW" , " =" , " %d%d" , socket->id , size);
357340 }
358341
359- _at.cmd_stop ();
360-
361342sisw_retry:
362343 _at.resp_start (" ^SISW:" );
363344 if (!_at.info_resp ()) {
@@ -418,10 +399,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
418399 size = UDP_PACKET_SIZE;
419400 }
420401
421- _at.cmd_start (" AT^SISR=" );
422- _at.write_int (socket->id );
423- _at.write_int (size);
424- _at.cmd_stop ();
402+ _at.cmd_start_stop (" ^SISR" , " =" , " %d%d" , socket->id , size);
425403
426404sisr_retry:
427405 _at.resp_start (" ^SISR:" );
@@ -516,8 +494,8 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int con
516494
517495 char conParamType[sizeof (" GPRS0" ) + 1 ];
518496 std::sprintf (conParamType, " GPRS%d" , (_stack_type == IPV4_STACK) ? 0 : 6 );
519- _at. cmd_start ( " AT^SICS? " );
520- _at.cmd_stop ( );
497+
498+ _at.cmd_start_stop ( " ^SICS " , " ? " );
521499 bool found_connection = false ;
522500 _at.resp_start (" ^SICS:" );
523501 while (_at.info_resp ()) {
@@ -543,46 +521,25 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int con
543521
544522 // connection profile is bound to a PDP context and it can not be changed
545523 if (!found_connection) {
546- _at.cmd_start (" AT^SICS=" );
547- _at.write_int (connection_profile_id);
548- _at.write_string (" conType" );
549- _at.write_string (conParamType);
550- _at.cmd_stop_read_resp ();
524+ _at.at_cmd_discard (" ^SICS" , " =" , " %d%s%s" , connection_profile_id, " conType" , conParamType);
551525
552526 if (_apn && strlen (_apn) > 0 ) {
553- _at.cmd_start (" AT^SICS=" );
554- _at.write_int (connection_profile_id);
555- _at.write_string (" apn" );
556- _at.write_string (_apn);
557- _at.cmd_stop_read_resp ();
527+ _at.at_cmd_discard (" ^SICS" , " =" , " %d%s%s" , connection_profile_id, " apn" , _apn);
558528 }
559529
560530 if (_user && strlen (_user) > 0 ) {
561- _at.cmd_start (" AT^SICS=" );
562- _at.write_int (connection_profile_id);
563- _at.write_string (" user" );
564- _at.write_string (_user);
565- _at.cmd_stop_read_resp ();
531+ _at.at_cmd_discard (" ^SICS" , " =" , " %d%s%s" , connection_profile_id, " user" , _user);
566532 }
567533
568534 if (_password && strlen (_password) > 0 ) {
569- _at.cmd_start (" AT^SICS=" );
570- _at.write_int (connection_profile_id);
571- _at.write_string (" passwd" );
572- _at.write_string (_password);
573- _at.cmd_stop_read_resp ();
535+ _at.at_cmd_discard (" ^SICS" , " =" , " %d%s%s" , connection_profile_id, " passwd" , _password);
574536 }
575537
576538 // set maximum inactivity timeout
577- _at.cmd_start (" AT^SICS=" );
578- _at.write_int (connection_profile_id);
579- _at.write_string (" inactTO" );
580- _at.write_int (0xffff ); // 2^16-1
581- _at.cmd_stop_read_resp ();
539+ _at.at_cmd_discard (" ^SICS" , " =" , " %d%s%d" , connection_profile_id, " inactTO" , 0xffff );
582540
583541 // use URC mode ON
584- _at.cmd_start (" AT^SCFG=\" Tcp/withURCs\" ,\" on\" " );
585- _at.cmd_stop_read_resp ();
542+ _at.at_cmd_discard (" ^SCFG" , " =" , " %s%s" , " Tcp/withURCs" , " on" );
586543 }
587544
588545 tr_debug (" Cinterion profile %d, %s (err %d)" , connection_profile_id, (_stack_type == IPV4_STACK) ? " IPv4" : " IPv6" , _at.get_last_error ());
@@ -598,15 +555,10 @@ void GEMALTO_CINTERION_CellularStack::close_connection_profile(int connection_pr
598555 // To clear connection profile need to detach from packet data.
599556 // After detach modem sends PDP disconnected event to network class,
600557 // which propagates network disconnected to upper layer to start reconnecting.
601- _at.cmd_start (" AT+CGATT=0" );
602- _at.cmd_stop_read_resp ();
558+ _at.at_cmd_discard (" +CGATT" , " =0" );
603559 _at.clear_error ();
604560
605- _at.cmd_start (" AT^SICS=" );
606- _at.write_int (connection_profile_id);
607- _at.write_string (" conType" );
608- _at.write_string (" none" );
609- _at.cmd_stop_read_resp ();
561+ _at.at_cmd_discard (" ^SICS" , " =" , " %d%s%s" , connection_profile_id, " conType" , " none" );
610562
611563 _at.clear_error ();
612564}
0 commit comments