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