Skip to content

Cellular: Added write_hex_string to AT handler #11754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions features/cellular/framework/AT/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,3 +1597,18 @@ void ATHandler::set_send_delay(uint16_t 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);
}
}
8 changes: 8 additions & 0 deletions features/cellular/framework/AT/ATHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ class ATHandler {
*/
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.
*
* @return the non-negative integer or -1 in case of error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
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) {
_at.cmd_start("AT+NSOST=");
_at.write_int(socket->id);
Expand All @@ -201,20 +196,17 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
_at.write_int(socket->id);
_at.write_int(size);
} else {
delete [] hexstr;
return NSAPI_ERROR_PARAMETER;
}

_at.write_string(hexstr, false);
_at.write_hex_string((char *)data, size);
_at.cmd_stop();
_at.resp_start();
// skip socket id
_at.skip_param();
sent_len = _at.read_int();
_at.resp_stop();

delete [] hexstr;

if (_at.get_last_error() == NSAPI_ERROR_OK) {
return sent_len;
}
Expand Down