-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathGSM.h
182 lines (151 loc) · 5.52 KB
/
GSM.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
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
/*
GSM.h - Library for GSM on mbed platforms.
Copyright (c) 2011-2023 Arduino LLC. All right reserved.
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
*/
#ifndef GSM_h
#define GSM_h
#include <inttypes.h>
#include "SocketHelpers.h"
#include "CellularContext.h"
#include "GEMALTO_CINTERION.h"
#include "GENERIC_AT3GPP.h"
#include "drivers/BufferedSerial.h"
#include "drivers/UnbufferedSerial.h"
#include "CMUXClass.h"
#include "PTYSerial.h"
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
#define MBED_CONF_GEMALTO_CINTERION_TX PA_0
#define MBED_CONF_GEMALTO_CINTERION_RX PI_9
#define MBED_CONF_GEMALTO_CINTERION_RTS PI_10
#define MBED_CONF_GEMALTO_CINTERION_CTS PI_13
#define MBED_CONF_GEMALTO_CINTERION_RST PJ_10
#define MBED_CONF_GEMALTO_CINTERION_ON PJ_7
#elif defined (ARDUINO_EDGE_CONTROL)
/* IMPORTANT: turn on the module's 5V on demand by calling
pinMode(ON_MKR2, OUTPUT);
digitalWrite(ON_MKR2, HIGH);
*/
#define MBED_CONF_GEMALTO_CINTERION_TX p24
#define MBED_CONF_GEMALTO_CINTERION_RX p25
#define MBED_CONF_GEMALTO_CINTERION_RTS NC
#define MBED_CONF_GEMALTO_CINTERION_CTS NC
#define MBED_CONF_GEMALTO_CINTERION_RST p31
#define MBED_CONF_GEMALTO_CINTERION_ON p2
#else
#error Gemalto Cinterion cellular connectivity not supported
#endif
#if defined __has_include
#if __has_include ("GPS.h")
# define _CMUX_ENABLE 1
#else
# define _CMUX_ENABLE 0
#endif
#endif
namespace arduino {
class GSMClass : public MbedSocketClass {
public:
GSMClass()
: _rat(CATNB) {
if(_CMUX_ENABLE){
arduino::GSMClass::enableCmux();
}
}
/*
* Start GSM connection. Configure the credentials into the device.
*
* param pin: Pointer to the pin string.
* param apn: Pointer to the apn string.
* param username: Pointer to the username string.
* param password: Pointer to the password string.
* param rat: Radio Access Technology.
*
* return: 0 in case of success, negative number in case of failure
*/
int begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat = CATNB, uint32_t band = BAND_20, bool restart = false);
/*
* Disconnect from the network
*
* return: one value of wl_status_t enum
*/
int disconnect(void);
/*
* Reset internal state machine in order to be ready to reconnect again.
*/
void end(void);
/*
* Send AT+CFUN=1,1 command to trigger a software reset. To be called only after end();
*/
void reset();
/*
* Send AT^SMSO="fast command to power off the modem. To be called only after end();
*/
void off();
/*
* Change cellular state timeouts. Needs to be called before GSM.begin()
*/
void setTimeout(unsigned long timeout);
unsigned long getTime();
unsigned long getLocalTime();
bool setTime(unsigned long const epoch, int const timezone = 0);
void enableCmux();
bool isCmuxEnable();
#if MBED_CONF_MBED_TRACE_ENABLE
void trace(Stream& stream);
void setTraceLevel(int trace_level, bool timestamp = false, bool at_trace = false);
#endif
int ping(const char* hostname, int ttl = 5000);
int ping(const String& hostname, int ttl = 5000);
int ping(IPAddress host, int ttl = 5000);
bool isConnected();
friend class GSMClient;
friend class GSMUDP;
NetworkInterface* getNetwork();
private:
const char* _pin = nullptr;
const char* _apn = nullptr;
const char* _username = nullptr;
const char* _password = nullptr;
bool _cmuxGSMenable = _CMUX_ENABLE;
RadioAccessTechnologyType _rat;
FrequencyBand _band;
NetworkInterface* gsm_if = nullptr;
mbed::CellularContext* _context = nullptr;
mbed::CellularDevice* _device = nullptr;
bool _at_debug = false;
unsigned long _timeout = 1000;
/* Internal cellular state machine retries. Values are in seconds.
* This array also defines the maximum number of retries to CELLULAR_RETRY_ARRAY_SIZE
*/
const uint16_t _retry_timeout[CELLULAR_RETRY_ARRAY_SIZE] = {1, 2, 4, 8, 8, 8, 8, 8, 8, 8};
static constexpr int RSSI_UNKNOWN = 99;
static const char * const sim_state_str[];
static const char * const reg_type_str[];
static const char * const rat_str[];
static const char * const state_str[];
static const char * const event_str[];
static const char * getRATString(const mbed::CellularNetwork::RadioAccessTechnology rat);
static const char * getStateString(const mbed::CellularStateMachine::CellularState state);
static const char * getEventString(const cellular_event_status event);
static const char * getSIMStateString(const mbed::CellularDevice::SimState state);
static const char * getRegistrationStateString(const mbed::CellularNetwork::RegistrationStatus state);
void onStatusChange(nsapi_event_t ev, intptr_t in);
void hardwareReset();
void on();
};
}
extern GSMClass GSM;
#include "GSMClient.h"
#include "GSMSSLClient.h"
#include "GSMUdp.h"
#endif