-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathGPRS.h
110 lines (87 loc) · 2.98 KB
/
GPRS.h
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
/*
This file is part of the MKR GSM library.
Copyright (C) 2017 Arduino AG (http://www.arduino.cc/)
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _GPRS_H_INCLUDED
#define _GPRS_H_INCLUDED
#include <IPAddress.h>
#include "GSM.h"
#include "Modem.h"
enum {
GPRS_PING_DEST_UNREACHABLE = -1,
GPRS_PING_TIMEOUT = -2,
GPRS_PING_UNKNOWN_HOST = -3,
GPRS_PING_ERROR = -4
};
class GPRS : public ModemUrcHandler {
public:
GPRS();
virtual ~GPRS();
/** Attach to GPRS/GSM network
@param networkId APN GPRS
@param user Username
@param pass Password
@return connection status
*/
GSM3_NetworkStatus_t networkAttach(char* networkId, char* user, char* pass)
{
return attachGPRS(networkId, user, pass);
};
/** Detach GPRS/GSM network
@return connection status
*/
GSM3_NetworkStatus_t networkDetach(){ return detachGPRS(); };
/** Attach to GPRS service
@param apn APN GPRS
@param user_name Username
@param password Password
@param synchronous Sync mode
@return connection status
*/
GSM3_NetworkStatus_t attachGPRS(const char* apn, const char* user_name, const char* password, bool synchronous = true);
/** Detach GPRS service
@param synchronous Sync mode
@return connection status
*/
GSM3_NetworkStatus_t detachGPRS(bool synchronous = true);
/** Returns 0 if last command is still executing
@return 1 if success, >1 if error
*/
int ready();
/** Get actual assigned IP address in IPAddress format
@return IP address in IPAddress format
*/
IPAddress getIPAddress();
unsigned long timeout();
void setTimeout(unsigned long timeout);
int hostByName(const char* hostname, IPAddress& result);
int hostByName(const String &hostname, IPAddress& result) { return hostByName(hostname.c_str(), result); }
int ping(const char* hostname, uint8_t ttl = 128);
int ping(const String& hostname, uint8_t ttl = 128);
int ping(IPAddress ip, uint8_t ttl = 128);
GSM3_NetworkStatus_t status();
int state();
void setState(int state);
void handleUrc(const String& urc);
private:
const char* _apn;
const char* _username;
const char* _password;
int _state;
GSM3_NetworkStatus_t _status;
String _response;
int _pingResult;
unsigned long _timeout;
};
#endif