|
| 1 | +/* |
| 2 | + This file is part of the Arduino_ConnectionHandler library. |
| 3 | +
|
| 4 | + Copyright (c) 2024 Arduino SA |
| 5 | +
|
| 6 | + This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | +*/ |
| 10 | + |
| 11 | +#pragma once |
| 12 | + |
| 13 | +#include "ConnectionHandlerDefinitions.h" |
| 14 | +#include <stdint.h> |
| 15 | +#include <IPAddress.h> |
| 16 | + |
| 17 | +namespace models { |
| 18 | + constexpr size_t WifiSsidLength = 33; // Max length of wifi ssid is 32 + \0 |
| 19 | + constexpr size_t WifiPwdLength = 64; // Max length of wifi password is 63 + \0 |
| 20 | + |
| 21 | + constexpr size_t CellularPinLength = 9; |
| 22 | + constexpr size_t CellularApnLength = 101; // Max length of apn is 100 + \0 |
| 23 | + constexpr size_t CellularLoginLength = 65; |
| 24 | + constexpr size_t CellularPassLength = 65; |
| 25 | + |
| 26 | + constexpr size_t LoraAppeuiLength = 17; // appeui is 8 octets * 2 (hex format) + \0 |
| 27 | + constexpr size_t LoraAppkeyLength = 33; // appeui is 16 octets * 2 (hex format) + \0 |
| 28 | + constexpr size_t LoraChannelMaskLength = 13; |
| 29 | + |
| 30 | + #if defined(BOARD_HAS_WIFI) |
| 31 | + struct WiFiSetting { |
| 32 | + char ssid[WifiSsidLength]; |
| 33 | + char pwd[WifiPwdLength]; |
| 34 | + }; |
| 35 | + #endif //defined(BOARD_HAS_WIFI) |
| 36 | + |
| 37 | + #if defined(BOARD_HAS_ETHERNET) |
| 38 | + // this struct represents an ip address in its simplest form. |
| 39 | + // FIXME this should be available from ArduinoCore-api IPAddress |
| 40 | + struct ip_addr { |
| 41 | + IPType type; |
| 42 | + union { |
| 43 | + uint8_t bytes[16]; |
| 44 | + uint32_t dword[4]; |
| 45 | + }; |
| 46 | + }; |
| 47 | + |
| 48 | + struct EthernetSetting { |
| 49 | + ip_addr ip; |
| 50 | + ip_addr dns; |
| 51 | + ip_addr gateway; |
| 52 | + ip_addr netmask; |
| 53 | + unsigned long timeout; |
| 54 | + unsigned long response_timeout; |
| 55 | + }; |
| 56 | + #endif // BOARD_HAS_ETHERNET |
| 57 | + |
| 58 | + #if defined(BOARD_HAS_NB) || defined(BOARD_HAS_GSM) ||defined(BOARD_HAS_CELLULAR) |
| 59 | + struct CellularSetting { |
| 60 | + char pin[CellularPinLength]; |
| 61 | + char apn[CellularApnLength]; |
| 62 | + char login[CellularLoginLength]; |
| 63 | + char pass[CellularPassLength]; |
| 64 | + }; |
| 65 | + #endif // defined(BOARD_HAS_NB) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR) |
| 66 | + |
| 67 | + #if defined(BOARD_HAS_GSM) |
| 68 | + typedef CellularSetting GSMSetting; |
| 69 | + #endif //defined(BOARD_HAS_GSM) |
| 70 | + |
| 71 | + #if defined(BOARD_HAS_NB) |
| 72 | + typedef CellularSetting NBSetting; |
| 73 | + #endif //defined(BOARD_HAS_NB) |
| 74 | + |
| 75 | + #if defined(BOARD_HAS_CATM1_NBIOT) |
| 76 | + struct CATM1Setting { |
| 77 | + char pin[CellularPinLength]; |
| 78 | + char apn[CellularApnLength]; |
| 79 | + char login[CellularLoginLength]; |
| 80 | + char pass[CellularPassLength]; |
| 81 | + uint32_t band; |
| 82 | + uint8_t rat; |
| 83 | + }; |
| 84 | + #endif //defined(BOARD_HAS_CATM1_NBIOT) |
| 85 | + |
| 86 | +#if defined(BOARD_HAS_LORA) |
| 87 | + struct LoraSetting { |
| 88 | + char appeui[LoraAppeuiLength]; |
| 89 | + char appkey[LoraAppkeyLength]; |
| 90 | + uint8_t band; |
| 91 | + char channelMask[LoraChannelMaskLength]; |
| 92 | + uint8_t deviceClass; |
| 93 | + }; |
| 94 | +#endif |
| 95 | + |
| 96 | + struct NetworkSetting { |
| 97 | + NetworkAdapter type; |
| 98 | + union { |
| 99 | + #if defined(BOARD_HAS_WIFI) |
| 100 | + WiFiSetting wifi; |
| 101 | + #endif |
| 102 | + |
| 103 | + #if defined(BOARD_HAS_ETHERNET) |
| 104 | + EthernetSetting eth; |
| 105 | + #endif |
| 106 | + |
| 107 | + #if defined(BOARD_HAS_NB) |
| 108 | + NBSetting nb; |
| 109 | + #endif |
| 110 | + |
| 111 | + #if defined(BOARD_HAS_GSM) |
| 112 | + GSMSetting gsm; |
| 113 | + #endif |
| 114 | + |
| 115 | + #if defined(BOARD_HAS_CATM1_NBIOT) |
| 116 | + CATM1Setting catm1; |
| 117 | + #endif |
| 118 | + |
| 119 | + #if defined(BOARD_HAS_CELLULAR) |
| 120 | + CellularSetting cell; |
| 121 | + #endif |
| 122 | + |
| 123 | + #if defined(BOARD_HAS_LORA) |
| 124 | + LoraSetting lora; |
| 125 | + #endif |
| 126 | + }; |
| 127 | + }; |
| 128 | +} |
0 commit comments