Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
IxxatCommonFunctions.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_COMMS_IXXAT_IXXATCOMMONFUNCTIONS_HPP_
2#define IV_SRC_COMMS_IXXAT_IXXATCOMMONFUNCTIONS_HPP_
3
4#include "IxxatUsbToCanV1.hpp"
5#include "IxxatUsbToCanV2.hpp"
6#include "core/assert.hpp"
7
8#include <ECI/ECI_cantype.h>
9#include <cstring>
10#include <string>
11
12namespace iv::comms::ixxat
13{
14
15const BYTE ECI_CAN_FD_DLC_LUT[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64};
16
17inline void EciPrintCtrlMessage(const ECI_CTRL_MESSAGE *pStcCtrlMsg, const std::string &strDevice, const bool isSending)
18{
19 if (pStcCtrlMsg != nullptr)
20 {
21 switch (pStcCtrlMsg->wCtrlClass)
22 {
23 case ECI_CTRL_CAN:
24 {
25 if ((ECI_STRUCT_VERSION_V0 == pStcCtrlMsg->u.sCanMessage.dwVer) ||
26 (ECI_STRUCT_VERSION_V1 == pStcCtrlMsg->u.sCanMessage.dwVer))
27 {
28 OS_Printf(isSending ? ">>>>> CAN >>>>> " : "<<<<< CAN <<<<< ");
29 OS_Printf("Device: %s, Time: %10u, Type: %2u, ID: %08X, Flags: %c%c%c%c%c%c ", strDevice.c_str(),
30 pStcCtrlMsg->u.sCanMessage.u.V1.dwTime,
31 pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.type,
32 pStcCtrlMsg->u.sCanMessage.u.V1.dwMsgId,
33 pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.ext ? 'E' : ' ',
34 pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.rtr ? 'R' : ' ',
35 pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.srr ? 'S' : ' ',
36 pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.edl ? 'L' : ' ',
37 pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.brs ? 'B' : ' ',
38 pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.ovr ? 'O' : ' ');
39
40 if (not pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.rtr)
41 {
42 BYTE bRealLen = ECI_CAN_FD_DLC_LUT[pStcCtrlMsg->u.sCanMessage.u.V1.uMsgInfo.Bits.dlc];
43
44 if (ECI_STRUCT_VERSION_V0 == pStcCtrlMsg->u.sCanMessage.dwVer)
45 {
46 bRealLen = static_cast<BYTE>(
47 std::min(static_cast<uint64_t>(bRealLen), std::size(pStcCtrlMsg->u.sCanMessage.u.V0.abData)));
48 }
49 else if (ECI_STRUCT_VERSION_V1 == pStcCtrlMsg->u.sCanMessage.dwVer)
50 {
51 bRealLen = static_cast<BYTE>(
52 std::min(static_cast<uint64_t>(bRealLen), std::size(pStcCtrlMsg->u.sCanMessage.u.V1.abData)));
53 }
54
55 if (bRealLen)
56 {
57 OS_Printf("Data: ");
58
59 for (BYTE bIndex = 0; bIndex < bRealLen; bIndex++)
60 {
61 OS_Printf("%02X ", pStcCtrlMsg->u.sCanMessage.u.V1.abData[bIndex]);
62 }
63 }
64 }
65 else
66 {
67 OS_Printf("DLC: %u", pStcCtrlMsg->u.sCanMessage.u.V0.uMsgInfo.Bits.dlc);
68 }
69
70 OS_Printf("\n");
71 }
72 break;
73 }
74
75 case ECI_CTRL_LIN:
76 {
77 if (ECI_STRUCT_VERSION_V0 == pStcCtrlMsg->u.sLinMessage.dwVer)
78 {
79 OS_Printf(
80 "Time: %10u, Type: %2u, ID: %08X, Flags: %c%c%c%c ", pStcCtrlMsg->u.sLinMessage.u.V0.dwTime,
81 pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.type, pStcCtrlMsg->u.sLinMessage.u.V0.dwMsgId,
82 pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.ecs ? 'E' : ' ',
83 pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.ido ? 'I' : ' ',
84 pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.sor ? 'S' : ' ',
85 pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.ovr ? 'O' : ' ');
86
87 if (!pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.ido)
88 {
89 if (pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.dlc)
90 {
91 BYTE bIndex = 0;
92 OS_Printf("Data: ");
93 for (bIndex = 0; bIndex < pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.dlc; bIndex++)
94 {
95 OS_Printf("%02X ", pStcCtrlMsg->u.sLinMessage.u.V0.abData[bIndex]);
96 }
97 }
98 }
99 else
100 {
101 OS_Printf("DLC: %u", pStcCtrlMsg->u.sLinMessage.u.V0.uMsgInfo.Bits.dlc);
102 }
103 }
104 break;
105 }
106
107 default:
108 break;
109 }
110
111 OS_Fflush(stdout);
112 }
113 else
114 {
115 OS_Printf("ERROR: invalid pointer: pStcCtrlMsg\n");
116 }
117}
118
119inline bool parseBoard(const iv::model::comms::NetworkData &commConfig, IIxxatInterface **interfaceOpt,
120 std::string *hwSerial, uint32_t *hwPort, unsigned char *operationMode,
121 unsigned char *busTimingRegister0, unsigned char *busTimingRegister1)
122{
123 bool isParsedOK = true;
124 *interfaceOpt = new IxxatUsbToCanV1();
125
126 if (not commConfig._interfaceSettings.ixxatUsbDeviceSettings._hwSerial.empty())
127 {
129 }
130 else
131 {
132 isParsedOK = false;
133 }
134
136
138 {
140 *operationMode = ECI_CAN_OPMODE_EXTENDED;
141 break;
142
144 *operationMode = ECI_CAN_OPMODE_LISTONLY;
145 break;
146
148 *operationMode = ECI_CAN_OPMODE_LOWSPEED;
149 break;
150
152 *operationMode = ECI_CAN_OPMODE_STANDARD;
153 break;
154
157 default:
158 isParsedOK = false;
159 IV_ASSERT_MSG("[IXXATCommonFunctions:parseBoard] Open mode not valid.");
160 break;
161 }
162
164 {
165 *operationMode |= ECI_CAN_OPMODE_ERRFRAME;
166 }
167
169 {
171 *busTimingRegister0 = ECI_CAN_BT0_10KB;
172 *busTimingRegister1 = ECI_CAN_BT1_10KB;
173 break;
174
176 *busTimingRegister0 = ECI_CAN_BT0_20KB;
177 *busTimingRegister1 = ECI_CAN_BT1_20KB;
178 break;
179
181 *busTimingRegister0 = ECI_CAN_BT0_50KB;
182 *busTimingRegister1 = ECI_CAN_BT1_50KB;
183 break;
184
186 *busTimingRegister0 = ECI_CAN_BT0_100KB;
187 *busTimingRegister1 = ECI_CAN_BT1_100KB;
188 break;
189
191 *busTimingRegister0 = ECI_CAN_BT0_125KB;
192 *busTimingRegister1 = ECI_CAN_BT1_125KB;
193 break;
194
196 *busTimingRegister0 = ECI_CAN_BT0_250KB;
197 *busTimingRegister1 = ECI_CAN_BT1_250KB;
198 break;
199
201 *busTimingRegister0 = ECI_CAN_BT0_500KB;
202 *busTimingRegister1 = ECI_CAN_BT1_500KB;
203 break;
204
206 *busTimingRegister0 = ECI_CAN_BT0_800KB;
207 *busTimingRegister1 = ECI_CAN_BT1_800KB;
208 break;
209
211 *busTimingRegister0 = ECI_CAN_BT0_1000KB;
212 *busTimingRegister1 = ECI_CAN_BT1_1000KB;
213 break;
214
215 default:
216 isParsedOK = false;
217 IV_ASSERT_MSG("[IXXATCommonFunctions:parseBoard] Baud rate not valid.");
218 break;
219 }
220
221 return isParsedOK;
222}
223
224}// namespace iv::comms::ixxat
225
226#endif /* IV_SRC_COMMS_IXXAT_IXXATCOMMONFUNCTIONS_HPP_ */
#define IV_ASSERT_MSG(msg,...)
Definition assert.hpp:152
Definition IIxxatInterface.hpp:11
Definition IxxatUsbToCanV1.hpp:15
Definition IIxxatInterface.hpp:8
const BYTE ECI_CAN_FD_DLC_LUT[16]
Definition IxxatCommonFunctions.hpp:15
void EciPrintCtrlMessage(const ECI_CTRL_MESSAGE *pStcCtrlMsg, const std::string &strDevice, const bool isSending)
Definition IxxatCommonFunctions.hpp:17
bool parseBoard(const iv::model::comms::NetworkData &commConfig, IIxxatInterface **interfaceOpt, std::string *hwSerial, uint32_t *hwPort, unsigned char *operationMode, unsigned char *busTimingRegister0, unsigned char *busTimingRegister1)
Definition IxxatCommonFunctions.hpp:119
iv::model::comms::ixxat::UsbDeviceSettings ixxatUsbDeviceSettings
Definition InterfaceSettings.hpp:34
Definition NetworkData.hpp:18
iv::model::comms::InterfaceSettings _interfaceSettings
Definition NetworkData.hpp:49
iv::model::comms::ixxat::eBaudRate _baudRate
Definition IxxatSettings.hpp:61
iv::types::ipPort _hwPort
Definition IxxatSettings.hpp:60
std::string _hwSerial
Definition IxxatSettings.hpp:59
iv::model::comms::ixxat::eOperationMode _operationMode
Definition IxxatSettings.hpp:62
bool _enableErrorFrames
Definition IxxatSettings.hpp:63