New version of configuration and control script
This commit is contained in:
parent
35f9b0b644
commit
91f7ea8f5f
2 changed files with 58 additions and 0 deletions
17
moxanix2.cfg
Normal file
17
moxanix2.cfg
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Configuration format:
|
||||||
|
# tcp=<tcp_port> tty=<tty_device> baud=<tty_baudrate>
|
||||||
|
#
|
||||||
|
# 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
|
41
moxanix2.sh
Executable file
41
moxanix2.sh
Executable file
|
@ -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=<tcp_port> tty=<tty_device> baud=<tty_baudrate>
|
||||||
|
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]}
|
Loading…
Add table
Add a link
Reference in a new issue