Skip to content

Commit c784952

Browse files
defining interface settings in a struct
1 parent 8014ed9 commit c784952

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

src/settings/settings.h

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* This file is part of ArduinoIoTCloud.
3+
*
4+
* Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License version 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to license@arduino.cc.
16+
*/
17+
18+
#pragma once
19+
20+
#include "ConnectionHandlerDefinitions.h"
21+
#include <stdint.h>
22+
#include <IPAddress.h>
23+
24+
namespace models {
25+
constexpr size_t WifiSsidLength = 33; // Max length of wifi ssid is 32 + \0
26+
constexpr size_t WifiPwdLength = 64; // Max length of wifi password is 63 + \0
27+
28+
constexpr size_t CellularPinLength = 9;
29+
constexpr size_t CellularApnLength = 101; // Max length of apn is 100 + \0
30+
constexpr size_t CellularLoginLength = 65;
31+
constexpr size_t CellularPassLength = 65;
32+
33+
constexpr size_t LoraAppeuiLength = 17; // appeui is 8 octets * 2 (hex format) + \0
34+
constexpr size_t LoraAppkeyLength = 33; // appeui is 16 octets * 2 (hex format) + \0
35+
constexpr size_t LoraChannelMaskLength = 13;
36+
37+
#if defined(BOARD_HAS_WIFI)
38+
struct WiFiSetting {
39+
char ssid[WifiSsidLength];
40+
char pwd[WifiPwdLength];
41+
};
42+
#endif //defined(BOARD_HAS_WIFI)
43+
44+
#if defined(BOARD_HAS_ETHERNET)
45+
// this struct represents an ip address in its simplest form.
46+
// FIXME this should be available from ArduinoCore-api IPAddress
47+
struct ip_addr {
48+
IPType type;
49+
union {
50+
uint8_t bytes[16];
51+
uint32_t dword[4];
52+
};
53+
};
54+
55+
struct EthernetSetting {
56+
ip_addr ip;
57+
ip_addr dns;
58+
ip_addr gateway;
59+
ip_addr netmask;
60+
unsigned long timeout;
61+
unsigned long response_timeout;
62+
};
63+
#endif // BOARD_HAS_ETHERNET
64+
65+
#if defined(BOARD_HAS_NB) || defined(BOARD_HAS_GSM) ||defined(BOARD_HAS_CELLULAR)
66+
struct CellularSetting {
67+
char pin[CellularPinLength];
68+
char apn[CellularApnLength];
69+
char login[CellularLoginLength];
70+
char pass[CellularPassLength];
71+
};
72+
#endif // defined(BOARD_HAS_NB) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR)
73+
74+
#if defined(BOARD_HAS_GSM)
75+
typedef CellularSetting GSMSetting;
76+
#endif //defined(BOARD_HAS_GSM)
77+
78+
#if defined(BOARD_HAS_NB)
79+
typedef CellularSetting NBSetting;
80+
#endif //defined(BOARD_HAS_NB)
81+
82+
#if defined(BOARD_HAS_CATM1_NBIOT)
83+
struct CATM1Setting {
84+
char pin[CellularPinLength];
85+
char apn[CellularApnLength];
86+
char login[CellularLoginLength];
87+
char pass[CellularPassLength];
88+
uint32_t band;
89+
uint8_t rat;
90+
};
91+
#endif //defined(BOARD_HAS_CATM1_NBIOT)
92+
93+
#if defined(BOARD_HAS_LORA)
94+
struct LoraSetting {
95+
char appeui[LoraAppeuiLength];
96+
char appkey[LoraAppkeyLength];
97+
uint8_t band;
98+
char channelMask[LoraChannelMaskLength];
99+
uint8_t deviceClass;
100+
};
101+
#endif
102+
103+
struct NetworkSetting {
104+
NetworkAdapter type;
105+
union {
106+
#if defined(BOARD_HAS_WIFI)
107+
WiFiSetting wifi;
108+
#endif
109+
110+
#if defined(BOARD_HAS_ETHERNET)
111+
EthernetSetting eth;
112+
#endif
113+
114+
#if defined(BOARD_HAS_NB)
115+
NBSetting nb;
116+
#endif
117+
118+
#if defined(BOARD_HAS_GSM)
119+
GSMSetting gsm;
120+
#endif
121+
122+
#if defined(BOARD_HAS_CATM1_NBIOT)
123+
CATM1Setting catm1;
124+
#endif
125+
126+
#if defined(BOARD_HAS_CELLULAR)
127+
CellularSetting cell;
128+
#endif
129+
130+
#if defined(BOARD_HAS_LORA)
131+
LoraSetting lora;
132+
#endif
133+
};
134+
};
135+
}

0 commit comments

Comments
 (0)