-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_driver.py
More file actions
executable file
·174 lines (154 loc) · 5.01 KB
/
ssh_driver.py
File metadata and controls
executable file
·174 lines (154 loc) · 5.01 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/python
"""
This application is intended to run on RaspberryPi startup and requires no console input
The application has four states, an initialization state, a location reader state, a wristband scanner state, and a wristband registration state
In this application, interrupts are triggered by button presses according to the attached schematic
Initialization State:
All global variables are initialized
Location is read from location file if one exists
All imports are made
All interrupts are registered
Event Scanning State:
Scan wristband
If new scan, continue, else, repeat
Relay scan location, time, and wristband id to redis server
Receive response from redis server
Display data from redis response to LCD
repeat
Location Reading State:
Scan wristband
If new scan, continue, else repeat
Authenticate with wristband
Read sectors to get location from wristband
Update location file
repeat
Registration Scanning State:
Get user PIN
Query redis server to receive Name & Shirt Size
Display data from redis server
Scan wristband
Post wristband ID to redis with PIN
Verify acknowledgment from redis
repeat
FSM Diagram:
+----------------+
| |
| Initialization |
| |
+-------+--------+
|
| Initialization Complete
|
+-------v--------+ +------------------+
| | Location Interrupt Fired | |
| Event Scanning +----------------------------> Location Reading |
| <----------------------------+ |
+------^---------+ Event Interrupt Fired +----------------^-+
Event || Registration Interrupt Fired | |
Interrupt || | |
Fired || Registration Interrupt Fired | |
+-------v---------------+ | |
| <---------------------+ |
| Registration Scanning | |
| +--------------------------------------+
+-----------------------+ Location Interrupt Fired
"""
import time
import calendar
import threading
import logging
try:
import RPi.GPIO as GPIO
except ImportError:
logging.ERROR('RaspberryPi GPIO is unavailable; please check OS installation')
exit(-1)
#TODO: import all HackPSU abstraction modules
#import hackpsuLCD as lcd
import HackPSUrfid as rfid
import HackPSUredis as redis
import HackPSUconfig as config
import HackPSUfauxlcd as lcd
global state
state = 1
def getWifi():
return "XXX%"
def advanceState(dummy):
global state
state = (state + 1)%3
print("STATE " + str(state))
#Prevent warnings from reusing IO ports
GPIO.setwarnings(False)
#TODO
#Change to logging.WARNING or ERROR for release
logging.basicConfig(filename='scanner.log', level=logging.DEBUG)
#TODO
#register mode switch interrupts
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # set GPIO25 as input (button)
GPIO.add_event_detect(13, GPIO.RISING, callback=advanceState)
#TODO
#Load information from config file
#Launch into the scanner mode
configurationDictionary = config.getProperties("pi.cfg")
lastUID = None
while True:
if state == 0:
print("Scanner mode")
lcd.printDebug(configurationDictionary["location"], getWifi())
#Wait until band is detected
uid = None
#Wait for a wristband
while not rfid.detectBand():
pass
#Once we have one, go
#If it stops here, restart the program
l("Scanning...")
#Get UID, skip scan if same as last
uid = rfid.getUID()
#Pls no let multiple scans happen
if uid == lastUID:
continue
print(uid)
lcd.printMsg("Scanned Wristband")
#Tell redis who scanned, when, and where
timestamp = calendar.timegm(time.gmtime())
location = configurationDictionary["location"]
result = redis.postScan(configurationDictionary["redisLocation"], uid, timestamp, location)
lcd.printScan(result)
lastUID = uid
elif state == 1:
print("Registration mode")
lcd.printDebug(configurationDictionary["location"], getWifi())
uid = None
print("Enter Pin")
key = None
pin = raw_input()
print("#=Sub, *=Clear")
(name, size) = redis.postPin(configurationDictionary["redisLocation"], pin)
print(name)
#lcd.printMsg("#=Sub, *=Clear")
key = raw_input()
if key == "*":
continue
lcd.printDebug(configurationDictionary["location"], getWifi())
lcd.printMsg(size)
while not rfid.detectBand():
pass
lcd.printMsg("Scanned")
uid = rfid.getUID()
resp = redis.postRegistration(configurationDictionary["redisLocation"], uid, pin)
lcd.printMsg(resp)
time.sleep(1)
lastUID = uid
else:
print("Location Mode")
lcd.printDebug(configurationDictionary["location"], getWifi())
uid = None
lcd.printMsg("Waiting...")
while not rfid.detectBand():
pass
lcd.printMsg("Detected Wristband")
loc = rfid.readLocation()
configurationDictionary["location"] = loc
lcd.printLocation(loc)
lastUID = uid
config.setProperties("pi.cfg", configurationDictionary)