git.ucc.asn.au
/
uccvend-vendserver.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use an anonymous LDAP bind to search for MIFARE cards - server ACLs have been updated...
[uccvend-vendserver.git]
/
sql-edition
/
servers
/
VendingMachine.py
diff --git
a/sql-edition/servers/VendingMachine.py
b/sql-edition/servers/VendingMachine.py
index
d73eb4b
..
b7d747a
100644
(file)
--- a/
sql-edition/servers/VendingMachine.py
+++ b/
sql-edition/servers/VendingMachine.py
@@
-4,6
+4,7
@@
from CRC import do_crc
from select import select
import socket, logging
from time import time, sleep
from select import select
import socket, logging
from time import time, sleep
+from MIFAREClient import MIFAREClient
asynchronous_responses = [ '400', '401', # door open/closed
'610', # switches changed
asynchronous_responses = [ '400', '401', # door open/closed
'610', # switches changed
@@
-14,11
+15,12
@@
DOOR = 1
SWITCH = 2
KEY = 3
TICK = 4
SWITCH = 2
KEY = 3
TICK = 4
+MIFARE = 5
class VendingException(Exception): pass
class VendingMachine:
class VendingException(Exception): pass
class VendingMachine:
- def __init__(self, rfh, wfh):
+ def __init__(self, rfh, wfh
, use_mifare
):
self.events = []
# Secret
self.secret = 'SN4CKZ0RZZZZZZZZ'
self.events = []
# Secret
self.secret = 'SN4CKZ0RZZZZZZZZ'
@@
-35,6
+37,11
@@
class VendingMachine:
while code != '000':
code = self.get_response()[0]
self.get_switches()
while code != '000':
code = self.get_response()[0]
self.get_switches()
+ if use_mifare:
+ self.mifare = MIFAREClient()
+ self.mifare_timeout = 0
+ else:
+ self.mifare = None
def await_prompt(self):
self.wfh.flush()
def await_prompt(self):
self.wfh.flush()
@@
-161,15
+168,34
@@
class VendingMachine:
def next_event(self, timeout = None):
# we don't want to buffer in the serial port, so we get all the events
# we can ASAP.
def next_event(self, timeout = None):
# we don't want to buffer in the serial port, so we get all the events
# we can ASAP.
+
+ # Never have no timeout...
+ if timeout == None: timeout = 60*60*24*365
+
+ # Make sure we go through the loop at least once.
if timeout < 0: timeout = 0
if timeout < 0: timeout = 0
- if len(self.events) > 0: timeout = 0
- while True:
- (r, _, _) = select([self.rfh], [], [], timeout)
+
+ while timeout >= 0:
+ this_timeout = min(timeout, 0.2)
+ timeout -= this_timeout
+
+ (r, _, _) = select([self.rfh], [], [], this_timeout)
if r:
self.get_response(async = True)
timeout = 0
if r:
self.get_response(async = True)
timeout = 0
- else:
+
+ if self.mifare:
+ now = time()
+ if now > self.mifare_timeout:
+ 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)))
+ self.events.append((MIFARE, mifare_uid))
+ timeout = 0
+ if timeout == 0:
break
break
+
if len(self.events) == 0: return (TICK, time())
ret = self.events[0]
del self.events[0]
if len(self.events) == 0: return (TICK, time())
ret = self.events[0]
del self.events[0]
UCC
git Repository :: git.ucc.asn.au