pyxcp 0.22.23__cp313-cp313-manylinux_2_28_x86_64.manylinux_2_27_x86_64.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.

Potentially problematic release.


This version of pyxcp might be problematic. Click here for more details.

Files changed (140) hide show
  1. pyxcp/__init__.py +20 -0
  2. pyxcp/aml/EtasCANMonitoring.a2l +82 -0
  3. pyxcp/aml/EtasCANMonitoring.aml +67 -0
  4. pyxcp/aml/XCP_Common.aml +408 -0
  5. pyxcp/aml/XCPonCAN.aml +78 -0
  6. pyxcp/aml/XCPonEth.aml +33 -0
  7. pyxcp/aml/XCPonFlx.aml +113 -0
  8. pyxcp/aml/XCPonSxI.aml +66 -0
  9. pyxcp/aml/XCPonUSB.aml +106 -0
  10. pyxcp/aml/ifdata_CAN.a2l +20 -0
  11. pyxcp/aml/ifdata_Eth.a2l +11 -0
  12. pyxcp/aml/ifdata_Flx.a2l +94 -0
  13. pyxcp/aml/ifdata_SxI.a2l +13 -0
  14. pyxcp/aml/ifdata_USB.a2l +81 -0
  15. pyxcp/asam/__init__.py +0 -0
  16. pyxcp/asam/types.py +131 -0
  17. pyxcp/asamkeydll.c +116 -0
  18. pyxcp/asamkeydll.sh +2 -0
  19. pyxcp/checksum.py +722 -0
  20. pyxcp/cmdline.py +52 -0
  21. pyxcp/config/__init__.py +1100 -0
  22. pyxcp/config/legacy.py +120 -0
  23. pyxcp/constants.py +47 -0
  24. pyxcp/cpp_ext/__init__.py +0 -0
  25. pyxcp/cpp_ext/bin.hpp +104 -0
  26. pyxcp/cpp_ext/blockmem.hpp +58 -0
  27. pyxcp/cpp_ext/cpp_ext.cpython-310-x86_64-linux-gnu.so +0 -0
  28. pyxcp/cpp_ext/cpp_ext.cpython-311-x86_64-linux-gnu.so +0 -0
  29. pyxcp/cpp_ext/cpp_ext.cpython-312-x86_64-linux-gnu.so +0 -0
  30. pyxcp/cpp_ext/cpp_ext.cpython-313-x86_64-linux-gnu.so +0 -0
  31. pyxcp/cpp_ext/cpp_ext.cpython-39-x86_64-linux-gnu.so +0 -0
  32. pyxcp/cpp_ext/daqlist.hpp +200 -0
  33. pyxcp/cpp_ext/event.hpp +67 -0
  34. pyxcp/cpp_ext/extension_wrapper.cpp +96 -0
  35. pyxcp/cpp_ext/helper.hpp +280 -0
  36. pyxcp/cpp_ext/mcobject.hpp +246 -0
  37. pyxcp/cpp_ext/tsqueue.hpp +46 -0
  38. pyxcp/daq_stim/__init__.py +228 -0
  39. pyxcp/daq_stim/optimize/__init__.py +67 -0
  40. pyxcp/daq_stim/optimize/binpacking.py +41 -0
  41. pyxcp/daq_stim/scheduler.cpp +28 -0
  42. pyxcp/daq_stim/scheduler.hpp +75 -0
  43. pyxcp/daq_stim/stim.cpp +13 -0
  44. pyxcp/daq_stim/stim.cpython-310-x86_64-linux-gnu.so +0 -0
  45. pyxcp/daq_stim/stim.cpython-311-x86_64-linux-gnu.so +0 -0
  46. pyxcp/daq_stim/stim.cpython-312-x86_64-linux-gnu.so +0 -0
  47. pyxcp/daq_stim/stim.cpython-313-x86_64-linux-gnu.so +0 -0
  48. pyxcp/daq_stim/stim.cpython-39-x86_64-linux-gnu.so +0 -0
  49. pyxcp/daq_stim/stim.hpp +604 -0
  50. pyxcp/daq_stim/stim_wrapper.cpp +48 -0
  51. pyxcp/dllif.py +95 -0
  52. pyxcp/errormatrix.py +878 -0
  53. pyxcp/examples/conf_can.toml +19 -0
  54. pyxcp/examples/conf_can_user.toml +16 -0
  55. pyxcp/examples/conf_can_vector.json +11 -0
  56. pyxcp/examples/conf_can_vector.toml +11 -0
  57. pyxcp/examples/conf_eth.toml +9 -0
  58. pyxcp/examples/conf_nixnet.json +20 -0
  59. pyxcp/examples/conf_socket_can.toml +12 -0
  60. pyxcp/examples/conf_sxi.json +9 -0
  61. pyxcp/examples/conf_sxi.toml +7 -0
  62. pyxcp/examples/ex_arrow.py +109 -0
  63. pyxcp/examples/ex_csv.py +85 -0
  64. pyxcp/examples/ex_excel.py +95 -0
  65. pyxcp/examples/ex_mdf.py +124 -0
  66. pyxcp/examples/ex_sqlite.py +128 -0
  67. pyxcp/examples/run_daq.py +148 -0
  68. pyxcp/examples/xcp_policy.py +60 -0
  69. pyxcp/examples/xcp_read_benchmark.py +38 -0
  70. pyxcp/examples/xcp_skel.py +49 -0
  71. pyxcp/examples/xcp_unlock.py +38 -0
  72. pyxcp/examples/xcp_user_supplied_driver.py +54 -0
  73. pyxcp/examples/xcphello.py +79 -0
  74. pyxcp/examples/xcphello_recorder.py +107 -0
  75. pyxcp/master/__init__.py +9 -0
  76. pyxcp/master/errorhandler.py +436 -0
  77. pyxcp/master/master.py +2030 -0
  78. pyxcp/py.typed +0 -0
  79. pyxcp/recorder/__init__.py +102 -0
  80. pyxcp/recorder/build_clang.cmd +1 -0
  81. pyxcp/recorder/build_clang.sh +2 -0
  82. pyxcp/recorder/build_gcc.cmd +1 -0
  83. pyxcp/recorder/build_gcc.sh +2 -0
  84. pyxcp/recorder/build_gcc_arm.sh +2 -0
  85. pyxcp/recorder/converter/__init__.py +37 -0
  86. pyxcp/recorder/lz4.c +2829 -0
  87. pyxcp/recorder/lz4.h +879 -0
  88. pyxcp/recorder/lz4hc.c +2041 -0
  89. pyxcp/recorder/lz4hc.h +413 -0
  90. pyxcp/recorder/mio.hpp +1714 -0
  91. pyxcp/recorder/reader.hpp +139 -0
  92. pyxcp/recorder/reco.py +277 -0
  93. pyxcp/recorder/recorder.rst +0 -0
  94. pyxcp/recorder/rekorder.cpp +59 -0
  95. pyxcp/recorder/rekorder.cpython-310-x86_64-linux-gnu.so +0 -0
  96. pyxcp/recorder/rekorder.cpython-311-x86_64-linux-gnu.so +0 -0
  97. pyxcp/recorder/rekorder.cpython-312-x86_64-linux-gnu.so +0 -0
  98. pyxcp/recorder/rekorder.cpython-313-x86_64-linux-gnu.so +0 -0
  99. pyxcp/recorder/rekorder.cpython-39-x86_64-linux-gnu.so +0 -0
  100. pyxcp/recorder/rekorder.hpp +274 -0
  101. pyxcp/recorder/setup.py +41 -0
  102. pyxcp/recorder/test_reko.py +34 -0
  103. pyxcp/recorder/unfolder.hpp +1332 -0
  104. pyxcp/recorder/wrap.cpp +189 -0
  105. pyxcp/recorder/writer.hpp +302 -0
  106. pyxcp/scripts/__init__.py +0 -0
  107. pyxcp/scripts/pyxcp_probe_can_drivers.py +20 -0
  108. pyxcp/scripts/xcp_examples.py +64 -0
  109. pyxcp/scripts/xcp_fetch_a2l.py +40 -0
  110. pyxcp/scripts/xcp_id_scanner.py +19 -0
  111. pyxcp/scripts/xcp_info.py +112 -0
  112. pyxcp/scripts/xcp_profile.py +27 -0
  113. pyxcp/stim/__init__.py +0 -0
  114. pyxcp/tests/test_asam_types.py +24 -0
  115. pyxcp/tests/test_binpacking.py +186 -0
  116. pyxcp/tests/test_can.py +1324 -0
  117. pyxcp/tests/test_checksum.py +95 -0
  118. pyxcp/tests/test_daq.py +193 -0
  119. pyxcp/tests/test_frame_padding.py +156 -0
  120. pyxcp/tests/test_master.py +2006 -0
  121. pyxcp/tests/test_transport.py +64 -0
  122. pyxcp/tests/test_utils.py +30 -0
  123. pyxcp/timing.py +60 -0
  124. pyxcp/transport/__init__.py +10 -0
  125. pyxcp/transport/base.py +440 -0
  126. pyxcp/transport/base_transport.hpp +0 -0
  127. pyxcp/transport/can.py +443 -0
  128. pyxcp/transport/eth.py +219 -0
  129. pyxcp/transport/sxi.py +133 -0
  130. pyxcp/transport/transport_wrapper.cpp +0 -0
  131. pyxcp/transport/usb_transport.py +213 -0
  132. pyxcp/types.py +993 -0
  133. pyxcp/utils.py +102 -0
  134. pyxcp/vector/__init__.py +0 -0
  135. pyxcp/vector/map.py +82 -0
  136. pyxcp-0.22.23.dist-info/LICENSE +165 -0
  137. pyxcp-0.22.23.dist-info/METADATA +107 -0
  138. pyxcp-0.22.23.dist-info/RECORD +140 -0
  139. pyxcp-0.22.23.dist-info/WHEEL +6 -0
  140. pyxcp-0.22.23.dist-info/entry_points.txt +8 -0
