Skip to content

Commit

Permalink
initial dynamic ody connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed Apr 14, 2024
1 parent 90cc901 commit c4f1283
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dev/scripts/alias.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ alias serial='/home/dev/scripts/serial.sh'
alias flash='/home/dev/scripts/flash.sh'
alias emulate='/home/dev/scripts/emulate.sh'
alias debug='/home/dev/scripts/gdb.sh'
alias ody-connect='/home/dev/scripts/ody-connect.sh'
alias ody-connect='source /home/dev/scripts/ody-connect.sh'
33 changes: 32 additions & 1 deletion dev/scripts/ody-connect.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
#!/bin/bash

usbip attach -r 192.168.100.12 -b "$USBIP_PORT"
# this script has to be sourced

if [[ -z "${USBIP_PORT}" || -z "${PROJECT_NAME}" ]]
then
echo "This project doesnt use USB/IP"
return 1
fi

if ls /dev/tty* | grep -q "$PROJECT_NAME" && [[ ! $(wc -l <(usbip port) | head -c 1) -eq 2 ]]
then
echo "Found /dev/tty$PROJECT_NAME, setting it to be used by container"
DEBUG_PORT="/dev/tty$PROJECT_NAME"
return 0
else
echo "Didn't find existing tty USB/IP connected"
rm "/dev/tty$PROJECT_NAME"
fi


PREV_LIST_OF_TARGETS=$(ls /dev/tty*)

if usbip attach -r 192.168.100.12 -b "$USBIP_PORT"
then
echo "Successfully attached, linking to /dev/tty$PROJECT_NAME"
# find the new target in the dev fs and symlink it to project name
ln -s /dev/tty$(diff -n <(echo "$PREV_LIST_OF_TARGETS") <(ls /dev/tty*) | tail -n 1) /dev/tty"$PROJECT_NAME"
DEBUG_PORT="/dev/tty$PROJECT_NAME"
else
echo "Failed to connect, please see below if any USB devices are available"
usbip list -r 192.168.100.12
return 1
fi
2 changes: 1 addition & 1 deletion dev/scripts/serial.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#! /bin/bash
minicom -b 115200 -o -D /dev/ttyACM0
minicom -b 115200 -o -D "$DEBUG_PORT"

0 comments on commit c4f1283

Please sign in to comment.