-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstation.py
More file actions
143 lines (116 loc) · 2.97 KB
/
station.py
File metadata and controls
143 lines (116 loc) · 2.97 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
'''
@author Juan Carlos Aguilera
'''
#Estación
#Comunicación del Serial independiende a la de Variable
#Esta comunicación es únicamente para la estación.
#Comunicación con el Bote a través de XBEE
#Establecer Comunicación con el Servidor de AUVSI
#Comunicarse con BT a la aplicación
#Leer Kill Switch del Bote
#Sí se puede saber del Kill Switch del Drone
import os
import io
import sys
import xbee
import time
#import serial
import threading
from PIL import Image
from bluetooth import *
from array import array
import lib.bluetoothServer as bt
import lib.auvsiServerCommunication as auvsi
xb = xbee('/dev/ttyUSB0')
status = True
data = []
teamCode = "Tecnológico de Monterrey"
course = "courseA"
file = "image.jpg"
class readKillSwitches(threading.Thread):
def __init__(self, threadID,name):
threading.Thread.__init__(self);
self.threadID = threadID;
self.name = name;
def run(self):
kill = x.read_kill_switch()
if kill == "emergency":
print("Abort Everything");
#Manage Drone Communication
class BTtransmission(threading.Thread):
def __init__(self, threadID,name):
threading.Thread.__init__(self);
self.threadID = threadID;
self.name = name;
def run(self):
timestamp = data[0]
#Manage Drone Kill Switch
#Manage Boat Remote Kill Switch
class XBeeThread(threading.Thread):
def __init__(self, threadID,name):
threading.Thread.__init__(self);
self.threadID = threadID;
self.name = name;
def run(self):
global data
x = xbee.xbee('/dev/ttyUSB0');
data = x.receive_from_boat().split('-');
if(status):
x.send2boat(str(status));
#Get XBee info and send it to AUVSI server
class AUVSICommunication(threading.Thread):
def __init__(self, threadID,name):
threading.Thread.__init__(self);
self.threadID = threadID;
self.name = name;
def run(self):
timestamp = data
def send_heart_beat():
timestamp = data[0];
challenge = data[1];
latitude = data[2];
longitude = data[3];
stat = data[4];
if(len(timestamp) > 14 or len(challenge) != 0 or len(latitude) < 11 or len(longitude) < 11):
send_heart_beat();
else:
auvsi.send_heart_beat(course,timestamp,challenge,latitude,longitude);
def send_follow():
if( len(course > 4) ):
gate = auvsi.send_follow_leader(course);
else:
send_follow();
def send_docking():
if(len(course) > 4):
imgID = auvsi.send_docking(course,file);
else:
send_docking()
def init():
#Start sequence
#Call XBee and read info
'''
while(status):
if(challenge == 'docking'):
send_docking();
elif(challenge == 'follow'):
gate = sendFollow();
elif(challenge == 'return'):
print("Return")
sendHeartBeat();
'''
'''
' Inicio del Programa
'''
xbThread = XBeeThread(1,"XBeeThread");
#btTranThread = BTtransmission(2,"BTtransmission");
#AUVSIThread = AUVSICommunication(3,"AUVSICommunication");
#Start Threads
xbThread.start();
#btTranThread.start();
#AUVSIThread.start();
xbThread.join();
#btTranThread.join();
#AUVSIThread.join();
if __name__ == '__main__':
init()
print("Exiting Main Thread");