From 85b017769c4051c4c4739af4f8f6998e88c1bb35 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 08:47:19 +0100 Subject: [PATCH 01/13] Fix file header --- libraries/GSM/src/GSMUdp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/GSM/src/GSMUdp.h b/libraries/GSM/src/GSMUdp.h index 6b93bd966..519adff50 100644 --- a/libraries/GSM/src/GSMUdp.h +++ b/libraries/GSM/src/GSMUdp.h @@ -1,5 +1,5 @@ /* - WiFiUdp.h + GSMUdp.h Copyright (c) 2021 Arduino SA. All right reserved. This library is free software; you can redistribute it and/or From 105e93a4f43d2b0c82f87e193ccc20e5c5fdd0bb Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 08:50:24 +0100 Subject: [PATCH 02/13] Add isConnected() method --- libraries/GSM/src/GSM.cpp | 9 +++++++++ libraries/GSM/src/GSM.h | 1 + 2 files changed, 10 insertions(+) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 1da0d49b3..78055aaf3 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -130,6 +130,15 @@ bool arduino::GSMClass::setTime(unsigned long const epoch, int const timezone) return _device->set_time(epoch, timezone); } +bool arduino::GSMClass::isConnected() +{ + if (_context) { + return _context->is_connected(); + } else { + return false; + } +} + static PlatformMutex trace_mutex; static void trace_wait() diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 8b48d3e84..8643dcd2a 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -91,6 +91,7 @@ class GSMClass : public MbedSocketClass { int ping(const char* hostname, uint8_t ttl = 128); int ping(const String& hostname, uint8_t ttl = 128); int ping(IPAddress host, uint8_t ttl = 128); + bool isConnected(); friend class GSMClient; friend class GSMUDP; From 8d032c84ccc4fbed55597c26ed713ae45762a799 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 08:52:51 +0100 Subject: [PATCH 03/13] Add GSMSSLClient class --- libraries/GSM/src/GSM.h | 1 + libraries/GSM/src/GSMSSLClient.h | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 libraries/GSM/src/GSMSSLClient.h diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 8643dcd2a..933054201 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -116,6 +116,7 @@ class GSMClass : public MbedSocketClass { extern GSMClass GSM; #include "GSMClient.h" +#include "GSMSSLClient.h" #include "GSMUdp.h" #endif diff --git a/libraries/GSM/src/GSMSSLClient.h b/libraries/GSM/src/GSMSSLClient.h new file mode 100644 index 000000000..92ae4206b --- /dev/null +++ b/libraries/GSM/src/GSMSSLClient.h @@ -0,0 +1,38 @@ +/* + GSMSSLClient.h + Copyright (c) 2023 Arduino SA. 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 GSMSSLCLIENT_H +#define GSMSSLCLIENT_H + +#include "GSM.h" +#include "MbedSSLClient.h" + +extern const char CA_CERTIFICATES[]; + +namespace arduino { + +class GSMSSLClient : public arduino::MbedSSLClient { + NetworkInterface *getNetwork() { + return GSM.getNetwork(); + } +}; + +} + +#endif /* GSMSSLCLIENT_H */ \ No newline at end of file From 99410c542ee9557ae976143c0710d8e97b537966 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 10:14:15 +0100 Subject: [PATCH 04/13] MbedClient add possibility to set socket timeout in constructor --- libraries/SocketWrapper/src/MbedClient.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/SocketWrapper/src/MbedClient.h b/libraries/SocketWrapper/src/MbedClient.h index a2132ebf3..eca0e5a34 100644 --- a/libraries/SocketWrapper/src/MbedClient.h +++ b/libraries/SocketWrapper/src/MbedClient.h @@ -49,6 +49,10 @@ class MbedClient : public arduino::Client { public: MbedClient(); + MbedClient(unsigned long timeout) { + _timeout = timeout; + } + // Copy constructor, to be used when a Client returned by server.available() // needs to "survive" event if it goes out of scope // Sample usage: Client* new_client = new Client(existing_client) From 414f56b8691b478e32f6a3e9ac0d08ca1a2cc353 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:10:44 +0100 Subject: [PATCH 05/13] MbedClient::connectSSL set timeout before TLS handshake starts --- libraries/SocketWrapper/src/MbedClient.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/SocketWrapper/src/MbedClient.cpp b/libraries/SocketWrapper/src/MbedClient.cpp index dfd856f77..49265c002 100644 --- a/libraries/SocketWrapper/src/MbedClient.cpp +++ b/libraries/SocketWrapper/src/MbedClient.cpp @@ -150,6 +150,11 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) { return 0; } + /* For TLS connection timeout needs to be configured before handshake starts + * otherwise socket timeout is not adopted. See TLSSocketWrapper::set_timeout(int timeout) + */ + sock->set_timeout(_timeout); + restart_connect: nsapi_error_t returnCode = static_cast(sock)->connect(socketAddress); int ret = 0; From f6303365cb88382c653ef0adbea100e48ef34779 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:13:52 +0100 Subject: [PATCH 06/13] MbedSSLClient add possibility to set socket timeout in constructor --- libraries/SocketWrapper/src/MbedSSLClient.cpp | 4 ++++ libraries/SocketWrapper/src/MbedSSLClient.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/libraries/SocketWrapper/src/MbedSSLClient.cpp b/libraries/SocketWrapper/src/MbedSSLClient.cpp index e0aa1d2dd..3233c8dba 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.cpp +++ b/libraries/SocketWrapper/src/MbedSSLClient.cpp @@ -1,5 +1,9 @@ #include "MbedSSLClient.h" +arduino::MbedSSLClient::MbedSSLClient(unsigned long timeout): MbedClient(timeout), _disableSNI{false} { + onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA)); +} + arduino::MbedSSLClient::MbedSSLClient(): _disableSNI{false} { onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA)); }; diff --git a/libraries/SocketWrapper/src/MbedSSLClient.h b/libraries/SocketWrapper/src/MbedSSLClient.h index c4705fc7b..4c010a684 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.h +++ b/libraries/SocketWrapper/src/MbedSSLClient.h @@ -33,6 +33,9 @@ class MbedSSLClient : public arduino::MbedClient { public: MbedSSLClient(); + + MbedSSLClient(unsigned long timeout); + virtual ~MbedSSLClient() { stop(); } From 566c6832dcd095f96c9bc74c054672a0b85db956 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:17:04 +0100 Subject: [PATCH 07/13] GSMClient: set default socket timeout --- libraries/GSM/src/GSMClient.cpp | 24 ++++++++++++++++++++++++ libraries/GSM/src/GSMClient.h | 4 ++++ libraries/GSM/src/GSMSSLClient.cpp | 24 ++++++++++++++++++++++++ libraries/GSM/src/GSMSSLClient.h | 4 ++++ 4 files changed, 56 insertions(+) create mode 100644 libraries/GSM/src/GSMClient.cpp create mode 100644 libraries/GSM/src/GSMSSLClient.cpp diff --git a/libraries/GSM/src/GSMClient.cpp b/libraries/GSM/src/GSMClient.cpp new file mode 100644 index 000000000..71043da70 --- /dev/null +++ b/libraries/GSM/src/GSMClient.cpp @@ -0,0 +1,24 @@ +/* + GSMClient.cpp + Copyright (c) 2023 Arduino SA. 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 +*/ + +#include "GSMClient.h" + +arduino::GSMClient::GSMClient(): MbedClient(100) { + +} diff --git a/libraries/GSM/src/GSMClient.h b/libraries/GSM/src/GSMClient.h index b2f4a9036..8ac465975 100644 --- a/libraries/GSM/src/GSMClient.h +++ b/libraries/GSM/src/GSMClient.h @@ -26,6 +26,10 @@ namespace arduino { class GSMClient : public MbedClient { +public: + GSMClient(); + +private: NetworkInterface *getNetwork() { return GSM.getNetwork(); } diff --git a/libraries/GSM/src/GSMSSLClient.cpp b/libraries/GSM/src/GSMSSLClient.cpp new file mode 100644 index 000000000..c953adb4f --- /dev/null +++ b/libraries/GSM/src/GSMSSLClient.cpp @@ -0,0 +1,24 @@ +/* + GSMSSLClient.cpp + Copyright (c) 2023 Arduino SA. 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 +*/ + +#include "GSMSSLClient.h" + +arduino::GSMSSLClient::GSMSSLClient(): MbedSSLClient(100) { + +} diff --git a/libraries/GSM/src/GSMSSLClient.h b/libraries/GSM/src/GSMSSLClient.h index 92ae4206b..2ea0ae713 100644 --- a/libraries/GSM/src/GSMSSLClient.h +++ b/libraries/GSM/src/GSMSSLClient.h @@ -28,6 +28,10 @@ extern const char CA_CERTIFICATES[]; namespace arduino { class GSMSSLClient : public arduino::MbedSSLClient { +public: + GSMSSLClient(); + +private: NetworkInterface *getNetwork() { return GSM.getNetwork(); } From 3f6204c2f2f47329ab527538b95f1442db2106ef Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:19:54 +0100 Subject: [PATCH 08/13] GSM: Add GSMSSLClient example --- .../examples/GSMSSLClient/GSMSSLClient.ino | 66 +++++++++++++++++++ .../examples/GSMSSLClient/arduino_secrets.h | 4 ++ 2 files changed, 70 insertions(+) create mode 100644 libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino create mode 100644 libraries/GSM/examples/GSMSSLClient/arduino_secrets.h diff --git a/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino b/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino new file mode 100644 index 000000000..5d35c7d62 --- /dev/null +++ b/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino @@ -0,0 +1,66 @@ +/* + GSMSSLlient + + This sketch connects to a website (https://ifconfig.me) + using the Portenta CAT.M1/NB IoT GNSS Shield and TLS. + + */ + +#include + +#include "arduino_secrets.h" +char pin[] = SECRET_PIN; +char apn[] = SECRET_APN; +char username[] = SECRET_USERNAME; +char pass[] = SECRET_PASSWORD; + +const char server[] = "ifconfig.me"; +const char* ip_address; +int port = 443; +GSMSSLClient client; + +void setup() { + Serial.begin(115200); + while(!Serial) {} + Serial.println("Starting Carrier Network registration"); + if(!GSM.begin(pin, apn, username, pass, CATM1, BAND_3 | BAND_20 | BAND_19)){ + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while(1); + } + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /ip HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("unable to connect to server"); + } + +} + +void loop() { + + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } + +} diff --git a/libraries/GSM/examples/GSMSSLClient/arduino_secrets.h b/libraries/GSM/examples/GSMSSLClient/arduino_secrets.h new file mode 100644 index 000000000..8c5842fa6 --- /dev/null +++ b/libraries/GSM/examples/GSMSSLClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" From 69c7ba0e41ac425784752ec0ebb029ab63d131a6 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 13:13:26 +0100 Subject: [PATCH 09/13] GSM: fix file headers --- libraries/GSM/src/GSM.cpp | 19 +++++++++++++++++++ libraries/GSM/src/GSM.h | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 78055aaf3..d8aaeab71 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -1,3 +1,22 @@ +/* + GSM.cpp - 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 +*/ + #include "GSM.h" #include "mbed.h" diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 933054201..0a25571c2 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -1,14 +1,17 @@ /* GSM.h - Library for GSM on mbed platforms. - Copyright (c) 2011-2021 Arduino LLC. All right reserved. + 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 From 10d0f1a6e82404b1c1c73b2c49cdd98d15fc9c1c Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 13:13:54 +0100 Subject: [PATCH 10/13] GSM: remove unused function --- libraries/GSM/src/GSM.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index d8aaeab71..8f37827eb 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -27,7 +27,6 @@ #define MAXRETRY 3 -bool _cmuxEnable = false; arduino::CMUXClass * arduino::CMUXClass::get_default_instance() { static mbed::UnbufferedSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200); From dadeba7577aff74c4174677fbda14a8f9de0ec86 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 15:06:50 +0100 Subject: [PATCH 11/13] GSM: rename debug() method into trace() * Move functions in a separate GSMTrace.cpp file * Add function to set trace level and enable/disable trace timestamps * Cleanup --- libraries/GSM/src/GSM.cpp | 46 -------------------- libraries/GSM/src/GSM.h | 3 +- libraries/GSM/src/GSMTrace.cpp | 79 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 libraries/GSM/src/GSMTrace.cpp diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 8f37827eb..700a33701 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -157,53 +157,7 @@ bool arduino::GSMClass::isConnected() } } -static PlatformMutex trace_mutex; -static void trace_wait() -{ - trace_mutex.lock(); -} - -static void trace_release() -{ - trace_mutex.unlock(); -} - -static char* trace_time(size_t ss) -{ - static char time_st[50]; - auto ms = std::chrono::time_point_cast(rtos::Kernel::Clock::now()).time_since_epoch().count(); - //snprintf(time_st, 49, "[%08llums]", ms); - snprintf(time_st, 1, "\n"); - return time_st; -} - -static Stream* trace_stream = nullptr; -static void arduino_print(const char* c) { - if (trace_stream) { - trace_stream->println(c); - } -} - -void arduino::GSMClass::debug(Stream& stream) { - -#if MBED_CONF_MBED_TRACE_ENABLE - - mbed_trace_init(); - - trace_stream = &stream; - mbed_trace_print_function_set(arduino_print); - mbed_trace_prefix_function_set( &trace_time ); - - mbed_trace_mutex_wait_function_set(trace_wait); - mbed_trace_mutex_release_function_set(trace_release); - - mbed_cellular_trace::mutex_wait_function_set(trace_wait); - mbed_cellular_trace::mutex_release_function_set(trace_release); - -#endif - -} NetworkInterface* arduino::GSMClass::getNetwork() { return _context; diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 0a25571c2..e9e95fc77 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -90,7 +90,8 @@ class GSMClass : public MbedSocketClass { bool setTime(unsigned long const epoch, int const timezone = 0); void enableCmux(); bool isCmuxEnable(); - void debug(Stream& stream); + void trace(Stream& stream); + void setTraceLevel(int trace_level, bool timestamp = false); int ping(const char* hostname, uint8_t ttl = 128); int ping(const String& hostname, uint8_t ttl = 128); int ping(IPAddress host, uint8_t ttl = 128); diff --git a/libraries/GSM/src/GSMTrace.cpp b/libraries/GSM/src/GSMTrace.cpp new file mode 100644 index 000000000..8c65e192a --- /dev/null +++ b/libraries/GSM/src/GSMTrace.cpp @@ -0,0 +1,79 @@ +/* + 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 +*/ + +#include +#include + +#if MBED_CONF_MBED_TRACE_ENABLE + +static Stream* trace_stream = nullptr; +static PlatformMutex trace_mutex; +static char trace_timestamp[8]; + +static void trace_wait() { + trace_mutex.lock(); +} + +static void trace_release() { + trace_mutex.unlock(); +} + +static char* trace_time(size_t ss) { + auto ms = std::chrono::time_point_cast(rtos::Kernel::Clock::now()).time_since_epoch().count(); + snprintf(trace_timestamp, 8, "[%08llu]", ms); + return trace_timestamp; +} + +static void trace_println(const char* c) { + if (trace_stream) { + trace_stream->println(c); + } +} +#endif + +void arduino::GSMClass::setTraceLevel(int trace_level, bool timestamp) { +#if MBED_CONF_MBED_TRACE_ENABLE + switch(trace_level) { + case 0: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE); break; + case 1: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_CMD); break; + case 2: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR); break; + case 3: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN); break; + case 4: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO); break; + case 5: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); break; + case 6: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); break; + default: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); break; + } + + if (timestamp) { + mbed_trace_prefix_function_set( &trace_time ); + } +#endif +} + +void arduino::GSMClass::trace(Stream& stream) { +#if MBED_CONF_MBED_TRACE_ENABLE + trace_stream = &stream; + + mbed_trace_init(); + mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); + mbed_trace_print_function_set(trace_println); + mbed_trace_mutex_wait_function_set(trace_wait); + mbed_trace_mutex_release_function_set(trace_release); +#endif +} From d0dce40b5d6cf0fc63cea626a2a4f5f5c20840d7 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 15:10:48 +0100 Subject: [PATCH 12/13] GSM: fix identation and spacing --- libraries/GSM/src/GSM.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 700a33701..9285ce838 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -21,13 +21,14 @@ #include "mbed.h" #include "CellularLog.h" +#include "CellularDevice.h" #include "CellularContext.h" #include "CellularInterface.h" #include "GEMALTO_CINTERION_CellularStack.h" #define MAXRETRY 3 -arduino::CMUXClass * arduino::CMUXClass::get_default_instance() +arduino::CMUXClass *arduino::CMUXClass::get_default_instance() { static mbed::UnbufferedSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200); serial.set_flow_control(mbed::SerialBase::RTSCTS_SW, MBED_CONF_GEMALTO_CINTERION_CTS, NC); @@ -37,11 +38,11 @@ arduino::CMUXClass * arduino::CMUXClass::get_default_instance() mbed::CellularDevice *mbed::CellularDevice::get_default_instance() { - static auto cmux = arduino::CMUXClass::get_default_instance(); - static mbed::GEMALTO_CINTERION device(cmux->get_serial(0)); - nextSerialPort++; - device.enableCMUXChannel = mbed::callback(cmux, &arduino::CMUXClass::enableCMUXChannel); - return &device; + static auto cmux = arduino::CMUXClass::get_default_instance(); + static mbed::GEMALTO_CINTERION device(cmux->get_serial(0)); + nextSerialPort++; + device.enableCMUXChannel = mbed::callback(cmux, &arduino::CMUXClass::enableCMUXChannel); + return &device; } int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat, uint32_t band, bool restart) { @@ -117,11 +118,11 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern return connect_status == NSAPI_ERROR_OK ? 1 : 0; } -void arduino::GSMClass::enableCmux(){ +void arduino::GSMClass::enableCmux() { _cmuxGSMenable = true; } -bool arduino::GSMClass::isCmuxEnable(){ +bool arduino::GSMClass::isCmuxEnable() { return _cmuxGSMenable; } From 6c87ca1c5db33f31ed80f97256792ed8243939bd Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 10 Nov 2023 17:13:00 +0100 Subject: [PATCH 13/13] GSM: use define for RESET and power ON pin --- libraries/GSM/src/GSM.cpp | 14 +++++++------- libraries/GSM/src/GSM.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 9285ce838..19305540b 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -48,14 +48,14 @@ mbed::CellularDevice *mbed::CellularDevice::get_default_instance() int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat, uint32_t band, bool restart) { if(restart || isCmuxEnable()) { - pinMode(PJ_10, OUTPUT); - digitalWrite(PJ_10, HIGH); + pinMode(MBED_CONF_GEMALTO_CINTERION_RST, OUTPUT); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_RST, HIGH); delay(800); - digitalWrite(PJ_10, LOW); - pinMode(PJ_7, OUTPUT); - digitalWrite(PJ_7, LOW); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_RST, LOW); + pinMode(MBED_CONF_GEMALTO_CINTERION_ON, OUTPUT); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_ON, LOW); delay(1); - digitalWrite(PJ_7, HIGH); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_ON, HIGH); delay(1); // this timer is to make sure that at boottime and when the CMUX is used, // ^SYSTART is received in time to avoid stranger behaviour @@ -69,7 +69,7 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern printf("Invalid context\n"); return 0; } - pinMode(PJ_7, INPUT_PULLDOWN); + pinMode(MBED_CONF_GEMALTO_CINTERION_ON, INPUT_PULLDOWN); static mbed::DigitalOut rts(MBED_CONF_GEMALTO_CINTERION_RTS, 0); diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index e9e95fc77..278cb1e92 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -37,6 +37,8 @@ #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 #define MBED_CONF_APP_SOCK_TYPE 1 #if defined __has_include