Skip to content

Commit 79371ce

Browse files
committed
enhance util scripts
1 parent 5ae6744 commit 79371ce

2 files changed

Lines changed: 218 additions & 23 deletions

File tree

contrib/scripts/readall.sh

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,102 @@
1-
#!/bin/sh
2-
port=8888
3-
if [ "x$1" = "x-p" ]; then
4-
shift
5-
port=$1
6-
shift
1+
#!/bin/bash
2+
3+
# print help
4+
help() {
5+
cat << EOF
6+
Usage: $0 [OPTION...] [FIND-ARGS...]
7+
Helper script to read all known/matching messages from an ebusd instance.
8+
9+
Options:
10+
-s, --server=HOST Connect to ebusd on HOST (name or IP) [localhost]
11+
-p, --port=PORT Connect to ebusd on PORT [8888]
12+
-t, --timeout=SECS Timeout for connecting to/receiving from ebusd, 0 for
13+
none [60]
14+
-R, --readargs=... Additional arguments to pass to the 'read' command []
15+
16+
If given, FIND-ARGS can be used to pass arguments to the 'find' command to
17+
limit/widen the message list, e.g. '-c hwc' for the 'hwc' circuit.
18+
EOF
19+
}
20+
21+
# parse cmdline options
22+
OPTS=$(getopt -n ebusctl -o 's:p:t:R:h' -l 'server:,port:,timeout:,readargs:,help' -- "$@")
23+
if [ $? -ne 0 ]; then
24+
help
25+
exit 1
726
fi
27+
eval set -- "$OPTS"
28+
server=localhost
29+
port=8888
30+
timeout=60
831
readargs=
9-
if [ "x$1" = "x-R" ]; then
10-
shift
11-
readargs=$1
12-
shift
32+
while true; do
33+
case "$1" in
34+
'-s'|'--server')
35+
shift
36+
server="$1"
37+
shift
38+
if [ -z "$server" ]; then
39+
echo "invalid server" >&2
40+
exit 1
41+
fi
42+
continue
43+
;;
44+
'-p'|'--port')
45+
shift
46+
port="$1"
47+
shift
48+
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
49+
echo "invalid port" >&2
50+
exit 1
51+
fi
52+
continue
53+
;;
54+
'-t'|'--timeout')
55+
shift
56+
timeout="$1"
57+
shift
58+
if [ "$timeout" -lt 0 ] || [ "$timeout" -gt 3600 ]; then
59+
echo "invalid timeout" >&2
60+
exit 1
61+
fi
62+
continue
63+
;;
64+
'-R'|'--readargs')
65+
shift
66+
readargs="$1"
67+
shift
68+
continue
69+
;;
70+
'-h'|'--help')
71+
shift
72+
help
73+
exit
74+
;;
75+
'--')
76+
shift
77+
break
78+
;;
79+
*)
80+
echo "error" >&2
81+
exit 1
82+
;;
83+
esac
84+
done
85+
86+
# set arguments to netcat
87+
args=(-q 0)
88+
if [ "$timeout" -gt 0 ]; then
89+
args+=(-w "$timeout")
1390
fi
14-
for i in `echo "f -F circuit,name" "$@"|nc -q 1 127.0.0.1 $port|sort -u|grep ','`; do
91+
args+=("$server" "$port")
92+
93+
# query the messages
94+
for i in `echo "f -F circuit,name" "$@"|nc "${args[@]}"|sort -u|grep ','`; do
1595
circuit=${i%%,*}
1696
name=${i##*,}
1797
if [ -z "$circuit" ] || [ -z "$name" ] || [ "$circuit,$name" = "scan,id" ]; then
1898
continue
1999
fi
20-
ret=`echo "r ${readargs} -c $circuit $name" |nc -q 1 127.0.0.1 $port|head -n 1`
100+
ret=`echo "r ${readargs} -c $circuit $name" |nc "${args[@]}"|head -n 1`
21101
echo "$circuit $name = $ret"
22102
done
Lines changed: 126 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,133 @@
11
#!/bin/bash
2-
port=8888
3-
if [ "x$1" = "x-p" ]; then
4-
shift
5-
port=$1
6-
shift
2+
# readallvaillantregisters.sh - helper script to read all Vaillant registers from an ebusd instance.
3+
4+
# print help
5+
help() {
6+
cat << EOF
7+
Usage: $0 [OPTION...]
8+
Helper script to read all Vaillant registers from an ebusd instance.
9+
10+
Options:
11+
-s, --server=HOST Connect to ebusd on HOST (name or IP) [localhost]
12+
-p, --port=PORT Connect to ebusd on PORT [8888]
13+
-t, --timeout=SECS Timeout for connecting to/receiving from ebusd, 0 for
14+
none [60]
15+
-a, --addr=ZZ Address to read (hex) [08]
16+
-f, --from=NUM First register to read [0]
17+
-c, --count=NUM Number of registers to read [128]
18+
EOF
19+
}
20+
21+
# parse cmdline options
22+
OPTS=$(getopt -n ebusctl -o 's:p:t:a:f:c:h' -l 'server:,port:,timeout:,addr:,from:,count:,help' -- "$@")
23+
if [ $? -ne 0 ]; then
24+
help
25+
exit 1
726
fi
27+
eval set -- "$OPTS"
28+
server=localhost
29+
port=8888
30+
timeout=60
831
addr=08
9-
if [ "x$1" = "x-a" ]; then
10-
shift
11-
addr=$1
12-
shift
32+
from=0
33+
count=128
34+
while true; do
35+
case "$1" in
36+
'-s'|'--server')
37+
shift
38+
server="$1"
39+
shift
40+
if [ -z "$server" ]; then
41+
echo "invalid server" >&2
42+
exit 1
43+
fi
44+
continue
45+
;;
46+
'-p'|'--port')
47+
shift
48+
port="$1"
49+
shift
50+
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
51+
echo "invalid port" >&2
52+
exit 1
53+
fi
54+
continue
55+
;;
56+
'-t'|'--timeout')
57+
shift
58+
timeout="$1"
59+
shift
60+
if [ "$timeout" -lt 0 ] || [ "$timeout" -gt 3600 ]; then
61+
echo "invalid timeout" >&2
62+
exit 1
63+
fi
64+
continue
65+
;;
66+
'-a'|'--addr')
67+
shift
68+
addr="$1"
69+
shift
70+
if [ "${#addr}" != 2 ]; then
71+
echo "invalid addr" >&2
72+
exit 1
73+
fi
74+
continue
75+
;;
76+
'-f'|'--from')
77+
shift
78+
from="$1"
79+
shift
80+
if [ "$from" -lt 0 ] || [ "$from" -gt 65535 ]; then
81+
echo "invalid from" >&2
82+
exit 1
83+
fi
84+
from=$(( $from ))
85+
continue
86+
;;
87+
'-c'|'--count')
88+
shift
89+
count="$1"
90+
shift
91+
if [ "$count" -lt 1 ] || [ "$count" -gt 65535 ]; then
92+
echo "invalid count" >&2
93+
exit 1
94+
fi
95+
count=$(( $count ))
96+
continue
97+
;;
98+
'-h'|'--help')
99+
shift
100+
help
101+
exit
102+
;;
103+
'--')
104+
shift
105+
break
106+
;;
107+
*)
108+
echo "error" >&2
109+
exit 1
110+
;;
111+
esac
112+
done
113+
114+
# check from/to bounds
115+
to=$(( $from + $count ))
116+
if [ "$to" -gt 65535 ]; then
117+
echo "invalid from/count" >&2
118+
exit 1
119+
fi
120+
121+
# set arguments to netcat
122+
args=(-q 0)
123+
if [ "$timeout" -gt 0 ]; then
124+
args+=(-w "$timeout")
13125
fi
14-
for (( i=0; i<512; i++ )) ; do
126+
args+=("$server" "$port")
127+
128+
# query the registers
129+
for (( i=$from; i<$to; i++ )) ; do
15130
h=`printf "%4.4X" $i`
16-
ret=`echo "hex ${addr}b509030d${h##??}${h%%??}"|nc -q 1 localhost $port|head -n 1`
131+
ret=`echo "hex ${addr}b509030d${h##??}${h%%??}"|nc "${args[@]}"|head -n 1`
17132
echo $i "=" $ret
18133
done

0 commit comments

Comments
 (0)