diff options
author | Brett Weiland <brett_weiland@bpcsapce.com> | 2023-01-12 13:41:48 -0600 |
---|---|---|
committer | Brett Weiland <brett_weiland@bpcsapce.com> | 2023-01-12 13:41:48 -0600 |
commit | b666668d0e6b67e4632e65486cae814ab5abbc39 (patch) | |
tree | 0cf0c2d689799c5e98d505e632248fdc5ed5a072 /src/write_eeprom.py | |
parent | 94304b11e7220f060dbc345de5fa1952d0465016 (diff) |
updating for linkedin
Diffstat (limited to 'src/write_eeprom.py')
-rwxr-xr-x | src/write_eeprom.py | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/write_eeprom.py b/src/write_eeprom.py index e0a8604..b0c2594 100755 --- a/src/write_eeprom.py +++ b/src/write_eeprom.py @@ -22,55 +22,83 @@ eeprom_file = open("./compiled_eeprom", "rb") eeprom_filesize = os.fstat(eeprom_file.fileno()).st_size page_len = ceil(eeprom_filesize / EEPROM_PAGESIZE) -s = serial.Serial(port=args.port, baudrate=args.baud, parity=serial.PARITY_NONE, timeout=0, dsrdtr=1) +s = serial.Serial(port=args.port, baudrate=args.baud, parity=serial.PARITY_NONE, timeout=0, rtscts=0, dsrdtr=0, write_timeout = 0) +s.rts = 0 #slow method def write_hwf(data): + #check if the other guy is already trying to send debugval = 0 print("writing") data_parsed = [data[b:b+1] for b in range(len(data))] for c in data_parsed: print(debugval) + if s.cts: + print("Slave is trying to send before we do!") + exit(1) debugval += 1 s.rts = 1 while not s.cts: pass - s.rts = 0 s.write(c) + while s.cts: + pass + s.rts = 0 + print("done writing") def read_hwf(length): print("reading") msg = b'' for c in range(length): - s.rts = 1 + print("waiting for CTS") while not s.cts: pass - s.rts = 0 + s.rts = 1 msg += s.read(size=1) + s.rts = 0 + print("waiting for CTS to go back up, recieved {}".format(msg)) + while s.cts: + pass + print("done reading") return(msg) -def handle_writer_error(write_status): - if write_status == 1: # verification failed - print("Verification failed on page {}!".format(page)) - elif write_status == 0xff: - print("Unknown error writing page {}!".format(page)) +#def handle_writer_error(write_status): #while True: # write_hwf(b"abcdef\r\n") # print(read_hwf(10)) +input() +blah = 0 +tots_blah = 0 +while True: + tots_blah += 1 + print("PACKET {}".format(tots_blah)) + if blah > 8: + blah = 0 + blah += 1 + write_hwf(bytes("Debugstr {}\r\n".format(blah), 'UTF-8')) + print(read_hwf(12)) + +print(page_len) write_hwf(page_len.to_bytes(1, 'little')) + for page in range(0, page_len): - print(page) + print("PAGE: {}".format(page)) if EEPROM_PAGESIZE > (eeprom_filesize - eeprom_file.tell()): + print("writing and padding last page") write_hwf(eeprom_file.read()) [write_hwf(b'\x00') for b in range(0, eeprom_filesize % EEPROM_PAGESIZE)] else: write_hwf(eeprom_file.read(EEPROM_PAGESIZE)) - write_status = read_hwf(1) + write_status = int(read_hwf(1)) print("WRITE STATUS: {}".format(write_status)) - if not write_status == 0: - handle_writer_error(write_status) + if write_status == 0: + pass + elif write_status == 1: # verification failed + print("Verification failed on page {}!".format(page)) + elif write_status == 0xff: + print("Unknown error writing page {}!".format(page)) print("Done writing to EEPROM!\n") |