Skip to content

Commit

Permalink
#15 #17: Add TDoA 2 YAML decoded for binary sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel committed Nov 29, 2017
1 parent 491952b commit 84ee4f6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tools/sniffer/tdoa2_decoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# YAML sniffer log TDOA2 decoder, generates a stream of YAML documents
# containing the decoded packet
# out of simplicity (and lazyness), reads from STDIN and write to STDOUT,
# just use your shell piping functionalities!

import sys
import yaml
import struct

# Packet format:
# NSLOTS = 8
# typedef struct rangePacket_s {
# uint8_t type;
# uint8_t seqs[NSLOTS]; // Packet sequence number of the timestamps
# uint32_t timestamps[NSLOTS]; // Relevant time for anchors
# uint16_t distances[NSLOTS];
# } __attribute__((packed)) rangePacket_t;

for packet in yaml.load_all(sys.stdin, Loader=yaml.CLoader):
if not packet:
continue

# Its alost free so we keel the raw data and just add the decoded fields
packetType = packet["data"][0]

if packetType == 34:
decoded = struct.unpack("<BBBBBBBBBLLLLLLLLHHHHHHHH", packet["data"])
packet["type"] = decoded[0]
if packet["type"] == 34:
packet["seqs"] = list(decoded[1:9])
packet["timestamps"] = list(decoded[9:17])
packet["distances"] = list(decoded[17:25])

print("---")
print(yaml.dump(packet, Dumper=yaml.CDumper))

0 comments on commit 84ee4f6

Please sign in to comment.