diff --git a/CMakeLists.txt b/CMakeLists.txt index 35fc4d4..7800c71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,16 @@ rclcpp_components_register_node(zenoh_bridge_component EXECUTABLE zenoh_bridge ) +add_executable(get_default_config + src/bin/get_default_config.cpp +) +target_link_libraries(get_default_config + zenohcxx::zenohc + fmt::fmt +) + ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) -install(TARGETS zenoh_bridge_component +install(TARGETS zenoh_bridge_component get_default_config EXPORT export_${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib diff --git a/launch/test.launch.xml b/launch/test.launch.xml index 90c0e7c..241d31f 100644 --- a/launch/test.launch.xml +++ b/launch/test.launch.xml @@ -1,8 +1,10 @@ + + diff --git a/params/DEFAULT_CONFIG.json5 b/params/DEFAULT_CONFIG.json5 new file mode 100644 index 0000000..1d4cf31 --- /dev/null +++ b/params/DEFAULT_CONFIG.json5 @@ -0,0 +1,41 @@ +{ + /// The node's mode (router, peer or client) + mode: "peer", + + /// The node's metadata (name, location, DNS name, etc.) Arbitrary JSON data not interpreted by zenoh and available in admin space @//router, @//peer or @//client + metadata: { + }, + + /// Which endpoints to connect to. E.g. tcp/localhost:7447. + /// By configuring the endpoints, it is possible to tell zenoh which router/peer to connect to at startup. + connect: { + /// timeout waiting for all endpoints connected (0: no retry, -1: infinite timeout) + /// Accepts a single value (e.g. timeout_ms: 0) + /// or different values for router, peer and client (e.g. timeout_ms: { router: -1, peer: -1, client: 0 }). + timeout_ms: { router: -1, peer: -1, client: 0 }, + + /// The list of endpoints to connect to. + /// Accepts a single list (e.g. endpoints: ["tcp/10.10.10.10:7447", "tcp/11.11.11.11:7447"]) + /// or different lists for router, peer and client (e.g. endpoints: { router: ["tcp/10.10.10.10:7447"], peer: ["tcp/11.11.11.11:7447"] }). + /// + /// See https://docs.rs/zenoh/latest/zenoh/config/struct.EndPoint.html + endpoints: [ + // "/
" + ], + + }, + + /// Which endpoints to listen on. E.g. tcp/0.0.0.0:7447. + /// By configuring the endpoints, it is possible to tell zenoh which are the endpoints that other routers, + /// peers, or client can use to establish a zenoh session. + listen: { + + /// The list of endpoints to listen on. + /// Accepts a single list (e.g. endpoints: ["tcp/[::]:7447", "udp/[::]:7447"]) + /// or different lists for router, peer and client (e.g. endpoints: { router: ["tcp/[::]:7447"], peer: ["tcp/[::]:0"] }). + /// + /// See https://docs.rs/zenoh/latest/zenoh/config/struct.EndPoint.html + endpoints: ["tcp/[::]:0"], + + }, +} diff --git a/src/ZenohBridge.cpp b/src/ZenohBridge.cpp index f3abe71..d0699cf 100644 --- a/src/ZenohBridge.cpp +++ b/src/ZenohBridge.cpp @@ -18,17 +18,17 @@ namespace j7s ZenohBridge::ZenohBridge(const rclcpp::NodeOptions & options) : Node("zenoh_bridge", options) { - // Should this be from a file? - // TODO: static inline Config from_file(const std::string &path, ZResult *err = nullptr) - auto config = zenoh::Config::create_default(); - m_zenohSession = std::make_shared(std::move(config)); - const auto emptyVector = std::vector(); const auto zenohSourceNames = this->declare_parameter>("zenoh_sources", emptyVector); const auto rosSourceNames = this->declare_parameter>("ros_sources", emptyVector); + const auto zenohConfigPath = this->declare_parameter("zenoh_config_path"); + auto config = zenoh::Config::from_file(zenohConfigPath); + m_zenohSession = std::make_shared(std::move(config)); + + // Make all the zenoh subs. for (const auto & source : zenohSourceNames) { diff --git a/src/bin/get_default_config.cpp b/src/bin/get_default_config.cpp new file mode 100644 index 0000000..6d60a8a --- /dev/null +++ b/src/bin/get_default_config.cpp @@ -0,0 +1,20 @@ +// +// Copyright 2026 James Pace +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +// +// This Source Code Form is "Incompatible With Secondary Licenses", as +// defined by the Mozilla Public License, v. 2.0. +// +#include +#include "zenoh.hxx" + + +int main(int, char **) +{ + const auto config = zenoh::Config::create_default(); + const auto configJson = config.to_string(); + std::cout << configJson << std::endl; +}