nyni je funkce
[mirrors/Programs.git] / bash / serial_loopback_test.sh
index f160b2da06bcae539970abb0cc22bdfd3c904866..8b945fa5ca4d554c8d8c180ddcc008e908c2aeae 100755 (executable)
@@ -1,6 +1,11 @@
 #!/bin/sh
-#Serial line tester, should work in busybox ash
+#
+#Serial line tester v0.3
 #(c) Tomas Mudrunka 2022-2024
+#
+#Tested in: busybox ash, bash
+
+function serial_loopback_test() {
 
 trylimit=0
 seconds=0
@@ -54,9 +59,8 @@ while true; do
        unset line
        read -rst 1 -u 6 line
        #echo "LINE: $line"
-       [ "$line" != "$testdata" ] && {
+       [ "$line" != "$testdata" ] && errcnt=$((errcnt+1)) &&
                echo -e "$(date +'%D %T')\t$errcnt\tError receiving data $port_tx -> $port_rx"
-       } && errcnt=$((errcnt+1))
        trycnt=$((trycnt+1))
        #echo "try $trycnt err $errcnt lim $trylimit"
        [ $trylimit -gt 0 -a $trycnt -gt $trylimit ] && break
@@ -69,3 +73,7 @@ exec 6<&-
 echo TRANSMITTED: $trycnt, ERRORS: $errcnt, SECONDS: $(($(date +%s)-$datestart))
 [ "$errcnt" = "0" -a "$trycnt" -gt 0 ] && exit 0
 exit 255
+
+}
+
+serial_loopback_test "$@"
This page took 0.101032 seconds and 4 git commands to generate.