-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add example that extracts gps raw data from a log file
- Loading branch information
1 parent
59dcecd
commit 0e2bfba
Showing
1 changed file
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
import dronecan | ||
import sys | ||
# progress bar | ||
from tqdm import tqdm | ||
|
||
if len(sys.argv) != 4: | ||
print("Usage: python3 canlog2gps.py <messageName> <logfile> <outputfile>") | ||
sys.exit(1) | ||
|
||
# Create a CAN bus instance | ||
global node | ||
print('Starting server as Node ID', 10) | ||
|
||
filename = sys.argv[2] | ||
out_file = open(sys.argv[3],'wb') | ||
node = dronecan.make_node("filein:"+filename, node_id=10, bitrate=1000000,speedup=-1) | ||
|
||
def handle_Data(msg): | ||
# dump the message data to a file | ||
out_file.write(msg.message.data.to_bytes()) | ||
|
||
# message type by key name | ||
message_type = getattr(dronecan.ardupilot.gnss, sys.argv[1]) | ||
node.add_handler(message_type, handle_Data) | ||
|
||
# progress bar | ||
pbar = tqdm(total=100) | ||
|
||
while True: | ||
try: | ||
node.spin(0.001) | ||
# print(node.can_driver.stream_progress()) | ||
# show the progress of the stream | ||
pbar.update(node.can_driver.stream_progress() - pbar.n) | ||
if node.can_driver.end_of_stream(): | ||
print('End of stream') | ||
out_file.flush() | ||
out_file.close() | ||
sys.exit(0) | ||
except KeyboardInterrupt: | ||
out_file.flush() | ||
out_file.close() | ||
sys.exit(0) |