From 7cac4cd4fa221b3479c8ee72d551d51e651e3c9f Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 24 May 2015 14:23:04 +0300 Subject: [PATCH] uavcan_dynamic_node_id_server - cleaner time formatting --- .../linux/apps/uavcan_dynamic_node_id_server.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp b/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp index 7ccb690af1..a922230892 100644 --- a/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp +++ b/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp @@ -86,20 +86,19 @@ public: uavcan::MakeString<81>::Type toString() const // Heapless return { - char timerbuf[11] = { }; + char timebuf[11] = { }; { const std::time_t rawtime = utc_timestamp.toUSec() * 1e-6; const auto tm = localtime(&rawtime); - std::strftime(timerbuf, sizeof(timerbuf) - 1U, "%H:%M:%S.", tm); - timerbuf[9] = '0' + (utc_timestamp.toMSec() % 1000) / 100; - timerbuf[10] = '\0'; + std::strftime(timebuf, 10, "%H:%M:%S.", tm); + std::snprintf(&timebuf[9], 3, "%02u", static_cast((utc_timestamp.toMSec() % 1000U) / 10U)); } decltype(toString()) out; out.resize(out.capacity()); (void)std::snprintf(reinterpret_cast(out.begin()), out.size() - 1U, - "%-10s %-28s % -20lld %016llx", - timerbuf, + "%-11s %-28s %-20lld %016llx", + timebuf, getEventName(code), static_cast(argument), static_cast(argument)); @@ -109,7 +108,7 @@ public: static const char* getTableHeader() { // Matches the string format above - return "Timestamp Event name Argument (dec) Argument (hex)"; + return "Timestamp Event name Argument (dec) Argument (hex)"; } };