Skip to content
Snippets Groups Projects
Commit 694d9136 authored by Hoop77's avatar Hoop77
Browse files

logging node finished and pc side implemented

parent 4e5c092a
No related merge requests found
cmake_minimum_required(VERSION 3.9)
project(PC)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost REQUIRED COMPONENTS regex system)
set(SOURCE_FILES
src/main.cpp
src/Logging.cpp
include/Logging.h)
add_executable(PC ${SOURCE_FILES})
target_link_libraries(PC ${Boost_LIBRARIES})
\ No newline at end of file
//
// Created by philipp on 22.03.18.
//
#ifndef PC_LOGGING_H
#define PC_LOGGING_H
#include <boost/asio.hpp>
namespace pc
{
class Logging
{
public:
explicit Logging(std::uint16_t port)
: port(port)
{}
void start();
void stop();
private:
std::uint16_t port;
std::atomic<bool> running{false};
boost::asio::io_service ioService;
};
}
#endif //PC_LOGGING_H
//
// Created by philipp on 22.03.18.
//
#include <iostream>
#include "../include/Logging.h"
namespace pc
{
void Logging::start()
{
using boost::asio::ip::tcp;
if (running)
return;
running = true;
tcp::endpoint endpoint{tcp::v4(), port};
tcp::acceptor acceptor{ioService, endpoint};
while (running)
{
try
{
tcp::iostream stream;
boost::system::error_code ec;
acceptor.accept(*stream.rdbuf(), ec);
if (ec)
continue;
while (running)
{
std::string msg;
stream >> msg;
std::cout << msg << std::endl;
if (stream.error())
{
if (stream.error() != boost::asio::error::eof)
std::cerr << "LOGGING ERROR: " << stream.error().message() << "\n";
break;
}
}
}
catch (const std::exception & e)
{
std::cerr << "LOGGING ERROR: " << e.what() << "\n";
}
}
}
void Logging::stop()
{
running = false;
}
}
\ No newline at end of file
#include "../include/Logging.h"
int main()
{
pc::Logging logging{10207};
logging.start();
return 0;
}
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <nodelet/nodelet.h> #include <nodelet/nodelet.h>
#include <ros/ros.h> #include <ros/ros.h>
#include <boost/asio.hpp>
#include "car/camDataMsg.h" #include "car/camDataMsg.h"
#include "car/ccDataMsg.h" #include "car/ccDataMsg.h"
#include "car/environmentDataMsg.h" #include "car/environmentDataMsg.h"
...@@ -35,6 +37,9 @@ private: ...@@ -35,6 +37,9 @@ private:
ros::NodeHandle nh_; ros::NodeHandle nh_;
std::string name_; std::string name_;
std::string host{"127.0.0.1"};
std::string port{"10207"};
ros::Subscriber camData; ros::Subscriber camData;
ros::Subscriber ccData; ros::Subscriber ccData;
ros::Subscriber environmentData; ros::Subscriber environmentData;
...@@ -45,6 +50,8 @@ private: ...@@ -45,6 +50,8 @@ private:
ros::Subscriber stmData; ros::Subscriber stmData;
ros::Subscriber ussData; ros::Subscriber ussData;
void logMessage(const std::string & str);
void camDataCallback(const camDataMsg::ConstPtr & inMsg); void camDataCallback(const camDataMsg::ConstPtr & inMsg);
void ccDataCallback(const ccDataMsg::ConstPtr & inMsg); void ccDataCallback(const ccDataMsg::ConstPtr & inMsg);
void environmentDataCallback(const environmentDataMsg::ConstPtr & inMsg); void environmentDataCallback(const environmentDataMsg::ConstPtr & inMsg);
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
#include "logging/Logging.h" #include "logging/Logging.h"
PLUGINLIB_EXPORT_CLASS(car::Logging, nodelet::Nodelet PLUGINLIB_EXPORT_CLASS(car::Logging, nodelet::Nodelet);
);
namespace car namespace car
{ {
...@@ -40,6 +39,27 @@ void Logging::onInit() ...@@ -40,6 +39,27 @@ void Logging::onInit()
NODELET_INFO("Logging::onInit -- END"); NODELET_INFO("Logging::onInit -- END");
} }
void Logging::logMessage(const std::string & msg)
{
try
{
using boost::asio::ip::tcp;
tcp::iostream stream;
stream.expires_from_now(boost::posix_time::seconds(10));
stream.connect(host, port);
if (stream.error())
{
NODELET_ERROR_STREAM("Logging: Could not connect to PC!\n" << stream.error().message());
return;
}
stream << msg;
}
catch (const std::exception & e)
{
NODELET_ERROR_STREAM("Logging: Could not connect to PC!\n" << e.what());
}
}
void Logging::ccDataCallback(const ccDataMsg::ConstPtr & inMsg) void Logging::ccDataCallback(const ccDataMsg::ConstPtr & inMsg)
{ {
std::cout << "Logging received new cc data ( ).\n"; std::cout << "Logging received new cc data ( ).\n";
...@@ -53,6 +73,7 @@ void Logging::camDataCallback(const camDataMsg::ConstPtr & inMsg) ...@@ -53,6 +73,7 @@ void Logging::camDataCallback(const camDataMsg::ConstPtr & inMsg)
void Logging::environmentDataCallback(const environmentDataMsg::ConstPtr & inMsg) void Logging::environmentDataCallback(const environmentDataMsg::ConstPtr & inMsg)
{ {
std::cout << "Logging received new environment data ( ).\n"; std::cout << "Logging received new environment data ( ).\n";
logMessage(std::string{"Environment [distance]: "} + std::to_string(inMsg->distance));
} }
void Logging::laneDataCallback(const laneDataMsg::ConstPtr & inMsg) void Logging::laneDataCallback(const laneDataMsg::ConstPtr & inMsg)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment