-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
84 lines (61 loc) · 2.1 KB
/
main.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
import time
import queue
import threading
from android import Android
from arduino import Arduino
from interface import Interface
class Main:
interface = None
listen_rate = 1
android=None
arduino=None
def __init__(self):
threading.Thread.__init__(self)
#self.pc = PC(tcp_ip="192.168.1.1")
self.android = Android()
self.arduino = Arduino()
#self.pc.connect()
self.android.connect()
self.arduino.connect()
time.sleep(1)
self.interface = Interface(arduino = self.arduino, fakeRun=False, android=self.android)
def write_to_pc(self, msg):
self.pc.write(msg)
print("[@] Sent to PC: {}".format(msg))
def read_from_pc(self):
msg = self.pc.read()
if msg == None:
return print("[#] nothing to read [read_from_pc]")
def start_listening(self):
self.android.write('{"canExplore": true}')
while True:
msg = self.android.read()
if msg == None:
continue
try:
results = self.interface.readinstructions(msg)
if results is None:
print("Instruction Done")
else:
self.android.write(results)
except Exception as e:
print("[@] Error reading instructions")
print(e)
time.sleep(self.listen_rate)
import sys, os
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
def close_all_connections(self):
#self.pc.close()
self.android.close()
self.arduino.close()
if __name__ == "__main__":
print("[@] Starting main program..")
app = Main()
try:
app.start_listening()
except Exception as e:
print("[@] Error running main")
app.close_all_connections()
print(e)