Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
NetworkInfo.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_CHANNELS_NETWORKINFO_HPP_
2#define IV_SRC_CHANNELS_NETWORKINFO_HPP_
3
5#include "comms/enums.hpp"
6
7#include <memory>
8
9namespace iv::channels
10{
11
12class INetworkInfo;
13
14static std::shared_ptr<iv::channels::INetworkInfo> createNetworkType(iv::comms::eProtocolType protocolType,
15 const iv::types::networkId &networkId);
16
18{
19public:
20 enum class eDirection
21 {
22 In,
23 Out
24 };
25
26 virtual ~INetworkInfo() = default;
27
28 static std::shared_ptr<INetworkInfo> loadStatic(const iv::file::xml::node &nodeNetwork)
29 {
30 std::shared_ptr<INetworkInfo> networkInfo {nullptr};
31 auto protocolType = magic_enum::enum_cast<iv::comms::eProtocolType>(
33
34 if (protocolType.has_value())
35 {
37 networkInfo->load(nodeNetwork);
38 }
39
40 return networkInfo;
41 }
42
43 virtual void update(const std::shared_ptr<INetworkInfo> &other)
44 {
45 m_protocolType = other->m_protocolType;
46 m_nameNetwork = other->m_nameNetwork;
47 m_direction = other->m_direction;
48 }
49
50 virtual bool save(iv::file::xml::node &nodeNetwork) const
51 {
52 nodeNetwork.addAttribute(Keys::protocol, magic_enum::enum_name(m_protocolType));
54 nodeNetwork.addAttribute(Keys::direction, magic_enum::enum_name(m_direction));
55 return true;
56 }
57
59 {
60 return m_nameNetwork;
61 }
62
64 {
65 return m_protocolType;
66 }
67
68 [[nodiscard]] eDirection direction() const
69 {
70 return m_direction;
71 }
72
74
75protected:
76 virtual bool load(const iv::file::xml::node &nodeNetwork)
77 {
78 m_protocolType = magic_enum::enum_cast<iv::comms::eProtocolType>(
82 m_direction = magic_enum::enum_cast<iv::channels::INetworkInfo::eDirection>(
84 .value_or(DefaultValues::direction);
85
86 return true;
87 }
88
91
92private:
93 struct Keys
94 {
95 static constexpr std::string_view protocol {"Type"};
96 static constexpr std::string_view nameNetwork {"Name"};
97 static constexpr std::string_view direction {"Direction"};
98 };
99
107};
108
109class J1939NetworkInfo final : public INetworkInfo
110{
111public:
112 explicit J1939NetworkInfo(const iv::types::networkId &networkId);
113
114 void update(const std::shared_ptr<INetworkInfo> &other) override;
115 bool load(const iv::file::xml::node &nodeNetwork) override;
116 bool save(iv::file::xml::node &nodeNetwork) const override;
117
119 {
120 return m_info;
121 }
122
123private:
125
126 struct Sections
127 {
128 static constexpr std::string_view registerInfo {"J1939RegisterInfo"};
129 };
130};
131
132class ModbusNetworkInfo final : public INetworkInfo
133{
134public:
135 explicit ModbusNetworkInfo(const iv::types::networkId &networkId);
136
137 void update(const std::shared_ptr<INetworkInfo> &other) override;
138 bool load(const iv::file::xml::node &nodeNetwork) override;
139 bool save(iv::file::xml::node &nodeNetwork) const override;
140
145
147
148private:
149 struct Sections
150 {
151 static constexpr std::string_view registerInfo {"ModbusChannelInfo"};
152 };
153};
154
156{
157public:
158 explicit Nmea0183NetworkInfo(const iv::types::networkId &networkId);
159
160 void update(const std::shared_ptr<INetworkInfo> &other) override;
161 bool load(const iv::file::xml::node &nodeNetwork) override;
162 bool save(iv::file::xml::node &nodeNetwork) const override;
163
168
170
171private:
172 struct Sections
173 {
174 static constexpr std::string_view registerInfo {"Nmea0183RegisterInfo"};
175 };
176};
177
178class Nmea2kNetworkInfo final : public INetworkInfo
179{
180public:
181 explicit Nmea2kNetworkInfo(const iv::types::networkId &networkId);
182
183 void update(const std::shared_ptr<INetworkInfo> &other) override;
184 bool load(const iv::file::xml::node &nodeNetwork) override;
185 bool save(iv::file::xml::node &nodeNetwork) const override;
186
191
193
194private:
195 struct Sections
196 {
197 static constexpr std::string_view registerInfo {"Nmea2kRegisterInfo"};
198 };
199};
200
201class VdrNetworkInfo final : public INetworkInfo
202{
203public:
204 explicit VdrNetworkInfo(const iv::types::networkId &networkId);
205
206 void update(const std::shared_ptr<INetworkInfo> &other) override;
207 bool load(const iv::file::xml::node &nodeNetwork) override;
208 bool save(iv::file::xml::node &nodeNetwork) const override;
209
211 {
212 return m_info;
213 }
214
216
217private:
218 struct Sections
219 {
220 static constexpr std::string_view registerInfo {"VdrRegisterInfo"};
221 };
222};
223
224static std::shared_ptr<iv::channels::INetworkInfo> createNetworkType(iv::comms::eProtocolType protocolType,
225 const iv::types::networkId &networkId)
226{
227 switch (protocolType)
228 {
230 return std::make_shared<iv::channels::J1939NetworkInfo>(networkId);
231
233 return std::make_shared<iv::channels::ModbusNetworkInfo>(networkId);
234
236 return std::make_shared<iv::channels::Nmea0183NetworkInfo>(networkId);
237
239 return std::make_shared<iv::channels::VdrNetworkInfo>(networkId);
240
242 return std::make_shared<iv::channels::Nmea2kNetworkInfo>(networkId);
243 default:
244 break;
245 }
246
247 return nullptr;
248}
249
250}// namespace iv::channels
251
252#endif//IV_SRC_CHANNELS_NETWORKINFO_HPP_
Definition NetworkInfo.hpp:18
virtual bool load(const iv::file::xml::node &nodeNetwork)
Definition NetworkInfo.hpp:76
virtual void update(const std::shared_ptr< INetworkInfo > &other)
Definition NetworkInfo.hpp:43
eDirection direction() const
Definition NetworkInfo.hpp:68
virtual bool save(iv::file::xml::node &nodeNetwork) const
Definition NetworkInfo.hpp:50
static std::shared_ptr< INetworkInfo > loadStatic(const iv::file::xml::node &nodeNetwork)
Definition NetworkInfo.hpp:28
iv::types::networkId & nameNetwork()
Definition NetworkInfo.hpp:58
iv::comms::eProtocolType m_protocolType
Definition NetworkInfo.hpp:89
iv::channels::INetworkInfo::eDirection m_direction
Definition NetworkInfo.hpp:73
iv::types::networkId m_nameNetwork
Definition NetworkInfo.hpp:90
iv::comms::eProtocolType protocolType() const
Definition NetworkInfo.hpp:63
eDirection
Definition NetworkInfo.hpp:21
virtual ~INetworkInfo()=default
Definition NetworkInfo.hpp:110
void update(const std::shared_ptr< INetworkInfo > &other) override
Definition NetworkInfo.cpp:24
bool load(const iv::file::xml::node &nodeNetwork) override
Definition NetworkInfo.cpp:15
iv::channels::J1939RegisterInfo & getInfo()
Definition NetworkInfo.hpp:118
iv::channels::J1939RegisterInfo m_info
Definition NetworkInfo.hpp:124
bool save(iv::file::xml::node &nodeNetwork) const override
Definition NetworkInfo.cpp:36
J1939NetworkInfo(const iv::types::networkId &networkId)
Definition NetworkInfo.cpp:8
Definition NetworkInfo.hpp:133
iv::channels::ModbusRegisterInfo m_info
Definition NetworkInfo.hpp:146
iv::channels::ModbusRegisterInfo & getInfo()
Definition NetworkInfo.hpp:141
void update(const std::shared_ptr< INetworkInfo > &other) override
Definition NetworkInfo.cpp:69
bool save(iv::file::xml::node &nodeNetwork) const override
Definition NetworkInfo.cpp:61
bool load(const iv::file::xml::node &nodeNetwork) override
Definition NetworkInfo.cpp:52
ModbusNetworkInfo(const iv::types::networkId &networkId)
Definition NetworkInfo.cpp:45
Definition NetworkInfo.hpp:156
void update(const std::shared_ptr< INetworkInfo > &other) override
Definition NetworkInfo.cpp:105
iv::channels::Nmea0183RegisterInfo m_info
Definition NetworkInfo.hpp:169
iv::channels::Nmea0183RegisterInfo & getInfo()
Definition NetworkInfo.hpp:164
bool load(const iv::file::xml::node &nodeNetwork) override
Definition NetworkInfo.cpp:88
Nmea0183NetworkInfo(const iv::types::networkId &networkId)
Definition NetworkInfo.cpp:81
bool save(iv::file::xml::node &nodeNetwork) const override
Definition NetworkInfo.cpp:97
Definition NetworkInfo.hpp:179
bool save(iv::file::xml::node &nodeNetwork) const override
Definition NetworkInfo.cpp:175
iv::channels::Nmea2kRegisterInfo m_info
Definition NetworkInfo.hpp:192
iv::channels::Nmea2kRegisterInfo & getInfo()
Definition NetworkInfo.hpp:187
void update(const std::shared_ptr< INetworkInfo > &other) override
Definition NetworkInfo.cpp:155
Nmea2kNetworkInfo(const iv::types::networkId &networkId)
Definition NetworkInfo.cpp:149
bool load(const iv::file::xml::node &nodeNetwork) override
Definition NetworkInfo.cpp:167
Definition NetworkInfo.hpp:202
void update(const std::shared_ptr< INetworkInfo > &other) override
Definition NetworkInfo.cpp:122
iv::channels::VdrRegisterInfo m_info
Definition NetworkInfo.hpp:215
bool load(const iv::file::xml::node &nodeNetwork) override
Definition NetworkInfo.cpp:133
iv::channels::VdrRegisterInfo & getInfo()
Definition NetworkInfo.hpp:210
VdrNetworkInfo(const iv::types::networkId &networkId)
Definition NetworkInfo.cpp:116
bool save(iv::file::xml::node &nodeNetwork) const override
Definition NetworkInfo.cpp:141
Definition xmlFile.hpp:15
T getAttribute(const std::string_view key, T defaultValue) const
Definition xmlFile.hpp:33
bool addAttribute(const std::string_view key, T value)
Definition xmlFile.hpp:77
Definition AlarmsManager.hpp:17
static std::shared_ptr< iv::channels::INetworkInfo > createNetworkType(iv::comms::eProtocolType protocolType, const iv::types::networkId &networkId)
Definition NetworkInfo.hpp:224
eProtocolType
Definition enums.hpp:260
std::string networkId
Definition types.hpp:43
Definition NetworkInfo.hpp:101
static constexpr std::string string
Definition NetworkInfo.hpp:102
static constexpr iv::channels::INetworkInfo::eDirection direction
Definition NetworkInfo.hpp:105
static constexpr iv::comms::eProtocolType protocolType
Definition NetworkInfo.hpp:103
static constexpr iv::types::networkId nameNetwork
Definition NetworkInfo.hpp:104
Definition NetworkInfo.hpp:94
static constexpr std::string_view protocol
Definition NetworkInfo.hpp:95
static constexpr std::string_view direction
Definition NetworkInfo.hpp:97
static constexpr std::string_view nameNetwork
Definition NetworkInfo.hpp:96
Definition NetworkInfo.hpp:127
static constexpr std::string_view registerInfo
Definition NetworkInfo.hpp:128
Definition structs.hpp:389
Definition NetworkInfo.hpp:150
static constexpr std::string_view registerInfo
Definition NetworkInfo.hpp:151
Definition structs.hpp:509
Definition NetworkInfo.hpp:173
static constexpr std::string_view registerInfo
Definition NetworkInfo.hpp:174
Definition structs.hpp:591
Definition NetworkInfo.hpp:196
static constexpr std::string_view registerInfo
Definition NetworkInfo.hpp:197
Definition structs.hpp:288
Definition NetworkInfo.hpp:219
static constexpr std::string_view registerInfo
Definition NetworkInfo.hpp:220
Definition structs.hpp:629