Update
This commit is contained in:
parent
d1e385a2a1
commit
1d91792c56
35 changed files with 2275 additions and 237 deletions
|
@ -25,6 +25,8 @@ public:
|
|||
|
||||
void set_speed(uint8_t port, double speed_rad_s);
|
||||
|
||||
void stop_all();
|
||||
|
||||
void generate_step_response_data();
|
||||
|
||||
void generate_tuned_step_response_data();
|
||||
|
|
35
server_v2/include/HealthChecker.hpp
Normal file
35
server_v2/include/HealthChecker.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef COMPLIB_SERVER_HEALTHCHECKER_HPP
|
||||
#define COMPLIB_SERVER_HEALTHCHECKER_HPP
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#define HEALTH_CHECK_TIMEOUT_MS 500
|
||||
|
||||
class HealthChecker {
|
||||
public:
|
||||
static HealthChecker &getInstance() {
|
||||
static HealthChecker instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
HealthChecker(HealthChecker const &) = delete;
|
||||
|
||||
void operator=(HealthChecker const &) = delete;
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
HealthChecker();
|
||||
|
||||
[[noreturn]] void check_loop();
|
||||
|
||||
typedef std::chrono::steady_clock clock;
|
||||
|
||||
std::thread check_thread;
|
||||
std::chrono::time_point<clock> last_update;
|
||||
bool stop_sent = false;
|
||||
};
|
||||
|
||||
|
||||
#endif //COMPLIB_SERVER_HEALTHCHECKER_HPP
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <thread>
|
||||
|
||||
#define SOCKET_PATH "/tmp/compLib"
|
||||
#define SOCKET_BUFFER_SIZE 128
|
||||
|
||||
class TCPSocketServer {
|
||||
|
|
49
server_v2/include/networkUtils.hpp
Normal file
49
server_v2/include/networkUtils.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef COMPLIB_SERVER_NETWORKUTILS_H
|
||||
#define COMPLIB_SERVER_NETWORKUTILS_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <netdb.h>
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
namespace networkUtils {
|
||||
inline std::tuple<std::string, std::string> get_current_host_and_ip() {
|
||||
struct ifaddrs *ifaddr, *ifa;
|
||||
int family, s;
|
||||
char host[NI_MAXHOST];
|
||||
|
||||
if (getifaddrs(&ifaddr) == -1) {
|
||||
spdlog::error("getifaddrs failed");
|
||||
freeifaddrs(ifaddr);
|
||||
return std::tuple("", "");
|
||||
}
|
||||
|
||||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr == NULL)
|
||||
continue;
|
||||
|
||||
family = ifa->ifa_addr->sa_family;
|
||||
|
||||
if (family == AF_INET) {
|
||||
s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
if (s != 0) {
|
||||
spdlog::error("getnameinfo() failed: {}", gai_strerror(s));
|
||||
freeifaddrs(ifaddr);
|
||||
return std::tuple("", "");
|
||||
}
|
||||
|
||||
if (std::string(ifa->ifa_name) != "lo") {
|
||||
freeifaddrs(ifaddr);
|
||||
return std::tuple(ifa->ifa_name, std::string(host));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::tuple("", "");
|
||||
}
|
||||
}
|
||||
|
||||
#endif //COMPLIB_SERVER_NETWORKUTILS_H
|
|
@ -31,6 +31,8 @@ public:
|
|||
|
||||
void write_array(uint8_t reg, uint8_t length, const uint8_t *data);
|
||||
|
||||
std::array<uint8_t, 4> read_version();
|
||||
|
||||
enum Register : uint8_t {
|
||||
IDENTIFICATION_MODEL_ID = 1,
|
||||
IDENTIFICATION_MODEL_REV_MAJOR = 2,
|
||||
|
|
Reference in a new issue