From: David Adam Date: Sat, 9 Apr 2011 03:29:12 +0000 (+0000) Subject: MIFARE: better logging, thanks to [TRS] I think X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=1dbac750026cfc6886c6bfd9139a4a87fa61b016;p=zanchey%2Fdispense2.git MIFARE: better logging, thanks to [TRS] I think --- diff --git a/sql-edition/servers/MIFAREDriver.py b/sql-edition/servers/MIFAREDriver.py index a3a65b6..46a0731 100644 --- a/sql-edition/servers/MIFAREDriver.py +++ b/sql-edition/servers/MIFAREDriver.py @@ -7,7 +7,7 @@ Requires Python 2.5. Licensed under an MIT-style license: see LICENSE file for details. ''' -import serial +import serial, logging xor = lambda x, y: x ^ y def checksum(string): @@ -111,7 +111,12 @@ class MIFAREReader: serial = self.send_packet(command)[3:] # Select the card for use - capacity = ord(self.send_packet('\x03\x02' + serial)[3]) + try: + select_response = self.send_packet('\x03\x02' + serial) + capacity = ord(select_response[3]) + except IndexError: + logging.warning('Tried to select card but failed: card_type %s, serial %s, select_response %s' % (card_type.__repr__(), serial.__repr__(), select_response.__repr__())) + capacity = 0 return (serial, capacity) def sector_login(self, blockvect, key, keytype=0): diff --git a/sql-edition/servers/VendingMachine.py b/sql-edition/servers/VendingMachine.py index b7d747a..e96832a 100644 --- a/sql-edition/servers/VendingMachine.py +++ b/sql-edition/servers/VendingMachine.py @@ -190,7 +190,7 @@ class VendingMachine: self.mifare_timeout = now + 0.5 mifare_uid = self.mifare.get_card_id() if mifare_uid != None: - logging.info('Got MIFARE card id %s'%(str(mifare_uid))) + logging.info('Got MIFARE card id %s'%(repr(mifare_uid))) self.events.append((MIFARE, mifare_uid)) timeout = 0 if timeout == 0: