-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#15: Improve sniffer performance with binary mode
- Loading branch information
Showing
6 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python3 | ||
# UWB binary sniffer decoder | ||
# | ||
# The LPS node should be in sniffer mode already, it will be switched to | ||
# binary mode by this script. | ||
|
||
import sys | ||
import struct | ||
import serial | ||
import binascii | ||
|
||
if len(sys.argv) != 2: | ||
print("usage: {} <sniffer serial port>".format(sys.argv[0])) | ||
sys.exit(1) | ||
|
||
ser = serial.Serial('/dev/ttyACM0') | ||
|
||
# Switch to binary mode | ||
ser.write(b'b') | ||
|
||
while True: | ||
c = ser.read(1) | ||
|
||
if c == b'\xbc': | ||
ts = ser.read(5) | ||
ts += b'\0\0\0' | ||
ts = struct.unpack('<Q', ts)[0] | ||
addrFrom, addrTo = struct.unpack('<BB', ser.read(2)) | ||
length = struct.unpack('<H', ser.read(2))[0] | ||
if length > 1024: | ||
continue | ||
data = ser.read(length) | ||
l2 = struct.unpack('<H', ser.read(2))[0] | ||
if length == l2: | ||
print("@{:010x} from {} to {}: {}".format(ts, addrFrom, addrTo, | ||
binascii.hexlify(data) | ||
.decode('utf8'))) | ||
else: | ||
print("Out of sync!") |