Skip to content

Commit 6cae979

Browse files
committed
use netcat replacement for ebusctl (closes #1676, closes #1704)
1 parent 856bb0d commit 6cae979

File tree

7 files changed

+118
-387
lines changed

7 files changed

+118
-387
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ build-/
2828
*.gc*
2929
app.info
3030
/src/ebusd/ebusd
31-
/src/tools/ebusctl
3231
/src/tools/ebusfeed
3332
/src/lib/ebus/contrib/test/test_tem
3433
/src/lib/ebus/test/test_symbol

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The main features of the daemon are:
4242
* log messages and problems to a log file
4343
* capture messages or sent/received bytes to a log file as text
4444
* dump received bytes to binary files for later playback/analysis
45-
* listen for [command line client](https://github.com/john30/ebusd/wiki/3.1.-TCP-client-commands) connections on a dedicated TCP port
45+
* listen for [command line client](https://github.com/john30/ebusd/wiki/3.1.-TCP-client-commands) connections on a dedicated TCP port, e.g. by using netcat or the [wrapper ebusctl script](https://github.com/john30/ebusd/blob/master/contrib/scripts/ebusctl)
4646
* provide a rudimentary HTML interface
4747
* format messages and data in [JSON on dedicated HTTP port](https://github.com/john30/ebusd/wiki/3.2.-HTTP-client)
4848
* publish received data to [MQTT topics](https://github.com/john30/ebusd/wiki/3.3.-MQTT-client) and vice versa (if authorized)

contrib/scripts/ebusctl

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
# ebusctl - tool for accessing ebusd via TCP.
3+
# this can either pass excess arguments to ebusd and then quit,
4+
# or run interactively if no excess arguments were given.
5+
6+
# print help
7+
help() {
8+
cat << EOF
9+
Usage: ebusctl [OPTION...] [COMMAND...]
10+
Client for accessing ebusd via TCP.
11+
12+
Options:
13+
-s, --server=HOST Connect to ebusd on HOST (name or IP) [localhost]
14+
-p, --port=PORT Connect to ebusd on PORT [8888]
15+
-t, --timeout=SECS Timeout for connecting to/receiving from ebusd, 0 for
16+
none [60]
17+
-e, --error Exit non-zero if the connection was fine but the response
18+
indicates non-success
19+
[COMMAND...] COMMAND (and arguments) to send to ebusd.
20+
21+
If given, send COMMAND together with arguments to ebusd.
22+
Use 'help' as COMMAND for help on available ebusd commands.
23+
EOF
24+
}
25+
26+
# parse cmdline options
27+
OPTS=$(getopt -n ebusctl -o 's:p:t:eh' -l 'server:,port:,timeout:,error,help' -- "$@")
28+
if [ $? -ne 0 ]; then
29+
help
30+
exit 1
31+
fi
32+
eval set -- "$OPTS"
33+
server=localhost
34+
port=8888
35+
timeout=60
36+
error=
37+
while true; do
38+
case "$1" in
39+
'-s'|'--server')
40+
shift
41+
server="$1"
42+
shift
43+
if [ -z "$server" ]; then
44+
echo "invalid server" >&2
45+
exit 1
46+
fi
47+
continue
48+
;;
49+
'-p'|'--port')
50+
shift
51+
port="$1"
52+
shift
53+
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
54+
echo "invalid port" >&2
55+
exit 1
56+
fi
57+
continue
58+
;;
59+
'-t'|'--timeout')
60+
shift
61+
timeout="$1"
62+
shift
63+
if [ "$timeout" -lt 0 ] || [ "$timeout" -gt 3600 ]; then
64+
echo "invalid timeout" >&2
65+
exit 1
66+
fi
67+
continue
68+
;;
69+
'-e'|'--error')
70+
shift
71+
error=1
72+
continue
73+
;;
74+
'-h'|'--help')
75+
shift
76+
help
77+
exit
78+
;;
79+
'--')
80+
shift
81+
break
82+
;;
83+
*)
84+
echo "error" >&2
85+
exit 1
86+
;;
87+
esac
88+
done
89+
90+
# set arguments to netcat
91+
args=(-q 0)
92+
if [ "$timeout" -gt 0 ]; then
93+
args+=(-w "$timeout")
94+
fi
95+
args+=("$server" "$port")
96+
97+
# check interactive mode
98+
if [ $# -ne 0 ]; then
99+
# non-interactive mode
100+
ret=0
101+
while IFS= read -r line; do
102+
echo "$line"
103+
if [ -n "$error" ] && [ "${line##ERR:}" != "$line" ]; then
104+
ret=1
105+
fi
106+
done < <(echo "$@"|nc "${args[@]}")
107+
exit $ret
108+
fi
109+
110+
# interactive mode
111+
echo "entering interactive mode" >&2
112+
nc "${args[@]}"

make_debian.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ echo "*************"
117117
echo " pack"
118118
echo "*************"
119119
echo
120+
cp contrib/scripts/ebusctl $RELEASE/usr/bin/ || exit 1
121+
chmod a+x $RELEASE/usr/bin/ebusctl || exit 1
120122
mkdir -p $RELEASE/DEBIAN $RELEASE/etc/logrotate.d || exit 1
121123
cp contrib/etc/logrotate.d/ebusd $RELEASE/etc/logrotate.d/ || exit 1
122124
cp ChangeLog.md $RELEASE/DEBIAN/changelog || exit 1
@@ -129,7 +131,7 @@ Architecture: $ARCH
129131
Maintainer: John Baier <ebusd@ebusd.eu>
130132
Homepage: https://github.com/john30/ebusd
131133
Bugs: https://github.com/john30/ebusd/issues
132-
Depends: libstdc++6 (>= 4.8.1), libc6, libgcc1$extralibs
134+
Depends: netcat-openbsd, util-linux, bash, libstdc++6 (>= 4.8.1), libc6, libgcc1$extralibs
133135
Recommends: logrotate
134136
Description: eBUS daemon.
135137
ebusd is a daemon for handling communication with eBUS devices connected to a

src/tools/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
add_definitions(-Wno-unused-parameter)
22

3-
set(ebusctl_SOURCES ebusctl.cpp)
43
set(ebuspicloader_SOURCES ebuspicloader.cpp intelhex/intelhexclass.cpp)
54

65
include_directories(../lib/ebus)
76
include_directories(../lib/utils)
87
include_directories(intelhex)
98

10-
add_executable(ebusctl ${ebusctl_SOURCES})
119
add_executable(ebuspicloader ${ebuspicloader_SOURCES})
12-
target_link_libraries(ebusctl utils ebus ${ebusctl_LIBS})
1310
target_link_libraries(ebuspicloader utils ${ebuspicloader_LIBS})
1411

15-
install(TARGETS ebusctl ebuspicloader EXPORT ebusd DESTINATION bin)
12+
install(TARGETS ebuspicloader EXPORT ebusd DESTINATION bin)

src/tools/Makefile.am

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/src \
22
-isystem$(top_srcdir) \
33
-Wno-unused-parameter
44

5-
bin_PROGRAMS = ebusctl \
6-
ebuspicloader
7-
8-
ebusctl_SOURCES = ebusctl.cpp
9-
ebusctl_LDADD = ../lib/utils/libutils.a
5+
bin_PROGRAMS = ebuspicloader
106

117
ebuspicloader_SOURCES = ebuspicloader.cpp intelhex/intelhexclass.cpp
128
ebuspicloader_LDADD = ../lib/utils/libutils.a

0 commit comments

Comments
 (0)