Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
Unit.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_UNITS_MODEL_UNIT_HPP_
2#define IV_SRC_UNITS_MODEL_UNIT_HPP_
3
9
10namespace iv::units
11{
12
13class Unit
14{
15 friend class Units;
16
17public:
18 Unit();
19
21
22 void update(const iv::units::Unit &other);
23 bool load(const iv::file::xml::File &xml);
24 bool save(const std::shared_ptr<iv::file::xml::File> &xml) const;
25
26 [[nodiscard]] std::shared_ptr<Unit> clone() const;
27
28 [[nodiscard]] iv::types::unitId getId() const;
29 [[nodiscard]] std::optional<iv::units::eUnitType> getType() const;
30 [[nodiscard]] iv::units::UnitInfo &getUnitInfo();
31 [[nodiscard]] iv::types::timestamp getLastHeartbeat() const;
32
33 [[nodiscard]] bool hasChannels() const;
35
36 void initializeChannels(const std::shared_ptr<AbstractProgress> &progress);
37 // Unit's channel manipulation: Controller
38 [[nodiscard]] std::shared_ptr<iv::channels::AbstractChannel> extractChannel(iv::types::channelOrder channelOrder);
39 [[nodiscard]] std::shared_ptr<iv::channels::AbstractChannel> extractChannel(const iv::types::channelId &channelId);
40
41 bool changeChannelId(const iv::types::channelId &channelId, const iv::types::channelId &newChannelId);
42 bool changeChannelOrder(iv::types::channelOrder channelOrder, iv::types::channelOrder newChannelOrder);
43
44 bool deleteChannel(iv::types::channelOrder channelOrder);
45 bool deleteChannel(const iv::types::channelId &channelId);
46
47 std::weak_ptr<iv::channels::AbstractChannel>
49 std::optional<iv::types::channelOrder> channelOrder = std::nullopt,
50 const std::optional<iv::types::channelId> &channelId = std::nullopt);
51
52 bool insertChannel(std::shared_ptr<iv::channels::AbstractChannel> channel);
53
54 [[nodiscard]] std::weak_ptr<iv::channels::AbstractChannel> getChannel(iv::types::channelOrder channelOrder) const;
55 [[nodiscard]] std::weak_ptr<iv::channels::AbstractChannel> getChannel(const iv::types::channelId &channelId) const;
56 [[nodiscard]] std::weak_ptr<iv::channels::AbstractChannel> getChannelByShipyardTag(const std::string &channelTag);
57
58 [[nodiscard]] const std::unordered_map<iv::types::channelId, std::shared_ptr<iv::channels::AbstractChannel>> &
59 getChannels() const;
60 const std::map<iv::types::channelOrder, std::shared_ptr<iv::channels::AbstractChannel>> &
61 getActiveChannels(bool refreshCache = false) const;
62 [[nodiscard]] const std::map<iv::types::channelOrder, std::shared_ptr<iv::channels::AbstractChannel>> &
63 getChannelsByOrder() const;
64 [[nodiscard]] std::shared_ptr<std::vector<std::weak_ptr<iv::channels::AbstractChannel>>>
65 getActiveChannelsByGroupId(const iv::types::groupId &groupId, bool refreshCache = false) const;
66 [[nodiscard]] std::map<iv::types::indexChannel, std::shared_ptr<iv::channels::AbstractChannel>> &
68
69 [[nodiscard]] std::optional<iv::types::channelOrder> getFirstFreeChannelOrder(
70 std::optional<iv::channels::eChannelSpecificType> channelType = std::nullopt,
71 const std::optional<std::function<bool(iv::types::channelOrder)>> &addedCondition = std::nullopt) const;
72
73 std::pair<iv::alarms::eAlarmState, iv::alarms::eAlarmPriority> calculateUnitAlarmStatePriority() const;
74
75 void setOfflineChannel(const std::weak_ptr<iv::channels::AbstractChannel> &offlineChannel);
76 void setCanAFailChannel(const std::weak_ptr<iv::channels::AbstractChannel> &canAFailChannel);
77 void setCanBFailChannel(const std::weak_ptr<iv::channels::AbstractChannel> &canBFailChannel);
78 void setCanCFailChannel(const std::weak_ptr<iv::channels::AbstractChannel> &canCFailChannel);
79 void setHeartbeatChannel(const std::weak_ptr<iv::channels::AbstractChannel> &heartbeatChannel);
80
81 std::weak_ptr<iv::channels::AbstractChannel> getOfflineChannel();
82 std::weak_ptr<iv::channels::AbstractChannel> getCanAFailChannel();
83 std::weak_ptr<iv::channels::AbstractChannel> getCanBFailChannel();
84 std::weak_ptr<iv::channels::AbstractChannel> getCanCFailChannel();
85 std::weak_ptr<iv::channels::AbstractChannel> getHeartbeatChannel();
86
89 // Checks
90 [[nodiscard]] bool isStation() const;
91 [[nodiscard]] bool isLIM() const;
92 [[nodiscard]] bool isLOM() const;
93 [[nodiscard]] std::string getName(bool isNotInProjectUnit = false) const;
94
95 [[nodiscard]] bool isOn() const;
96 [[nodiscard]] bool existsChannel(const iv::types::channelId &channelId) const;
97 bool isOnOnCanLine(comms::eLomLine line) const;
98
99public:
102
103 bool m_isEnabled {true};
104 //Only for editDiamar
105 std::optional<iv::comms::eHeartbeatState> m_lastHeartbeatState;
109 std::optional<iv::units::eUnitType> m_unitType;
110
112
114
115private:
116 bool changeChannelsDefaultId(const iv::types::unitId &newUnitId);
118
119 std::unordered_map<iv::types::channelId, std::shared_ptr<iv::channels::AbstractChannel>> m_channels;
120
124 std::map<iv::types::channelOrder, std::shared_ptr<iv::channels::AbstractChannel>> m_channelsByOrder;
125 std::map<iv::types::indexChannel, std::shared_ptr<iv::channels::AbstractChannel>> m_channelsByIndex;
126
130 mutable std::optional<std::map<iv::types::channelOrder, std::shared_ptr<iv::channels::AbstractChannel>>>
132 mutable std::map<iv::types::groupId, std::shared_ptr<std::vector<std::weak_ptr<iv::channels::AbstractChannel>>>>
134
135 std::weak_ptr<iv::channels::AbstractChannel> m_offlineChannel;
136 std::weak_ptr<iv::channels::AbstractChannel> m_canAFailChannel;
137 std::weak_ptr<iv::channels::AbstractChannel> m_canBFailChannel;
138 std::weak_ptr<iv::channels::AbstractChannel> m_canCFailChannel;
139 std::weak_ptr<iv::channels::AbstractChannel> m_heartbeatChannel;
140
141 std::map<iv::comms::eLomLine, iv::types::timestamp> m_lastHeartbeat;
142
143private:
144 struct Sections
145 {
146 static constexpr std::string_view unit {"Unit"};
147 static constexpr std::string_view systemChannels {"SystemChannels"};
148 static constexpr std::string_view channels {"Channels"};
149 static constexpr std::string_view channel {"Channel"};
150 static constexpr std::string_view unitData {"Data"};
151 };
152 struct Keys
153 {
154 static constexpr std::string_view unitId {"Id"};
155 static constexpr std::string_view unitType {"Type"};
156 static constexpr std::string_view isEnabled {"Enabled"};
157 static constexpr std::string_view internalDescription {"InternalDescription"};
158 static constexpr std::string_view cabinetId {"CabinetId"};
159 static constexpr std::string_view offlineChannel {"OfflineChannel"};
160 static constexpr std::string_view canAFailChannel {"CanAFailChannel"};
161 static constexpr std::string_view canBFailChannel {"CanBFailChannel"};
162 static constexpr std::string_view canCFailChannel {"CanCFailChannel"};
163 static constexpr std::string_view heartbeatChannel {"HeartbeatChannel"};
164 };
166 {
167 static constexpr std::string string {};
168 static constexpr std::string_view unitType {"Aim18"};
169 static constexpr iv::types::unitId unitId {0};
170 static constexpr bool isEnabled {true};
171 };
172};
173
174}// namespace iv::units
175
176#endif//IV_SRC_UNITS_MODEL_UNIT_HPP_
Definition xmlFile.hpp:128
Definition UnitInfo.hpp:12
Definition Unit.hpp:14
std::pair< iv::alarms::eAlarmState, iv::alarms::eAlarmPriority > calculateUnitAlarmStatePriority() const
Definition Unit.cpp:797
iv::types::cabinetId m_cabinetId
Definition Unit.hpp:108
std::optional< iv::comms::eHeartbeatState > m_lastHeartbeatState
Definition Unit.hpp:105
const std::map< iv::types::channelOrder, std::shared_ptr< iv::channels::AbstractChannel > > & getChannelsByOrder() const
Definition Unit.cpp:720
std::weak_ptr< iv::channels::AbstractChannel > m_canCFailChannel
Definition Unit.hpp:138
void setOfflineChannel(const std::weak_ptr< iv::channels::AbstractChannel > &offlineChannel)
Definition Unit.cpp:831
std::weak_ptr< iv::channels::AbstractChannel > getChannel(iv::types::channelOrder channelOrder) const
Definition Unit.cpp:652
std::string getName(bool isNotInProjectUnit=false) const
Definition Unit.cpp:957
std::weak_ptr< iv::channels::AbstractChannel > m_canAFailChannel
Definition Unit.hpp:136
void setCanBFailChannel(const std::weak_ptr< iv::channels::AbstractChannel > &canBFailChannel)
Definition Unit.cpp:840
std::weak_ptr< iv::channels::AbstractChannel > getHeartbeatChannel()
Definition Unit.cpp:1137
bool m_isEnabled
Definition Unit.hpp:103
std::map< iv::types::indexChannel, std::shared_ptr< iv::channels::AbstractChannel > > m_channelsByIndex
Definition Unit.hpp:125
bool changeChannelOrder(iv::types::channelOrder channelOrder, iv::types::channelOrder newChannelOrder)
Definition Unit.cpp:547
std::optional< iv::types::channelOrder > getFirstFreeChannelOrder(std::optional< iv::channels::eChannelSpecificType > channelType=std::nullopt, const std::optional< std::function< bool(iv::types::channelOrder)> > &addedCondition=std::nullopt) const
Definition Unit.cpp:763
std::map< iv::types::channelOrder, std::shared_ptr< iv::channels::AbstractChannel > > m_channelsByOrder
Definition Unit.hpp:124
void setCanAFailChannel(const std::weak_ptr< iv::channels::AbstractChannel > &canAFailChannel)
Definition Unit.cpp:835
std::weak_ptr< iv::channels::AbstractChannel > m_canBFailChannel
Definition Unit.hpp:137
const std::unordered_map< iv::types::channelId, std::shared_ptr< iv::channels::AbstractChannel > > & getChannels() const
Definition Unit.cpp:688
const std::map< iv::types::channelOrder, std::shared_ptr< iv::channels::AbstractChannel > > & getActiveChannels(bool refreshCache=false) const
Definition Unit.cpp:694
bool isLOM() const
Definition Unit.cpp:923
std::shared_ptr< std::vector< std::weak_ptr< iv::channels::AbstractChannel > > > getActiveChannelsByGroupId(const iv::types::groupId &groupId, bool refreshCache=false) const
Get all channels in the unit that belong to the group.
Definition Unit.cpp:732
bool isLIM() const
Definition Unit.cpp:889
bool hasChannels() const
Definition Unit.cpp:462
bool deleteChannel(iv::types::channelOrder channelOrder)
Definition Unit.cpp:561
std::weak_ptr< iv::channels::AbstractChannel > createChannel(iv::channels::eChannelSpecificType channelType, std::optional< iv::types::channelOrder > channelOrder=std::nullopt, const std::optional< iv::types::channelId > &channelId=std::nullopt)
Definition Unit.cpp:589
iv::units::UnitInfo & getUnitInfo()
Definition Unit.cpp:457
void setLasHeartbeat(iv::comms::eLomLine line, iv::types::timestamp timestamp)
Definition Unit.cpp:1147
std::optional< std::map< iv::types::channelOrder, std::shared_ptr< iv::channels::AbstractChannel > > > m_activeChannelsByOrder
Definition Unit.hpp:131
std::shared_ptr< Unit > clone() const
Definition Unit.cpp:426
std::map< iv::types::indexChannel, std::shared_ptr< iv::channels::AbstractChannel > > & getChannelsByIndex()
Definition Unit.cpp:757
bool changeChannelId(const iv::types::channelId &channelId, const iv::types::channelId &newChannelId)
Definition Unit.cpp:531
std::weak_ptr< iv::channels::AbstractChannel > getChannelByShipyardTag(const std::string &channelTag)
Definition Unit.cpp:671
void initializeChannels(const std::shared_ptr< AbstractProgress > &progress)
Definition Unit.cpp:488
iv::types::unitId m_id
Definition Unit.hpp:106
std::optional< iv::units::eUnitType > m_unitType
Definition Unit.hpp:109
std::map< iv::types::groupId, std::shared_ptr< std::vector< std::weak_ptr< iv::channels::AbstractChannel > > > > m_channelsByGroupId
Definition Unit.hpp:133
void setHeartbeatChannel(const std::weak_ptr< iv::channels::AbstractChannel > &heartbeatChannel)
Definition Unit.cpp:850
void prvCreateKLimSystemChannels()
Definition Unit.cpp:1017
Unit()
Definition Unit.cpp:243
iv::types::unitId getId() const
Definition Unit.cpp:447
void updateChannelsUnitId()
Definition Unit.cpp:1103
std::mutex m_lomCommunicationMutex
Definition Unit.hpp:113
bool isOn() const
Definition Unit.cpp:972
std::weak_ptr< iv::channels::AbstractChannel > getOfflineChannel()
Definition Unit.cpp:1117
bool changeChannelsDefaultId(const iv::types::unitId &newUnitId)
esto ahora debe funcionar diferente
Definition Unit.cpp:1047
bool insertChannel(std::shared_ptr< iv::channels::AbstractChannel > channel)
Definition Unit.cpp:637
std::weak_ptr< iv::channels::AbstractChannel > m_offlineChannel
Definition Unit.hpp:135
iv::units::UnitInfo m_unitInfo
Definition Unit.hpp:111
void update(const iv::units::Unit &other)
Definition Unit.cpp:292
std::weak_ptr< iv::channels::AbstractChannel > getCanCFailChannel()
Definition Unit.cpp:1132
std::optional< iv::units::eUnitType > getType() const
Definition Unit.cpp:452
bool load(const iv::file::xml::File &xml)
Definition Unit.cpp:315
std::weak_ptr< iv::channels::AbstractChannel > getCanAFailChannel()
Definition Unit.cpp:1122
std::unordered_map< iv::types::channelId, std::shared_ptr< iv::channels::AbstractChannel > > m_channels
Definition Unit.hpp:119
std::string m_internalDescription
Definition Unit.hpp:107
bool save(const std::shared_ptr< iv::file::xml::File > &xml) const
Definition Unit.cpp:384
void createSystemChannels()
Definition Unit.cpp:467
std::shared_ptr< iv::channels::AbstractChannel > extractChannel(iv::types::channelOrder channelOrder)
Definition Unit.cpp:506
bool existsChannel(const iv::types::channelId &channelId) const
Definition Unit.cpp:994
void setCanCFailChannel(const std::weak_ptr< iv::channels::AbstractChannel > &canCFailChannel)
Definition Unit.cpp:845
bool isOnOnCanLine(comms::eLomLine line) const
Definition Unit.cpp:985
bool isStation() const
Definition Unit.cpp:855
std::map< iv::comms::eLomLine, iv::types::timestamp > m_lastHeartbeat
Definition Unit.hpp:141
iv::types::timestamp getLastHeartbeat() const
Definition Unit.cpp:1111
std::weak_ptr< iv::channels::AbstractChannel > m_heartbeatChannel
Definition Unit.hpp:139
std::weak_ptr< iv::channels::AbstractChannel > getCanBFailChannel()
Definition Unit.cpp:1127
void prvCreateLomSystemChannels()
Definition Unit.cpp:999
Definition Units.hpp:14
eChannelSpecificType
Definition enums.hpp:72
eLomLine
Definition enums.hpp:231
uint64_t timestamp
Definition types.hpp:21
uint16_t unitId
Definition types.hpp:77
uint16_t channelOrder
Definition types.hpp:68
std::string cabinetId
Definition types.hpp:65
std::string channelId
Definition types.hpp:66
std::string groupId
Definition types.hpp:70
Definition AbstractChannel.hpp:16
eUnitType
Definition enums.hpp:8
Definition Unit.hpp:166
static constexpr std::string_view unitType
Definition Unit.hpp:168
static constexpr bool isEnabled
Definition Unit.hpp:170
static constexpr iv::types::unitId unitId
Definition Unit.hpp:169
Definition Unit.hpp:153
static constexpr std::string_view canAFailChannel
Definition Unit.hpp:160
static constexpr std::string_view offlineChannel
Definition Unit.hpp:159
static constexpr std::string_view unitId
Definition Unit.hpp:154
static constexpr std::string_view isEnabled
Definition Unit.hpp:156
static constexpr std::string_view cabinetId
Definition Unit.hpp:158
static constexpr std::string_view internalDescription
Definition Unit.hpp:157
static constexpr std::string_view canCFailChannel
Definition Unit.hpp:162
static constexpr std::string_view canBFailChannel
Definition Unit.hpp:161
static constexpr std::string_view heartbeatChannel
Definition Unit.hpp:163
static constexpr std::string_view unitType
Definition Unit.hpp:155
Definition Unit.hpp:145
static constexpr std::string_view systemChannels
Definition Unit.hpp:147
static constexpr std::string_view unitData
Definition Unit.hpp:150
static constexpr std::string_view channel
Definition Unit.hpp:149
static constexpr std::string_view channels
Definition Unit.hpp:148
static constexpr std::string_view unit
Definition Unit.hpp:146