|
| 1 | +/* |
| 2 | + This file is part of ArduinoIoTCloud. |
| 3 | + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 4 | + This software is released under the GNU General Public License version 3, |
| 5 | + which covers the main part of arduino-cli. |
| 6 | + The terms of this license can be found at: |
| 7 | + https://www.gnu.org/licenses/gpl-3.0.en.html |
| 8 | + You can be released from the requirements of the above licenses by purchasing |
| 9 | + a commercial license. Buying such a license is mandatory if you want to modify or |
| 10 | + otherwise use the software for commercial activities involving the Arduino |
| 11 | + software without disclosing the source code of your own applications. To purchase |
| 12 | + a commercial license, send an email to [email protected]. |
| 13 | +*/ |
| 14 | + |
| 15 | +/****************************************************************************** |
| 16 | + INCLUDE |
| 17 | + ******************************************************************************/ |
| 18 | + |
| 19 | +#include "Arduino_ConnectionHandler.h" |
| 20 | +#include "GenericConnectionHandler.h" |
| 21 | + |
| 22 | +void GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) { |
| 23 | + |
| 24 | + switch(s.type) { |
| 25 | + #if defined(BOARD_HAS_WIFI) |
| 26 | + case WIFI: |
| 27 | + _ch = new WiFiConnectionHandler(); |
| 28 | + break; |
| 29 | + #endif |
| 30 | + |
| 31 | + #if defined(BOARD_HAS_ETHERNET) |
| 32 | + case ETHERNET: |
| 33 | + _ch = new EthernetConnectionHandler(); |
| 34 | + break; |
| 35 | + #endif |
| 36 | + |
| 37 | + #if defined(BOARD_HAS_NB) |
| 38 | + case NB: |
| 39 | + _ch = new NBConnectionHandler(); |
| 40 | + break; |
| 41 | + #endif |
| 42 | + |
| 43 | + #if defined(BOARD_HAS_GSM) |
| 44 | + case GSM: |
| 45 | + _ch = new GSMConnectionHandler(); |
| 46 | + break; |
| 47 | + #endif |
| 48 | + |
| 49 | + #if defined(BOARD_HAS_CATM1_NBIOT) |
| 50 | + case CATM1: |
| 51 | + _ch = new CatM1ConnectionHandler(); |
| 52 | + break; |
| 53 | + #endif |
| 54 | + |
| 55 | + #if defined(BOARD_HAS_CELLULAR) |
| 56 | + case CELL: |
| 57 | + _ch = new CellularConnectionHandler(); |
| 58 | + break; |
| 59 | + #endif |
| 60 | + |
| 61 | + #if defined(BOARD_HAS_NOTECARD) // FIXME understand how to adapt it to the settings structure |
| 62 | + case NOTECARD: |
| 63 | + _ch = new NotecardConnectionHandler(); |
| 64 | + break; |
| 65 | + #endif |
| 66 | + |
| 67 | + default: |
| 68 | + Debug.print(DBG_ERROR, "Network adapter not supported by this platform: %d", s.type); |
| 69 | + return; |
| 70 | + } |
| 71 | + _ch->updateSetting(s); |
| 72 | +} |
| 73 | + |
| 74 | +NetworkConnectionState GenericConnectionHandler::update_handleInit() { |
| 75 | + return _ch != nullptr ? _ch->update_handleInit() : INIT; |
| 76 | +} |
| 77 | + |
| 78 | +NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() { |
| 79 | + return _ch != nullptr ? _ch->update_handleDisconnecting() : INIT; |
| 80 | +} |
| 81 | + |
| 82 | + |
| 83 | +NetworkConnectionState GenericConnectionHandler::update_handleConnected() { |
| 84 | + return _ch != nullptr ? _ch->update_handleConnected() : INIT; |
| 85 | +} |
| 86 | + |
| 87 | +NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() { |
| 88 | + return _ch != nullptr ? _ch->update_handleDisconnecting() : INIT; |
| 89 | +} |
| 90 | + |
| 91 | +NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() { |
| 92 | + return _ch != nullptr ? _ch->update_handleDisconnected() : INIT; |
| 93 | +} |
0 commit comments