3 #Serial line tester v0.3
4 #(c) Tomas Mudrunka 2022-2024
6 #Tested in: busybox ash, bash
8 function serial_loopback_test
() {
13 workaround_rs485
=false
15 while getopts ":t:r:b:l:s:w" OPT
; do
16 #echo "$OPT ==> $OPTARG";
23 w
) workaround_rs485
=true
;;
25 '?') echo "Usage: $0 -t /dev/ttyTX [-r /dev/ttyRX] [-b 9600] [-l 10] [-s 10] [-w]" >&2; exit 250;;
26 ':') echo "Missing option argument for -$OPTARG" >&2; exit 251;;
27 * ) echo "Unimplemented option: -$OPT" >&2; exit 252;;
31 [ -z "$port_tx" ] && port_tx
="$port_rx"
32 [ -z "$port_rx" ] && port_rx
="$port_tx"
33 [ -z "$port_rx" ] && { echo Port not specified
; exit 253; }
36 testdata
="${RANDOM}d82b2ae45432e7c80699852ab557b279c42180a379711aae85487bda0cc58602f65c0ab5af0d510d6ac1606c52f887f3332052f67c45212dbbf2730${RANDOM}"
38 echo "Running $baudrate baud loopback test on $port_tx -> $port_rx"
39 echo "Limiting to $trylimit iterations and $seconds seconds (0 = no limit)"
41 stty
-F "$port_tx" raw
-echo "$baudrate"
42 stty
-F "$port_rx" raw
-echo "$baudrate"
47 $workaround_rs485 && {
48 echo "Deasserting RTS on buggy RS485 drivers by writing to RX port"
55 datestart
="$(date +%s)"
56 dateend
="$(($datestart+$seconds))"
62 [ "$line" != "$testdata" ] && errcnt
=$
((errcnt
+1)) &&
63 echo -e "$(date +'%D %T')\t$errcnt\tError receiving data $port_tx -> $port_rx"
65 #echo "try $trycnt err $errcnt lim $trylimit"
66 [ $trylimit -gt 0 -a $trycnt -gt $trylimit ] && break
67 [ $seconds -gt 0 ] && [ $
(date +%s
) -gt $dateend ] && break
73 echo TRANSMITTED
: $trycnt, ERRORS
: $errcnt, SECONDS
: $
(($
(date +%s
)-$datestart))
74 [ "$errcnt" = "0" -a "$trycnt" -gt 0 ] && exit 0
79 serial_loopback_test
"$@"
This page took 0.357197 seconds and 5 git commands to generate.