pyxcp 0.23.0__cp312-cp312-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.

Potentially problematic release.


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

Files changed (131) 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 +732 -0
  20. pyxcp/cmdline.py +52 -0
  21. pyxcp/config/__init__.py +1113 -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.cp310-win_arm64.pyd +0 -0
  28. pyxcp/cpp_ext/cpp_ext.cp311-win_arm64.pyd +0 -0
  29. pyxcp/cpp_ext/cpp_ext.cp312-win_arm64.pyd +0 -0
  30. pyxcp/cpp_ext/daqlist.hpp +206 -0
  31. pyxcp/cpp_ext/event.hpp +67 -0
  32. pyxcp/cpp_ext/extension_wrapper.cpp +100 -0
  33. pyxcp/cpp_ext/helper.hpp +280 -0
  34. pyxcp/cpp_ext/mcobject.hpp +246 -0
  35. pyxcp/cpp_ext/tsqueue.hpp +46 -0
  36. pyxcp/daq_stim/__init__.py +232 -0
  37. pyxcp/daq_stim/optimize/__init__.py +67 -0
  38. pyxcp/daq_stim/optimize/binpacking.py +41 -0
  39. pyxcp/daq_stim/scheduler.cpp +62 -0
  40. pyxcp/daq_stim/scheduler.hpp +75 -0
  41. pyxcp/daq_stim/stim.cp310-win_arm64.pyd +0 -0
  42. pyxcp/daq_stim/stim.cp311-win_arm64.pyd +0 -0
  43. pyxcp/daq_stim/stim.cp312-win_arm64.pyd +0 -0
  44. pyxcp/daq_stim/stim.cpp +13 -0
  45. pyxcp/daq_stim/stim.hpp +604 -0
  46. pyxcp/daq_stim/stim_wrapper.cpp +50 -0
  47. pyxcp/dllif.py +100 -0
  48. pyxcp/errormatrix.py +878 -0
  49. pyxcp/examples/conf_can.toml +19 -0
  50. pyxcp/examples/conf_can_user.toml +16 -0
  51. pyxcp/examples/conf_can_vector.json +11 -0
  52. pyxcp/examples/conf_can_vector.toml +11 -0
  53. pyxcp/examples/conf_eth.toml +9 -0
  54. pyxcp/examples/conf_nixnet.json +20 -0
  55. pyxcp/examples/conf_socket_can.toml +12 -0
  56. pyxcp/examples/conf_sxi.json +9 -0
  57. pyxcp/examples/conf_sxi.toml +7 -0
  58. pyxcp/examples/run_daq.py +163 -0
  59. pyxcp/examples/xcp_policy.py +60 -0
  60. pyxcp/examples/xcp_read_benchmark.py +38 -0
  61. pyxcp/examples/xcp_skel.py +49 -0
  62. pyxcp/examples/xcp_unlock.py +38 -0
  63. pyxcp/examples/xcp_user_supplied_driver.py +44 -0
  64. pyxcp/examples/xcphello.py +78 -0
  65. pyxcp/examples/xcphello_recorder.py +107 -0
  66. pyxcp/master/__init__.py +9 -0
  67. pyxcp/master/errorhandler.py +442 -0
  68. pyxcp/master/master.py +2047 -0
  69. pyxcp/py.typed +0 -0
  70. pyxcp/recorder/__init__.py +101 -0
  71. pyxcp/recorder/build_clang.cmd +1 -0
  72. pyxcp/recorder/build_clang.sh +2 -0
  73. pyxcp/recorder/build_gcc.cmd +1 -0
  74. pyxcp/recorder/build_gcc.sh +2 -0
  75. pyxcp/recorder/build_gcc_arm.sh +2 -0
  76. pyxcp/recorder/converter/__init__.py +450 -0
  77. pyxcp/recorder/lz4.c +2829 -0
  78. pyxcp/recorder/lz4.h +879 -0
  79. pyxcp/recorder/lz4hc.c +2041 -0
  80. pyxcp/recorder/lz4hc.h +413 -0
  81. pyxcp/recorder/mio.hpp +1714 -0
  82. pyxcp/recorder/reader.hpp +139 -0
  83. pyxcp/recorder/reco.py +277 -0
  84. pyxcp/recorder/recorder.rst +0 -0
  85. pyxcp/recorder/rekorder.cp310-win_arm64.pyd +0 -0
  86. pyxcp/recorder/rekorder.cp311-win_arm64.pyd +0 -0
  87. pyxcp/recorder/rekorder.cp312-win_arm64.pyd +0 -0
  88. pyxcp/recorder/rekorder.cpp +59 -0
  89. pyxcp/recorder/rekorder.hpp +274 -0
  90. pyxcp/recorder/setup.py +41 -0
  91. pyxcp/recorder/test_reko.py +34 -0
  92. pyxcp/recorder/unfolder.hpp +1332 -0
  93. pyxcp/recorder/wrap.cpp +189 -0
  94. pyxcp/recorder/writer.hpp +302 -0
  95. pyxcp/scripts/__init__.py +0 -0
  96. pyxcp/scripts/pyxcp_probe_can_drivers.py +20 -0
  97. pyxcp/scripts/xcp_examples.py +64 -0
  98. pyxcp/scripts/xcp_fetch_a2l.py +40 -0
  99. pyxcp/scripts/xcp_id_scanner.py +19 -0
  100. pyxcp/scripts/xcp_info.py +144 -0
  101. pyxcp/scripts/xcp_profile.py +27 -0
  102. pyxcp/scripts/xmraw_converter.py +31 -0
  103. pyxcp/stim/__init__.py +0 -0
  104. pyxcp/tests/test_asam_types.py +24 -0
  105. pyxcp/tests/test_binpacking.py +186 -0
  106. pyxcp/tests/test_can.py +1324 -0
  107. pyxcp/tests/test_checksum.py +95 -0
  108. pyxcp/tests/test_daq.py +193 -0
  109. pyxcp/tests/test_daq_opt.py +426 -0
  110. pyxcp/tests/test_frame_padding.py +156 -0
  111. pyxcp/tests/test_master.py +2006 -0
  112. pyxcp/tests/test_transport.py +81 -0
  113. pyxcp/tests/test_utils.py +30 -0
  114. pyxcp/timing.py +60 -0
  115. pyxcp/transport/__init__.py +10 -0
  116. pyxcp/transport/base.py +440 -0
  117. pyxcp/transport/base_transport.hpp +0 -0
  118. pyxcp/transport/can.py +556 -0
  119. pyxcp/transport/eth.py +219 -0
  120. pyxcp/transport/sxi.py +135 -0
  121. pyxcp/transport/transport_wrapper.cpp +0 -0
  122. pyxcp/transport/usb_transport.py +213 -0
  123. pyxcp/types.py +1000 -0
  124. pyxcp/utils.py +128 -0
  125. pyxcp/vector/__init__.py +0 -0
  126. pyxcp/vector/map.py +82 -0
  127. pyxcp-0.23.0.dist-info/LICENSE +165 -0
  128. pyxcp-0.23.0.dist-info/METADATA +107 -0
  129. pyxcp-0.23.0.dist-info/RECORD +131 -0
  130. pyxcp-0.23.0.dist-info/WHEEL +4 -0
  131. pyxcp-0.23.0.dist-info/entry_points.txt +9 -0
