Skip to content

Commit 05d3428

Browse files
Merge pull request #73 from CU-Robotics/patch-tty-separation
Move tty id finding to get_tty_path.sh
2 parents fef4e2b + afab7ab commit 05d3428

File tree

4 files changed

+54
-33
lines changed

4 files changed

+54
-33
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ upload: build
9797
@echo [Uploading] - If this fails, press the button on the teensy and re-run make upload
9898
@tycmd upload $(PROJECT_NAME).hex
9999
# Teensy serial isn't immediately available after upload, so we wait a bit
100-
@sleep 0.25s
100+
# The teensy waits for 20 + 280 + 20 ms after power up/boot
101+
@sleep 0.4s
101102
@bash tools/monitor.sh
102103

103104
# # # Clean Targets # # #

tools/get_tty_path.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# This finds the correct ttyACM device. First argument passed in should be the device ID.
4+
# Example usage: tty_path=$(./tools/get_tty_path.sh *-f00)
5+
6+
# Device id, passed in as first argument with $1.
7+
tty_id=$1
8+
9+
# path to the /dev/ serial device that the Teensy is connected to
10+
tty_path=""
11+
12+
# if no first argument provided
13+
if [ ! -n "$tty_id" ]; then
14+
# 1>&2 redirects stdout (1) into stderr (2)
15+
echo "\"$1\" is not a valid tty ID" 1>&2
16+
exit 1
17+
fi
18+
19+
# Find the correct serial device
20+
# The important part is the ID/interface number at the end, which is compared here
21+
for i in /dev/serial/by-id/*; do
22+
# compare with first argument passed to this command
23+
if [[ "$i" == $tty_id ]]; then
24+
tty_path=$i
25+
break
26+
fi
27+
done
28+
29+
# found the id, now we need the actual path to the specific ttyACM device
30+
if [ -n "$tty_path" ]; then
31+
tty_path=$(readlink -f $tty_path)
32+
fi
33+
34+
# if no tty path found
35+
if [ ! -n "$tty_path" ]; then
36+
# 1>&2 redirects stdout (1) into stderr (2)
37+
echo "Failed to find the correct serial device for Teensy with tty_id '$tty_id' " 1>&2
38+
echo "This probably means the Teensy is not connected or the Teensy is in bootloader mode (red LED on/blinking)" 1>&2
39+
40+
exit 1
41+
fi
42+
43+
echo $tty_path # outputs to stdout by default
44+
45+
exit 0

tools/monitor.sh

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# path to the /dev/ serial device that the Teensy is connected to
2-
tty_path=""
1+
#!/bin/bash
32

43
# handle sigint in a strange way to not break tycmd monitor
54
trap 'exit 0' INT;
@@ -9,18 +8,7 @@ trap 'exit 0' INT;
98
# where * is a number
109
# The important part is the "if00" at the end, its interface number 00
1110

12-
# Find the correct serial device
13-
for i in /dev/serial/by-id/*; do
14-
if [[ "$i" == *-if00 ]]; then
15-
tty_path=$i
16-
break
17-
fi
18-
done
19-
20-
# found the id, now we need the actual path to the specific ttyACM device
21-
if [ -n "$tty_path" ]; then
22-
tty_path=$(readlink -f $tty_path)
23-
fi
11+
tty_path=$(./tools/get_tty_path.sh *-if00)
2412

2513
# If the tty path is not empty, we can start the monitor
2614
if [ -n "$tty_path" ]; then
@@ -32,8 +20,7 @@ if [ -n "$tty_path" ]; then
3220
exit 0
3321
else
3422
# failed to find the correct serial device
35-
echo "Failed to monitor: Could not find the correct serial device for Teensy"
36-
echo "This probably means the Teensy is not connected or the Teensy is in bootloader mode (red LED on/blinking)"
23+
echo "Failed to monitor."
3724

3825
exit 1
3926
fi

tools/prepare_gdb.sh

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
# This finds the correct ttyACM device and puts it into gdb_commands.txt
24

35
# The correct serial device has the following name
@@ -6,29 +8,15 @@
68
# The important part is the "if02" at the end, its interface number 02
79
# SerialUSB1 is what interface 02 references
810

9-
tty_path=""
10-
11-
# Find the correct serial device
12-
for i in /dev/serial/by-id/*; do
13-
if [[ "$i" == *-if02 ]]; then
14-
tty_path=$i
15-
break
16-
fi
17-
done
18-
19-
# found the id, now we need the actual path to the specific ttyACM device
20-
if [ -n "$tty_path" ]; then
21-
tty_path=$(readlink -f $tty_path)
22-
fi
11+
tty_path=$(./tools/get_tty_path.sh *-if02)
2312

2413
# Now we put it into gdb_commands.txt
2514
if [ -n "$tty_path" ]; then
2615
echo "target remote $tty_path" > ./tools/gdb_commands.txt
2716

2817
exit 0
2918
else
30-
echo "Failed to find the correct serial device for Teensy"
31-
echo "This probably means the Teensy is not connected or the Teensy is in bootloader mode (red LED on/blinking)"
19+
echo "Failed to prepare gdb"
3220

3321
exit 1
3422
fi

0 commit comments

Comments
 (0)