From 273590f615133c54d786c8a1e8855dabc7775916 Mon Sep 17 00:00:00 2001 From: Mirela Chirica Date: Mon, 15 Oct 2018 10:40:43 +0300 Subject: [PATCH] Cellular: Added ATHandler option to write parameters without delimiters --- features/cellular/framework/AT/ATHandler.cpp | 11 +++++++++++ features/cellular/framework/AT/ATHandler.h | 7 +++++++ features/cellular/framework/AT/AT_CellularNetwork.cpp | 8 +++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index 4d1e4b0866..be45c51a4c 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -81,6 +81,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char _max_resp_length(MAX_RESP_LENGTH), _debug_on(MBED_CONF_CELLULAR_DEBUG_AT), _cmd_start(false), + _use_delimiter(true), _start_time(0) { clear_error(); @@ -612,6 +613,11 @@ void ATHandler::set_default_delimiter() _delimiter = DEFAULT_DELIMITER; } +void ATHandler::use_delimiter(bool use_delimiter) +{ + _use_delimiter = use_delimiter; +} + void ATHandler::set_tag(tag_t *tag_dst, const char *tag_seq) { if (tag_seq) { @@ -1147,6 +1153,11 @@ bool ATHandler::check_cmd_send() return false; } + // Don't write delimiter if flag was set so + if (!_use_delimiter) { + return true; + } + // Don't write delimiter if this is the first subparameter if (_cmd_start) { _cmd_start = false; diff --git a/features/cellular/framework/AT/ATHandler.h b/features/cellular/framework/AT/ATHandler.h index 8c5713d166..1e9952a4f7 100644 --- a/features/cellular/framework/AT/ATHandler.h +++ b/features/cellular/framework/AT/ATHandler.h @@ -281,6 +281,12 @@ public: */ void set_default_delimiter(); + /** Defines behaviour for using or ignoring the delimiter within an AT command + * + * @param use_delimiter indicating if delimiter should be used or not + */ + void use_delimiter(bool use_delimiter); + /** Consumes the reading buffer up to the delimiter or stop_tag * * @param count number of parameters to be skipped @@ -435,6 +441,7 @@ private: char _info_resp_prefix[BUFF_SIZE]; bool _debug_on; bool _cmd_start; + bool _use_delimiter; // time when a command or an URC processing was started uint64_t _start_time; diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index c99c6eaa79..527589a04d 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -386,9 +386,11 @@ nsapi_error_t AT_CellularNetwork::open_data_channel() _at.write_int(_cid); } else { MBED_ASSERT(_cid >= 0 && _cid <= 99); - char cmd_buf[sizeof("ATD*99***xx#")]; - std::sprintf(cmd_buf, "ATD*99***%d#", _cid); - _at.cmd_start(cmd_buf); + _at.cmd_start("ATD*99***"); + _at.use_delimiter(false); + _at.write_int(_cid); + _at.write_string("#", false); + _at.use_delimiter(true); } _at.cmd_stop();