1 | /*
|
---|
2 | This file is part of the GSM3 communications library for Arduino
|
---|
3 | -- Multi-transport communications platform
|
---|
4 | -- Fully asynchronous
|
---|
5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
|
---|
6 | -- Voice calls
|
---|
7 | -- SMS
|
---|
8 | -- TCP/IP connections
|
---|
9 | -- HTTP basic clients
|
---|
10 |
|
---|
11 | This library has been developed by Telefónica Digital - PDI -
|
---|
12 | - Physical Internet Lab, as part as its collaboration with
|
---|
13 | Arduino and the Open Hardware Community.
|
---|
14 |
|
---|
15 | September-December 2012
|
---|
16 |
|
---|
17 | This library is free software; you can redistribute it and/or
|
---|
18 | modify it under the terms of the GNU Lesser General Public
|
---|
19 | License as published by the Free Software Foundation; either
|
---|
20 | version 2.1 of the License, or (at your option) any later version.
|
---|
21 |
|
---|
22 | This library is distributed in the hope that it will be useful,
|
---|
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
25 | Lesser General Public License for more details.
|
---|
26 |
|
---|
27 | You should have received a copy of the GNU Lesser General Public
|
---|
28 | License along with this library; if not, write to the Free Software
|
---|
29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
30 |
|
---|
31 | The latest version of this library can always be found at
|
---|
32 | https://github.com/BlueVia/Official-Arduino
|
---|
33 | */
|
---|
34 | #ifndef __GSM3_SHIELDV1SMSPROVIDER__
|
---|
35 | #define __GSM3_SHIELDV1SMSPROVIDER__
|
---|
36 |
|
---|
37 | #include <GSM3ShieldV1ModemCore.h>
|
---|
38 | #include <GSM3MobileSMSProvider.h>
|
---|
39 | #include <GSM3ShieldV1SMSProvider.h>
|
---|
40 |
|
---|
41 |
|
---|
42 | class GSM3ShieldV1SMSProvider : public GSM3MobileSMSProvider, public GSM3ShieldV1BaseProvider
|
---|
43 | {
|
---|
44 | public:
|
---|
45 | GSM3ShieldV1SMSProvider();
|
---|
46 |
|
---|
47 | /** Manages modem response
|
---|
48 | @param from Initial byte of buffer
|
---|
49 | @param to Final byte of buffer
|
---|
50 | */
|
---|
51 | void manageResponse(byte from, byte to);
|
---|
52 |
|
---|
53 | /** Begin a SMS to send it
|
---|
54 | @param to Destination
|
---|
55 | @return error command if it exists
|
---|
56 | */
|
---|
57 | inline int beginSMS(const char* to);
|
---|
58 |
|
---|
59 | /** Write a SMS character by character
|
---|
60 | @param c Character
|
---|
61 | */
|
---|
62 | inline void writeSMS(char c);
|
---|
63 |
|
---|
64 | /** End SMS
|
---|
65 | @return error command if it exists
|
---|
66 | */
|
---|
67 | inline int endSMS();
|
---|
68 |
|
---|
69 | /** Check if SMS available and prepare it to be read
|
---|
70 | @return number of bytes in a received SMS
|
---|
71 | */
|
---|
72 | int availableSMS();
|
---|
73 |
|
---|
74 | /** Read a byte but do not advance the buffer header (circular buffer)
|
---|
75 | @return character
|
---|
76 | */
|
---|
77 | int peekSMS();
|
---|
78 |
|
---|
79 | /** Delete the SMS from Modem memory and proccess answer
|
---|
80 | */
|
---|
81 | void flushSMS();
|
---|
82 |
|
---|
83 | /** Read sender number phone
|
---|
84 | @param number Buffer for save number phone
|
---|
85 | @param nlength Buffer length
|
---|
86 | @return 1 success, >1 error
|
---|
87 | */
|
---|
88 | int remoteSMSNumber(char* number, int nlength); //Before reading the SMS, read the phone number.
|
---|
89 |
|
---|
90 | /** Read one char for SMS buffer (advance circular buffer)
|
---|
91 | @return character
|
---|
92 | */
|
---|
93 | int readSMS();
|
---|
94 |
|
---|
95 | /** Get last command status
|
---|
96 | @return returns 0 if last command is still executing, 1 success, >1 error
|
---|
97 | */
|
---|
98 | int ready(){return GSM3ShieldV1BaseProvider::ready();};
|
---|
99 |
|
---|
100 | private:
|
---|
101 |
|
---|
102 | int idSMS; // Id from current SMS being read.
|
---|
103 | bool flagReadingSMS; // To detect first SMS char if not yet reading.
|
---|
104 | bool fullBufferSMS; // To detect if the SMS being read needs another buffer.
|
---|
105 | bool twoSMSinBuffer; // To detect if the buffer has more than 1 SMS.
|
---|
106 | bool checkSecondBuffer; // Pending to detect if the second buffer has more than 1 SMS.
|
---|
107 |
|
---|
108 | /** Continue to begin SMS function
|
---|
109 | */
|
---|
110 | void beginSMSContinue();
|
---|
111 |
|
---|
112 | /** Continue to end SMS function
|
---|
113 | */
|
---|
114 | void endSMSContinue();
|
---|
115 |
|
---|
116 | /** Continue to available SMS function
|
---|
117 | */
|
---|
118 | void availableSMSContinue();
|
---|
119 |
|
---|
120 | /** Continue to flush SMS function
|
---|
121 | */
|
---|
122 | void flushSMSContinue();
|
---|
123 |
|
---|
124 | /** Parse CMGL response
|
---|
125 | @param rsp Returns true if expected response exists
|
---|
126 | @return true if command executed correctly
|
---|
127 | */
|
---|
128 | bool parseCMGL_available(bool& rsp);
|
---|
129 | };
|
---|
130 | #endif
|
---|