AT command fix - hex string shouldn't be quoted on bc95

pull/14922/head
Paul Szczepanek 2021-07-14 21:43:53 +01:00
parent d147abc3e5
commit a8982ca06e
3 changed files with 10 additions and 5 deletions

View File

@ -352,8 +352,9 @@ public:
* *
* @param str input buffer to be converted to hex ascii * @param str input buffer to be converted to hex ascii
* @param size of the input param str * @param size of the input param str
* @param quote_string if true it will add the double-quote character at beginning and end of string
*/ */
void write_hex_string(const char *str, size_t size); void write_hex_string(const char *str, size_t size, bool quote_string = true);
/** Reads as string and converts result to integer. Supports only non-negative integers. /** Reads as string and converts result to integer. Supports only non-negative integers.
* *

View File

@ -1551,21 +1551,25 @@ void ATHandler::set_send_delay(uint16_t send_delay)
_at_send_delay = std::chrono::duration<uint16_t, std::milli>(send_delay); _at_send_delay = std::chrono::duration<uint16_t, std::milli>(send_delay);
} }
void ATHandler::write_hex_string(const char *str, size_t size) void ATHandler::write_hex_string(const char *str, size_t size, bool quote_string)
{ {
// do common checks before sending subparameter // do common checks before sending subparameter
if (check_cmd_send() == false) { if (check_cmd_send() == false) {
return; return;
} }
(void) write("\"", 1); if (quote_string) {
(void) write("\"", 1);
}
char hexbuf[2]; char hexbuf[2];
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
hexbuf[0] = hex_values[((str[i]) >> 4) & 0x0F]; hexbuf[0] = hex_values[((str[i]) >> 4) & 0x0F];
hexbuf[1] = hex_values[(str[i]) & 0x0F]; hexbuf[1] = hex_values[(str[i]) & 0x0F];
write(hexbuf, 2); write(hexbuf, 2);
} }
(void) write("\"", 1); if (quote_string) {
(void) write("\"", 1);
}
} }
void ATHandler::set_baud(int baud_rate) void ATHandler::set_baud(int baud_rate)

View File

@ -211,7 +211,7 @@ retry_send:
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
_at.write_hex_string((char *)data, size); _at.write_hex_string((char *)data, size, false);
_at.cmd_stop(); _at.cmd_stop();
_at.resp_start(); _at.resp_start();
// skip socket id // skip socket id