-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxbee.py
79 lines (65 loc) · 1.92 KB
/
xbee.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
import datetime
import serial
import time
leidoAnterior = ""
class xbee:
def __init__(self,USB):
self.connection=serial.Serial(USB,9600)
self.timestamp=''
self.challenge='0'
self.latitude= 'HDDD.DDDDDD'
self.longitude='HDDD.DDDDDD'
self.takeoff='0'
self.flying='0'
self.landing = '0'
def set_challenge(self,chal='N'):
self.challenge = chal
def set_latlong(self,latitude,longitude):
self.latitude=latitude
self.longitude=longitude
def set_takeoff(self,take):
self.takeoff=take
def set_flying(self, fly):
self.flying=fly
def set_landing(self, land):
self.landing=land
def send2station(self):
date=str(datetime.datetime.now())
#print(date)
fecha=date.split('-')
dia=fecha[2].split(' ')[0]
horas=fecha[2].split(' ')[1].split(':')
self.timestamp=(fecha[0]+fecha[1]+dia+horas[0]+horas[1]+horas[2][:2]).zfill(14)
string=self.timestamp+','+self.latitude+','+self.longitude+','+self.challenge+','+self.takeoff+','+self.flying+','+self.landing+','+'%'
print(string)
self.connection.write(bytes(string, encoding='utf-8'))
def send2boat(self,data):
transmit = data[0]
R_kill_switch = data[1]
status = data[2]
course = data[3]
challenge = data[4]
dock = data[5]
string=','+str(transmit)+','+str(R_kill_switch)+','+str(status)+','+str(course)+','+str(challenge)+','+str(dock)+','+'%'
print(string)
self.connection.write(bytes(string, encoding='utf-8'))
def receive_from_station(self):
leido=self.connection.read(17).decode("utf-8")
self.connection.flush()
time.sleep(.1)
data = leido.split(',');
data = data[1 :]
data = data[: 6]
return data
#29.151098, -81.016505
def receive_from_boat(self):
#self.connection.flush()
#self.connection.reset_input_buffer()
#time.sleep(.1)
#print("After connection")
leido=self.connection.readline(48).decode("utf-8")
#print("Before Connection")
print(leido)
return leido;
def clean_buffer(self):
self.connection.flush()