Skip to content

Commit 18fe1f3

Browse files
authored
couple of mini bug fixes (#48)
1 parent 6519339 commit 18fe1f3

2 files changed

Lines changed: 27 additions & 28 deletions

File tree

clients/cpp/Telecmd.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
#ifndef TELECMD_H
55
#define TELECMD_H
66

7-
#include <stdio.h>
8-
#include <stdlib.h>
9-
#include <unistd.h>
10-
#include <string.h>
11-
#include <sys/types.h>
12-
#include <sys/socket.h>
137
#include <arpa/inet.h>
14-
#include <netinet/in.h>
15-
8+
#include <cstring>
9+
#include <functional>
1610
#include <iostream>
17-
#include <sstream>
1811
#include <map>
19-
#include <functional>
12+
#include <netinet/in.h>
13+
#include <string>
14+
#include <sys/socket.h>
15+
#include <sys/types.h>
16+
#include <unistd.h>
2017

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

@@ -30,8 +27,8 @@ class Telecmd {
3027
#endif
3128
// Create UDP socket
3229
sockfd_ = socket(AF_INET, SOCK_DGRAM, 0);
33-
memset(&serv_, 0, sizeof(serv_));
34-
memset(&client_, 0, sizeof(client_));
30+
std::memset(&serv_, 0, sizeof(serv_));
31+
std::memset(&client_, 0, sizeof(client_));
3532
serv_.sin_family = AF_INET; // IPv4
3633
serv_.sin_addr.s_addr = htonl(INADDR_ANY);
3734
serv_.sin_port = htons(47268);

clients/cpp/Teleplot.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
#ifndef TELEPLOT_H
55
#define TELEPLOT_H
66

7-
#include <iostream>
8-
#include <iomanip>
97
#include <arpa/inet.h>
108
#include <cerrno>
9+
#include <chrono>
10+
#include <cstdint>
1111
#include <fcntl.h>
12-
#include <unistd.h>
12+
#include <iomanip>
13+
#include <map>
14+
#include <sstream>
15+
#include <string>
1316
#include <sys/socket.h>
1417
#include <sys/types.h>
15-
#include <stdio.h>
16-
#include <string.h>
17-
#include <stdlib.h>
18-
#include <sstream>
19-
#include <map>
20-
#include <chrono>
18+
#include <unistd.h>
2119

2220
// Enable/Disable implementation optimisations:
2321
//#define TELEPLOT_DISABLE // Would prevent teleplot from doing anything, useful for production builds
@@ -48,7 +46,7 @@ class ShapeTeleplot {
4846
std::string roundValue(const double value, const unsigned short precision) const
4947
{
5048
std::string value_str = std::to_string(value);
51-
int res_length = value_str.length();
49+
int res_length = static_cast<int>(value_str.length());
5250

5351
int i = 0;
5452
bool stop = false;
@@ -58,7 +56,7 @@ class ShapeTeleplot {
5856
if (value_str[i] == '.')
5957
{
6058
int u = i + precision;
61-
if (u+1 < value_str.length())
59+
if (u+1 < static_cast<int>(value_str.length()))
6260
{
6361
while (value_str[u] == '0') u--;
6462

@@ -202,7 +200,7 @@ class Teleplot {
202200
public:
203201
Teleplot(std::string address, unsigned int port=47269, unsigned int bufferingFrequencyHz = 30)
204202
: sockfd_(-1)
205-
, address_(address)
203+
, address_(std::move(address))
206204
, bufferingFrequencyHz_(bufferingFrequencyHz)
207205
{
208206
#ifdef TELEPLOT_DISABLE
@@ -211,7 +209,7 @@ class Teleplot {
211209
// Create UDP socket
212210
sockfd_ = socket(AF_INET, SOCK_DGRAM, 0);
213211
serv_.sin_family = AF_INET;
214-
serv_.sin_port = htons(port);
212+
serv_.sin_port = htons(static_cast<std::uint16_t>(port));
215213
serv_.sin_addr.s_addr = inet_addr(address_.c_str());
216214
if (sockfd_ >= 0) {
217215
int fl = fcntl(sockfd_, F_GETFL, 0);
@@ -234,7 +232,7 @@ class Teleplot {
234232
return ;
235233
#endif
236234
int64_t nowUs = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
237-
double nowMs = static_cast<double>(nowUs)/1000.d;
235+
double nowMs = static_cast<double>(nowUs)/1000.0;
238236
updateData(key, nowMs, value, 0, flags, maxFrequencyHz, unit);
239237
}
240238

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

@@ -254,7 +252,7 @@ class Teleplot {
254252
#endif
255253
int64_t nowUs = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
256254
double nowMs = static_cast<double>(nowUs)/1000.0;
257-
updateData(mshape.getName(), nowMs, NULL, NULL, flags, maxFrequencyHz, "", mshape);
255+
updateData(mshape.getName(), nowMs, nullptr, nullptr, flags, maxFrequencyHz, "", mshape);
258256
}
259257

260258
void log(std::string const& log){
@@ -276,6 +274,8 @@ class Teleplot {
276274
}
277275
return false;
278276
#else
277+
(void)key;
278+
(void)frequency;
279279
return true;
280280
#endif
281281
}
@@ -297,6 +297,8 @@ class Teleplot {
297297
#ifdef TELEPLOT_USE_FREQUENCY
298298
if(not shouldUpdateData(key ,maxFrequencyHz)) return; // may be used to reduce the update frequency by ignoring some values
299299
saveUpdateDataTime(key);
300+
#else
301+
(void)maxFrequencyHz;
300302
#endif
301303

302304
// Format

0 commit comments

Comments
 (0)