-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.py
63 lines (54 loc) · 1.59 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import vector_dbc
db = vector_dbc.Database.load('OBDII.dbc')
print('=== Database Metadata ===')
print()
print('version_year:', db.version_year)
print('version_day:', db.version_day)
print('version_week:', db.version_week)
print('version:', db.version)
print('version_number:', db.version_number)
print('db_name:', db.db_name)
print('bus_type:', db.bus_type)
print('protocol_type:', db.protocol_type)
print('manufacturer:', db.manufacturer)
print()
print('=== End Database Metadata ===')
print()
print('=== OBDII Encoded Requests ===')
print()
for signal in db.get_message('TX').signals:
if signal.name in ('length_tx', 'mode', 'pid'):
continue
data = signal.encode()
print(signal.name + ':', data.frame_id_hex + ',', data.hex)
print()
print('=== End OBDII Encoded Requests ===')
print()
print('=== Simulated Response Frame ===')
print()
rx = db.get_message('RX')
data = dict(
mode='Live Data',
response=2,
length=3,
VehicleSpeed=200,
pid='VehicleSpeed'
)
print('encoding a test response:', data)
encoded_data = rx.encode(data)
print('encoded data:', encoded_data.frame_id_hex + ',', encoded_data.hex)
decoded_data = db.decode_message(encoded_data.frame_id, encoded_data)
response = {}
for signal in decoded_data:
value = signal.value
response[signal.name] = value
if signal.name in ('mode', 'response', 'length', 'pid'):
continue
print()
print(signal.name + ':', value, signal.unit)
print()
print('decoded test frame:', response)
print('decoded data same as test data:', data == response)
print()
print('=== End Simulated Response Frame ===')
print()