-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckloop.py
More file actions
108 lines (106 loc) · 2.77 KB
/
Copy pathcheckloop.py
File metadata and controls
108 lines (106 loc) · 2.77 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
import os
import RPi.GPIO as GPIO
from theft_check import *
from time import sleep
from trip_register import *
from trip_update import *
from CFstat import *
import peewee as pw
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(17,GPIO.OUT)
comp=False
while not comp:
x=os.popen("node card2.js").read().split('\n')
if x[0] == "card removed":
GPIO.output(23,GPIO.HIGH)
GPIO.output(24,GPIO.LOW)
GPIO.output(17,GPIO.LOW)
print("Not available")
else:
db=pw.SqliteDatabase('admin')
db.connect()
cur=db.execute_sql("select * from admin_cards where id='%s'"%x[1])
z=list(cur.fetchall())
try:
per=z[0][1]
except:
per=None
if per=="add":
GPIO.output(23,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
GPIO.output(17,GPIO.HIGH)
print("Add card for addition")
sleep(5)
x=os.popen("node card2.js").read().split('\n')
while x[0] == "card removed":
x=os.popen("node card2.js").read().split('\n')
continue
cur=db.execute_sql("select * from admin_cards where id='%s';"%x[1])
z=len(cur.fetchall())
if z!=0:
print("Card already registered")
else:
db.execute_sql("insert into admin_cards values('%s','access');"%x[1])
print("Card Registered")
for i in range(3):
GPIO.output(17,GPIO.LOW)
sleep(0.5)
GPIO.output(17,GPIO.HIGH)
sleep(0.5)
elif per=="delete":
GPIO.output(23,GPIO.HIGH)
GPIO.output(24,GPIO.LOW)
GPIO.output(17,GPIO.HIGH)
print("Add card for deletion")
sleep(2)
x=os.popen("node card2.js").read().split('\n')
while x[0] == "card removed":
x=os.popen("node card2.js").read().split('\n')
continue
cur=db.execute_sql("select * from admin_cards where id='%s' and purpose='access';"%x[1])
z=len(cur.fetchall())
if z==0:
print("Card not registered yet")
else:
for i in range(3):
GPIO.output(17,GPIO.LOW)
sleep(0.5)
GPIO.output(17,GPIO.HIGH)
sleep(0.5)
db.execute_sql("delete from admin_cards where id='%s';"%x[1])
print("Card Deleted")
elif per=="access":
istrip=True;
theft=False;
init_time=0;
GPIO.output(23,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
print("Card Accepted")
x=os.popen("node card2.js").read().split('\n')
trip_id=0;
while x[0] != "card removed":
print("Sending location")
if(istrip):
init_time,trip_id=trip_init()
else:
trip_cont(init_time,True,trip_id)
x=os.popen("node card2.js").read().split('\n')
trip_time=trip_cont(init_time,False,trip_id)
poll_count(x[1],trip_time)
theft=stop_command(vehicle_id)
if(theft):
break
else:
print("Card not registered")
# except:
# GPIO.cleanup()
# comp=True
for i in range(10):
GPIO.output(23,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
sleep(2)
GPIO.output(23,GPIO.HIGH)
GPIO.output(24,GPIO.LOW)