X-Git-Url: https://robinkrens.nl/gitweb/?a=blobdiff_plain;f=src%2FRAConnect.py;h=fb2a33404b1c0b3c338fb0782bc917bdd8554a3b;hb=c072efbf71180e056352c4b42a6249fa9601bde8;hp=15a54a475620c76691e89d3f237286ed943c4770;hpb=f969a6fb10665bcaf1432b56234e60197c26a54a;p=renesas-ra-flasher diff --git a/src/RAConnect.py b/src/RAConnect.py index 15a54a4..fb2a334 100644 --- a/src/RAConnect.py +++ b/src/RAConnect.py @@ -3,6 +3,8 @@ import time import usb.core import usb.util +MAX_TRANSFER_SIZE = 64 + class RAConnect: def __init__(self, vendor_id, product_id): self.vendor_id = vendor_id @@ -64,14 +66,43 @@ class RAConnect: print(f"Timeout: retry #{i}", e) return False -# Usage -communicator = RAConnect(vendor_id=0x1a86, product_id=0x7523) + def authenticate_connection(self): + raise Exception("Not implemented") + + def send_data(self, packed_data): + if (self.tx_ep == None): + return False + try: + self.tx_ep.write(packed_data, self.timeout_ms) + except usb.core.USBError as e: + print(f"Timeout: error", e) + return False + return True + + # packets are length 7, except for a read package + def recv_data(self, exp_len): + if (exp_len > MAX_TRANSFER_SIZE): + raise ValueError(f"length package {exp_len} over max transfer size") + if (self.rx_ep == None): + return False + try: + msg = self.rx_ep.read(exp_len, self.timeout_ms) + except usb.core.USBError as e: + print(f"Timeout: error", e) + return False + return msg + + +#communicator = RAConnect(vendor_id=0x1a86, product_id=0x7523) -if not communicator.establish_connection(): - print("Cannot connect") - sys.exit(0) +#communicator.send_data(b'\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA') +#communicator.recv_data(7) -if not communicator.confirm_connection(): - print("Failed to confirm boot code") - sys.exit(0) +#if not communicator.establish_connection(): +# print("Cannot connect") +# sys.exit(0) +# +#if not communicator.confirm_connection(): +# print("Failed to confirm boot code") +# sys.exit(0)