-def inquire_connection(dev):
- packed = pack_pkt(INQ_CMD, "")
- dev.send_data(packed)
- info = dev.recv_data(7)
- #print(info)
- if info == bytearray(b'\x00') or info == bytearray(b''):
- return False
- msg = unpack_pkt(info)
- print("Connection already established")
- #print(msg)
- return True
+def hex_type(string):
+ try:
+ value = int(string, 16)
+ return value
+ except ValueError:
+ raise argparse.ArgumentTypeError(f"'{string}' is not a valid hexadecimal value.")
+
+def set_size_boundaries(start_addr, size):
+ if start_addr % SECTOR_SIZE:
+ raise ValueError(f"start addr not aligned on sector size {SECTOR_SIZE}")
+
+ if size < SECTOR_SIZE:
+ print("Warning: you are trying to write something that is less than one sector size: padding with zeroes")
+
+ blocks = (size + SECTOR_SIZE - 1) // SECTOR_SIZE
+ end_addr = blocks * SECTOR_SIZE + start_addr - 1
+
+ if (end_addr <= start_addr):
+ raise ValueError(f"End address smaller or equal than start_address")
+
+ if (end_addr > 0x3FFFF):
+ raise ValueError(f"Binary file is bigger than available ROM space")
+
+ return (start_addr, end_addr)