Skip to content

Commit a57cbd0

Browse files
authored
Publish capabilities via MQTT (#254)
The idea is to have a map of capabilities that make it easy for apps to check what the mower supports, without having to compare versions. For simplicity in usage, the capabilities should be represented by a simple, flat object with the respective capabilities as keys and the "generation" as value. It starts with 1 when the capability gets added and increases whenever a significant change was done. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * System capabilities are now published as JSON on connection for improved discovery. * **Updates** * Version publication now includes a JSON payload on an updated topic path while retaining the existing binary publication. * Capabilities publication occurs early during connection setup to ensure consumers receive current state promptly. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 12e0e1e commit a57cbd0

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include "nlohmann/json.hpp"
4+
5+
inline const nlohmann::ordered_json CAPABILITIES = {
6+
{"rpc", 1},
7+
};

src/lib/xbot_monitoring/src/xbot_monitoring.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
#include "xbot_rpc/constants.h"
2727
#include "xbot_rpc/provider.h"
2828
#include "xbot_rpc/RegisterMethodsSrv.h"
29+
#include "capabilities.h"
2930

3031
using json = nlohmann::ordered_json;
3132

33+
void publish_capabilities();
3234
void publish_sensor_metadata();
3335
void publish_map();
3436
void publish_map_overlay();
@@ -74,6 +76,7 @@ class MqttCallback : public mqtt::callback {
7476

7577
void connected(const mqtt::string &string) override {
7678
ROS_INFO_STREAM("MQTT Connected");
79+
publish_capabilities();
7780
publish_sensor_metadata();
7881
publish_map();
7982
publish_map_overlay();
@@ -263,11 +266,15 @@ void publish_version() {
263266
json version = {
264267
{"version", version_string}
265268
};
266-
try_publish("version", version.dump(), true);
269+
try_publish("version/json", version.dump(), true);
267270
auto bson = json::to_bson(version);
268271
try_publish_binary("version", bson.data(), bson.size(), true);
269272
}
270273

274+
void publish_capabilities() {
275+
try_publish("capabilities/json", CAPABILITIES.dump(2), true);
276+
}
277+
271278
void publish_sensor_metadata() {
272279
std::unique_lock<std::mutex> lk(mqtt_callback_mutex);
273280

0 commit comments

Comments
 (0)