ADD: added testing of client
This commit is contained in:
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "gdb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Program",
|
||||||
|
"target": "./build/SimControlApplication",
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"valuesFormatting": "parseText"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@@ -21,15 +22,16 @@ namespace SimControl {
|
|||||||
class SimControl{
|
class SimControl{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SimControl(const std::string &addr,const std::int16_t port);
|
SimControl( std::string addr, ushort port);
|
||||||
|
~SimControl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void MainFunction_();
|
void MainFunction_();
|
||||||
|
|
||||||
|
void HandleMessage(std::string msg);
|
||||||
|
|
||||||
std::shared_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_;
|
std::unique_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,32 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
namespace SimControl {
|
namespace SimControl {
|
||||||
|
|
||||||
|
|
||||||
SimControl::SimControl(const std::string &addr,const std::int16_t port)
|
SimControl::SimControl( std::string addr, ushort port)
|
||||||
{
|
{
|
||||||
|
|
||||||
TCPClient_ = std::make_shared<DirectCommunication::DirectCommunicationClient>(port,addr);
|
TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(port,addr);
|
||||||
|
TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1));
|
||||||
|
TCPClient_->sendMessage("Hello Server");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SimControl::~SimControl()
|
||||||
|
{
|
||||||
|
TCPClient_ = nullptr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimControl::HandleMessage(std::string msg)
|
||||||
|
{
|
||||||
|
|
||||||
|
LOG_S(INFO)<<msg;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +36,4 @@ namespace SimControl {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
18
src/main.cpp
18
src/main.cpp
@@ -1,7 +1,9 @@
|
|||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
|
||||||
#include <SimControl/SimControl.hpp>
|
#include <SimControl/SimControl.hpp>
|
||||||
|
#include <loguru.hpp>
|
||||||
|
|
||||||
/// variable for stopping the application
|
/// variable for stopping the application
|
||||||
bool running = true;
|
bool running = true;
|
||||||
@@ -30,14 +32,26 @@ int main()
|
|||||||
sigIntHandler.sa_flags = 0;
|
sigIntHandler.sa_flags = 0;
|
||||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||||
|
|
||||||
|
ushort port = 3500;
|
||||||
|
// SimControl::SimControl sc("127.0.0.1",5557);
|
||||||
|
|
||||||
SimControl::SimControl sc("127.0.0.255",8000);
|
|
||||||
|
DirectCommunication::DirectCommunicationClient client(port,"127.0.0.1");
|
||||||
|
|
||||||
|
client.sendMessage("Hello Server");
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
client.sendMessage("Hello Server");
|
||||||
|
|
||||||
|
std::string MessageString = client.getLatestMessage();
|
||||||
|
LOG_S(INFO)<<MessageString;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"end app";
|
||||||
|
std::exit(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user