Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions MAVProxy/modules/mavproxy_asterix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This listens for SDPS on UDP and translates to ADSB_VEHICLE messages
'''

import pickle
import json
from math import *

from MAVProxy.modules.lib import mp_module
Expand Down Expand Up @@ -200,12 +200,14 @@ def idle_task(self):
return
try:
if pkt.startswith(b'PICKLED:'):
pkt = pkt[8:]
# pickled packet
try:
amsg = [pickle.loads(pkt)]
except pickle.UnpicklingError:
amsg = asterix.parse(pkt)
print("bad packet")
return
if pkt.startswith(b'JSON:'):
pkt = pkt[5:]
decoded = json.loads(pkt.decode('utf-8'))
if not isinstance(decoded, dict):
raise ValueError("JSON packet root is not a dictionary")
amsg = [decoded]
else:
amsg = asterix.parse(pkt)
self.pkt_count += 1
Expand Down Expand Up @@ -358,4 +360,3 @@ def init(mpstate):
#amsg = asterix.parse(pkt)
#print(amsg)


8 changes: 4 additions & 4 deletions MAVProxy/modules/mavproxy_genobstacles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
generate dynamic obstacles for OBC 2018
'''

import time, pickle
import time, json
from math import *

from MAVProxy.modules.lib import mp_module
Expand Down Expand Up @@ -196,8 +196,8 @@ def update(self, deltat=1.0):
def __str__(self):
return str(self.pkt)

def pickled(self):
return b'PICKLED:' + pickle.dumps(self.pkt)
def json_packet(self):
return b'JSON:' + json.dumps(self.pkt).encode('utf-8')

class Aircraft(DNFZ):
'''an aircraft that flies in a circuit'''
Expand Down Expand Up @@ -459,7 +459,7 @@ def mavlink_packet(self, m):
for a in self.aircraft:
if not gen_settings.stop:
a.update(1.0)
self.pkt_queue.append(a.pickled())
self.pkt_queue.append(a.json_packet())
while len(self.pkt_queue) > len(self.aircraft)*2:
self.pkt_queue.pop(0)

Expand Down