Skip to content

Commit 38db2d2

Browse files
committed
add typespec template option
1 parent 79371ce commit 38db2d2

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

contrib/scripts/readallvaillantregisters.sh

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ Helper script to read all Vaillant registers from an ebusd instance.
1515
-a, --addr=ZZ Address to read (hex) [08]
1616
-f, --from=NUM First register to read [0]
1717
-c, --count=NUM Number of registers to read [128]
18+
--tsp Create a TypeSpec template from the data
1819
EOF
1920
}
2021

2122
# 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+
OPTS=$(getopt -n ebusctl -o 's:p:t:a:f:c:h' -l 'server:,port:,timeout:,addr:,from:,count:,tsp,help' -- "$@")
2324
if [ $? -ne 0 ]; then
2425
help
2526
exit 1
@@ -31,6 +32,7 @@ timeout=60
3132
addr=08
3233
from=0
3334
count=128
35+
tsp=
3436
while true; do
3537
case "$1" in
3638
'-s'|'--server')
@@ -95,6 +97,10 @@ while true; do
9597
count=$(( $count ))
9698
continue
9799
;;
100+
'--tsp')
101+
shift
102+
tsp=1
103+
;;
98104
'-h'|'--help')
99105
shift
100106
help
@@ -125,9 +131,43 @@ if [ "$timeout" -gt 0 ]; then
125131
fi
126132
args+=("$server" "$port")
127133

134+
# emit tsp header if requested
135+
if [ -n "$tsp" ]; then
136+
cat << EOF
137+
import "@ebusd/ebus-typespec";
138+
import "./_templates.tsp";
139+
import "./hcmode_inc.tsp";
140+
import "./errors_inc.tsp";
141+
using Ebus;
142+
using Ebus.Num;
143+
using Ebus.Dtm;
144+
using Ebus.Str;
145+
namespace Vaillant;
146+
147+
// @zz(0x${addr})
148+
namespace circuit { // TODO use the circuit name from the scan result instead
149+
EOF
150+
fi
151+
128152
# query the registers
129153
for (( i=$from; i<$to; i++ )) ; do
130154
h=`printf "%4.4X" $i`
131155
ret=`echo "hex ${addr}b509030d${h##??}${h%%??}"|nc "${args[@]}"|head -n 1`
132-
echo $i "=" $ret
156+
if [ -z "$tsp" ]; then
157+
echo $i "=" $ret
158+
else
159+
d=$(echo "$ret"|egrep "^([0-9a-f][0-9a-f])*$"|head -n 1|sed -e 's#^..##')
160+
if [ -n "$d" ]; then
161+
echo " /** <describe the message> */"
162+
echo " @Ebus.example(\"<enter the value>\", \"31${addr}b5090d${h##??}${h%%??}\", \"$d\")"
163+
echo " @ext(0x${h##??}, 0x${h%%??})"
164+
echo " model Register$i is ReadonlyRegister<UCH>; // TODO rename 'Register...' to something meaningful (e.g. RoomTemp) and determine the right datatype/model instead of 'UCH' (e.g. as in _templates.tsp)"
165+
echo
166+
fi
167+
fi
133168
done
169+
170+
# emit tsp footer if requested
171+
if [ -n "$tsp" ]; then
172+
echo "}"
173+
fi

0 commit comments

Comments
 (0)