Skip to content

Commit

Permalink
refactor(bluetooth_monitor): rework parameters (#5239)
Browse files Browse the repository at this point in the history
* refactor(bluetooth_monitor): rework parameters

Signed-off-by: Yuqi Huai <[email protected]>

* style(pre-commit): autofix

* doc(bluetooth_monitor): fix default for integer parameters

Signed-off-by: Yuqi Huai <[email protected]>

* doc(bluetooth_monitor): add default for parameter addresses

Signed-off-by: Yuqi Huai <[email protected]>

* style(pre-commit): autofix

* doc(bluetooth_monitor): fix parameter description

---------

Signed-off-by: Yuqi Huai <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
YuqiHuai and pre-commit-ci[bot] authored Nov 30, 2023
1 parent 7d7c93e commit 5df706e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
7 changes: 1 addition & 6 deletions system/bluetooth_monitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
51 changes: 51 additions & 0 deletions system/bluetooth_monitor/schema/bluetooth_monitor.shcema.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions system/bluetooth_monitor/src/bluetooth_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>("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<std::string>());
config_.l2ping.timeout = declare_parameter<int64_t>("timeout");
config_.l2ping.rtt_warn = declare_parameter<double>("rtt_warn");
config_.addresses = declare_parameter<std::vector<std::string>>("addresses");

updater_.add("bluetooth_connection", this, &BluetoothMonitor::checkConnection);
updater_.setHardwareID(host_name);
Expand Down

0 comments on commit 5df706e

Please sign in to comment.