From 14f8d15242dce94dd982a8f83601e34abb2c1fb9 Mon Sep 17 00:00:00 2001 From: Marcin Radomski Date: Fri, 16 Aug 2019 12:24:54 +0200 Subject: [PATCH 1/3] Add option to set up SMS encoding --- features/cellular/framework/API/CellularSMS.h | 8 +++++++- features/cellular/framework/AT/AT_CellularSMS.cpp | 5 ++++- features/cellular/framework/AT/AT_CellularSMS.h | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/features/cellular/framework/API/CellularSMS.h b/features/cellular/framework/API/CellularSMS.h index 54d2afc2c4..22da301b1f 100644 --- a/features/cellular/framework/API/CellularSMS.h +++ b/features/cellular/framework/API/CellularSMS.h @@ -62,6 +62,11 @@ public: CellularSMSMmodeText }; + enum CellularSMSEncoding { + CellularSMSEncoding7Bit, + CellularSMSEncoding8Bit, + }; + /** Does all the necessary initializations needed for receiving and sending SMS. * * @param mode enumeration for choosing the correct mode: text/pdu @@ -69,7 +74,8 @@ public: * NSAPI_ERROR_NO_MEMORY on memory failure * NSAPI_ERROR_DEVICE_ERROR on other failures */ - virtual nsapi_error_t initialize(CellularSMSMmode mode) = 0; + virtual nsapi_error_t initialize(CellularSMSMmode mode, + CellularSMSEncoding encoding = CellularSMSEncoding::CellularSMSEncoding7Bit) = 0; /** Send the SMS with the given parameters * diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index b0b0187982..4fa1dd4062 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -245,8 +245,11 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header) return _at.at_cmd_discard("+CSDH", "=", "%d", show_header); } -nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode) +nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode, + CellularSMSEncoding encoding) { + _use_8bit_encoding = (encoding == CellularSMSEncoding8Bit); + _at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)); _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc)); diff --git a/features/cellular/framework/AT/AT_CellularSMS.h b/features/cellular/framework/AT/AT_CellularSMS.h index 04501b279a..c0e19ac7b5 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.h +++ b/features/cellular/framework/AT/AT_CellularSMS.h @@ -39,7 +39,8 @@ public: public: // from CellularSMS - virtual nsapi_error_t initialize(CellularSMSMmode mode); + virtual nsapi_error_t initialize(CellularSMSMmode mode, + CellularSMSEncoding encoding = CellularSMSEncoding7Bit); virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len); From cd7e6c9708334fb5834c53e33b30e6f764646a0b Mon Sep 17 00:00:00 2001 From: Marcin Radomski Date: Fri, 16 Aug 2019 12:32:04 +0200 Subject: [PATCH 2/3] Adjust AT_CellularSMS_stub API --- UNITTESTS/stubs/AT_CellularSMS_stub.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UNITTESTS/stubs/AT_CellularSMS_stub.cpp b/UNITTESTS/stubs/AT_CellularSMS_stub.cpp index c43d4b2c82..e69ab3aa88 100644 --- a/UNITTESTS/stubs/AT_CellularSMS_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularSMS_stub.cpp @@ -71,7 +71,8 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header) return NSAPI_ERROR_OK; } -nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode) +nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode, + CellularSMSEncoding encoding) { return NSAPI_ERROR_OK; } From f3e9501ac6c3a179bd0dff9e2ac4d49e545d8062 Mon Sep 17 00:00:00 2001 From: Marcin Radomski Date: Tue, 13 Aug 2019 17:08:33 +0200 Subject: [PATCH 3/3] Increase PDU buffer size to fit 8-bit-encoded hex string --- features/cellular/framework/AT/AT_CellularSMS.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index 4fa1dd4062..f55a978a32 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -291,8 +291,11 @@ char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message, // there might be need for padding so some more space totalPDULength += 2; - // message 7-bit padded and it will be converted to hex so it will take twice as much space - totalPDULength += (message_length - (message_length / 8)) * 2; + // 8-bit message, converted to hex so it will take twice as much space + totalPDULength += message_length * 2; + + // terminating nullbyte, because callers use strlen() to find out PDU size + totalPDULength += 1; char *pdu = new char[totalPDULength]; memset(pdu, 0, totalPDULength);