Skip to content

Commit 06bc5a9

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents f7e69fe + 5e64a74 commit 06bc5a9

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

OnLand/PDS/spacexPacket.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import struct
2+
3+
def spacex_packet(pod_data):
4+
team_id = 'Paradigm'
5+
podState = pod_data['podState']
6+
acceleration = pod_data['podAccelerationX']
7+
position = pod_data['podPosition']
8+
velocity = pod_data['podVelocity']
9+
10+
if podState == 0:
11+
status = 1
12+
elif podState == 1:
13+
status = 1
14+
elif podState == 2:
15+
status = 1
16+
elif podState == 3:
17+
status = 1
18+
elif podState == 4:
19+
status = 2
20+
elif podState == 5:
21+
status = 3
22+
elif podState == 6:
23+
status = 4
24+
elif podState == 7:
25+
status = 5
26+
elif podState == 8:
27+
status = 1
28+
elif podState == 9:
29+
status = 0
30+
else:
31+
status = 0
32+
33+
return struct.pack(">BB7iI", team_id, int(status), int(acceleration),
34+
int(position), int(velocity), 0, 0, 0, 0, 0)

OnLand/PDS/telemetry.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import time
33
import logging as log
44
import time
5-
from datetime import timedelta
6-
5+
import socket
76
import socketio
7+
8+
from datetime import timedelta
89
from google.protobuf import json_format
910
from google.protobuf.json_format import MessageToDict
1011

12+
from PDS.spacexPacket import spacex_packet
1113
from PDS.UDP.PodUdpConnection import PodUdpConnection
1214
from PDS.helpers.heartbeat_timer import HeartbeatTimer
1315
from Paradigm_pb2 import Telemetry
@@ -18,6 +20,12 @@
1820
broadcast_timer = HeartbeatTimer()
1921
log.basicConfig(stream=sys.stdout, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
2022

23+
# SpaceX Packet connection, only to be turned on during Competition run
24+
SEND_SPACEX_PACKET = False
25+
if SEND_SPACEX_PACKET:
26+
server = ('127.0.0.1', 3000)
27+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
28+
2129
# Create socket to connect to server
2230
sio = socketio.Client()
2331
connection_status = {'name': 'telemetry', 'status': 0}
@@ -64,6 +72,9 @@ def main():
6472
sio.emit('pod_telemetry', json_pod_data)
6573
pod_data = MessageToDict(pod_data)
6674
log.warning("Telemetry: {}".format(pod_data))
75+
if SEND_SPACEX_PACKET:
76+
packet = spacex_packet(pod_data)
77+
sock.sendto(packet, server)
6778
else:
6879
connection_status['status'] = 0
6980
sio.emit('connection_updates', json.dumps(connection_status))

0 commit comments

Comments
 (0)