Skip to content

Commit

Permalink
works on my laptop
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbrook committed Apr 8, 2024
1 parent 811e332 commit afe79a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions py_data_acq/py_data_acq/io_handler/serial_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@
async def serial_reciever(can_db: cantools.db.Database, message_classes, q1, q2):
# Start asyncio on the port
reader, writer = await serial_asyncio.open_serial_connection(
url="/dev/xboi", baudrate=230400
url="/dev/ttyUSB0", baudrate=115200
)

while True:
# Wait for the next message from the buffer, then break it into parts using the byte value for ","
nl_byte = await reader.readline()
vals = nl_byte.split(b",")

print(f"Raw Line: {nl_byte}")
print(f"Comma delimited: {vals}")
# try:
# Get message data for foxglove
frameid = int.from_bytes(vals[0],byteorder='little')
try:
# Get message data for foxglove
msg = can_db.get_message_by_frame_id(int.from_bytes(vals[0]))

msg = can_db.get_message_by_frame_id(frameid)
# Break down message
decoded_msg = can_db.decode_message(
int.from_bytes(vals[0]), vals[1], decode_containers=True
frameid, vals[1], decode_containers=True
)

# Package as protobuf guy
msg = protobuf_helpers.pack_protobuf_msg(
decoded_msg, msg.name.lower(), message_classes
)
data = QueueData(msg.DESCRIPTOR.name, msg)

# Throw data into queues and start again
# Throw data into queues and start again
await q1.put(data)
await q2.put(data)
except:
print("Fail")
pass
# except:
# print("Fail")
# pass
except (KeyError,TypeError,ValueError) as e:
print(f"Error with id {frameid}, error : {e}")
continue


2 changes: 1 addition & 1 deletion py_data_acq/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def run(logger):
path_to_mcap = "/home/nixos/recordings"
mcap_writer = HTPBMcapWriter(path_to_mcap, list_of_msg_names, True)
mcap_server = MCAPServer(mcap_writer=mcap_writer, path=path_to_mcap)

os.environ["D_SOURCE"] = "SERIAL"
# Get data source
match os.environ.get("D_SOURCE"):
case "SERIAL":
Expand Down

0 comments on commit afe79a3

Please sign in to comment.