def ecr_log(data, incoming=False): try: if incoming: incoming = '<' else: incoming = '>' if is_stringlike(data): data = bs2hl(data) # logit to the logfile try: _logfile.write('%s %s\n' % (incoming, toHexString(data))) except Exception: pass try: data = repr(parse_represented_data(data)) _logfile.write('= %s\n' % data) except Exception as e: print('DEBUG: Cannot be represented: %s' % data) print(e) _logfile.write('? did not understand ?\n') data = toHexString(data) print('%s %s' % (incoming, data)) except Exception: import traceback traceback.print_exc() print('| error in log')
def ecr_log(data, incoming=False): try: if incoming: incoming = '<' else: incoming = '>' if isinstance(data, basestring): data = conv.bs2hl(data) # logit to the logfile try: _logfile.write('%s %s\n' % (incoming, conv.toHexString(data))) except: pass try: data = repr(parse_represented_data(data)) _logfile.write('= %s\n' % data) except Exception as e: print("DEBUG: Cannot be represented: %s" % data) print(e) _logfile.write('? did not understand ?\n') data = conv.toHexString(data) print("%s %s" % (incoming, data)) except: import traceback traceback.print_exc() print("| error in log")
def std_serial_log(instance, data, incoming=False): try: if is_stringlike(incoming): data = bs2hl(data) if incoming: print('< %s' % toHexString(data)) else: print('> %s' % toHexString(data)) except Exception: print('| error in log')
def std_serial_log(instance, data, incoming=False): try: if isinstance(incoming, basestring): data = conv.bs2hl(data) if incoming: print "< %s" % conv.toHexString(data) else: print "> %s" % conv.toHexString(data) except: print "| error in log"
def std_serial_log(instance, data, incoming=False): try: if is_stringlike(incoming): data = conv.bs2hl(data) if incoming: print("< %s" % conv.toHexString(data)) else: print("> %s" % conv.toHexString(data)) except: print("| error in log")
def __repr__(self): bitmap_stati = [{b._key: b.value()} for b in self.bitmaps] introspection = self.introspect_fixed() if introspection: introspection = '*%s **%s' % (introspection, bitmap_stati) else: introspection = '**%s' % bitmap_stati return '%s{%s %s} %s' % (self.__class__.__name__, toHexString([self.cmd_class]), toHexString([self.cmd_instr]), introspection)
def __repr__(self): bitmap_stati = [ {b._key: b.value()} for b in self.bitmaps ] introspection = self.introspect_fixed() if introspection: introspection = '*%s **%s' % (introspection, bitmap_stati) else: introspection = '**%s' % bitmap_stati return "%s{%s %s} %s" % (self.__class__.__name__, conv.toHexString([self.cmd_class]), conv.toHexString([self.cmd_instr]), introspection)
def test_all_packets(self): """ create packets, dump their binary data and try to find them out again! """ PACKETS = Packets.packets.values() for packet in PACKETS: rep = parse_represented_data(conv.toHexString(packet().to_list())) self.assertEqual(rep.__class__, packet)
def test_all_packets(self): """ Create packets, dump their binary data and compare them to their expected versions. """ PACKETS = Packets.packets.values() for packet in PACKETS: rep = parse_represented_data(conv.toHexString(packet().to_list())) self.assertEqual(rep.__class__, packet)
def ecr_log(data, incoming=False): try: if incoming: incoming = '<' else: incoming = '>' if isinstance(data, basestring): data = conv.bs2hl(data) # logit to the logfile try: _logfile.write('%s %s\n' % (incoming, conv.toHexString(data))) except: pass try: data = repr(parse_represented_data(data)) _logfile.write('= %s\n' % data) except Exception, e: print "DEBUG: Cannot be represented: %s" % data print e _logfile.write('? did not understand ?\n') data = conv.toHexString(data) print "%s %s" % (incoming, data)
def consume_fixed(self, data, length): if length < 4: raise Exception, "Registration needs at least 4 bytes." if length >= 4: # only password and byte # no cc self.fixed_values['password'] = ''.join([conv.toHexString([c]) for c in data[0:3]]) self.fixed_values['config_byte'] = data[3] if length >= 6: self.fixed_values['cc'] = data[4:6] # rest is bitmaps if length > 6: return data[6:] return []
def consume_fixed(self, data, length): if length: self.fixed_values['password'] = ''.join( [toHexString([c]) for c in data[0:3]]) return data[3:]
def __repr__(self): return 'PacketReceivedERROR{84 %s}: %s' % ( toHexString([self.error_code]), ERRORCODES.get(self.error_code, 'Unknown Error'), )
def __repr__(self): return "SerialMessage (APDU: %s, CRC-L: %s CRC-H: %s)" % ( conv.toHexString(self.apdu), hex(self.crc_l), hex(self.crc_h))
def list_of_bytes(apdu): sm = SerialMessage(apdu) byte_list = sm.dump_message() #return " ".join(["%02h" % i for i in byte_list]) return conv.toHexString(byte_list)
def __repr__(self): return "PacketReceivedERROR{84 %s}: %s" % ( conv.toHexString([self.error_code]), common.ERRORCODES.get(self.error_code, 'Unknown Error'), )
def consume_fixed(self, data, length): if length: self.fixed_values['password'] = ''.join([conv.toHexString([c]) for c in data[0:3] ]) return data[3:]