-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
SMS.h
195 lines (167 loc) · 5.64 KB
/
SMS.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifndef SMS_h
#define SMS_h
#include <Arduino.h>
#include "DTE.h"
struct MessageIndication {
unsigned char mode;
unsigned char mt;
unsigned char broadcastMessage;
unsigned char ds;
unsigned char buffer;
};
struct Message {
unsigned char index = 0;
unsigned char status;
char address[16] = "";
unsigned char typeOfAddress = 0;
char timestamp[21] = "";
unsigned char firstOctet = 0;
unsigned int pid = 0;
unsigned int dataCodingScheme = 0;
char serviceCenterAddress[16] = "";
unsigned char typeOfSeviceCenterAddress = 0;
unsigned char length = 0;
char data[163] = "";
};
class SMS {
private:
DTE *dte;
bool textMode = false;
struct MessageIndication messageIndication;
struct Message message;
unsigned int mrSend;
bool showParameter = false;
public:
SMS(DTE &dte);
unsigned char messageStatusIndex(const char status[]);
unsigned char messageStatusIndex(const __FlashStringHelper *status);
/**
* Command AT+CMGD=
* @param index Location
* @param delFlag Delete Flag
* 0: Delete message on specified index
* 1: Delete all read message
* 2: Delete all read and sent message
* 3: Delete all read, sent, and unsent message
* 4: Delete all message
* @return true: If command successful, false: Otherwise
*/
bool atDeleteSMS(unsigned char index, unsigned char delFlag = 0);
/**
* Command AT+CMGF?
* @return true: If command successful, false: Otherwise
*/
bool atSelectSMSFormat(void);
/**
* Command AT+CMGF=
* @param mode SMS Mode
* false: PDU Mode, default
* true: Text Mode
* @return true: If command successful, false: Otherwise
*/
bool atSelectSMSFormat(bool textMode);
/**
* Command AT+CMGL=
* @param status List SMS with status
* 0: "REC UNREAD"
* 1: "REC READ"
* 2: "STO UNSENT"
* 3: "STO SENT"
* 4: "ALL"
* @param mode Read Mode
* 0: Normal, change status, default 0
* 1: Unchange status
* @return true: If command successful, false: Otherwise
*/
bool atListSMS(unsigned char status = 0, unsigned char mode = 0);
/**
* Command AT+CMGR=
* @param index Location
* @param mode Read Mode
* 0: Normal, change status from Unread to Read, default
* 1: Not change status
* @return true: If command successful, false: Otherwise
*/
bool atReadSMS(unsigned char index, unsigned char mode = 0);
/**
* Command AT+CMGS=
* @param destination Destination Address/Phone Number
* @param message Message
* @return true: If command successful, false: Otherwise
*/
bool atSendSMS(const char destination[], const char message[]);
bool atSendSMS(const __FlashStringHelper *destination, const char message[]);
bool atSendSMS(const char destination[], const __FlashStringHelper *message);
bool atSendSMS(const __FlashStringHelper *destination, const __FlashStringHelper *message);
bool atNewMessageIndications(void);
bool atNewMessageIndications(unsigned char mode, unsigned char mt = 255, unsigned char broadcastMessage = 255, unsigned char ds = 255, unsigned char buffer = 255);
/**
* Command AT+CSDH?
* @return true: If command successful, false: Otherwise
*/
bool atShowSMSTextModeParameter(void);
/**
* Command AT+CSDH=
* @param show Show extended parameter in +CMGR
* true: Do not show, false: Show
* @return true: If command successful, false: Otherwise
*/
bool atShowSMSTextModeParameter(bool show);
/**
* Delete SMS by specified index
* @param index Location
* @return true: If command successful, false: Otherwise
*/
bool deleteSMS(unsigned char index) { return atDeleteSMS(index); };
/**
* Delete all read SMS
* @return true: If command successful, false: Otherwise
*/
bool deleteSMSAllRead(void) { return atDeleteSMS(0, 1); };
/**
* Delete all read and sent SMS
* @return true: If command successful, false: Otherwise
*/
bool deleteSMSAllReadSent(void) { return atDeleteSMS(0, 2); };
/**
* Delete all read, sent, and unsent SMS
* @return true: If command successful, false: Otherwise
*/
bool deleteSMSAllReadSentUnsent(void) { return atDeleteSMS(0, 3); };
/**
* Delete all SMS
* @return true: If command successful, false: Otherwise
*/
bool deleteSMSAll(void) { return atDeleteSMS(0, 4); };
/**
* Is SMS Format Text Mode
* @return true: Text Mode, false: PDU Mode
*/
bool isTextMode(void);
/**
* Read SMS. This method is return a Struct that contain
* Phone Number, and Timestamp
* @param index Location
* @return Message Struct
*/
struct Message readSMS(unsigned char index);
/**
* Send SMS. If message length longer than 160 character,
* this method automatically send multiple SMS.
* @param destination Destination Address/Phone Number
* @param message Message
* @return true: If command successful, false: Otherwise
*/
bool sendSMS(const char destination[], const char message[]);
bool sendSMS(const __FlashStringHelper *destination, const char message[]);
bool sendSMS(const char destination[], const __FlashStringHelper *message);
bool sendSMS(const __FlashStringHelper *destination, const __FlashStringHelper *message);
bool newMessageToURC(bool set);
bool selectSMSFormat(bool mode);
/**
* Is show extended parameter for +CGMR
* @return true: Show, false: Hide
*/
bool isShowParameter(void);
};
#endif