Skip to content

Instantly share code, notes, and snippets.

@LarryRuane
Created May 16, 2023 23:07
Show Gist options
  • Save LarryRuane/06a7aa0b4da902fb5ae7a736dc92d852 to your computer and use it in GitHub Desktop.
Save LarryRuane/06a7aa0b4da902fb5ae7a736dc92d852 to your computer and use it in GitHub Desktop.
temporary script to turn logging lines into binary
#!/bin/env python3
import sys
from struct import pack
if len(sys.argv) != 2:
print("usage:", sys.argv[0], "file")
sys.exit(1)
bitoffset = 0
v = 0
f = open(sys.argv[1], 'r')
for line in f:
if line[30:34] != 'LMR ': continue
for c in line[34:-1]:
assert c == 'F' or c == '.'
v = (v << 1) + (1 if c == 'F' else 0)
bitoffset += 1
if bitoffset == 8:
sys.stdout.buffer.write(pack('B', v))
v = 0
bitoffset = 0
# exactly how many of these last 8 bits are valid
# won't be known, but that's okay
sys.stdout.buffer.write(pack('B', v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment