ublox-at-cellular-interface-n2xx
Diff: UbloxATCellularInterfaceN2xx.cpp
- Revision:
- 9:f6d022f5c4f5
- Parent:
- 6:658419981430
- Child:
- 10:08c5a69437ac
--- a/UbloxATCellularInterfaceN2xx.cpp Wed Sep 13 15:57:06 2017 +0100 +++ b/UbloxATCellularInterfaceN2xx.cpp Thu Sep 28 15:18:00 2017 +0100 @@ -180,7 +180,7 @@ socket = find_socket(); if (socket != NULL) { tr_debug("socket_open(%d)", proto); - if (_at->send("AT+NSOCR=DGRAM,17,%d", _localListenPort) && + if (_at->send("AT+NSOCR=\"DGRAM\",17,%d", _localListenPort) && _at->recv("%d\n", &modem_handle) && _at->recv("OK")) { tr_debug("Socket 0x%8x: handle %d was created", (unsigned int) socket, modem_handle); @@ -310,8 +310,6 @@ bin_to_hex(buf, size, dataStr); tr_debug("Got hex string"); - - // AT+NSOSTF= socket, remote_addr, remote_port, length, data tr_debug("Writing AT+NSOSTF=<sktid>,<ipaddr>,<port>,<flags>,<size>,<hex string> command..."); char *cmdStr = (char *) malloc(50); @@ -320,7 +318,7 @@ return NSAPI_ERROR_NO_MEMORY; } - int cmdsize = sprintf(cmdStr, "AT+NSOSTF=%d,%s,%d,0x0,%d,", socket->modem_handle, address.get_ip_address(), address.get_port(), size); + int cmdsize = sprintf(cmdStr, "AT+NSOSTF=%d,\"%s\",%d,0x0,%d,\"", socket->modem_handle, address.get_ip_address(), address.get_port(), size); tr_debug("%s", cmdStr); LOCK(); @@ -366,8 +364,13 @@ // if we are at the end of the line, use the send command to // provide the \r\n terminator for the AT command if (*cmd == '\0') { - tr_debug("send(%d): %s", i, buff); - if (!_at->send(buff)) + tr_debug("send(%d): %s", i, buff); + // write the last buffer... + if (!_at->write(buff,i)) + return false; + + // ...send the enclosing quote to complete the AT command + if (!_at->send("\"")) return false; } else { tr_debug("write(50): %s", buff); @@ -453,7 +456,7 @@ memcpy(buf, tmpBuf, nsapi_error_size); if (read_blk != (uint) nsapi_error_size) - tr_error("Requested size is not the same as the returned size!"); + tr_debug("Requested size is not the same as the returned size."); socket->pending -= nsapi_error_size; count += nsapi_error_size; @@ -526,20 +529,23 @@ unsigned int id, port; // ReadFrom header, to get length - if no data then this will time out - if (_at->recv("%d,%15[^,],%d,%d,", &id, ipAddress, &port, &size)) { + if (_at->recv("%d,\"%15[^\"]\",%d,%d,", &id, ipAddress, &port, &size)) { tr_debug("Socket RecvFrom: #%d: %d", id, size); address->set_ip_address(ipAddress); address->set_port(port); + // read the beginning quote for this data + _at->read(tmpBuf, 1); + // now read hex data if (_at->read(tmpBuf, size*2) == size*2) { // convert to bytes hex_to_bin(tmpBuf, buf, size); - // read the "remaining" value - if (!_at->recv(",%d\n", &remaining)) { + // read the "remaining" value - remembing there is an enclosing quote at the beginning of this read + if (!_at->recv("\",%d\n", &remaining)) { tr_error("Failed reading the 'remaining' value after the received data."); size = NSAPI_ERROR_DEVICE_ERROR; }