Easyuino  1.2.0
GSMService.h
1 /*
2 MIT License
3 
4 Copyright (c) 2017 André Pires
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 /*
25 GSMService.h
26 */
27 #ifndef _EASYUINO_GSM_SERVICE_h
28 #define _EASYUINO_GSM_SERVICE_h
29 
30 #include <SoftwareSerial.h>
31 #include "Utilities.h"
32 #include "Device.h"
33 #include "SMS.h"
34 
36 #define GSM_DELAY_NETWORK_LOGIN 10000
37 
38 #define GSM_DEFAULT_BAUD_RATE 9600
39 
44 #define INTERNAL_BUFFER_SIZE_BYTES 128
45 
46 namespace Easyuino {
47 
49  enum class GSMRequestStatus : uint8_t {
51  GSM_OK = 0,
57  GSM_UNEXPECTED_REPLY = 1,
61  GSM_MODULE_DIDNT_REPLY = 2,
63  GSM_REQUEST_INVALID_ARGUMENT = 4,
65  GSM_MAXIMUM_ALLOWED_NUMBERS_REACHED = 5,
67  NOT_INITIALIZED = 255
68  };
69 
74  class GSMService : public Device {
75 
76  private:
78  enum GSMSmsDeleteFlag : uint8_t {
79  INDEX_PARAMTER_CHOSEN_ONLY = 0,
80  ALL_READ_SMS = 1,
81  ALL_SENT_AND_READ_SMS = 2,
82  ALL_SMS = 3
83  };
84 
85  const char *AT_OK = "OK\r\n";
86  const char *AT_ERROR = "ERROR\r\n";
87 
89  uint8_t _powerPin;
90 
92  Stream*_outputStream;
93 
95  SoftwareSerial* _GSMSerial;
96 
98  char _internalBuffer[INTERNAL_BUFFER_SIZE_BYTES];
99 
101  bool _readyToReceiveSMS;
102 
103  public:
110  GSMService(IN uint8_t txPin, IN uint8_t rxPin, IN uint8_t powerPin, IN Stream &outputStream);
111 
117  GSMService(IN uint8_t txPin, IN uint8_t rxPin, IN uint8_t powerPin);
118 
120  ~GSMService();
121 
126  bool begin(IN unsigned long gsmModuleBaudRate);
127 
132  bool begin();
133 
135  void end();
136 
137 #pragma region GSM Physical Module Management
138 
142  GSMRequestStatus turnOn();
143 
147  GSMRequestStatus turnOff();
148 
153  GSMRequestStatus isOn(OUT bool &isOn);
154 
161  GSMRequestStatus setBaudRate(IN unsigned long newBaudRate);
162 
163 #pragma endregion
164 
165 #pragma region SMS Management
166 
170  GSMRequestStatus beginListenForSMS();
171 
177  virtual GSMRequestStatus availableSMS(OUT SMS &message, OUT bool &smsRead);
178 
183  GSMRequestStatus sendSMS(IN SMS &sms);
184 
191  GSMRequestStatus sendSMS(IN unsigned long phoneNumber, IN const char* message, IN unsigned int countryPrefixCode);
192 
196  GSMRequestStatus deleteAllSMS();
197 
201  GSMRequestStatus deleteAllReadSMS();
202 
206  GSMRequestStatus deleteAllSentAndReadSMS();
207 
208 #pragma endregion
209 
210  private:
214  GSMRequestStatus getUnreadSMS(INOUT SMS &sms, OUT bool &smsAvailable);
215 
221  GSMRequestStatus deleteSMS(IN GSMSmsDeleteFlag parameter, IN unsigned int messageIndex = 0);
222 
226  GSMRequestStatus waitForGSMmoduleData();
227 
231  bool lookForGSMmoduleData();
232 
236  void zeroInternalBuffer();
237 
238  };
239 
240 };
241 
242 #endif
Represents a SMS object used to send and receive it from the GSMService API.
Definition: SMS.h:38
Definition: Button.h:38
GSMService API allows to interact with GSM boards in order to perform calls, sms management etc...
Definition: GSMService.h:74
General class that provides the common API behaviour for all the devices/sensors. ...
Definition: Device.h:42