mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Added write_hex_string to AT handler
parent
262a62a375
commit
beeccbe52c
|
@ -1597,3 +1597,18 @@ void ATHandler::set_send_delay(uint16_t send_delay)
|
||||||
{
|
{
|
||||||
_at_send_delay = send_delay;
|
_at_send_delay = send_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ATHandler::write_hex_string(char *str, size_t size)
|
||||||
|
{
|
||||||
|
// do common checks before sending subparameter
|
||||||
|
if (check_cmd_send() == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char hexbuf[2];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
hexbuf[0] = hex_values[((str[i]) >> 4) & 0x0F];
|
||||||
|
hexbuf[1] = hex_values[(str[i]) & 0x0F];
|
||||||
|
write(hexbuf, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -419,6 +419,14 @@ public:
|
||||||
*/
|
*/
|
||||||
ssize_t read_hex_string(char *str, size_t size);
|
ssize_t read_hex_string(char *str, size_t size);
|
||||||
|
|
||||||
|
/** Converts contained chars to their hex ascii value and writes the resulting string to the file handle
|
||||||
|
* For example: "AV" to "4156".
|
||||||
|
*
|
||||||
|
* @param str input buffer to be converted to hex ascii
|
||||||
|
* @param size of the input param str
|
||||||
|
*/
|
||||||
|
void write_hex_string(char *str, size_t size);
|
||||||
|
|
||||||
/** 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.
|
||||||
*
|
*
|
||||||
* @return the non-negative integer or -1 in case of error.
|
* @return the non-negative integer or -1 in case of error.
|
||||||
|
|
|
@ -185,11 +185,6 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
|
||||||
return NSAPI_ERROR_PARAMETER;
|
return NSAPI_ERROR_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *hexstr = new char[size * 2 + 1];
|
|
||||||
int hexlen = char_str_to_hex_str((const char *)data, size, hexstr);
|
|
||||||
// NULL terminated for write_string
|
|
||||||
hexstr[hexlen] = 0;
|
|
||||||
|
|
||||||
if (socket->proto == NSAPI_UDP) {
|
if (socket->proto == NSAPI_UDP) {
|
||||||
_at.cmd_start("AT+NSOST=");
|
_at.cmd_start("AT+NSOST=");
|
||||||
_at.write_int(socket->id);
|
_at.write_int(socket->id);
|
||||||
|
@ -201,11 +196,10 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
|
||||||
_at.write_int(socket->id);
|
_at.write_int(socket->id);
|
||||||
_at.write_int(size);
|
_at.write_int(size);
|
||||||
} else {
|
} else {
|
||||||
delete [] hexstr;
|
|
||||||
return NSAPI_ERROR_PARAMETER;
|
return NSAPI_ERROR_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
_at.write_string(hexstr, false);
|
_at.write_hex_string((char *)data, size);
|
||||||
_at.cmd_stop();
|
_at.cmd_stop();
|
||||||
_at.resp_start();
|
_at.resp_start();
|
||||||
// skip socket id
|
// skip socket id
|
||||||
|
@ -213,8 +207,6 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
|
||||||
sent_len = _at.read_int();
|
sent_len = _at.read_int();
|
||||||
_at.resp_stop();
|
_at.resp_stop();
|
||||||
|
|
||||||
delete [] hexstr;
|
|
||||||
|
|
||||||
if (_at.get_last_error() == NSAPI_ERROR_OK) {
|
if (_at.get_last_error() == NSAPI_ERROR_OK) {
|
||||||
return sent_len;
|
return sent_len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue