Created
September 24, 2021 06:49
-
-
Save projectgus/7146a2f4b252759226a58179e590b18e to your computer and use it in GitHub Desktop.
Quick script to check no CAN messages were dropped - see https://github.com/hardbyte/python-can/pull/1127
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import csv | |
import base64 | |
import re | |
import struct | |
last_counter = [None, None] | |
lines = 0 | |
with open("spammer.txt") as f: | |
for l in f: | |
lines += 1 | |
m = re.match(r'Timestamp: *([\d\.]+) *ID: ([\da-f]+) *([S]) (Rx)? *DLC: *(\d+) *([\da-f ]{23}) *Channel: (\d)', l) | |
if m: | |
timestamp, canid, idtype, _, dlc, data, channel = m.groups() | |
timestamp = int(float(timestamp) * 1e6) # to microseconds | |
dbytes = bytes.fromhex(data) | |
extended = idtype != 'S' # bit hacky | |
canid = int(canid, 16) | |
channel = int(channel) | |
# print(timestamp, channel, dbytes.hex()) | |
counter = struct.unpack("<Q", dbytes)[0] | |
if last_counter[channel] is not None: | |
if last_counter[channel] + 1 != counter: | |
print(f"Line {lines}. Channel {channel}. Expected counter {hex(last_counter[channel]+1)}, got {hex(counter)}") | |
last_counter[channel] = counter | |
print(f"Done! {lines} lines. Final counters {last_counter}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment