|
1 | 1 | #!/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 |
7 | 26 | fi |
| 27 | +eval set -- "$OPTS" |
| 28 | +server=localhost |
| 29 | +port=8888 |
| 30 | +timeout=60 |
8 | 31 | 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") |
13 | 125 | 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 |
15 | 130 | 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` |
17 | 132 | echo $i "=" $ret |
18 | 133 | done |
0 commit comments