1
+ /*
2
+ GSM.cpp - Library for GSM on mbed platforms.
3
+ Copyright (c) 2011-2023 Arduino LLC. All right reserved.
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
1
20
#include " GSM.h"
2
21
3
22
#include " mbed.h"
4
23
#include " CellularLog.h"
24
+ #include " CellularDevice.h"
5
25
#include " CellularContext.h"
6
26
#include " CellularInterface.h"
7
27
#include " GEMALTO_CINTERION_CellularStack.h"
8
28
9
29
#define MAXRETRY 3
10
30
11
- bool _cmuxEnable = false ;
12
- arduino::CMUXClass * arduino::CMUXClass::get_default_instance ()
31
+ arduino::CMUXClass *arduino::CMUXClass::get_default_instance ()
13
32
{
14
33
static mbed::UnbufferedSerial serial (MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200 );
15
34
serial.set_flow_control (mbed::SerialBase::RTSCTS_SW, MBED_CONF_GEMALTO_CINTERION_CTS, NC);
@@ -19,24 +38,24 @@ arduino::CMUXClass * arduino::CMUXClass::get_default_instance()
19
38
20
39
mbed::CellularDevice *mbed::CellularDevice::get_default_instance ()
21
40
{
22
- static auto cmux = arduino::CMUXClass::get_default_instance ();
23
- static mbed::GEMALTO_CINTERION device (cmux->get_serial (0 ));
24
- nextSerialPort++;
25
- device.enableCMUXChannel = mbed::callback (cmux, &arduino::CMUXClass::enableCMUXChannel);
26
- return &device;
41
+ static auto cmux = arduino::CMUXClass::get_default_instance ();
42
+ static mbed::GEMALTO_CINTERION device (cmux->get_serial (0 ));
43
+ nextSerialPort++;
44
+ device.enableCMUXChannel = mbed::callback (cmux, &arduino::CMUXClass::enableCMUXChannel);
45
+ return &device;
27
46
}
28
47
29
48
int arduino::GSMClass::begin (const char * pin, const char * apn, const char * username, const char * password, RadioAccessTechnologyType rat, uint32_t band, bool restart) {
30
49
31
50
if (restart || isCmuxEnable ()) {
32
- pinMode (PJ_10 , OUTPUT);
33
- digitalWrite (PJ_10 , HIGH);
51
+ pinMode (MBED_CONF_GEMALTO_CINTERION_RST , OUTPUT);
52
+ digitalWrite (MBED_CONF_GEMALTO_CINTERION_RST , HIGH);
34
53
delay (800 );
35
- digitalWrite (PJ_10 , LOW);
36
- pinMode (PJ_7 , OUTPUT);
37
- digitalWrite (PJ_7 , LOW);
54
+ digitalWrite (MBED_CONF_GEMALTO_CINTERION_RST , LOW);
55
+ pinMode (MBED_CONF_GEMALTO_CINTERION_ON , OUTPUT);
56
+ digitalWrite (MBED_CONF_GEMALTO_CINTERION_ON , LOW);
38
57
delay (1 );
39
- digitalWrite (PJ_7 , HIGH);
58
+ digitalWrite (MBED_CONF_GEMALTO_CINTERION_ON , HIGH);
40
59
delay (1 );
41
60
// this timer is to make sure that at boottime and when the CMUX is used,
42
61
// ^SYSTART is received in time to avoid stranger behaviour
@@ -50,7 +69,7 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
50
69
printf (" Invalid context\n " );
51
70
return 0 ;
52
71
}
53
- pinMode (PJ_7 , INPUT_PULLDOWN);
72
+ pinMode (MBED_CONF_GEMALTO_CINTERION_ON , INPUT_PULLDOWN);
54
73
55
74
static mbed::DigitalOut rts (MBED_CONF_GEMALTO_CINTERION_RTS, 0 );
56
75
@@ -99,11 +118,11 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
99
118
return connect_status == NSAPI_ERROR_OK ? 1 : 0 ;
100
119
}
101
120
102
- void arduino::GSMClass::enableCmux (){
121
+ void arduino::GSMClass::enableCmux () {
103
122
_cmuxGSMenable = true ;
104
123
}
105
124
106
- bool arduino::GSMClass::isCmuxEnable (){
125
+ bool arduino::GSMClass::isCmuxEnable () {
107
126
return _cmuxGSMenable;
108
127
}
109
128
@@ -130,53 +149,16 @@ bool arduino::GSMClass::setTime(unsigned long const epoch, int const timezone)
130
149
return _device->set_time (epoch, timezone );
131
150
}
132
151
133
- static PlatformMutex trace_mutex;
134
-
135
- static void trace_wait ()
152
+ bool arduino::GSMClass::isConnected ()
136
153
{
137
- trace_mutex.lock ();
138
- }
139
-
140
- static void trace_release ()
141
- {
142
- trace_mutex.unlock ();
143
- }
144
-
145
- static char * trace_time (size_t ss)
146
- {
147
- static char time_st[50 ];
148
- auto ms = std::chrono::time_point_cast<std::chrono::milliseconds>(rtos::Kernel::Clock::now ()).time_since_epoch ().count ();
149
- // snprintf(time_st, 49, "[%08llums]", ms);
150
- snprintf (time_st, 1 , " \n " );
151
- return time_st;
152
- }
153
-
154
- static Stream* trace_stream = nullptr ;
155
- static void arduino_print (const char * c) {
156
- if (trace_stream) {
157
- trace_stream->println (c);
154
+ if (_context) {
155
+ return _context->is_connected ();
156
+ } else {
157
+ return false ;
158
158
}
159
159
}
160
160
161
- void arduino::GSMClass::debug (Stream& stream) {
162
-
163
- #if MBED_CONF_MBED_TRACE_ENABLE
164
-
165
- mbed_trace_init ();
166
161
167
- trace_stream = &stream;
168
- mbed_trace_print_function_set (arduino_print);
169
- mbed_trace_prefix_function_set ( &trace_time );
170
-
171
- mbed_trace_mutex_wait_function_set (trace_wait);
172
- mbed_trace_mutex_release_function_set (trace_release);
173
-
174
- mbed_cellular_trace::mutex_wait_function_set (trace_wait);
175
- mbed_cellular_trace::mutex_release_function_set (trace_release);
176
-
177
- #endif
178
-
179
- }
180
162
181
163
NetworkInterface* arduino::GSMClass::getNetwork () {
182
164
return _context;
0 commit comments