From 3640d56e8c50a57ab675d3e905f6bb4d32f7cee8 Mon Sep 17 00:00:00 2001 From: trns1997 Date: Fri, 24 Apr 2026 14:26:50 +0200 Subject: [PATCH] couple of mini bug fixes --- clients/cpp/Telecmd.h | 21 +++++++++------------ clients/cpp/Teleplot.h | 34 ++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/clients/cpp/Telecmd.h b/clients/cpp/Telecmd.h index 56d9dd4..25d347c 100644 --- a/clients/cpp/Telecmd.h +++ b/clients/cpp/Telecmd.h @@ -4,19 +4,16 @@ #ifndef TELECMD_H #define TELECMD_H -#include -#include -#include -#include -#include -#include #include -#include - +#include +#include #include -#include #include -#include +#include +#include +#include +#include +#include //#define TELECMD_DISABLE // Would prevent telecmd from doing anything, useful for production builds @@ -30,8 +27,8 @@ class Telecmd { #endif // Create UDP socket sockfd_ = socket(AF_INET, SOCK_DGRAM, 0); - memset(&serv_, 0, sizeof(serv_)); - memset(&client_, 0, sizeof(client_)); + std::memset(&serv_, 0, sizeof(serv_)); + std::memset(&client_, 0, sizeof(client_)); serv_.sin_family = AF_INET; // IPv4 serv_.sin_addr.s_addr = htonl(INADDR_ANY); serv_.sin_port = htons(47268); diff --git a/clients/cpp/Teleplot.h b/clients/cpp/Teleplot.h index 89348a0..e682a3b 100644 --- a/clients/cpp/Teleplot.h +++ b/clients/cpp/Teleplot.h @@ -4,20 +4,18 @@ #ifndef TELEPLOT_H #define TELEPLOT_H -#include -#include #include #include +#include +#include #include -#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include // Enable/Disable implementation optimisations: //#define TELEPLOT_DISABLE // Would prevent teleplot from doing anything, useful for production builds @@ -48,7 +46,7 @@ class ShapeTeleplot { std::string roundValue(const double value, const unsigned short precision) const { std::string value_str = std::to_string(value); - int res_length = value_str.length(); + int res_length = static_cast(value_str.length()); int i = 0; bool stop = false; @@ -58,7 +56,7 @@ class ShapeTeleplot { if (value_str[i] == '.') { int u = i + precision; - if (u+1 < value_str.length()) + if (u+1 < static_cast(value_str.length())) { while (value_str[u] == '0') u--; @@ -202,7 +200,7 @@ class Teleplot { public: Teleplot(std::string address, unsigned int port=47269, unsigned int bufferingFrequencyHz = 30) : sockfd_(-1) - , address_(address) + , address_(std::move(address)) , bufferingFrequencyHz_(bufferingFrequencyHz) { #ifdef TELEPLOT_DISABLE @@ -211,7 +209,7 @@ class Teleplot { // Create UDP socket sockfd_ = socket(AF_INET, SOCK_DGRAM, 0); serv_.sin_family = AF_INET; - serv_.sin_port = htons(port); + serv_.sin_port = htons(static_cast(port)); serv_.sin_addr.s_addr = inet_addr(address_.c_str()); if (sockfd_ >= 0) { int fl = fcntl(sockfd_, F_GETFL, 0); @@ -234,7 +232,7 @@ class Teleplot { return ; #endif int64_t nowUs = std::chrono::time_point_cast(std::chrono::system_clock::now()).time_since_epoch().count(); - double nowMs = static_cast(nowUs)/1000.d; + double nowMs = static_cast(nowUs)/1000.0; updateData(key, nowMs, value, 0, flags, maxFrequencyHz, unit); } @@ -244,7 +242,7 @@ class Teleplot { return ; #endif int64_t nowUs = std::chrono::time_point_cast(std::chrono::system_clock::now()).time_since_epoch().count(); - double nowMs = static_cast(nowUs)/1000.d; + double nowMs = static_cast(nowUs)/1000.0; updateData(key, valueX, valueY, nowMs, flags, maxFrequencyHz); } @@ -254,7 +252,7 @@ class Teleplot { #endif int64_t nowUs = std::chrono::time_point_cast(std::chrono::system_clock::now()).time_since_epoch().count(); double nowMs = static_cast(nowUs)/1000.0; - updateData(mshape.getName(), nowMs, NULL, NULL, flags, maxFrequencyHz, "", mshape); + updateData(mshape.getName(), nowMs, nullptr, nullptr, flags, maxFrequencyHz, "", mshape); } void log(std::string const& log){ @@ -276,6 +274,8 @@ class Teleplot { } return false; #else + (void)key; + (void)frequency; return true; #endif } @@ -297,6 +297,8 @@ class Teleplot { #ifdef TELEPLOT_USE_FREQUENCY if(not shouldUpdateData(key ,maxFrequencyHz)) return; // may be used to reduce the update frequency by ignoring some values saveUpdateDataTime(key); + #else + (void)maxFrequencyHz; #endif // Format