@@ -0,0 +1,2006 @@
1
+ #!/usr/bin/env python
2
+ import struct
3
+ import time
4
+ from collections import deque
5
+ from unittest import mock
6
+
7
+ from pyxcp import types
8
+ from pyxcp.master import Master
9
+
10
+
11
+ def create_config():
12
+ # Exception: XCPonEth - Failed to resolve address <MagicMock name='mock.transport.eth.host' id='2414047113872'>:<MagicMock name='mock.transport.eth.port' id='2414047478992'>
13
+ config = mock.MagicMock()
14
+ config.general.return_value = mock.MagicMock()
15
+ config.transport.return_value = mock.MagicMock()
16
+ config.transport.eth.return_value = mock.MagicMock()
17
+ config.transport.eth.host = "localhost"
18
+ config.transport.eth.port = 5555
19
+ config.transport.eth.bind_to_address = ""
20
+ config.transport.eth.bind_to_port = 0
21
+ return config
22
+
23
+
24
+ class MockSocket:
25
+ def __init__(self):
26
+ self.data = bytearray()
27
+ self.ctr = 0
28
+
29
+ # push frame consisting of header (len + ctr) and packet
30
+ def push_frame(self, frame):
31
+ try:
32
+ self.data.extend(frame)
33
+ except TypeError:
34
+ self.data.extend(bytes.fromhex(frame))
35
+ self.ctr += 1
36
+
37
+ # push packet, automatically add header (len + ctr)
38
+ def push_packet(self, data):
39
+ try:
40
+ data = bytes.fromhex(data)
41
+ except TypeError:
42
+ pass
43
+
44
+ header = struct.pack("<HH", len(data), self.ctr)
45
+ self.push_frame(header + data)
46
+
47
+ def recv(self, bufsize):
48
+ r = self.data[:bufsize]
49
+ self.data = self.data[bufsize:]
50
+ return r
51
+
52
+ def select(self, timeout):
53
+ if self.data:
54
+ return [(0, 1)]
55
+ else:
56
+ time.sleep(timeout)
57
+ return []
58
+
59
+ def connect(self):
60
+ pass
61
+
62
+
63
+ class MockCanInterface: # CanInterfaceBase
64
+ def __init__(self):
65
+ self.data = deque()
66
+ self.receive_callback = None
67
+ self.is_fd = False
68
+
69
+ def init(self, parent, receive_callback):
70
+ self.receive_callback = receive_callback
71
+
72
+ # push packet
73
+ def push_packet(self, data):
74
+ try:
75
+ data = bytes.fromhex(data)
76
+ except TypeError:
77
+ pass
78
+ # no header on CAN
79
+ self.push_frame(data)
80
+
81
+ def push_frame(self, packet):
82
+ self.data.append(packet)
83
+
84
+ def transmit(self, payload: bytes):
85
+ time.sleep(0.001)
86
+ try:
87
+ resp = self.data.popleft()
88
+ if resp:
89
+ self.receive_callback(resp)
90
+ except IndexError:
91
+ pass
92
+
93
+ def close(self):
94
+ pass
95
+
96
+ def connect(self):
97
+ pass
98
+
99
+ def read(self):
100
+ pass
101
+
102
+ def get_timestamp_resolution(self):
103
+ pass
104
+
105
+
106
+ class TestMaster:
107
+ DefaultConnectCmd = bytes([0x02, 0x00, 0x00, 0x00, 0xFF, 0x00])
108
+ DefaultConnectResponse = "FF 3D C0 FF DC 05 01 01"
109
+
110
+ @mock.patch("pyxcp.transport.eth")
111
+ def testConnect(self, eth):
112
+ with Master("eth", config=create_config()) as xm:
113
+ xm.transport = eth()
114
+ xm.transport.request.return_value = bytes([0x1D, 0xC0, 0xFF, 0xDC, 0x05, 0x01, 0x01])
115
+
116
+ res = xm.connect()
117
+
118
+ assert res.maxCto == 255
119
+ assert res.maxDto == 1500
120
+ assert res.protocolLayerVersion == 1
121
+ assert res.transportLayerVersion == 1
122
+ assert res.resource.pgm is True
123
+ assert res.resource.stim is True
124
+ assert res.resource.daq is True
125
+ assert res.resource.calpag is True
126
+ assert res.commModeBasic.optional is True
127
+ assert res.commModeBasic.slaveBlockMode is True
128
+ assert res.commModeBasic.addressGranularity == types.AddressGranularity.BYTE
129
+ assert res.commModeBasic.byteOrder == types.ByteOrder.INTEL
130
+ assert xm.slaveProperties.maxCto == res.maxCto
131
+ assert xm.slaveProperties.maxDto == res.maxDto
132
+
133
+ @mock.patch("pyxcp.transport.eth")
134
+ def testDisconnect(self, eth):
135
+ with Master("eth", config=create_config()) as xm:
136
+ xm.transport = eth()
137
+ xm.transport.request_optional_response.return_value = bytes([])
138
+ res = xm.disconnect()
139
+ assert res == b""
140
+
141
+ @mock.patch("pyxcp.transport.eth")
142
+ def testGetStatus(self, eth):
143
+ with Master("eth", config=create_config()) as xm:
144
+ xm.transport = eth()
145
+ xm.transport.request.return_value = bytes([0x1D, 0xC0, 0xFF, 0xDC, 0x05, 0x01, 0x01])
146
+
147
+ res = xm.connect()
148
+
149
+ xm.transport.request.return_value = bytes([0x00, 0x1D, 0xFF, 0x00, 0x00])
150
+
151
+ res = xm.getStatus()
152
+
153
+ assert res.sessionConfiguration == 0
154
+ assert res.sessionStatus.resume is False
155
+ assert res.sessionStatus.daqRunning is False
156
+ assert res.sessionStatus.clearDaqRequest is False
157
+ assert res.sessionStatus.storeDaqRequest is False
158
+ assert res.sessionStatus.storeCalRequest is False
159
+ assert res.resourceProtectionStatus.pgm is True
160
+ assert res.resourceProtectionStatus.stim is True
161
+ assert res.resourceProtectionStatus.daq is True
162
+ assert res.resourceProtectionStatus.calpag is True
163
+
164
+ @mock.patch("pyxcp.transport.eth")
165
+ def testSync(self, eth):
166
+ with Master("eth", config=create_config()) as xm:
167
+ xm.transport = eth()
168
+ xm.transport.request.return_value = bytes([0x00])
169
+ res = xm.synch()
170
+ assert len(res) == 1
171
+
172
+ @mock.patch("pyxcp.transport.eth")
173
+ def testGetCommModeInfo(self, eth):
174
+ with Master("eth", config=create_config()) as xm:
175
+ xm.transport = eth()
176
+ xm.transport.request.return_value = bytes([0x1D, 0xC0, 0xFF, 0xDC, 0x05, 0x01, 0x01])
177
+
178
+ res = xm.connect()
179
+
180
+ xm.transport.request.return_value = bytes([0x00, 0x01, 0xFF, 0x02, 0x00, 0x00, 0x19])
181
+
182
+ res = xm.getCommModeInfo()
183
+
184
+ assert res.commModeOptional.interleavedMode is False
185
+ assert res.commModeOptional.masterBlockMode is True
186
+ assert res.maxBs == 2
187
+ assert res.minSt == 0
188
+ assert res.queueSize == 0
189
+ assert res.xcpDriverVersionNumber == 25
190
+
191
+ @mock.patch("pyxcp.transport.eth")
192
+ def testGetId(self, eth):
193
+ with Master("eth", config=create_config()) as xm:
194
+ xm.transport = eth()
195
+ xm.transport.MAX_DATAGRAM_SIZE = 512
196
+ xm.transport.request.return_value = bytes([0x1D, 0xC0, 0xFF, 0xDC, 0x05, 0x01, 0x01])
197
+
198
+ res = xm.connect()
199
+
200
+ xm.transport.request.return_value = bytes([0x00, 0x01, 0xFF, 0x06, 0x00, 0x00, 0x00])
201
+
202
+ gid = xm.getId(0x01)
203
+ xm.transport.DATAGRAM_SIZE = 512
204
+ xm.transport.request.return_value = bytes([0x58, 0x43, 0x50, 0x73, 0x69, 0x6D])
205
+ res = xm.upload(gid.length)
206
+ assert gid.mode == 0
207
+ assert gid.length == 6
208
+ assert res == b"XCPsim"
209
+
210
+ @mock.patch("pyxcp.transport.eth.socket.socket")
211
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
212
+ def testConnect2(self, mock_selector, mock_socket):
213
+ ms = MockSocket()
214
+
215
+ mock_socket.return_value.recv.side_effect = ms.recv
216
+ mock_selector.return_value.select.side_effect = ms.select
217
+
218
+ with Master("eth", config=create_config()) as xm:
219
+ ms.push_packet(self.DefaultConnectResponse)
220
+
221
+ res = xm.connect()
222
+
223
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
224
+
225
+ assert res.maxCto == 255
226
+ assert res.maxDto == 1500
227
+ assert res.protocolLayerVersion == 1
228
+ assert res.transportLayerVersion == 1
229
+ assert res.resource.dbg is True
230
+ assert res.resource.pgm is True
231
+ assert res.resource.stim is True
232
+ assert res.resource.daq is True
233
+ assert res.resource.calpag is True
234
+ assert res.commModeBasic.optional is True
235
+ assert res.commModeBasic.slaveBlockMode is True
236
+ assert res.commModeBasic.addressGranularity == types.AddressGranularity.BYTE
237
+ assert res.commModeBasic.byteOrder == types.ByteOrder.INTEL
238
+
239
+ assert xm.slaveProperties.byteOrder == res.commModeBasic.byteOrder
240
+ assert xm.slaveProperties.maxCto == res.maxCto
241
+ assert xm.slaveProperties.maxDto == res.maxDto
242
+
243
+ ms.push_frame("06 00 01 00 FF 00 01 05 01 04")
244
+
245
+ res = xm.getVersion()
246
+
247
+ mock_socket.return_value.send.assert_called_with(bytes([0x02, 0x00, 0x01, 0x00, 0xC0, 0x00]))
248
+
249
+ assert res.protocolMajor == 1
250
+ assert res.protocolMinor == 5
251
+ assert res.transportMajor == 1
252
+ assert res.transportMinor == 4
253
+
254
+ @mock.patch("pyxcp.transport.eth.socket.socket")
255
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
256
+ def testDisconnect2(self, mock_selector, mock_socket):
257
+ ms = MockSocket()
258
+
259
+ mock_socket.return_value.recv.side_effect = ms.recv
260
+ mock_selector.return_value.select.side_effect = ms.select
261
+
262
+ with Master("eth", config=create_config()) as xm:
263
+ ms.push_packet(self.DefaultConnectResponse)
264
+
265
+ res = xm.connect()
266
+
267
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
268
+
269
+ ms.push_frame("01 00 01 00 FF")
270
+
271
+ res = xm.disconnect()
272
+
273
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x01, 0x00, 0xFE]))
274
+
275
+ assert res == b""
276
+
277
+ @mock.patch("pyxcp.transport.eth.socket.socket")
278
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
279
+ def testGetStatus2(self, mock_selector, mock_socket):
280
+ ms = MockSocket()
281
+
282
+ mock_socket.return_value.recv.side_effect = ms.recv
283
+ mock_selector.return_value.select.side_effect = ms.select
284
+
285
+ with Master("eth", config=create_config()) as xm:
286
+ ms.push_packet(self.DefaultConnectResponse)
287
+
288
+ res = xm.connect()
289
+
290
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
291
+
292
+ ms.push_packet("FF 09 1D 00 34 12")
293
+
294
+ res = xm.getStatus()
295
+
296
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x01, 0x00, 0xFD]))
297
+
298
+ assert res.sessionStatus.storeCalRequest is True
299
+ assert res.sessionStatus.storeDaqRequest is False
300
+ assert res.sessionStatus.clearDaqRequest is True
301
+ assert res.sessionStatus.daqRunning is False
302
+ assert res.sessionStatus.resume is False
303
+ assert res.resourceProtectionStatus.pgm is True
304
+ assert res.resourceProtectionStatus.stim is True
305
+ assert res.resourceProtectionStatus.daq is True
306
+ assert res.resourceProtectionStatus.calpag is True
307
+ assert res.sessionConfiguration == 0x1234
308
+
309
+ @mock.patch("pyxcp.transport.eth.socket.socket")
310
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
311
+ def testSynch(self, mock_selector, mock_socket):
312
+ ms = MockSocket()
313
+
314
+ mock_socket.return_value.recv.side_effect = ms.recv
315
+ mock_selector.return_value.select.side_effect = ms.select
316
+
317
+ with Master("eth", config=create_config()) as xm:
318
+ ms.push_packet(self.DefaultConnectResponse)
319
+
320
+ res = xm.connect()
321
+
322
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
323
+
324
+ ms.push_frame([0x02, 0x00, 0x01, 0x00, 0xFE, 0x00])
325
+
326
+ res = xm.synch()
327
+
328
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x01, 0x00, 0xFC]))
329
+
330
+ assert res == b"\x00"
331
+
332
+ @mock.patch("pyxcp.transport.eth.socket.socket")
333
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
334
+ def testGetCommModeInfo2(self, mock_selector, mock_socket):
335
+ ms = MockSocket()
336
+
337
+ mock_socket.return_value.recv.side_effect = ms.recv
338
+ mock_selector.return_value.select.side_effect = ms.select
339
+
340
+ with Master("eth", config=create_config()) as xm:
341
+ ms.push_packet(self.DefaultConnectResponse)
342
+
343
+ res = xm.connect()
344
+
345
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
346
+
347
+ ms.push_packet("FF 00 01 FF 02 00 00 19")
348
+
349
+ res = xm.getCommModeInfo()
350
+
351
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x01, 0x00, 0xFB]))
352
+
353
+ assert res.commModeOptional.interleavedMode is False
354
+ assert res.commModeOptional.masterBlockMode is True
355
+ assert res.maxBs == 2
356
+ assert res.minSt == 0
357
+ assert res.queueSize == 0
358
+ assert res.xcpDriverVersionNumber == 25
359
+
360
+ @mock.patch("pyxcp.transport.eth.socket.socket")
361
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
362
+ def testGetId2(self, mock_selector, mock_socket):
363
+ ms = MockSocket()
364
+
365
+ mock_socket.return_value.recv.side_effect = ms.recv
366
+ mock_selector.return_value.select.side_effect = ms.select
367
+
368
+ with Master("eth", config=create_config()) as xm:
369
+ ms.push_packet(self.DefaultConnectResponse)
370
+
371
+ res = xm.connect()
372
+
373
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
374
+
375
+ ms.push_frame([0x08, 0x00, 0x01, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00])
376
+
377
+ gid = xm.getId(0x01)
378
+
379
+ mock_socket.return_value.send.assert_called_with(bytes([0x02, 0x00, 0x01, 0x00, 0xFA, 0x01]))
380
+
381
+ assert gid.mode == 0
382
+ assert gid.length == 6
383
+
384
+ ms.push_frame([0x07, 0x00, 0x02, 0x00, 0xFF, 0x58, 0x43, 0x50, 0x73, 0x69, 0x6D])
385
+
386
+ res = xm.upload(gid.length)
387
+
388
+ mock_socket.return_value.send.assert_called_with(bytes([0x02, 0x00, 0x02, 0x00, 0xF5, 0x06]))
389
+
390
+ assert res == b"XCPsim"
391
+
392
+ ms.push_frame(
393
+ [
394
+ 0x0E,
395
+ 0x00,
396
+ 0x03,
397
+ 0x00,
398
+ 0xFF,
399
+ 0x01,
400
+ 0x00,
401
+ 0x00,
402
+ 0x06,
403
+ 0x00,
404
+ 0x00,
405
+ 0x00,
406
+ 0x58,
407
+ 0x43,
408
+ 0x50,
409
+ 0x73,
410
+ 0x69,
411
+ 0x6D,
412
+ ]
413
+ )
414
+
415
+ gid = xm.getId(0x01)
416
+
417
+ mock_socket.return_value.send.assert_called_with(bytes([0x02, 0x00, 0x03, 0x00, 0xFA, 0x01]))
418
+
419
+ assert gid.mode == 1
420
+ assert gid.length == 6
421
+ assert gid.identification == list(b"XCPsim")
422
+
423
+ @mock.patch("pyxcp.transport.eth.socket.socket")
424
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
425
+ def testSetRequest(self, mock_selector, mock_socket):
426
+ ms = MockSocket()
427
+
428
+ mock_socket.return_value.recv.side_effect = ms.recv
429
+ mock_selector.return_value.select.side_effect = ms.select
430
+
431
+ with Master("eth", config=create_config()) as xm:
432
+ ms.push_packet(self.DefaultConnectResponse)
433
+
434
+ res = xm.connect()
435
+
436
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
437
+
438
+ ms.push_frame([0x01, 0x00, 0x01, 0x00, 0xFF])
439
+
440
+ res = xm.setRequest(0x15, 0x1234)
441
+
442
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x01, 0x00, 0xF9, 0x15, 0x12, 0x34]))
443
+
444
+ assert res == b""
445
+
446
+ @mock.patch("pyxcp.transport.eth.socket.socket")
447
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
448
+ def testGetSeed(self, mock_selector, mock_socket):
449
+ ms = MockSocket()
450
+
451
+ mock_socket.return_value.recv.side_effect = ms.recv
452
+ mock_selector.return_value.select.side_effect = ms.select
453
+
454
+ with Master("eth", config=create_config()) as xm:
455
+ ms.push_packet(self.DefaultConnectResponse)
456
+
457
+ res = xm.connect()
458
+
459
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
460
+
461
+ ms.push_packet("FF 04 12 34 56 78")
462
+
463
+ res = xm.getSeed(0x00, 0x00)
464
+
465
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x01, 0x00, 0xF8, 0x00, 0x00]))
466
+
467
+ assert res.length == 4
468
+ assert res.seed == list(b"\x12\x34\x56\x78")
469
+
470
+ @mock.patch("pyxcp.transport.eth.socket.socket")
471
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
472
+ def testUnlock(self, mock_selector, mock_socket):
473
+ ms = MockSocket()
474
+
475
+ mock_socket.return_value.recv.side_effect = ms.recv
476
+ mock_selector.return_value.select.side_effect = ms.select
477
+
478
+ with Master("eth", config=create_config()) as xm:
479
+ ms.push_packet(self.DefaultConnectResponse)
480
+
481
+ res = xm.connect()
482
+
483
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
484
+
485
+ ms.push_packet("FF 10")
486
+
487
+ res = xm.unlock(0x04, [0x12, 0x34, 0x56, 0x78])
488
+
489
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x01, 0x00, 0xF7, 0x04, 0x12, 0x34, 0x56, 0x78]))
490
+
491
+ assert res.calpag is False
492
+ assert res.daq is False
493
+ assert res.stim is False
494
+ assert res.pgm is True
495
+
496
+ @mock.patch("pyxcp.transport.eth.socket.socket")
497
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
498
+ def testSetMta(self, mock_selector, mock_socket):
499
+ ms = MockSocket()
500
+
501
+ mock_socket.return_value.recv.side_effect = ms.recv
502
+ mock_selector.return_value.select.side_effect = ms.select
503
+
504
+ with Master("eth", config=create_config()) as xm:
505
+ ms.push_packet(self.DefaultConnectResponse)
506
+
507
+ res = xm.connect()
508
+
509
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
510
+
511
+ ms.push_frame("01 00 01 00 FF")
512
+
513
+ res = xm.setMta(0x12345678, 0x55)
514
+
515
+ mock_socket.return_value.send.assert_called_with(
516
+ bytes(
517
+ [
518
+ 0x08,
519
+ 0x00,
520
+ 0x01,
521
+ 0x00,
522
+ 0xF6,
523
+ 0x00,
524
+ 0x00,
525
+ 0x55,
526
+ 0x78,
527
+ 0x56,
528
+ 0x34,
529
+ 0x12,
530
+ ]
531
+ )
532
+ )
533
+
534
+ assert res == b""
535
+
536
+ @mock.patch("pyxcp.transport.eth.socket.socket")
537
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
538
+ def testUpload(self, mock_selector, mock_socket):
539
+ ms = MockSocket()
540
+
541
+ mock_socket.return_value.recv.side_effect = ms.recv
542
+ mock_selector.return_value.select.side_effect = ms.select
543
+
544
+ with Master("eth", config=create_config()) as xm:
545
+ ms.push_packet(self.DefaultConnectResponse)
546
+
547
+ res = xm.connect()
548
+
549
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
550
+
551
+ ms.push_frame(
552
+ [
553
+ 0x09,
554
+ 0x00,
555
+ 0x01,
556
+ 0x00,
557
+ 0xFF,
558
+ 0x01,
559
+ 0x02,
560
+ 0x03,
561
+ 0x04,
562
+ 0x05,
563
+ 0x06,
564
+ 0x07,
565
+ 0x08,
566
+ ]
567
+ )
568
+
569
+ res = xm.upload(8)
570
+
571
+ mock_socket.return_value.send.assert_called_with(bytes([0x02, 0x00, 0x01, 0x00, 0xF5, 0x08]))
572
+
573
+ assert res == b"\x01\x02\x03\x04\x05\x06\x07\x08"
574
+
575
+ @mock.patch("pyxcp.transport.eth.socket.socket")
576
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
577
+ def testShortUpload(self, mock_selector, mock_socket):
578
+ ms = MockSocket()
579
+
580
+ mock_socket.return_value.recv.side_effect = ms.recv
581
+ mock_selector.return_value.select.side_effect = ms.select
582
+
583
+ with Master("eth", config=create_config()) as xm:
584
+ ms.push_packet(self.DefaultConnectResponse)
585
+
586
+ res = xm.connect()
587
+
588
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
589
+
590
+ ms.push_frame("09 00 01 00 FF 01 02 03 04 05 06 07 08")
591
+
592
+ res = xm.shortUpload(8, 0xCAFEBABE, 1)
593
+
594
+ mock_socket.return_value.send.assert_called_with(
595
+ bytes(
596
+ [
597
+ 0x08,
598
+ 0x00,
599
+ 0x01,
600
+ 0x00,
601
+ 0xF4,
602
+ 0x08,
603
+ 0x00,
604
+ 0x01,
605
+ 0xBE,
606
+ 0xBA,
607
+ 0xFE,
608
+ 0xCA,
609
+ ]
610
+ )
611
+ )
612
+
613
+ assert res == b"\x01\x02\x03\x04\x05\x06\x07\x08"
614
+
615
+ @mock.patch("pyxcp.transport.eth.socket.socket")
616
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
617
+ def testBuildChecksum(self, mock_selector, mock_socket):
618
+ ms = MockSocket()
619
+
620
+ mock_socket.return_value.recv.side_effect = ms.recv
621
+ mock_selector.return_value.select.side_effect = ms.select
622
+
623
+ with Master("eth", config=create_config()) as xm:
624
+ ms.push_packet(self.DefaultConnectResponse)
625
+
626
+ res = xm.connect()
627
+
628
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
629
+
630
+ ms.push_frame("08 00 01 00 FF 09 00 00 04 05 06 07")
631
+
632
+ res = xm.buildChecksum(1024)
633
+
634
+ mock_socket.return_value.send.assert_called_with(
635
+ bytes(
636
+ [
637
+ 0x08,
638
+ 0x00,
639
+ 0x01,
640
+ 0x00,
641
+ 0xF3,
642
+ 0x00,
643
+ 0x00,
644
+ 0x00,
645
+ 0x00,
646
+ 0x04,
647
+ 0x00,
648
+ 0x00,
649
+ ]
650
+ )
651
+ )
652
+
653
+ assert res.checksumType == types.BuildChecksumResponse.checksumType.XCP_CRC_32
654
+ assert res.checksum == 0x07060504
655
+
656
+ @mock.patch("pyxcp.transport.eth.socket.socket")
657
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
658
+ def testTransportLayerCmd(self, mock_selector, mock_socket):
659
+ ms = MockSocket()
660
+
661
+ mock_socket.return_value.recv.side_effect = ms.recv
662
+ mock_selector.return_value.select.side_effect = ms.select
663
+
664
+ with Master("eth", config=create_config()) as xm:
665
+ ms.push_packet(self.DefaultConnectResponse)
666
+
667
+ res = xm.connect()
668
+
669
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
670
+
671
+ ms.push_frame([0x03, 0x00, 0x01, 0x00, 0xFF, 0xAA, 0xBB])
672
+
673
+ data = [0xBE, 0xEF]
674
+ res = xm.transportLayerCmd(0x55, data)
675
+
676
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x01, 0x00, 0xF2, 0x55, 0xBE, 0xEF]))
677
+
678
+ assert res == b"\xaa\xbb"
679
+
680
+ @mock.patch("pyxcp.transport.eth.socket.socket")
681
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
682
+ def testUserCmd(self, mock_selector, mock_socket):
683
+ ms = MockSocket()
684
+
685
+ mock_socket.return_value.recv.side_effect = ms.recv
686
+ mock_selector.return_value.select.side_effect = ms.select
687
+
688
+ with Master("eth", config=create_config()) as xm:
689
+ ms.push_packet(self.DefaultConnectResponse)
690
+
691
+ res = xm.connect()
692
+
693
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
694
+
695
+ ms.push_frame([0x03, 0x00, 0x01, 0x00, 0xFF, 0xAA, 0xBB])
696
+
697
+ data = [0xBE, 0xEF]
698
+ res = xm.userCmd(0x55, data)
699
+
700
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x01, 0x00, 0xF1, 0x55, 0xBE, 0xEF]))
701
+
702
+ assert res == b"\xaa\xbb"
703
+
704
+ @mock.patch("pyxcp.transport.eth.socket.socket")
705
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
706
+ def testGetVersion(self, mock_selector, mock_socket):
707
+ ms = MockSocket()
708
+
709
+ mock_socket.return_value.recv.side_effect = ms.recv
710
+ mock_selector.return_value.select.side_effect = ms.select
711
+
712
+ with Master("eth", config=create_config()) as xm:
713
+ ms.push_packet(self.DefaultConnectResponse)
714
+
715
+ res = xm.connect()
716
+
717
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
718
+
719
+ ms.push_packet("FF 00 01 05 01 04")
720
+
721
+ res = xm.getVersion()
722
+
723
+ mock_socket.return_value.send.assert_called_with(bytes([0x02, 0x00, 0x01, 0x00, 0xC0, 0x00]))
724
+
725
+ assert res.protocolMajor == 1
726
+ assert res.protocolMinor == 5
727
+ assert res.transportMajor == 1
728
+ assert res.transportMinor == 4
729
+
730
+ @mock.patch("pyxcp.transport.eth.socket.socket")
731
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
732
+ def testDownload(self, mock_selector, mock_socket):
733
+ ms = MockSocket()
734
+
735
+ mock_socket.return_value.recv.side_effect = ms.recv
736
+ mock_selector.return_value.select.side_effect = ms.select
737
+
738
+ with Master("eth", config=create_config()) as xm:
739
+ ms.push_packet(self.DefaultConnectResponse)
740
+
741
+ res = xm.connect()
742
+
743
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
744
+
745
+ ms.push_frame([0x01, 0x00, 0x01, 0x00, 0xFF])
746
+
747
+ data = [0xCA, 0xFE, 0xBA, 0xBE]
748
+ res = xm.download(data)
749
+
750
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x01, 0x00, 0xF0, 0x04, 0xCA, 0xFE, 0xBA, 0xBE]))
751
+
752
+ assert res == b""
753
+
754
+ def testDownloadBlock(self):
755
+ conf = {
756
+ "CAN_ID_MASTER": 1,
757
+ "CAN_ID_SLAVE": 2,
758
+ "CAN_DRIVER": "MockCanInterface",
759
+ "CAN_USE_DEFAULT_LISTENER": False,
760
+ }
761
+ with Master("can", config=conf) as xm:
762
+ mock_caninterface = xm.transport.can_interface
763
+ mock_caninterface.push_packet(self.DefaultConnectResponse)
764
+ xm.connect()
765
+
766
+ data = bytes([i for i in range(14)])
767
+ # Downloading 14 bytes in block mode:
768
+ # command code n payload...
769
+ # testing -> DOWNLOAD: 0xF0, 14, 0, 1, 2, 3, 4, 5
770
+ # DOWNLOAD_NEXT: 0xEF, 8, 6, 7, 8, 9, 10,11
771
+ # DOWNLOAD_NEXT: 0xEF, 2, 12,13
772
+ # DOWNLOAD service with block mode, this is the first DOWNLOAD packet of a block, no response
773
+ # is expected from the slave device:
774
+ res = xm.download(data=data, blockModeLength=len(data))
775
+ assert res is None
776
+
777
+ # DOWNLOAD service with normal mode, normal response expected
778
+ mock_caninterface.push_packet("FF")
779
+ res = xm.download(data=data, blockModeLength=None)
780
+ assert res == b""
781
+
782
+ @mock.patch("pyxcp.transport.eth.socket.socket")
783
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
784
+ def testDownloadNext(self, mock_selector, mock_socket):
785
+ ms = MockSocket()
786
+
787
+ mock_socket.return_value.recv.side_effect = ms.recv
788
+ mock_selector.return_value.select.side_effect = ms.select
789
+
790
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
791
+ ms.push_packet(self.DefaultConnectResponse)
792
+
793
+ res = xm.connect()
794
+
795
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
796
+
797
+ ms.push_frame([0x01, 0x00, 0x01, 0x00, 0xFF])
798
+
799
+ data = [0xCA, 0xFE, 0xBA, 0xBE]
800
+ remaining_block_length = 42
801
+ res = xm.downloadNext(data, remainingBlockLength=remaining_block_length)
802
+
803
+ mock_socket.return_value.send.assert_called_with(
804
+ bytes(
805
+ [
806
+ 0x06,
807
+ 0x00,
808
+ 0x01,
809
+ 0x00,
810
+ 0xEF,
811
+ remaining_block_length,
812
+ 0xCA,
813
+ 0xFE,
814
+ 0xBA,
815
+ 0xBE,
816
+ ]
817
+ )
818
+ )
819
+
820
+ # no response shall be expected if it is not the last DOWNLOAD_NEXT packet of a block
821
+ assert res is None
822
+
823
+ def testDownloadNextBlock(self):
824
+ conf = {
825
+ "CAN_ID_MASTER": 1,
826
+ "CAN_ID_SLAVE": 2,
827
+ "CAN_DRIVER": "MockCanInterface",
828
+ "CAN_USE_DEFAULT_LISTENER": False,
829
+ }
830
+ with Master("can", config=conf) as xm:
831
+ mock_caninterface = xm.transport.can_interface
832
+ mock_caninterface.push_packet(self.DefaultConnectResponse)
833
+ xm.connect()
834
+
835
+ data = bytes([i for i in range(14)])
836
+ # Downloading 14 bytes in block mode:
837
+ # command code n payload...
838
+ # DOWNLOAD: 0xF0, 14, 0, 1, 2, 3, 4, 5
839
+ # testing -> DOWNLOAD_NEXT: 0xEF, 8, 6, 7, 8, 9, 10,11
840
+ # testing -> DOWNLOAD_NEXT: 0xEF, 2, 12,13
841
+
842
+ # This is the first DOWNLOAD_NEXT packet of a block, no response is expected from the slave device.
843
+ res = xm.downloadNext(data=data, remainingBlockLength=8, last=False)
844
+ assert res is None
845
+
846
+ # This is the last DOWNLOAD_NEXT packet of a block, positive response is expected from the slave device.
847
+ mock_caninterface.push_packet("FF")
848
+ res = xm.downloadNext(data=data, remainingBlockLength=2, last=True)
849
+ assert res == b""
850
+
851
+ @mock.patch("pyxcp.transport.eth.socket.socket")
852
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
853
+ def testDownloadMax(self, mock_selector, mock_socket):
854
+ ms = MockSocket()
855
+
856
+ mock_socket.return_value.recv.side_effect = ms.recv
857
+ mock_selector.return_value.select.side_effect = ms.select
858
+
859
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
860
+ ms.push_packet(self.DefaultConnectResponse)
861
+
862
+ res = xm.connect()
863
+
864
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
865
+
866
+ ms.push_frame([0x01, 0x00, 0x01, 0x00, 0xFF])
867
+
868
+ data = [0xCA, 0xFE, 0xBA, 0xBE]
869
+ res = xm.downloadMax(data)
870
+
871
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x01, 0x00, 0xEE, 0xCA, 0xFE, 0xBA, 0xBE]))
872
+
873
+ assert res == b""
874
+
875
+ @mock.patch("pyxcp.transport.eth.socket.socket")
876
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
877
+ def testShortDownload(self, mock_selector, mock_socket):
878
+ ms = MockSocket()
879
+
880
+ mock_socket.return_value.recv.side_effect = ms.recv
881
+ mock_selector.return_value.select.side_effect = ms.select
882
+
883
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
884
+ ms.push_packet(self.DefaultConnectResponse)
885
+
886
+ res = xm.connect()
887
+
888
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
889
+
890
+ ms.push_frame("01 00 01 00 FF")
891
+
892
+ data = [0xCA, 0xFE, 0xBA, 0xBE]
893
+ res = xm.shortDownload(0x12345678, 0x55, data)
894
+
895
+ mock_socket.return_value.send.assert_called_with(
896
+ bytes(
897
+ [
898
+ 0x0C,
899
+ 0x00,
900
+ 0x01,
901
+ 0x00,
902
+ 0xED,
903
+ 0x04,
904
+ 0x00,
905
+ 0x55,
906
+ 0x78,
907
+ 0x56,
908
+ 0x34,
909
+ 0x12,
910
+ 0xCA,
911
+ 0xFE,
912
+ 0xBA,
913
+ 0xBE,
914
+ ]
915
+ )
916
+ )
917
+
918
+ assert res == b""
919
+
920
+ @mock.patch("pyxcp.transport.eth.socket.socket")
921
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
922
+ def testModifyBits(self, mock_selector, mock_socket):
923
+ ms = MockSocket()
924
+
925
+ mock_socket.return_value.recv.side_effect = ms.recv
926
+ mock_selector.return_value.select.side_effect = ms.select
927
+
928
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
929
+ ms.push_packet(self.DefaultConnectResponse)
930
+
931
+ res = xm.connect()
932
+
933
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
934
+
935
+ ms.push_frame("01 00 01 00 ff")
936
+
937
+ res = xm.modifyBits(0xFF, 0x1234, 0xABCD)
938
+
939
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x01, 0x00, 0xEC, 0xFF, 0x34, 0x12, 0xCD, 0xAB]))
940
+
941
+ assert res == b""
942
+
943
+ @mock.patch("pyxcp.transport.eth.socket.socket")
944
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
945
+ def testPagCommands(self, mock_selector, mock_socket):
946
+ ms = MockSocket()
947
+
948
+ mock_socket.return_value.recv.side_effect = ms.recv
949
+ mock_selector.return_value.select.side_effect = ms.select
950
+
951
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
952
+ ms.push_packet(self.DefaultConnectResponse)
953
+
954
+ res = xm.connect()
955
+
956
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
957
+
958
+ ms.push_packet("FF")
959
+
960
+ res = xm.setCalPage(0x03, 0x12, 0x34)
961
+
962
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x01, 0x00, 0xEB, 0x03, 0x12, 0x34]))
963
+
964
+ assert res == b""
965
+
966
+ ms.push_packet("FF 00 00 55")
967
+
968
+ res = xm.getCalPage(0x02, 0x44)
969
+
970
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x02, 0x00, 0xEA, 0x02, 0x44]))
971
+
972
+ assert res == 0x55
973
+
974
+ ms.push_packet("FF 10 01")
975
+
976
+ res = xm.getPagProcessorInfo()
977
+
978
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x03, 0x00, 0xE9]))
979
+
980
+ assert res.maxSegments == 16
981
+ assert res.pagProperties == 0x01
982
+
983
+ ms.push_packet("FF 00 00 00 78 56 34 12")
984
+
985
+ res = xm.getSegmentInfo(0, 5, 1, 0)
986
+
987
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x04, 0x00, 0xE8, 0x00, 0x05, 0x01, 0x00]))
988
+
989
+ assert res.basicInfo == 0x12345678
990
+
991
+ ms.push_packet("FF aa bb cc 78 56")
992
+
993
+ res = xm.getSegmentInfo(1, 5, 0, 0)
994
+
995
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x05, 0x00, 0xE8, 0x01, 0x05, 0x00, 0x00]))
996
+
997
+ assert res.maxPages == 0xAA
998
+ assert res.addressExtension == 0xBB
999
+ assert res.maxMapping == 0xCC
1000
+ assert res.compressionMethod == 0x78
1001
+ assert res.encryptionMethod == 0x56
1002
+
1003
+ ms.push_packet("FF 00 00 00 78 56 34 12")
1004
+
1005
+ res = xm.getSegmentInfo(2, 5, 1, 3)
1006
+
1007
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x06, 0x00, 0xE8, 0x02, 0x05, 0x01, 0x03]))
1008
+
1009
+ assert res.mappingInfo == 0x12345678
1010
+
1011
+ ms.push_packet("FF 3F 55")
1012
+
1013
+ res = xm.getPageInfo(0x12, 0x34)
1014
+
1015
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x07, 0x00, 0xE7, 0x00, 0x12, 0x34]))
1016
+
1017
+ assert res[0].xcpWriteAccessWithEcu
1018
+ assert res[1] == 0x55
1019
+
1020
+ ms.push_packet("FF")
1021
+
1022
+ res = xm.setSegmentMode(0x01, 0x23)
1023
+
1024
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x08, 0x00, 0xE6, 0x01, 0x23]))
1025
+
1026
+ assert res == b""
1027
+
1028
+ ms.push_packet("FF 00 01")
1029
+
1030
+ res = xm.getSegmentMode(0x23)
1031
+
1032
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x09, 0x00, 0xE5, 0x00, 0x23]))
1033
+
1034
+ assert res == 0x01
1035
+
1036
+ ms.push_packet("FF")
1037
+
1038
+ res = xm.copyCalPage(0x12, 0x34, 0x56, 0x78)
1039
+
1040
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x0A, 0x00, 0xE4, 0x12, 0x34, 0x56, 0x78]))
1041
+
1042
+ assert res == b""
1043
+
1044
+ @mock.patch("pyxcp.transport.eth.socket.socket")
1045
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
1046
+ def testDaqCommands(self, mock_selector, mock_socket):
1047
+ ms = MockSocket()
1048
+
1049
+ mock_socket.return_value.recv.side_effect = ms.recv
1050
+ mock_selector.return_value.select.side_effect = ms.select
1051
+
1052
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
1053
+ ms.push_packet(self.DefaultConnectResponse)
1054
+
1055
+ res = xm.connect()
1056
+
1057
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
1058
+
1059
+ ms.push_frame([0x01, 0x00, 0x01, 0x00, 0xFF])
1060
+
1061
+ res = xm.setDaqPtr(2, 3, 4)
1062
+
1063
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x01, 0x00, 0xE2, 0x00, 0x02, 0x00, 0x03, 0x04]))
1064
+
1065
+ assert res == b""
1066
+
1067
+ ms.push_frame([0x01, 0x00, 0x02, 0x00, 0xFF])
1068
+
1069
+ res = xm.writeDaq(31, 15, 1, 0x12345678)
1070
+
1071
+ mock_socket.return_value.send.assert_called_with(
1072
+ bytes(
1073
+ [
1074
+ 0x08,
1075
+ 0x00,
1076
+ 0x02,
1077
+ 0x00,
1078
+ 0xE1,
1079
+ 0x1F,
1080
+ 0x0F,
1081
+ 0x01,
1082
+ 0x78,
1083
+ 0x56,
1084
+ 0x34,
1085
+ 0x12,
1086
+ ]
1087
+ )
1088
+ )
1089
+
1090
+ assert res == b""
1091
+
1092
+ ms.push_frame([0x01, 0x00, 0x03, 0x00, 0xFF])
1093
+
1094
+ res = xm.setDaqListMode(0x3B, 256, 512, 1, 0xFF)
1095
+
1096
+ mock_socket.return_value.send.assert_called_with(
1097
+ bytes(
1098
+ [
1099
+ 0x08,
1100
+ 0x00,
1101
+ 0x03,
1102
+ 0x00,
1103
+ 0xE0,
1104
+ 0x3B,
1105
+ 0x00,
1106
+ 0x01,
1107
+ 0x00,
1108
+ 0x02,
1109
+ 0x01,
1110
+ 0xFF,
1111
+ ]
1112
+ )
1113
+ )
1114
+
1115
+ assert res == b""
1116
+
1117
+ ms.push_frame([0x02, 0x00, 0x04, 0x00, 0xFF, 0x00])
1118
+
1119
+ res = xm.startStopDaqList(1, 512)
1120
+
1121
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x04, 0x00, 0xDE, 0x01, 0x00, 0x02]))
1122
+
1123
+ assert res.firstPid == 0
1124
+
1125
+ ms.push_frame([0x01, 0x00, 0x05, 0x00, 0xFF])
1126
+
1127
+ res = xm.startStopSynch(3)
1128
+
1129
+ mock_socket.return_value.send.assert_called_with(bytes([0x02, 0x00, 0x05, 0x00, 0xDD, 0x03]))
1130
+
1131
+ assert res == b""
1132
+
1133
+ ms.push_packet("FF")
1134
+
1135
+ res = xm.writeDaqMultiple(
1136
+ [
1137
+ dict(bitOffset=1, size=2, address=3, addressExt=4),
1138
+ dict(bitOffset=5, size=6, address=0x12345678, addressExt=7),
1139
+ ]
1140
+ )
1141
+
1142
+ mock_socket.return_value.send.assert_called_with(
1143
+ bytes(
1144
+ [
1145
+ 0x12,
1146
+ 0x00,
1147
+ 0x06,
1148
+ 0x00,
1149
+ 0xC7,
1150
+ 0x02,
1151
+ 0x01,
1152
+ 0x02,
1153
+ 0x03,
1154
+ 0x00,
1155
+ 0x00,
1156
+ 0x00,
1157
+ 0x04,
1158
+ 0x00,
1159
+ 0x05,
1160
+ 0x06,
1161
+ 0x78,
1162
+ 0x56,
1163
+ 0x34,
1164
+ 0x12,
1165
+ 0x07,
1166
+ 0x00,
1167
+ ]
1168
+ )
1169
+ )
1170
+
1171
+ assert res == b""
1172
+
1173
+ ms.push_frame("08 00 07 00 FF 1F 03 04 78 56 34 12")
1174
+
1175
+ res = xm.readDaq()
1176
+
1177
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x07, 0x00, 0xDB]))
1178
+
1179
+ assert res.bitOffset == 31
1180
+ assert res.sizeofDaqElement == 3
1181
+ assert res.adressExtension == 4
1182
+ assert res.address == 0x12345678
1183
+
1184
+ ms.push_frame("08 00 08 00 FF 00 03 04 78 56 34 12")
1185
+
1186
+ res = xm.getDaqClock()
1187
+
1188
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x08, 0x00, 0xDC]))
1189
+
1190
+ # todo: assert res.triggerInfo ==
1191
+ # todo: assert res.payloadFmt ==
1192
+ # todo: assert res.timestamp == 0x12345678
1193
+ assert res == 0x12345678
1194
+
1195
+ ms.push_frame("08 00 09 00 FF 55 00 01 34 12 22 03")
1196
+
1197
+ res = xm.getDaqProcessorInfo()
1198
+
1199
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x09, 0x00, 0xDA]))
1200
+
1201
+ assert res.daqProperties.overloadMsb is True
1202
+ assert res.daqProperties.bitStimSupported is False
1203
+ assert res.maxDaq == 256
1204
+ assert res.maxEventChannel == 0x1234
1205
+ assert res.minDaq == 0x22
1206
+ assert res.daqKeyByte.Optimisation_Type == "OM_ODT_TYPE_64"
1207
+
1208
+ ms.push_frame("08 00 0A 00 FF 12 34 56 78 AA 34 12")
1209
+
1210
+ res = xm.getDaqResolutionInfo()
1211
+
1212
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x0A, 0x00, 0xD9]))
1213
+
1214
+ assert res.granularityOdtEntrySizeDaq == 0x12
1215
+ assert res.maxOdtEntrySizeDaq == 0x34
1216
+ assert res.granularityOdtEntrySizeStim == 0x56
1217
+ assert res.maxOdtEntrySizeStim == 0x78
1218
+ assert res.timestampMode.size == "S2"
1219
+ assert res.timestampMode.fixed is True
1220
+ assert res.timestampMode.unit == "DAQ_TIMESTAMP_UNIT_1PS"
1221
+ assert res.timestampTicks == 0x1234
1222
+
1223
+ ms.push_frame("08 00 0B 00 FF AA 00 00 34 12 56 78")
1224
+
1225
+ res = xm.getDaqListMode(256)
1226
+
1227
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x0B, 0x00, 0xDF, 0x00, 0x00, 0x01]))
1228
+
1229
+ assert res.currentMode.resume is True
1230
+ assert res.currentMode.selected is False
1231
+ assert res.currentEventChannel == 0x1234
1232
+ assert res.currentPrescaler == 0x56
1233
+ assert res.currentPriority == 0x78
1234
+
1235
+ ms.push_frame("07 00 0C 00 FF 48 EE 05 06 07 FF")
1236
+
1237
+ res = xm.getDaqEventInfo(256)
1238
+
1239
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x0C, 0x00, 0xD7, 0x00, 0x00, 0x01]))
1240
+
1241
+ assert res.daqEventProperties.consistency == "CONSISTENCY_DAQ"
1242
+ assert res.daqEventProperties.stim is True
1243
+ assert res.daqEventProperties.daq is False
1244
+ assert res.maxDaqList == 0xEE
1245
+ assert res.eventChannelNameLength == 0x05
1246
+ assert res.eventChannelTimeCycle == 0x06
1247
+ assert res.eventChannelTimeUnit == "EVENT_CHANNEL_TIME_UNIT_10MS"
1248
+ assert res.eventChannelPriority == 0xFF
1249
+
1250
+ ms.push_packet("FF AA 34 12 02")
1251
+
1252
+ res = xm.dtoCtrProperties(0x05, 0x1234, 0x5678, 0x02)
1253
+
1254
+ mock_socket.return_value.send.assert_called_with(
1255
+ bytes([0x07, 0x00, 0x0D, 0x00, 0xC5, 0x05, 0x34, 0x12, 0x78, 0x56, 0x02])
1256
+ )
1257
+
1258
+ assert res.properties.evtCtrPresent is True
1259
+ assert res.properties.relatedEventFixed is False
1260
+ assert res.relatedEventChannel == 0x1234
1261
+ assert res.mode.stimMode is True
1262
+ assert res.mode.daqMode is False
1263
+
1264
+ ms.push_frame([0x01, 0x00, 0x0E, 0x00, 0xFF])
1265
+
1266
+ res = xm.clearDaqList(256)
1267
+
1268
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x0E, 0x00, 0xE3, 0x00, 0x00, 0x01]))
1269
+
1270
+ assert res == b""
1271
+
1272
+ ms.push_frame("06 00 0F 00 FF 15 10 20 34 12")
1273
+
1274
+ res = xm.getDaqListInfo(256)
1275
+
1276
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x0F, 0x00, 0xD8, 0x00, 0x00, 0x01]))
1277
+
1278
+ assert res.daqListProperties.packed is True
1279
+ assert res.daqListProperties.eventFixed is False
1280
+ assert res.maxOdt == 0x10
1281
+ assert res.maxOdt == 0x10
1282
+ assert res.maxOdtEntries == 0x20
1283
+ assert res.fixedEvent == 0x1234
1284
+
1285
+ ms.push_frame([0x01, 0x00, 0x10, 0x00, 0xFF])
1286
+
1287
+ res = xm.freeDaq()
1288
+
1289
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x10, 0x00, 0xD6]))
1290
+
1291
+ assert res == b""
1292
+
1293
+ ms.push_frame([0x01, 0x00, 0x11, 0x00, 0xFF])
1294
+
1295
+ res = xm.allocDaq(258)
1296
+
1297
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x11, 0x00, 0xD5, 0x00, 0x02, 0x01]))
1298
+
1299
+ assert res == b""
1300
+
1301
+ ms.push_frame([0x01, 0x00, 0x12, 0x00, 0xFF])
1302
+
1303
+ res = xm.allocOdt(258, 3)
1304
+
1305
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x12, 0x00, 0xD4, 0x00, 0x02, 0x01, 0x03]))
1306
+
1307
+ assert res == b""
1308
+
1309
+ ms.push_frame([0x01, 0x00, 0x13, 0x00, 0xFF])
1310
+
1311
+ res = xm.allocOdtEntry(258, 3, 4)
1312
+
1313
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x13, 0x00, 0xD3, 0x00, 0x02, 0x01, 0x03, 0x04]))
1314
+
1315
+ assert res == b""
1316
+
1317
+ ms.push_frame([0x01, 0x00, 0x14, 0x00, 0xFF])
1318
+
1319
+ res = xm.setDaqPackedMode(258, 0)
1320
+
1321
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x14, 0x00, 0xC0, 0x01, 0x02, 0x01, 0x00]))
1322
+
1323
+ assert res == b""
1324
+
1325
+ ms.push_frame([0x03, 0x00, 0x15, 0x00, 0xFF, 0x00, 0x00])
1326
+
1327
+ res = xm.getDaqPackedMode(258)
1328
+
1329
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x15, 0x00, 0xC0, 0x02, 0x02, 0x01]))
1330
+
1331
+ assert res.daqPackedMode == types.DaqPackedMode.NONE
1332
+ assert res.dpmTimestampMode is None
1333
+
1334
+ ms.push_frame([0x01, 0x00, 0x16, 0x00, 0xFF])
1335
+
1336
+ res = xm.setDaqPackedMode(258, 2, 0b01, 0x1234)
1337
+
1338
+ mock_socket.return_value.send.assert_called_with(
1339
+ bytes(
1340
+ [
1341
+ 0x08,
1342
+ 0x00,
1343
+ 0x16,
1344
+ 0x00,
1345
+ 0xC0,
1346
+ 0x01,
1347
+ 0x02,
1348
+ 0x01,
1349
+ 0x02,
1350
+ 0x01,
1351
+ 0x34,
1352
+ 0x12,
1353
+ ]
1354
+ )
1355
+ )
1356
+
1357
+ assert res == b""
1358
+
1359
+ ms.push_frame("06 00 17 00 FF 00 02 01 34 12")
1360
+
1361
+ res = xm.getDaqPackedMode(258)
1362
+
1363
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x17, 0x00, 0xC0, 0x02, 0x02, 0x01]))
1364
+
1365
+ assert res.daqPackedMode == "EVENT_GROUPED"
1366
+ assert res.dpmTimestampMode == 0x01
1367
+ assert res.dpmSampleCount == 0x1234
1368
+
1369
+ @mock.patch("pyxcp.transport.eth.socket.socket")
1370
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
1371
+ def testPgmCommands(self, mock_selector, mock_socket):
1372
+ ms = MockSocket()
1373
+
1374
+ mock_socket.return_value.recv.side_effect = ms.recv
1375
+ mock_selector.return_value.select.side_effect = ms.select
1376
+
1377
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
1378
+ ms.push_packet(self.DefaultConnectResponse)
1379
+
1380
+ res = xm.connect()
1381
+
1382
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
1383
+
1384
+ ms.push_packet(b"\xFF\x00\x01\x08\x2A\xFF\x55")
1385
+
1386
+ res = xm.programStart()
1387
+
1388
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x01, 0x00, 0xD2]))
1389
+
1390
+ assert res.commModePgm.masterBlockMode is True
1391
+ assert res.commModePgm.interleavedMode is False
1392
+ assert res.commModePgm.slaveBlockMode is False
1393
+ assert res.maxCtoPgm == 8
1394
+ assert res.maxBsPgm == 0x2A
1395
+ assert res.minStPgm == 0xFF
1396
+ assert res.queueSizePgm == 0x55
1397
+
1398
+ ms.push_packet("FF")
1399
+
1400
+ res = xm.programClear(0x00, 0xA0000100)
1401
+
1402
+ mock_socket.return_value.send.assert_called_with(
1403
+ bytes(
1404
+ [
1405
+ 0x08,
1406
+ 0x00,
1407
+ 0x02,
1408
+ 0x00,
1409
+ 0xD1,
1410
+ 0x00,
1411
+ 0x00,
1412
+ 0x00,
1413
+ 0x00,
1414
+ 0x01,
1415
+ 0x00,
1416
+ 0xA0,
1417
+ ]
1418
+ )
1419
+ )
1420
+
1421
+ assert res == b""
1422
+
1423
+ ms.push_packet("FF")
1424
+
1425
+ res = xm.program([0x01, 0x02, 0x03, 0x04], blockLength=4, last=True)
1426
+
1427
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x03, 0x00, 0xD0, 0x04, 0x01, 0x02, 0x03, 0x04]))
1428
+
1429
+ assert res == b""
1430
+
1431
+ ms.push_packet("FF")
1432
+
1433
+ res = xm.programReset()
1434
+
1435
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x04, 0x00, 0xCF]))
1436
+
1437
+ assert res == b""
1438
+
1439
+ ms.push_packet("FF AA BB")
1440
+
1441
+ res = xm.getPgmProcessorInfo()
1442
+
1443
+ mock_socket.return_value.send.assert_called_with(bytes([0x01, 0x00, 0x05, 0x00, 0xCE]))
1444
+
1445
+ assert res.pgmProperties.nonSeqPgmRequired is True
1446
+ assert res.pgmProperties.nonSeqPgmSupported is False
1447
+ assert res.maxSector == 0xBB
1448
+
1449
+ ms.push_packet("FF AA BB CC 78 56 34 12")
1450
+
1451
+ res = xm.getSectorInfo(0, 0x12)
1452
+
1453
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x06, 0x00, 0xCD, 0, 0x12]))
1454
+
1455
+ assert res.clearSequenceNumber == 0xAA
1456
+ assert res.programSequenceNumber == 0xBB
1457
+ assert res.programmingMethod == 0xCC
1458
+ assert res.sectorInfo == 0x12345678
1459
+
1460
+ ms.push_packet("FF AA")
1461
+
1462
+ res = xm.getSectorInfo(2, 0x12)
1463
+
1464
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x07, 0x00, 0xCD, 2, 0x12]))
1465
+
1466
+ assert res.sectorNameLength == 0xAA
1467
+
1468
+ ms.push_packet("FF")
1469
+
1470
+ res = xm.programPrepare(0x1234)
1471
+
1472
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x08, 0x00, 0xCC, 0x00, 0x34, 0x12]))
1473
+
1474
+ assert res == b""
1475
+
1476
+ ms.push_packet("FF")
1477
+
1478
+ res = xm.programFormat(0x81, 0x82, 0x83, 0x01)
1479
+
1480
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x09, 0x00, 0xCB, 0x81, 0x82, 0x83, 0x01]))
1481
+
1482
+ assert res == b""
1483
+
1484
+ ms.push_packet("FF")
1485
+
1486
+ res = xm.programNext([0x01, 0x02, 0x03, 0x04], remainingBlockLength=4, last=True)
1487
+
1488
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x0A, 0x00, 0xCA, 0x04, 0x01, 0x02, 0x03, 0x04]))
1489
+
1490
+ assert res == b""
1491
+
1492
+ ms.push_packet("FF")
1493
+
1494
+ res = xm.programMax([0x01, 0x02, 0x03, 0x04])
1495
+
1496
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x0B, 0x00, 0xC9, 0x01, 0x02, 0x03, 0x04]))
1497
+
1498
+ assert res == b""
1499
+
1500
+ ms.push_packet("FF")
1501
+
1502
+ res = xm.programVerify(0x01, 0x0004, 0xCAFEBABE)
1503
+
1504
+ mock_socket.return_value.send.assert_called_with(
1505
+ bytes(
1506
+ [
1507
+ 0x08,
1508
+ 0x00,
1509
+ 0x0C,
1510
+ 0x00,
1511
+ 0xC8,
1512
+ 0x01,
1513
+ 0x04,
1514
+ 0x00,
1515
+ 0xBE,
1516
+ 0xBA,
1517
+ 0xFE,
1518
+ 0xCA,
1519
+ ]
1520
+ )
1521
+ )
1522
+
1523
+ assert res == b""
1524
+
1525
+ @mock.patch("pyxcp.transport.eth.socket.socket")
1526
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
1527
+ def testDbgCommands(self, mock_selector, mock_socket):
1528
+ ms = MockSocket()
1529
+
1530
+ mock_socket.return_value.recv.side_effect = ms.recv
1531
+ mock_selector.return_value.select.side_effect = ms.select
1532
+
1533
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
1534
+ ms.push_packet(self.DefaultConnectResponse)
1535
+ res = xm.connect()
1536
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
1537
+
1538
+ ms.push_packet(b"\xFF\x01\x00\x02\x03\xFF\xFE\xCA")
1539
+ res = xm.dbgAttach()
1540
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x01, 0x00, 0xC0, 0xFC, 0x00]))
1541
+
1542
+ assert res.major == 1
1543
+ assert res.minor == 0
1544
+ assert res.timeout1 == 2
1545
+ assert res.timeout7 == 3
1546
+ assert res.maxCtoDbg == 0xCAFE
1547
+
1548
+ ms.push_packet(b"\xFF\x04\xFE\xCA\xEF\xBE\xAD\xDE")
1549
+ res = xm.dbgGetVendorInfo()
1550
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x02, 0x00, 0xC0, 0xFC, 0x01]))
1551
+
1552
+ assert res.length == 4
1553
+ assert res.vendorId == 0xCAFE
1554
+ assert res.vendorInfo == list(b"\xEF\xBE\xAD\xDE")
1555
+
1556
+ ms.push_packet(b"\xFF\xFF\x04\x02\x01\x03")
1557
+ res = xm.dbgGetModeInfo()
1558
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x03, 0x00, 0xC0, 0xFC, 0x02]))
1559
+
1560
+ assert res.maxHwIoPins == 4
1561
+ assert res.dialect == 2
1562
+ assert res.feature == 1
1563
+ assert res.serviceLevel == 3
1564
+
1565
+ ms.push_packet(b"\xFF\xFF\xFF\xFF\xBE\xBA\xFE\xCA")
1566
+ res = xm.dbgGetJtagId()
1567
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x04, 0x00, 0xC0, 0xFC, 0x03]))
1568
+
1569
+ assert res.jtagId == 0xCAFEBABE
1570
+
1571
+ ms.push_packet(b"\xFF")
1572
+ res = xm.dbgHaltAfterReset()
1573
+ mock_socket.return_value.send.assert_called_with(bytes([0x03, 0x00, 0x05, 0x00, 0xC0, 0xFC, 0x04]))
1574
+
1575
+ assert res == b""
1576
+
1577
+ ms.push_packet(b"\xFF\x02\x01\x03\x01\x02\x02\x03\x02\x02")
1578
+ res = xm.dbgGetHwioInfo(0)
1579
+ mock_socket.return_value.send.assert_called_with(bytes([0x04, 0x00, 0x06, 0x00, 0xC0, 0xFC, 0x05, 0x00]))
1580
+
1581
+ assert res.num == 2
1582
+ assert res.pins[0].index == 1
1583
+ assert res.pins[0].mode == 3
1584
+ assert res.pins[0].pinClass == 1
1585
+ assert res.pins[0].state == 2
1586
+ assert res.pins[1].index == 2
1587
+ assert res.pins[1].mode == 3
1588
+ assert res.pins[1].pinClass == 2
1589
+ assert res.pins[1].state == 2
1590
+
1591
+ ms.push_packet(b"\xFF")
1592
+ res = xm.dbgSetHwioEvent(0, 1)
1593
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x07, 0x00, 0xC0, 0xFC, 0x06, 0x00, 0x01]))
1594
+
1595
+ assert res == b""
1596
+
1597
+ ms.push_packet(b"\xFF\x01\x00")
1598
+ res = xm.dbgHwioControl([[1, 2, 0], [2, 0, 0]])
1599
+ mock_socket.return_value.send.assert_called_with(
1600
+ bytes(
1601
+ [
1602
+ 0x0C,
1603
+ 0x00,
1604
+ 0x08,
1605
+ 0x00,
1606
+ 0xC0,
1607
+ 0xFC,
1608
+ 0x07,
1609
+ 0x02,
1610
+ 0x01,
1611
+ 0x02,
1612
+ 0x00,
1613
+ 0x00,
1614
+ 0x02,
1615
+ 0x00,
1616
+ 0x00,
1617
+ 0x00,
1618
+ ]
1619
+ )
1620
+ )
1621
+
1622
+ assert res[0] == 1
1623
+ assert res[1] == 0
1624
+
1625
+ ms.push_packet(b"\xFF")
1626
+ res = xm.dbgExclusiveTargetAccess(1, 0)
1627
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x09, 0x00, 0xC0, 0xFC, 0x08, 0x01, 0x00]))
1628
+
1629
+ assert res == b""
1630
+
1631
+ ms.push_packet(b"\xFF\xFF\x02\x00\x01\x04\x03\x02\x01\x00\x02\xCA\xFE\xBA\xBE")
1632
+ res = xm.dbgSequenceMultiple(0x3, 0)
1633
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x0A, 0x00, 0xC0, 0xFC, 0x09, 0x03, 0x00, 0x00]))
1634
+
1635
+ assert res.num == 2
1636
+ assert res.results[0].status == 0
1637
+ assert res.results[0].repeat == 1
1638
+ assert res.results[0].tdo == 0x04030201
1639
+ assert res.results[1].status == 0
1640
+ assert res.results[1].repeat == 2
1641
+ assert res.results[1].tdo == 0xCAFEBABE
1642
+
1643
+ ms.push_packet(b"\xFF\x02\x08\xAA\x10\xAA\x55")
1644
+ res = xm.dbgLlt(0, 1)
1645
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x0B, 0x00, 0xC0, 0xFC, 0x0A, 0x00, 0x01]))
1646
+
1647
+ assert res.num == 2
1648
+ assert res.results[0].length == 8
1649
+ assert res.results[0].data == list(b"\xAA")
1650
+ assert res.results[1].length == 16
1651
+ assert res.results[1].data == list(b"\xAA\x55")
1652
+
1653
+ ms.push_packet(b"\xFF\xFF\xFF\xFF\x0D\xF0\xAD\xBA")
1654
+ res = xm.dbgReadModifyWrite(1, 4, 0xCAFEBABE, 0xFFFFFFFF, 0xDEADBEEF)
1655
+ mock_socket.return_value.send.assert_called_with(
1656
+ bytes(
1657
+ [
1658
+ 0x18,
1659
+ 0x00,
1660
+ 0x0C,
1661
+ 0x00,
1662
+ 0xC0,
1663
+ 0xFC,
1664
+ 0x0B,
1665
+ 0x00,
1666
+ 0x01,
1667
+ 0x04,
1668
+ 0x00,
1669
+ 0x00,
1670
+ 0xBE,
1671
+ 0xBA,
1672
+ 0xFE,
1673
+ 0xCA,
1674
+ 0x00,
1675
+ 0x00,
1676
+ 0x00,
1677
+ 0x00,
1678
+ 0xFF,
1679
+ 0xFF,
1680
+ 0xFF,
1681
+ 0xFF,
1682
+ 0xEF,
1683
+ 0xBE,
1684
+ 0xAD,
1685
+ 0xDE,
1686
+ ]
1687
+ )
1688
+ )
1689
+
1690
+ assert res.value == 0xBAADF00D
1691
+
1692
+ ms.push_packet(b"\xFF")
1693
+ res = xm.dbgWrite(1, 4, 0xAAAA0001, [0xDDDD0001, 0xDDDD0002])
1694
+ mock_socket.return_value.send.assert_called_with(
1695
+ bytes(
1696
+ [
1697
+ 0x18,
1698
+ 0x00,
1699
+ 0x0D,
1700
+ 0x00,
1701
+ 0xC0,
1702
+ 0xFC,
1703
+ 0x0C,
1704
+ 0x00,
1705
+ 0x01,
1706
+ 0x04,
1707
+ 0x02,
1708
+ 0x00,
1709
+ 0x01,
1710
+ 0x00,
1711
+ 0xAA,
1712
+ 0xAA,
1713
+ 0x00,
1714
+ 0x00,
1715
+ 0x00,
1716
+ 0x00,
1717
+ 0x01,
1718
+ 0x00,
1719
+ 0xDD,
1720
+ 0xDD,
1721
+ 0x02,
1722
+ 0x00,
1723
+ 0xDD,
1724
+ 0xDD,
1725
+ ]
1726
+ )
1727
+ )
1728
+
1729
+ assert res == b""
1730
+
1731
+ ms.push_packet(b"\xFF")
1732
+ res = xm.dbgWriteNext(2, [0xDDDD0003, 0xDDDD0004])
1733
+ mock_socket.return_value.send.assert_called_with(
1734
+ bytes(
1735
+ [
1736
+ 0x10,
1737
+ 0x00,
1738
+ 0x0E,
1739
+ 0x00,
1740
+ 0xC0,
1741
+ 0xFC,
1742
+ 0x0D,
1743
+ 0x00,
1744
+ 0x02,
1745
+ 0x00,
1746
+ 0x00,
1747
+ 0x00,
1748
+ 0x03,
1749
+ 0x00,
1750
+ 0xDD,
1751
+ 0xDD,
1752
+ 0x04,
1753
+ 0x00,
1754
+ 0xDD,
1755
+ 0xDD,
1756
+ ]
1757
+ )
1758
+ )
1759
+
1760
+ assert res == b""
1761
+
1762
+ ms.push_packet(b"\xFF")
1763
+ res = xm.dbgWriteCan1(1, 0xAAAA0001)
1764
+ mock_socket.return_value.send.assert_called_with(
1765
+ bytes(
1766
+ [
1767
+ 0x08,
1768
+ 0x00,
1769
+ 0x0F,
1770
+ 0x00,
1771
+ 0xC0,
1772
+ 0xFC,
1773
+ 0x0E,
1774
+ 0x01,
1775
+ 0x01,
1776
+ 0x00,
1777
+ 0xAA,
1778
+ 0xAA,
1779
+ ]
1780
+ )
1781
+ )
1782
+
1783
+ assert res == b""
1784
+
1785
+ ms.push_packet(b"\xFF")
1786
+ res = xm.dbgWriteCan2(4, 2)
1787
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x10, 0x00, 0xC0, 0xFC, 0x0F, 0x04, 0x02]))
1788
+
1789
+ assert res == b""
1790
+
1791
+ ms.push_packet(b"\xFF")
1792
+ res = xm.dbgWriteCanNext(1, [0xCAFEBABE])
1793
+ mock_socket.return_value.send.assert_called_with(
1794
+ bytes(
1795
+ [
1796
+ 0x08,
1797
+ 0x00,
1798
+ 0x11,
1799
+ 0x00,
1800
+ 0xC0,
1801
+ 0xFC,
1802
+ 0x10,
1803
+ 0x01,
1804
+ 0xBE,
1805
+ 0xBA,
1806
+ 0xFE,
1807
+ 0xCA,
1808
+ ]
1809
+ )
1810
+ )
1811
+
1812
+ assert res == b""
1813
+
1814
+ ms.push_packet(b"\xFF\xFF\xFF\xFF\x01\x00\xDD\xDD\x02\x00\xDD\xDD")
1815
+ res = xm.dbgRead(1, 4, 2, 0xAAAA0001)
1816
+ mock_socket.return_value.send.assert_called_with(
1817
+ bytes(
1818
+ [
1819
+ 0x10,
1820
+ 0x00,
1821
+ 0x12,
1822
+ 0x00,
1823
+ 0xC0,
1824
+ 0xFC,
1825
+ 0x11,
1826
+ 0x00,
1827
+ 0x01,
1828
+ 0x04,
1829
+ 0x02,
1830
+ 0x00,
1831
+ 0x01,
1832
+ 0x00,
1833
+ 0xAA,
1834
+ 0xAA,
1835
+ 0x00,
1836
+ 0x00,
1837
+ 0x00,
1838
+ 0x00,
1839
+ ]
1840
+ )
1841
+ )
1842
+
1843
+ assert res.data[0] == 0xDDDD0001
1844
+ assert res.data[1] == 0xDDDD0002
1845
+
1846
+ ms.push_packet(b"\xFF")
1847
+ res = xm.dbgReadCan1(1, 0xAAAA0001)
1848
+ mock_socket.return_value.send.assert_called_with(
1849
+ bytes(
1850
+ [
1851
+ 0x08,
1852
+ 0x00,
1853
+ 0x13,
1854
+ 0x00,
1855
+ 0xC0,
1856
+ 0xFC,
1857
+ 0x12,
1858
+ 0x01,
1859
+ 0x01,
1860
+ 0x00,
1861
+ 0xAA,
1862
+ 0xAA,
1863
+ ]
1864
+ )
1865
+ )
1866
+
1867
+ assert res == b""
1868
+
1869
+ ms.push_packet(b"\xFF")
1870
+ res = xm.dbgReadCan2(4, 2)
1871
+ mock_socket.return_value.send.assert_called_with(bytes([0x05, 0x00, 0x14, 0x00, 0xC0, 0xFC, 0x13, 0x04, 0x02]))
1872
+
1873
+ assert res == b""
1874
+
1875
+ ms.push_packet(
1876
+ "FF 01 00 00 D0 00 00 00 07 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00"
1877
+ " 06 00 00 00 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 07 00 00 00 00 00 02 01 00 00"
1878
+ "00 00 00 00 00 00 01 00 00 00 00 00 05 00 01 00 00 00 00 00 03 01 00 00 00 00 00 00 00 00 02 00 00 00 "
1879
+ "00 00 05 00 04 00 00 00 00 00 04 02 00 00 00 00 00 00 00 00 02 00 00 00 00 00 05 00 04 00 00 00 00 00 "
1880
+ "00 00 01 00 00 00 00 00 05 00 05 00 00 00 00 00 05 02 00 00 00 00 00 00 00 00 02 00 00 00 00 00 05 00 "
1881
+ "04 00 00 00 00 00 00 00 02 00 00 00 00 00 05 00 05 00 00 00 00 00 06 01 00 00 00 00 00 00 00 00 04 00 "
1882
+ "00 00 00 00 05 00 05 00 00 00 00 00"
1883
+ )
1884
+ res = xm.dbgGetTriDescTbl()
1885
+ mock_socket.return_value.send.assert_called_with(
1886
+ bytes(
1887
+ [
1888
+ 0x08,
1889
+ 0x00,
1890
+ 0x15,
1891
+ 0x00,
1892
+ 0xC0,
1893
+ 0xFC,
1894
+ 0x14,
1895
+ 0x00,
1896
+ 0x00,
1897
+ 0x00,
1898
+ 0x00,
1899
+ 0x00,
1900
+ ]
1901
+ )
1902
+ )
1903
+
1904
+ assert res.mode == 1
1905
+ assert res.length == 208
1906
+ assert res.table.tri_cnt == 7
1907
+ assert res.table.tris[0].tri == 0
1908
+ assert res.table.tris[0].trad_cnt == 1
1909
+ assert res.table.tris[0].trads[0].trai == 0x0
1910
+ assert res.table.tris[0].trads[0].trdt == 0x5
1911
+ assert res.table.tris[0].trads[0].trat == 0x6
1912
+ assert res.table.tris[1].tri == 1
1913
+ assert res.table.tris[1].trad_cnt == 1
1914
+ assert res.table.tris[1].trads[0].trai == 0x0
1915
+ assert res.table.tris[1].trads[0].trdt == 0x5
1916
+ assert res.table.tris[1].trads[0].trat == 0x7
1917
+ assert res.table.tris[2].tri == 2
1918
+ assert res.table.tris[2].trad_cnt == 1
1919
+ assert res.table.tris[2].trads[0].trai == 0x10000
1920
+ assert res.table.tris[2].trads[0].trdt == 0x5
1921
+ assert res.table.tris[2].trads[0].trat == 0x1
1922
+ assert res.table.tris[3].tri == 3
1923
+ assert res.table.tris[3].trad_cnt == 1
1924
+ assert res.table.tris[3].trads[0].trai == 0x20000
1925
+ assert res.table.tris[3].trads[0].trdt == 0x5
1926
+ assert res.table.tris[3].trads[0].trat == 0x4
1927
+ assert res.table.tris[4].tri == 4
1928
+ assert res.table.tris[4].trad_cnt == 2
1929
+ assert res.table.tris[4].trads[0].trai == 0x20000
1930
+ assert res.table.tris[4].trads[0].trdt == 0x5
1931
+ assert res.table.tris[4].trads[0].trat == 0x4
1932
+ assert res.table.tris[4].trads[1].trai == 0x10000
1933
+ assert res.table.tris[4].trads[1].trdt == 0x5
1934
+ assert res.table.tris[4].trads[1].trat == 0x5
1935
+ assert res.table.tris[5].tri == 5
1936
+ assert res.table.tris[5].trad_cnt == 2
1937
+ assert res.table.tris[5].trads[0].trai == 0x20000
1938
+ assert res.table.tris[5].trads[0].trdt == 0x5
1939
+ assert res.table.tris[5].trads[0].trat == 0x4
1940
+ assert res.table.tris[5].trads[1].trai == 0x20000
1941
+ assert res.table.tris[5].trads[1].trdt == 0x5
1942
+ assert res.table.tris[5].trads[1].trat == 0x5
1943
+ assert res.table.tris[6].tri == 6
1944
+ assert res.table.tris[6].trad_cnt == 1
1945
+ assert res.table.tris[6].trads[0].trai == 0x40000
1946
+ assert res.table.tris[6].trads[0].trdt == 0x5
1947
+ assert res.table.tris[6].trads[0].trat == 0x5
1948
+
1949
+ ms.push_packet("FF 00 0F 00 81 00 0A 34 00 00 00 00 00 00 00 00 00 C2 03")
1950
+ res = xm.dbgLlbt([0x01, 0x00, 0x05, 0x34, 0x00, 0x26, 0x25, 0xA0, 0xDC, 0x03])
1951
+ mock_socket.return_value.send.assert_called_with(
1952
+ bytes(
1953
+ [
1954
+ 0x10,
1955
+ 0x00,
1956
+ 0x16,
1957
+ 0x00,
1958
+ 0xC0,
1959
+ 0xFC,
1960
+ 0x15,
1961
+ 0x00,
1962
+ 0x0A,
1963
+ 0x00,
1964
+ 0x01,
1965
+ 0x00,
1966
+ 0x05,
1967
+ 0x34,
1968
+ 0x00,
1969
+ 0x26,
1970
+ 0x25,
1971
+ 0xA0,
1972
+ 0xDC,
1973
+ 0x03,
1974
+ ]
1975
+ )
1976
+ )
1977
+
1978
+ assert res.length == 15
1979
+ assert res.data == list(b"\x81\x00\x0A\x34\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC2\x03")
1980
+
1981
+ @mock.patch("pyxcp.transport.eth.socket.socket")
1982
+ @mock.patch("pyxcp.transport.eth.selectors.DefaultSelector")
1983
+ def testTimeCorrelationProperties(self, mock_selector, mock_socket):
1984
+ ms = MockSocket()
1985
+
1986
+ mock_socket.return_value.recv.side_effect = ms.recv
1987
+ mock_selector.return_value.select.side_effect = ms.select
1988
+
1989
+ with Master("eth", config={"HOST": "localhost", "LOGLEVEL": "DEBUG"}) as xm:
1990
+ ms.push_packet(self.DefaultConnectResponse)
1991
+
1992
+ res = xm.connect()
1993
+
1994
+ mock_socket.return_value.send.assert_called_with(self.DefaultConnectCmd)
1995
+
1996
+ ms.push_packet("FF 15 25 01 1F 00 78 56")
1997
+
1998
+ res = xm.timeCorrelationProperties(0x15, 0x01, 0x1234)
1999
+
2000
+ mock_socket.return_value.send.assert_called_with(bytes([0x06, 0x00, 0x01, 0x00, 0xC6, 0x15, 0x01, 0x00, 0x34, 0x12]))
2001
+
2002
+ assert res.slaveConfig == 0x15
2003
+ assert res.observableClocks == 0x25
2004
+ assert res.syncState == 0x01
2005
+ assert res.clockInfo == 0x1F
2006
+ assert res.clusterId == 0x5678