pyxcp/checksum.py ADDED
@@ -0,0 +1,722 @@
1
+ #!/usr/bin/env python
2
+ """Checksum calculation for memory ranges
3
+
4
+ .. [1] XCP Specification, BUILD_CHECKSUM service.
5
+ """
6
+ import enum
7
+ import struct
8
+ import zlib
9
+
10
+
11
+ class Algorithm(enum.IntEnum):
12
+ """Enumerates available checksum algorithms"""
13
+
14
+ XCP_ADD_11 = 1
15
+ XCP_ADD_12 = 2
16
+ XCP_ADD_14 = 3
17
+ XCP_ADD_22 = 4
18
+ XCP_ADD_24 = 5
19
+ XCP_ADD_44 = 6
20
+ XCP_CRC_16 = 7
21
+ XCP_CRC_16_CITT = 8
22
+ XCP_CRC_32 = 9
23
+ XCP_USER_DEFINED = 10
24
+
25
+
26
+ CRC16 = (
27
+ 0x0000,
28
+ 0x8005,
29
+ 0x800F,
30
+ 0x000A,
31
+ 0x801B,
32
+ 0x001E,
33
+ 0x0014,
34
+ 0x8011,
35
+ 0x8033,
36
+ 0x0036,
37
+ 0x003C,
38
+ 0x8039,
39
+ 0x0028,
40
+ 0x802D,
41
+ 0x8027,
42
+ 0x0022,
43
+ 0x8063,
44
+ 0x0066,
45
+ 0x006C,
46
+ 0x8069,
47
+ 0x0078,
48
+ 0x807D,
49
+ 0x8077,
50
+ 0x0072,
51
+ 0x0050,
52
+ 0x8055,
53
+ 0x805F,
54
+ 0x005A,
55
+ 0x804B,
56
+ 0x004E,
57
+ 0x0044,
58
+ 0x8041,
59
+ 0x80C3,
60
+ 0x00C6,
61
+ 0x00CC,
62
+ 0x80C9,
63
+ 0x00D8,
64
+ 0x80DD,
65
+ 0x80D7,
66
+ 0x00D2,
67
+ 0x00F0,
68
+ 0x80F5,
69
+ 0x80FF,
70
+ 0x00FA,
71
+ 0x80EB,
72
+ 0x00EE,
73
+ 0x00E4,
74
+ 0x80E1,
75
+ 0x00A0,
76
+ 0x80A5,
77
+ 0x80AF,
78
+ 0x00AA,
79
+ 0x80BB,
80
+ 0x00BE,
81
+ 0x00B4,
82
+ 0x80B1,
83
+ 0x8093,
84
+ 0x0096,
85
+ 0x009C,
86
+ 0x8099,
87
+ 0x0088,
88
+ 0x808D,
89
+ 0x8087,
90
+ 0x0082,
91
+ 0x8183,
92
+ 0x0186,
93
+ 0x018C,
94
+ 0x8189,
95
+ 0x0198,
96
+ 0x819D,
97
+ 0x8197,
98
+ 0x0192,
99
+ 0x01B0,
100
+ 0x81B5,
101
+ 0x81BF,
102
+ 0x01BA,
103
+ 0x81AB,
104
+ 0x01AE,
105
+ 0x01A4,
106
+ 0x81A1,
107
+ 0x01E0,
108
+ 0x81E5,
109
+ 0x81EF,
110
+ 0x01EA,
111
+ 0x81FB,
112
+ 0x01FE,
113
+ 0x01F4,
114
+ 0x81F1,
115
+ 0x81D3,
116
+ 0x01D6,
117
+ 0x01DC,
118
+ 0x81D9,
119
+ 0x01C8,
120
+ 0x81CD,
121
+ 0x81C7,
122
+ 0x01C2,
123
+ 0x0140,
124
+ 0x8145,
125
+ 0x814F,
126
+ 0x014A,
127
+ 0x815B,
128
+ 0x015E,
129
+ 0x0154,
130
+ 0x8151,
131
+ 0x8173,
132
+ 0x0176,
133
+ 0x017C,
134
+ 0x8179,
135
+ 0x0168,
136
+ 0x816D,
137
+ 0x8167,
138
+ 0x0162,
139
+ 0x8123,
140
+ 0x0126,
141
+ 0x012C,
142
+ 0x8129,
143
+ 0x0138,
144
+ 0x813D,
145
+ 0x8137,
146
+ 0x0132,
147
+ 0x0110,
148
+ 0x8115,
149
+ 0x811F,
150
+ 0x011A,
151
+ 0x810B,
152
+ 0x010E,
153
+ 0x0104,
154
+ 0x8101,
155
+ 0x8303,
156
+ 0x0306,
157
+ 0x030C,
158
+ 0x8309,
159
+ 0x0318,
160
+ 0x831D,
161
+ 0x8317,
162
+ 0x0312,
163
+ 0x0330,
164
+ 0x8335,
165
+ 0x833F,
166
+ 0x033A,
167
+ 0x832B,
168
+ 0x032E,
169
+ 0x0324,
170
+ 0x8321,
171
+ 0x0360,
172
+ 0x8365,
173
+ 0x836F,
174
+ 0x036A,
175
+ 0x837B,
176
+ 0x037E,
177
+ 0x0374,
178
+ 0x8371,
179
+ 0x8353,
180
+ 0x0356,
181
+ 0x035C,
182
+ 0x8359,
183
+ 0x0348,
184
+ 0x834D,
185
+ 0x8347,
186
+ 0x0342,
187
+ 0x03C0,
188
+ 0x83C5,
189
+ 0x83CF,
190
+ 0x03CA,
191
+ 0x83DB,
192
+ 0x03DE,
193
+ 0x03D4,
194
+ 0x83D1,
195
+ 0x83F3,
196
+ 0x03F6,
197
+ 0x03FC,
198
+ 0x83F9,
199
+ 0x03E8,
200
+ 0x83ED,
201
+ 0x83E7,
202
+ 0x03E2,
203
+ 0x83A3,
204
+ 0x03A6,
205
+ 0x03AC,
206
+ 0x83A9,
207
+ 0x03B8,
208
+ 0x83BD,
209
+ 0x83B7,
210
+ 0x03B2,
211
+ 0x0390,
212
+ 0x8395,
213
+ 0x839F,
214
+ 0x039A,
215
+ 0x838B,
216
+ 0x038E,
217
+ 0x0384,
218
+ 0x8381,
219
+ 0x0280,
220
+ 0x8285,
221
+ 0x828F,
222
+ 0x028A,
223
+ 0x829B,
224
+ 0x029E,
225
+ 0x0294,
226
+ 0x8291,
227
+ 0x82B3,
228
+ 0x02B6,
229
+ 0x02BC,
230
+ 0x82B9,
231
+ 0x02A8,
232
+ 0x82AD,
233
+ 0x82A7,
234
+ 0x02A2,
235
+ 0x82E3,
236
+ 0x02E6,
237
+ 0x02EC,
238
+ 0x82E9,
239
+ 0x02F8,
240
+ 0x82FD,
241
+ 0x82F7,
242
+ 0x02F2,
243
+ 0x02D0,
244
+ 0x82D5,
245
+ 0x82DF,
246
+ 0x02DA,
247
+ 0x82CB,
248
+ 0x02CE,
249
+ 0x02C4,
250
+ 0x82C1,
251
+ 0x8243,
252
+ 0x0246,
253
+ 0x024C,
254
+ 0x8249,
255
+ 0x0258,
256
+ 0x825D,
257
+ 0x8257,
258
+ 0x0252,
259
+ 0x0270,
260
+ 0x8275,
261
+ 0x827F,
262
+ 0x027A,
263
+ 0x826B,
264
+ 0x026E,
265
+ 0x0264,
266
+ 0x8261,
267
+ 0x0220,
268
+ 0x8225,
269
+ 0x822F,
270
+ 0x022A,
271
+ 0x823B,
272
+ 0x023E,
273
+ 0x0234,
274
+ 0x8231,
275
+ 0x8213,
276
+ 0x0216,
277
+ 0x021C,
278
+ 0x8219,
279
+ 0x0208,
280
+ 0x820D,
281
+ 0x8207,
282
+ 0x0202,
283
+ )
284
+
285
+ CRC16_CCITT = (
286
+ 0x0000,
287
+ 0x1021,
288
+ 0x2042,
289
+ 0x3063,
290
+ 0x4084,
291
+ 0x50A5,
292
+ 0x60C6,
293
+ 0x70E7,
294
+ 0x8108,
295
+ 0x9129,
296
+ 0xA14A,
297
+ 0xB16B,
298
+ 0xC18C,
299
+ 0xD1AD,
300
+ 0xE1CE,
301
+ 0xF1EF,
302
+ 0x1231,
303
+ 0x0210,
304
+ 0x3273,
305
+ 0x2252,
306
+ 0x52B5,
307
+ 0x4294,
308
+ 0x72F7,
309
+ 0x62D6,
310
+ 0x9339,
311
+ 0x8318,
312
+ 0xB37B,
313
+ 0xA35A,
314
+ 0xD3BD,
315
+ 0xC39C,
316
+ 0xF3FF,
317
+ 0xE3DE,
318
+ 0x2462,
319
+ 0x3443,
320
+ 0x0420,
321
+ 0x1401,
322
+ 0x64E6,
323
+ 0x74C7,
324
+ 0x44A4,
325
+ 0x5485,
326
+ 0xA56A,
327
+ 0xB54B,
328
+ 0x8528,
329
+ 0x9509,
330
+ 0xE5EE,
331
+ 0xF5CF,
332
+ 0xC5AC,
333
+ 0xD58D,
334
+ 0x3653,
335
+ 0x2672,
336
+ 0x1611,
337
+ 0x0630,
338
+ 0x76D7,
339
+ 0x66F6,
340
+ 0x5695,
341
+ 0x46B4,
342
+ 0xB75B,
343
+ 0xA77A,
344
+ 0x9719,
345
+ 0x8738,
346
+ 0xF7DF,
347
+ 0xE7FE,
348
+ 0xD79D,
349
+ 0xC7BC,
350
+ 0x48C4,
351
+ 0x58E5,
352
+ 0x6886,
353
+ 0x78A7,
354
+ 0x0840,
355
+ 0x1861,
356
+ 0x2802,
357
+ 0x3823,
358
+ 0xC9CC,
359
+ 0xD9ED,
360
+ 0xE98E,
361
+ 0xF9AF,
362
+ 0x8948,
363
+ 0x9969,
364
+ 0xA90A,
365
+ 0xB92B,
366
+ 0x5AF5,
367
+ 0x4AD4,
368
+ 0x7AB7,
369
+ 0x6A96,
370
+ 0x1A71,
371
+ 0x0A50,
372
+ 0x3A33,
373
+ 0x2A12,
374
+ 0xDBFD,
375
+ 0xCBDC,
376
+ 0xFBBF,
377
+ 0xEB9E,
378
+ 0x9B79,
379
+ 0x8B58,
380
+ 0xBB3B,
381
+ 0xAB1A,
382
+ 0x6CA6,
383
+ 0x7C87,
384
+ 0x4CE4,
385
+ 0x5CC5,
386
+ 0x2C22,
387
+ 0x3C03,
388
+ 0x0C60,
389
+ 0x1C41,
390
+ 0xEDAE,
391
+ 0xFD8F,
392
+ 0xCDEC,
393
+ 0xDDCD,
394
+ 0xAD2A,
395
+ 0xBD0B,
396
+ 0x8D68,
397
+ 0x9D49,
398
+ 0x7E97,
399
+ 0x6EB6,
400
+ 0x5ED5,
401
+ 0x4EF4,
402
+ 0x3E13,
403
+ 0x2E32,
404
+ 0x1E51,
405
+ 0x0E70,
406
+ 0xFF9F,
407
+ 0xEFBE,
408
+ 0xDFDD,
409
+ 0xCFFC,
410
+ 0xBF1B,
411
+ 0xAF3A,
412
+ 0x9F59,
413
+ 0x8F78,
414
+ 0x9188,
415
+ 0x81A9,
416
+ 0xB1CA,
417
+ 0xA1EB,
418
+ 0xD10C,
419
+ 0xC12D,
420
+ 0xF14E,
421
+ 0xE16F,
422
+ 0x1080,
423
+ 0x00A1,
424
+ 0x30C2,
425
+ 0x20E3,
426
+ 0x5004,
427
+ 0x4025,
428
+ 0x7046,
429
+ 0x6067,
430
+ 0x83B9,
431
+ 0x9398,
432
+ 0xA3FB,
433
+ 0xB3DA,
434
+ 0xC33D,
435
+ 0xD31C,
436
+ 0xE37F,
437
+ 0xF35E,
438
+ 0x02B1,
439
+ 0x1290,
440
+ 0x22F3,
441
+ 0x32D2,
442
+ 0x4235,
443
+ 0x5214,
444
+ 0x6277,
445
+ 0x7256,
446
+ 0xB5EA,
447
+ 0xA5CB,
448
+ 0x95A8,
449
+ 0x8589,
450
+ 0xF56E,
451
+ 0xE54F,
452
+ 0xD52C,
453
+ 0xC50D,
454
+ 0x34E2,
455
+ 0x24C3,
456
+ 0x14A0,
457
+ 0x0481,
458
+ 0x7466,
459
+ 0x6447,
460
+ 0x5424,
461
+ 0x4405,
462
+ 0xA7DB,
463
+ 0xB7FA,
464
+ 0x8799,
465
+ 0x97B8,
466
+ 0xE75F,
467
+ 0xF77E,
468
+ 0xC71D,
469
+ 0xD73C,
470
+ 0x26D3,
471
+ 0x36F2,
472
+ 0x0691,
473
+ 0x16B0,
474
+ 0x6657,
475
+ 0x7676,
476
+ 0x4615,
477
+ 0x5634,
478
+ 0xD94C,
479
+ 0xC96D,
480
+ 0xF90E,
481
+ 0xE92F,
482
+ 0x99C8,
483
+ 0x89E9,
484
+ 0xB98A,
485
+ 0xA9AB,
486
+ 0x5844,
487
+ 0x4865,
488
+ 0x7806,
489
+ 0x6827,
490
+ 0x18C0,
491
+ 0x08E1,
492
+ 0x3882,
493
+ 0x28A3,
494
+ 0xCB7D,
495
+ 0xDB5C,
496
+ 0xEB3F,
497
+ 0xFB1E,
498
+ 0x8BF9,
499
+ 0x9BD8,
500
+ 0xABBB,
501
+ 0xBB9A,
502
+ 0x4A75,
503
+ 0x5A54,
504
+ 0x6A37,
505
+ 0x7A16,
506
+ 0x0AF1,
507
+ 0x1AD0,
508
+ 0x2AB3,
509
+ 0x3A92,
510
+ 0xFD2E,
511
+ 0xED0F,
512
+ 0xDD6C,
513
+ 0xCD4D,
514
+ 0xBDAA,
515
+ 0xAD8B,
516
+ 0x9DE8,
517
+ 0x8DC9,
518
+ 0x7C26,
519
+ 0x6C07,
520
+ 0x5C64,
521
+ 0x4C45,
522
+ 0x3CA2,
523
+ 0x2C83,
524
+ 0x1CE0,
525
+ 0x0CC1,
526
+ 0xEF1F,
527
+ 0xFF3E,
528
+ 0xCF5D,
529
+ 0xDF7C,
530
+ 0xAF9B,
531
+ 0xBFBA,
532
+ 0x8FD9,
533
+ 0x9FF8,
534
+ 0x6E17,
535
+ 0x7E36,
536
+ 0x4E55,
537
+ 0x5E74,
538
+ 0x2E93,
539
+ 0x3EB2,
540
+ 0x0ED1,
541
+ 0x1EF0,
542
+ )
543
+
544
+
545
+ def reflect(data, nBits):
546
+ """Reflect data, i.e. reverse bit order.
547
+
548
+ Parameters
549
+ ----------
550
+ data : int
551
+ nBits : int
552
+ width in bits of `data`
553
+ """
554
+ reflection = 0x00000000
555
+ for bit in range(nBits):
556
+ if data & 0x01:
557
+ reflection |= 1 << ((nBits - 1) - bit)
558
+ data = data >> 1
559
+ return reflection
560
+
561
+
562
+ class Crc16:
563
+ """Calculate CRC (16-bit)
564
+
565
+
566
+ Parameters
567
+ ----------
568
+ table: list-like
569
+ lookup table for CRC calculation
570
+ initalRemainder : int
571
+ value to start with
572
+ finalXorValue : int
573
+ final XOR value
574
+ reflectData : bool
575
+ reflect input data
576
+ reflectRemainder : bool
577
+ reflect output data
578
+
579
+ .. [1] A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS
580
+ http://www.ross.net/crc/download/crc_v3.txt
581
+ .. [2] Understanding and implementing CRC (Cyclic Redundancy Check)
582
+ calculation
583
+ http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html
584
+ .. [3] Online CRC calculator
585
+ http://zorc.breitbandkatze.de/crc.html
586
+ """
587
+
588
+ WIDTH = 16
589
+
590
+ def __init__(self, table, initalRemainder, finalXorValue, reflectData, reflectRemainder):
591
+ self.table = table
592
+ self.initalRemainder = initalRemainder
593
+ self.finalXorValue = finalXorValue
594
+ self.reflectData = reflectData
595
+ self.reflectRemainder = reflectRemainder
596
+
597
+ def __call__(self, frame):
598
+ remainder = self.initalRemainder
599
+ for ch in frame:
600
+ data = self.reflectIn(ch, remainder)
601
+ remainder = (self.table[data] ^ (remainder << 8)) & 0xFFFF
602
+ return self.reflectOut(remainder)
603
+
604
+ def reflectIn(self, ch, remainder):
605
+ if self.reflectData:
606
+ return (reflect(ch, 8) ^ (remainder >> (self.WIDTH - 8))) & 0xFF
607
+ else:
608
+ return (ch ^ (remainder >> (self.WIDTH - 8))) & 0xFF
609
+
610
+ def reflectOut(self, remainder):
611
+ if self.reflectRemainder:
612
+ return reflect(remainder, 16) ^ self.finalXorValue
613
+ else:
614
+ return remainder ^ self.finalXorValue
615
+
616
+
617
+ def adder(modulus):
618
+ """Factory function for modulus adders
619
+
620
+ Parameters
621
+ ----------
622
+ modulus : int
623
+ modulus to use
624
+
625
+ Returns
626
+ -------
627
+ function
628
+ adder function
629
+
630
+ Examples
631
+ --------
632
+ >>> a256=adder(256)
633
+ >>> a256([11, 22, 33, 44, 55, 66, 77, 88, 99])
634
+ 239
635
+
636
+ """
637
+
638
+ def add(frame):
639
+ return sum(frame) % modulus
640
+
641
+ return add
642
+
643
+
644
+ def wordSum(modulus, step):
645
+ """Factory function for (double-)word modulus sums
646
+
647
+ Parameters
648
+ ----------
649
+ modulus : int
650
+ step : [2, 4]
651
+ 2 - word wise
652
+ 4 - double-word wise
653
+
654
+ Returns
655
+ -------
656
+ function
657
+ summation function
658
+ """
659
+
660
+ def add(frame):
661
+ if step == 2:
662
+ mask = "<H"
663
+ elif step == 4:
664
+ mask = "<I"
665
+ else:
666
+ raise NotImplementedError("Only WORDs or DWORDs are supported.")
667
+ x = [struct.unpack(mask, frame[x : x + step])[0] for x in range(0, len(frame), step)]
668
+ return sum(x) % modulus
669
+
670
+ return add
671
+
672
+
673
+ ADD11 = adder(2**8)
674
+ ADD12 = adder(2**16)
675
+ ADD14 = adder(2**32)
676
+ ADD22 = wordSum(2**16, 2)
677
+ ADD24 = wordSum(2**32, 2)
678
+ ADD44 = wordSum(2**32, 4)
679
+ CRC16 = Crc16(CRC16, 0x0000, 0x0000, True, True)
680
+ CRC16_CCITT = Crc16(CRC16_CCITT, 0xFFFF, 0x0000, False, False)
681
+
682
+
683
+ def CRC32(x):
684
+ return zlib.crc32(x) & 0xFFFFFFFF
685
+
686
+
687
+ def userDefined(x):
688
+ """User defined algorithms are not supported yet."""
689
+ raise NotImplementedError("Checksum method 'XCP_USER_DEFINED' not supported yet.")
690
+
691
+
692
+ ALGO = {
693
+ "XCP_ADD_11": ADD11,
694
+ "XCP_ADD_12": ADD12,
695
+ "XCP_ADD_14": ADD14,
696
+ "XCP_ADD_22": ADD22,
697
+ "XCP_ADD_24": ADD24,
698
+ "XCP_ADD_44": ADD44,
699
+ "XCP_CRC_16": CRC16,
700
+ "XCP_CRC_16_CITT": CRC16_CCITT,
701
+ "XCP_CRC_32": CRC32,
702
+ "XCP_USER_DEFINED": userDefined,
703
+ }
704
+
705
+
706
+ def check(frame, algo):
707
+ """Calculate checksum using given algorithm
708
+
709
+ Parameters
710
+ ----------
711
+ frame : list of integers
712
+ algo : `ALGO`
713
+
714
+ Returns
715
+ -------
716
+ int
717
+ """
718
+ fun = ALGO.get(algo)
719
+ if fun:
720
+ return fun(frame)
721
+ else:
722
+ raise NotImplementedError(f"Invalid algorithm '{algo:d}'")