添加接收机子项目
This commit is contained in:
29
rx/hex2bin.py
Normal file
29
rx/hex2bin.py
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Convert Intel HEX to binary"""
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: hex2bin.py <input.hex> <output.bin>")
|
||||
sys.exit(1)
|
||||
|
||||
with open(sys.argv[1], 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
data = bytearray()
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line or line[0] != ':':
|
||||
continue
|
||||
count = int(line[1:3], 16)
|
||||
rtype = int(line[7:9], 16)
|
||||
if rtype == 0: # Data record
|
||||
for i in range(count):
|
||||
byte_val = int(line[9+i*2:11+i*2], 16)
|
||||
data.append(byte_val)
|
||||
elif rtype == 1: # EOF
|
||||
break
|
||||
|
||||
with open(sys.argv[2], 'wb') as f:
|
||||
f.write(data)
|
||||
|
||||
print(f"Binary: {len(data)} bytes")
|
||||
Reference in New Issue
Block a user