def set_data(self, blob): # setting the data of a packet means, it is parsed actually. # note: data does NOT containt cmd_class, cmd_instr anymore! # however, it DOES contain the LENGTH # now we introspect data pos = 0 bitmaps = [] if blob[pos] == 0xff: # length field is next two bytes. # @todo: could be wrong: l = (blob[pos + 1] << 8) + blob[pos + 2] pos += 2 # consume 2 bytes. else: l = blob[pos] pos += 1 # we move one byte further in all cases. # now we should read our data ahead to length. # look ahead if we have enough data. if len(blob) >= pos + l: data = blob[pos:pos + l] else: raise self.NotEnoughData, "Not enough Data to create the packet data." # step 1: fixed arguments. ## if this packet has some fixed arguments, they have to be ## parsed first. data = self.consume_fixed(data, l) # step 2: bitmaps. while data: bmp, data = BMP.read_stream(data) bitmaps += [bmp] self.bitmaps = bitmaps
# -*- coding: utf-8 -*- """ Implements all known Bitmaps in two Dictionaries: BITMAPS is keyed after the CODE of the bitmap in the protocol. use this if you know "the code" of the bitmap and retrieve its class, keyname (and description) BITMAPS_ARGS is created from BITMAPS, representing bitmaps in a key-value-store. use this if you know "the key name" of the bitmap and want to get its class, code (and description) """ from ecrterm.packets.bmp import BMP BITMAPS = { 0x01 : (BMP.FormatByte(1), 'timeout', "binary time-out"), 0x02 : (BMP.FormatByte(1), 'max_status_infos', "binary max.status infos"), 0x03 : (BMP.FormatByte(1), 'service_byte', "binary service-byte"), 0x04 : (BMP.FormatBCDByte(6), 'amount', "Amount"), 0x05 : (BMP.FormatByte(1), 'pump_nr', "binary pump-Nr."), 0x06 : (BMP.FormatTLV(), 'tlv', "TLV"), 0x0B : (BMP.FormatBCDByte(3), 'trace_number', "trace-number"), 0x0C : (BMP.FormatBCDByte(3), 'time', "Time"), 0x0D : (BMP.FormatBCDByte(2), 'date_day', "date, MM DD (see AA)"), 0x0E : (BMP.FormatBCDByte(2), 'card_expire', "expiry-date, YY MM"), 0x17 : (BMP.FormatBCDByte(2), 'card_sequence_number', "card sequence-number"), 0x19 : (BMP.FormatByte(1), 'type', "binary status-byte/payment-type/card-type"), 0x22 : (BMP.FormatLLVAR(), 'card_number', "card_number, PAN / EF_ID, 'E' used to indicate masked numeric digit"), 0x23 : (BMP.FormatLLVAR(), 'track_2', "track 2 data, 'E' used to indicate masked numeric digit1"), 0x24 : (BMP.FormatLLLVAR(), 'track_3', "track 3 data, 'E' used to indicate masked numeric digit1"), 0x27 : (BMP.FormatByte(1), 'result_code', "binary result-code"),
# -*- coding: utf-8 -*- """ Implements all known Bitmaps in two Dictionaries: BITMAPS is keyed after the CODE of the bitmap in the protocol. use this if you know "the code" of the bitmap and retrieve its class, keyname (and description) BITMAPS_ARGS is created from BITMAPS, representing bitmaps in a key-value-store. use this if you know "the key name" of the bitmap and want to get its class, code (and description) """ from ecrterm.packets.bmp import BMP BITMAPS = { 0x01: (BMP.FormatByte(1), 'timeout', 'binary time-out'), 0x02: (BMP.FormatByte(1), 'max_status_infos', 'binary max.status infos'), 0x03: (BMP.FormatByte(1), 'service_byte', 'binary service-byte'), 0x04: (BMP.FormatBCDByte(6), 'amount', 'Amount'), 0x05: (BMP.FormatByte(1), 'pump_nr', 'binary pump-Nr.'), 0x06: (BMP.FormatTLV(), 'tlv', 'TLV'), 0x0B: (BMP.FormatBCDByte(3), 'trace_number', 'trace-number'), 0x0C: (BMP.FormatBCDByte(3), 'time', 'Time'), 0x0D: (BMP.FormatBCDByte(2), 'date_day', 'date, MM DD (see AA)'), 0x0E: (BMP.FormatBCDByte(2), 'card_expire', 'expiry-date, YY MM'), 0x17: (BMP.FormatBCDByte(2), 'card_sequence_number', 'card sequence-number'), 0x19: (BMP.FormatByte(1), 'type', 'binary status-byte/payment-type/card-type'), 0x22: (BMP.FormatLLVAR(), 'card_number', 'card_number, PAN / EF_ID, \'E\' used to indicate masked numeric '