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 _GSM3SHIELDV1DATANETWORKPROVIDER_
|
---|
35 | #define _GSM3SHIELDV1DATANETWORKPROVIDER_
|
---|
36 |
|
---|
37 | #include <GSM3MobileDataNetworkProvider.h>
|
---|
38 | #include <GSM3ShieldV1BaseProvider.h>
|
---|
39 | #include <GSM3ShieldV1ModemCore.h>
|
---|
40 | #include <IPAddress.h>
|
---|
41 |
|
---|
42 | class GSM3ShieldV1DataNetworkProvider : public GSM3MobileDataNetworkProvider, public GSM3ShieldV1BaseProvider
|
---|
43 | {
|
---|
44 | private:
|
---|
45 |
|
---|
46 | char* user; // Username for GPRS
|
---|
47 | char* passwd; // Password for GPRS
|
---|
48 |
|
---|
49 | /** Continue to attach GPRS function
|
---|
50 | */
|
---|
51 | void attachGPRSContinue();
|
---|
52 |
|
---|
53 | /** Continue to detach GPRS function
|
---|
54 | */
|
---|
55 | void detachGPRSContinue();
|
---|
56 |
|
---|
57 | /** Parse QILOCIP response
|
---|
58 | @param LocalIP Buffer for save local IP address
|
---|
59 | @param LocalIPlength Buffer size
|
---|
60 | @param rsp Returns true if expected response exists
|
---|
61 | @return true if command executed correctly
|
---|
62 | */
|
---|
63 | bool parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp);
|
---|
64 |
|
---|
65 | /** Continue to get IP function
|
---|
66 | */
|
---|
67 | void getIPContinue();
|
---|
68 |
|
---|
69 | /** Implementation of inet_aton standard function
|
---|
70 | @param aIPAddrString IP address in characters buffer
|
---|
71 | @param aResult IP address in IPAddress format
|
---|
72 | @return 1 if the address is successfully converted, or 0 if the conversion failed
|
---|
73 | */
|
---|
74 | int inet_aton(const char* aIPAddrString, IPAddress& aResult);
|
---|
75 |
|
---|
76 | public:
|
---|
77 |
|
---|
78 | /** Attach to GPRS/GSM network
|
---|
79 | @param networkId APN GPRS
|
---|
80 | @param user Username
|
---|
81 | @param pass Password
|
---|
82 | @return connection status
|
---|
83 | */
|
---|
84 | GSM3_NetworkStatus_t networkAttach(char* networkId, char* user, char* pass)
|
---|
85 | {
|
---|
86 | return attachGPRS(networkId, user, pass);
|
---|
87 | };
|
---|
88 |
|
---|
89 | /** Detach GPRS/GSM network
|
---|
90 | @return connection status
|
---|
91 | */
|
---|
92 | GSM3_NetworkStatus_t networkDetach(){ return detachGPRS();};
|
---|
93 |
|
---|
94 | /** Attach to GPRS service
|
---|
95 | @param apn APN GPRS
|
---|
96 | @param user_name Username
|
---|
97 | @param password Password
|
---|
98 | @param synchronous Sync mode
|
---|
99 | @return connection status
|
---|
100 | */
|
---|
101 | GSM3_NetworkStatus_t attachGPRS(char* apn, char* user_name, char* password, bool synchronous=true);
|
---|
102 |
|
---|
103 | /** Detach GPRS service
|
---|
104 | @param synchronous Sync mode
|
---|
105 | @return connection status
|
---|
106 | */
|
---|
107 | GSM3_NetworkStatus_t detachGPRS(bool synchronous=true);
|
---|
108 |
|
---|
109 | /** Returns 0 if last command is still executing
|
---|
110 | @return 1 if success, >1 if error
|
---|
111 | */
|
---|
112 | int ready(){return GSM3ShieldV1BaseProvider::ready();};
|
---|
113 |
|
---|
114 | /** Get network status (connection)
|
---|
115 | @return status
|
---|
116 | */
|
---|
117 | inline GSM3_NetworkStatus_t getStatus(){return theGSM3ShieldV1ModemCore.getStatus();};
|
---|
118 |
|
---|
119 | /** Get actual assigned IP address
|
---|
120 | @param LocalIP Buffer for copy IP address
|
---|
121 | @param LocalIPlength Buffer length
|
---|
122 | @return command error if exists
|
---|
123 | */
|
---|
124 | int getIP(char* LocalIP, int LocalIPlength);
|
---|
125 |
|
---|
126 | /** Get actual assigned IP address in IPAddress format
|
---|
127 | @return IP address in IPAddress format
|
---|
128 | */
|
---|
129 | IPAddress getIPAddress();
|
---|
130 |
|
---|
131 | /** Manages modem response
|
---|
132 | @param from Initial byte of buffer
|
---|
133 | @param to Final byte of buffer
|
---|
134 | */
|
---|
135 | void manageResponse(byte from, byte to);
|
---|
136 |
|
---|
137 |
|
---|
138 | };
|
---|
139 |
|
---|
140 | #endif
|
---|