From b67ae60414ad3e482b5ea31f8e2de011fb817242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-=C3=85ke=20Larsson?= Date: Sat, 5 Dec 2020 10:27:02 +0100 Subject: [PATCH 1/4] Add a choice of what messages to preserve to clear() --- src/NB_SMS.cpp | 6 ++++-- src/NB_SMS.h | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/NB_SMS.cpp b/src/NB_SMS.cpp index 85c391f..55b6709 100644 --- a/src/NB_SMS.cpp +++ b/src/NB_SMS.cpp @@ -436,13 +436,15 @@ void NB_SMS::flush() } } -void NB_SMS::clear() +void NB_SMS::clear(int flag) { _ptrUTF8 = ""; while (MODEM.ready() == 0); - MODEM.sendf("AT+CMGD=0,2"); + if (flag<1 || flag>4) flag = 2; + + MODEM.sendf("AT+CMGD=0,%d",flag); if (_synch) { MODEM.waitForResponse(55000); diff --git a/src/NB_SMS.h b/src/NB_SMS.h index 26b85ae..1ba776b 100644 --- a/src/NB_SMS.h +++ b/src/NB_SMS.h @@ -85,8 +85,12 @@ class NB_SMS : public Stream { void flush(); /** Delete all read and sent SMS from Modem memory and process answer + * flag=1 preserves sent, unsent, and unread messages + * flag=2 preserves unsent and unread messages + * flag=3 preserves unread messages + * flag=4 preserves no messages */ - void clear(); + void clear(int flag=2); private: bool _synch; From f221527ed861addea41f2cbf13eadf3ab8f08d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-=C3=85ke=20Larsson?= Date: Wed, 9 Dec 2020 10:43:05 +0100 Subject: [PATCH 2/4] Add labels for the possible flag values --- src/NB_SMS.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/NB_SMS.h b/src/NB_SMS.h index 1ba776b..2bb9702 100644 --- a/src/NB_SMS.h +++ b/src/NB_SMS.h @@ -84,13 +84,12 @@ class NB_SMS : public Stream { */ void flush(); - /** Delete all read and sent SMS from Modem memory and process answer - * flag=1 preserves sent, unsent, and unread messages - * flag=2 preserves unsent and unread messages - * flag=3 preserves unread messages - * flag=4 preserves no messages - */ - void clear(int flag=2); + /** Delete all read and sent SMS from Modem memory and process answer */ +#define NB_SMS_CLEAR_READ 1 +#define NB_SMS_CLEAR_READ_SENT 2 +#define NB_SMS_CLEAR_READ_SENT_UNSENT 3 +#define NB_SMS_CLEAR_ALL 4 + void clear(int flag=NB_SMS_CLEAR_READ_SENT); private: bool _synch; From 7bb6f434ebd180061d2690ecc7eaefb259b8647d Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 9 Dec 2020 12:57:50 +0100 Subject: [PATCH 3/4] Moving defines up to top of file and adding bracelets around constants (good programming practice) --- src/NB_SMS.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/NB_SMS.h b/src/NB_SMS.h index 2bb9702..b77b88e 100644 --- a/src/NB_SMS.h +++ b/src/NB_SMS.h @@ -22,6 +22,11 @@ #include +#define NB_SMS_CLEAR_READ (1) +#define NB_SMS_CLEAR_READ_SENT (2) +#define NB_SMS_CLEAR_READ_SENT_UNSENT (3) +#define NB_SMS_CLEAR_ALL (4) + class NB_SMS : public Stream { public: @@ -85,11 +90,7 @@ class NB_SMS : public Stream { void flush(); /** Delete all read and sent SMS from Modem memory and process answer */ -#define NB_SMS_CLEAR_READ 1 -#define NB_SMS_CLEAR_READ_SENT 2 -#define NB_SMS_CLEAR_READ_SENT_UNSENT 3 -#define NB_SMS_CLEAR_ALL 4 - void clear(int flag=NB_SMS_CLEAR_READ_SENT); + void clear(int flag = NB_SMS_CLEAR_READ_SENT); private: bool _synch; From 1504346005cda9ab43c10fbfe3713958c0d8f27f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 9 Dec 2020 12:58:56 +0100 Subject: [PATCH 4/4] Fix comment layout to be consistent with the rest of the file --- src/NB_SMS.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NB_SMS.h b/src/NB_SMS.h index b77b88e..c5b3777 100644 --- a/src/NB_SMS.h +++ b/src/NB_SMS.h @@ -89,7 +89,8 @@ class NB_SMS : public Stream { */ void flush(); - /** Delete all read and sent SMS from Modem memory and process answer */ + /** Delete all read and sent SMS from Modem memory and process answer + */ void clear(int flag = NB_SMS_CLEAR_READ_SENT); private: