Created
October 4, 2017 14:35
-
-
Save appleguru/97f74c1235f55a28c4d8ba3a19ab7c92 to your computer and use it in GitHub Desktop.
Decode UDP streaming data from panda
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
import struct | |
import binascii | |
import csv | |
with open('output.bin', mode='rb') as file: # b is important -> binary | |
dat = file.read() | |
ret = [] | |
for j in range(0, len(dat), 0x10): | |
ddat = dat[j:j+0x10] | |
f1, f2 = struct.unpack("II", ddat[0:8]) | |
extended = 4 | |
if f1 & extended: | |
address = f1 >> 3 | |
else: | |
address = f1 >> 21 | |
frame = f2>>16 | |
data = ddat[8:8+(f2&0xF)] | |
data_text = binascii.hexlify(data) | |
bus = (f2>>4)&0xFF | |
ret.append((address, frame, data_text, bus)) | |
with open("output.csv", "wb") as f: | |
writer = csv.writer(f) | |
writer.writerows(ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment