Last active
May 11, 2023 20:33
-
-
Save jagotu/a9773c9d1d37f8ff837a163f92dfd099 to your computer and use it in GitHub Desktop.
use the same output format as rfid raw_analyze
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 sys | |
import struct | |
import io | |
def varint(f): | |
shift = 0 | |
result = 0 | |
while True: | |
i = f.read(1)[0] | |
result |= (i & 0x7f) << shift | |
shift += 7 | |
if not (i & 0x80): | |
break | |
return result | |
def r32(f): | |
return struct.unpack('I', f.read(4))[0] | |
def rf(f): | |
return struct.unpack('f', f.read(4))[0] | |
with open(sys.argv[1], 'rb') as f: | |
assert(f.read(4) == b'RIFL') #magic | |
assert(r32(f) == 1) #version | |
frequency = rf(f) | |
duty_cycle = rf(f) | |
max_buffer_size = r32(f) | |
#print("frequencey", frequency) | |
#print("duty_cycle", duty_cycle) | |
#print("max_buffer_size", max_buffer_size) | |
smp = 0 | |
while True: | |
a = f.read(4) | |
if len(a) != 4: | |
break | |
bufferlength = struct.unpack('I', a)[0] | |
buffer = f.read(bufferlength) | |
bio = io.BytesIO(buffer) | |
while bio.tell() < len(buffer): | |
pulse = varint(bio) | |
duration = varint(bio) | |
print("[%d %d]\t[%d %d]" % (pulse, duration, pulse, duration-pulse)) | |
#print("0"*pulse + "1"*(duration-pulse), end='') | |
#i | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment