forked from asteroidDavis/re-vend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.py
72 lines (53 loc) · 1.97 KB
/
box.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
#By Chris Schoener and Nate Davis, Python 2.7
import ConfigParser #uses built in module to read config
from select import select
import struct
import argparse
import sys
from solenoid import *
import time
import socket
from Student import *
from CodeReader import *
from subprocess import PIPE, Popen
from threading import Thread
from ComponentRESTClient import ComponentRESTClient
def main():
#input parsing stuff
try:
from Queue import Queue, Empty
except ImportError:
from queue import Queue, Empty # python 3.x
ON_POSIX = 'posix' in sys.builtin_module_names
def enqueue_output(out, queue):
for line in iter(out.readline, b''):
queue.put(line)
out.close()
config = ConfigParser.RawConfigParser()
config.read("boxconfig.txt")
waitSecs = config.getint("general","seconds_box_is_unlocked")
lock = solenoid(config.getint("lock", "pin"), waitSecs)
containerIDInputHostPath = config.get("container_id_input_host", "ENTRY_POINT")
containerIDInputHostArgs = config.get("container_id_input_host", "ARGS")
containerIDInputHostTarget = []
containerIDInputHostTarget.append(containerIDInputHostPath)
containerIDInputHostTarget.extend(containerIDInputHostArgs.split(str=";"))
containerIDInputHost = Popen(containerIDInputHostTarget, stdout=PIPE, stderr=PIPE, bufsize=50, close_fds=ON_POSIX)
inputQueue = Queue()
inputQueueWatcher = Thread(target=enqueue_output, args=(containerIDInputHost.stdout, inputQueue))
inputQueueWatcher.daemon = True # thread dies with the program
inputQueueWatcher.start()
RESTClient = ComponentRESTClient()
while True:
idInput = ''
while (idInput == ''):
try: idInput = inputQueue.get_nowait()
except Empty:
pass
if RESTClinet.CheckInBox(idInput):
print("RFID accepted")
lock.unlockThenLock()
else:
print("RFID rejected")
main()