-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add snap packaging Add a snapcraft.yaml to support building the agent as a snap. Also add the install and configure hooks to support configuration, as well as a script to run the agent with the requested configuration. Signed-off-by: Kyle Fazzari <[email protected]> * s/system/transport/ Also update default port to 8888 and rename pseudo-serial to pseudoterminal. Signed-off-by: Kyle Fazzari <[email protected]> * Disable daemon upon install Signed-off-by: Kyle Fazzari <[email protected]>
- Loading branch information
Kyle Fazzari
authored
Sep 10, 2020
1 parent
f85c3d5
commit 1baab24
Showing
4 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/bin/sh -e | ||
|
||
# Confirm that the transport is valid | ||
transport="$(snapctl get transport)" | ||
case "$transport" in | ||
udp4) ;; | ||
udp6) ;; | ||
tcp4) ;; | ||
tcp6) ;; | ||
serial) ;; | ||
pseudoterminal) ;; | ||
*) | ||
echo "'$transport' is not a supported transport" >&2 | ||
return 1 | ||
;; | ||
esac | ||
|
||
# Confirm that the middleware is valid | ||
middleware="$(snapctl get middleware)" | ||
case "$middleware" in | ||
dds) ;; | ||
rtps) ;; | ||
ced) ;; | ||
*) | ||
echo "'$middleware' is not a supported middleware" >&2 | ||
return 1 | ||
;; | ||
esac | ||
|
||
if [ "$transport" = "serial" ] || [ "$transport" = "pseudoterminal" ]; then | ||
# A serial transport if being used, which requires a valid baud rate | ||
# as well as a valid device | ||
baudrate="$(snapctl get baudrate)" | ||
if ! expr "$baudrate" : '^[0-9]\+$' > /dev/null; then | ||
echo "'$baudrate' is not a valid baud rate" >&2 | ||
return 1 | ||
fi | ||
|
||
device="$(snapctl get device)" | ||
if [ -z "$device" ]; then | ||
echo "Device must be specified" >&2 | ||
return 1 | ||
fi | ||
else | ||
port="$(snapctl get port)" | ||
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then | ||
echo "'$port' is not a valid port" >&2 | ||
return 1 | ||
fi | ||
fi | ||
|
||
# Confirm that discovery is a boolean | ||
discovery="$(snapctl get discovery)" | ||
case "$discovery" in | ||
true) | ||
# Confirm that discovery port is valid | ||
port="$(snapctl get discovery-port)" | ||
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then | ||
echo "'$port' is not a valid discovery port" >&2 | ||
return 1 | ||
fi | ||
;; | ||
false) ;; | ||
*) | ||
echo "'$discovery' is not a valid boolean for discovery" >&2 | ||
return 1 | ||
;; | ||
esac | ||
|
||
# Confirm that the verbosity is valid | ||
verbosity="$(snapctl get verbosity)" | ||
if ! expr "$verbosity" : '^[0-6]$' > /dev/null; then | ||
echo "'$verbosity' is not a valid verbosity" >&2 | ||
return 1 | ||
fi | ||
|
||
# Confirm that p2p port is valid (assuming it's set) | ||
p2p_port="$(snapctl get p2p-port)" | ||
if [ -n "$p2p_port" ]; then | ||
port="$(snapctl get p2p-port)" | ||
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then | ||
echo "'$port' is not a valid p2p port" >&2 | ||
return 1 | ||
fi | ||
fi | ||
|
||
# Confirm that daemon is a boolean, and enable the service if true | ||
daemon="$(snapctl get daemon)" | ||
case "$daemon" in | ||
true) | ||
snapctl start --enable "$SNAP_INSTANCE_NAME.daemon" | ||
|
||
# In case it was alraedy started and the configuration changed, | ||
# restart the service | ||
snapctl restart "$SNAP_INSTANCE_NAME.daemon" | ||
;; | ||
false) | ||
snapctl stop --disable "$SNAP_INSTANCE_NAME.daemon" | ||
;; | ||
*) | ||
echo "'$daemon' is not a valid boolean for daemon" >&2 | ||
return 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh -e | ||
|
||
# Set default configuration values | ||
snapctl set transport=udp4 | ||
snapctl set middleware=dds | ||
snapctl set verbosity=4 | ||
snapctl set discovery=false | ||
snapctl set discovery-port=7400 | ||
snapctl set p2p-port! # unset | ||
|
||
# Network-specific things | ||
snapctl set port=8888 | ||
|
||
# Serial-specific things | ||
snapctl set baudrate=115200 | ||
snapctl set device! # unset | ||
|
||
# By default the daemon is disabled | ||
snapctl set daemon=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/sh -e | ||
|
||
set -- --middleware "$(snapctl get middleware)" "$@" | ||
set -- --verbose "$(snapctl get verbosity)" "$@" | ||
|
||
transport="$(snapctl get transport)" | ||
if [ "$transport" = "serial" ] || [ "$transport" = "pseudoterminal" ]; then | ||
set -- --dev "$(snapctl get device)" "$@" | ||
else | ||
set -- --port "$(snapctl get port)" "$@" | ||
fi | ||
|
||
if [ "$(snapctl get discovery)" = "true" ]; then | ||
set -- --discovery "$@" | ||
|
||
discovery_port="$(snapctl get discovery-port)" | ||
if [ -n "$discovery_port" ]; then | ||
set -- --disport "$discovery_port" "$@" | ||
fi | ||
fi | ||
|
||
p2p_port="$(snapctl get p2p-port)" | ||
if [ -n "$p2p_port" ]; then | ||
set -- --p2p "$p2p_port" "$@" | ||
fi | ||
|
||
exec "$SNAP/usr/bin/MicroXRCEAgent" "$transport" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
name: micro-xrce-dds-agent | ||
base: core20 | ||
version: git | ||
summary: Bridge between Micro XRCE-DDS clients and DDS | ||
description: | | ||
Micro XRCE-DDS Agents receive messages containing Operations from | ||
Clients. Agents keep track of the Clients and the Micro XRCE-DDS | ||
Entities they create. The Agent uses the Entities to interact with | ||
DDS Global Data Space on behalf of the Client. | ||
The communication between a Micro XRCE-DDS Client and a Micro | ||
XRCE-DDS Agent supports three kind transport: UDP, TCP, or SerialPort. | ||
While running Micro XRCE-DDS Agent will attend any received | ||
request from your Micro XRCE-DDS Clients. Micro XRCE-DDS Agent | ||
answers back with the result of a request each time a request is | ||
attended. | ||
The Agent supports being run by the user like this: | ||
$ micro-xrce-dds-agent --help | ||
In addition, the Agent supports running as a service that can be | ||
enabled with: | ||
$ snap set micro-xrce-dds-agent daemon=true | ||
If the service is enabled, by default it uses the `udp4` transport on | ||
port 8888. The following parameters can be changed (these are | ||
specific to the service, the `micro-xrce-dds-agent` command simply | ||
takes command-line arguments, but the capabilities are the same): | ||
* `transport`. Supported transports are `udp4`, `udp6`, `tcp4`, | ||
`tcp6`, `serial`, and `pseudoterminal`. Default is `udp4`. Change | ||
with: | ||
$ snap set micro-xrce-dds-agent transport="new transport" | ||
* `middleware`. Supported kinds of middleware are `ced`, `rtps`, and | ||
`dds`. Default is `dds`. Change with: | ||
$ snap set micro-xrce-dds-agent middleware="new middleware" | ||
* `verbosity`. Supported verbosity levels are 0-6, defaulting to 4. | ||
Change with: | ||
$ snap set micro-xrce-dds-agent verbosity="selected verbosity" | ||
* `discovery`. Enable or disable the discovery server. Defaults to | ||
"false". Change with: | ||
$ snap set micro-xrce-dds-agent discovery="true or false" | ||
* `discovery-port`. Port on which the discovery server (see above) | ||
listens. Defaults to 7400. Change with: | ||
$ snap set micro-xrce-dds-agent discovery-port="selected port" | ||
* `p2p-port`. Port to use for the P2P profile. Change with: | ||
$ snap set micro-xrce-dds-agent p2p-port="selected port" | ||
* `port`. Port on which the agent listens. Only applicable to one of | ||
the UDP or TCP transports (see above). Defaults to 8888. Change with: | ||
$ snap set micro-xrce-dds-agent port="selected port" | ||
* `baudrate`. Baud rate to use when accessing serial ports. Only | ||
applicable when using the `serial` or `pseudoterminal` transport. | ||
Defaults to 115200. Change with: | ||
$ snap set micro-xrce-dds-agent baudrate="baud rate" | ||
* `device`. The serial device to use. Only applicable when using the | ||
`serial` or `pseudoterminal` transport. Change with: | ||
$ snap set micro-xrce-dds-agent device="device path" | ||
grade: stable | ||
confinement: strict | ||
|
||
architectures: | ||
- build-on: amd64 | ||
- build-on: arm64 | ||
- build-on: armhf | ||
- build-on: ppc64el | ||
|
||
parts: | ||
agent: | ||
plugin: cmake | ||
source: . | ||
cmake-parameters: [-DCMAKE_INSTALL_PREFIX=/usr] | ||
build-packages: [make, gcc, g++] | ||
|
||
runner: | ||
plugin: dump | ||
source: snap/local/ | ||
organize: | ||
'*': usr/bin/ | ||
|
||
apps: | ||
micro-xrce-dds-agent: | ||
command: usr/bin/MicroXRCEAgent | ||
plugs: [network, network-bind, serial-port] | ||
|
||
daemon: | ||
command: usr/bin/MicroXRCEAgent-daemon | ||
daemon: simple | ||
plugs: [network, network-bind, serial-port] |