MIFARE: better logging, thanks to [TRS] I think
authorDavid Adam <[email protected]>
Sat, 9 Apr 2011 03:29:12 +0000 (03:29 +0000)
committerDavid Adam <[email protected]>
Sat, 9 Apr 2011 03:29:12 +0000 (03:29 +0000)
sql-edition/servers/MIFAREDriver.py
sql-edition/servers/VendingMachine.py

index a3a65b6..46a0731 100644 (file)
@@ -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):
index b7d747a..e96832a 100644 (file)
@@ -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:

UCC git Repository :: git.ucc.asn.au