def run(self): hx = hxtool.get(self.args) if hx is None: return 10 if not hx.comm.cp_mode: logger.critical( "For GPS log functions, device must be in CP mode (MENU + ON)") return 10 result = 0 hx.gps.send("$PMTK", ["605"]) # Query GPS module firmware version _ = hx.gps.receive() stat = hx.gps.read_log_status() logger.info(f"Log size {stat['pages_used'] * 4}kB, " f"{stat['slots_used']} trackpoints, " f"{stat['usage_percent']}% full") if stat["full_stop"]: logger.warning("Log is full. Logging is halted until erased") elif stat['usage_percent'] >= 80: logger.warning("Log is almost full. Consider erasing soon") if self.args.gpx or self.args.json or self.args.raw or self.args.print: if stat["slots_used"] > 0 or self.args.raw: logger.info("Reading GPS log from handset") raw_log_data = hx.gps.read_log(progress=True) logger.info( f"Received {len(raw_log_data)} bytes of raw log data from handset" ) else: logger.info("Nothing to read from handset") raw_log_data = None else: raw_log_data = None if self.args.print: result = max(dump_log(raw_log_data), result) if self.args.gpx: logger.info("Exporting GPX log data to `%s`", self.args.gpx) result = max(write_gpx(raw_log_data, self.args.gpx), result) if self.args.json: logger.info("Exporting JSON log data to `%s`", self.args.json) result = max(write_json(raw_log_data, self.args.json), result) if self.args.raw: logger.info("Exporting raw log data to `%s`", self.args.raw) result = max(write_raw(raw_log_data, self.args.raw), result) if self.args.erase: logger.info("Erasing GPS log data from device") hx.gps.erase_log() return result
def run(self): hx = hxtool.get(self.args) if hx is None: return 10 if hx.cp_mode: logger.error("Handset in CP mode, reboot to regular mode") return 10 try: print_nmea(hx) except KeyboardInterrupt: pass return 0
def run(self): hx = hxtool.get(self.args) if hx is None: return 10 if not hx.comm.cp_mode: logger.critical("Handset not in CP mode (MENU + ON)") return 11 if self.args.atis is None and self.args.mmsi is None and not self.args.reset: mmsi, mmsi_status = hx.config.read_mmsi() atis, atis_status = hx.config.read_atis() print(f"MMSI: {mmsi} [{mmsi_status}]") print(f"ATIS: {atis} [{atis_status}]") return 0 if self.args.reset: try: logger.info("Resetting MMSI") hx.config.write_mmsi() logger.info("Resetting ATIS") hx.config.write_atis() except ProtocolError as e: logger.error(e) return 12 if self.args.atis is not None: try: logger.info(f"New ATIS `{self.args.atis}`") hx.config.write_atis(self.args.atis) except ProtocolError as e: logger.error(e) return 13 if self.args.mmsi is not None: try: logger.info(f"New MMSI `{self.args.mmsi}`") hx.config.write_mmsi(self.args.mmsi) except ProtocolError as e: logger.error(e) return 14 logger.info("Operation successful") return 0
def run(self): hx = hxtool.get(self.args) if hx is None: return 10 if not hx.comm.cp_mode: logger.critical("Handset not in CP mode (MENU + ON)") return 11 if self.args.dump is None and self.args.flash is None: logger.critical("Specify --dump or --flash") return 10 ret = 0 if self.args.dump is not None: # TODO: warn on flash ID mismatch with open(self.args.dump, "wb") as f: logger.info("Reading config flash from handset") try: data = hx.config.config_read(progress=True) logger.info(f"Writing config to `{self.args.dump}`") f.write(data) except ProtocolError as e: logger.error(e) ret = 10 if self.args.flash is not None: # TODO: add --really safeguard on flash ID mismatch with open(self.args.flash, "rb") as f: logger.info(f"Reading config data from `{self.args.flash}`") data = f.read() logger.info("Writing config to handset") try: hx.config.config_write(data, progress=True) except ProtocolError as e: logger.error(e) ret = 10 if ret == 0: logger.info("Operation successful") return ret
def config_write(config): h = hxtool.get(HxToolArgs()) try: if not h.comm.cp_mode: raise Exception("not in CP mode (region mismatch?)") h.comm.sync() fw = h.comm.get_firmware_version() except Exception as exc: print( "Could not open connection to HX870." ) sys.exit(1) print( "Firmware " + fw + " installed on device" ) sys.stdout.write( "Writing to HX870 memory " ) sys.stdout.flush() try: h.config.set_progress_callback(progress_bar) config = h.config.config_write(config) except Exception as exc: print( " Error!" ) raise exc print( " done" )
def config_read(): h = hxtool.get(HxToolArgs()) try: if not h.comm.cp_mode: raise Exception("not in CP mode (region mismatch?)") h.comm.sync() mmsi = h.config.read_mmsi()[0] except Exception as exc: print("Could not open connection to HX870.") sys.exit(1) print("Device MMSI " + (mmsi if mmsi != "ffffffffff" else "not set")) sys.stdout.write("Reading HX870 memory ") sys.stdout.flush() try: h.config.set_progress_callback(progress_bar) config = h.config.config_read() except Exception as exc: print(" Error!") raise exc print(" done") return config
def run(self): hx = hxtool.get(self.args) if hx is None: return 10 print(f"Model:\t{hx.brand} {hx.model}") print(f"Handle:\t{hx.handle}") print(f"Manufacturer:\t{hx.usb_vendor_name}") print(f"Serial device:\t{hx.tty}") if not hx.comm.cp_mode: logger.warning("For firmware and config information, device must be in CP mode (MENU + ON)") return 0 fw = hx.comm.get_firmware_version() print(f"Firmware version: {fw}") fid = hx.comm.get_flash_id() if not hx.check_flash_id(): logger.warning(f"Flash ID mismatch. {fid} not in {hx.flash_id}") print(f"Flash ID:\t{fid}") region_code = ord(hx.comm.read_config_memory(0x010f, 1)) # TODO: move to config region = region_code_map[region_code] print(f"Region:\t{region} [{region_code:02x}]") mmsi, mmsi_status = hx.config.read_mmsi() print(f"MMSI:\t{mmsi}") print(f"MMSI status:\t{mmsi_status}") atis_enabled_code = ord(hx.comm.read_config_memory(0x00a2, 1)) # TODO: mode to config atis_enabled = "ENABLED" if atis_enabled_code == 1 else "DISABLED" print(f"ATIS function:\t{atis_enabled} [{atis_enabled_code:02x}]") atis, atis_status = hx.config.read_atis() print(f"ATIS:\t{atis}") print(f"ATIS status:\t{atis_status}") return 0