mirror of
https://github.com/modelec/cpp-lib.git
synced 2026-01-18 16:17:22 +01:00
update
This commit is contained in:
@@ -15,7 +15,7 @@ enum ParameterType
|
||||
CONST_CHAR_PTR
|
||||
};
|
||||
|
||||
template<typename T> struct ParameterTypeTraits {};
|
||||
template<typename T, typename E = void> struct ParameterTypeTraits {};
|
||||
|
||||
template<> struct ParameterTypeTraits<std::string> {
|
||||
static constexpr ParameterType type = STRING;
|
||||
@@ -56,3 +56,11 @@ template<> struct ParameterTypeTraits<char*> {
|
||||
template<> struct ParameterTypeTraits<const char*> {
|
||||
static constexpr ParameterType type = CONST_CHAR_PTR;
|
||||
};
|
||||
|
||||
template<typename T> struct ParameterTypeTraits<T, std::enable_if<std::is_same_v<T, std::string>>> {
|
||||
static constexpr ParameterType type = STRING;
|
||||
};
|
||||
|
||||
template<typename T> struct ParameterTypeTraits<T, std::enable_if_t<std::is_enum_v<T>>> {
|
||||
static constexpr ParameterType type = INT;
|
||||
};
|
||||
|
||||
@@ -6,60 +6,70 @@
|
||||
#include <csignal>
|
||||
#include <atomic>
|
||||
|
||||
std::atomic<bool> running(true);
|
||||
std::atomic<bool> shouldStop = false;
|
||||
|
||||
void signalHandler(int signal) {
|
||||
running = false;
|
||||
void signalHandler( int signum ) {
|
||||
shouldStop = true;
|
||||
}
|
||||
|
||||
void messageHandler(TCPClient& client) {
|
||||
std::string message;
|
||||
|
||||
while (!shouldStop && !client.shouldStop()) {
|
||||
std::getline(std::cin, message);
|
||||
|
||||
if (message == "quit") {
|
||||
client.stop();
|
||||
break;
|
||||
}
|
||||
if (message == "ready") {
|
||||
client.sendMessage("lidar;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("aruco;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("arduino;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("tirette;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("servo_moteur;strat;ready;1");
|
||||
} else if (message == "pong") {
|
||||
client.sendMessage("lidar;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("aruco;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("arduino;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("tirette;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("servo_moteur;ihm;pong;1");
|
||||
} else {
|
||||
client.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
signal(SIGINT, signalHandler);
|
||||
|
||||
CLParser parser(argc, argv);
|
||||
CLParser clParser(argc, argv);
|
||||
|
||||
int port = parser.getOption<int>("port", 8080);
|
||||
int port = clParser.getOption<int>("port", 8080);
|
||||
|
||||
bool loggerMode = parser.hasOption("logger");
|
||||
auto host = clParser.getOption("host", "127.0.0.1");
|
||||
|
||||
TCPClient client("127.0.0.1", port); // Replace "127.0.0.1" with the IP address of your server and 8080 with the port number
|
||||
bool loggerMode = clParser.hasOption("logger");
|
||||
|
||||
TCPClient client(host, port); // Replace "127.0.0.1" with the IP address of your server and 8080 with the port number
|
||||
|
||||
client.start();
|
||||
|
||||
while (!client.shouldStop() && !running) {
|
||||
if (loggerMode) {
|
||||
usleep(500'000);
|
||||
} else {
|
||||
std::string message;
|
||||
std::getline(std::cin, message);
|
||||
if (!loggerMode) {
|
||||
std::thread messageThread(messageHandler, std::ref(client));
|
||||
messageThread.detach();
|
||||
}
|
||||
|
||||
if (message == "quit") {
|
||||
client.stop();
|
||||
break;
|
||||
}
|
||||
if (message == "ready") {
|
||||
client.sendMessage("lidar;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("aruco;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("arduino;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("tirette;strat;ready;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("servo_moteur;strat;ready;1");
|
||||
} else if (message == "pong") {
|
||||
client.sendMessage("lidar;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("aruco;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("arduino;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("tirette;ihm;pong;1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
client.sendMessage("servo_moteur;ihm;pong;1");
|
||||
} else {
|
||||
client.sendMessage(message);
|
||||
}
|
||||
}
|
||||
while (!client.shouldStop() && !shouldStop) {
|
||||
usleep(500'000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
std::cout << "Port : " << port << std::endl;
|
||||
|
||||
auto test = parser.getOption<unsigned long long>("long");
|
||||
auto test = parser.getOption<long>("long");
|
||||
|
||||
if (test.has_value()) {
|
||||
std::cout << test.value() << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user