diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index b4f8e315..bb4c0e64 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -27,288 +27,34 @@ #endif #include +#include "ConnectionHandlerDefinitions.h" -#ifdef ARDUINO_SAMD_MKR1000 - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED -#endif - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ - defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_MODULE - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION -#endif - -#if defined(ARDUINO_PORTENTA_H7_M7) - #include - #include - #include - #include - #include - #include - - #define BOARD_HAS_WIFI - #define BOARD_HAS_ETHERNET - #define BOARD_HAS_CATM1_NBIOT - #define BOARD_HAS_CELLULAR - #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD - #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_PORTENTA_C33) - #include - #include - #include - #include - #include - - #define BOARD_HAS_WIFI - #define BOARD_HAS_ETHERNET - #define BOARD_HAS_CELLULAR - #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_NICLA_VISION) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_OPTA) - #include - #include - #include - #include - - #define BOARD_HAS_WIFI - #define BOARD_HAS_ETHERNET - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_GIGA) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#ifdef ARDUINO_SAMD_MKRGSM1400 - #include - #define BOARD_HAS_GSM - #define NETWORK_HARDWARE_ERROR GPRS_PING_ERROR - #define NETWORK_IDLE_STATUS GSM3_NetworkStatus_t::IDLE - #define NETWORK_CONNECTED GSM3_NetworkStatus_t::GPRS_READY -#endif - -#ifdef ARDUINO_SAMD_MKRNB1500 - #include - #define BOARD_HAS_NB - #define NETWORK_HARDWARE_ERROR - #define NETWORK_IDLE_STATUS NB_NetworkStatus_t::IDLE - #define NETWORK_CONNECTED NB_NetworkStatus_t::GPRS_READY -#endif - -#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) - #include - #define BOARD_HAS_LORA -#endif - -#if defined(ARDUINO_ARCH_ESP8266) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED -#endif - -#if defined(ARDUINO_ARCH_ESP32) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED -#endif - -#if defined(ARDUINO_UNOR4_WIFI) - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION +#if defined(BOARD_HAS_WIFI) + #include "WiFiConnectionHandler.h" #endif -#ifdef ARDUINO_EDGE_CONTROL - #include - #define BOARD_HAS_CATM1_NBIOT - #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD - #define NETWORK_HARDWARE_ERROR +#if defined(BOARD_HAS_GSM) + #include "GSMConnectionHandler.h" #endif -/****************************************************************************** - TYPEDEFS - ******************************************************************************/ - -enum class NetworkConnectionState : unsigned int { - INIT = 0, - CONNECTING = 1, - CONNECTED = 2, - DISCONNECTING = 3, - DISCONNECTED = 4, - CLOSED = 5, - ERROR = 6 -}; - -enum class NetworkConnectionEvent { - CONNECTED, - DISCONNECTED, - ERROR -}; - -enum class NetworkAdapter { - WIFI, - ETHERNET, - NB, - GSM, - LORA, - CATM1, - CELL -}; - -typedef void (*OnNetworkEventCallback)(); - -/****************************************************************************** - CONSTANTS - ******************************************************************************/ - -static unsigned int const CHECK_INTERVAL_TABLE[] = -{ - /* INIT */ 100, -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - /* CONNECTING */ 4000, -#else - /* CONNECTING */ 500, +#if defined(BOARD_HAS_NB) + #include "NBConnectionHandler.h" #endif - /* CONNECTED */ 10000, - /* DISCONNECTING */ 100, - /* DISCONNECTED */ 1000, - /* CLOSED */ 1000, - /* ERROR */ 1000 -}; - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ -class ConnectionHandler { - public: - - ConnectionHandler(bool const keep_alive, NetworkAdapter interface); - - - NetworkConnectionState check(); - - #if !defined(BOARD_HAS_LORA) - virtual unsigned long getTime() = 0; - virtual Client &getClient() = 0; - virtual UDP &getUDP() = 0; - #else - virtual int write(const uint8_t *buf, size_t size) = 0; - virtual int read() = 0; - virtual bool available() = 0; - #endif - - NetworkConnectionState getStatus() __attribute__((deprecated)) { - return _current_net_connection_state; - } - - NetworkAdapter getInterface() { - return _interface; - } - - void connect(); - void disconnect(); - - void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback); - void addConnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); - void addDisconnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); - void addErrorCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); - - protected: - - bool _keep_alive; - NetworkAdapter _interface; - - virtual NetworkConnectionState update_handleInit () = 0; - virtual NetworkConnectionState update_handleConnecting () = 0; - virtual NetworkConnectionState update_handleConnected () = 0; - virtual NetworkConnectionState update_handleDisconnecting() = 0; - virtual NetworkConnectionState update_handleDisconnected () = 0; - - - private: - - unsigned long _lastConnectionTickTime; - NetworkConnectionState _current_net_connection_state; - OnNetworkEventCallback _on_connect_event_callback = NULL, - _on_disconnect_event_callback = NULL, - _on_error_event_callback = NULL; -}; - -#if defined(BOARD_HAS_WIFI) - #include "Arduino_WiFiConnectionHandler.h" -#elif defined(BOARD_HAS_GSM) - #include "Arduino_GSMConnectionHandler.h" -#elif defined(BOARD_HAS_NB) - #include "Arduino_NBConnectionHandler.h" -#elif defined(BOARD_HAS_LORA) - #include "Arduino_LoRaConnectionHandler.h" +#if defined(BOARD_HAS_LORA) + #include "LoRaConnectionHandler.h" #endif #if defined(BOARD_HAS_ETHERNET) - #include "Arduino_EthernetConnectionHandler.h" + #include "EthernetConnectionHandler.h" #endif #if defined(BOARD_HAS_CATM1_NBIOT) - #include "Arduino_CatM1ConnectionHandler.h" + #include "CatM1ConnectionHandler.h" #endif #if defined(BOARD_HAS_CELLULAR) - #include "Arduino_CellularConnectionHandler.h" + #include "CellularConnectionHandler.h" #endif #endif /* CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp similarity index 96% rename from src/Arduino_CatM1ConnectionHandler.cpp rename to src/CatM1ConnectionHandler.cpp index 0b99716d..0263a397 100644 --- a/src/Arduino_CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_CatM1ConnectionHandler.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ +#include "CatM1ConnectionHandler.h" /****************************************************************************** CTOR/DTOR @@ -96,7 +97,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected() } else { - return NetworkConnectionState::CLOSED; + return NetworkConnectionState::CLOSED; } } diff --git a/src/Arduino_CatM1ConnectionHandler.h b/src/CatM1ConnectionHandler.h similarity index 91% rename from src/Arduino_CatM1ConnectionHandler.h rename to src/CatM1ConnectionHandler.h index de5fd01f..33ac9fea 100644 --- a/src/Arduino_CatM1ConnectionHandler.h +++ b/src/CatM1ConnectionHandler.h @@ -22,10 +22,15 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "ConnectionHandlerInterface.h" +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_EDGE_CONTROL) + #include +#endif -#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ +#ifndef BOARD_HAS_CATM1_NBIOT + #error "Board doesn't support CATM1_NBIOT" +#endif /****************************************************************************** CLASS DECLARATION @@ -66,6 +71,4 @@ class CatM1ConnectionHandler : public ConnectionHandler GSMClient _gsm_client; }; -#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */ - #endif /* #ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp similarity index 97% rename from src/Arduino_CellularConnectionHandler.cpp rename to src/CellularConnectionHandler.cpp index 7e543b0e..2e4499a0 100644 --- a/src/Arduino_CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -13,9 +13,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_CellularConnectionHandler.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ +#include "CellularConnectionHandler.h" /****************************************************************************** CTOR/DTOR diff --git a/src/Arduino_CellularConnectionHandler.h b/src/CellularConnectionHandler.h similarity index 90% rename from src/Arduino_CellularConnectionHandler.h rename to src/CellularConnectionHandler.h index 0c4d5f89..048c9f74 100644 --- a/src/Arduino_CellularConnectionHandler.h +++ b/src/CellularConnectionHandler.h @@ -18,12 +18,19 @@ #include "Arduino_ConnectionHandler.h" -#ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ /****************************************************************************** CLASS DECLARATION ******************************************************************************/ +#if defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_PORTENTA_H7_M7) +#include +#endif + +#ifndef BOARD_HAS_CELLULAR + #error "Board doesn't support CELLULAR" +#endif + class CellularConnectionHandler : public ConnectionHandler { public: @@ -56,6 +63,4 @@ class CellularConnectionHandler : public ConnectionHandler TinyGsmClient _gsm_client = _cellular.getNetworkClient(); }; -#endif /* #ifdef BOARD_HAS_CELLULAR */ - #endif /* #ifndef ARDUINO_CELLULAR_CONNECTION_HANDLER_H_ */ diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h new file mode 100644 index 00000000..3fdde169 --- /dev/null +++ b/src/ConnectionHandlerDefinitions.h @@ -0,0 +1,186 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#pragma once + +/****************************************************************************** + INCLUDES + ******************************************************************************/ + +#include + +#ifdef ARDUINO_SAMD_MKR1000 + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED +#endif + +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_MODULE + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION +#endif + +#if defined(ARDUINO_PORTENTA_H7_M7) + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define BOARD_HAS_CATM1_NBIOT + #define BOARD_HAS_CELLULAR + #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD + #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_PORTENTA_C33) + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define BOARD_HAS_CELLULAR + #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_NICLA_VISION) + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_OPTA) + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_GIGA) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#ifdef ARDUINO_SAMD_MKRGSM1400 + #define BOARD_HAS_GSM + #define NETWORK_HARDWARE_ERROR GPRS_PING_ERROR + #define NETWORK_IDLE_STATUS GSM3_NetworkStatus_t::IDLE + #define NETWORK_CONNECTED GSM3_NetworkStatus_t::GPRS_READY +#endif + +#ifdef ARDUINO_SAMD_MKRNB1500 + #define BOARD_HAS_NB + #define NETWORK_HARDWARE_ERROR + #define NETWORK_IDLE_STATUS NB_NetworkStatus_t::IDLE + #define NETWORK_CONNECTED NB_NetworkStatus_t::GPRS_READY +#endif + +#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) + #define BOARD_HAS_LORA +#endif + +#if defined(ARDUINO_ARCH_ESP8266) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED +#endif + +#if defined(ARDUINO_ARCH_ESP32) + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED +#endif + +#if defined(ARDUINO_UNOR4_WIFI) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION +#endif + +#ifdef ARDUINO_EDGE_CONTROL + #define BOARD_HAS_CATM1_NBIOT + #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD + #define NETWORK_HARDWARE_ERROR +#endif + +/****************************************************************************** + TYPEDEFS + ******************************************************************************/ + +enum class NetworkConnectionState : unsigned int { + INIT = 0, + CONNECTING = 1, + CONNECTED = 2, + DISCONNECTING = 3, + DISCONNECTED = 4, + CLOSED = 5, + ERROR = 6 +}; + +enum class NetworkConnectionEvent { + CONNECTED, + DISCONNECTED, + ERROR +}; + +enum class NetworkAdapter { + WIFI, + ETHERNET, + NB, + GSM, + LORA, + CATM1, + CELL +}; + +/****************************************************************************** + CONSTANTS + ******************************************************************************/ + +static unsigned int const CHECK_INTERVAL_TABLE[] = +{ + /* INIT */ 100, +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + /* CONNECTING */ 4000, +#else + /* CONNECTING */ 500, +#endif + /* CONNECTED */ 10000, + /* DISCONNECTING */ 100, + /* DISCONNECTED */ 1000, + /* CLOSED */ 1000, + /* ERROR */ 1000 +}; diff --git a/src/Arduino_ConnectionHandler.cpp b/src/ConnectionHandlerInterface.cpp similarity index 99% rename from src/Arduino_ConnectionHandler.cpp rename to src/ConnectionHandlerInterface.cpp index ab83fa08..2fdc10e1 100644 --- a/src/Arduino_ConnectionHandler.cpp +++ b/src/ConnectionHandlerInterface.cpp @@ -19,7 +19,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "ConnectionHandlerInterface.h" /****************************************************************************** CONSTRUCTOR/DESTRUCTOR diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h new file mode 100644 index 00000000..94768ea8 --- /dev/null +++ b/src/ConnectionHandlerInterface.h @@ -0,0 +1,99 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#pragma once + +/****************************************************************************** + INCLUDES + ******************************************************************************/ + +#if !defined(__AVR__) +# include +#endif + +#include +#include +#include +#include "ConnectionHandlerDefinitions.h" + +/****************************************************************************** + TYPEDEFS + ******************************************************************************/ + +typedef void (*OnNetworkEventCallback)(); + +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + +class ConnectionHandler { + public: + + ConnectionHandler(bool const keep_alive, NetworkAdapter interface); + + + NetworkConnectionState check(); + + #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) + virtual unsigned long getTime() = 0; + virtual Client &getClient() = 0; + virtual UDP &getUDP() = 0; + #endif + + #if defined(BOARD_HAS_LORA) + virtual int write(const uint8_t *buf, size_t size) = 0; + virtual int read() = 0; + virtual bool available() = 0; + #endif + + NetworkConnectionState getStatus() __attribute__((deprecated)) { + return _current_net_connection_state; + } + + NetworkAdapter getInterface() { + return _interface; + } + + void connect(); + void disconnect(); + + void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback); + void addConnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); + void addDisconnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); + void addErrorCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); + + protected: + + bool _keep_alive; + NetworkAdapter _interface; + + virtual NetworkConnectionState update_handleInit () = 0; + virtual NetworkConnectionState update_handleConnecting () = 0; + virtual NetworkConnectionState update_handleConnected () = 0; + virtual NetworkConnectionState update_handleDisconnecting() = 0; + virtual NetworkConnectionState update_handleDisconnected () = 0; + + + private: + + unsigned long _lastConnectionTickTime; + NetworkConnectionState _current_net_connection_state; + OnNetworkEventCallback _on_connect_event_callback = NULL, + _on_disconnect_event_callback = NULL, + _on_error_event_callback = NULL; +}; + diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp similarity index 98% rename from src/Arduino_EthernetConnectionHandler.cpp rename to src/EthernetConnectionHandler.cpp index 0fa2e254..14f7aee4 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -16,9 +16,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_EthernetConnectionHandler.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ +#include "EthernetConnectionHandler.h" /****************************************************************************** CTOR/DTOR diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/EthernetConnectionHandler.h similarity index 87% rename from src/Arduino_EthernetConnectionHandler.h rename to src/EthernetConnectionHandler.h index cc22bfee..35a02cd9 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/EthernetConnectionHandler.h @@ -19,9 +19,22 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" - -#ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ +#include "ConnectionHandlerInterface.h" + +#if defined(ARDUINO_PORTENTA_H7_M7) + #include + #include +#elif defined(ARDUINO_PORTENTA_C33) + #include + #include +#elif defined(ARDUINO_OPTA) + #include + #include +#endif + +#ifndef BOARD_HAS_ETHERNET + #error "Board doesn't support ETHERNET" +#endif /****************************************************************************** CLASS DECLARATION @@ -64,6 +77,4 @@ class EthernetConnectionHandler : public ConnectionHandler }; -#endif /* #ifdef BOARD_HAS_ETHERNET */ - #endif /* ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/GSMConnectionHandler.cpp similarity index 98% rename from src/Arduino_GSMConnectionHandler.cpp rename to src/GSMConnectionHandler.cpp index e57a7201..34bf1792 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/GSMConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_GSMConnectionHandler.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_GSM /* Only compile if this is a board with GSM */ +#include "GSMConnectionHandler.h" /****************************************************************************** CONSTANTS diff --git a/src/Arduino_GSMConnectionHandler.h b/src/GSMConnectionHandler.h similarity index 92% rename from src/Arduino_GSMConnectionHandler.h rename to src/GSMConnectionHandler.h index 714ed8c5..1f3db49a 100644 --- a/src/Arduino_GSMConnectionHandler.h +++ b/src/GSMConnectionHandler.h @@ -22,10 +22,15 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "ConnectionHandlerInterface.h" +#if defined(ARDUINO_SAMD_MKRGSM1400) + #include +#endif -#ifdef BOARD_HAS_GSM /* Only compile if this is a board with GSM */ +#ifndef BOARD_HAS_GSM + #error "Board doesn't support GSM" +#endif /****************************************************************************** CLASS DECLARATION @@ -65,6 +70,4 @@ class GSMConnectionHandler : public ConnectionHandler GSMClient _gsm_client; }; -#endif /* #ifdef BOARD_HAS_GSM */ - #endif /* #ifndef GSM_CONNECTION_MANAGER_H_ */ diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/LoRaConnectionHandler.cpp similarity index 98% rename from src/Arduino_LoRaConnectionHandler.cpp rename to src/LoRaConnectionHandler.cpp index cf1deaf0..1f454a51 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/LoRaConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_LoRaConnectionHandler.h" +#include "ConnectionHandlerDefinitions.h" #if defined(BOARD_HAS_LORA) /* Only compile if the board has LoRa */ +#include "LoRaConnectionHandler.h" /****************************************************************************** TYPEDEF diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/LoRaConnectionHandler.h similarity index 93% rename from src/Arduino_LoRaConnectionHandler.h rename to src/LoRaConnectionHandler.h index aa769ab5..3ddcca24 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/LoRaConnectionHandler.h @@ -22,9 +22,16 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "ConnectionHandlerInterface.h" + +#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) + #include +#endif + +#ifndef BOARD_HAS_LORA + #error "Board doesn't support LORA" +#endif -#ifdef BOARD_HAS_LORA /* Only compile if the board has LoRa */ /****************************************************************************** CLASS DECLARATION @@ -74,6 +81,4 @@ class LoRaConnectionHandler : public ConnectionHandler LoRaModem _modem; }; -#endif /* #ifdef BOARD_HAS_LORA */ - #endif /* ARDUINO_LORA_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/NBConnectionHandler.cpp similarity index 98% rename from src/Arduino_NBConnectionHandler.cpp rename to src/NBConnectionHandler.cpp index 344e104f..eb72f3e7 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/NBConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_NBConnectionHandler.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_NB /* Only compile if this is a board with NB */ +#include "NBConnectionHandler.h" /****************************************************************************** CONSTANTS diff --git a/src/Arduino_NBConnectionHandler.h b/src/NBConnectionHandler.h similarity index 93% rename from src/Arduino_NBConnectionHandler.h rename to src/NBConnectionHandler.h index 53d2174e..fd2afb6c 100644 --- a/src/Arduino_NBConnectionHandler.h +++ b/src/NBConnectionHandler.h @@ -22,9 +22,15 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "ConnectionHandlerInterface.h" -#ifdef BOARD_HAS_NB /* Only compile if this is a board with NB */ +#ifdef ARDUINO_SAMD_MKRNB1500 + #include +#endif + +#ifndef BOARD_HAS_NB + #error "Board doesn't support NB" +#endif /****************************************************************************** CLASS DECLARATION @@ -68,6 +74,4 @@ class NBConnectionHandler : public ConnectionHandler NBClient _nb_client; }; -#endif /* #ifdef BOARD_HAS_NB */ - #endif /* #ifndef NB_CONNECTION_MANAGER_H_ */ diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp similarity index 98% rename from src/Arduino_WiFiConnectionHandler.cpp rename to src/WiFiConnectionHandler.cpp index 902b53f0..0cd2e126 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_WiFiConnectionHandler.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */ +#include "WiFiConnectionHandler.h" /****************************************************************************** CONSTANTS @@ -143,7 +144,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() Debug.print(DBG_INFO, F("Attempting reconnection")); #endif } - + return NetworkConnectionState::DISCONNECTED; } return NetworkConnectionState::CONNECTED; diff --git a/src/Arduino_WiFiConnectionHandler.h b/src/WiFiConnectionHandler.h similarity index 69% rename from src/Arduino_WiFiConnectionHandler.h rename to src/WiFiConnectionHandler.h index bf16fa06..e5e2e25d 100644 --- a/src/Arduino_WiFiConnectionHandler.h +++ b/src/WiFiConnectionHandler.h @@ -22,9 +22,35 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" - -#ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */ +#include "ConnectionHandlerInterface.h" + +#ifdef ARDUINO_SAMD_MKR1000 + #include + #include +#elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) + #include + #include +#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M7) || \ + defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) + #include + #include +#elif defined(ARDUINO_PORTENTA_C33) + #include + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include + #include +#elif defined(ARDUINO_UNOR4_WIFI) + #include +#endif + +#ifndef BOARD_HAS_WIFI + #error "Board doesn't support WIFI" +#endif /****************************************************************************** CLASS DECLARATION @@ -59,6 +85,4 @@ class WiFiConnectionHandler : public ConnectionHandler WiFiClient _wifi_client; }; -#endif /* #ifdef BOARD_HAS_WIFI */ - #endif /* ARDUINO_WIFI_CONNECTION_HANDLER_H_ */