def get_file_metadata_by_idx(self, file_idx: int, options: int = 0) \ -> Dict[str, Any]: logger(__name__).debug('Sending ext 0x17 command') tx_payload = struct.pack("<2B", file_idx, options) rx = self._txrx_ext_struct(0x17, tx_payload, "<B3l4sll24s") rx = dict( zip([ 'idx', 'size', 'addr', 'crc', 'type', 'timestamp', 'version', 'filename' ], rx)) rx['type'] = decode_bytes_to_str(rx['type']) rx['timestamp'] = datetime(2000, 1, 1) + timedelta(seconds=rx['timestamp']) rx['filename'] = decode_bytes_to_str(rx['filename']) logger(__name__).debug('Completed ext 0x17 command') return rx
def get_file_metadata_by_name(self, file_name: str, vid: int_str = 1, options: int = 0) \ -> Dict[str, Any]: logger(__name__).debug('Sending ext 0x19 command') if isinstance(vid, str): vid = self.vid_map[vid.lower()] tx_payload = struct.pack("<2B24s", vid, options, file_name.encode(encoding='ascii')) rx = self._txrx_ext_struct(0x19, tx_payload, "<x3l4sll24s") rx = dict( zip([ 'size', 'addr', 'crc', 'type', 'timestamp', 'version', 'linked_filename' ], rx)) rx['type'] = decode_bytes_to_str(rx['type']) rx['timestamp'] = datetime(2000, 1, 1) + timedelta(seconds=rx['timestamp']) rx['linked_filename'] = decode_bytes_to_str(rx['linked_filename']) logger(__name__).debug('Completed ext 0x19 command') return rx
def reader(self): if self.request_banner: try: self.device.write(b'pRb') except Exception as e: logger(__name__).exception(e) try: while not self.alive.is_set() and self._reader_alive: data = self.device.read() if not data: continue if data[0] == b'sout': text = decode_bytes_to_str(data[1]) elif data[0] == b'serr': text = '{}{}{}'.format(colorama.Fore.RED, decode_bytes_to_str(data[1]), colorama.Style.RESET_ALL) elif data[0] == b'kdbg': text = '{}\n\nKERNEL DEBUG:\t{}{}\n'.format( colorama.Back.GREEN + colorama.Style.BRIGHT, decode_bytes_to_str(data[1]), colorama.Style.RESET_ALL) elif data[0] != b'': text = '{}{}'.format(decode_bytes_to_str(data[0]), decode_bytes_to_str(data[1])) else: text = "{}".format(decode_bytes_to_str(data[1])) self.console.write(text) except UnicodeError as e: logger(__name__).exception(e) except PortConnectionException: logger(__name__).warning( f'Connection to {self.device.name} broken') if not self.alive.is_set(): self.stop() except Exception as e: if not self.alive.is_set(): logger(__name__).exception(e) else: logger(__name__).debug(e) self.stop() logger(__name__).info('Terminal receiver dying')