$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(hw_node i2c)
-target_compile_features(hw_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
+target_compile_features(hw_node PUBLIC c_std_99 cxx_std_17)
add_executable(display src/display.cpp)
ament_target_dependencies(display rclcpp sensor_msgs)
+target_compile_features(display PUBLIC cxx_std_20)
install(TARGETS hw_node
DESTINATION lib/${PROJECT_NAME})
#include <memory>
+#include <chrono>
+#include <format>
#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/battery_state.hpp"
const char *svg_template = R"""(
<svg width="128" height="64" xmlns="http://www.w3.org/2000/svg">"
<rect width="128" height="64" x="0" y="0" style="fill:rgb(255,255,255)" />
- <text x="0" y="15" font-family="monospace" xml:space="preserve">%5.2f V</text>
- <text x="0" y="30" font-family="monospace" xml:space="preserve">%5.2f A</text>
+ <text x="0" y="15" font-family="monospace" xml:space="preserve">%s</text>
+ <text x="0" y="30" font-family="monospace" xml:space="preserve">%5.2f V %5.2f A</text>
<text x="0" y="45" font-family="monospace" xml:space="preserve"></text>
<text x="0" y="60" font-family="monospace" xml:space="preserve"></text>
</svg>
)""";
- snprintf(svg, 1024, svg_template, msg->voltage, msg->current);
+ const auto now = std::chrono::system_clock::now();
+ std::string timestr = std::format("{:%d.%m.%y %H:%M:%OS}", now);
+ snprintf(svg, 1024, svg_template, timestr.c_str(), msg->voltage, msg->current);
RCLCPP_DEBUG(this->get_logger(), "%s", svg);
if (sendto(sock, svg, strlen(svg), 0, (struct sockaddr *)&addr, sizeof(addr)) < 0 ) {
perror("sendto");