File tree Expand file tree Collapse file tree 3 files changed +24
-9
lines changed
features/cellular/framework Expand file tree Collapse file tree 3 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -1597,3 +1597,18 @@ void ATHandler::set_send_delay(uint16_t send_delay)
1597
1597
{
1598
1598
_at_send_delay = send_delay;
1599
1599
}
1600
+
1601
+ void ATHandler::write_hex_string (char *str, size_t size)
1602
+ {
1603
+ // do common checks before sending subparameter
1604
+ if (check_cmd_send () == false ) {
1605
+ return ;
1606
+ }
1607
+
1608
+ char hexbuf[2 ];
1609
+ for (int i = 0 ; i < size; i++) {
1610
+ hexbuf[0 ] = hex_values[((str[i]) >> 4 ) & 0x0F ];
1611
+ hexbuf[1 ] = hex_values[(str[i]) & 0x0F ];
1612
+ write (hexbuf, 2 );
1613
+ }
1614
+ }
Original file line number Diff line number Diff line change @@ -419,6 +419,14 @@ class ATHandler {
419
419
*/
420
420
ssize_t read_hex_string (char *str, size_t size);
421
421
422
+ /* * Converts contained chars to their hex ascii value and writes the resulting string to the file handle
423
+ * For example: "AV" to "4156".
424
+ *
425
+ * @param str input buffer to be converted to hex ascii
426
+ * @param size of the input param str
427
+ */
428
+ void write_hex_string (char *str, size_t size);
429
+
422
430
/* * Reads as string and converts result to integer. Supports only non-negative integers.
423
431
*
424
432
* @return the non-negative integer or -1 in case of error.
Original file line number Diff line number Diff line change @@ -185,11 +185,6 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
185
185
return NSAPI_ERROR_PARAMETER;
186
186
}
187
187
188
- char *hexstr = new char [size * 2 + 1 ];
189
- int hexlen = char_str_to_hex_str ((const char *)data, size, hexstr);
190
- // NULL terminated for write_string
191
- hexstr[hexlen] = 0 ;
192
-
193
188
if (socket->proto == NSAPI_UDP) {
194
189
_at.cmd_start (" AT+NSOST=" );
195
190
_at.write_int (socket->id );
@@ -201,20 +196,17 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
201
196
_at.write_int (socket->id );
202
197
_at.write_int (size);
203
198
} else {
204
- delete [] hexstr;
205
199
return NSAPI_ERROR_PARAMETER;
206
200
}
207
201
208
- _at.write_string (hexstr, false );
202
+ _at.write_hex_string (( char *)data, size );
209
203
_at.cmd_stop ();
210
204
_at.resp_start ();
211
205
// skip socket id
212
206
_at.skip_param ();
213
207
sent_len = _at.read_int ();
214
208
_at.resp_stop ();
215
209
216
- delete [] hexstr;
217
-
218
210
if (_at.get_last_error () == NSAPI_ERROR_OK) {
219
211
return sent_len;
220
212
}
You can’t perform that action at this time.
0 commit comments