def find_records(stream, opts): records = [ ] errors = [ ] bolus = bytearray( ) extra = bytearray( ) opcode = '' for B in iter(lambda: bytearray(stream.read(2)), bytearray("")): if B == bytearray( [ 0x00, 0x00 ] ): print ("#### STOPPING DOUBLE NULLS @ %s," % stream.tell( )), nulls = eat_nulls(stream) print "reading more to debug %#04x" % B[0] print lib.hexdump(B, indent=4) print lib.int_dump(B, indent=11) extra = bytearray(stream.read(32)) print "##### DEBUG HEX" print lib.hexdump(extra, indent=4) print "##### DEBUG DECIMAL" print lib.int_dump(extra, indent=11) # print "XXX:???:XXX", history.parse_date(bolus).isoformat( ) break record = parse_record( stream, B, larger=opts.larger ) records.append(record) return records
def pformat(self, prefix=''): head = '\n'.join([ " op hex (%s)" % len(self.head), lib.hexdump(self.head, indent=4), " decimal", lib.int_dump(self.head, indent=11) ]) date = '\n'.join([ " datetime (%s)" % self.date_str( ), lib.hexdump(self.date, indent=4) ]) body = " body (%s)" % len(self.body) if len(self.body) > 0: body = '\n'.join([ body, " hex", lib.hexdump(self.body, indent=4), " decimal", lib.int_dump(self.body, indent=11) ]) extra = [ ] hour_bits = self.date[1:] and extra_hour_bits(self.date[1]) or [ ] year_bits = self.date[4:] and extra_year_bits(self.date[4]) or [ ] day_bits = self.date[3:] and extra_hour_bits(self.date[3]) or [ ] if 1 in hour_bits: extra.append("HOUR BITS: {}".format(str(hour_bits))) if 1 in day_bits: extra.append("DAY BITS: {}".format(str(day_bits))) if 1 in year_bits: extra.append("YEAR BITS: {}".format(str(year_bits))) decoded = None if len(self.head + self.date + self.body) >= self.min_length( ): decoded = self.decode( ) decode_msg = '' if decoded is not None: decode_msg = '\n'.join([ '###### DECODED', '```python', '{}'.format(lib.pformat(self.decode( ))), '```', ]) if extra: extra = ' ' + ' '.join(extra) else: extra = '' return '\n'.join([ prefix, decode_msg, head, date, body, extra ])
def find_records(stream, opts): records = [] errors = [] bolus = bytearray() extra = bytearray() opcode = '' for B in iter(lambda: bytearray(stream.read(2)), bytearray("")): if B == bytearray([0x00, 0x00]): print("#### STOPPING DOUBLE NULLS @ %s," % stream.tell()), nulls = eat_nulls(stream) print "reading more to debug %#04x" % B[0] print lib.hexdump(B, indent=4) print lib.int_dump(B, indent=11) extra = bytearray(stream.read(32)) print "##### DEBUG HEX" print lib.hexdump(extra, indent=4) print "##### DEBUG DECIMAL" print lib.int_dump(extra, indent=11) # print "XXX:???:XXX", history.parse_date(bolus).isoformat( ) break record = parse_record(stream, B, larger=opts.larger) records.append(record) return records