Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General regexp to handle more hex formats and Python3 compatibility #3

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cfetool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import serial
import sys
import re
import binascii

lineregex = re.compile(r'(?:[0-9a-f]{8})(?:[:])((?: [0-9a-f]{2}){1,16})')
#lineregex = re.compile(r'(?:[0-9a-f]{8})(?:[:])((?: [0-9a-f]{2}){1,16})(?:\s{4})(?:.{16})')
lineregex = re.compile(r'(?:[0-9a-f]{8})(?:[:])((?: [0-9a-f]*){1,16}) ')

def printf(string):
sys.stdout.write(string)
Expand All @@ -21,7 +21,7 @@ def skip_prompt(ser):
def wait_prompt(ser):
printf("Waiting for a prompt...")
while True:
ser.write("\x03")
ser.write(b"\x03")
if(ser.read(1) == 'C' and ser.read(1) == 'F' and ser.read(1) == 'E' and ser.read(1) == '>'):
skip_prompt(ser)
printf(" OK\n")
Expand All @@ -33,11 +33,13 @@ def memreadblock(ser, addr, size):
buf=''
m = False
while not m:
m = lineregex.match(ser.readline().strip())
rsp = ser.readline().strip()
m = lineregex.match(rsp)
while m:
bytes = [chr(int(x, 16)) for x in m.group(1)[1:].split(' ')]
bytes = [binascii.unhexlify(x) for x in m.group(1)[1:].split(' ')]
buf+=''.join(bytes)
m = lineregex.match(ser.readline().strip())
rsp = ser.readline().strip()
m = lineregex.match(rsp.strip())
return buf

def memreadblock2file(ser, fd, addr, size):
Expand Down