From 91f7ea8f5f2e7debe2e8da05a3aa3901f91c47d6 Mon Sep 17 00:00:00 2001 From: Igor Socec Date: Fri, 9 Dec 2016 00:33:48 +0100 Subject: [PATCH] New version of configuration and control script --- moxanix2.cfg | 17 +++++++++++++++++ moxanix2.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 moxanix2.cfg create mode 100755 moxanix2.sh diff --git a/moxanix2.cfg b/moxanix2.cfg new file mode 100644 index 0000000..e2920d5 --- /dev/null +++ b/moxanix2.cfg @@ -0,0 +1,17 @@ +# Configuration format: +# tcp= tty= baud= +# +# Example: +# tcp=4001 tty=/dev/ttyS0 baud=115200 +# +# Supported baud rates: +# 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, +# 4800, 9600, 19200, 38400, 57600, 115200 +# + +tcp=4001 tty=/dev/ttyS1 baud=115200 +tcp=4002 tty=/dev/ttyS2 baud=115200 +tcp=4003 tty=/dev/ttyS3 baud=115200 +tcp=4004 tty=/dev/ttyS4 baud=115200 +tcp=4005 tty=/dev/ttyS5 baud=115200 +tcp=4006 tty=/dev/ttyS6 baud=115200 \ No newline at end of file diff --git a/moxanix2.sh b/moxanix2.sh new file mode 100755 index 0000000..2b738d7 --- /dev/null +++ b/moxanix2.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +CONFIGURATION_FILE="moxanix2.cfg" + +LINES=() +CONNECTIONS=() +SIZE=0 +ARGUMENTS=() + +read_config() +{ + # read lines from the configuration file + readarray LINES < $CONFIGURATION_FILE + + # count the number of configured connections and extract arguments + # while skipping comment lines and empty lines + count=0 + while [ "${LINES[count]}" != "" ] + do + LINE=${LINES[count]} + # filter lines and arguments according to the configuration format: + # tcp= tty= baud= + LINE_VALID=$(echo $LINE | grep -E "^tcp=") + if [ -n "$LINE_VALID" ]; then + CONNECTIONS[SIZE]=$LINE + TCP=$(echo $LINE | awk '{print $1}' | tr -d "tcp=") + TTY=$(echo $LINE | awk '{print $2}' | tr -d "tty=") + BAUD=$(echo $LINE | awk '{print $3}' | tr -d "baud=") + ARGUMENTS[SIZE]="-p $TCP -t $TTY -b $BAUD" + # increment size counter + SIZE=$(( $SIZE + 1 )) + fi + # increment line counter + count=$(( $count + 1 )) + done +} + +read_config +echo "size is $SIZE" +echo ${CONNECTIONS[3]} +echo ${ARGUMENTS[3]}