@@ -46,10 +46,28 @@ mbed::CellularDevice *mbed::CellularDevice::get_default_instance()
46
46
47
47
int arduino::GSMClass::begin (const char * pin, const char * apn, const char * username, const char * password, RadioAccessTechnologyType rat, uint32_t band, bool restart) {
48
48
49
- if (restart || isCmuxEnable ()) {
50
- reset ();
49
+ /* Assume module is powered ON. Uncomment this line is you are using
50
+ * Edge Control without Arduino_ConnectionHandler
51
+ * #if defined (ARDUINO_EDGE_CONTROL)
52
+ * pinMode(ON_MKR2, OUTPUT);
53
+ * digitalWrite(ON_MKR2, HIGH);
54
+ * #endif
55
+ */
56
+
57
+ /* Ensure module is not under reset */
58
+ pinMode (MBED_CONF_GEMALTO_CINTERION_RST, OUTPUT);
59
+ digitalWrite (MBED_CONF_GEMALTO_CINTERION_RST, LOW);
60
+
61
+ /* Reset module if needed */
62
+ const bool emergencyReset = restart || isCmuxEnable ();
63
+ DEBUG_INFO (" Emergency reset %s" , emergencyReset ? " enabled" : " disabled" );
64
+ if (emergencyReset) {
65
+ hardwareReset ();
51
66
}
52
67
68
+ /* Create rising edge on pin ON */
69
+ on ();
70
+
53
71
if (!_context) {
54
72
_context = mbed::CellularContext::get_default_instance ();
55
73
}
@@ -59,20 +77,18 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
59
77
return 0 ;
60
78
}
61
79
62
- pinMode (MBED_CONF_GEMALTO_CINTERION_ON, INPUT_PULLDOWN);
63
-
80
+ # if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
81
+ /* This is needed to wakeup module if hw flow control is enabled */
64
82
static mbed::DigitalOut rts (MBED_CONF_GEMALTO_CINTERION_RTS, 0 );
83
+ #endif
65
84
66
85
_device = _context->get_device ();
67
86
_device->modem_debug_on (_at_debug);
68
87
69
- if (!isReady ()) {
70
- DEBUG_ERROR (" Cellular device not ready" );
71
- return 0 ;
72
- }
73
-
88
+ DEBUG_INFO (" CMUX %s" , _cmuxGSMenable ? " enabled" : " disabled" );
74
89
_device->set_cmux_status_flag (_cmuxGSMenable);
75
90
_device->set_retry_timeout_array (_retry_timeout, sizeof (_retry_timeout) / sizeof (_retry_timeout[0 ]));
91
+ _device->set_timeout (_timeout);
76
92
_device->attach (mbed::callback (this , &GSMClass::onStatusChange));
77
93
_device->init ();
78
94
@@ -106,6 +122,10 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
106
122
return connect_status == NSAPI_ERROR_OK ? 1 : 0 ;
107
123
}
108
124
125
+ void arduino::GSMClass::setTimeout (unsigned long timeout) {
126
+ _timeout = timeout;
127
+ }
128
+
109
129
void arduino::GSMClass::enableCmux () {
110
130
_cmuxGSMenable = true ;
111
131
}
@@ -115,13 +135,62 @@ bool arduino::GSMClass::isCmuxEnable() {
115
135
}
116
136
117
137
void arduino::GSMClass::end () {
138
+ if (_device) {
139
+ _device->shutdown ();
140
+ }
141
+ }
142
+
143
+ void arduino::GSMClass::reset () {
144
+ if (_device) {
145
+ _device->soft_reset ();
146
+ }
147
+ }
148
+
149
+ void arduino::GSMClass::off () {
150
+ if (_device) {
151
+ _device->soft_power_off ();
152
+ }
153
+ }
154
+
155
+ int arduino::GSMClass::ping (const char * hostname, int ttl) {
156
+
157
+ mbed::GEMALTO_CINTERION_CellularStack* stack = (mbed::GEMALTO_CINTERION_CellularStack*)_context->get_stack ();
158
+ if (!stack) {
159
+ return -1 ;
160
+ }
161
+ return stack->ping (hostname, ttl);
162
+ }
163
+
164
+ int arduino::GSMClass::ping (const String &hostname, int ttl)
165
+ {
166
+ return ping (hostname.c_str (), ttl);
167
+ }
118
168
169
+ int arduino::GSMClass::ping (IPAddress ip, int ttl)
170
+ {
171
+ String host;
172
+ host.reserve (15 );
173
+
174
+ host += ip[0 ];
175
+ host += ' .' ;
176
+ host += ip[1 ];
177
+ host += ' .' ;
178
+ host += ip[2 ];
179
+ host += ' .' ;
180
+ host += ip[3 ];
181
+
182
+ return ping (host, ttl);
119
183
}
120
184
121
185
int arduino::GSMClass::disconnect () {
122
- if (_context) {
186
+ if (!_context) {
187
+ return 0 ;
188
+ }
189
+
190
+ if (_context->is_connected ()) {
123
191
return _context->disconnect ();
124
192
}
193
+
125
194
return 0 ;
126
195
}
127
196
@@ -158,34 +227,22 @@ NetworkInterface* arduino::GSMClass::getNetwork() {
158
227
return _context;
159
228
}
160
229
161
- void arduino::GSMClass::reset () {
230
+ void arduino::GSMClass::hardwareReset () {
231
+ /* Reset logic is inverted */
162
232
pinMode (MBED_CONF_GEMALTO_CINTERION_RST, OUTPUT);
163
233
digitalWrite (MBED_CONF_GEMALTO_CINTERION_RST, HIGH);
164
234
delay (800 );
165
235
digitalWrite (MBED_CONF_GEMALTO_CINTERION_RST, LOW);
236
+ }
237
+
238
+ void arduino::GSMClass::on () {
239
+ /* Module needs a rising edge to power on */
166
240
pinMode (MBED_CONF_GEMALTO_CINTERION_ON, OUTPUT);
167
241
digitalWrite (MBED_CONF_GEMALTO_CINTERION_ON, LOW);
168
242
delay (1 );
169
243
digitalWrite (MBED_CONF_GEMALTO_CINTERION_ON, HIGH);
170
244
delay (1 );
171
245
}
172
246
173
- bool arduino::GSMClass::isReady (const int timeout) {
174
- if (!_device) {
175
- DEBUG_ERROR (" No device found" );
176
- return false ;
177
- }
178
-
179
- const unsigned int start = millis ();
180
- while (_device->is_ready () != NSAPI_ERROR_OK) {
181
-
182
- if (millis () - start > timeout) {
183
- DEBUG_WARNING (" Timeout waiting device ready" );
184
- return false ;
185
- }
186
- delay (100 );
187
- }
188
- return true ;
189
- }
190
247
191
248
arduino::GSMClass GSM;
0 commit comments