Skip to content

Instantly share code, notes, and snippets.

@Wh1terat
Created May 16, 2022 11:44
Show Gist options
  • Save Wh1terat/6b4ae28a169652f5ef73d12b888ed39e to your computer and use it in GitHub Desktop.
Save Wh1terat/6b4ae28a169652f5ef73d12b888ed39e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import zlib
import json
signals = []
with open(sys.argv[1], "rb") as data:
fver = data.readline().decode('utf-8').strip()
sn = data.readline().decode('utf-8').strip()
unitsn = zlib.decompress(data.read(int.from_bytes(data.read(2), "big"))).decode(
"utf-8"
)
entries = int.from_bytes(data.read(2), "big")
for _ in range(entries):
chunk = zlib.decompress(data.read(int.from_bytes(data.read(2), "big"))).decode(
"utf-8"
)
arr = chunk.split(",")
canSignal = {
"name": arr[0],
"units": arr[2],
"identifier": int(arr[1]) & 0x7FFFFFFF,
"extended": True if ((int(arr[1]) & 0x80000000) == 0x80000000) else False,
"startBit": int(arr[3]),
"length": int(arr[4]),
"offset": float(arr[5]),
"scale": float(arr[6]),
"maximum": float(arr[7]),
"minimum": float(arr[8]),
"dataFormat": arr[9].lower(),
"byteOrder": arr[10].lower(),
}
if canSignal["byteOrder"] == "motorola":
canSignal["startBit"] += 56 - int(arr[3]) / 8 * 16
if fver.endswith('a'):
canSignal['dataLengthCode'] = int(arr[11])
signals.append(canSignal)
print(json.dumps(signals, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment