diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index cfc86ec54a..d464e634f9 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -1237,7 +1237,7 @@ void ATHandler::handle_args(const char *format, std::va_list list) { while (*format != '\0') { if (*format == 'd') { - int i = va_arg(list, int); + int32_t i = va_arg(list, int32_t); write_int(i); } else if (*format == 's') { char *str = (char *)va_arg(list, char *); @@ -1305,10 +1305,14 @@ nsapi_error_t ATHandler::at_cmd_str(const char *cmd, const char *cmd_chr, char * cmd_stop(); - memcpy(_cmd_buffer, cmd, strlen(cmd)); - _cmd_buffer[strlen(cmd)] = ':'; - _cmd_buffer[strlen(cmd) + 1] = '\0'; - resp_start(_cmd_buffer); + if (cmd && strlen(cmd) > 0) { + memcpy(_cmd_buffer, cmd, strlen(cmd)); + _cmd_buffer[strlen(cmd)] = ':'; + _cmd_buffer[strlen(cmd) + 1] = '\0'; + resp_start(_cmd_buffer); + } else { + resp_start(); + } resp_buf[0] = '\0'; read_string(resp_buf, buf_size); diff --git a/features/cellular/framework/AT/AT_CellularInformation.cpp b/features/cellular/framework/AT/AT_CellularInformation.cpp index 431884bdca..d7b182944f 100644 --- a/features/cellular/framework/AT/AT_CellularInformation.cpp +++ b/features/cellular/framework/AT/AT_CellularInformation.cpp @@ -83,8 +83,7 @@ nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size) return NSAPI_ERROR_PARAMETER; } _at.lock(); - _at.cmd_start("AT+CIMI"); - _at.cmd_stop(); + _at.cmd_start_stop("+CIMI", ""); _at.resp_start(); _at.read_string(imsi, MAX_IMSI_LENGTH + 1); _at.resp_stop(); diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp index 3f81221401..8699fde101 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularInformation.cpp @@ -25,13 +25,7 @@ GEMALTO_CINTERION_CellularInformation::GEMALTO_CINTERION_CellularInformation(ATH nsapi_error_t GEMALTO_CINTERION_CellularInformation::get_iccid(char *buf, size_t buf_size) { - _at.lock(); - _at.cmd_start("AT^SCID"); - _at.cmd_stop(); - _at.resp_start("^SCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); + return _at.at_cmd_str("^SCID", "", buf, buf_size); } } /* namespace mbed */ diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp index cf5550be8d..d4766530b1 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp @@ -144,16 +144,11 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_close_impl(int sock_id) _at.set_at_timeout(FAILURE_TIMEOUT); - _at.cmd_start("AT^SISC="); - _at.write_int(sock_id); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SISC", "=", "%d", sock_id); _at.clear_error(); // clear SISS even though SISC fails - _at.cmd_start("AT^SISS="); - _at.write_int(sock_id); - _at.write_string("srvType"); - _at.write_string("none"); - _at.cmd_stop_read_resp(); + + _at.at_cmd_discard("^SISS", "=", "%d%s%s", sock_id, "srvType", "none"); _at.restore_at_timeout(); @@ -170,8 +165,7 @@ retry_open: int internet_service_id = find_socket_index(socket); bool foundSrvType = false; bool foundConIdType = false; - _at.cmd_start("AT^SISS?"); - _at.cmd_stop(); + _at.cmd_start_stop("^SISS", "?"); _at.resp_start("^SISS:"); /* * Profile is a list of tag-value map: @@ -211,19 +205,11 @@ retry_open: _at.resp_stop(); if (!foundSrvType) { - _at.cmd_start("AT^SISS="); - _at.write_int(internet_service_id); - _at.write_string("srvType"); - _at.write_string("Socket"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SISS", "=", "%d%s%s", internet_service_id, "srvType", "Socket"); } if (!foundConIdType) { - _at.cmd_start("AT^SISS="); - _at.write_int(internet_service_id); - _at.write_string("conId"); - _at.write_int(connection_profile_id); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SISS", "=", "%d%s%d", internet_service_id, "conId", connection_profile_id); } // host address (IPv4) and local+remote port is needed only for BGS2 which does not support UDP server socket @@ -249,9 +235,7 @@ retry_open: _at.write_string(sock_addr); _at.cmd_stop_read_resp(); - _at.cmd_start("AT^SISO="); - _at.write_int(internet_service_id); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SISO", "=", "%d", internet_service_id); if (_at.get_last_error()) { tr_error("Socket %d open failed!", socket->id); @@ -337,13 +321,8 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul } _at.set_at_timeout(FAILURE_TIMEOUT); - _at.cmd_start("AT^SISW="); - _at.write_int(socket->id); - _at.write_int(size); if (GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) { - _at.write_int(0); - // UDP requires Udp_RemClient if (socket->proto == NSAPI_UDP) { 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 } else { std::sprintf(socket_address, "[%s]:%u", address.get_ip_address(), address.get_port()); } - _at.write_string(socket_address); + _at.cmd_start_stop("^SISW", "=", "%d%d%d%s", socket->id, size, 0, socket_address); + } else { + _at.cmd_start_stop("^SISW", "=", "%d%d%d", socket->id, size, 0); } + } else { + _at.cmd_start_stop("^SISW", "=", "%d%d", socket->id, size); } - _at.cmd_stop(); - sisw_retry: _at.resp_start("^SISW:"); if (!_at.info_resp()) { @@ -418,10 +399,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell size = UDP_PACKET_SIZE; } - _at.cmd_start("AT^SISR="); - _at.write_int(socket->id); - _at.write_int(size); - _at.cmd_stop(); + _at.cmd_start_stop("^SISR", "=", "%d%d", socket->id, size); sisr_retry: _at.resp_start("^SISR:"); @@ -516,8 +494,8 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int con char conParamType[sizeof("GPRS0") + 1]; std::sprintf(conParamType, "GPRS%d", (_stack_type == IPV4_STACK) ? 0 : 6); - _at.cmd_start("AT^SICS?"); - _at.cmd_stop(); + + _at.cmd_start_stop("^SICS", "?"); bool found_connection = false; _at.resp_start("^SICS:"); while (_at.info_resp()) { @@ -543,46 +521,25 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int con // connection profile is bound to a PDP context and it can not be changed if (!found_connection) { - _at.cmd_start("AT^SICS="); - _at.write_int(connection_profile_id); - _at.write_string("conType"); - _at.write_string(conParamType); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SICS", "=", "%d%s%s", connection_profile_id, "conType", conParamType); if (_apn && strlen(_apn) > 0) { - _at.cmd_start("AT^SICS="); - _at.write_int(connection_profile_id); - _at.write_string("apn"); - _at.write_string(_apn); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SICS", "=", "%d%s%s", connection_profile_id, "apn", _apn); } if (_user && strlen(_user) > 0) { - _at.cmd_start("AT^SICS="); - _at.write_int(connection_profile_id); - _at.write_string("user"); - _at.write_string(_user); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SICS", "=", "%d%s%s", connection_profile_id, "user", _user); } if (_password && strlen(_password) > 0) { - _at.cmd_start("AT^SICS="); - _at.write_int(connection_profile_id); - _at.write_string("passwd"); - _at.write_string(_password); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SICS", "=", "%d%s%s", connection_profile_id, "passwd", _password); } // set maximum inactivity timeout - _at.cmd_start("AT^SICS="); - _at.write_int(connection_profile_id); - _at.write_string("inactTO"); - _at.write_int(0xffff); // 2^16-1 - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SICS", "=", "%d%s%d", connection_profile_id, "inactTO", 0xffff); // use URC mode ON - _at.cmd_start("AT^SCFG=\"Tcp/withURCs\",\"on\""); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SCFG", "=", "%s%s", "Tcp/withURCs", "on"); } 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 // To clear connection profile need to detach from packet data. // After detach modem sends PDP disconnected event to network class, // which propagates network disconnected to upper layer to start reconnecting. - _at.cmd_start("AT+CGATT=0"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("+CGATT", "=0"); _at.clear_error(); - _at.cmd_start("AT^SICS="); - _at.write_int(connection_profile_id); - _at.write_string("conType"); - _at.write_string("none"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("^SICS", "=", "%d%s%s", connection_profile_id, "conType", "none"); _at.clear_error(); } diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 4853d1d3d6..a47e765b07 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -55,17 +55,16 @@ nsapi_error_t QUECTEL_BC95::get_sim_state(SimState &state) { _at->lock(); _at->flush(); - _at->cmd_start("AT+NCCID?"); - _at->cmd_stop(); - _at->resp_start("+NCCID:"); - if (_at->info_resp()) { - state = SimStateReady; - } else { + nsapi_error_t err = _at->at_cmd_discard("+NCCID", "?"); + _at->unlock(); + + state = SimStateReady; + if (err != NSAPI_ERROR_OK) { tr_warn("SIM not readable."); - state = SimStateUnknown; // SIM may not be ready yet + state = SimStateUnknown; } - _at->resp_stop(); - return _at->unlock_return_error(); + + return err; } AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at) @@ -89,12 +88,9 @@ nsapi_error_t QUECTEL_BC95::init() _at->lock(); _at->flush(); - _at->cmd_start("AT"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("", ""); //Send AT - _at->cmd_start("AT+CMEE="); // verbose responses - _at->write_int(1); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+CMEE", "=1"); // verbose responses return _at->unlock_return_error(); } diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp index 8bc51c5aef..88cdfdb5a0 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp @@ -29,13 +29,7 @@ QUECTEL_BC95_CellularInformation::~QUECTEL_BC95_CellularInformation() // According to BC95_AT_Commands_Manual_V1.9 nsapi_error_t QUECTEL_BC95_CellularInformation::get_iccid(char *buf, size_t buf_size) { - _at.lock(); - _at.cmd_start("AT+NCCID?"); - _at.cmd_stop(); - _at.resp_start("+NCCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); + return _at.at_cmd_str("+NCCID", "?", buf, buf_size); } } /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp index 29c199e4b3..7c09ec3dca 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp @@ -62,9 +62,8 @@ nsapi_error_t QUECTEL_BC95_CellularStack::socket_connect(nsapi_socket_t handle, _at.write_int(socket->id); _at.write_string(address.get_ip_address(), false); _at.write_int(address.get_port()); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.cmd_stop_read_resp(); + _at.unlock(); if (_at.get_last_error() == NSAPI_ERROR_OK) { @@ -130,13 +129,11 @@ nsapi_error_t QUECTEL_BC95_CellularStack::socket_close_impl(int sock_id) if (sock && sock->closed) { return NSAPI_ERROR_OK; } - _at.cmd_start("AT+NSOCL="); - _at.write_int(sock_id); - _at.cmd_stop_read_resp(); + nsapi_error_t err = _at.at_cmd_discard("+NSOCL", "=", "%d", sock_id); - tr_info("Close socket: %d error: %d", sock_id, _at.get_last_error()); + tr_info("Close socket: %d error: %d", sock_id, err); - return _at.get_last_error(); + return err; } nsapi_error_t QUECTEL_BC95_CellularStack::create_socket_impl(CellularSocket *socket) @@ -145,54 +142,23 @@ nsapi_error_t QUECTEL_BC95_CellularStack::create_socket_impl(CellularSocket *soc bool socketOpenWorking = false; if (socket->proto == NSAPI_UDP) { - _at.cmd_start("AT+NSOCR=DGRAM,17,"); + _at.cmd_start_stop("+NSOCR", "=DGRAM,", "%d%d%d", 17, socket->localAddress.get_port(), 1); } else if (socket->proto == NSAPI_TCP) { - _at.cmd_start("AT+NSOCR=STREAM,6,"); + _at.cmd_start_stop("+NSOCR", "=STREAM,", "%d%d%d", 6, socket->localAddress.get_port(), 1); } else { return NSAPI_ERROR_PARAMETER; } - _at.write_int(socket->localAddress.get_port()); - _at.write_int(1); - _at.cmd_stop(); _at.resp_start(); sock_id = _at.read_int(); _at.resp_stop(); socketOpenWorking = (_at.get_last_error() == NSAPI_ERROR_OK); - if (!socketOpenWorking) { - _at.cmd_start("AT+NSOCL=0"); - _at.cmd_stop_read_resp(); - - if (socket->proto == NSAPI_UDP) { - _at.cmd_start("AT+NSOCR=DGRAM,17,"); - } else if (socket->proto == NSAPI_TCP) { - _at.cmd_start("AT+NSOCR=STREAM,6,"); - } - _at.write_int(socket->localAddress.get_port()); - _at.write_int(1); - _at.cmd_stop(); - _at.resp_start(); - sock_id = _at.read_int(); - _at.resp_stop(); - - socketOpenWorking = (_at.get_last_error() == NSAPI_ERROR_OK); - } - if (!socketOpenWorking || (sock_id == -1)) { tr_error("Socket create failed!"); return NSAPI_ERROR_NO_SOCKET; } - // Check for duplicate socket id delivered by modem - for (int i = 0; i < BC95_SOCKET_MAX; i++) { - CellularSocket *sock = _socket[i]; - if (sock && sock->id != -1 && sock->id == sock_id) { - tr_error("Duplicate socket index: %d, sock_id: %d", i, sock_id); - return NSAPI_ERROR_NO_SOCKET; - } - } - tr_info("Socket create id: %d", sock_id); socket->id = sock_id; @@ -261,10 +227,8 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_recvfrom_impl(CellularS int port; char ip_address[NSAPI_IP_SIZE]; - _at.cmd_start("AT+NSORF="); - _at.write_int(socket->id); - _at.write_int(size <= PACKET_SIZE_MAX ? size : PACKET_SIZE_MAX); - _at.cmd_stop(); + _at.cmd_start_stop("+NSORF", "=", "%d%d", socket->id, size < PACKET_SIZE_MAX ? size : PACKET_SIZE_MAX); + _at.resp_start(); // receiving socket id _at.skip_param(); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 837f36c209..083bafa4a1 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -138,8 +138,7 @@ nsapi_error_t QUECTEL_BG96::soft_power_on() // check if modem was silently powered on _at->clear_error(); _at->set_at_timeout(100); - _at->cmd_start("AT"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("", ""); //Send AT _at->restore_at_timeout(); } return _at->unlock_return_error(); @@ -165,11 +164,9 @@ nsapi_error_t QUECTEL_BG96::init() _at->lock(); _at->flush(); - _at->cmd_start("ATE0"); // echo off - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("E0", ""); // echo off - _at->cmd_start("AT+CMEE=1"); // verbose responses - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+CMEE", "=1"); // verbose responses if (_at->get_last_error() != NSAPI_ERROR_OK) { return _at->unlock_return_error(); @@ -177,8 +174,7 @@ nsapi_error_t QUECTEL_BG96::init() do { _at->clear_error(); - _at->cmd_start("AT+CFUN=1"); // set full functionality - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+CFUN", "=1"); // set full functionality if (_at->get_last_error() == NSAPI_ERROR_OK) { break; } diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp index f988530935..39ab44fe07 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp @@ -20,8 +20,7 @@ nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::recv(void *buffer, nsapi_ { _at.lock(); - _at.cmd_start("AT+QCFGEXT=\"nipdr\",0"); - _at.cmd_stop(); + _at.cmd_start_stop("QCFGEXT", "=", "%s%d", "nipdr", 0); _at.resp_start("+QCFGEXT: "); // skip 3 params: "nipdr",, _at.skip_param(3); @@ -34,9 +33,7 @@ nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::recv(void *buffer, nsapi_ return NSAPI_ERROR_WOULD_BLOCK; } - _at.cmd_start("AT+QCFGEXT=\"nipdr\","); - _at.write_int(unread_length); - _at.cmd_stop(); + _at.cmd_start_stop("QCFGEXT", "=", "%s%d", "nipdr", unread_length); _at.resp_start("+QCFGEXT:"); // skip "nipdr" diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp index f398c24ee8..bbec885d7a 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp @@ -52,34 +52,28 @@ nsapi_error_t QUECTEL_M26::get_sim_state(SimState &state) char buf[13]; _at->lock(); - _at->cmd_start("AT+CPIN?"); - _at->cmd_stop(); - _at->resp_start("+CPIN:"); - if (_at->info_resp()) { - _at->read_string(buf, 13); - tr_debug("CPIN: %s", buf); - - if (memcmp(buf, "READY", 5) == 0) { - state = SimStateReady; - } else if (memcmp(buf, "SIM PIN", 7) == 0) { - state = SimStatePinNeeded; - } else if (memcmp(buf, "SIM PUK", 7) == 0) { - state = SimStatePukNeeded; - } else if (memcmp(buf, "PH_SIM PIN", 10) == 0) { - state = SimStatePinNeeded; - } else if (memcmp(buf, "PH_SIM PUK", 10) == 0) { - state = SimStatePukNeeded; - } else if (memcmp(buf, "SIM PIN2", 8) == 0) { - state = SimStatePinNeeded; - } else if (memcmp(buf, "SIM PUK2", 8) == 0) { - state = SimStatePukNeeded; - } else { - state = SimStateUnknown; // SIM may not be ready yet - } + nsapi_error_t err = _at->at_cmd_str("+CPIN", "?", buf, 13); + tr_debug("CPIN: %s", buf); + if (memcmp(buf, "READY", 5) == 0) { + state = SimStateReady; + } else if (memcmp(buf, "SIM PIN", 7) == 0) { + state = SimStatePinNeeded; + } else if (memcmp(buf, "SIM PUK", 7) == 0) { + state = SimStatePukNeeded; + } else if (memcmp(buf, "PH_SIM PIN", 10) == 0) { + state = SimStatePinNeeded; + } else if (memcmp(buf, "PH_SIM PUK", 10) == 0) { + state = SimStatePukNeeded; + } else if (memcmp(buf, "SIM PIN2", 8) == 0) { + state = SimStatePinNeeded; + } else if (memcmp(buf, "SIM PUK2", 8) == 0) { + state = SimStatePukNeeded; + } else { + state = SimStateUnknown; // SIM may not be ready yet } - _at->resp_stop(); - return _at->unlock_return_error(); + + return err; } 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 * nsapi_error_t QUECTEL_M26::shutdown() { - _at->lock(); - _at->cmd_start("AT+QPOWD=0"); - _at->cmd_stop(); - _at->resp_start(); - _at->resp_stop(); - - return _at->unlock_return_error();; + return _at->at_cmd_discard("+QPOWD", "=0"); } diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp index 852f2c437b..d96ce4eacf 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp @@ -36,22 +36,17 @@ NetworkStack *QUECTEL_M26_CellularContext::get_stack() nsapi_error_t QUECTEL_M26_CellularContext::do_user_authentication() { - - _at.cmd_start("AT+QICSGP="); - _at.write_int(1); /*GPRS MODE = 1, CSD MODE = 0*/ - _at.write_string(_apn); + nsapi_error_t err = NSAPI_ERROR_OK; if (_pwd && _uname) { - _at.write_string(_uname); - _at.write_string(_pwd); + err = _at.at_cmd_discard("^SISO", "=", "%d%s%s%s", 1, _apn, _uname, _pwd); + } else { + err = _at.at_cmd_discard("^SISO", "=", "%d%s", 1, _apn); } - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - if (_at.get_last_error() != NSAPI_ERROR_OK) { + if (err != NSAPI_ERROR_OK) { return NSAPI_ERROR_AUTH_FAILURE; } - return NSAPI_ERROR_OK; + return err; } } /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp index f55edcc961..1f5b414e10 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp @@ -27,11 +27,5 @@ QUECTEL_M26_CellularInformation::QUECTEL_M26_CellularInformation(ATHandler &atHa // According to M26_AT_Commands_Manual_V1.9 nsapi_error_t QUECTEL_M26_CellularInformation::get_iccid(char *buf, size_t buf_size) { - _at.lock(); - _at.cmd_start("AT+CCID"); - _at.cmd_stop(); - _at.resp_start("+CCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); + return _at.at_cmd_str("+CCID", "", buf, buf_size); } diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp index 252a8adb66..0c09c537e6 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp @@ -137,11 +137,7 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init() _at.lock(); /*AT+QIFGCNT=0*/ - _at.cmd_start("AT+QIFGCNT="); - _at.write_int(0); /* Set the Context 0 as the foreground context.*/ - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QIFGCNT", "=", "%d", 0); ret_val = _at.get_last_error(); if (ret_val != NSAPI_ERROR_OK) { @@ -149,17 +145,12 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init() return NSAPI_ERROR_DEVICE_ERROR; } #if 0 - /*AT+QICSGP=1*/ - _at.cmd_start("AT+QICSGP="); - _at.write_int(1); /* mode: 0-CSD, 1-GPRS */ - _at.write_string(_apn); if (_pwd && _uname) { - _at.write_string(_uname); - _at.write_string(_pwd); + _at.at_cmd_discard("+QICSGP", "=", "%d%s%s%s", 1, _apn, _uname, _pwd); + } else { + _at.at_cmd_discard("+QICSGP", "=", "%d%s", 1, _apn); } - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + #endif ret_val = _at.get_last_error(); if (ret_val != NSAPI_ERROR_OK) { @@ -168,19 +159,15 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init() } /*AT+QIMODE=0 Set transparent mode*/ - _at.cmd_start("AT+QIMODE?"); - _at.cmd_stop(); + _at.cmd_start_stop("+QIMODE", "?"); + _at.resp_start("+QIMODE:"); if (_at.info_resp()) { tcpip_mode = _at.read_int(); } _at.resp_stop(); if (tcpip_mode) { - _at.cmd_start("AT+QIMOD="); - _at.write_int(0); /* 0-Disable, 1-Enable */ - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QIMODE", "=", "%d", 0); } ret_val = _at.get_last_error(); if (ret_val != NSAPI_ERROR_OK) { @@ -189,19 +176,15 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init() } /*AT+QIMUX=1*/ - _at.cmd_start("AT+QIMUX?"); - _at.cmd_stop(); + _at.cmd_start_stop("+QIMUX", "?"); + _at.resp_start("+QIMUX:"); if (_at.info_resp()) { mux_mode = _at.read_int(); } _at.resp_stop(); if (!mux_mode) { - _at.cmd_start("AT+QIMUX="); - _at.write_int(1); /* 0-Disable, 1-Enable */ - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QIMUX", "=", "%d", 1); } ret_val = _at.get_last_error(); if (ret_val != NSAPI_ERROR_OK) { @@ -210,19 +193,15 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init() } /*AT+QINDI=2*/ - _at.cmd_start("AT+QINDI?"); - _at.cmd_stop(); + _at.cmd_start_stop("+QINDI", "?"); + _at.resp_start(); if (_at.info_resp()) { cache_mode = _at.read_int(); } _at.resp_stop(); if (cache_mode != 2) { - _at.cmd_start("AT+QINDI="); - _at.write_int(2); /* 0-Disable, 1-Single Cache, 2-Multi Cache */ - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QINDI", "=", "%d", 2); } ret_val = _at.get_last_error(); @@ -251,13 +230,7 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_close_impl(int sock_id) { tr_debug("QUECTEL_M26_CellularStack:%s:%u:", __FUNCTION__, __LINE__); - _at.cmd_start("AT+QICLOSE="); - _at.write_int(sock_id); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - - return _at.get_last_error(); + return _at.at_cmd_discard("+QICLOSE", "=", "%d", sock_id); } void QUECTEL_M26_CellularStack::handle_open_socket_response(int &modem_connect_id, int &err) @@ -312,28 +285,16 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_connect(nsapi_socket_t handle, c _at.lock(); if (socket->proto == NSAPI_TCP) { - _at.cmd_start("AT+QIOPEN="); - _at.write_int(request_connect_id); - _at.write_string("TCP"); - _at.write_string(address.get_ip_address()); - _at.write_int(address.get_port()); - _at.cmd_stop(); + _at.cmd_start_stop("+QIOPEN", "=", "%d%s%s%d", request_connect_id, "TCP", + address.get_ip_address(), address.get_port());; handle_open_socket_response(modem_connect_id, err); if ((_at.get_last_error() == NSAPI_ERROR_OK) && err) { - _at.cmd_start("AT+QICLOSE="); - _at.write_int(modem_connect_id); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QICLOSE", "=", "%d", modem_connect_id); - _at.cmd_start("AT+QIOPEN="); - _at.write_int(request_connect_id); - _at.write_string("TCP"); - _at.write_string(address.get_ip_address()); - _at.write_int(address.get_port()); - _at.cmd_stop(); + _at.cmd_start_stop("+QIOPEN", "=", "%d%s%s%d", request_connect_id, "TCP", + address.get_ip_address(), address.get_port()); handle_open_socket_response(modem_connect_id, err); } @@ -341,11 +302,7 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_connect(nsapi_socket_t handle, c // If opened successfully BUT not requested one, close it if (!err && (modem_connect_id != request_connect_id)) { - _at.cmd_start("AT+QICLOSE="); - _at.write_int(modem_connect_id); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QICLOSE", "=", "%d", modem_connect_id); } nsapi_error_t ret_val = _at.get_last_error(); @@ -391,40 +348,24 @@ nsapi_error_t QUECTEL_M26_CellularStack::create_socket_impl(CellularSocket *sock tr_debug("QUECTEL_M26_CellularStack:%s:%u:[%d,%d]", __FUNCTION__, __LINE__, socket->proto, socket->connected); if (socket->connected) { - _at.cmd_start("AT+QIOPEN="); - _at.write_int(request_connect_id); - _at.write_string((socket->proto == NSAPI_TCP) ? "TCP" : "UDP"); - _at.write_string(socket->remoteAddress.get_ip_address()); - _at.write_int(socket->remoteAddress.get_port()); - _at.cmd_stop(); + _at.cmd_start_stop("+QIOPEN", "=", "%d%s%s%d", request_connect_id, (socket->proto == NSAPI_TCP) ? "TCP" : "UDP", + socket->remoteAddress.get_ip_address(), socket->remoteAddress.get_port()); handle_open_socket_response(modem_connect_id, err); /* Close and retry if socket create fail */ if ((_at.get_last_error() != NSAPI_ERROR_OK) || err) { - _at.cmd_start("AT+QICLOSE="); - _at.write_int(modem_connect_id); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QICLOSE", "=", "%d", modem_connect_id); - _at.cmd_start("AT+QIOPEN="); - _at.write_int(request_connect_id); - _at.write_string((socket->proto == NSAPI_TCP) ? "TCP" : "UDP"); - _at.write_string(socket->remoteAddress.get_ip_address()); - _at.write_int(socket->remoteAddress.get_port()); - _at.cmd_stop(); + _at.cmd_start_stop("+QIOPEN", "=", "%d%s%s%d", request_connect_id, (socket->proto == NSAPI_TCP) ? "TCP" : "UDP", + socket->remoteAddress.get_ip_address(), socket->remoteAddress.get_port()); handle_open_socket_response(modem_connect_id, err); } /* If opened successfully BUT not requested one, close it */ if (!err && (modem_connect_id != request_connect_id)) { - _at.cmd_start("AT+QICLOSE="); - _at.write_int(modem_connect_id); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+QICLOSE", "=", "%d", modem_connect_id); } ret_val = _at.get_last_error(); @@ -472,9 +413,7 @@ nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_sendto_impl(CellularSock bool ready_to_send = false; uint64_t start_time = rtos::Kernel::get_ms_count(); while (!ready_to_send && start_time < rtos::Kernel::get_ms_count() + SOCKET_SEND_READY_TIMEOUT) { - _at.cmd_start("AT+QISACK="); - _at.write_int(socket->id); - _at.cmd_stop(); + _at.cmd_start_stop("+QISACK", "=", "%d", socket->id); _at.resp_start("+QISACK:"); sent_len_before = _at.read_int(); sent_acked = _at.read_int(); @@ -495,10 +434,7 @@ nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_sendto_impl(CellularSock } } - _at.cmd_start("AT+QISEND="); - _at.write_int(socket->id); - _at.write_int(sent_len); - _at.cmd_stop(); + _at.cmd_start_stop("+QISEND", "=", "%d%d", socket->id, sent_len); _at.resp_start(">"); _at.write_bytes((uint8_t *)data, sent_len); @@ -511,9 +447,7 @@ nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_sendto_impl(CellularSock } if (socket->proto == NSAPI_TCP) { - _at.cmd_start("AT+QISACK="); - _at.write_int(socket->id); - _at.cmd_stop(); + _at.cmd_start_stop("+QISACK", "=", "%d", socket->id); _at.resp_start("+QISACK:"); sent_len_after = _at.read_int(); @@ -556,12 +490,8 @@ nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_recvfrom_impl(CellularSo nsapi_size_t len = 0; for (; len < size;) { unsigned int read_len = (size - len > M26_RECV_BYTE_MAX) ? M26_RECV_BYTE_MAX : size - len; - _at.cmd_start("AT+QIRD="); - _at.write_int(0); /* at+qifgcnt 0-1 */ - _at.write_int(1); /* 1-Client, 2-Server */ - _at.write_int(socket->id); - _at.write_int(read_len); - _at.cmd_stop(); + + _at.cmd_start_stop("+QIRD", "=", "%d%d%d%d", 0, 1, socket->id, read_len); nsapi_size_t recv_len = 0; _at.resp_start("+QIRD:"); diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp index 7c61b6b25b..4fe5a8f518 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularContext.cpp @@ -29,23 +29,16 @@ QUECTEL_UG96_CellularContext::~QUECTEL_UG96_CellularContext() nsapi_error_t QUECTEL_UG96_CellularContext::do_user_authentication() { + nsapi_error_t err = NSAPI_ERROR_OK; if (_pwd && _uname) { - _at.cmd_start("AT+QICSGP="); - _at.write_int(_cid); - _at.write_int(1); // context type 1=IPv4 - _at.write_string(_apn); - _at.write_string(_uname); - _at.write_string(_pwd); - _at.write_int(_authentication_type); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - if (_at.get_last_error() != NSAPI_ERROR_OK) { + err = _at.at_cmd_discard("+QICSGP", "=", "%d%d%s%s%s%d", _cid, 1, _apn, + _uname, _pwd, _authentication_type); + if (err != NSAPI_ERROR_OK) { return NSAPI_ERROR_AUTH_FAILURE; } } - return NSAPI_ERROR_OK; + return err; } } /* namespace mbed */ diff --git a/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT.cpp b/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT.cpp index 9ea0163c2d..4f8c5b9472 100644 --- a/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT.cpp +++ b/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT.cpp @@ -71,18 +71,14 @@ nsapi_error_t RM1000_AT::init() _at->lock(); _at->flush(); - _at->cmd_start("ATE0"); // echo off - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("E0", ""); // echo off - _at->cmd_start("AT+SIM=physical"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+SIM", "=physical"); _at->set_at_timeout(5000); - _at->cmd_start("AT+CFUN=1"); // set full functionality - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+CFUN", "=1"); // set full functionality - _at->cmd_start("AT+VERBOSE=0"); // verbose responses - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+VERBOSE", "=0"); // verbose responses return _at->unlock_return_error(); } diff --git a/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp b/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp index 4068e55d3d..dc202aa8be 100644 --- a/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp +++ b/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp @@ -103,29 +103,17 @@ nsapi_error_t RM1000_AT_CellularStack::create_socket_impl(CellularSocket *socket int sock_id = SOCKET_UNUSED; - _at.lock(); + nsapi_error_t err = NSAPI_ERROR_OK; if (socket->proto == NSAPI_UDP) { - _at.cmd_start("AT+RSOCR=0"); - _at.cmd_stop(); - - _at.resp_start("+RSOCR:"); - sock_id = _at.read_int(); - _at.resp_stop(); + err = _at.at_cmd_int("+RSOCR", "=0", sock_id); } else if (socket->proto == NSAPI_TCP) { - _at.cmd_start("AT+RSOCR=1"); - _at.cmd_stop(); - - _at.resp_start("+RSOCR:"); - sock_id = _at.read_int(); - _at.resp_stop(); + err = _at.at_cmd_int("+RSOCR", "=1", sock_id); } // Unsupported protocol is checked in "is_protocol_supported" function - if ((_at.get_last_error() != NSAPI_ERROR_OK) || (sock_id == -1)) { - _at.unlock(); - tr_error("RM1000_AT_CellularStack::create_socket_impl error sock_id=%d err=%d", sock_id, _at.get_last_error()); + if ((err != NSAPI_ERROR_OK) || (sock_id == -1)) { + tr_error("RM1000_AT_CellularStack::create_socket_impl error sock_id=%d err=%d", sock_id, err); return NSAPI_ERROR_NO_SOCKET; } - _at.unlock(); // Check for duplicate socket id delivered by modem for (int i = 0; i < RM1000_MAX_SOCKET; i++) { @@ -137,7 +125,7 @@ nsapi_error_t RM1000_AT_CellularStack::create_socket_impl(CellularSocket *socket socket->id = sock_id; - return NSAPI_ERROR_OK; + return err; } nsapi_error_t RM1000_AT_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &addr) @@ -258,10 +246,7 @@ nsapi_size_or_error_t RM1000_AT_CellularStack::socket_recvfrom_impl(CellularSock read_blk = size; } if (socket->pending_bytes > 0) { - _at.cmd_start("AT+RSORCV="); - _at.write_int(socket->id); - _at.write_int(read_blk); - _at.cmd_stop(); + _at.cmd_start_stop("+RSORCV", "=", "%d%d", socket->id, read_blk); _at.resp_start("+RSORCV:"); _at.skip_param(); // receiving socket id @@ -323,11 +308,7 @@ nsapi_error_t RM1000_AT_CellularStack::socket_close_impl(int sock_id) { tr_debug("RM1000_AT_CellularStack::socket_close_impl"); - _at.cmd_start("AT+RSOCL="); - _at.write_int(sock_id); - _at.cmd_stop_read_resp(); - - return _at.get_last_error(); + return _at.at_cmd_discard("+RSOCL", "=", "%d", sock_id); } // Clear out the storage for a socket diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 94727678b6..abbfcffd1f 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -55,11 +55,7 @@ nsapi_error_t TELIT_HE910::init() if (err != NSAPI_ERROR_OK) { return err; } - _at->lock(); - _at->cmd_start("AT&K0;&C1;&D0"); - _at->cmd_stop_read_resp(); - - return _at->unlock_return_error(); + return _at->at_cmd_discard("&K0;&C1;&D0", ""); } #if MBED_CONF_TELIT_HE910_PROVIDE_DEFAULT diff --git a/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910.cpp b/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910.cpp index 6c7c7c1483..42bced57fd 100644 --- a/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910.cpp +++ b/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910.cpp @@ -89,11 +89,10 @@ nsapi_error_t TELIT_ME910::init() } _at->lock(); #if defined (MBED_CONF_TELIT_ME910_RTS) && defined (MBED_CONF_TELIT_ME910_CTS) - _at->cmd_start("AT&K3;&C1;&D0"); + _at->at_cmd_discard("&K3;&C1;&D0", ""); #else - _at->cmd_start("AT&K0;&C1;&D0"); + _at->at_cmd_discard("&K0;&C1;&D0", ""); #endif - _at->cmd_stop_read_resp(); // AT#QSS=1 // Enable the Query SIM Status unsolicited indication in the ME. The format of the @@ -104,8 +103,7 @@ nsapi_error_t TELIT_ME910::init() // values: // - 0: SIM not inserted // - 1: SIM inserted - _at->cmd_start("AT#QSS=1"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("#QSS", "=1"); // AT#PSNT=1 // Set command enables unsolicited result code for packet service network type (PSNT) @@ -115,8 +113,7 @@ nsapi_error_t TELIT_ME910::init() // - 0: GPRS network // - 4: LTE network // - 5: unknown or not registered - _at->cmd_start("AT#PSNT=1"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("#PSNT", "=1"); // AT+CMER=2 // Set command enables sending of unsolicited result codes from TA to TE in the case of @@ -124,8 +121,7 @@ nsapi_error_t TELIT_ME910::init() // Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is // reserved (e.g. on-line data mode) and flush them to the TE after // reservation; otherwise forward them directly to the TE - _at->cmd_start("AT+CMER=2"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+CMER", "=2"); // AT+CMEE=2 // Set command disables the use of result code +CME ERROR: as an indication of an @@ -133,16 +129,14 @@ nsapi_error_t TELIT_ME910::init() // ERROR: final result code instead of the default ERROR final result code. ERROR is returned // normally when the error message is related to syntax, invalid parameters or DTE functionality. // Current setting: enable and use verbose values - _at->cmd_start("AT+CMEE=2"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+CMEE", "=2"); // AT&W&P // - AT&W: Execution command stores on profile the complete configuration of the device. If // parameter is omitted, the command has the same behavior of AT&W0. // - AT&P: Execution command defines which full profile will be loaded at startup. If parameter // is omitted, the command has the same behavior as AT&P0 - _at->cmd_start("AT&W&P"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("&W&P", ""); return _at->unlock_return_error(); } diff --git a/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp b/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp index 3de2c11bca..e2fa4119d1 100644 --- a/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp +++ b/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp @@ -36,8 +36,8 @@ bool TELIT_ME910_CellularContext::get_context() { bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_PDP_TYPE); bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_PDP_TYPE); - _at.cmd_start("AT+CGDCONT?"); - _at.cmd_stop(); + + _at.cmd_start_stop("+CGDCONT", "?"); _at.resp_start("+CGDCONT:"); _cid = -1; int cid_max = 0; // needed when creating new context diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index a1194f0f0d..14b3931270 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -94,36 +94,30 @@ nsapi_error_t UBLOX_AT::init() _at->lock(); _at->flush(); - _at->cmd_start("AT"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("", ""); + + nsapi_error_t err = NSAPI_ERROR_OK; #ifdef TARGET_UBLOX_C027 - _at->cmd_start("AT+CFUN=0"); - _at->cmd_stop_read_resp(); - if (_at->get_last_error() == NSAPI_ERROR_OK) { - _at->cmd_start("ATE0"); // echo off - _at->cmd_stop_read_resp(); - _at->cmd_start("AT+CMEE=1"); // verbose responses - _at->cmd_stop_read_resp(); + err = _at->at_cmd_discard("+CFUN", "=0"); + + if (err == NSAPI_ERROR_OK) { + _at->at_cmd_discard("E0", ""); // echo off + _at->at_cmd_discard("+CMEE", "=1"); // verbose responses config_authentication_parameters(); - _at->cmd_start("AT+CFUN=1"); // set full functionality - _at->cmd_stop_read_resp(); + err = _at->at_cmd_discard("+CFUN", "=1"); // set full functionality } #else - _at->cmd_start("AT+CFUN=4"); - _at->cmd_stop_read_resp(); - if (_at->get_last_error() == NSAPI_ERROR_OK) { - _at->cmd_start("ATE0"); // echo off - _at->cmd_stop_read_resp(); - _at->cmd_start("AT+CMEE=1"); // verbose responses - _at->cmd_stop_read_resp(); + err = _at->at_cmd_discard("+CFUN", "=4"); + if (err == NSAPI_ERROR_OK) { + _at->at_cmd_discard("E0", ""); // echo off + _at->at_cmd_discard("+CMEE", "=1"); // verbose responses config_authentication_parameters(); - _at->cmd_start("AT+CFUN=1"); // set full functionality - _at->cmd_stop_read_resp(); + err = _at->at_cmd_discard("+CFUN", "=1"); // set full functionality } #endif - return _at->unlock_return_error(); + return err; } nsapi_error_t UBLOX_AT::config_authentication_parameters() @@ -158,59 +152,27 @@ nsapi_error_t UBLOX_AT::set_authentication_parameters(const char *apn, { int modem_security = ubx_context->nsapi_security_to_modem_security(auth); - _at->cmd_start("AT+CGDCONT=1,\"IP\","); - _at->write_string(apn); - _at->cmd_stop(); - _at->resp_start(); - _at->resp_stop(); + nsapi_error_t err = _at->at_cmd_discard("+CGDCONT", "=", "%d%s%s", 1, "IP", apn); - if (_at->get_last_error() == NSAPI_ERROR_OK) { + if (err == NSAPI_ERROR_OK) { #ifdef TARGET_UBLOX_C030_R41XM if (modem_security == CellularContext::CHAP) { - _at->cmd_start("AT+UAUTHREQ=1,"); - _at->write_int(modem_security); - _at->write_string(password); - _at->write_string(username); - _at->cmd_stop(); - _at->resp_start(); - _at->resp_stop(); + err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, password, username); } else if (modem_security == CellularContext::NOAUTH) { - _at->cmd_start("AT+UAUTHREQ=1,"); - _at->write_int(modem_security); - _at->cmd_stop(); - _at->resp_start(); - _at->resp_stop(); + err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d", 1, modem_security); } else { - _at->cmd_start("AT+UAUTHREQ=1,"); - _at->write_int(modem_security); - _at->write_string(username); - _at->write_string(password); - _at->cmd_stop(); - _at->resp_start(); - _at->resp_stop(); + err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, username, password); } #else - _at->cmd_start("AT+UAUTHREQ=1,"); - _at->write_int(modem_security); - _at->write_string(username); - _at->write_string(password); - _at->cmd_stop(); - _at->resp_start(); - _at->resp_stop(); + err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, username, password); #endif } - return _at->get_last_error(); + return err; } nsapi_error_t UBLOX_AT::get_imsi(char *imsi) { - _at->lock(); - _at->cmd_start("AT+CIMI"); - _at->cmd_stop(); - _at->resp_start(); - _at->read_string(imsi, MAX_IMSI_LENGTH + 1); - _at->resp_stop(); - - return _at->unlock_return_error(); + //Special case: Command put in cmd_chr to make a 1 liner + return _at->at_cmd_str("", "+CIMI", imsi, MAX_IMSI_LENGTH + 1); } diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp index 81fac5d07f..04c049e6fe 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp @@ -62,13 +62,9 @@ void UBLOX_AT_CellularContext::do_connect() if (rat == CellularNetwork::RadioAccessTechnology::RAT_EGPRS) { if (!_is_context_active) { _at.set_at_timeout(150 * 1000); - _at.cmd_start("AT+CGACT=1,1"); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+CGACT", "=", "%d%d", 1, 1); - _at.cmd_start("AT+CGACT?"); - _at.cmd_stop(); + _at.cmd_start_stop("+CGACT", "?"); _at.resp_start("+CGACT:"); _at.skip_param(1); _is_context_activated = _at.read_int(); @@ -117,12 +113,13 @@ nsapi_error_t UBLOX_AT_CellularContext::define_context() return err; } - _at.cmd_start("AT+UPSND=" PROFILE ",8"); - _at.cmd_stop(); + _at.lock(); + _at.cmd_start_stop("+UPSND", "=", "%d%d", PROFILE, 8); _at.resp_start("+UPSND:"); _at.skip_param(2); active = _at.read_int(); _at.resp_stop(); + _at.unlock(); if (active == 0) { // If the caller hasn't entered an APN, try to find it @@ -164,74 +161,47 @@ bool UBLOX_AT_CellularContext::activate_profile(const char *apn, // Set up the APN if (apn) { success = false; - _at.cmd_start("AT+UPSD=" PROFILE ",1,"); - _at.write_string(apn); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - - if (_at.get_last_error() == NSAPI_ERROR_OK) { + if (_at.at_cmd_discard("+UPSD", "=", "%d%d%s", PROFILE, 1, apn) == NSAPI_ERROR_OK) { success = true; } } // Set up the UserName if (success && username) { success = false; - _at.cmd_start("AT+UPSD=" PROFILE ",2,"); - _at.write_string(username); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - - if (_at.get_last_error() == NSAPI_ERROR_OK) { + if (_at.at_cmd_discard("+UPSD", "=", "%d%d%s", PROFILE, 2, username) == NSAPI_ERROR_OK) { success = true; } } // Set up the Password if (success && password) { success = false; - _at.cmd_start("AT+UPSD=" PROFILE ",3,"); - _at.write_string(password); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - - if (_at.get_last_error() == NSAPI_ERROR_OK) { + if (_at.at_cmd_discard("+UPSD", "=", "%d%d%s", PROFILE, 3, password) == NSAPI_ERROR_OK) { success = true; } } if (success) { - _at.cmd_start("AT+UPSD=" PROFILE ",7,\"0.0.0.0\""); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + _at.at_cmd_discard("+UPSD", "=", "%d%d%s", PROFILE, 7, "0.0.0.0"); - _at.cmd_start("AT+UPSD=" PROFILE ",6,"); - _at.write_int(nsapi_security_to_modem_security(auth)); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - - if (_at.get_last_error() == NSAPI_ERROR_OK) { + if (_at.at_cmd_discard("+UPSD", "=", "%d%d%d", PROFILE, 6, nsapi_security_to_modem_security(auth)) == NSAPI_ERROR_OK) { // Activate, wait upto 30 seconds for the connection to be made _at.set_at_timeout(30000); - _at.cmd_start("AT+UPSDA=" PROFILE ",3"); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); + + nsapi_error_t err = _at.at_cmd_discard("+UPSDA", "=", "%d%d", PROFILE, 3); + _at.restore_at_timeout(); - if (_at.get_last_error() == NSAPI_ERROR_OK) { + if (err == NSAPI_ERROR_OK) { Timer t1; t1.start(); while (!(t1.read() >= 180)) { - _at.cmd_start("AT+UPSND=" PROFILE ",8"); - _at.cmd_stop(); + _at.lock(); + _at.cmd_start_stop("+UPSND", "=", "%d%d", PROFILE, 8); _at.resp_start("+UPSND:"); _at.skip_param(2); _at.read_int() ? activated = true : activated = false; _at.resp_stop(); + _at.unlock(); if (activated) { //If context is activated, exit while loop and return status break; @@ -282,27 +252,19 @@ int UBLOX_AT_CellularContext::nsapi_security_to_modem_security(AuthenticationTyp // Disconnect the on board IP stack of the modem. bool UBLOX_AT_CellularContext::disconnect_modem_stack() { - bool success = false; - if (get_ip_address() != NULL) { - _at.cmd_start("AT+UPSDA=" PROFILE ",4"); - _at.cmd_stop(); - _at.resp_start(); - _at.resp_stop(); - - if (_at.get_last_error() == NSAPI_ERROR_OK) { - success = true; + if (_at.at_cmd_discard("+UPSDA", "=", "%d%d", PROFILE, 4) == NSAPI_ERROR_OK) { + return true; } } - return success; + return false; } nsapi_error_t UBLOX_AT_CellularContext::get_imsi(char *imsi) { _at.lock(); - _at.cmd_start("AT+CIMI"); - _at.cmd_stop(); + _at.cmd_start_stop("+CIMI", ""); _at.resp_start(); _at.read_string(imsi, MAX_IMSI_LENGTH + 1); _at.resp_stop(); @@ -351,11 +313,7 @@ CellularNetwork::RadioAccessTechnology UBLOX_AT_CellularContext::read_radio_tech int act; CellularNetwork::RadioAccessTechnology rat; - _at.cmd_start("AT+URAT?"); - _at.cmd_stop(); - _at.resp_start("+URAT:"); - act = _at.read_int(); - _at.resp_stop(); + _at.at_cmd_int("+URAT", "?", act); switch (act) { case 0: diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp index 986a5d5dc6..18ddee7f73 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp @@ -46,30 +46,25 @@ nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTe switch (opRat) { case RAT_EGPRS: #if defined (TARGET_UBLOX_C030_R412M) - _at.cmd_start("AT+URAT=9,8"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("+URAT", "=", "%d%d", 9, 8); break; #endif #if defined(TARGET_UBLOX_C030_U201) case RAT_GSM: - _at.cmd_start("AT+URAT=0,0"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("+URAT", "=", "%d%d", 0, 0); break; case RAT_UTRAN: case RAT_HSDPA: case RAT_HSUPA: case RAT_HSDPA_HSUPA: - _at.cmd_start("AT+URAT=2,2"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("+URAT", "=", "%d%d", 2, 2); break; #elif defined(TARGET_UBLOX_C030_R41XM) case RAT_CATM1: - _at.cmd_start("AT+URAT=7,8"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("+URAT", "=", "%d%d", 7, 8); break; case RAT_NB1: - _at.cmd_start("AT+URAT=8,7"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("+URAT", "=", "%d%d", 8, 7); break; #endif default: @@ -86,22 +81,22 @@ nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTe nsapi_error_t UBLOX_AT_CellularNetwork::ubx_reboot() { _at.lock(); - _at.cmd_start("AT+CFUN=15"); - _at.cmd_stop_read_resp(); + _at.at_cmd_discard("+CFUN", "=15"); + nsapi_error_t err = NSAPI_ERROR_OK; Timer t1; t1.start(); while (!(t1.read() >= 30)) { - _at.cmd_start("ATE0"); // echo off - _at.cmd_stop_read_resp(); - if (_at.get_last_error() == NSAPI_ERROR_OK) { + err = _at.at_cmd_discard("E0", ""); + if (err == NSAPI_ERROR_OK) { break; } else { + //Don't clear err here so that we get some error in case of failure _at.clear_error(); wait_ms(1000); } } t1.stop(); _at.unlock(); - return _at.get_last_error(); + return err; } diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp index e1fab7e540..848fbb5b1d 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp @@ -122,28 +122,16 @@ nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket) { int sock_id = SOCKET_UNUSED; - _at.lock(); + nsapi_error_t err = NSAPI_ERROR_OK; if (socket->proto == NSAPI_UDP) { - _at.cmd_start("AT+USOCR=17"); - _at.cmd_stop(); - - _at.resp_start("+USOCR:"); - sock_id = _at.read_int(); - _at.resp_stop(); + err = _at.at_cmd_int("+USOCR", "=17", sock_id); } else if (socket->proto == NSAPI_TCP) { - _at.cmd_start("AT+USOCR=6"); - _at.cmd_stop(); - - _at.resp_start("+USOCR:"); - sock_id = _at.read_int(); - _at.resp_stop(); + err = _at.at_cmd_int("+USOCR", "=6", sock_id); } // Unsupported protocol is checked in "is_protocol_supported" function - if ((_at.get_last_error() != NSAPI_ERROR_OK) || (sock_id == -1)) { - _at.unlock(); + if ((err != NSAPI_ERROR_OK) || (sock_id == -1)) { return NSAPI_ERROR_NO_SOCKET; } - _at.unlock(); // Check for duplicate socket id delivered by modem for (int i = 0; i < UBLOX_MAX_SOCKET; i++) { @@ -156,7 +144,7 @@ nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket) socket->started = true; socket->id = sock_id; - return NSAPI_ERROR_OK; + return err; } nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &addr) @@ -174,14 +162,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons return NSAPI_ERROR_DEVICE_ERROR; } - _at.lock(); - _at.cmd_start("AT+USOCO="); - _at.write_int(socket->id); - _at.write_string(addr.get_ip_address()); - _at.write_int(addr.get_port()); - _at.cmd_stop_read_resp(); - nsapi_error_t err = _at.get_last_error(); - _at.unlock(); + nsapi_error_t err = _at.at_cmd_discard("+USOCO", "=", "%d%s%d", socket->id, addr.get_ip_address(), addr.get_port()); if (err == NSAPI_ERROR_OK) { socket->remoteAddress = addr; @@ -206,12 +187,8 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket if (size > UBLOX_MAX_PACKET_SIZE) { return NSAPI_ERROR_PARAMETER; } - _at.cmd_start("AT+USOST="); - _at.write_int(socket->id); - _at.write_string(address.get_ip_address()); - _at.write_int(address.get_port()); - _at.write_int(size); - _at.cmd_stop(); + _at.cmd_start_stop("+USOST", "=", "%d%s%d%d", socket->id, address.get_ip_address(), address.get_port(), size); + (void)poll(&fhs, 1, 50); _at.write_bytes((uint8_t *)data, size); @@ -233,10 +210,8 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket if (count < blk) { blk = count; } - _at.cmd_start("AT+USOWR="); - _at.write_int(socket->id); - _at.write_int(blk); - _at.cmd_stop(); + _at.cmd_start_stop("+USOWR", "=", "%d%d", socket->id, blk); + (void)poll(&fhs, 1, 50); _at.write_bytes((uint8_t *)buf, blk); @@ -293,10 +268,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke read_blk = size; } if (socket->pending_bytes > 0) { - _at.cmd_start("AT+USORF="); - _at.write_int(socket->id); - _at.write_int(read_blk); - _at.cmd_stop(); + _at.cmd_start_stop("+USORF", "=", "%d%d", socket->id, read_blk); _at.resp_start("+USORF:"); _at.skip_param(); // receiving socket id @@ -343,10 +315,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke read_blk = size; } if (socket->pending_bytes > 0) { - _at.cmd_start("AT+USORD="); - _at.write_int(socket->id); - _at.write_int(read_blk); - _at.cmd_stop(); + _at.cmd_start_stop("+USORD", "=", "%d%d", socket->id, read_blk); _at.resp_start("+USORD:"); _at.skip_param(); // receiving socket id @@ -405,12 +374,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke nsapi_error_t UBLOX_AT_CellularStack::socket_close_impl(int sock_id) { - _at.lock(); - _at.cmd_start("AT+USOCL="); - _at.write_int(sock_id); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); + return _at.at_cmd_discard("+USOCL", "=", "%d", sock_id); } // Find or create a socket from the list. @@ -448,8 +412,7 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket) const char *UBLOX_AT_CellularStack::get_ip_address() { _at.lock(); - _at.cmd_start("AT+UPSND=" PROFILE ",0"); - _at.cmd_stop(); + _at.cmd_start_stop("+UPSND", "=", "%d%d", PROFILE, 0); _at.resp_start("+UPSND:"); if (_at.info_resp()) { @@ -487,9 +450,7 @@ nsapi_error_t UBLOX_AT_CellularStack::gethostbyname(const char *host, SocketAddr err = NSAPI_ERROR_OK; } else { // This interrogation can sometimes take longer than the usual 8 seconds - _at.cmd_start("AT+UDNSRN=0,"); - _at.write_string(host); - _at.cmd_stop(); + _at.cmd_start_stop("+UDNSRN", "=0,", "%s", host); #ifdef TARGET_UBLOX_C030_R41XM _at.set_at_timeout(70000); #else diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.h index e7da23100b..1614fc7602 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.h @@ -45,7 +45,7 @@ protected: // AT_CellularStack /** The profile to use (on board the modem). */ -#define PROFILE "0" +#define PROFILE 0 /** Socket "unused" value. */ diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp index fe3bc84df8..f7a0f6eef2 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp @@ -74,11 +74,9 @@ nsapi_error_t UBLOX_N2XX::init() _at->lock(); _at->flush(); - _at->cmd_start("AT"); - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("", ""); - _at->cmd_start("AT+CMEE=1"); // verbose responses - _at->cmd_stop_read_resp(); + _at->at_cmd_discard("+CMEE", "=1"); // verbose responses #ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN set_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN); @@ -92,12 +90,8 @@ nsapi_error_t UBLOX_N2XX::get_sim_state(SimState &state) _at->lock(); _at->flush(); - _at->cmd_start("AT+CFUN=1"); - _at->cmd_stop(); - - _at->resp_start(); - _at->read_string(simstr, sizeof(simstr)); - _at->resp_stop(); + //Special case: Command put in cmd_chr to make a 1 liner + _at->at_cmd_str("", "+CFUN=1", simstr, sizeof(simstr)); error = _at->unlock_return_error(); int len = strlen(simstr); @@ -149,11 +143,7 @@ nsapi_error_t UBLOX_N2XX::set_pin(const char *sim_pin) return NSAPI_ERROR_PARAMETER; } - _at->lock(); - _at->cmd_start("AT+NPIN=0,"); - _at->write_string(sim_pin); - _at->cmd_stop_read_resp(); - return _at->unlock_return_error(); + return _at->at_cmd_discard("+NPIN", "=", "%d%s", 0, sim_pin); } #if MBED_CONF_UBLOX_N2XX_PROVIDE_DEFAULT diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp index 876b8f3c1b..b11c1ecefb 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp @@ -84,10 +84,7 @@ nsapi_error_t UBLOX_N2XX_CellularStack::create_socket_impl(CellularSocket *socke } _at.lock(); - _at.cmd_start("AT+NSOCR=\"DGRAM\",17,"); - _at.write_int(localport); - _at.write_int(1); - _at.cmd_stop(); + _at.cmd_start_stop("+NSOCR", "=", "%s%d%d%d", "DGRAM", 17, localport, 1); _at.resp_start(); sock_id = _at.read_int(); @@ -129,13 +126,8 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_sendto_impl(CellularSocke } char_str_to_hex_str((const char *)data, size, dataStr); - _at.cmd_start("AT+NSOST="); - _at.write_int(socket->id); - _at.write_string(address.get_ip_address()); - _at.write_int(address.get_port()); - _at.write_int(size); - _at.write_string(dataStr); - _at.cmd_stop(); + _at.cmd_start_stop("+NSOST", "=", "%d%s%d%d%s", socket->id, address.get_ip_address(), + address.get_port(), size, dataStr); _at.resp_start(); _at.skip_param(); // skip socket id @@ -176,10 +168,7 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc read_blk = length; } if (socket->pending_bytes > 0) { - _at.cmd_start("AT+NSORF="); - _at.write_int(socket->id); - _at.write_int(read_blk); - _at.cmd_stop(); + _at.cmd_start_stop("+NSORF", "=", "%d%d", socket->id, read_blk); _at.resp_start(); _at.skip_param(); // receiving socket id @@ -237,10 +226,5 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc nsapi_error_t UBLOX_N2XX_CellularStack::socket_close_impl(int sock_id) { - _at.lock(); - _at.cmd_start("AT+NSOCL="); - _at.write_int(sock_id); - _at.cmd_stop_read_resp(); - - return _at.unlock_return_error(); + return _at.at_cmd_discard("+NSOCL", "=", "%d", sock_id); }