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+
120#include " GSM.h"
221
322#include " mbed.h"
423#include " CellularLog.h"
24+ #include " CellularDevice.h"
525#include " CellularContext.h"
626#include " CellularInterface.h"
727#include " GEMALTO_CINTERION_CellularStack.h"
828
929#define MAXRETRY 3
1030
11- bool _cmuxEnable = false ;
12- arduino::CMUXClass * arduino::CMUXClass::get_default_instance ()
31+ arduino::CMUXClass *arduino::CMUXClass::get_default_instance ()
1332{
1433 static mbed::UnbufferedSerial serial (MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200 );
1534 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()
1938
2039mbed::CellularDevice *mbed::CellularDevice::get_default_instance ()
2140{
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;
2746}
2847
2948int arduino::GSMClass::begin (const char * pin, const char * apn, const char * username, const char * password, RadioAccessTechnologyType rat, uint32_t band, bool restart) {
3049
3150 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);
3453 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);
3857 delay (1 );
39- digitalWrite (PJ_7 , HIGH);
58+ digitalWrite (MBED_CONF_GEMALTO_CINTERION_ON , HIGH);
4059 delay (1 );
4160 // this timer is to make sure that at boottime and when the CMUX is used,
4261 // ^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
5069 printf (" Invalid context\n " );
5170 return 0 ;
5271 }
53- pinMode (PJ_7 , INPUT_PULLDOWN);
72+ pinMode (MBED_CONF_GEMALTO_CINTERION_ON , INPUT_PULLDOWN);
5473
5574 static mbed::DigitalOut rts (MBED_CONF_GEMALTO_CINTERION_RTS, 0 );
5675
@@ -99,11 +118,11 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
99118 return connect_status == NSAPI_ERROR_OK ? 1 : 0 ;
100119}
101120
102- void arduino::GSMClass::enableCmux (){
121+ void arduino::GSMClass::enableCmux () {
103122 _cmuxGSMenable = true ;
104123}
105124
106- bool arduino::GSMClass::isCmuxEnable (){
125+ bool arduino::GSMClass::isCmuxEnable () {
107126 return _cmuxGSMenable;
108127}
109128
@@ -130,53 +149,16 @@ bool arduino::GSMClass::setTime(unsigned long const epoch, int const timezone)
130149 return _device->set_time (epoch, timezone);
131150}
132151
133- static PlatformMutex trace_mutex;
134-
135- static void trace_wait ()
152+ bool arduino::GSMClass::isConnected ()
136153{
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 ;
158158 }
159159}
160160
161- void arduino::GSMClass::debug (Stream& stream) {
162-
163- #if MBED_CONF_MBED_TRACE_ENABLE
164-
165- mbed_trace_init ();
166161
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- }
180162
181163NetworkInterface* arduino::GSMClass::getNetwork () {
182164 return _context;
0 commit comments