-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
GSM.h
345 lines (300 loc) · 9.65 KB
/
GSM.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#ifndef GSM_h
#define GSM_h
#include <Arduino.h>
#include "DTE.h"
struct Operator {
unsigned char mode;
unsigned char format;
char oper[16];
char operNumeric[6];
};
struct ServiceData {
unsigned char n;
};
struct PhonebookMemoryStorage {
char storage[3];
unsigned char used;
unsigned char total;
};
struct NetworkRegistration {
unsigned char n;
unsigned char status;
char lac[5];
char ci[5];
};
struct SignalQuality {
unsigned char rssi;
unsigned char ber;
};
struct Clock {
char timestamp[21];
unsigned int year;
unsigned char month;
unsigned char day;
unsigned char hour;
unsigned char minute;
unsigned char second;
unsigned char timezone;
};
struct SubscriberNumber {
char characterSet[9];
char number[17];
unsigned char type;
unsigned char speed;
unsigned char service;
};
struct BatteryStatus {
bool charge;
unsigned char capacityLevel;
float voltage;
};
class GSM {
private:
DTE *dte;
struct Operator selectedOperator;
struct ServiceData serviceData;
struct PhonebookMemoryStorage phonebookMemoryStorage;
char pinStatus[11];
struct NetworkRegistration networkRegistration;
struct SignalQuality signalQuality;
struct Clock clock;
struct SubscriberNumber subscriberNumber;
struct BatteryStatus batteryStatus;
public:
GSM(DTE &dte);
/**
* Command AT+COPS?
* @return true: If command successful, false: Otherwise
*/
bool atOperatorSelection(void);
/**
* Command AT+COPS=
* @param mode Selection mode.
* 0: Automatic mode
* 1: Manual mode, oper should be present
* 3: Setting format
* 4: Manual and Automatic, oper should be present, if fail, then
* automatic.
* @param format Operator format
* 0: Long format alphanumeric
* 1: Short format alphanumeric
* 2: Numeric format
* @param oper Operator
* @return true: If command successful, false: Otherwise
*/
bool atOperatorSelection(unsigned char mode, unsigned char format = 0, const char oper[] = "");
bool atOperatorSelection(unsigned char mode, unsigned char format, const __FlashStringHelper *oper);
/**
* Command AT+CPBS?
* @return true: If command successful, false: Otherwise
*/
bool atSelectPhonebookMemoryStorage(void);
/**
* Command AT+CPBS=
* @param storage Storage Name
* @return true: If command successful, false: Otherwise
*/
bool atSelectPhonebookMemoryStorage(const char storage[]);
bool atSelectPhonebookMemoryStorage(const __FlashStringHelper *storage);
/**
* Command AT+CPBW=
* @param index Location number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index);
/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[]);
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber);
/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @param type Type of Number:
* 129: National Number type
* 161: National Number type
* 145: International Number type
* 177: Network Specific Number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[], unsigned char type);
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber, unsigned char type);
/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @param type Type of Number:
* 129: National Number type
* 161: National Number type
* 145: International Number type
* 177: Network Specific Number
* @param text Text associated with number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[], unsigned char type, const char text[]);
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber, unsigned char type, const char text[]);
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[], unsigned char type, const __FlashStringHelper *text);
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber, unsigned char type, const __FlashStringHelper *text);
/**
* Command AT+CPIN?
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(void);
/**
* Command AT+CPIN=
* @param pin SIM Pin
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(const char pin[]);
bool atEnterPIN(const __FlashStringHelper *pin);
/**
* Command AT+CPIN=
* @param pin SIM Pin
* @param newPin New SIM Pin
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(const char pin[], const char newPin[]);
bool atEnterPIN(const __FlashStringHelper *pin, const char newPin[]);
bool atEnterPIN(const char pin[], const __FlashStringHelper *newPin);
bool atEnterPIN(const __FlashStringHelper *pin, const __FlashStringHelper *newPin);
/**
* Command AT+CREG?
* @return true: If command successful, false: Otherwise
*/
bool atNetworkRegistration(void);
/**
* Command AT+CREG=
* @param n URC Control
* 0: Disable URC
* 1: Enable URC
* 2: Enable URC, with location information
* @return true: If command successful, false: Otherwise
*/
bool atNetworkRegistration(unsigned char n);
/**
* Command AT+CSQ
* @return true: If command successful, false: Otherwise
*/
bool atSignalQualityReport(void);
/**
* Command AT+CNUM
* @return true: If command successful, false: Otherwise
*/
bool atSubscriberNumber(void);
/**
* Command AT+CCLK?
* @return true: If command successful, false: Otherwise
*/
bool atClock(void);
/**
* Command AT+CCLK=
* @param timestamp Timestamp in format
* @return true: If command successful, false: Otherwise
*/
bool atClock(const char timestamp[]);
bool atClock(const __FlashStringHelper *timestamp);
/**
* Command AT+CBC
* @return true: If command successful, false: Otherwise
*/
bool atBatteryCharge(void);
/**
* Command AT+CUSD?
* @return true: If command successful, false: Otherwise
*/
bool atUnstructuredSupplementaryServiceData(void);
/**
* Command AT+CUSD=
* @param n Control USSD, Code result presentation
* 0: Disable
* 1: Enable
* 2: Cancel Session
* @return true: If command successful, false: Otherwise
*/
bool atUnstructuredSupplementaryServiceData(unsigned char n);
/**
* Command AT+CUSD=
* @param n Control USSD, Code result presentation
* 0: Disable
* 1: Enable
* @param str USSD Code, ex: *123#
* @return true: If command successful, false: Otherwise
*/
bool atUnstructuredSupplementaryServiceData(unsigned char n, const char str[]);
bool atUnstructuredSupplementaryServiceData(unsigned char n, const __FlashStringHelper *str);
/**
* Command AT+CUSD=
* @param n Control USSD, Code result presentation
* 0: Disable
* 1: Enable
* @param str USSD Code, ex: *123#
* @param dcs Cell Broadcast Data Coding Scheme
* @return true: If command successful, false: Otherwise
*/
bool atUnstructuredSupplementaryServiceData(unsigned char n, const char str[], unsigned char dcs);
bool atUnstructuredSupplementaryServiceData(unsigned char n, const __FlashStringHelper *str, unsigned char dcs);
/**
* Get current Operator, this method also
* automatically fetch Operator in Numeric Format
* @param format Format operator name, default: 0
* 0: Long name format
* 1: Short name format
* @return Operator Struct
*/
struct Operator getOperator(unsigned char format = 0);
/**
* Get current Phonebook Memory Storage
* @return PhonebookMemoryStorage Struct
*/
struct PhonebookMemoryStorage getPhonebookMemoryStrorage(void);
/**
* Get current Pin Status
* @return Pin Status in char array
*/
const char *getPinStatus(void);
/**
* Get current Network Registration
* @return NetworkRegistration Struct
*/
struct NetworkRegistration getNetworkRegistration(void);
/**
* Get current Signal Quality
* @return SignalQuality Struct
*/
struct SignalQuality getSignalQuality(void);
/**
* Get current Timestatmp
* @return Clock Struct
*/
struct Clock getClock(void);
/**
* Get Subscriber/Owner Number
* @return SubscriberNumber Struct
*/
struct SubscriberNumber getSubscriberNumber(void);
/**
* Get current Battery Status
* @return BatteryStatus Struct
*/
struct BatteryStatus getBatteryStatus(void);
/**
* Send USSD data
* @param serviceNumber String to access USSD, ex: *123#
* @return true: If command successful, false: Otherwise
*/
bool sendServiceData(const char serviceNumber[]);
bool sendServiceData(const __FlashStringHelper *serviceNumber);
/**
* Cancel/close USSD session
*/
void cancelServiceData(void);
/**
* Set Own Number
*/
bool setOwnNumber(const char ownNumber[]);
};
#endif