Skip to content

Commit

Permalink
examples: add example that extracts gps raw data from a log file
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator authored and tridge committed Aug 2, 2023
1 parent 59dcecd commit 0e2bfba
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/canlog2gps.py
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)

0 comments on commit 0e2bfba

Please sign in to comment.