From c4f12832cd14147a7bb38d060176b9e312045211 Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Sun, 14 Apr 2024 17:05:55 -0400 Subject: [PATCH] initial dynamic ody connection --- dev/scripts/alias.sh | 2 +- dev/scripts/ody-connect.sh | 33 ++++++++++++++++++++++++++++++++- dev/scripts/serial.sh | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/dev/scripts/alias.sh b/dev/scripts/alias.sh index 4f4c16e..d32ef81 100755 --- a/dev/scripts/alias.sh +++ b/dev/scripts/alias.sh @@ -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' diff --git a/dev/scripts/ody-connect.sh b/dev/scripts/ody-connect.sh index 1e0d027..be4f661 100755 --- a/dev/scripts/ody-connect.sh +++ b/dev/scripts/ody-connect.sh @@ -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 diff --git a/dev/scripts/serial.sh b/dev/scripts/serial.sh index 74d18d6..e64749a 100755 --- a/dev/scripts/serial.sh +++ b/dev/scripts/serial.sh @@ -1,2 +1,2 @@ #! /bin/bash -minicom -b 115200 -o -D /dev/ttyACM0 +minicom -b 115200 -o -D "$DEBUG_PORT"