6e24309a871cab50cbe0d01a1a01568d6e8c611e
[mirrors/Programs.git] / bash / serial_loopback_test.sh
1 #!/bin/bash
2 #(c) Tomas Mudrunka 2022
3
4 [ -z "$1" ] && {
5 echo "Usage: $0 /dev/ttyTX [/dev/ttyRX]"
6 exit 1
7 }
8
9 port_tx="${1:-/dev/ttyUSB0}"
10 port_rx="${2:-$port_tx}"
11
12 testdata="${RANDOM}d82b2ae45432e7c80699852ab557b279c42180a379711aae85487bda0cc58602f65c0ab5af0d510d6ac1606c52f887f3332052f67c45212dbbf2730${RANDOM}"
13
14 echo "Running loopback test on $port_tx -> $port_rx"
15
16 stty -F "$port_tx" raw -echo
17 stty -F "$port_rx" raw -echo
18
19 exec 5>"$port_tx"
20 exec 6<"$port_rx"
21
22 errcnt=0
23 while true; do
24 echo "$testdata" >&5
25 unset line
26 read -rst 1 -u 6 line
27 #echo "LINE: $line"
28 [ "$line" != "$testdata" ] && {
29 ((errcnt=errcnt+1))
30 echo -e "$(date +'%D %T')\t$errcnt\tError receiving data $port_tx -> $port_rx"
31 }
32 done
33
34 exec 5>&-
35 exec 6<&-
This page took 0.278657 seconds and 3 git commands to generate.