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