aboutsummaryrefslogtreecommitdiff
path: root/libraries/GSM/GSM3MobileMockupProvider.h
blob: 59eee4185d65647b85883e432041cf9687ec19ce (plain)
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
/*
This file is part of the GSM3 communications library for Arduino
-- Multi-transport communications platform
-- Fully asynchronous
-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
-- Voice calls
-- SMS
-- TCP/IP connections
-- HTTP basic clients

This library has been developed by Telef�nica Digital - PDI -
- Physical Internet Lab, as part as its collaboration with
Arduino and the Open Hardware Community. 

September-December 2012

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

The latest version of this library can always be found at
https://github.com/BlueVia/Official-Arduino
*/
#ifndef _GSM3MOBILEMOCKUPPROVIDER_
#define _GSM3MOBILEMOCKUPPROVIDER_

#include <GSM3MobileNetworkProvider.h>
#include <GSM3MobileVoiceProvider.h>
		
class GSM3MobileMockupProvider: public GSM3MobileNetworkProvider
{				
	private:
		// Introducing this status is quite "heavy". But something like this should
		// be added to ShieldV1. Or not. 
		// Note, in ShieldV1 there is no "RECEIVINGSMS" status.
		enum GSM3_modemlinest_e { IDLE, WAITINGANSWER, SENDINGSMS};
		GSM3_modemlinest_e lineStatus;
		char* msgExample;
		int msgIndex;
		
	public:
	
		/** Minimum socket
			@return 1
		 */
		inline int minSocket(){return 1;};
		
		/** Maximum socket
			@return 8
		 */
		inline int maxSocket(){return 8;};

		/** Constructor */
		GSM3MobileMockupProvider();
		
		/** Get network status
			@return network status
		 */
		inline GSM3_NetworkStatus_t getStatus(){return ERROR;};
		
		/** Get voice call status
			@return call status
		 */
		inline GSM3_voiceCall_st getvoiceCallStatus(){return IDLE_CALL;};
		
		/** Get last command status
			@return Returns 0 if last command is still executing, 1 success, >1 error
		 */
		int ready();
		inline void closeCommand(int code){};
		
		//Configuration functions.
		
		/** Begin connection
			@param pin			PIN code
			@return 
		 */
		int begin(char* pin=0);
		
		/** Check if is modem alive
			@return 0
		 */
		inline int isModemAlive(){return 0;};
		
		/** Shutdown the modem (power off really)
			@return true if successful
		 */
		inline bool shutdown(){return false;};
		
		//Call functions
		
		/** Launch a voice call
			@param number	 	Phone number to be called
			@return If asynchronous, returns 0. If synchronous, 1 if success, other if error
		 */
		inline int voiceCall(const char* number){return 0;};
		
		/** Answer a voice call
			@return If asynchronous, returns 0. If synchronous, 1 if success, other if error
		 */
		inline int answerCall(){return 0;};
		
		/** Hang a voice call
			@return If asynchronous, returns 0. If synchronous, 1 if success, other if error
		 */
		inline int hangCall(){return 0;};
		
		/** Retrieve phone number of caller
			@param buffer		Buffer for copy phone number
			@param bufsize		Buffer size
			@return If asynchronous, returns 0. If synchronous, 1 if success, other if error
		 */
		inline int retrieveCallingNumber(char* buffer, int*& bufsize){return 0;};
		
		// SMS functions
		
		/** Begin a SMS to send it
			@param number		Destination
			@return error command if it exists
		 */
		int beginSMS(const char* number);
		
		/** End SMS
			@return error command if it exists
		 */
		int endSMS();
		
		/** Check if SMS available and prepare it to be read
			@return error command if it exists
		 */
		int availableSMS();
		
		/** Read a byte but do not advance the buffer header (circular buffer)
			@return character
		 */
		int peek();
		
		/** Delete the SMS from Modem memory and proccess answer
		 */
		void flushSMS();
		
		/** Read sender number phone
			@param number		Buffer for save number phone
			@param nlength		Buffer length
			@return 1 success, >1 error
		 */
		int remoteSMSNumber(char* number, int nlength); 
		
		/** Read one char for SMS buffer (advance circular buffer)
			@return character
		 */
		int readSMS();
		
		/** Write a SMS character by character
			@param c			Character
		 */
		void writeSMS(char c);
		
		// Socket functions
		
		/** Connect to a remote TCP server
			@param server		String with IP or server name
			@param port 		Remote port number
			@param id_socket	Local socket number
			@return 0 if command running, 1 if success, otherwise error
		*/
		int connectTCPClient(const char* server, int port, int id_socket);
		
		// Attention to parameter rewriting in ShieldV1
		/** Write buffer information into a socket
			@param buf			Buffer
			@param size			Buffer size
			@param idsocket		Socket
		 */
		void writeSocket(const uint8_t *buf, size_t size, int idsocket);
		
		// ShieldV1 will have two reading mechanisms:
		// Mechanism 1: Call AT+QIRD for size bytes. Put them in the circular buffer,
		// fill buf. Take care to xon/xoff effect, as we may copy just a part of the 
		// incoming bytes.
		/** Read socket and put information in a buffer
			@param buf			Buffer
			@param size			Buffer size
			@param idsocket		Socket
			@return
		 */
		int readSocket(uint8_t *buf, size_t size, int idsocket);
		
		// Mechanism 2 in ShieldV1:
		// When called "available()" or "read()" reuse readSocket code to execute 
		// QIRD SYNCHRONOUSLY. Ask the modem for 1500 bytes but do not copy them anywhere, 
		// leave data in the circular buffer. Put buffer head at the start of received data.
		// Peek() will get a character but will not advance the buffer head.
		// Read() will get one character. XON/XOFF will take care of buffer filling
		// If Read() gets to the end of the QIRD response, execute again QIRD SYNCHRONOUSLY 
		// If the user executes flush(), execute read() until there is nothing more to read()
		// (the modem gives no way to empty the socket of incoming data)
		
		/** Check if there are data to be read in socket.
			@param idsocket	Local socket number
			@return 0 if command running, 1 if there are data available, 4 if no data, otherwise error
		*/
		int availableSocket(int idsocket);
		
		/** Read data (get a character) available in socket
			@param idsocket		Socket
			@param advance		Determines if advance the buffer head
			@return character
		 */
		int readSocket(int idsocket, bool advance=true);
		
		/** Flush socket
			@param idsocket		Socket
		 */
		void flushSocket(int idsocket);
		
		// This is the same in ShieldV1
		/** Close a socket
			@param idsocket			Socket
			@return 0 if command running, 1 if success, otherwise error
		 */
		int disconnectTCP(int idsocket);
		
		// TCP Server. Attention. Changing the int*&. We'll receive a buffer for the IP
		// If the pointer ins NULL just forget it
		// I think that opening a server does not occupy a socket. Is that true?
		/** Establish a TCP connection
			@param port				Port
			@param localIP			IP address
			@param localIPlength	IP address size in characters
			@return	command error if exists
		 */
		int connectTCPServer(int port, char* localIP, int* localIPlength);
		
		// Modem sockets status. Return TRUE if the modem thinks the socket is occupied.
		// This should be detected through an unrequisited response
		/** Get modem status
			@param s			Socket
			@return modem status (true if connected)
		 */
		bool getSocketModemStatus(uint8_t s);


};
#endif