From c7c379c9436accf3ee222bc58388039561618eed Mon Sep 17 00:00:00 2001 From: Ircama Date: Tue, 25 Jul 2023 01:48:19 +0200 Subject: [PATCH] Add eeprom dump --- README.md | 5 ++++- epson_print_conf.py | 39 +++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c9fadf0..382ddbd 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ cd epson_print_conf ``` usage: epson_print_conf.py [-h] -m MODEL -a HOSTNAME [-i] [--reset_waste_ink] [--brute-force-read-key] [-d] - [--dry-run] [--write-first-ti-received-time FTRT FTRT FTRT] + [-e DUMP_EEPROM DUMP_EEPROM DUMP_EEPROM] [--dry-run] + [--write-first-ti-received-time FTRT FTRT FTRT] optional arguments: -h, --help show this help message and exit @@ -26,6 +27,8 @@ optional arguments: --brute-force-read-key Detect the read_key via brute force -d, --debug Print debug information + -e DUMP_EEPROM DUMP_EEPROM DUMP_EEPROM, --eeprom-dump DUMP_EEPROM DUMP_EEPROM DUMP_EEPROM + Dump EEPROM (arguments: extension, start, stop) --dry-run Dry-run change operations --write-first-ti-received-time FTRT FTRT FTRT Change the first TI received time (year, month, day) diff --git a/epson_print_conf.py b/epson_print_conf.py index d5cc288..bca5ca5 100644 --- a/epson_print_conf.py +++ b/epson_print_conf.py @@ -13,15 +13,6 @@ import time class EpsonPrinter: """Known Epson models""" PRINTER_MODEL = { - "L355": { - "read_key": [65, 9], - # to be completed - }, - "L4160": { - "read_key": [73, 8], - "write_key": b'Arantifo', - # to be completed - }, "XP-205": { "read_key": [25, 7], "write_key": b'Wakatobi', @@ -48,6 +39,15 @@ class EpsonPrinter: "last_printer_fatal_errors": [60, 203, 204, 205, 206], "last_printer_fatal_err_ext": [211], }, + "L355": { + "read_key": [65, 9], + # to be completed + }, + "L4160": { + "read_key": [73, 8], + "write_key": b'Arantifo', + # to be completed + }, "XP-315": { "read_key": [129, 8], "write_key": b'Wakatobi', @@ -281,11 +281,11 @@ class EpsonSession(easysnmp.Session): except Exception as e: raise ValueError(str(e)) - def dump_eeprom(self, start: int = 0, end: int = 0xFF): + def dump_eeprom(self, ext: str="0", start: int = 0, end: int = 0xFF): """Dump EEPROM data from start to end.""" d = {} for oid in range(start, end): - d[oid] = int(self.read_eeprom(oid), 16) + d[oid] = int(self.read_eeprom(oid, ext), 16) return d def get_sys_info(self) -> str: @@ -637,6 +637,14 @@ if __name__ == "__main__": dest='debug', action='store_true', help='Print debug information') + parser.add_argument( + '-e', + '--eeprom-dump', + dest='dump_eeprom', + action='store', + type=int, + nargs=3, + help='Dump EEPROM (arguments: extension, start, stop)') parser.add_argument( '--dry-run', dest='dry_run', @@ -645,7 +653,7 @@ if __name__ == "__main__": parser.add_argument( '--write-first-ti-received-time', dest='ftrt', - type=int, + type=int, help='Change the first TI received time (year, month, day)', nargs=3, ) @@ -665,6 +673,13 @@ if __name__ == "__main__": if args.ftrt: printer.session.write_first_ti_received_time( int(args.ftrt[0]), int(args.ftrt[1]), int(args.ftrt[2])) + if args.dump_eeprom: + for addr, val in printer.session.dump_eeprom( + str(args.dump_eeprom[0] % 256), + args.dump_eeprom[1] % 256, + int(args.dump_eeprom[2] % 256 + 1) + ).items(): + print(f"{str(addr).rjust(3)}: {val:#04x} = {str(val).rjust(3)}") if args.info: pprint(printer.stats) except TimeoutError as e: