• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1% Regression tests for the CCP layer
2
3+ Configuration
4~ conf
5
6= Imports
7
8from test.testsocket import TestSocket, cleanup_testsockets
9
10############
11############
12
13+ Basic operations
14
15= Load module
16load_contrib("automotive.ccp", globals_dict=globals())
17
18= Build CRO CONNECT
19
20cro = CCP(identifier=0x700)/CRO(ctr=1)/CONNECT(station_address=0x02)
21
22assert cro.identifier == 0x700
23assert cro.length == 8
24assert cro.flags == 0
25assert cro.ctr == 1
26assert cro.cmd == 1
27assert cro.station_address == 0x02
28assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x01\x01\x02\x00\xff\xff\xff\xff'
29
30= Dissect DTO CONNECT
31
32dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x01\xff\xff\xff\xff\xff')
33
34assert dto.answers(cro)
35assert dto.identifier == 0x700
36assert dto.length == 8
37assert dto.flags == 0
38assert dto.ctr == 1
39assert dto.load == b"\xff" * 5
40
41= Build CRO EXCHANGE_ID
42
43cro = CCP(identifier=0x700)/CRO(ctr=18)/EXCHANGE_ID(ccp_master_device_id=b'abcdef')
44
45assert cro.identifier == 0x700
46assert cro.length == 8
47assert cro.flags == 0
48assert cro.ctr == 18
49assert cro.cmd == 0x17
50assert cro.ccp_master_device_id == b"abcdef"
51assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x17\x12abcdef'
52
53= Dissect DTO EXCHANGE_ID
54
55dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x12\x04\x02\x03\x03\xff')
56
57assert dto.ctr == 18
58assert dto.packet_id == 0xff
59assert dto.return_code == 0
60assert dto.load == b'\x04\x02\x03\x03\xff'
61# answers will interpret payload
62assert dto.answers(cro)
63assert dto.ctr == 18
64assert dto.packet_id == 0xff
65assert dto.return_code == 0
66assert hasattr(dto, "load") == False
67assert dto.slave_device_ID_length == 4
68assert dto.data_type_qualifier == 2
69assert dto.resource_availability_mask == 3
70assert dto.resource_protection_mask == 3
71assert dto.ccp_reserved == b"\xff"
72
73= Build CRO GET_SEED
74
75cro = CCP(identifier=0x711)/CRO(ctr=19)/GET_SEED(resource=2)
76
77assert cro.identifier == 0x711
78assert cro.length == 8
79assert cro.flags == 0
80assert cro.ctr == 19
81assert cro.cmd == 0x12
82assert cro.resource == 2
83assert cro.ccp_reserved == b"\xff" * 5
84
85assert bytes(cro) == b'\x00\x00\x07\x11\x08\x00\x00\x00\x12\x13\x02\xff\xff\xff\xff\xff'
86
87= Dissect DTO GET_SEED
88
89dto = CCP(b'\x00\x00\x07\x11\x08\x00\x00\x00\xff\x00\x13\x01\x14\x15\x16\x17')
90
91assert dto.ctr == 19
92assert dto.packet_id == 0xff
93assert dto.return_code == 0
94assert dto.load == b'\x01\x14\x15\x16\x17'
95# answers will interpret payload
96assert dto.answers(cro)
97assert dto.ctr == 19
98assert dto.packet_id == 0xff
99assert dto.return_code == 0
100assert hasattr(dto, "load") == False
101assert dto.protection_status == 0x1
102assert dto.seed == b'\x14\x15\x16\x17'
103
104= Build CRO UNLOCK
105
106cro = CCP(identifier=0x711)/CRO(ctr=20)/UNLOCK(key=b"123456")
107
108assert cro.identifier == 0x711
109assert cro.length == 8
110assert cro.flags == 0
111assert cro.ctr == 20
112assert cro.cmd == 0x13
113assert cro.key == b"123456"
114
115assert bytes(cro) == b'\x00\x00\x07\x11\x08\x00\x00\x00\x13\x14123456'
116
117= Dissect DTO UNLOCK
118
119dto = CCP(b'\x00\x00\x07\x11\x08\x00\x00\x00\xff\x00\x14\x02\xff\xff\xff\xff')
120
121assert dto.ctr == 20
122assert dto.packet_id == 0xff
123assert dto.return_code == 0
124assert dto.load == b'\x02\xff\xff\xff\xff'
125# answers will interpret payload
126assert dto.answers(cro)
127assert dto.ctr == 20
128assert dto.packet_id == 0xff
129assert dto.return_code == 0
130assert hasattr(dto, "load") == False
131assert dto.privilege_status == 0x2
132assert dto.ccp_reserved == b"\xff" * 4
133
134= Build CRO SET_MTA
135
136cro = CCP(identifier=0x711)/CRO(ctr=21)/SET_MTA(mta_num=0, address_extension=0x02, address=0x34002000)
137
138assert cro.identifier == 0x711
139assert cro.length == 8
140assert cro.flags == 0
141assert cro.ctr == 21
142assert cro.cmd == 0x02
143assert cro.mta_num == 0
144assert cro.address_extension == 2
145assert cro.address == 0x34002000
146
147assert bytes(cro) == b'\x00\x00\x07\x11\x08\x00\x00\x00\x02\x15\x00\x02\x34\x00\x20\x00'
148
149= Dissect DTO SET_MTA
150
151dto = CCP(b'\x00\x00\x07\x11\x08\x00\x00\x00\xff\x00\x15\xff\xff\xff\xff\xff')
152
153assert dto.ctr == 21
154assert dto.packet_id == 0xff
155assert dto.return_code == 0
156assert dto.load == b'\xff\xff\xff\xff\xff'
157# answers will interpret payload
158assert dto.answers(cro)
159assert dto.ctr == 21
160assert dto.packet_id == 0xff
161assert dto.return_code == 0
162assert hasattr(dto, "load") == True
163assert dto.load == b"\xff" * 5
164
165= Build CRO DNLOAD
166
167cro = CCP(identifier=0x700)/CRO(ctr=17)/DNLOAD(size=0x05, data=b'abcde')
168
169assert cro.identifier == 0x700
170assert cro.length == 8
171assert cro.flags == 0
172assert cro.ctr == 17
173assert cro.cmd == 3
174assert cro.size == 0x05
175assert cro.data == b'abcde'
176assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x03\x11\x05abcde'
177
178= Dissect DTO DNLOAD
179
180dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x11\x02\x34\x00\x20\x05')
181
182assert dto.ctr == 17
183assert dto.packet_id == 0xff
184assert dto.return_code == 0
185assert dto.load == b'\x024\x00 \x05'
186# answers will interpret payload
187assert dto.answers(cro)
188assert dto.ctr == 17
189assert dto.packet_id == 0xff
190assert dto.return_code == 0
191assert hasattr(dto, "load") == False
192assert dto.MTA0_extension == 2
193assert dto.MTA0_address == 0x34002005
194
195= Build CRO DNLOAD_6
196
197cro = CCP(identifier=0x700)/CRO(ctr=0x40)/DNLOAD_6(data=b'abcdef')
198
199assert cro.identifier == 0x700
200assert cro.length == 8
201assert cro.flags == 0
202assert cro.ctr == 0x40
203assert cro.cmd == 0x23
204assert cro.data == b'abcdef'
205assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x23\x40abcdef'
206
207= Dissect DTO DNLOAD_6
208
209dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x40\x02\x34\x00\x20\x06')
210
211assert dto.ctr == 64
212assert dto.packet_id == 0xff
213assert dto.return_code == 0
214assert dto.load == b'\x024\x00 \x06'
215# answers will interpret payload
216assert dto.answers(cro)
217assert dto.ctr == 64
218assert dto.packet_id == 0xff
219assert dto.return_code == 0
220assert hasattr(dto, "load") == False
221assert dto.MTA0_extension == 2
222assert dto.MTA0_address == 0x34002006
223
224= Build CRO UPLOAD
225
226cro = CCP(identifier=0x700)/CRO(ctr=0x41)/UPLOAD(size=4)
227
228assert cro.identifier == 0x700
229assert cro.length == 8
230assert cro.flags == 0
231assert cro.ctr == 0x41
232assert cro.cmd == 0x04
233assert cro.size == 4
234assert cro.ccp_reserved == b"\xff" * 5
235assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x04\x41\x04\xff\xff\xff\xff\xff'
236
237= Dissect DTO UPLOAD
238
239dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x41\x10\x11\x12\x13\xff')
240
241assert dto.ctr == 65
242assert dto.packet_id == 0xff
243assert dto.return_code == 0
244assert dto.load == b'\x10\x11\x12\x13\xff'
245# answers will interpret payload
246assert dto.answers(cro)
247assert dto.ctr == 65
248assert dto.packet_id == 0xff
249assert dto.return_code == 0
250assert hasattr(dto, "load") == False
251assert dto.data == b"\x10\x11\x12\x13\xff"
252
253= Build CRO SHORT_UP
254
255cro = CCP(identifier=0x700)/CRO(ctr=0x42)/SHORT_UP(size=4, address_extension=0, address=0x12345678)
256
257assert cro.identifier == 0x700
258assert cro.length == 8
259assert cro.flags == 0
260assert cro.ctr == 0x42
261assert cro.cmd == 0x0f
262assert cro.size == 4
263assert cro.address == 0x12345678
264assert cro.address_extension == 0
265assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0f\x42\x04\x00\x12\x34\x56\x78'
266
267= Dissect DTO SHORT_UP
268
269dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x42\x10\x11\x12\x13\xff')
270
271assert dto.ctr == 66
272assert dto.packet_id == 0xff
273assert dto.return_code == 0
274assert dto.load == b'\x10\x11\x12\x13\xff'
275# answers will interpret payload
276assert dto.answers(cro)
277assert dto.ctr == 66
278assert dto.packet_id == 0xff
279assert dto.return_code == 0
280assert hasattr(dto, "load") == False
281assert dto.data == b"\x10\x11\x12\x13\xff"
282
283= Build CRO SELECT_CAL_PAGE
284
285cro = CCP(identifier=0x700)/CRO(ctr=0x43)/SELECT_CAL_PAGE()
286
287assert cro.identifier == 0x700
288assert cro.length == 8
289assert cro.flags == 0
290assert cro.ctr == 0x43
291assert cro.cmd == 0x11
292assert cro.ccp_reserved == b"\xff" * 6
293assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x11\x43\xff\xff\xff\xff\xff\xff'
294
295= Dissect DTO SELECT_CAL_PAGE
296
297dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x43\xff\xff\xff\xff\xff')
298
299assert dto.ctr == 67
300assert dto.packet_id == 0xff
301assert dto.return_code == 0
302assert dto.load == b'\xff\xff\xff\xff\xff'
303# answers will interpret payload
304assert dto.answers(cro)
305assert dto.ctr == 67
306assert dto.packet_id == 0xff
307assert dto.return_code == 0
308assert hasattr(dto, "load") == True
309assert dto.load == b"\xff\xff\xff\xff\xff"
310
311= Build CRO GET_DAQ_SIZE
312
313cro = CCP(identifier=0x700)/CRO(ctr=0x44)/GET_DAQ_SIZE(DAQ_num=0x03, DTO_identifier=0x1020304)
314
315assert cro.identifier == 0x700
316assert cro.length == 8
317assert cro.flags == 0
318assert cro.ctr == 0x44
319assert cro.cmd == 0x14
320assert cro.DAQ_num == 0x03
321assert cro.ccp_reserved == 00
322assert cro.DTO_identifier == 0x01020304
323assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x14\x44\x03\x00\x01\x02\x03\x04'
324
325= Dissect DTO GET_DAQ_SIZE
326
327dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x44\x10\x08\xff\xff\xff')
328
329assert dto.ctr == 68
330assert dto.packet_id == 0xff
331assert dto.return_code == 0
332assert dto.load == b'\x10\x08\xff\xff\xff'
333# answers will interpret payload
334assert dto.answers(cro)
335assert dto.ctr == 68
336assert dto.packet_id == 0xff
337assert dto.return_code == 0
338assert hasattr(dto, "load") == False
339assert dto.DAQ_list_size == 16
340assert dto.first_pid == 8
341assert dto.ccp_reserved == b"\xff\xff\xff"
342
343= Build CRO SET_DAQ_PTR
344
345cro = CCP(identifier=0x700)/CRO(ctr=0x45)/SET_DAQ_PTR(DAQ_num=3, ODT_num=5, ODT_element=2)
346
347assert cro.identifier == 0x700
348assert cro.length == 8
349assert cro.flags == 0
350assert cro.ctr == 0x45
351assert cro.cmd == 0x15
352assert cro.DAQ_num == 0x03
353assert cro.ODT_num == 5
354assert cro.ODT_element == 2
355assert cro.ccp_reserved == b"\xff\xff\xff"
356assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x15\x45\x03\x05\x02\xff\xff\xff'
357
358= Dissect DTO SET_DAQ_PTR
359
360dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x45\xff\xff\xff\xff\xff')
361
362assert dto.ctr == 69
363assert dto.packet_id == 0xff
364assert dto.return_code == 0
365assert dto.load == b'\xff\xff\xff\xff\xff'
366# answers will interpret payload
367assert dto.answers(cro)
368assert dto.ctr == 69
369assert dto.packet_id == 0xff
370assert dto.return_code == 0
371assert hasattr(dto, "load") == True
372assert dto.load == b'\xff\xff\xff\xff\xff'
373
374= Build CRO WRITE_DAQ
375
376cro = CCP(identifier=0x700)/CRO(ctr=0x46)/WRITE_DAQ(DAQ_size=2, address_extension=1, address=0x2004200)
377
378assert cro.identifier == 0x700
379assert cro.length == 8
380assert cro.flags == 0
381assert cro.ctr == 0x46
382assert cro.cmd == 0x16
383assert cro.DAQ_size == 0x02
384assert cro.address_extension == 1
385assert cro.address == 0x2004200
386assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x16\x46\x02\x01\x02\x00\x42\x00'
387
388= Dissect DTO WRITE_DAQ
389
390dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x46\xff\xff\xff\xff\xff')
391
392assert dto.ctr == 70
393assert dto.packet_id == 0xff
394assert dto.return_code == 0
395assert dto.load == b'\xff\xff\xff\xff\xff'
396# answers will interpret payload
397assert dto.answers(cro)
398assert dto.ctr == 70
399assert dto.packet_id == 0xff
400assert dto.return_code == 0
401assert hasattr(dto, "load") == True
402assert dto.load == b'\xff\xff\xff\xff\xff'
403
404= Build CRO START_STOP
405
406cro = CCP(identifier=0x700)/CRO(ctr=0x47)/START_STOP(mode=1, DAQ_num=3, ODT_num=7, event_channel=2, transmission_rate=1)
407
408assert cro.identifier == 0x700
409assert cro.length == 8
410assert cro.flags == 0
411assert cro.ctr == 0x47
412assert cro.cmd == 0x06
413assert cro.mode == 0x01
414assert cro.DAQ_num == 3
415assert cro.event_channel == 2
416assert cro.transmission_rate == 1
417assert cro.ODT_num == 7
418assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x06\x47\x01\x03\x07\x02\x00\x01'
419
420= Dissect DTO START_STOP
421
422dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x47\xff\xff\xff\xff\xff')
423
424assert dto.ctr == 71
425assert dto.packet_id == 0xff
426assert dto.return_code == 0
427assert dto.load == b'\xff\xff\xff\xff\xff'
428# answers will interpret payload
429assert dto.answers(cro)
430assert dto.ctr == 71
431assert dto.packet_id == 0xff
432assert dto.return_code == 0
433assert hasattr(dto, "load") == True
434assert dto.load == b'\xff\xff\xff\xff\xff'
435
436= Build CRO DISCONNECT
437
438cro = CCP(identifier=0x700)/CRO(ctr=0x48)/DISCONNECT(type="temporary", station_address=0x208)
439
440assert cro.identifier == 0x700
441assert cro.length == 8
442assert cro.flags == 0
443assert cro.ctr == 0x48
444assert cro.cmd == 0x07
445assert cro.type == 0x00
446assert cro.station_address == 0x208
447assert cro.ccp_reserved0 == b"\xff"
448assert cro.ccp_reserved == b"\xff" * 2
449assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x07\x48\x00\xff\x08\x02\xff\xff'
450
451= Dissect DTO DISCONNECT
452
453dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x48\xff\xff\xff\xff\xff')
454
455assert dto.ctr == 72
456assert dto.packet_id == 0xff
457assert dto.return_code == 0
458assert dto.load == b'\xff\xff\xff\xff\xff'
459# answers will interpret payload
460assert dto.answers(cro)
461assert dto.ctr == 72
462assert dto.packet_id == 0xff
463assert dto.return_code == 0
464assert hasattr(dto, "load") == True
465assert dto.load == b'\xff\xff\xff\xff\xff'
466
467= Build CRO SET_S_STATUS
468
469cro = CCP(identifier=0x700)/CRO(ctr=0x49)/SET_S_STATUS(session_status="RUN+CAL")
470
471assert cro.identifier == 0x700
472assert cro.length == 8
473assert cro.flags == 0
474assert cro.ctr == 0x49
475assert cro.cmd == 0x0c
476assert cro.session_status == 0x81
477assert cro.ccp_reserved == b"\xff" * 5
478assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0c\x49\x81\xff\xff\xff\xff\xff'
479
480= Dissect DTO SET_S_STATUS
481
482dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x49\xff\xff\xff\xff\xff')
483
484assert dto.ctr == 73
485assert dto.packet_id == 0xff
486assert dto.return_code == 0
487assert dto.load == b'\xff\xff\xff\xff\xff'
488# answers will interpret payload
489assert dto.answers(cro)
490assert dto.ctr == 73
491assert dto.packet_id == 0xff
492assert dto.return_code == 0
493assert hasattr(dto, "load") == True
494assert dto.load == b'\xff\xff\xff\xff\xff'
495
496= Build CRO GET_S_STATUS
497
498cro = CCP(identifier=0x700)/CRO(ctr=0x4a)/GET_S_STATUS()
499
500assert cro.identifier == 0x700
501assert cro.length == 8
502assert cro.flags == 0
503assert cro.ctr == 0x4a
504assert cro.cmd == 0x0D
505assert cro.ccp_reserved == b"\xff" * 6
506assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0d\x4a\xff\xff\xff\xff\xff\xff'
507
508= Dissect DTO GET_S_STATUS
509
510dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x4a\x81\xff\xff\xff\xff')
511
512assert dto.ctr == 74
513assert dto.packet_id == 0xff
514assert dto.return_code == 0
515assert dto.load == b'\x81\xff\xff\xff\xff'
516# answers will interpret payload
517assert dto.answers(cro)
518assert dto.ctr == 74
519assert dto.packet_id == 0xff
520assert dto.return_code == 0
521assert hasattr(dto, "load") == False
522assert dto.session_status == 0x81
523assert dto.information_qualifier == 0xff
524assert dto.information == b"\xff" * 3
525
526= Build CRO BUILD_CHKSUM
527
528cro = CCP(identifier=0x700)/CRO(ctr=0x50)/BUILD_CHKSUM(size=0x8000)
529
530assert cro.identifier == 0x700
531assert cro.length == 8
532assert cro.flags == 0
533assert cro.ctr == 0x50
534assert cro.cmd == 0x0e
535assert cro.size == 0x8000
536assert cro.ccp_reserved == b"\xff" * 2
537assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0e\x50\x00\x00\x80\x00\xff\xff'
538
539= Dissect DTO BUILD_CHKSUM
540
541dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x50\x02\x12\x34\xff\xff')
542
543assert dto.ctr == 80
544assert dto.packet_id == 0xff
545assert dto.return_code == 0
546assert dto.load == b'\x02\x12\x34\xff\xff'
547# answers will interpret payload
548assert dto.answers(cro)
549assert dto.ctr == 80
550assert dto.packet_id == 0xff
551assert dto.return_code == 0
552assert hasattr(dto, "load") == False
553assert dto.checksum_size == 2
554assert dto.checksum_data == b'\x12\x34'
555assert dto.ccp_reserved == b'\xff\xff'
556
557= Dissect DTO BUILD_CHKSUM2
558
559dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x50\x04\x12\x34\x56\x78')
560
561assert dto.ctr == 80
562assert dto.packet_id == 0xff
563assert dto.return_code == 0
564assert dto.load == b'\x04\x12\x34\x56\x78'
565# answers will interpret payload
566assert dto.answers(cro)
567assert dto.ctr == 80
568assert dto.packet_id == 0xff
569assert dto.return_code == 0
570assert hasattr(dto, "load") == False
571assert dto.checksum_size == 4
572assert dto.checksum_data == b'\x12\x34\x56\x78'
573assert dto.ccp_reserved == b''
574
575= Build CRO CLEAR_MEMORY
576
577cro = CCP(identifier=0x700)/CRO(ctr=0x51)/CLEAR_MEMORY(size=0x8000)
578
579assert cro.identifier == 0x700
580assert cro.length == 8
581assert cro.flags == 0
582assert cro.ctr == 0x51
583assert cro.cmd == 0x10
584assert cro.size == 0x8000
585assert cro.ccp_reserved == b"\xff" * 2
586assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x10\x51\x00\x00\x80\x00\xff\xff'
587
588= Dissect DTO CLEAR_MEMORY
589
590dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x51\xff\xff\xff\xff\xff')
591
592assert dto.ctr == 81
593assert dto.packet_id == 0xff
594assert dto.return_code == 0
595assert dto.load == b'\xff\xff\xff\xff\xff'
596# answers will interpret payload
597assert dto.answers(cro)
598assert dto.ctr == 81
599assert dto.packet_id == 0xff
600assert dto.return_code == 0
601assert hasattr(dto, "load") == True
602assert dto.load == b'\xff\xff\xff\xff\xff'
603
604= Build CRO PROGRAM
605
606cro = CCP(identifier=0x700)/CRO(ctr=0x52)/PROGRAM(size=0x3, data=b"\x10\x11\x12")
607
608assert cro.identifier == 0x700
609assert cro.length == 8
610assert cro.flags == 0
611assert cro.ctr == 0x52
612assert cro.cmd == 0x18
613assert cro.size == 0x3
614assert cro.data == b"\x10\x11\x12"
615assert cro.ccp_reserved == b"\xff" * 5
616assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x18\x52\x03\x10\x11\x12\xff\xff'
617
618= Dissect DTO PROGRAM
619
620dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x52\x02\x34\x00\x20\x03')
621
622assert dto.ctr == 82
623assert dto.packet_id == 0xff
624assert dto.return_code == 0
625assert dto.load == b'\x02\x34\x00\x20\x03'
626# answers will interpret payload
627assert dto.answers(cro)
628assert dto.ctr == 82
629assert dto.packet_id == 0xff
630assert dto.return_code == 0
631assert hasattr(dto, "load") == False
632assert dto.MTA0_extension == 2
633assert dto.MTA0_address == 0x34002003
634
635= Build CRO PROGRAM_6
636
637cro = CCP(identifier=0x700)/CRO(ctr=0x53)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12")
638
639assert cro.identifier == 0x700
640assert cro.length == 8
641assert cro.flags == 0
642assert cro.ctr == 0x53
643assert cro.cmd == 0x22
644assert cro.data == b"\x10\x11\x12\x10\x11\x12"
645assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x22\x53\x10\x11\x12\x10\x11\x12'
646
647= Dissect DTO PROGRAM_6
648
649dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x53\x02\x34\x00\x20\x06')
650
651assert dto.ctr == 83
652assert dto.packet_id == 0xff
653assert dto.return_code == 0
654assert dto.load == b'\x02\x34\x00\x20\x06'
655# answers will interpret payload
656assert dto.answers(cro)
657assert dto.ctr == 83
658assert dto.packet_id == 0xff
659assert dto.return_code == 0
660assert hasattr(dto, "load") == False
661assert dto.MTA0_extension == 2
662assert dto.MTA0_address == 0x34002006
663
664= Build CRO MOVE
665
666cro = CCP(identifier=0x700)/CRO(ctr=0x54)/MOVE(size=0x8000)
667
668assert cro.identifier == 0x700
669assert cro.length == 8
670assert cro.flags == 0
671assert cro.ctr == 0x54
672assert cro.cmd == 0x19
673assert cro.size == 0x8000
674assert cro.ccp_reserved == b'\xff\xff'
675assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x19\x54\x00\x00\x80\x00\xff\xff'
676
677= Dissect DTO MOVE
678
679dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x54\xff\xff\xff\xff\xff')
680
681assert dto.ctr == 84
682assert dto.packet_id == 0xff
683assert dto.return_code == 0
684assert dto.load == b'\xff\xff\xff\xff\xff'
685# answers will interpret payload
686assert dto.answers(cro)
687assert dto.ctr == 84
688assert dto.packet_id == 0xff
689assert dto.return_code == 0
690assert hasattr(dto, "load") == True
691
692= Build CRO DIAG_SERVICE
693
694cro = CCP(identifier=0x700)/CRO(ctr=0x55)/DIAG_SERVICE(diag_service=0x8000)
695
696assert cro.identifier == 0x700
697assert cro.length == 8
698assert cro.flags == 0
699assert cro.ctr == 0x55
700assert cro.cmd == 0x20
701assert cro.diag_service == 0x8000
702assert cro.ccp_reserved == b'\xff\xff\xff\xff'
703assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x20\x55\x80\x00\xff\xff\xff\xff'
704
705= Dissect DTO DIAG_SERVICE
706
707dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x55\x20\x00\xff\xff\xff')
708
709assert dto.ctr == 85
710assert dto.packet_id == 0xff
711assert dto.return_code == 0
712assert dto.load == b'\x20\x00\xff\xff\xff'
713# answers will interpret payload
714assert dto.answers(cro)
715assert dto.ctr == 85
716assert dto.packet_id == 0xff
717assert dto.return_code == 0
718assert hasattr(dto, "load") == False
719assert dto.data_length == 0x20
720assert dto.data_type == 0x00
721assert dto.ccp_reserved == b"\xff\xff\xff"
722
723= Build CRO ACTION_SERVICE
724
725cro = CCP(identifier=0x700)/CRO(ctr=0x56)/ACTION_SERVICE(action_service=0x8000)
726
727assert cro.identifier == 0x700
728assert cro.length == 8
729assert cro.flags == 0
730assert cro.ctr == 0x56
731assert cro.cmd == 0x21
732assert cro.action_service == 0x8000
733assert cro.ccp_reserved == b'\xff\xff\xff\xff'
734assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x21\x56\x80\x00\xff\xff\xff\xff'
735
736= Dissect DTO ACTION_SERVICE
737
738dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x56\x20\x00\xff\xff\xff')
739
740assert dto.ctr == 86
741assert dto.packet_id == 0xff
742assert dto.return_code == 0
743assert dto.load == b'\x20\x00\xff\xff\xff'
744# answers will interpret payload
745assert dto.answers(cro)
746assert dto.ctr == 86
747assert dto.packet_id == 0xff
748assert dto.return_code == 0
749assert hasattr(dto, "load") == False
750assert dto.data_length == 0x20
751assert dto.data_type == 0x00
752assert dto.ccp_reserved == b"\xff\xff\xff"
753
754= Build CRO TEST
755
756cro = CCP(identifier=0x700)/CRO(ctr=0x60)/TEST(station_address=0x80)
757
758assert cro.identifier == 0x700
759assert cro.length == 8
760assert cro.flags == 0
761assert cro.ctr == 0x60
762assert cro.cmd == 0x05
763assert cro.station_address == 0x80
764assert cro.ccp_reserved == b"\xff" * 4
765assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x05\x60\x80\x00\xff\xff\xff\xff'
766
767= Dissect DTO TEST
768
769dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x60\xff\xff\xff\xff\xff')
770
771assert dto.ctr == 96
772assert dto.packet_id == 0xff
773assert dto.return_code == 0
774assert dto.load == b'\xff\xff\xff\xff\xff'
775# answers will interpret payload
776assert dto.answers(cro)
777assert dto.ctr == 96
778assert dto.packet_id == 0xff
779assert dto.return_code == 0
780assert hasattr(dto, "load") == True
781assert dto.load == b'\xff\xff\xff\xff\xff'
782
783= Build CRO START_STOP_ALL
784
785cro = CCP(identifier=0x700)/CRO(ctr=0x61)/START_STOP_ALL(type="start")
786
787assert cro.identifier == 0x700
788assert cro.length == 8
789assert cro.flags == 0
790assert cro.ctr == 0x61
791assert cro.cmd == 0x08
792assert cro.type == 0x01
793assert cro.ccp_reserved == b"\xff" * 5
794assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x08\x61\x01\xff\xff\xff\xff\xff'
795
796= Dissect DTO START_STOP_ALL
797
798dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x61\xff\xff\xff\xff\xff')
799
800assert dto.ctr == 97
801assert dto.packet_id == 0xff
802assert dto.return_code == 0
803assert dto.load == b'\xff\xff\xff\xff\xff'
804# answers will interpret payload
805assert dto.answers(cro)
806assert dto.ctr == 97
807assert dto.packet_id == 0xff
808assert dto.return_code == 0
809assert hasattr(dto, "load") == True
810assert dto.load == b'\xff\xff\xff\xff\xff'
811
812= Build CRO GET_ACTIVE_CAL_PAGE
813
814cro = CCP(identifier=0x700)/CRO(ctr=0x62)/GET_ACTIVE_CAL_PAGE()
815
816assert cro.identifier == 0x700
817assert cro.length == 8
818assert cro.flags == 0
819assert cro.ctr == 0x62
820assert cro.cmd == 0x09
821assert cro.ccp_reserved == b"\xff" * 6
822assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x09\x62\xff\xff\xff\xff\xff\xff'
823
824= Dissect DTO GET_ACTIVE_CAL_PAGE
825
826dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x62\x01\x11\x44\x77\x22')
827
828assert dto.ctr == 98
829assert dto.packet_id == 0xff
830assert dto.return_code == 0
831assert dto.load == b'\x01\x11\x44\x77\x22'
832# answers will interpret payload
833assert dto.answers(cro)
834assert dto.ctr == 98
835assert dto.packet_id == 0xff
836assert dto.return_code == 0
837assert hasattr(dto, "load") == False
838assert dto.address_extension == 1
839assert dto.address == 0x11447722
840
841= Build CRO GET_CCP_VERSION
842
843cro = CCP(identifier=0x700)/CRO(ctr=0x63)/GET_CCP_VERSION(main_protocol_version=2, release_version=1)
844
845assert cro.identifier == 0x700
846assert cro.length == 8
847assert cro.flags == 0
848assert cro.ctr == 0x63
849assert cro.cmd == 0x1b
850assert cro.main_protocol_version == 2
851assert cro.release_version == 1
852assert cro.ccp_reserved == b"\xff" * 4
853assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x1b\x63\x02\x01\xff\xff\xff\xff'
854
855assert dto.hashret() != cro.hashret()
856assert not dto.answers(cro)
857
858= Dissect DTO GET_CCP_VERSION
859
860dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x63\x02\x01\xff\xff\xff')
861
862assert dto.ctr == 99
863assert dto.packet_id == 0xff
864assert dto.return_code == 0
865assert dto.load == b'\x02\x01\xff\xff\xff'
866# answers will interpret payload
867assert dto.answers(cro)
868assert dto.ctr == 99
869assert dto.packet_id == 0xff
870assert dto.return_code == 0
871assert hasattr(dto, "load") == False
872assert dto.main_protocol_version == 2
873assert dto.release_version == 1
874assert dto.ccp_reserved == b"\xff" * 3
875
876assert dto.hashret() == cro.hashret()
877
878+ Tests on a virtual CAN-Bus
879
880= CAN Socket sr1 with dto.answers(cro) == True
881
882sock1 = TestSocket(CCP)
883sock2 = TestSocket(CAN)
884sock1.pair(sock2)
885
886def answer(pkt):
887    cro = CRO(pkt.data)
888    assert cro.cmd == 0x22
889    assert cro.data == b"\x10\x11\x12\x10\x11\x12"
890    sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x53\x02\x34\x00\x20\x06'))
891
892sniffer = AsyncSniffer(opened_socket=sock2, count=1, timeout=5, prn=answer)
893sniffer.start()
894dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x53)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=1, verbose=False)
895sniffer.join(timeout=5)
896sock1.close()
897sock2.close()
898
899assert dto.ctr == 83
900assert dto.packet_id == 0xff
901assert dto.return_code == 0
902assert hasattr(dto, "load") == False
903assert dto.MTA0_extension == 2
904assert dto.MTA0_address == 0x34002006
905
906= CAN Socket sr1 with dto.answers(cro) == False
907
908sock1 = TestSocket(CCP)
909sock2 = TestSocket(CAN)
910sock1.pair(sock2)
911
912def answer(pkt):
913    cro = CRO(pkt.data)
914    assert cro.cmd == 0x22
915    assert cro.data == b"\x10\x11\x12\x10\x11\x12"
916    sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x55\x02\x34\x00\x20\x06'))
917
918sniffer = AsyncSniffer(opened_socket=sock2, count=1, timeout=5, prn=answer)
919sniffer.start()
920dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x54)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=0.1, verbose=False)
921sniffer.join(timeout=5)
922sock1.close()
923sock2.close()
924assert dto is None
925
926
927= CAN Socket sr1 with error code
928
929sock1 = TestSocket(CCP)
930sock2 = TestSocket(CAN)
931sock1.pair(sock2)
932
933def answer(pkt):
934    cro = CRO(pkt.data)
935    assert cro.cmd == 0x22
936    assert cro.data == b"\x10\x11\x12\x10\x11\x12"
937    sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x01\x55\xff\xff\xff\xff\xff'))
938
939sniffer = AsyncSniffer(opened_socket=sock2, count=1, timeout=5, prn=answer)
940sniffer.start()
941dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x55)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=1, verbose=False)
942sniffer.join(timeout=5)
943sock1.close()
944sock2.close()
945
946assert dto.ctr == 85
947assert dto.packet_id == 0xff
948assert dto.return_code == 1
949assert hasattr(dto, "load") == False
950assert dto.MTA0_extension == 0xff
951assert dto.MTA0_address == 0xffffffff
952
953+ Cleanup
954
955= Delete TestSockets
956
957cleanup_testsockets()
958
959