python-can-hirain-test 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1661 @@
1
+ import ctypes
2
+ from ctypes import c_ubyte
3
+
4
+ # HiMetalAPI公共部分结构
5
+ CRITICAL_SECTION_TIMEOUT = 4000
6
+ MAX_DEVICE_COUNT = 5 # 设备同时在线最大个数
7
+ H3_CHANNEL_COUNT = 12 # 硬件通道数
8
+
9
+ H3_BUS_COUNT = 3 # 总线类型个数
10
+ MAX_BUS_ERROR_TYPE_COUNT = 13 # 总线错误类型最大个数
11
+
12
+ MAX_PROT_ON_CHANNEL = 10 # 一个物理通道上最多同时打开的端口上限(可调)
13
+
14
+ WINXP = 0x051 # XP系统版本号
15
+
16
+ # 缓冲区大小
17
+ MAX_TX_DATA_SIZE = 4128
18
+ MAX_RX_DATA_SIZE = 8192 # 极限情况下(1M波特率,高(92.5%)负载)的trace缓存大小
19
+
20
+ BUF_MAX_SIZE = 256
21
+ BUF_MID_SIZE = 128
22
+ BUF_MIN_SIZE = 64
23
+
24
+ # 设备传输模式
25
+ DEVICE_TRANS_MODE_USB = 0
26
+ DEVICE_TRANS_MODE_WIFI = 1
27
+ DEVICE_TRANS_MODE_BLUETOOTH = 2
28
+
29
+ # 设备类型
30
+ TESTBASEVCI_3 = 0
31
+ TESTBASEVCI_4 = 1
32
+
33
+ # CAN波特率
34
+ BAUD_100K = 100000
35
+ BAUD_125K = 125000
36
+ BAUD_250K = 250000
37
+ BAUD_500K = 500000
38
+ BAUD_33K = 33000
39
+ BAUD_1M = 1000000
40
+ BAUD_2M = 2000000
41
+ BAUD_3M = 3000000
42
+ BAUD_4M = 4000000
43
+ BAUD_5M = 5000000
44
+
45
+ LISTEN_NORMAL_TRANSMIT = 0
46
+ LISTEN_BUS_LISTEN = 1
47
+
48
+ SAMPLE_75 = 0
49
+ SAMPLE_50 = 1
50
+
51
+ LIN_DATA_FIELD_LEN = 11 # ErrorCode + TxRxFlag + LinData + Checksum
52
+
53
+ '''
54
+ typedef struct
55
+ {
56
+ UNUM8 ucChannelIndex;//通道索引号(多硬件时依次为1,2,3,4...)
57
+ UNUM32 unChannelMask;//通道掩码(1,2,4,8,16,32,...) = (1<<(ucChannelIndex-1));
58
+ CHAR8 szHwName[BUF_MIN_SIZE];//所属硬件名称
59
+ UNUM8 ucHwType;//所属硬件类型(H3_HARDWARE_TYPE 0-TESTBASEVCI_3, 1-TESTBASEVCI_4)
60
+ CHAR8 szHwAdditionalInfo[BUF_MAX_SIZE];//所属硬件附加信息(USB:path; WIFI:ip)
61
+ UNUM8 ucHwChannelNo;//所属硬件中的实际通道号(1~8)
62
+ UNUM8 ucHwTransMode;//所属硬件通信方式(H3_TRANS_MODE 0-USB; 1-WIFI; 3-BLUETOOTH)
63
+ UNUM8 ucBusCapabilities;//通道支持的总线类型掩码(H3_BUS_TYPE组合,如H3_BUS_TYPE_CAN, H3_BUS_TYPE_CAN | H3_BUS_TYPE_CANFD)
64
+ } H3ChannelConfig;
65
+ '''
66
+
67
+
68
+ class H3ChannelConfig(ctypes.Structure):
69
+ # 通道信息
70
+ _fields_ = [("ucChannelIndex", ctypes.c_ubyte),
71
+ ("unChannelMask", ctypes.c_ulonglong),
72
+ ("szHwName", ctypes.c_char * BUF_MIN_SIZE),
73
+ ("szHwType", ctypes.c_ubyte),
74
+ ("szHwAdditionalInfo", ctypes.c_char * BUF_MAX_SIZE),
75
+ ("ucHwChannelNo", ctypes.c_ubyte),
76
+ ("ucHwTransMode", ctypes.c_ubyte),
77
+ ("ucBusCapabilities", ctypes.c_ubyte)]
78
+
79
+
80
+ class StaticMacAddress(ctypes.Structure):
81
+ # 静态MAC地址结构体
82
+ _fields_ = [("szMac", ctypes.c_ubyte * 20),
83
+ ("szIP", ctypes.c_ubyte * 20)]
84
+
85
+
86
+ MAX_ONLINE_CHANNEL_COUNT = 64
87
+ MAX_ONLINE_CHANNEL_COUNT_EX = 320
88
+ MAX_ONLINE_DEVICE_COUNT = 5
89
+
90
+
91
+ class H3DriverConfig(ctypes.Structure):
92
+ # 可用硬件设备配置
93
+ _fields_ = [("nChannelCount", ctypes.c_int),
94
+ ("h3Channels", H3ChannelConfig * MAX_ONLINE_CHANNEL_COUNT)]
95
+
96
+ class H3DriverConfigEx(ctypes.Structure):
97
+ # 可用硬件设备配置
98
+ _fields_ = [("nChannelCount", ctypes.c_int),
99
+ ("h3Channels", H3ChannelConfig * MAX_ONLINE_CHANNEL_COUNT_EX)]
100
+
101
+
102
+ # 访问权限
103
+ ACCESS_CHANNEL_CAN_TXRX = 0x00
104
+ ACCESS_CHANNEL_CAN_15765 = 0x01
105
+ ACCESS_CHANNEL_CAN_J1939 = 0x02
106
+ ACCESS_CHANNEL_K = 0x03
107
+ ACCESS_CHANNEL_LIN = 0x04
108
+ ACCESS_DEVICE = 0x05
109
+ ACCESS_DEFAULT = 0xff
110
+
111
+
112
+ class CANTransChangeData(ctypes.Structure):
113
+ # CAN转发数据修改信息结构体
114
+ _fields_ = [("unChangeStartBit", ctypes.c_uint16), # 数据修改起始位
115
+ ("unChangeBitLen", ctypes.c_ubyte), # 数据修改比特长度(上限8)
116
+ ("unChangeVal", ctypes.c_ubyte)] # 修改为的数据(未修改位补零)
117
+
118
+
119
+ class CANTransConfig(ctypes.Structure):
120
+ # CAN转发服务配置结构体
121
+ _fields_ = [("unSourceChannel", ctypes.c_ubyte), # 数据修改起始位
122
+ ("unTargetChannel", ctypes.c_ubyte), # 数据修改比特长度(上限8)
123
+ ("bStartStopFlag", ctypes.c_ubyte),
124
+ ("unCANid", ctypes.c_ulonglong),
125
+ ("unCounter", ctypes.c_ubyte),
126
+ ("ChangeData", CANTransChangeData * 64)] # 修改为的数据(未修改位补零)
127
+
128
+
129
+ class UsbDevice(ctypes.Structure):
130
+ # US枚举信息
131
+ _fields_ = [("szDevName", ctypes.c_char * BUF_MIN_SIZE), # 设备名称
132
+ ("szDevPath", ctypes.c_char * BUF_MAX_SIZE), # 设备路径
133
+ ("szManufacturer", ctypes.c_char * BUF_MAX_SIZE), # 厂商名称
134
+ ("szProduct", ctypes.c_char * BUF_MAX_SIZE), # 商品名称
135
+ ("szFirmwareVersion", ctypes.c_char * BUF_MIN_SIZE)] # 设备固件版本
136
+
137
+
138
+ class WifiDevice(ctypes.Structure):
139
+ # wifi枚举信息
140
+ _fields_ = [("szDevName", ctypes.c_char * BUF_MIN_SIZE),
141
+ ("szDevIP", ctypes.c_char * BUF_MIN_SIZE)]
142
+
143
+
144
+ class BlueToothDevice(ctypes.Structure):
145
+ # 蓝牙枚举信息
146
+ _fields_ = []
147
+
148
+
149
+ class DEVICE_SWBUILDVERSION(ctypes.Structure):
150
+ # 获取设备应用软件构建服务信息
151
+ _fields_ = [("sw_GreekVersion", ctypes.c_uint), # 希腊字母版本号
152
+ ("szBuild", ctypes.c_uint * 5),
153
+ ("sw_BuildVersion", ctypes.c_uint32)] # 应用软件日期版本号
154
+
155
+
156
+ METAL_EVENT_TYPE_DIAGNOSTIC = 0x01 # 诊断序列事件
157
+ METAL_EVENT_TYPE_TRACE = 0x02 # Trace序列事件
158
+ METAL_EVENT_TYPE_ERROR = 0x03 # 错误信息事件
159
+
160
+ SERVICE_ERROR_PROCESS_BUFFER_FULL = 0x10
161
+ SERVICE_ERROR_SAME_REQUEST = 0x11
162
+ SERVICE_ERROR_REQ_CONDITON_CORRECT = 0x12
163
+ SERVICE_ERROR_REQ_PARAM_OUT_OF_BUFFER = 0x13
164
+ SERVICE_ERROR_REQ_GID_NOT_SUPPORT = 0x14
165
+ SERVICE_ERROR_REQ_SID_NOT_SUPPORT = 0x15
166
+ SERVICE_ERROR_TRANSFER_LENGTH_INVALID = 0x16
167
+ SERVICE_ERROR_REQ_OUTOF_RANGE = 0x17
168
+ SERVICE_ERROR_NOT_INIT_BEFOR_CHANNGE = 0x18
169
+ SERVICE_ERROR_REQ_CAN_ID_NOT_SUPPORT = 0x19
170
+ SERVICE_ERROR_FLASH_ERASE = 0x1c
171
+ SERVICE_ERROR_FLASH_WRITE = 0x1d
172
+
173
+
174
+ class SERVICE_ERROR(ctypes.Structure):
175
+ _fields_ = [("ucErrorCode", ctypes.c_ubyte)]
176
+
177
+
178
+ class DeviceConfig(ctypes.Structure):
179
+ _fields_ = [("ucDevType", ctypes.c_ubyte), # 设备类型
180
+ ("szSerialNo", ctypes.c_char_p), # 序列号
181
+ ("ucHwVersion_1", ctypes.c_ubyte), # 硬件主版本号
182
+ ("ucHwVersion_2", ctypes.c_ubyte), # 硬件从版本号
183
+ ("ucBtVersion_1", ctypes.c_ubyte), # boostloader主版本号
184
+ ("ucBtVersion_2", ctypes.c_ubyte), # boostloader从版本号
185
+ ("ucBtVersion_3", ctypes.c_ubyte)] # boostloader修订版本号
186
+
187
+
188
+ class DeviceIdentifier(ctypes.Structure):
189
+ # 获取设备标识符
190
+ _fields_ = [("ucDevTypeMask", ctypes.c_ubyte), # 设备类型掩码
191
+ ("szDevSerialNo", ctypes.c_char * BUF_MIN_SIZE)] # 序列号
192
+
193
+
194
+ class WifiCommConfig(ctypes.Structure):
195
+ # wifi配置结构体
196
+ _fields_ = [("szSSID", ctypes.c_char * 40), # wifi名称
197
+ ("szKey", ctypes.c_char * 64), # wifi密匙
198
+ ("szDevIP", ctypes.c_char * 20), # 设备ip
199
+ ("szNetMask", ctypes.c_char * 20), # 设备网络掩码
200
+ ("szGateway", ctypes.c_char * 20)] # 设备ip网关
201
+
202
+
203
+ class DeviceVersion(ctypes.Structure):
204
+ _fields_ = [("hw_version_1", ctypes.c_ubyte), # hardware主版本号
205
+ ("hw_version_2", ctypes.c_ubyte), # hardware从版本号
206
+ ("bt_version_1", ctypes.c_ubyte), # boostloader主版本号
207
+ ("bt_version_2", ctypes.c_ubyte), # boostloader从版本号
208
+ ("bt_version_3", ctypes.c_ubyte), # boostloader修订版本号
209
+ ("sw_version_1", ctypes.c_ubyte), # software主版本号
210
+ ("sw_version_2", ctypes.c_ubyte), # software从版本号
211
+ ("sw_version_3", ctypes.c_ubyte)] # software修订版本号
212
+
213
+
214
+ # CAN监听状态
215
+ NORMAL_TRANSMIT = 0
216
+ BUS_LISTEN = 1
217
+
218
+ # CAN采样点
219
+ SAMPLE_75 = 0
220
+ SAMPLE_50 = 1
221
+
222
+
223
+ class CAN_HW_CONFIG(ctypes.Structure):
224
+ # CAN通道配置结构体
225
+ _fields_ = [("ucBaudrate", ctypes.c_ubyte), # 波特率 CAN_BAUDRATE枚举值
226
+ ("ucListenFlag", ctypes.c_ubyte), # 监听状态 CAN_LISTEN_FLAG枚举值
227
+ ("ucSamplePoint", ctypes.c_ubyte)] # 采样点 CAN_SAMPLEPOINT枚举值
228
+
229
+
230
+ class EcuInfo(ctypes.Structure):
231
+ # ECU ID对
232
+ _fields_ = [("ucEcuAddr", ctypes.c_ubyte),
233
+ ("unReqID", ctypes.c_uint), # 物理请求ID
234
+ ("unUSDTRespID", ctypes.c_uint), # 响应ID
235
+ ("unUUDTRespID", ctypes.c_uint)]
236
+
237
+
238
+ class CAN_DIAGNOSTIC_CONFIG(ctypes.Structure):
239
+ # CAN诊断服务配置
240
+ _fields_ = [("ucDataPadding", ctypes.c_ubyte), # CAN数据域中未使用字节的填充数值
241
+ ("ucDeviceAddr", ctypes.c_ubyte), # 设备地址
242
+ ("unFuncReqID", ctypes.c_uint),
243
+ ("ucEcuCount", ctypes.c_ubyte),
244
+ ("ecuInfo", EcuInfo * BUF_MAX_SIZE)]
245
+
246
+
247
+ # UDS诊断类型
248
+ MTYPE_LOCAL = 0x01
249
+ MTYPE_REMOTE = 0x02
250
+
251
+ # UDS帧报文数据场最大字节
252
+ MAX_15765_DATA_FILED_LENGTH = 4095
253
+
254
+
255
+ class CanRequest(ctypes.Structure):
256
+ # CAN诊断请求结构体
257
+ _fields_ = [("unReqID", ctypes.c_uint),
258
+ ("ucMType", ctypes.c_ubyte), # CANMType枚举值
259
+ ("usDataLen", ctypes.c_ushort), # 最大MAX_15765_DATA_FILED_LENGTH = 4095
260
+ ("ucData", ctypes.c_ubyte * MAX_15765_DATA_FILED_LENGTH)]
261
+
262
+
263
+ '''
264
+ //CAN数据信息
265
+ typedef struct CAN_MSG
266
+ {
267
+ UNUM32 unCanId;
268
+ UNUM8 ucTag;//0-发送/1-接收帧
269
+ UNUM8 ucEDL;//0-CAN 1-CANFD
270
+ UNUM8 ucBRS;//0-关 1-开
271
+ UNUM8 ucDLC;//数据长度,最大为CAN_MSG_LENGTH
272
+ UNUM8 ucData[CAN_MSG_LENGTH];
273
+ UNUM32 unTimestamp;
274
+ } CanMsg;
275
+
276
+ '''
277
+ CAN_MSG_LENGTH = 64
278
+
279
+
280
+ class GET_CAN_TRACE(ctypes.Structure):
281
+ # CAN数据信息
282
+ _fields_ = [("unCanId", ctypes.c_uint),
283
+ ("ucTag", ctypes.c_ubyte),
284
+ ("ucEDL", ctypes.c_ubyte),
285
+ ("ucBRS", ctypes.c_ubyte),
286
+ ("ucDLC", ctypes.c_ubyte),
287
+ ("ucData", ctypes.c_ubyte * CAN_MSG_LENGTH),
288
+ ("unTimestamp", ctypes.c_uint32)]
289
+
290
+
291
+ class CanPeriodTxInfo(ctypes.Structure):
292
+ # CAN周期性发送数据
293
+ _fields_ = [("canMsg", GET_CAN_TRACE),
294
+ ("usPeriod", ctypes.c_ushort)]
295
+
296
+
297
+ class SEQ_MSG_LIST(ctypes.Structure):
298
+ # generator CAN报文序列发送
299
+ _fields_ = [("ucChannelIndex", ctypes.c_ubyte),
300
+ ("ucSendCount", ctypes.c_uint16),
301
+ ("unSendTime", ctypes.c_uint32),
302
+ ("unDelayTime", ctypes.c_uint32),
303
+ ("canMsg", GET_CAN_TRACE)]
304
+
305
+
306
+ MAX_SEQ_MSG_COUNT = 32
307
+
308
+
309
+ class GEN_SEQ_CONFIG(ctypes.Structure):
310
+ # generator 序列发送配置
311
+ _fields_ = [("bonoff", ctypes.c_bool),
312
+ ("seqMsgsList", SEQ_MSG_LIST * MAX_SEQ_MSG_COUNT)]
313
+
314
+
315
+ class BusErrorInfo(ctypes.Structure):
316
+ _fields_ = [("unTimestamp", ctypes.c_ubyte),
317
+ ("ucErrorCode", ctypes.c_ubyte)]
318
+
319
+
320
+ MAX_CHANNEL_COUNT = 3
321
+
322
+
323
+ # GET_BUS_ERROR用于外部通过GetTrace接口获取错误帧/无应答帧类型的总线错误信息
324
+ class GET_BUS_ERROR(ctypes.Structure):
325
+ _fields_ = [("unTimestamp", ctypes.c_uint32),
326
+ ("ucFrameType", ctypes.c_ubyte),
327
+ ("ucErrorCode", ctypes.c_ubyte)]
328
+
329
+
330
+ # 配适V90A做错误帧
331
+ class GET_BUS_ERROREX(ctypes.Structure):
332
+ _fields_ = [("unTimestamp", ctypes.c_uint32),
333
+ ("ucFrameType", ctypes.c_ubyte),
334
+ ("ucErrorCode", ctypes.c_ubyte),
335
+ ("usErrorPosition", ctypes.c_uint16),
336
+ ("ucErrorMessage", ctypes.c_ubyte),
337
+ ("unCanId", ctypes.c_uint32),
338
+ ("ucTag", ctypes.c_ubyte),
339
+ ("ucEDL", ctypes.c_ubyte),
340
+ ("ucBRS", ctypes.c_ubyte),
341
+ ("ucDLC", ctypes.c_ubyte),
342
+ ("ucData", ctypes.c_ubyte * CAN_MSG_LENGTH)]
343
+
344
+
345
+ MAX_VALID_PDU_DATA_LEN = 10
346
+
347
+
348
+ class GET_DIAGNOSTIC_ERROR(ctypes.Structure):
349
+ _fields_ = [("ucErrorCode", ctypes.c_ubyte),
350
+ ("nDataSize", ctypes.c_int32),
351
+ ("ucData", ctypes.c_ubyte * MAX_VALID_PDU_DATA_LEN)]
352
+
353
+
354
+ # 获取15765诊断网络层确认
355
+ class GET_15765_2_CONFIRM(ctypes.Structure):
356
+ _fields_ = [("unEcuReqId", ctypes.c_uint32),
357
+ ("ucMType", ctypes.c_ubyte),
358
+ ("ucNResult", ctypes.c_ubyte)]
359
+
360
+
361
+ # 15765诊断第一帧指示
362
+ class GET_15765_2_FF_INDICATION(ctypes.Structure):
363
+ _fields_ = [("unEcuRespId", ctypes.c_uint32),
364
+ ("ucMType", ctypes.c_ubyte),
365
+ ("usLength", ctypes.c_ubyte)]
366
+
367
+
368
+ MAX_15765_DATA_FILED_LENGTH = 4095
369
+
370
+
371
+ # 15765诊断响应指示
372
+ class GET_15765_2_RESP_INDICATION(ctypes.Structure):
373
+ _fields_ = [("unEcuRespId", ctypes.c_uint32),
374
+ ("ucMType", ctypes.c_ubyte),
375
+ ("ucNResult", ctypes.c_ubyte),
376
+ ("usLength", ctypes.c_uint16),
377
+ ("ucData", ctypes.c_ubyte * MAX_15765_DATA_FILED_LENGTH)]
378
+
379
+
380
+ # 获取14230传输层确认信息
381
+ class GET_14230_2_CONFIRM(ctypes.Structure):
382
+ _fields_ = [("ucLResult", ctypes.c_ubyte)]
383
+
384
+
385
+ # 14230头部指示
386
+ class GET_14230_2_HEADER_INDICATION(ctypes.Structure):
387
+ _fields_ = [("ucFormat", ctypes.c_ubyte)]
388
+
389
+
390
+ MAX_14230_FRAME_SIZE = 260 # header(MAX=4)+DataField(MAX=255)+Checksum(1)
391
+
392
+
393
+ # 14230诊断响应指示
394
+ class GET_14230_2_RESP_INDICATION(ctypes.Structure):
395
+ _fields_ = [("ucLResult", ctypes.c_ubyte),
396
+ ("nFrameLen", ctypes.c_ubyte),
397
+ ("ucFrameBytes", ctypes.c_ubyte * MAX_14230_FRAME_SIZE)]
398
+
399
+
400
+ MAX_TRACE_MSG_COUNT = 2048
401
+
402
+ LIN_MSG_LEN = 8
403
+
404
+
405
+ class GET_LIN_TRACE(ctypes.Structure):
406
+ _fields_ = [("ucLinId", ctypes.c_ubyte),
407
+ ("unStartTimestamp", ctypes.c_uint32),
408
+ ("unEndTimestamp", ctypes.c_uint32),
409
+ ("ucCtlByte", ctypes.c_ubyte),
410
+ ("ucDataFiledLen", ctypes.c_ubyte),
411
+ ("ucDataFiled", ctypes.c_ubyte * LIN_DATA_FIELD_LEN)]
412
+
413
+
414
+ ETH_MSG_LENGTH = 1518
415
+
416
+
417
+ class ETH_MSG(ctypes.Structure):
418
+ _fields_ = [("unDataLength", ctypes.c_uint),
419
+ ("ucData", ctypes.c_ubyte * ETH_MSG_LENGTH)]
420
+
421
+
422
+ class LINMsg(ctypes.Structure):
423
+ _fields_ = [("ucLinId", ctypes.c_ubyte),
424
+ ("ucDataLen", ctypes.c_ubyte),
425
+ ("ucData", ctypes.c_ubyte * LIN_MSG_LEN)]
426
+
427
+
428
+ class LinNode(ctypes.Structure):
429
+ _fields_ = [("ucLinId", ctypes.c_ubyte),
430
+ ("ucDlc", ctypes.c_ubyte),
431
+ ("usDelay", ctypes.c_ushort)]
432
+
433
+
434
+ class J1939SimulateFilter(ctypes.Structure):
435
+ _fields_ = [("unPGN", ctypes.c_uint),
436
+ ("ucSA", ctypes.c_ubyte),
437
+ ("ucDA", ctypes.c_ubyte)]
438
+
439
+
440
+ class J1939PG(ctypes.Structure):
441
+ _fields_ = [("unPGN", ctypes.c_uint),
442
+ ("ucSA", ctypes.c_ubyte),
443
+ ("ucDA", ctypes.c_ubyte)]
444
+
445
+
446
+ MAX_1939_DATA_LEN = 1785
447
+
448
+
449
+ class GET_1939_2_PACKET(ctypes.Structure):
450
+ _fields_ = [("unPGN", ctypes.c_uint),
451
+ ("ucSA", ctypes.c_ubyte),
452
+ ("ucDA", ctypes.c_ubyte),
453
+ ("unTimestamp", ctypes.c_uint32),
454
+ ("unDataLen", ctypes.c_uint),
455
+ ("ucData", ctypes.c_ubyte * MAX_1939_DATA_LEN)]
456
+
457
+
458
+ MAX_IO_ADC_LEN = 8
459
+
460
+
461
+ class GET_IO_TRACE(ctypes.Structure):
462
+ _fields_ = [("unEndTimestamp", ctypes.c_uint),
463
+ ("ucTrigger", ctypes.c_ubyte),
464
+ ("ucDI", ctypes.c_ubyte),
465
+ ("ucDO", ctypes.c_ubyte),
466
+ ("VCC3V3", ctypes.c_float),
467
+ ("fADC", ctypes.c_float * MAX_IO_ADC_LEN)]
468
+
469
+ class LinRxMsgEx(ctypes.Structure):
470
+ _fields_ = [('unLinId', ctypes.c_uint8), # LIN id,此id为接收到的包含2个奇偶检验位的LIN标识符场
471
+ ('unTimeStartOfFrame', ctypes.c_uint32), # LIN数据帧start_of_frame时刻
472
+ ('unTimeEnfOfFrame', ctypes.c_uint32), # LIN数据帧end_of_frame时刻
473
+ ('unCtlByte', ctypes.c_uint8), # 参考通信协议
474
+ ('unLinErrorCode', ctypes.c_uint16), # 参考通信协议
475
+ ('emTxRx', ctypes.c_uint8), # TX/RX标志,为0表示由设备发送,为1表示设备接收
476
+ ('unDLC', ctypes.c_uint8), # 报文数据场长度
477
+ ('unLinData', ctypes.c_uint8 * 8), # 字节(byte24-byte31)为lin_data
478
+ ('unChecksum', ctypes.c_uint8), # 接收报文校验和值
479
+ ('unCalculateChecksum', ctypes.c_uint8), # 理论报文校验和值
480
+ ('unEOH', ctypes.c_uint32), # 完整接收到报头的时间,需要硬件来记录时间戳。精度10ns以下时间参数精度都是10ns
481
+ ('unBreakField', ctypes.c_uint32), # 表示了同步间隔段的位时间
482
+ ('unBreakDelimiter', ctypes.c_uint32), # delimiterLen表示了间隔界定符的位时间
483
+ ('unInterbyte', ctypes.c_uint32), # 同步场和PID之前的字节间隔时间
484
+ ('unSyncByteData', ctypes.c_uint32), # 同步场数据段的位时间
485
+ ('unRespInterbytes', ctypes.c_uint32 * 8), # 表示了数据场第X字节前的间隔时间(8个)4byte*8
486
+ ('unInterbyteBeforeChecksum', ctypes.c_uint32), # checksum前的间隔位时间
487
+ ('unResponseLength', ctypes.c_uint32), # 总响应的位时间
488
+ ('unBaudrateofHeader', ctypes.c_uint32), # 请求场(header)的波特率
489
+ ('unBaudrateofData', ctypes.c_uint32)] # 响应场(data)的波特率]
490
+
491
+ class LinRxWakeupMsg(ctypes.Structure):
492
+ _fields_ = [('unStartTimeStamp', ctypes.c_uint32), # 接收唤醒信号的起始时间戳(10ns)
493
+ ('unEndTimeStamp', ctypes.c_uint32)] # 接收唤醒信号的最后时间戳(10ns)]
494
+
495
+ class LinParamsEx(ctypes.Structure):
496
+ _fields_ = [('emOpenClose', ctypes.c_uint8), # 0:close 1:open
497
+ ('unBaudrate', ctypes.c_uint16), # LIN通信波特率 200~20480
498
+ ('emLinVersion', ctypes.c_uint8), # LIN协议版本 0:1.3 1:2.0 2:2.1 3:2.2 4:SAE J-2602 2021
499
+ ('emPowerSupply', ctypes.c_uint8)] # 0:内部供电; 1:外部供电]
500
+
501
+
502
+
503
+
504
+ # # 无确认/双确认服务类型枚举
505
+ # RX_SERVICE_TYPE_BUS_ERROR = 0x00
506
+ # RX_SERVICE_TYPE_DIAGNOSTIC_ERROR = 0x01
507
+ # RX_SERVICE_TYPE_15765_2_CONFIRM = 0x02
508
+ # RX_SERVICE_TYPE_15765_2_FF_IND = 0x03
509
+ # RX_SERVICE_TYPE_15765_2_RESP_IND = 0x04
510
+ # RX_SERVICE_TYPE_14230_2_CONFIRM = 0x05
511
+ # RX_SERVICE_TYPE_14230_2_HEADER_IND = 0x06
512
+ # RX_SERVICE_TYPE_14230_2_RESP_IND = 0x07
513
+ # RX_SERVICE_TYPE_CAN_TRACE = 0x08
514
+ # RX_SERVICE_TYPE_1939_2_PACKET = 0x09
515
+ # RX_SERVICE_TYPE_LIN_TRACE = 0x0a
516
+ # RX_SERVICE_TYPE_IO_TRACE = 0X0b
517
+ # RX_SERVICE_TYPE_ETH_TRACE = 0x0C
518
+ #
519
+ # class RX_SERVICE_UNION(ctypes.Union):
520
+ # _fields_ = [("getBusError", GET_BUS_ERROR),
521
+ # ("getDiagnosticError", GET_DIAGNOSTIC_ERROR),
522
+ # ("get15765_2_Confirm", GET_15765_2_CONFIRM),
523
+ # ("get15765_2_FFInd", GET_15765_2_FF_INDICATION),
524
+ # ("get15765_2_RespInd", GET_15765_2_RESP_INDICATION),
525
+ # ("get14230_2_Confirm", GET_14230_2_CONFIRM),
526
+ # ("get14230_2_HeaderInd", GET_14230_2_HEADER_INDICATION),
527
+ # ("get14230_2_RespInd", GET_14230_2_RESP_INDICATION),
528
+ # ('get1939_2_Packet', GET_1939_2_PACKET),
529
+ # ("getCanTrace", GET_CAN_TRACE),
530
+ # ("getLinTrace", GET_LIN_TRACE),
531
+ # ("getIoTrace", GET_IO_TRACE),
532
+ # ("getEthTrace", GET_ETHERNET_TRACE)]
533
+ #
534
+ # # 无确认/双确认服务数据联合体
535
+ # class RX_SERVICE(ctypes.Structure):
536
+ # _fields_=[
537
+ # ("ucChannelIndex", ctypes.c_ubyte),
538
+ # ("nServiceType", ctypes.c_uint32),
539
+ # ("service", RX_SERVICE_UNION)
540
+ # ]
541
+
542
+ class CAN_PARAMS(ctypes.Structure):
543
+ _fields_ = [("ucListenFlag", ctypes.c_ubyte),
544
+ ("ucBaudrate", ctypes.c_uint),
545
+ ("ucSamplePoint", ctypes.c_ubyte)]
546
+
547
+
548
+ class CANFD_PARAMS(ctypes.Structure):
549
+ _fields_ = [("ucListenFlag", ctypes.c_ubyte),
550
+ ("abrBaudrate", ctypes.c_uint),
551
+ ("dbrBaudrate", ctypes.c_uint),
552
+ ("abrSamplePoint", ctypes.c_ubyte),
553
+ ("dbrSamplePoint", ctypes.c_ubyte)
554
+ ]
555
+
556
+
557
+ class K_PARAMS(ctypes.Structure):
558
+ _fields_ = [("unBaudrate", ctypes.c_uint)]
559
+
560
+
561
+ class LIN_PARAMS(ctypes.Structure):
562
+ _fields_ = [("unBaudrate", ctypes.c_short),
563
+ ("ucLinVersion", ctypes.c_ubyte)]
564
+
565
+
566
+ class LIN_PARAMS(ctypes.Structure):
567
+ _fields_ = [("unBaudrate", ctypes.c_short),
568
+ ("ucLinVersion", ctypes.c_ubyte)]
569
+
570
+
571
+ BUF_MAX_SIZE = 256
572
+ MAX_PATH = 260
573
+
574
+
575
+ class ETH_PARAMS(ctypes.Structure):
576
+ _fields_ = [("szFilter", ctypes.c_char * BUF_MAX_SIZE), # 过滤器
577
+ ("nMaxSize", ctypes.c_uint32), # DUMP文件记录最大字节数(暂不支持),0-不限制
578
+ ("nMaxPacks", ctypes.c_uint32), # DUMP文件记录最大以太网包个数,0-不限制
579
+ ("szDumpFileDir", ctypes.c_char * MAX_PATH)] # DUMP文件存放目录
580
+
581
+
582
+ class BaseTxT1_PARAMS(ctypes.Structure):
583
+ _fields_ = [
584
+ ("ucOperatModeType", ctypes.c_uint8),
585
+ ]
586
+
587
+
588
+ class CAN_CANFD_PARAMS_EX(ctypes.Structure):
589
+ _fields_ = [
590
+ ("ucCanMode", ctypes.c_uint8),
591
+ ("ucListenFlag", ctypes.c_uint8),
592
+ ("ucCanBrtBrp", ctypes.c_uint8),
593
+ ("ucCanBrtSjw", ctypes.c_uint8),
594
+ ("ucCanBrtTseg1", ctypes.c_uint8),
595
+ ("ucCanBrtTseg2", ctypes.c_uint8),
596
+ ("ucCanfdBrtBrp", ctypes.c_uint8),
597
+ ("ucCanfdBrtSjw", ctypes.c_uint8),
598
+ ("ucCanfdBrtTseg1", ctypes.c_uint8),
599
+ ("ucCanfdBrtTseg2", ctypes.c_uint8),
600
+ ("unAbrBaudrate", ctypes.c_uint32),
601
+ ("ucAbrSamplePoint", ctypes.c_uint8),
602
+ ("unDbrBaudrate", ctypes.c_uint32),
603
+ ("ucDbrSamplePoint", ctypes.c_uint8),
604
+ ]
605
+
606
+
607
+ class BUS_PARAM_UNION(ctypes.Union):
608
+ _fields_ = [("can", CAN_PARAMS),
609
+ ("canFd", CANFD_PARAMS),
610
+ ("k", K_PARAMS),
611
+ ("lin", LIN_PARAMS),
612
+ ("eth", ETH_PARAMS),
613
+ ("base", BaseTxT1_PARAMS),
614
+ ("canCanfdEx", CAN_CANFD_PARAMS_EX),
615
+ ("linEx", LinParamsEx),]
616
+
617
+
618
+ class CHANNEL_BUS_PARAMS(ctypes.Structure):
619
+ _fields_ = [
620
+ ("ucBusType", ctypes.c_ubyte),
621
+ ("busParam", BUS_PARAM_UNION)
622
+ ]
623
+
624
+
625
+ class ChannelOperate(ctypes.Structure):
626
+ # 启动通道监听
627
+ _fields_ = [("ucChannelNo", ctypes.c_ubyte),
628
+ ("ucPeriod", ctypes.c_ubyte),
629
+ ("ucOperate", ctypes.c_ubyte)]
630
+
631
+
632
+ class CAN_RX_MSGS(ctypes.Structure):
633
+ # 获取CAN通道接收数据
634
+ _fields_ = [("ucCanIdCount", ctypes.c_ubyte),
635
+ ("canMsg", GET_CAN_TRACE * BUF_MIN_SIZE)]
636
+
637
+
638
+ # 硬件
639
+ H3_DEVICE_ARRIVAL = 0x8000 # 设备加入
640
+ H3_DEVICE_REMOVAL = 0x8004 # 设备移除
641
+ H3_DEVICE_CONFLICT = 0x8006 # 设备冲突
642
+ H3_DEVICE_SYNCREMOVE = 0x8008 # 设备同步信号掉线
643
+
644
+
645
+ class DEVICE(ctypes.Structure):
646
+ _fields_ = [("szDevName", ctypes.c_char * BUF_MIN_SIZE), # 设备名称
647
+ ("ucTransMode", ctypes.c_ubyte), # 设备通信方式(H3_TRANS_MODE 0-USB; 1-WIFI; 3-BLUETOOTH)
648
+ ("unChangeCode", ctypes.c_uint)] # 设备变动码
649
+
650
+
651
+ class DEVICE_CHANGE(ctypes.Structure):
652
+ _fields_ = [("nDeviceCount", ctypes.c_int),
653
+ ("devices", DEVICE * MAX_ONLINE_DEVICE_COUNT)]
654
+
655
+
656
+ class SEQ_LISTSEND_RESULT(ctypes.Structure):
657
+ _fields_ = [("nMessageCount", ctypes.c_int),
658
+ ("unSeqListID", ctypes.c_int64 * 10)]
659
+
660
+
661
+ class VCI_EXCEPTION(ctypes.Structure):
662
+ _fields_ = [("szFuncName", ctypes.c_char * BUF_MAX_SIZE),
663
+ ("usLineNumber", ctypes.c_uint),
664
+ ("szExpression", ctypes.c_char * BUF_MAX_SIZE)]
665
+
666
+
667
+ class REPLAY_EVENT(ctypes.Structure):
668
+ _fields_ = [("szDevName", ctypes.c_char * BUF_MIN_SIZE),
669
+ ("ucReplayCode", ctypes.c_uint)]
670
+
671
+
672
+ class DYNAMIC_MSG_EXCEPTION(ctypes.Structure):
673
+ _fields_ = [("unCanid", ctypes.c_uint), # 错误CANID
674
+ ("pDLLFunctionH", ctypes.c_uint), # 错误DLL回调函数指针高4位
675
+ ("pDLLFunctionL", ctypes.c_uint), # 错误DLL回调函数指针低4位
676
+ ("szExceptionDLLPath", ctypes.c_char * 256), # DLL路径
677
+ ("szExceptionInfo", ctypes.c_char * 200)] # 异常信息
678
+
679
+
680
+ class AUTHORIZE_EVENT(ctypes.Structure):
681
+ _fields_ = [("ucFeatureId", ctypes.c_uint),
682
+ ("ucAuthCode", ctypes.c_uint)]
683
+
684
+
685
+ class BOOTLOADER_EVENT(ctypes.Structure):
686
+ _fields_ = [("szDevName", ctypes.c_char * BUF_MIN_SIZE),
687
+ ("ucBootCode", ctypes.c_uint)]
688
+
689
+
690
+ class AUTHORIZE_TRY_DAYS_EVENT(ctypes.Structure):
691
+ _fields_ = [("ucFeatureId", ctypes.c_uint),
692
+ ("ucRemainTryDays", ctypes.c_uint)]
693
+
694
+
695
+ class EVENT_INFO(ctypes.Union):
696
+ _fields_ = [("deviceChange", DEVICE_CHANGE),
697
+ ("exception", VCI_EXCEPTION),
698
+ ("replay", REPLAY_EVENT),
699
+ ("bootloader", BOOTLOADER_EVENT),
700
+ ("authorize", AUTHORIZE_EVENT),
701
+ ("authorizetrydue", AUTHORIZE_TRY_DAYS_EVENT),
702
+ ("dynamicMsg", DYNAMIC_MSG_EXCEPTION),
703
+ ("seqListsend", SEQ_LISTSEND_RESULT)]
704
+
705
+
706
+ class H3_EVENT(ctypes.Structure):
707
+ # 获取CAN通道接收数据
708
+ _fields_ = [("ucEventType", ctypes.c_ubyte),
709
+ ("eventInfo", EVENT_INFO)]
710
+
711
+ class CAN_Parameter(ctypes.Structure):
712
+ _fields_ = [("ucMType", ctypes.c_ubyte),
713
+ ("ucParameter", ctypes.c_ubyte),
714
+ ("unValue", ctypes.c_ushort)]
715
+
716
+
717
+ # 协议载荷
718
+ ETHERNET_MAX_PAYLOAD_SIZE = 1500
719
+
720
+
721
+ class Payload(ctypes.Structure):
722
+ _fields_ = [("data_len", ctypes.c_uint32),
723
+ ("data", ctypes.c_ubyte * ETHERNET_MAX_PAYLOAD_SIZE)]
724
+
725
+
726
+ class TcpHeader(ctypes.Structure):
727
+ _fields_ = [("src_port", ctypes.c_uint16),
728
+ ("des_port", ctypes.c_uint16),
729
+ ("seq_num", ctypes.c_uint32),
730
+ ("ack", ctypes.c_uint32),
731
+ ("header_len", ctypes.c_uint8),
732
+ ("flags", ctypes.c_uint8),
733
+ ("winows", ctypes.c_uint16),
734
+ ("checksum", ctypes.c_uint16),
735
+ ("urp", ctypes.c_uint16)]
736
+
737
+
738
+ class TCP(ctypes.Structure):
739
+ _fields_ = [("header", TcpHeader),
740
+ ("payload", Payload)]
741
+
742
+
743
+ class UdpHeader(ctypes.Structure):
744
+ _fields_ = [("src_port", ctypes.c_uint16),
745
+ ("des_port", ctypes.c_uint16),
746
+ ("length", ctypes.c_uint16),
747
+ ("checksum", ctypes.c_uint16),
748
+ ("urp", ctypes.c_uint16)]
749
+
750
+
751
+ class UDP(ctypes.Structure):
752
+ _fields_ = [("header", UdpHeader),
753
+ ("payload", Payload)]
754
+
755
+
756
+ class IcmpHeader(ctypes.Structure):
757
+ _fields_ = []
758
+
759
+
760
+ class IcmpData(ctypes.Structure):
761
+ _fields_ = []
762
+
763
+
764
+ class ICMP(ctypes.Structure):
765
+ _fields_ = [("header", IcmpHeader),
766
+ ("data", IcmpData)]
767
+
768
+
769
+ class IpHeader(ctypes.Structure):
770
+ _fields_ = [("ip_header_length", ctypes.c_ubyte),
771
+ ("ip_tos", ctypes.c_ubyte),
772
+ ("ip_length", ctypes.c_uint16),
773
+ ("ip_id", ctypes.c_uint16),
774
+ ("ip_flags", ctypes.c_uint16),
775
+ ("ip_ttl", ctypes.c_ubyte),
776
+ ("ip_protocol", ctypes.c_ubyte),
777
+ ("ip_checksum", ctypes.c_uint16),
778
+ ("ip_souce_address", ctypes.c_char * 255),
779
+ ("ip_destination_address", ctypes.c_char * 255)]
780
+
781
+
782
+ class IpData(ctypes.Union):
783
+ _fields_ = [("tcp", TCP),
784
+ ("UDP", UDP),
785
+ ("ICMP", ICMP)]
786
+
787
+
788
+ class IP(ctypes.Structure):
789
+ _fields_ = [("header", IpHeader),
790
+ ("data", IpData)]
791
+
792
+
793
+ class ArpHeader(ctypes.Structure):
794
+ _fields_ = [("ip_header_length", ctypes.c_ubyte),
795
+ ("ip_tos", ctypes.c_ubyte),
796
+ ("ip_length", ctypes.c_uint16),
797
+ ("ip_id", ctypes.c_uint16),
798
+ ("ip_flags", ctypes.c_uint16),
799
+ ("ip_ttl", ctypes.c_ubyte),
800
+ ("ip_protocol", ctypes.c_ubyte),
801
+ ("ip_checksum", ctypes.c_uint16),
802
+ ("ip_souce_address", ctypes.c_char * 255),
803
+ ("ip_destination_address", ctypes.c_char * 255)]
804
+
805
+
806
+ class ARPData(ctypes.Union):
807
+ _fields_ = []
808
+
809
+
810
+ class ARP(ctypes.Structure):
811
+ _fields_ = [("header", ArpHeader),
812
+ ("data", ARPData)]
813
+
814
+
815
+ class EthernetHeader(ctypes.Structure):
816
+ _fields_ = [("ether_dhost", ctypes.c_ubyte * 6),
817
+ ("ether_shost", ctypes.c_ubyte * 6),
818
+ ("ether_type", ctypes.c_uint16)]
819
+
820
+
821
+ class EthernetData(ctypes.Union):
822
+ _fields_ = [("ip", IP),
823
+ ("arp", ARP)]
824
+
825
+
826
+ # ETHERNET_MAX_SIZE = 9216 #1600 9216
827
+ ETHERNET_MAX_SIZE = 16384 # 1600 9216
828
+
829
+
830
+ class EthRawData(ctypes.Structure):
831
+ _fields_ = [("unDataLen", ctypes.c_uint32),
832
+ ("ucData", ctypes.c_ubyte * ETHERNET_MAX_SIZE)]
833
+
834
+
835
+ class GET_ETHERNET_TRACE(ctypes.Structure):
836
+ _fields_ = [("unTimestamp", ctypes.c_uint64),
837
+ ("ethRawData", EthRawData)]
838
+
839
+
840
+ BASET1TX_MAX_SIZE = 1600
841
+
842
+
843
+ class GET_BASET1TX_TRACE(ctypes.Structure):
844
+ _fields_ = [("unTimestamp", ctypes.c_uint64),
845
+ ("unETHFrameTimestamp", ctypes.c_uint64),
846
+ ("ucTag", ctypes.c_uint8),
847
+ ("unDataLen", ctypes.c_uint32),
848
+ ("ucData", ctypes.c_uint8 * BASET1TX_MAX_SIZE)]
849
+
850
+
851
+ class POSITIVE_RESPONSEDATA(ctypes.Structure):
852
+ _fields_ = [("ucAddress", ctypes.c_ubyte * 2),
853
+ ("unDataLen", ctypes.c_uint16),
854
+ ("ucData", ctypes.c_ubyte * 65535)
855
+ ]
856
+
857
+
858
+ DOIP_RespCount = 50
859
+
860
+
861
+ class DOIP_POSITIVE_RESPONSE(ctypes.Structure):
862
+ _fields_ = [("ucResp_Count", ctypes.c_uint16),
863
+ ("ResponseData", POSITIVE_RESPONSEDATA * DOIP_RespCount)]
864
+
865
+
866
+ class DOIP_NEGATIVE_RESPONSE(ctypes.Structure):
867
+ _fields_ = [("ucNrc", ctypes.c_uint16)]
868
+
869
+
870
+ class DoipDiagnostUnion(ctypes.Union):
871
+ _fields_ = [("positive_response", DOIP_POSITIVE_RESPONSE), # doip诊断报文肯定响应
872
+ ("negative_response", DOIP_NEGATIVE_RESPONSE) # doip诊断报文否定响应
873
+ ]
874
+
875
+
876
+ class GET_DOIP_DIAGNOSTIC(ctypes.Structure):
877
+ _fields_ = [("unTimestamp", ctypes.c_uint64),
878
+ ("unSocketCfgId", ctypes.c_uint16),
879
+ ("bRespType", ctypes.c_ubyte), # 0:肯定响应 1:否定响应
880
+ ("doipdiagnostic", DoipDiagnostUnion)]
881
+
882
+
883
+ # 无确认/双确认服务类型枚举
884
+ RX_SERVICE_TYPE_BUS_ERROR = 0x00
885
+ RX_SERVICE_TYPE_DIAGNOSTIC_ERROR = 0x01
886
+ RX_SERVICE_TYPE_15765_2_CONFIRM = 0x02
887
+ RX_SERVICE_TYPE_15765_2_FF_IND = 0x03
888
+ RX_SERVICE_TYPE_15765_2_RESP_IND = 0x04
889
+ RX_SERVICE_TYPE_14230_2_CONFIRM = 0x05
890
+ RX_SERVICE_TYPE_14230_2_HEADER_IND = 0x06
891
+ RX_SERVICE_TYPE_14230_2_RESP_IND = 0x07
892
+ RX_SERVICE_TYPE_CAN_TRACE = 0x08
893
+ RX_SERVICE_TYPE_1939_2_PACKET = 0x09
894
+ RX_SERVICE_TYPE_LIN_TRACE = 0x0a
895
+ RX_SERVICE_TYPE_IO_TRACE = 0X0b
896
+ RX_SERVICE_TYPE_ETH_TRACE = 0x0C
897
+ RX_SERVICE_TYPE_BASET1TX = 0x0d
898
+ RX_SERVICE_TYPE_BUS_ERROR_EX = 0x10
899
+
900
+
901
+ class RX_SERVICE_UNION(ctypes.Union):
902
+ _fields_ = [("getBusError", GET_BUS_ERROR),
903
+ ("getDiagnosticError", GET_DIAGNOSTIC_ERROR),
904
+ ("get15765_2_Confirm", GET_15765_2_CONFIRM),
905
+ ("get15765_2_FFInd", GET_15765_2_FF_INDICATION),
906
+ ("get15765_2_RespInd", GET_15765_2_RESP_INDICATION),
907
+ ("get14230_2_Confirm", GET_14230_2_CONFIRM),
908
+ ("get14230_2_HeaderInd", GET_14230_2_HEADER_INDICATION),
909
+ ("get14230_2_RespInd", GET_14230_2_RESP_INDICATION),
910
+ ('get1939_2_Packet', GET_1939_2_PACKET),
911
+ ("getCanTrace", GET_CAN_TRACE),
912
+ ("getLinTrace", GET_LIN_TRACE),
913
+ ("getIoTrace", GET_IO_TRACE),
914
+ ("getEthTrace", GET_ETHERNET_TRACE),
915
+ ("getBASET1TXTrace", GET_BASET1TX_TRACE),
916
+ ("getBusErrorEX", GET_BUS_ERROREX),
917
+ ("getLinTraceEx", LinRxMsgEx),
918
+ ("getLinWakeup", LinRxWakeupMsg)]
919
+
920
+
921
+ # 无确认/双确认服务数据联合体
922
+ class RX_SERVICE(ctypes.Structure):
923
+ _fields_ = [
924
+ ("ucChannelIndex", ctypes.c_ubyte),
925
+ ("nServiceType", ctypes.c_uint32),
926
+ ("service", RX_SERVICE_UNION)
927
+ ]
928
+
929
+
930
+ # -----------------V90A-----------------
931
+ class OperatMode(ctypes.Structure):
932
+ _fields_ = [
933
+ ("unChannelIndex", ctypes.c_uint32),
934
+ ("ucChannelMode", ctypes.c_uint8)
935
+ ]
936
+
937
+
938
+ class BypassMode(ctypes.c_int):
939
+ NOBypass = 0
940
+ MACBypass = 1
941
+ PHYBypass = 2
942
+
943
+
944
+ class TapMode(ctypes.Structure):
945
+ _fields_ = [
946
+ ("unTapChannelIndex", ctypes.c_uint8),
947
+ ("ucBypassMode", ctypes.c_uint8)
948
+ ]
949
+
950
+
951
+ class Channelstate(ctypes.Structure):
952
+ _fields_ = [
953
+ ("ucChannelIndex", ctypes.c_uint8),
954
+ ("unChannelState", ctypes.c_uint8)
955
+ ]
956
+
957
+
958
+ MAC_IP_MASK_NUM = 20
959
+
960
+
961
+ class DeviceInfomation(ctypes.Structure):
962
+ _fields_ = [
963
+ ("szMac", ctypes.c_ubyte * MAC_IP_MASK_NUM),
964
+ ("szDevIP", ctypes.c_ubyte * MAC_IP_MASK_NUM),
965
+ ("szGateway", ctypes.c_ubyte * MAC_IP_MASK_NUM),
966
+ ("szNetMask", ctypes.c_ubyte * MAC_IP_MASK_NUM),
967
+ ("szVlanTagFlag", ctypes.c_ubyte),
968
+ ("unVlanTag", ctypes.c_uint32)
969
+ ]
970
+
971
+
972
+ IP_COUNT = 4
973
+ PORT_COUNT = 2
974
+
975
+
976
+ class BaseCommParam(ctypes.Structure):
977
+ _fields_ = [
978
+ ("ucVirdevnumber", ctypes.c_uint16),
979
+ ("szCommonbase_dip", ctypes.c_ubyte * IP_COUNT),
980
+ ("szCommonbase_sport", ctypes.c_ubyte * PORT_COUNT),
981
+ ("szCommonbase_dport", ctypes.c_ubyte * PORT_COUNT)
982
+ ]
983
+
984
+
985
+ BUF_BASECHANNEL_COUNT = 256
986
+
987
+
988
+ class CommParamList(ctypes.Structure):
989
+ _fields_ = [
990
+ ("ucChannelIndex", ctypes.c_uint8),
991
+ ("ucSocketCfgCounts", ctypes.c_uint8),
992
+ ("szSocketIdList", ctypes.c_uint16 * BUF_BASECHANNEL_COUNT)
993
+ ]
994
+
995
+
996
+ H3_MAX_PERIODTX_PACK_COUNT = 150
997
+
998
+
999
+ class TaskIDList(ctypes.Structure):
1000
+ _fields_ = [
1001
+ ("ucChannelIndex", ctypes.c_uint8),
1002
+ ("ucTaskCounts", ctypes.c_char),
1003
+ ("szTaskIdList", ctypes.c_uint16 * H3_MAX_PERIODTX_PACK_COUNT)
1004
+ ]
1005
+
1006
+
1007
+ BASE_MSG_ETH_LENGTH = 1518
1008
+ BASE_MSG_TU_LENGTH = 65535
1009
+
1010
+
1011
+ class BaseMsg(ctypes.Structure):
1012
+ _fields_ = [
1013
+ ("ucType", ctypes.c_uint8),
1014
+ ("usSocketCfgId", ctypes.c_uint16),
1015
+ ("ucDLC", ctypes.c_uint16),
1016
+ ("ucData", ctypes.c_uint8 * BASE_MSG_TU_LENGTH)
1017
+ ]
1018
+
1019
+
1020
+ class BaseEthFrame(ctypes.Structure):
1021
+ _fields_ = [
1022
+ ("unDataLength", ctypes.c_uint32),
1023
+ ("ucData", ctypes.c_uint8 * BASE_MSG_ETH_LENGTH)
1024
+ ]
1025
+
1026
+
1027
+ class BasePeriodMsg(ctypes.Union):
1028
+ _fields_ = [
1029
+ ("baseMsg", BaseMsg),
1030
+ ("baseethframe", BaseEthFrame)
1031
+ ]
1032
+
1033
+
1034
+ class BasePeriodTxInfo(ctypes.Structure):
1035
+ _fields_ = [
1036
+ ("usPeriod", ctypes.c_uint32),
1037
+ ("usTaskId", ctypes.c_uint16),
1038
+ ("ucBaseMsgType", ctypes.c_uint8),
1039
+ ("basePeriodMsg", BasePeriodMsg)
1040
+ ]
1041
+
1042
+
1043
+ class AddressConfig(ctypes.Structure):
1044
+ _fields_ = [
1045
+ ("szMac", ctypes.c_ubyte * MAC_IP_MASK_NUM),
1046
+ ("szDevIP", ctypes.c_ubyte * MAC_IP_MASK_NUM),
1047
+ ("szNetMask", ctypes.c_ubyte * MAC_IP_MASK_NUM),
1048
+ ("szGateway", ctypes.c_ubyte * MAC_IP_MASK_NUM)
1049
+ ]
1050
+
1051
+
1052
+ class IPRange(ctypes.Structure):
1053
+ _fields_ = [
1054
+ ("szStartIP", ctypes.c_ubyte * MAC_IP_MASK_NUM),
1055
+ ("szEndIP", ctypes.c_ubyte * MAC_IP_MASK_NUM)
1056
+ ]
1057
+
1058
+
1059
+ class DiagServiceMsg(ctypes.Structure):
1060
+ _fields_ = [
1061
+ ("usSocketCfgId", ctypes.c_uint16),
1062
+ ("usDoipP6Max", ctypes.c_uint16),
1063
+ ("usDoipP6Start", ctypes.c_uint16),
1064
+ ("usDoipP3Phy", ctypes.c_uint16),
1065
+ ("usDoipP3Func", ctypes.c_uint16),
1066
+ ("usDoipS3Client", ctypes.c_uint16),
1067
+ ("ucFlagAddress", ctypes.c_uint8),
1068
+ ("ucLogicalAddress", ctypes.c_uint16),
1069
+ ("ucFlagResponse", ctypes.c_uint8),
1070
+ ("unDataLength", ctypes.c_uint32),
1071
+ ("szData", ctypes.c_uint8 * 4096)
1072
+ ]
1073
+
1074
+
1075
+ class DiagCommonConfig(ctypes.Structure):
1076
+ _fields_ = [
1077
+ ("ucChannelIndex", ctypes.c_uint8),
1078
+ ("ucVirdevnumber", ctypes.c_uint16),
1079
+ ("ucLogicalAddress", ctypes.c_uint16),
1080
+ ("ucDoipVersion", ctypes.c_uint8)
1081
+ ]
1082
+
1083
+
1084
+ class DiagDoipCommonConfig(ctypes.Structure):
1085
+ _fields_ = [
1086
+ ("ucChannelIndex", ctypes.c_ubyte),
1087
+ ("szEntityIp", ctypes.c_ubyte * 4),
1088
+ ("ucPhyLogicalAddress", ctypes.c_uint16),
1089
+ ("ucFunLogicalAddress", ctypes.c_uint16)
1090
+ ]
1091
+
1092
+
1093
+ class VehicleInfomationTable(ctypes.Structure):
1094
+ _fields_ = [
1095
+ ("szDevIP", ctypes.c_ubyte * 4),
1096
+ ("szVin", ctypes.c_ubyte * 17),
1097
+ ("szLoicalAddress", ctypes.c_ubyte * 2),
1098
+ ("szEid", ctypes.c_ubyte * 6),
1099
+ ("szGid", ctypes.c_ubyte * 6),
1100
+ ("szFurtherActionRequire", ctypes.c_ubyte),
1101
+ ("szVinGidSyncStatus", ctypes.c_ubyte)
1102
+ ]
1103
+
1104
+
1105
+ class VehicleInfomation(ctypes.Structure):
1106
+ _fields_ = [
1107
+ ("unTimestamp", ctypes.c_uint64),
1108
+ ("usAnnoCount", ctypes.c_uint16),
1109
+ ("VehicleInfoTable", VehicleInfomationTable * 512)
1110
+ ]
1111
+
1112
+
1113
+ # 车辆声明请求配置结构体
1114
+ class VehicleInfomationRequest(ctypes.Structure):
1115
+ _fields_ = [
1116
+ ("usAnnounceWaitTime", ctypes.c_uint16), # 车辆识别请求中的等待时间
1117
+ ("ucAnnounceRepeatTime", ctypes.c_uint8), # 车辆识别请求重复次数
1118
+ ("usAnnounceTimeInterval", ctypes.c_uint16), # 车辆识别请求时间间隔
1119
+ ("ucFlag", ctypes.c_ubyte), # 组播或广播,0:广播 1:组播
1120
+ ("usPort", ctypes.c_uint16), # port端口号
1121
+ ("szMulticastIP", ctypes.c_ubyte * 4) # 组播IP地址
1122
+ ]
1123
+
1124
+
1125
+ class DiagnosticTimParameters(ctypes.Structure):
1126
+ _fields_ = [
1127
+ ("ucSocketCfgId", ctypes.c_uint16),
1128
+ ("ucDoipP6Max", ctypes.c_uint16),
1129
+ ("ucDoipP6Start", ctypes.c_uint16),
1130
+ ("ucDoipP3Phy", ctypes.c_uint16),
1131
+ ("ucDoipP3Func", ctypes.c_uint16),
1132
+ ("ucDoipS3Client", ctypes.c_uint16)
1133
+ ]
1134
+
1135
+
1136
+ class BASE_BAUDRATE(ctypes.c_int):
1137
+ BASET1_1000_MASTER_TX1000 = 0
1138
+ BASET1_1000_SLAVE_TX100 = 1
1139
+ BASET1_100_MASTER_TXAUTO = 2
1140
+ BASET1_100_SLAVE = 3
1141
+
1142
+
1143
+ class STATIC_MAC_ADDRESS(ctypes.Structure):
1144
+ _fields_ = [
1145
+ ("szMac", ctypes.c_ubyte * MAC_IP_MASK_NUM),
1146
+ ("szIP", ctypes.c_ubyte * MAC_IP_MASK_NUM),
1147
+ ("unDevNum", ctypes.c_ubyte),
1148
+ ]
1149
+
1150
+
1151
+ # -------------V90X-------------
1152
+ class SwBasePortOption(ctypes.Structure):
1153
+ _fields_ = [
1154
+ ("ucPortNum", ctypes.c_ubyte),
1155
+ ("ucPortState", ctypes.c_ubyte),
1156
+ ("ucMasterSlaverMode", ctypes.c_ubyte),
1157
+ ("ucSpeed", ctypes.c_ubyte),
1158
+ ("ucMode", ctypes.c_ubyte),
1159
+ ]
1160
+
1161
+
1162
+ # V90X SFP端口配置结构体
1163
+ class SwSFPPortOption(ctypes.Structure):
1164
+ _fields_ = [
1165
+ ("ucPortNum", ctypes.c_ubyte),
1166
+ ("ucPortState", ctypes.c_ubyte),
1167
+ ("ucSpeed", ctypes.c_ubyte),
1168
+ ]
1169
+
1170
+
1171
+ # V90X 端口隔离配置结构体
1172
+ class SwPortSegmentationOption(ctypes.Structure):
1173
+ _fields_ = [
1174
+ ("ucIngressId", ctypes.c_ubyte),
1175
+ ("usEgressConnection", ctypes.c_ushort),
1176
+ ]
1177
+
1178
+
1179
+ V90X_CHANNEL_NUM = 10
1180
+
1181
+
1182
+ class SWVlanConfiguration(ctypes.Structure):
1183
+ _fields_ = [
1184
+ ("usVlanID", ctypes.c_ushort),
1185
+ ("ucEgressVidRemarking", ctypes.c_ubyte * V90X_CHANNEL_NUM),
1186
+ ]
1187
+
1188
+
1189
+ # V90X VLAN配置结构体
1190
+ class SwVlanOption(ctypes.Structure):
1191
+ _fields_ = [
1192
+ ("usVID", ctypes.c_ushort),
1193
+ ("ucEgressVidRemarking", ctypes.c_ubyte),
1194
+ ]
1195
+
1196
+
1197
+ SZ_UC_MAC = 6
1198
+
1199
+
1200
+ # V90X 地址解析表
1201
+ class SwAddressResolutionTable(ctypes.Structure):
1202
+ _fields_ = [
1203
+ ("ucMac", ctypes.c_ubyte * SZ_UC_MAC),
1204
+ ("ucPort", ctypes.c_ubyte),
1205
+ ("ucAge", ctypes.c_ubyte),
1206
+ ]
1207
+
1208
+
1209
+ # Gateway CANTransChangeData
1210
+ class CANTransChangeData(ctypes.Structure):
1211
+ _fields_ = [
1212
+ ("unChangeStartBit", ctypes.c_uint16),
1213
+ ("unChangeBitLen", ctypes.c_ubyte),
1214
+ ("unChangeVal", ctypes.c_ubyte),
1215
+ ]
1216
+
1217
+
1218
+ # Gateway CANTransConfig
1219
+ class CANTransConfig(ctypes.Structure):
1220
+ _fields_ = [
1221
+ ("unSourceChannel", ctypes.c_ubyte),
1222
+ ("unTargetChannel", ctypes.c_ubyte),
1223
+ ("bStartStopFlag", ctypes.c_ubyte),
1224
+ ("unCANid", ctypes.c_uint32),
1225
+ ("unCounter", ctypes.c_ubyte),
1226
+ ("ChangeData", CANTransChangeData * 64),
1227
+ ]
1228
+
1229
+
1230
+ # LICENSE日期
1231
+ class ITEM_LICENSE(ctypes.Structure):
1232
+ _fields_ = [("unFeatureID", ctypes.c_uint32),
1233
+ ("bTry", ctypes.c_int),
1234
+ ("unDateStart", ctypes.c_uint16 * 3),
1235
+ ("unDateDue", ctypes.c_uint16 * 3)]
1236
+
1237
+
1238
+ # 设备具有的所有授权项
1239
+ class DEVICE_LICENSES(ctypes.Structure):
1240
+ _fields_ = [("unItemLicensesNum", ctypes.c_uint32),
1241
+ ("ItemLicenses", ITEM_LICENSE * 12)]
1242
+
1243
+
1244
+ # V90A报文发送功能组
1245
+ class BaseTCPClientCommParam(ctypes.Structure):
1246
+ _fields_ = [("ucVirdevnumber", ctypes.c_uint16),
1247
+ ("szCommonbase_dip", ctypes.c_ubyte * IP_COUNT),
1248
+ ("unSrcPort", ctypes.c_uint16),
1249
+ ("unDestPort", ctypes.c_uint16),
1250
+ ("unTimeOut", ctypes.c_uint8)]
1251
+
1252
+
1253
+ class BaseTCPServerCommParam(ctypes.Structure):
1254
+ _fields_ = [("ucVirdevnumber", ctypes.c_uint16),
1255
+ ("unSrcPort", ctypes.c_uint16),
1256
+ ("unTimeOut", ctypes.c_uint8)]
1257
+
1258
+
1259
+ class BaseTCPServerConnection(ctypes.Structure):
1260
+ _fields_ = [("unConnNum", ctypes.c_uint32),
1261
+ ("unClientIP", ctypes.c_ubyte * IP_COUNT),
1262
+ ("unClientPort", ctypes.c_uint16)]
1263
+
1264
+
1265
+ class BaseTCPServerConnections(ctypes.Structure):
1266
+ _fields_ = [("unConnCount", ctypes.c_uint8),
1267
+ ("TCPConnections", BaseTCPServerConnection * 256)]
1268
+
1269
+
1270
+ class OperateMode(ctypes.Structure):
1271
+ _fields_ = [
1272
+ ("ucChannelIndex", ctypes.c_uint8),
1273
+ ("ucOperatModeType", ctypes.c_uint8)
1274
+ ]
1275
+
1276
+
1277
+ class BaseEthMsg(ctypes.Structure):
1278
+ _fields_ = [
1279
+ ("ucBaseMsgType", ctypes.c_uint8),
1280
+ ("usSocketCfgId", ctypes.c_uint32),
1281
+ ("szDestIp", ctypes.c_ubyte * IP_COUNT),
1282
+ ("ucDestPort", ctypes.c_uint16),
1283
+ ("ucDLC", ctypes.c_uint16),
1284
+ ("ucData", ctypes.c_ubyte * BASE_MSG_TU_LENGTH)
1285
+ ]
1286
+
1287
+
1288
+ class PeriodSendCtrlCode(ctypes.c_int):
1289
+ PERIOD_CTRL_SEND = 1 # 发送周期报文
1290
+ PERIOD_CTRL_UPDATE = 2 # 更新周期报文
1291
+ PERIOD_CTRL_DELETE = 3 # 删除周期报文
1292
+
1293
+
1294
+ class SetBasePeriodTxInfo(ctypes.Structure):
1295
+ _fields_ = [
1296
+ ("ucBaseMsgType", ctypes.c_uint8),
1297
+ ("usSocketCfgId", ctypes.c_uint32),
1298
+ ("szDestIp", ctypes.c_ubyte * IP_COUNT),
1299
+ ("ucDestPort", ctypes.c_uint16),
1300
+ ("usPeriod", ctypes.c_uint32),
1301
+ ("usTaskId", ctypes.c_uint16),
1302
+ ("ucDLC", ctypes.c_uint16),
1303
+ ("ucData", ctypes.c_ubyte * BASE_MSG_TU_LENGTH)
1304
+ ]
1305
+
1306
+
1307
+ class UpdateBasePeriodTxInfo(ctypes.Structure):
1308
+ _fields_ = [
1309
+ ("usPeriod", ctypes.c_uint32),
1310
+ ("usTaskId", ctypes.c_uint16),
1311
+ ("ucDLC", ctypes.c_uint16),
1312
+ ("ucData", ctypes.c_ubyte * BASE_MSG_TU_LENGTH)
1313
+ ]
1314
+
1315
+
1316
+ class DeleteBasePeriodTxInfo(ctypes.Structure):
1317
+ _fields_ = [
1318
+ ("ucTaskCount", ctypes.c_uint8),
1319
+ ("usTaskId", ctypes.c_uint16 * 255)
1320
+ ]
1321
+
1322
+
1323
+ class BasePeriodMsgex(ctypes.Union):
1324
+ _fields_ = [("setperiodMsg", SetBasePeriodTxInfo),
1325
+ ("updateperiodMsg", UpdateBasePeriodTxInfo),
1326
+ ("deleteperiodMsg", DeleteBasePeriodTxInfo)
1327
+ ]
1328
+
1329
+
1330
+ class BasePeriodTxInfoEx(ctypes.Structure):
1331
+ _fields_ = [("ucCode", ctypes.c_uint8),
1332
+ ("basePeriodMsgex", BasePeriodMsgex)
1333
+ ]
1334
+
1335
+
1336
+ class StaticIPAddress(ctypes.Union):
1337
+ _fields_ = [("unMac", ctypes.c_ubyte * SZ_UC_MAC),
1338
+ ("unIP", ctypes.c_ubyte * IP_COUNT)
1339
+ ]
1340
+
1341
+
1342
+ class DHCPParams(ctypes.Structure):
1343
+ _fields_ = [("unStartIP", ctypes.c_ubyte * IP_COUNT),
1344
+ ("unEndIP", ctypes.c_ubyte * IP_COUNT),
1345
+ ("unMask", ctypes.c_uint8), # 子网掩码连续1的个数
1346
+ ("unGateway", ctypes.c_ubyte * IP_COUNT),
1347
+ ("unLeasesTime", ctypes.c_uint16),
1348
+ ("unStaticIPCount", ctypes.c_uint8),
1349
+ ("StaticIPAddress", StaticIPAddress * 256)]
1350
+
1351
+
1352
+ # --------------------------------------------someIP 结构体---------------------------------------------
1353
+ class SomeIPSDInstance(ctypes.Structure):
1354
+ _fields_ = [("unIP", ctypes.c_ubyte * 4),
1355
+ ("unMask", ctypes.c_uint8),
1356
+ ("unVlan", ctypes.c_uint16),
1357
+ ("unPriority", ctypes.c_uint8)]
1358
+
1359
+
1360
+ class SomeIPClientEventGroup(ctypes.Structure):
1361
+ _fields_ = [("unID", ctypes.c_uint16),
1362
+ ("unMaxRequestResponseDelay", ctypes.c_uint16),
1363
+ ("unMinRequestResponseDelay", ctypes.c_uint16),
1364
+ ("unRetryDelay", ctypes.c_uint16),
1365
+ ("unMaxRetryCount", ctypes.c_uint8),
1366
+ ("unSubScriptionTTL", ctypes.c_uint8)]
1367
+
1368
+
1369
+ class SomeIPServerEventGroup(ctypes.Structure):
1370
+ _fields_ = [("unID", ctypes.c_uint16),
1371
+ ("unMaxRequestResponseDelay", ctypes.c_uint16),
1372
+ ("unMinRequestResponseDelay", ctypes.c_uint16)]
1373
+
1374
+
1375
+ class SomeIPSD(ctypes.Structure):
1376
+ # someIP下发的SD配置
1377
+ _fields_ = [("unMac", ctypes.c_ubyte * 6),
1378
+ ("unMuticastIP", ctypes.c_ubyte * 4),
1379
+ ("unPort", ctypes.c_uint16),
1380
+ ("unCount", ctypes.c_uint8),
1381
+ ("someIPSDInstanceList", SomeIPSDInstance * 10)]
1382
+
1383
+
1384
+ class SomeIPClient(ctypes.Structure):
1385
+ # 下发的SomeipClient配置
1386
+ _fields_ = [("unServiceID", ctypes.c_uint16),
1387
+ ("unInstanceID", ctypes.c_uint16),
1388
+ ("unIP", ctypes.c_ubyte * 4),
1389
+ ("unMask", ctypes.c_uint8),
1390
+ ("unUdpPort", ctypes.c_uint16),
1391
+ ("unTcpPort", ctypes.c_uint16),
1392
+ ("unMaxDelay", ctypes.c_uint16),
1393
+ ("unMinDelay", ctypes.c_uint16),
1394
+ ("unFindBehavior", ctypes.c_uint8),
1395
+ ("unRequiredMinorVersion", ctypes.c_uint8),
1396
+ ("unRepetitionBaseDelay", ctypes.c_uint64),
1397
+ ("unMaxInitalRepetition", ctypes.c_uint64),
1398
+ ("unUdpCollectionThreshold", ctypes.c_uint32),
1399
+ ("eventGroupCount", ctypes.c_uint8),
1400
+ ("someIPClientEventGroupList", SomeIPClientEventGroup * 256)]
1401
+
1402
+
1403
+ class SomeIPServer(ctypes.Structure):
1404
+ # 下发的SomeipServer配置
1405
+ _fields_ = [("unServiceID", ctypes.c_uint16),
1406
+ ("unInstanceID", ctypes.c_uint16),
1407
+ ("unIP", ctypes.c_ubyte * 4),
1408
+ ("unMask", ctypes.c_uint8),
1409
+ ("unUdpPort", ctypes.c_uint16),
1410
+ ("unTcpPort", ctypes.c_uint16),
1411
+ ("unMaxDelay", ctypes.c_uint16),
1412
+ ("unMinDelay", ctypes.c_uint16),
1413
+ ("unTTL", ctypes.c_uint32),
1414
+ ("unLoadBalancingPriority", ctypes.c_uint8),
1415
+ ("unLoadBalancingWeight", ctypes.c_uint8),
1416
+ ("unOfferCyclicDelay", ctypes.c_uint64),
1417
+ ("unRepetitionBaseDelay", ctypes.c_uint64),
1418
+ ("unMaxInitalRepetition", ctypes.c_uint32),
1419
+ ("unUdpCollectionThreshold", ctypes.c_uint32),
1420
+ ("eventGroupCount", ctypes.c_uint8),
1421
+ ("someIPServerEventGroupList", SomeIPServerEventGroup * 256)]
1422
+
1423
+
1424
+ class SomeIPService(ctypes.Structure):
1425
+ # 下发的SomeipMethod配置
1426
+ _fields_ = [("unModeType", ctypes.c_uint8), # 0-client,1-server,2-both
1427
+ ("unServiceID", ctypes.c_uint16),
1428
+ ("unVersion", ctypes.c_uint8 * 2),
1429
+ ("unProtocolType", ctypes.c_uint8)] # 0-None,1-tcp,2-udp,3-both
1430
+
1431
+
1432
+ class SomeIPMethod(ctypes.Structure):
1433
+ # 下发的SomeipMethod配置
1434
+ _fields_ = [("unModeType", ctypes.c_uint8), # 0-client,1-server,2-both
1435
+ ("unServiceID", ctypes.c_uint16),
1436
+ ("ununMethodID", ctypes.c_uint16),
1437
+ ("unProtocolType", ctypes.c_uint8), # 0-None,1-tcp,2-udp,3-both
1438
+ ("bFireandForget", ctypes.c_uint8), # 1-true 0-false Service对该请求是否回复
1439
+ ("unMaxRequestSeglen", ctypes.c_uint16),
1440
+ ("unMaxResponseSeglen", ctypes.c_uint16),
1441
+ ("unRequestSptime", ctypes.c_uint8),
1442
+ ("unResponseSptime", ctypes.c_uint8),
1443
+ ("unBurstSize", ctypes.c_uint16),
1444
+ ("unLength", ctypes.c_uint32),
1445
+ ("unPayload", ctypes.c_uint8 * 65535)] # 是否将多个udp合并发送,1-true,0-false
1446
+
1447
+
1448
+ class SomeIPEvent(ctypes.Structure):
1449
+ # 下发的SomeipEvent配置
1450
+ _fields_ = [("unModeType", ctypes.c_uint8),
1451
+ ("unServiceID", ctypes.c_uint16),
1452
+ ("unEventID", ctypes.c_uint16),
1453
+ ("unProtocolType", ctypes.c_uint8), # 0-None,1-tcp,2-udp,3-both
1454
+ ("bEditd", ctypes.c_uint8), # 1-true
1455
+ ("unLoopCycleTimer", ctypes.c_uint8),
1456
+ ("unBurstSize", ctypes.c_uint16),
1457
+ ("unMaxSegLen", ctypes.c_uint32),
1458
+ ("unSptime", ctypes.c_uint8),
1459
+ ("unLength", ctypes.c_uint32),
1460
+ ("unPayload", ctypes.c_uint8 * 65535)] # 1-true,0-false
1461
+
1462
+
1463
+ class SomeIPEventGroup(ctypes.Structure):
1464
+ # 下发的下发的SomeipEventGroup配置
1465
+ _fields_ = [("unModeType", ctypes.c_uint8),
1466
+ ("unServiceID", ctypes.c_uint16),
1467
+ ("unEventGroupID", ctypes.c_uint16),
1468
+ ("unProtocolType", ctypes.c_uint8), # 0-None,1-tcp,2-udp,3-both
1469
+ ("unEventCount", ctypes.c_uint32),
1470
+ ("unEventIDs", ctypes.c_uint16 * 256)]
1471
+
1472
+
1473
+ class SomeIPClientFireForget(ctypes.Structure):
1474
+ _fields_ = [("unServiceID", ctypes.c_uint16),
1475
+ ("unInstanceID", ctypes.c_uint16),
1476
+ ("unMethodID", ctypes.c_uint16),
1477
+ ("unLength", ctypes.c_uint32),
1478
+ ("unPayload", ctypes.c_uint8 * 65535)]
1479
+
1480
+
1481
+ class SomeIPServerRR(ctypes.Structure):
1482
+ _fields_ = [("unServiceID", ctypes.c_uint16),
1483
+ ("unInstanceID", ctypes.c_uint16),
1484
+ ("unMethodID", ctypes.c_uint16),
1485
+ ("unLength", ctypes.c_uint32),
1486
+ ("unPayload", ctypes.c_uint8 * 65535)]
1487
+
1488
+
1489
+ class SomeIPClientRR(ctypes.Structure):
1490
+ _fields_ = [("unServiceID", ctypes.c_uint16),
1491
+ ("unInstanceID", ctypes.c_uint16),
1492
+ ("unMethodID", ctypes.c_uint16),
1493
+ ("unTimeOut", ctypes.c_uint16), # ms,到达后90A立即返回6802
1494
+ ("unPostLength", ctypes.c_uint32),
1495
+ ("unPostPayload", ctypes.c_uint8 * 65535),
1496
+ ("unGetLength", ctypes.c_uint32),
1497
+ ("unGetPayload", ctypes.c_uint8 * 65535)]
1498
+
1499
+
1500
+ class SomeIPEventPacket(ctypes.Structure):
1501
+ _fields_ = [("unServiceID", ctypes.c_uint16),
1502
+ ("unInstanceID", ctypes.c_uint16),
1503
+ ("unEventID", ctypes.c_uint16),
1504
+ ("unSendMode", ctypes.c_uint8), # 0-单次 1-周期
1505
+ ("unPeriod", ctypes.c_uint16), # ms mode=1有效
1506
+ ("unStartStop", ctypes.c_uint8), # mode=1有效,0-停止 1-启动
1507
+ ("unLength", ctypes.c_uint32),
1508
+ ("unPayload", ctypes.c_uint8 * 65535)]
1509
+
1510
+ class FaultInjMsgSelection(ctypes.Structure):
1511
+ _fields_ = [('emMsgSelectionMode', ctypes.c_uint8), # 报文选择模式 0-黑名单 1-白名单
1512
+ ('emChlType', ctypes.c_uint8), # 报文类型 0-CAN/CANFD 1-LIN 2-ETH
1513
+ ('unMsgIdListSize', ctypes.c_uint16),
1514
+ ('unMsgIdList', ctypes.c_uint32 * 20),]
1515
+
1516
+ class FaultInjBitLocation(ctypes.Structure):
1517
+ _fields_ = [('emBitLocationType', ctypes.c_uint8), # 0-intel,1-摩托罗拉
1518
+ ('unBitStart', ctypes.c_uint16), # 起始比特
1519
+ ('unBitLength', ctypes.c_uint16),]
1520
+
1521
+ class FaultInjClicked(ctypes.Structure):
1522
+ _fields_ = [('emClickedMode', ctypes.c_uint8), # 故障注入触发模式,0-立即触发, 1-注册为信号触发并等待信号
1523
+ ('emDurationMode', ctypes.c_uint8), # 故障注入触发持续模式, 0-按次数 1-按持续时间
1524
+ ('unTimes', ctypes.c_uint16),
1525
+ ('hSem', ctypes.c_uint64)]
1526
+
1527
+ class FaultInjCRCAlgorithm(ctypes.Structure):
1528
+ _fields_ = [('emCRCAlgorithmType', ctypes.c_uint8), # 0x00-XOR8 0x01-CRC8 0x02-CRC16 0x10-自定义算法
1529
+ ('unPolynomial', ctypes.c_uint16),
1530
+ ('unInitial', ctypes.c_uint16),
1531
+ ('unOutXOR', ctypes.c_uint16),
1532
+ ('bInReflect', ctypes.c_bool),
1533
+ ('bOutReflect', ctypes.c_bool),
1534
+ ('bByteReflect', ctypes.c_bool),
1535
+ ('emComplementMode', ctypes.c_uint8), # 0-不补码 1-补码
1536
+ ('unComplementValue', ctypes.c_uint16),
1537
+ ('emDataIdPosition', ctypes.c_uint8), # 0-无Dataid 1-最前 2-最后
1538
+ ('unDataIdWidth', ctypes.c_uint8), # 0, 1, 2
1539
+ ('unDataIdValue', ctypes.c_uint16),
1540
+ ('pfAlgorithm', ctypes.c_void_p), # 仅当算法类型为自定义算法时需要设置
1541
+ ('stCRCLocation', FaultInjBitLocation),]
1542
+
1543
+ class FaultInjConfuse(ctypes.Structure):
1544
+ _fields_ = [('unConfuseFrame', ctypes.c_uint8 * 2),]
1545
+
1546
+ class FaultInjRevaluate(ctypes.Structure):
1547
+ _fields_ = [('emOriginFaultType', ctypes.c_uint8), # 原始故障类型 0-Counter 1-Signal 2-CRC
1548
+ ('szFormula', ctypes.c_char_p)]
1549
+
1550
+ # class FaultInjCustomization(ctypes.Structure):
1551
+ # _fields_ = [('emIntefaceType', ctypes.c_uint8),
1552
+ # 【ERROR】,]
1553
+
1554
+ class LinTxMsg(ctypes.Structure):
1555
+ _fields_ = [('emCtrlByte', ctypes.c_uint8), # 0-单发Header;1-发response或都发
1556
+ ('unLinId', ctypes.c_uint8), # 报文id 范围[0,63]
1557
+ ('unDLC', ctypes.c_uint8), # 数据长度 范围[0,8]
1558
+ ('unSyncByte', ctypes.c_uint8), # Value of Sync Byte field default:0x55 范围 [0,255]
1559
+ ('unInterByteBeforePID', ctypes.c_uint8), # interByte space before PID default: 0 范围 [0,63]
1560
+ ('unPID', ctypes.c_uint8), # Value of Protected Identifier field (8-bit).
1561
+ ('unBreakLength', ctypes.c_uint8), # Length of the Break field (dominant bits) in bit units default: 13 范围 [0,255]
1562
+ ('unDEL', ctypes.c_uint8), # Length of the Break Delimiter field (recessive bits) in bit units default:1 范围 [0,63]
1563
+ ('unLinData', ctypes.c_uint8 * 8), # 固定8个byte
1564
+ ('unInterByte', ctypes.c_uint8 * 8), # Length of inter-byte space between data bytes with corresponding indexes. Number of configurable values is defined by the Length Trans. value in the Transmit list. default:0 范围 [0,255]
1565
+ ('unInterByteCS', ctypes.c_uint8), # Length of inter-byte space before the checksum byte. default:0 范围 [0,255]
1566
+ ('emHeaderBaudrate', ctypes.c_uint32), # 报文头波特率 200-20480bps
1567
+ ('emRespBaudrate', ctypes.c_uint32)] # 响应的波特率 200-20480bps]
1568
+
1569
+ class LinWakeupMsg(ctypes.Structure):
1570
+ _fields_ = [('unToChannel', ctypes.c_uint8), # 0:唤醒或休眠VCI后不向总线发送相应的信号;1:唤醒或休眠VCI后向总线发送相应的信号
1571
+ ('unType', ctypes.c_uint8), # 0:唤醒VCI,VCI处于唤醒状态时也可直接发送唤醒信号;1:休眠VCI
1572
+ ('unRepeatTime', ctypes.c_uint8), # 唤醒信号重传次数
1573
+ ('emIntertime', ctypes.c_uint16), # 设置两个连续LIN唤醒电平的唤醒时间间隔,默认为【150ms】,支持用户配置为【50-500ms】
1574
+ ('emLength', ctypes.c_uint16), # 修改唤醒帧宽度,默认为【1000µs】,支持用户配置为【250-5000µs】
1575
+ ('unWakeupAndRun', ctypes.c_uint8)] # 支持修改唤醒后是否继续执行调度表的配置,默认为【是】;0:否;1:是]
1576
+
1577
+ class LinDisturbMsg(ctypes.Structure):
1578
+ _fields_ = [('emStartStop', ctypes.c_uint8), # 0:开启干扰;1:关闭干扰
1579
+ ('emEnableId', ctypes.c_uint8), # 使能数据场干扰报文ID,不使能时对所有ID生效;0:不使能;1:使能
1580
+ ('unId', ctypes.c_uint8), # Lin_id (非PID) : 设置数据场干扰报文ID
1581
+ ('emType', ctypes.c_uint8), # 0: 干扰为显性 ;1: 干扰为隐性
1582
+ ('unDisturbLength', ctypes.c_uint8), # 设置干扰位时间(单位bits)
1583
+ ('unOffset', ctypes.c_uint8), # 设置干扰偏移,0为最低位
1584
+ ('emField', ctypes.c_uint8),
1585
+ ('emEnableDistubTimes', ctypes.c_uint8), # 使能干扰次数设置,不使能时永久生效。0:不使能;1:使能
1586
+ ('unDisturbTimes', ctypes.c_uint16)] # 设置干扰次数]
1587
+
1588
+
1589
+ class SeqMsg(ctypes.Structure):
1590
+ # 序列报文
1591
+ _fields_ = [("ucChannelNo", ctypes.c_ubyte),
1592
+ ("ucSendCount", ctypes.c_uint16),
1593
+ ("unSendTime", ctypes.c_uint32),
1594
+ ("unDeltaTime", ctypes.c_uint32),
1595
+ ("canMsg", GET_CAN_TRACE)]
1596
+
1597
+ class SeqMsgList(ctypes.Structure):
1598
+ # 序列报文
1599
+ _fields_ = [("bonoff", ctypes.c_bool),
1600
+ ("SeqMsgs", SeqMsg*32)]
1601
+
1602
+
1603
+ class ReplayPack(ctypes.Structure):
1604
+ # CAN报文信息
1605
+ _fields_ = [("ucChannelIndex", ctypes.c_ubyte),
1606
+ ("unDeltaTime", ctypes.c_uint),
1607
+ ("canMsg", GET_CAN_TRACE)]
1608
+
1609
+
1610
+ class TestBaseVCI_ChlMode:
1611
+ CAN = 0
1612
+ CANFD = 1
1613
+
1614
+
1615
+ class TestBaseVCI_SAMPLEPOINT:
1616
+ SAMPLE_75 = 0
1617
+ SAMPLE_50 = 1
1618
+ SAMPLE_52_5 = 2
1619
+ SAMPLE_55 = 3
1620
+ SAMPLE_57_5 = 4
1621
+ SAMPLE_60 = 5
1622
+ SAMPLE_61_25 = 6
1623
+ SAMPLE_62_5 = 7
1624
+ SAMPLE_63_75 = 8
1625
+ SAMPLE_65 = 9
1626
+ SAMPLE_66_25 = 10
1627
+ SAMPLE_67_5 = 11
1628
+ SAMPLE_68 = 12
1629
+ SAMPLE_68_75 = 13
1630
+ SAMPLE_70 = 14
1631
+ SAMPLE_71_25 = 15
1632
+ SAMPLE_72_5 = 16
1633
+ SAMPLE_73_75 = 17
1634
+ SAMPLE_76_25 = 18
1635
+ SAMPLE_77_5 = 19
1636
+ SAMPLE_78_75 = 20
1637
+ SAMPLE_80 = 21
1638
+ SAMPLE_81_25 = 22
1639
+ SAMPLE_82_5 = 23
1640
+ SAMPLE_85 = 24
1641
+ SAMPLE_87_5 = 25
1642
+ SAMPLE_90 = 26
1643
+ SAMPLE_92_5 = 27
1644
+ SAMPLE_95 = 28
1645
+
1646
+ class CAN_LISTEN_MODE:
1647
+ NORMAL_TRANSMIT = 0
1648
+ BUS_LISTEN = 1
1649
+
1650
+
1651
+ class N_Parameter:
1652
+ N_STmin = 0x01
1653
+ N_BS = 0x02
1654
+ N_Cs = 0x03
1655
+ N_Bs = 0x04
1656
+ N_Cr = 0x05
1657
+ N_Opt = 0x06
1658
+
1659
+ class CANMType:
1660
+ MTYPE_LOCAL = 0x01
1661
+ MTYPE_REMOTE = 0x02