Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions clients/cpp/Telecmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
#ifndef TELECMD_H
#define TELECMD_H

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#include <cstring>
#include <functional>
#include <iostream>
#include <sstream>
#include <map>
#include <functional>
#include <netinet/in.h>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

//#define TELECMD_DISABLE // Would prevent telecmd from doing anything, useful for production builds

Expand All @@ -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);
Expand Down
34 changes: 18 additions & 16 deletions clients/cpp/Teleplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
#ifndef TELEPLOT_H
#define TELEPLOT_H

#include <iostream>
#include <iomanip>
#include <arpa/inet.h>
#include <cerrno>
#include <chrono>
#include <cstdint>
#include <fcntl.h>
#include <unistd.h>
#include <iomanip>
#include <map>
#include <sstream>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <map>
#include <chrono>
#include <unistd.h>

// Enable/Disable implementation optimisations:
//#define TELEPLOT_DISABLE // Would prevent teleplot from doing anything, useful for production builds
Expand Down Expand Up @@ -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<int>(value_str.length());

int i = 0;
bool stop = false;
Expand All @@ -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<int>(value_str.length()))
{
while (value_str[u] == '0') u--;

Expand Down Expand Up @@ -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
Expand All @@ -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<std::uint16_t>(port));
serv_.sin_addr.s_addr = inet_addr(address_.c_str());
if (sockfd_ >= 0) {
int fl = fcntl(sockfd_, F_GETFL, 0);
Expand All @@ -234,7 +232,7 @@ class Teleplot {
return ;
#endif
int64_t nowUs = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
double nowMs = static_cast<double>(nowUs)/1000.d;
double nowMs = static_cast<double>(nowUs)/1000.0;
updateData(key, nowMs, value, 0, flags, maxFrequencyHz, unit);
}

Expand All @@ -244,7 +242,7 @@ class Teleplot {
return ;
#endif
int64_t nowUs = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
double nowMs = static_cast<double>(nowUs)/1000.d;
double nowMs = static_cast<double>(nowUs)/1000.0;
updateData(key, valueX, valueY, nowMs, flags, maxFrequencyHz);
}

Expand All @@ -254,7 +252,7 @@ class Teleplot {
#endif
int64_t nowUs = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
double nowMs = static_cast<double>(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){
Expand All @@ -276,6 +274,8 @@ class Teleplot {
}
return false;
#else
(void)key;
(void)frequency;
return true;
#endif
}
Expand All @@ -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
Expand Down