-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshm-modbus
More file actions
executable file
·128 lines (107 loc) · 2.95 KB
/
shm-modbus
File metadata and controls
executable file
·128 lines (107 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
VERSION="2.1.7"
EXEC_COMMANDS=( \
"modbus-tcp-client-shm" \
"modbus-rtu-client-shm" \
"dump-shm" \
"write-shm" \
"stdin-to-modbus-shm" \
"shared-mem-random" \
"shm-modbus-signal-gen" \
"wago-modbus-coupler-shm" \
"shm-modbus-gui" \
"shm-format" \
)
# default command: shm-modbus-gui
if [[ "$#" -lt 1 ]] ; then
command="shm-modbus-gui"
else
command=${1}
fi
trap "exit 0" INT TERM
function print_help {
echo "usage: $(basename "$0") [OPTION] command [CMD_OPTION..]"
echo ""
echo " This script is a launcher script for several Modbus client simulator programs."
echo " Use --help as argument for commands to get more information about the usage of the program."
echo ""
echo " options:"
echo " -h --help show this message"
echo " --help-all show usage message of all Modbus tools"
echo " --gui start GUI (default)"
echo " --version show version of this script"
echo " --version-all show version of all Modbus tools"
echo ""
echo " commands:"
for cmd in "${EXEC_COMMANDS[@]}"
do
printf ' %-25s execute %s with the given arguments' "${cmd}" "${cmd}"
echo ""
done
}
if [[ "${command}" = "--help" ]] || [[ "${command}" = "-h" ]]; then
print_help
exit 0
fi
if [[ "${command}" = "--gui" ]]; then
command="shm-modbus-gui"
fi
if [[ "${command}" = "--help-all" ]]; then
echo "===============> shm-modbus <==============="
print_help
echo ""
echo ""
for cmd in "${EXEC_COMMANDS[@]}"
do
echo "===============> ${cmd} <==============="
if ! command -v "${cmd}" > /dev/null
then
>&2 echo "ERROR: command \"${cmd}\" not found in \$PATH"
else
"${cmd}" --help
fi
echo ""
echo ""
done
exit 0
fi
if [[ "${command}" = "--version" ]]; then
echo "shm-modbus ${VERSION}"
exit 0
fi
if [[ "${command}" = "--version-all" ]]; then
echo "shm-modbus ${VERSION}"
for cmd in "${EXEC_COMMANDS[@]}"
do
printf " > "
if [[ "${cmd}" = "shm-modbus-signal-gen" ]]; then
printf "%s " "${cmd}"
fi
if ! command -v "${cmd}" > /dev/null
then
>&2 echo "ERROR: command \"${cmd}\" not found in \$PATH"
else
"${cmd}" --version
fi
done
exit 0
fi
# for compatibility reasons, may be removed in future version
if [[ "${command}" = "signal-gen" ]]; then
command="shm-modbus-signal-gen"
fi
for cmd in "${EXEC_COMMANDS[@]}"
do
if [[ "${command}" = "${cmd}" ]]; then
trap "" INT TERM
if ! command -v "${command}" > /dev/null
then
>&2 echo "ERROR: command \"${cmd}\" not found in \$PATH"
exit 127
fi
"${command}" "${@:2}"
exit $?
fi
done
>&2 echo "unknown command: ${command}"
exit 64