Updates for key validation:

- Check the start and stop bytes of the RFID message in addition to the
  expected length to prevent crashes.
- There is no need to re-lock the door if it was never unlocked.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2017-06-19 16:32:53 -04:00
parent 71db8b6220
commit 7296900ddf
1 changed files with 3 additions and 3 deletions

View File

@ -154,8 +154,8 @@ RFID_SERIAL = serial.Serial(RFID_PATH, 2400, timeout=1)
def read_key():
RFID_SERIAL.reset_input_buffer() # Clear input buffer before reading
string = RFID_SERIAL.read(12)
if len(string) > 0:
key = string[1:11].decode() #exclude start x0A and stop x0D bytes
if len(string) == 12 and string[0] == 0xA and string[-1] == 0xD:
key = string[1:11].decode() #exclude start 0xA and stop 0xD bytes
if key.isalnum():
return key;
return None
@ -166,7 +166,7 @@ def read_rfid():
if key and verify_key(key):
unlock_door()
time.sleep(5) # block for 5 seconds before resetting door
lock_door()
lock_door()
flush_keys()
except Exception as e:
print(e)