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)
15971597{
15981598 _at_send_delay = send_delay;
15991599}
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 {
419419 */
420420 ssize_t read_hex_string (char *str, size_t size);
421421
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+
422430 /* * Reads as string and converts result to integer. Supports only non-negative integers.
423431 *
424432 * @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
185185 return NSAPI_ERROR_PARAMETER;
186186 }
187187
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-
193188 if (socket->proto == NSAPI_UDP) {
194189 _at.cmd_start (" AT+NSOST=" );
195190 _at.write_int (socket->id );
@@ -201,20 +196,17 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
201196 _at.write_int (socket->id );
202197 _at.write_int (size);
203198 } else {
204- delete [] hexstr;
205199 return NSAPI_ERROR_PARAMETER;
206200 }
207201
208- _at.write_string (hexstr, false );
202+ _at.write_hex_string (( char *)data, size );
209203 _at.cmd_stop ();
210204 _at.resp_start ();
211205 // skip socket id
212206 _at.skip_param ();
213207 sent_len = _at.read_int ();
214208 _at.resp_stop ();
215209
216- delete [] hexstr;
217-
218210 if (_at.get_last_error () == NSAPI_ERROR_OK) {
219211 return sent_len;
220212 }
You can’t perform that action at this time.
0 commit comments