From 5df706ee4ceda7715310ebbf0f6d466593ae965d Mon Sep 17 00:00:00 2001 From: Yuqi Huai <34195403+YuqiHuai@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:34:17 -0800 Subject: [PATCH] refactor(bluetooth_monitor): rework parameters (#5239) * refactor(bluetooth_monitor): rework parameters Signed-off-by: Yuqi Huai * style(pre-commit): autofix * doc(bluetooth_monitor): fix default for integer parameters Signed-off-by: Yuqi Huai * doc(bluetooth_monitor): add default for parameter addresses Signed-off-by: Yuqi Huai * style(pre-commit): autofix * doc(bluetooth_monitor): fix parameter description --------- Signed-off-by: Yuqi Huai Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- system/bluetooth_monitor/README.md | 7 +-- .../schema/bluetooth_monitor.shcema.json | 51 +++++++++++++++++++ .../src/bluetooth_monitor.cpp | 8 +-- 3 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 system/bluetooth_monitor/schema/bluetooth_monitor.shcema.json diff --git a/system/bluetooth_monitor/README.md b/system/bluetooth_monitor/README.md index 54d59fd18f739..c0f9c3aecca98 100644 --- a/system/bluetooth_monitor/README.md +++ b/system/bluetooth_monitor/README.md @@ -46,12 +46,7 @@ L2ping is only allowed for root by default, so this package provides the followi ## Parameters -| Name | Type | Default Value | Explanation | -| ----------- | ------ | ------------- | --------------------------------------------------------- | -| `port` | int | 7640 | Port number to connect to L2ping service. | -| `timeout` | int | 5 | Wait timeout seconds for the response. | -| `rtt_warn` | float | 0.00 | RTT(Round-Trip Time) to generate warn. | -| `addresses` | string | \* | List of bluetooth address of wireless devices to monitor. | +{{ json_to_markdown("system/bluetooth_monitor/schema/bluetooth_monitor.schema.json") }} - `rtt_warn` diff --git a/system/bluetooth_monitor/schema/bluetooth_monitor.shcema.json b/system/bluetooth_monitor/schema/bluetooth_monitor.shcema.json new file mode 100644 index 0000000000000..6951ecd6aed88 --- /dev/null +++ b/system/bluetooth_monitor/schema/bluetooth_monitor.shcema.json @@ -0,0 +1,51 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Parameters for bluetooth monitor", + "type": "object", + "definitions": { + "bluetooth_monitor": { + "type": "object", + "properties": { + "address": { + "type": "array", + "description": "Bluetooth addresses of the device to monitor", + "items": { + "type": "string" + }, + "default": ["4C:B9:9B:6E:7F:9A"] + }, + "port": { + "type": "integer", + "description": "Port number to connect to L2ping service on the host", + "default": 7640 + }, + "timeout": { + "type": "integer", + "description": "Time in seconds to wait for a response from the device", + "default": 5 + }, + "rtt_warn": { + "type": "number", + "description": "Time in seconds to warn if the round trip time is greater than this value", + "default": 0.1 + } + }, + "required": ["address", "port", "timeout", "rtt_warn"], + "additionalProperties": false + } + }, + "properties": { + "/**": { + "type": "object", + "properties": { + "ros__parameters": { + "$ref": "#/definitions/bluetooth_monitor" + } + }, + "required": ["ros__parameters"], + "additionalProperties": false + } + }, + "required": ["/**"], + "additionalProperties": false +} diff --git a/system/bluetooth_monitor/src/bluetooth_monitor.cpp b/system/bluetooth_monitor/src/bluetooth_monitor.cpp index e7e20e0801965..d2ef42faa1dbc 100644 --- a/system/bluetooth_monitor/src/bluetooth_monitor.cpp +++ b/system/bluetooth_monitor/src/bluetooth_monitor.cpp @@ -32,16 +32,16 @@ BluetoothMonitor::BluetoothMonitor(const rclcpp::NodeOptions & options) : Node("bluetooth_monitor", options), updater_(this), socket_(-1), - port_(declare_parameter("port", DEFAULT_PORT)) + port_(declare_parameter("port")) { // Get host name char host_name[HOST_NAME_MAX + 1]; gethostname(host_name, sizeof(host_name)); // Build L2ping configuration - config_.l2ping.timeout = declare_parameter("timeout", DEFAULT_TIMEOUT); - config_.l2ping.rtt_warn = declare_parameter("rtt_warn", RTT_NO_WARN); - config_.addresses = declare_parameter("addresses", std::vector()); + config_.l2ping.timeout = declare_parameter("timeout"); + config_.l2ping.rtt_warn = declare_parameter("rtt_warn"); + config_.addresses = declare_parameter>("addresses"); updater_.add("bluetooth_connection", this, &BluetoothMonitor::checkConnection); updater_.setHardwareID(host_name);