Skip to content

Commit f34627d

Browse files
adding a function to get the dafault initialization values for NetworkSetting
1 parent 4b9301c commit f34627d

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/settings/settings.h

+2
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,5 @@ namespace models {
126126
};
127127
};
128128
}
129+
130+
#include "settings_default.h"

src/settings/settings_default.h

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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_ETHERNET)
30+
case NetworkAdapter::ETHERNET:
31+
res.eth.timeout = 15000;
32+
res.eth.response_timeout = 4000;
33+
break;
34+
#endif //defined(BOARD_HAS_ETHERNET)
35+
36+
#if defined(BOARD_HAS_CATM1_NBIOT)
37+
case NetworkAdapter::CATM1:
38+
res.catm1.rat = 7; // CATM1
39+
res.catm1.band = 0x04 | 0x80000 | 0x40000; // BAND_3 | BAND_20 | BAND_19
40+
break;
41+
#endif //defined(BOARD_HAS_CATM1_NBIOT)
42+
43+
#if defined(BOARD_HAS_LORA)
44+
case NetworkAdapter::LORA:
45+
res.lora.band = 5; // _lora_band::EU868
46+
res.lora.channelMask[0] = '\0';
47+
res.lora.deviceClass = 'A'; // _lora_class::CLASS_A
48+
break;
49+
#endif //defined(BOARD_HAS_LORA)
50+
51+
#if defined(BOARD_HAS_WIFI)
52+
case NetworkAdapter::WIFI: // nothing todo, default optional values are fine with 0
53+
#endif //defined(BOARD_HAS_WIFI)
54+
55+
#if defined(BOARD_HAS_NB)
56+
case NetworkAdapter::NB: // nothing todo, default optional values are fine with 0
57+
#endif //defined(BOARD_HAS_NB)
58+
59+
#if defined(BOARD_HAS_GSM)
60+
case NetworkAdapter::GSM: // nothing todo, default optional values are fine with 0
61+
#endif //defined(BOARD_HAS_GSM)
62+
63+
#if defined(BOARD_HAS_CELLULAR)
64+
case NetworkAdapter::CELL: // nothing todo, default optional values are fine with 0
65+
#endif //defined(BOARD_HAS_CELLULAR)
66+
default:
67+
(void) 0;
68+
}
69+
70+
return res;
71+
}
72+
}

0 commit comments

Comments
 (0)