-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverV2.py
129 lines (108 loc) · 3.15 KB
/
serverV2.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
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
import rpyc
from rpyc.utils.server import ThreadedServer
import sqlite3
import time
import datetime
import serial
running_on_pie = False # pie or windows
if running_on_pie:
conn = sqlite3.connect('/home/sysop/pos/order.db', check_same_thread=False)
robot = serial.Serial('/dev/ttyUSB0', 19200, timeout=None)
else:
conn = sqlite3.connect('order.db', check_same_thread=False)
robot = serial.Serial('COM7', 19200, timeout=None)
c = conn.cursor()
def log_it(note):
if running_on_pie:
f = open("/home/sysop/pos/server_log.txt", "a+")
else:
f = open("server_log.txt", "a+")
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%d-%m-%Y %H:%M:%S')
info = st + ' > '
info += note
info += '\n\r'
f.write(info)
def data_test(a1):
c.execute("SELECT * FROM donut WHERE orderNUM=:a1", {"a1": str(a1)})
data1 = c.fetchall()
if data1:
return data1
def data_delete(a1):
c.execute("DELETE FROM donut WHERE orderNUM=:a1", {"a1": str(a1)})
conn.commit()
def order_process(order):
if len(order) == 4:
xa = str(data_test(order))
if xa != 'None':
xa = xa.strip('[]()')
xa = xa.replace(" ", "")
xa = xa.split(",")
dm = '$A' + str(xa[0])
if str(xa[1]) == '0':
dm += '1000#'
else:
dm += str(xa[1])
dm += '#'
else:
dm = xa
return dm
class ServerHead(rpyc.Service):
def __init__(self, **kwargs):
super(ServerHead, self).__init__(**kwargs)
self.bill = False
self.phil = False # remove
self.last = ''
self.onbord = 0
def on_connect(self, connects):
self.onbord += 1
print("connected")
def on_disconnect(self, connects):
self.onbord -= 1
print("disconnected")
@staticmethod
def exposed_order(orders):
message = order_process(orders)
log_it(message)
return message
def exposed_robot(self, bot):
while self.bill:
time.sleep(.5)
self.bill = True
robot.write(bot.encode("utf-8"))
line_in = robot.readline()
line = line_in.decode("utf-8")
line = line.rstrip()
log_it(line)
print(line)
self.bill = False
return line
def exposed_pay(self, bot):
while self.bill:
time.sleep(.25)
self.bill = True
robot.write(bot.encode("utf-8"))
line_in = robot.readline()
line = line_in.decode("utf-8")
line = line.rstrip()
if line != self.last:
print(line)
log_it(line)
self.last = line
self.bill = False
return line
def exposed_card(self):
while self.phil:
time.sleep(.25)
self.bill = True
sender = 'C#'
robot.write(sender.encode("utf-8"))
line_in = robot.readline()
line = line_in.decode("utf-8")
line = line.rstrip()
self.bill = False
return line
if __name__ == '__main__':
t = ThreadedServer(ServerHead, port=12345)
print(t.host)
t.start()