-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseStation.py
46 lines (36 loc) · 1.27 KB
/
baseStation.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
import socket
from models import *
import math
def setup_udp_socket(base_ip, base_port):
UDP_IP = str(base_ip)
UDP_PORT = base_port
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
return sock
def read_base_station(boat_1, boat_2, buoy_list, socket):
data, addr = socket.recvfrom(1024)
data_list = data.split(',')
# boat 1
boat_1_index = data_list.index(boat_1.greek)
pos_1 = (int(data_list[boat_1_index+1]), int(data_list[boat_1_index+2]))
heading_1 = math.radians(int(data_list[boat_1_index+3])-90)
boat_1.update(pos_1, heading_1)
# boat 2
boat_2_index = data_list.index(boat_2.greek)
pos_2 = (int(data_list[boat_2_index+1]), int(data_list[boat_2_index+2]))
heading_2 = math.radians(int(data_list[boat_2_index+3])-90)
boat_2.update(pos_2, heading_2)
# buoy
for buoy in buoy_list:
buoy_index = data_list.index(buoy.name)
buoy.position = (int(data_list[buoy_index+1]), int(data_list[buoy_index+2]))
if __name__ == '__main__':
boat1 = Boat('deborah', 'L')
boat2 = Boat('beth', 'P')
buoy_list = [Buoy(name) for name in ['A', 'B', 'C', 'D']]
socket = setup_udp_socket(0xFFFFFFFF, 61557)
read_base_station(boat1, boat2, buoy_list, socket)
print boat1
print boat2
for b in buoy_list:
print b