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: 8 additions & 9 deletions zp_sitl/sitl_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,18 @@ async def rfd_viewer_handler(request):
messages = sitl.zp.get_rfd_messages()
for direction, message in messages:
# Try to decode as MAVLink
# TODO: If a message is split between two UDP messages, we currently don't handle it correctly and just stream the bytes. This is pretty rare though rn
# TODO: If a message is split between two UDP messages, we currently don't handle it correctly and just stream the bytes. Currently ZP never splits messages, so it is not yet an issue.
decoded = mavlink_decoder.decode_hex_message(message)

if decoded:
msg_name, formatted = decoded
await ws.send_json({
"direction": direction,
"raw": message,
"decoded": formatted,
"type": msg_name
})
for msg_name, formatted in decoded:
await ws.send_json({
"direction": direction,
"raw": message,
"decoded": formatted,
"type": msg_name
})
else:
# Send raw if decoding fails
await ws.send_json({
"direction": direction,
"raw": message,
Expand Down
4 changes: 3 additions & 1 deletion zp_sitl/ui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function handleJoystick(ws, controls) {
}

function startRFDViewer() {
const MAX_MESSAGES = 1000;

const rfdWs = new WebSocket('ws://localhost:8080/rfd');
const txDiv = document.getElementById('telem-tx');
const rxDiv = document.getElementById('telem-rx');
Expand All @@ -159,6 +161,6 @@ function startRFDViewer() {
: data.raw;

div.insertBefore(msgElem, div.firstChild);
if (div.children.length > 100) div.removeChild(div.lastChild);
if (div.children.length > MAX_MESSAGES) div.removeChild(div.lastChild);
};
}
29 changes: 12 additions & 17 deletions zp_sitl/util/mavlink_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,22 @@ def decode_hex_message(self, hex_string):
if len(data) < 3 or (data[0] != 0xFE and data[0] != 0xFD):
return None

# Parse the message by feeding bytes one at a time
msg = None
# Parse ALL messages by feeding bytes one at a time
messages = []
for byte in data:
msg = self.mav.parse_char(bytes([byte]))
if msg:
break
msg_name = msg.get_type()
msg_dict = msg.to_dict()

formatted = f"{msg_name}"
for key, value in msg_dict.items():
if key != 'mavpackettype':
formatted += f"\n {key}: {value}"

messages.append((msg_name, formatted))

if msg is None:
return None

# Extract message info
msg_name = msg.get_type()
msg_dict = msg.to_dict()

# Format nicely
formatted = f"{msg_name}"
for key, value in msg_dict.items():
if key != 'mavpackettype':
formatted += f"\n {key}: {value}"

return (msg_name, formatted)
return messages if messages else None
except Exception as e:
return None

Expand Down