From 7e299dd3773bb7d41bce1ab11e93c7968903c39a Mon Sep 17 00:00:00 2001 From: Jochen Vothknecht <jochen3120@gmail.com> Date: Fri, 27 May 2022 08:59:05 +0200 Subject: [PATCH] Floating point getters --- CLC-qthing/SiliconTorch/NVSExplorer.cpp | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/CLC-qthing/SiliconTorch/NVSExplorer.cpp b/CLC-qthing/SiliconTorch/NVSExplorer.cpp index e6e4ad7..56df9c5 100644 --- a/CLC-qthing/SiliconTorch/NVSExplorer.cpp +++ b/CLC-qthing/SiliconTorch/NVSExplorer.cpp @@ -2,6 +2,7 @@ // C++ system level #include <set> +#include <cmath> #include <vector> #include <cstring> // memset, memcpy, strncmp // #include <cstdlib> @@ -111,6 +112,42 @@ namespace SiliconTorch { qthing::add_binary_message_callback(requestTopic("rm/+/+"), wrapMessageHandler(rmKey)); + + auto getFloat = [&](std::vector<std::string>& topic, qthing::multipart_message_t msg) { + float value = this->getFloat(topic[1], topic[2]); + + if (!std::isnan(value)) { + + char buffer[64]; + snprintf(buffer, 64, "%f", value); + + qthing::publish_message(responseTopic("get_float", topic[1], topic[2]), std::string(buffer)); + } else { + // publish error…? + } + }; + + qthing::add_binary_message_callback(requestTopic("get_float/+/+"), wrapMessageHandler(getFloat)); + + + + auto getDouble = [&](std::vector<std::string>& topic, qthing::multipart_message_t msg) { + double value = this->getDouble(topic[1], topic[2]); + + if (!std::isnan(value)) { + + char buffer[64]; + snprintf(buffer, 64, "%f", value); + + qthing::publish_message(responseTopic("get_double", topic[1], topic[2]), std::string(buffer)); + } else { + // publish error…? + } + }; + + qthing::add_binary_message_callback(requestTopic("get_double/+/+"), wrapMessageHandler(getDouble)); + + } -- GitLab