Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#ifndef IV_COMMS_CAN_UTILS_HPP
2#define IV_COMMS_CAN_UTILS_HPP
3
5#include "comms/can/enums.hpp"
9#include "core/defines.hpp"
10#include "core/enums.hpp"
11#include "core/parsers.hpp"
12#include "model/enums.hpp"
13#include "utils/Calendar.hpp"
14
15namespace iv::comms::can
16{
17
18constexpr uint32_t kPrvUnitIdMask = 0x07F;
19
20constexpr uint16_t kPrvAllSubnetwork = 0xFFFF;
21constexpr uint8_t kPrvFirstStation = 119;
22constexpr uint16_t kPrvMaxModulesForSubnetwork = 1000;
23constexpr uint16_t kPrvMaxNumberModulesInSubnetwork = 127;
24
25constexpr uint8_t kPrvAllNode = 0;
26
27constexpr uint8_t kPrvCommandStopNode = 2;
28constexpr uint8_t kPrvCommandPreOperationalNode = 0x80;// 128
29constexpr uint8_t kPrvCommandResetNode = 0x81; // 129
30constexpr uint8_t kPrvCommandACK = 0x80; // 128
31constexpr uint8_t kPrvCommandCtrl = 0x81; // 129
32constexpr uint8_t kPrvTypeRealValue = 0x90; // 144
33
34constexpr uint8_t kPrvTypeTextPositionMask = 0x3F;
35constexpr uint8_t kPrvTypeTextStateMask = 0xC0;
36constexpr uint8_t kPrvTypeTextConcat = 0x00;
37constexpr uint8_t kPrvTypeTextInit = 0x40;
38constexpr uint8_t kPrvTypeTextFinish = 0x80;
39
40constexpr uint8_t kPrvCommandOnDutyWatchCall = 0x01;
41constexpr uint8_t kPrvCommandCallAllWatchCallEcr = 1;
42constexpr uint8_t kPrvCommandCallAllOff = 0;
44constexpr uint16_t kPrvIndexWatchCall = 0x6000;
45constexpr uint32_t kPrvLengthMessageWatchCall = 8;
46
47constexpr uint16_t kPrvBroadcastNewAlarm = 0;
48constexpr uint16_t kPrvBroadcastSoundOff = 1;
49constexpr uint16_t kPrvBroadcastACK = 2;
50constexpr uint16_t kPrvBroadcastStartArea = 4;
51constexpr uint16_t kPrvIndexCommandChannelOffset = 0x3800;
52constexpr uint16_t kPrvOffsetCmd = 400;
53constexpr uint16_t kPrvOffsetInternMemory = 500;
55
56constexpr uint16_t MAX_ANALOG_INPUT_INDEX = 0x363;
57
58constexpr std::string_view kPrvStrSend = "TO_SEND";
59
61 iv::types::subnetwork *idSubnetwork)
62{
63 IV_ASSERT_NULL_POINTER(idLocalUnit);
64 IV_ASSERT_NULL_POINTER(idSubnetwork);
65
66 *idLocalUnit = idUnit % kPrvMaxModulesForSubnetwork;
67 *idSubnetwork = idUnit / kPrvMaxModulesForSubnetwork;
68}
69
70inline bool isInSdoResponseCanIdRange(const uint32_t canId)
71{
72 return (canId >= iv::comms::can::canMessageIds::sdoServer && canId < 0x700);
73}
74
75inline bool isInHeartbeatCanIdRange(const uint32_t canId)
76{
79}
80
81inline bool isHeartbeatOk(const iv::comms::eHeartbeatState heartbeatState)
82{
83 switch (heartbeatState)
84 {
89 return true;
90
91 default:
92 break;
93 }
94
95 return false;
96}
97
98inline uint8_t prvIdUnitStation(iv::types::unitId idStation)
99{
100 return static_cast<uint8_t>(idStation + kPrvFirstStation);
101}
102
103inline uint16_t prvIndexChannelBroadCast(iv::model::eShipArea areaStation, uint16_t typeBroadcast)
104{
105 uint16_t indexChannel;
106 uint16_t broadcastArea;
107
108 broadcastArea = static_cast<uint16_t>(kPrvBroadcastStartArea * static_cast<int32_t>(areaStation));
109 indexChannel = static_cast<uint16_t>(kPrvIndexCommandChannelOffset + typeBroadcast + broadcastArea);
110
111 return indexChannel;
112}
113
114inline bool isWatchCall(uint16_t indexChannel, uint16_t *areaRepeater)
115{
116 bool isWatchCall {false};
117
118 IV_ASSERT_NULL_POINTER(areaRepeater);
119
120 if (indexChannel >= kPrvIndexWatchCall && indexChannel <= kPrvIndexWatchCall + 0xFF)
121 {
122 *areaRepeater = indexChannel - kPrvIndexWatchCall;
123 isWatchCall = true;
124 }
125
126 return isWatchCall;
127}
128
129inline bool isBroadCastCommand(uint16_t indexChannel, iv::comms::can::eBroadcastType *typeBroadCast,
130 uint16_t *typeZoneRepeaters)
131{
132 bool isBroadCast {false};
133
134 IV_ASSERT_NULL_POINTER(typeBroadCast);
135 IV_ASSERT_NULL_POINTER(typeZoneRepeaters);
136
137 if (indexChannel >= kPrvIndexCommandChannelOffset &&
139 {
140 uint16_t idChannel;
141
142 idChannel = indexChannel - kPrvIndexCommandChannelOffset;
143
144 if (idChannel < kPrvOffsetCmd)
145 {
146 uint16_t idBroadCast;
147
148 idBroadCast = idChannel % kPrvBroadcastStartArea;
149 *typeZoneRepeaters = idChannel / kPrvBroadcastStartArea;
150 *typeBroadCast = (iv::comms::can::eBroadcastType) idBroadCast;
151
152 isBroadCast = true;
153 }
154 }
155
156 return isBroadCast;
157}
158
163
168
170 iv::types::subnetwork *idSubnetwork)
171{
172 iv::comms::can::prvGetIdLocalUnitAndSubnetwork(idUnit, idUnitLocal, idSubnetwork);
173}
174
176 uint32_t &milliseconds)
177{
178 iv::time::Timestamp(now).getLomsTime(daysSince1984, milliseconds);
179}
180
181inline uint16_t getIdUnitGlobal(uint16_t idUnitLocal, uint16_t idSubnetwork)
182{
183 uint32_t idGlobal;
184
185 if (idSubnetwork != kPrvAllSubnetwork)
186 {
187 uint16_t idFirstUnitSubnetwork;
188
189 idFirstUnitSubnetwork = idSubnetwork * kPrvMaxModulesForSubnetwork;
190 idGlobal = idFirstUnitSubnetwork + idUnitLocal;
191 }
192 else
193 {
194 idGlobal = idUnitLocal;
195 }
196
197 return static_cast<uint16_t>(idGlobal);
198}
199
200inline uint16_t idUnitStation(uint16_t idStation)
201{
202 return idStation + kPrvFirstStation;
203}
204
206 const iv::comms::can::CanDataMessage *message2)
207{
208 IV_ASSERT_NULL_POINTER(message1);
209 IV_ASSERT_NULL_POINTER(message2);
210
211 return message1->m_msgId == message2->m_msgId && message1->m_lengthData == message2->m_lengthData &&
212 iv::utils::compareSubstring((const char *) message1->m_bytes, (const char *) message2->m_bytes,
213 message1->m_lengthData) == 0;
214}
215
217{
219
221 {
223 }
225 {
227 }
229 {
231 }
233 {
235 }
237 {
239 }
241 {
243 }
245 {
247 }
250 {
252 }
254 {
256 }
259 {
261 }
263 {
265 }
267 {
269 }
271 {
273 }
276 {
278 }
280 {
282 }
284 {
285 if (msgId <= MAX_ANALOG_INPUT_INDEX)
286 {
288 }
289 else
290 {
292 }
293 }
295 {
297 }
300 {
302 }
304 {
306 }
307 else
308 {
309 IV_ASSERT_MSG("[prvMessageType] Unknown message type.");
310 }
311
312 return messageType;
313}
314
315inline unsigned char idTypeRepeaterByArea(iv::model::eShipArea eAreaShip)
316{
317 constexpr uint16_t PRV_INDEX_AREA_ECR = 0;
318 constexpr uint16_t PRV_INDEX_AREA_BRIDGE = 7;
319 unsigned char idTypeRepeater {PRV_INDEX_AREA_ECR};
320
321 switch (eAreaShip)
322 {
324 idTypeRepeater = PRV_INDEX_AREA_ECR;
325 break;
326
328 idTypeRepeater = PRV_INDEX_AREA_BRIDGE;
329 break;
330
332 default:
333 IV_MISSING_CASE_CHECK(eAreaShip);
334 break;
335 }
336
337 return idTypeRepeater;
338}
339
340}// namespace iv::comms::can
341
342#endif//IV_COMMS_CAN_UTILS_HPP
#define IV_ASSERT_MSG(msg,...)
Definition assert.hpp:152
#define IV_ASSERT_NULL_POINTER(ptr)
Definition assert.hpp:128
#define IV_MISSING_CASE_CHECK(msg,...)
Definition assert.hpp:166
Definition Timestamp.hpp:17
void getLomsTime(uint16_t &numDaysSince1984, uint32_t &milliseconds) const
Definition Timestamp.cpp:22
Definition AbstractMessageProcessor.hpp:12
constexpr uint16_t kPrvBroadcastACK
Definition utils.hpp:49
constexpr uint8_t kPrvTypeRealValue
Definition utils.hpp:32
uint16_t indexChannelBroadcastSoundOff(iv::model::eShipArea stationArea)
Definition utils.hpp:164
constexpr uint16_t kPrvBroadcastSoundOff
Definition utils.hpp:48
constexpr uint8_t kPrvCommandACK
Definition utils.hpp:30
constexpr uint16_t kPrvMaxModulesForSubnetwork
Definition utils.hpp:22
eBroadcastType
Definition enums.hpp:33
constexpr uint8_t kPrvFirstStation
Definition utils.hpp:21
constexpr uint8_t kPrvTypeTextFinish
Definition utils.hpp:38
unsigned char idTypeRepeaterByArea(iv::model::eShipArea eAreaShip)
Definition utils.hpp:315
constexpr uint16_t kPrvAllSubnetwork
Definition utils.hpp:20
constexpr uint8_t kPrvTypeTextStateMask
Definition utils.hpp:35
constexpr uint8_t kPrvTypeTextPositionMask
Definition utils.hpp:34
constexpr uint16_t MAX_ANALOG_INPUT_INDEX
Definition utils.hpp:56
constexpr uint8_t kPrvCommandCallAllWatchCallBridge
Definition utils.hpp:43
void getNumDaysAndMillisecondsSinceLOMBaseDate(iv::types::timestamp now, uint16_t &daysSince1984, uint32_t &milliseconds)
Definition utils.hpp:175
uint8_t prvIdUnitStation(iv::types::unitId idStation)
Definition utils.hpp:98
constexpr uint32_t kPrvLengthMessageBroadCastSoundOff
Definition utils.hpp:54
bool isHeartbeatOk(const iv::comms::eHeartbeatState heartbeatState)
Definition utils.hpp:81
constexpr uint16_t kPrvBroadcastNewAlarm
Definition utils.hpp:47
uint16_t indexChannelBroadcastNewAlarm(iv::model::eShipArea stationArea)
Definition utils.hpp:159
constexpr uint16_t kPrvOffsetCmd
Definition utils.hpp:52
constexpr uint16_t kPrvIndexWatchCall
Definition utils.hpp:44
bool isBroadCastCommand(uint16_t indexChannel, iv::comms::can::eBroadcastType *typeBroadCast, uint16_t *typeZoneRepeaters)
Definition utils.hpp:129
bool isInSdoResponseCanIdRange(const uint32_t canId)
Definition utils.hpp:70
constexpr std::string_view kPrvStrSend
Definition utils.hpp:58
uint16_t getIdUnitGlobal(uint16_t idUnitLocal, uint16_t idSubnetwork)
Definition utils.hpp:181
constexpr uint8_t kPrvAllNode
Definition utils.hpp:25
constexpr uint8_t kPrvCommandResetNode
Definition utils.hpp:29
constexpr uint16_t kPrvIndexCommandChannelOffset
Definition utils.hpp:51
constexpr uint32_t kPrvLengthMessageWatchCall
Definition utils.hpp:45
iv::comms::can::eMessageType getMessageType(const uint64_t msgId)
Definition utils.hpp:216
constexpr uint8_t kPrvCommandCtrl
Definition utils.hpp:31
void prvGetIdLocalUnitAndSubnetwork(iv::types::unitId idUnit, iv::types::unitId *idLocalUnit, iv::types::subnetwork *idSubnetwork)
Definition utils.hpp:60
bool isInHeartbeatCanIdRange(const uint32_t canId)
Definition utils.hpp:75
uint16_t idUnitStation(uint16_t idStation)
Definition utils.hpp:200
constexpr uint8_t kPrvCommandStopNode
Definition utils.hpp:27
constexpr uint32_t kPrvUnitIdMask
Definition utils.hpp:18
constexpr uint8_t kPrvTypeTextConcat
Definition utils.hpp:36
eMessageType
Definition enums.hpp:8
bool isEqualMessageCAN(const iv::comms::can::CanDataMessage *message1, const iv::comms::can::CanDataMessage *message2)
Definition utils.hpp:205
constexpr uint16_t kPrvBroadcastStartArea
Definition utils.hpp:50
void getIdUnitLocalAndSubnetwork(iv::types::unitId idUnit, iv::types::unitId *idUnitLocal, iv::types::subnetwork *idSubnetwork)
Definition utils.hpp:169
constexpr uint8_t kPrvCommandOnDutyWatchCall
Definition utils.hpp:40
uint16_t prvIndexChannelBroadCast(iv::model::eShipArea areaStation, uint16_t typeBroadcast)
Definition utils.hpp:103
constexpr uint16_t kPrvOffsetInternMemory
Definition utils.hpp:53
constexpr uint16_t kPrvMaxNumberModulesInSubnetwork
Definition utils.hpp:23
constexpr uint8_t kPrvCommandCallAllWatchCallEcr
Definition utils.hpp:41
bool isWatchCall(uint16_t indexChannel, uint16_t *areaRepeater)
Definition utils.hpp:114
constexpr uint8_t kPrvCommandCallAllOff
Definition utils.hpp:42
constexpr uint8_t kPrvTypeTextInit
Definition utils.hpp:37
constexpr uint8_t kPrvCommandPreOperationalNode
Definition utils.hpp:28
eHeartbeatState
Definition enums.hpp:297
eShipArea
Definition enums.hpp:11
uint64_t timestamp
Definition types.hpp:21
uint16_t subnetwork
Definition types.hpp:76
uint16_t unitId
Definition types.hpp:77
int32_t compareSubstring(const CharT1 *str1, const CharT2 *str2, std::size_t length)
Simple comparator of x chars where x is the length provided.
Definition stringUtils.hpp:56
Definition structs.hpp:14
uint32_t m_msgId
Definition structs.hpp:45
uint8_t m_bytes[8]
Definition structs.hpp:46
uint32_t m_lengthData
Definition structs.hpp:48
static constexpr uint32_t updateHistorySync
Definition defines.hpp:29
static constexpr uint32_t ackHistorySync
Definition defines.hpp:11
static constexpr uint32_t lssSlave
Definition defines.hpp:23
static constexpr uint32_t digitalInput0_63
Definition defines.hpp:17
static constexpr uint32_t sdoServer
Definition defines.hpp:26
static constexpr uint32_t analogInput
Definition defines.hpp:15
static constexpr uint32_t digitalInput128_191
Definition defines.hpp:19
static constexpr uint32_t alarmTimestamp
Definition defines.hpp:14
static constexpr uint32_t digitalInput64_127
Definition defines.hpp:18
static constexpr uint32_t alarm
Definition defines.hpp:12
static constexpr uint32_t sdoClient
Definition defines.hpp:25
static constexpr uint32_t lssMaster
Definition defines.hpp:22
static constexpr uint32_t gmtSync
Definition defines.hpp:20
static constexpr uint32_t command
Definition defines.hpp:16
static constexpr uint32_t heartbeat
Definition defines.hpp:21
static constexpr uint32_t text
Definition defines.hpp:28
static constexpr uint32_t timestampSync
Definition defines.hpp:27
static constexpr uint32_t alarmGroups
Definition defines.hpp:13
static constexpr uint32_t nmtService
Definition defines.hpp:24