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 _GSM3MOBILECLIENTSERVICE_
|
---|
35 | #define _GSM3MOBILECLIENTSERVICE_
|
---|
36 |
|
---|
37 | #include <GSM3MobileNetworkProvider.h>
|
---|
38 | #include <Client.h>
|
---|
39 |
|
---|
40 |
|
---|
41 | class GSM3MobileClientService : public Client
|
---|
42 | {
|
---|
43 | private:
|
---|
44 |
|
---|
45 | uint8_t mySocket;
|
---|
46 | uint8_t flags;
|
---|
47 |
|
---|
48 | /** Blocks waiting for an answer
|
---|
49 | @return returns 0 if last command is still executing, 1 success, >1 error
|
---|
50 | */
|
---|
51 | int waitForAnswer();
|
---|
52 |
|
---|
53 | public:
|
---|
54 |
|
---|
55 | /** Constructor
|
---|
56 | @param synch Sync mode
|
---|
57 | */
|
---|
58 | GSM3MobileClientService(bool synch=true);
|
---|
59 |
|
---|
60 | /** Constructor
|
---|
61 | @param socket Socket
|
---|
62 | @param synch Sync mode
|
---|
63 | */
|
---|
64 | GSM3MobileClientService(int socket, bool synch);
|
---|
65 |
|
---|
66 | /** Get last command status
|
---|
67 | @return returns 0 if last command is still executing, 1 success, >1 error
|
---|
68 | */
|
---|
69 | int ready();
|
---|
70 |
|
---|
71 | // we take this function out as IPAddress is complex to bring to
|
---|
72 | // version 1.
|
---|
73 | /** Connect to server by IP address
|
---|
74 | @param (IPAddress)
|
---|
75 | @param (uint16_t)
|
---|
76 | @return returns 0 if last command is still executing, 1 success, 2 if there are no resources
|
---|
77 | */
|
---|
78 | inline int connect(IPAddress, uint16_t);
|
---|
79 |
|
---|
80 | /** Connect to server by hostname
|
---|
81 | @param host Hostname
|
---|
82 | @param port Port
|
---|
83 | @return returns 0 if last command is still executing, 1 success, 2 if there are no resources
|
---|
84 | */
|
---|
85 | int connect(const char *host, uint16_t port);
|
---|
86 |
|
---|
87 | /** Initialize write in request
|
---|
88 | @param sync Sync mode
|
---|
89 | */
|
---|
90 | void beginWrite(bool sync=false);
|
---|
91 |
|
---|
92 | /** Write a character in request
|
---|
93 | @param c Character
|
---|
94 | @return size
|
---|
95 | */
|
---|
96 | size_t write(uint8_t c);
|
---|
97 |
|
---|
98 | /** Write a characters buffer in request
|
---|
99 | @param buf Buffer
|
---|
100 | @return buffer size
|
---|
101 | */
|
---|
102 | size_t write(const uint8_t *buf);
|
---|
103 |
|
---|
104 | /** Write a characters buffer with size in request
|
---|
105 | @param (uint8_t*) Buffer
|
---|
106 | @param (size_t) Buffer size
|
---|
107 | @return buffer size
|
---|
108 | */
|
---|
109 | size_t write(const uint8_t*, size_t);
|
---|
110 |
|
---|
111 | /** Finish write request
|
---|
112 | @param sync Sync mode
|
---|
113 | */
|
---|
114 | void endWrite(bool sync=false);
|
---|
115 |
|
---|
116 | /** Check if connected to server
|
---|
117 | @return 1 if connected
|
---|
118 | */
|
---|
119 | uint8_t connected();
|
---|
120 |
|
---|
121 | operator bool();
|
---|
122 |
|
---|
123 | /** Read from response buffer and copy size specified to buffer
|
---|
124 | @param buf Buffer
|
---|
125 | @param size Buffer size
|
---|
126 | @return bytes read
|
---|
127 | */
|
---|
128 | int read(uint8_t *buf, size_t size);
|
---|
129 |
|
---|
130 | /** Read a character from response buffer
|
---|
131 | @return character
|
---|
132 | */
|
---|
133 | int read();
|
---|
134 |
|
---|
135 | /** Check if exists a response available
|
---|
136 | @return 1 if exists, 0 if not exists
|
---|
137 | */
|
---|
138 | int available();
|
---|
139 |
|
---|
140 | /** Read a character from response buffer but does not move the pointer.
|
---|
141 | @return character
|
---|
142 | */
|
---|
143 | int peek();
|
---|
144 |
|
---|
145 | /** Flush response buffer
|
---|
146 | */
|
---|
147 | void flush();
|
---|
148 |
|
---|
149 | /** Stop client
|
---|
150 | */
|
---|
151 | void stop();
|
---|
152 |
|
---|
153 | /** Get socket
|
---|
154 | @return socket
|
---|
155 | */
|
---|
156 | inline int getSocket(){return (int)mySocket;};
|
---|
157 |
|
---|
158 |
|
---|
159 | };
|
---|
160 |
|
---|
161 |
|
---|
162 | #endif
|
---|