Skip to content

Commit f674482

Browse files
adding a function to get the dafault initialization values for NetworkSetting
1 parent df2bfae commit f674482

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/settings/settings.h

+2
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ namespace models {
133133
};
134134
};
135135
}
136+
137+
#include "settings_default.h"

src/settings/settings_default.h

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
#include "settings.h"
13+
14+
namespace models {
15+
16+
/*
17+
* if the cpp version is older than cpp14 then a constexpr function cannot include
18+
* other than a simple return statement, thsu we can define it only as inline
19+
*/
20+
#if __cplusplus > 201103L
21+
constexpr NetworkSetting settingsDefault(NetworkAdapter type) {
22+
#else
23+
inline NetworkSetting settingsDefault(NetworkAdapter type) {
24+
#endif
25+
26+
NetworkSetting res = {type};
27+
28+
switch(type) {
29+
#if defined(BOARD_HAS_WIFI)
30+
case NetworkAdapter::WIFI: // nothing todo, default optional values are fine with 0
31+
break;
32+
#endif //defined(BOARD_HAS_WIFI)
33+
34+
#if defined(BOARD_HAS_NB)
35+
case NetworkAdapter::NB: // nothing todo, default optional values are fine with 0
36+
break;
37+
#endif //defined(BOARD_HAS_NB)
38+
39+
#if defined(BOARD_HAS_GSM)
40+
case NetworkAdapter::GSM: // nothing todo, default optional values are fine with 0
41+
break;
42+
#endif //defined(BOARD_HAS_GSM)
43+
44+
#if defined(BOARD_HAS_CELLULAR)
45+
case NetworkAdapter::CELL: // nothing todo, default optional values are fine with 0
46+
break;
47+
#endif //defined(BOARD_HAS_CELLULAR)
48+
49+
#if defined(BOARD_HAS_ETHERNET)
50+
case NetworkAdapter::ETHERNET:
51+
res.eth.timeout = 15000;
52+
res.eth.response_timeout = 4000;
53+
break;
54+
#endif //defined(BOARD_HAS_ETHERNET)
55+
56+
#if defined(BOARD_HAS_CATM1_NBIOT)
57+
case NetworkAdapter::CATM1:
58+
res.catm1.rat = 7; // CATM1
59+
res.catm1.band = 0x04 | 0x80000 | 0x40000; // BAND_3 | BAND_20 | BAND_19
60+
break;
61+
#endif //defined(BOARD_HAS_CATM1_NBIOT)
62+
63+
#if defined(BOARD_HAS_LORA)
64+
case NetworkAdapter::LORA:
65+
res.lora.band = 5; // _lora_band::EU868
66+
res.lora.channelMask[0] = '\0';
67+
res.lora.deviceClass = 'A'; // _lora_class::CLASS_A
68+
break;
69+
#endif //defined(BOARD_HAS_LORA)
70+
}
71+
72+
return res;
73+
}
74+
}

0 commit comments

Comments
 (0)