Pull it together.
This commit is contained in:
parent
d1314797a5
commit
f5adbb59a4
|
|
@ -4,6 +4,7 @@ project(j7s_diagnostics_ros CXX)
|
||||||
find_package(ament_cmake REQUIRED)
|
find_package(ament_cmake REQUIRED)
|
||||||
find_package(rclcpp REQUIRED)
|
find_package(rclcpp REQUIRED)
|
||||||
find_package(diagnostic_msgs REQUIRED)
|
find_package(diagnostic_msgs REQUIRED)
|
||||||
|
find_package(fmt REQUIRED)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
|
|
@ -38,6 +39,7 @@ target_include_directories(conversions PUBLIC
|
||||||
target_link_libraries(conversions PUBLIC
|
target_link_libraries(conversions PUBLIC
|
||||||
j7s_diagnostics_cxx_bridge
|
j7s_diagnostics_cxx_bridge
|
||||||
j7s_diagnostics_cxx
|
j7s_diagnostics_cxx
|
||||||
|
fmt
|
||||||
${diagnostic_msgs_TARGETS}
|
${diagnostic_msgs_TARGETS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -51,7 +53,7 @@ target_link_libraries(test_bin PRIVATE
|
||||||
|
|
||||||
install(TARGETS
|
install(TARGETS
|
||||||
conversions
|
conversions
|
||||||
#test_bin
|
test_bin
|
||||||
DESTINATION lib/${PROJECT_NAME})
|
DESTINATION lib/${PROJECT_NAME})
|
||||||
|
|
||||||
ament_export_targets(export_${PROJECT_NAME})
|
ament_export_targets(export_${PROJECT_NAME})
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "j7s_diagnostics_cxx_bridge/lib.h"
|
|
||||||
#include <diagnostic_msgs/msg/diagnostic_array.hpp>
|
#include <diagnostic_msgs/msg/diagnostic_array.hpp>
|
||||||
#include <diagnostic_msgs/msg/diagnostic_status.hpp>
|
#include <diagnostic_msgs/msg/diagnostic_status.hpp>
|
||||||
|
|
||||||
|
#include "j7s_diagnostics_cxx_bridge/lib.h"
|
||||||
|
|
||||||
std::string convertString(const rust::String & rust);
|
std::string convertString(const rust::String & rust);
|
||||||
|
|
||||||
|
|
@ -11,10 +11,18 @@ j7s_diagnostics_cxx::DiagnosticLevel convertLevel(const uint8_t rosLevel);
|
||||||
|
|
||||||
uint8_t convertLevel(const j7s_diagnostics_cxx::DiagnosticLevel & level);
|
uint8_t convertLevel(const j7s_diagnostics_cxx::DiagnosticLevel & level);
|
||||||
|
|
||||||
std::vector<diagnostic_msgs::msg::KeyValue> convertValues(const rust::Box<j7s_diagnostics_cxx::StringMap>& map);
|
std::vector<diagnostic_msgs::msg::KeyValue> convertValues(
|
||||||
|
const rust::Box<j7s_diagnostics_cxx::StringMap> & map);
|
||||||
|
|
||||||
rust::Box<j7s_diagnostics_cxx::StringMap> convertValues(const std::vector<diagnostic_msgs::msg::KeyValue>& map);
|
rust::Box<j7s_diagnostics_cxx::StringMap> convertValues(
|
||||||
|
const std::vector<diagnostic_msgs::msg::KeyValue> & map);
|
||||||
|
|
||||||
j7s_diagnostics_cxx::DiagnosticStatus fromMsg(const diagnostic_msgs::msg::DiagnosticStatus & msg);
|
j7s_diagnostics_cxx::DiagnosticStatus fromMsg(const diagnostic_msgs::msg::DiagnosticStatus & msg);
|
||||||
|
|
||||||
diagnostic_msgs::msg::DiagnosticStatus toMsg(const j7s_diagnostics_cxx::DiagnosticStatus & status);
|
diagnostic_msgs::msg::DiagnosticStatus toMsg(const j7s_diagnostics_cxx::DiagnosticStatus & status);
|
||||||
|
|
||||||
|
rust::Vec<j7s_diagnostics_cxx::DiagnosticStatus> fromMsg(
|
||||||
|
const diagnostic_msgs::msg::DiagnosticArray & msg);
|
||||||
|
|
||||||
|
diagnostic_msgs::msg::DiagnosticArray toMsg(
|
||||||
|
const rust::Vec<j7s_diagnostics_cxx::DiagnosticStatus> & statuses);
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.3.0"
|
version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c89588d05638b5b4594a3348a2d6c20277e43a7f5c5202b05cc56888475a47b8"
|
checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
"shlex",
|
"shlex",
|
||||||
|
|
@ -160,7 +160,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "j7s_diagnostics"
|
name = "j7s_diagnostics"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.jpace121.net/public/j7s_diagnostics.git?branch=main#5f5e9c3b8aa82fd6d14f7a7931604a225fd6b551"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"limbo_graph",
|
"limbo_graph",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ crate-type = ["staticlib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.103"
|
anyhow = "1.0.103"
|
||||||
cxx = "1.0"
|
cxx = "1.0"
|
||||||
j7s_diagnostics = { branch = "main", git="https://git.jpace121.net/public/j7s_diagnostics.git" }
|
j7s_diagnostics = { path="../../j7s_diagnostics/" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cxx-build = "1.0"
|
cxx-build = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ mod ffi {
|
||||||
#[Self = "DiagnosticTree"]
|
#[Self = "DiagnosticTree"]
|
||||||
fn build() -> Box<DiagnosticTree>;
|
fn build() -> Box<DiagnosticTree>;
|
||||||
fn add_statuses(self: &mut DiagnosticTree, statuses: &Vec<DiagnosticStatus>) -> Result<()>;
|
fn add_statuses(self: &mut DiagnosticTree, statuses: &Vec<DiagnosticStatus>) -> Result<()>;
|
||||||
|
fn add_status(self: &mut DiagnosticTree, status: &DiagnosticStatus) -> Result<()>;
|
||||||
fn reconcile(self: &mut DiagnosticTree) -> Result<()>;
|
fn reconcile(self: &mut DiagnosticTree) -> Result<()>;
|
||||||
fn aggregate(self: &DiagnosticTree) -> Result<Vec<DiagnosticStatus>>;
|
fn aggregate(self: &DiagnosticTree) -> Result<Vec<DiagnosticStatus>>;
|
||||||
|
|
||||||
|
|
@ -138,6 +139,10 @@ impl DiagnosticTree {
|
||||||
Ok(self.graph.add_status_vec(&converted_statuses)?)
|
Ok(self.graph.add_status_vec(&converted_statuses)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_status(self: &mut DiagnosticTree, status: &crate::ffi::DiagnosticStatus) -> anyhow::Result<()> {
|
||||||
|
Ok(self.graph.add_status(diagnostic_status_to_rust(&status))?)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn reconcile(self: &mut DiagnosticTree) -> anyhow::Result<()> {
|
pub fn reconcile(self: &mut DiagnosticTree) -> anyhow::Result<()> {
|
||||||
Ok(self.graph.reconcile_levels()?)
|
Ok(self.graph.reconcile_levels()?)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@ uint8_t convertLevel(const j7s_diagnostics_cxx::DiagnosticLevel& level )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<diagnostic_msgs::msg::KeyValue> convertValues(const rust::Box<j7s_diagnostics_cxx::StringMap>& map)
|
std::vector<diagnostic_msgs::msg::KeyValue> convertValues(
|
||||||
|
const rust::Box<j7s_diagnostics_cxx::StringMap> & map)
|
||||||
{
|
{
|
||||||
std::vector<diagnostic_msgs::msg::KeyValue> toReturn;
|
std::vector<diagnostic_msgs::msg::KeyValue> toReturn;
|
||||||
|
|
||||||
|
|
@ -59,10 +60,10 @@ std::vector<diagnostic_msgs::msg::KeyValue> convertValues(const rust::Box<j7s_di
|
||||||
}
|
}
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rust::Box<j7s_diagnostics_cxx::StringMap> convertValues(const std::vector<diagnostic_msgs::msg::KeyValue>& map)
|
rust::Box<j7s_diagnostics_cxx::StringMap> convertValues(
|
||||||
|
const std::vector<diagnostic_msgs::msg::KeyValue> & map)
|
||||||
{
|
{
|
||||||
rust::Box<j7s_diagnostics_cxx::StringMap> toReturn = j7s_diagnostics_cxx::StringMap::build();
|
rust::Box<j7s_diagnostics_cxx::StringMap> toReturn = j7s_diagnostics_cxx::StringMap::build();
|
||||||
|
|
||||||
|
|
@ -86,6 +87,19 @@ j7s_diagnostics_cxx::DiagnosticStatus fromMsg(const diagnostic_msgs::msg::Diagno
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rust::Vec<j7s_diagnostics_cxx::DiagnosticStatus> fromMsg(
|
||||||
|
const diagnostic_msgs::msg::DiagnosticArray & msg)
|
||||||
|
{
|
||||||
|
rust::Vec<j7s_diagnostics_cxx::DiagnosticStatus> toReturn;
|
||||||
|
toReturn.reserve(msg.status.size());
|
||||||
|
|
||||||
|
for (const auto & rosMsg : msg.status)
|
||||||
|
{
|
||||||
|
toReturn.emplace_back(fromMsg(rosMsg));
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
diagnostic_msgs::msg::DiagnosticStatus toMsg(const j7s_diagnostics_cxx::DiagnosticStatus & status)
|
diagnostic_msgs::msg::DiagnosticStatus toMsg(const j7s_diagnostics_cxx::DiagnosticStatus & status)
|
||||||
{
|
{
|
||||||
diagnostic_msgs::msg::DiagnosticStatus toReturn;
|
diagnostic_msgs::msg::DiagnosticStatus toReturn;
|
||||||
|
|
@ -97,3 +111,16 @@ diagnostic_msgs::msg::DiagnosticStatus toMsg(const j7s_diagnostics_cxx::Diagnost
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diagnostic_msgs::msg::DiagnosticArray toMsg(
|
||||||
|
const rust::Vec<j7s_diagnostics_cxx::DiagnosticStatus> & statuses)
|
||||||
|
{
|
||||||
|
diagnostic_msgs::msg::DiagnosticArray msg;
|
||||||
|
msg.status.reserve(statuses.size());
|
||||||
|
|
||||||
|
for (const auto & status : statuses)
|
||||||
|
{
|
||||||
|
msg.status.emplace_back(toMsg(status));
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
|
||||||
53
src/test.cpp
53
src/test.cpp
|
|
@ -1,17 +1,54 @@
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <j7s_diagnostics_ros/conversions.hpp>
|
#include <j7s_diagnostics_ros/conversions.hpp>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
diagnostic_msgs::msg::DiagnosticStatus make_test_status(const std::string & name, uint8_t level)
|
||||||
{
|
{
|
||||||
const auto my_string = j7s_diagnostics_cxx::OptionalString::some(rust::String("test"));
|
diagnostic_msgs::msg::DiagnosticStatus status;
|
||||||
if(my_string->is_some())
|
status.name = name;
|
||||||
{
|
status.level = level;
|
||||||
auto as_string = my_string->value();
|
|
||||||
std::cout << as_string.c_str() << std::endl;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto my_map = j7s_diagnostics_cxx::StringMap::build();
|
std::string levelToString(uint8_t level)
|
||||||
my_map->insert(rust::String("a"), rust::String("b"));
|
{
|
||||||
|
switch (level)
|
||||||
|
{
|
||||||
|
case diagnostic_msgs::msg::DiagnosticStatus::OK:
|
||||||
|
return "OK";
|
||||||
|
case diagnostic_msgs::msg::DiagnosticStatus::WARN:
|
||||||
|
return "WARN";
|
||||||
|
case diagnostic_msgs::msg::DiagnosticStatus::ERROR:
|
||||||
|
return "ERROR";
|
||||||
|
case diagnostic_msgs::msg::DiagnosticStatus::STALE:
|
||||||
|
return "STALE";
|
||||||
|
default:
|
||||||
|
return "N/A";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
diagnostic_msgs::msg::DiagnosticArray diagArray;
|
||||||
|
diagArray.status.emplace_back(
|
||||||
|
make_test_status("a", diagnostic_msgs::msg::DiagnosticStatus::OK));
|
||||||
|
diagArray.status.emplace_back(
|
||||||
|
make_test_status("a/b", diagnostic_msgs::msg::DiagnosticStatus::WARN));
|
||||||
|
diagArray.status.emplace_back(
|
||||||
|
make_test_status("a/c", diagnostic_msgs::msg::DiagnosticStatus::OK));
|
||||||
|
diagArray.status.emplace_back(
|
||||||
|
make_test_status("a/c/d", diagnostic_msgs::msg::DiagnosticStatus::OK));
|
||||||
|
|
||||||
|
auto tree = j7s_diagnostics_cxx::DiagnosticTree::build();
|
||||||
|
tree->add_statuses(fromMsg(diagArray));
|
||||||
|
tree->reconcile();
|
||||||
|
const auto aggregate = toMsg(tree->aggregate());
|
||||||
|
for (const auto & status : aggregate.status)
|
||||||
|
{
|
||||||
|
fmt::println("Name: {} Level: {}", status.name, levelToString(status.level));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue