mirror of
https://github.com/modelec/detection_pot.git
synced 2026-01-19 00:57:28 +01:00
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#include "MyClient.h"
|
|
|
|
MyClient::MyClient(const char* ip, const int port) : TCPClient(ip, port)
|
|
{
|
|
|
|
}
|
|
|
|
void MyClient::handleMessage(const std::string& message)
|
|
{
|
|
std::cout << message << std::endl;
|
|
|
|
std::vector<std::string> messageSplited = TCPSocket::split(message, ";");
|
|
|
|
if (messageSplited.size() != 4) {
|
|
std::cerr << "Invalid message format" << std::endl;
|
|
return;
|
|
}
|
|
|
|
if (messageSplited[1] == "aruco" || messageSplited[1] == "all")
|
|
{
|
|
if (messageSplited[2] == "get aruco")
|
|
{
|
|
std::string res;
|
|
|
|
res += "aruco;strat;get aruco;";
|
|
|
|
if (arucoTags.empty())
|
|
{
|
|
res += "404";
|
|
} else {
|
|
for (auto& [tag, pos] : arucoTags)
|
|
{
|
|
res += std::to_string(tag.id) + ",";
|
|
res += tag.name + ",";
|
|
res += std::to_string(pos.first.at<double>(2, 0)) + ",";
|
|
res += std::to_string(pos.first.at<double>(0, 0)) + ",";
|
|
res += std::to_string(pos.second.at<double>(0, 0)) + ",";
|
|
res += std::to_string(pos.second.at<double>(1, 0)) + ",";
|
|
res += std::to_string(pos.second.at<double>(2, 0)) + ",";
|
|
}
|
|
}
|
|
|
|
std::cout << "Sent to client " << res << std::endl;
|
|
|
|
this->sendMessage(res.c_str());
|
|
|
|
this->arucoTags.clear();
|
|
} else if (messageSplited[2] == "ping")
|
|
{
|
|
this->sendMessage("aruco;ihm;pong;1");
|
|
}
|
|
}
|
|
}
|
|
|
|
void MyClient::setArucoTags(const std::vector<std::pair<ArucoTag, std::pair<cv::Mat, cv::Mat>>>& arucoTags)
|
|
{
|
|
this->arucoTags = arucoTags;
|
|
}
|