Skip to content
Snippets Groups Projects
Commit 0204bedc authored by Hoop77's avatar Hoop77
Browse files

pc builds now

parent b6257541
Branches
No related merge requests found
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
namespace pc namespace pc
{ {
class Logger : public std::enable_shared_from_this<Logger> class Logger
: public std::enable_shared_from_this<Logger>
, private networking::Busyable
{ {
private: private:
struct PrivateTag struct PrivateTag
...@@ -35,15 +37,31 @@ public: ...@@ -35,15 +37,31 @@ public:
static Ptr create(networking::Networking & net, const std::string & host) static Ptr create(networking::Networking & net, const std::string & host)
{ return std::make_shared<Logger>(PrivateTag{}, net, host); } { return std::make_shared<Logger>(PrivateTag{}, net, host); }
Logger(PrivateTag, networking::Networking & net, const std::string & host) Logger(PrivateTag, networking::Networking & net, const std::string & host);
void start();
void stop();
private: private:
struct AsyncState
{
using Ptr = std::shared_ptr<AsyncState>;
AsyncState(Logger::Ptr self)
: lock(*self), self(self)
{}
networking::BusyLock lock;
Logger::Ptr self;
};
networking::Networking & net; networking::Networking & net;
std::string host; std::string host;
LoggingClient::Ptr loggingClient; LoggingClient::Ptr client;
networking::time::Timer::Ptr timer; networking::time::Timer::Ptr timer;
void log(); void log(AsyncState::Ptr state);
}; };
} }
......
...@@ -3,32 +3,44 @@ ...@@ -3,32 +3,44 @@
// //
#include "../include/Logger.h" #include "../include/Logger.h"
#include <iostream>
namespace pc namespace pc
{ {
void Logger::log() Logger::Logger(Logger::PrivateTag, networking::Networking & net, const std::string & host)
: net(net), host(host)
{
client = LoggingClient::create(net, MAX_MESSAGE_SIZE);
timer = networking::time::Timer::create(net);
}
void Logger::start()
{
auto self = shared_from_this();
auto state = std::make_shared<AsyncState>(self);
log(state);
}
void Logger::stop()
{
timer->stop();
client->stop();
}
void Logger::log(AsyncState::Ptr state)
{ {
using namespace std::chrono_literals; using namespace std::chrono_literals;
std::string emptyRequest; std::string emptyRequest;
auto self = shared_from_this(); client->asyncCall(
loggingClient->asyncCall(
emptyRequest, host, PORT, 10s, emptyRequest, host, PORT, 10s,
[self](const auto & error, auto & responseMessage) [state](const auto & error, auto & responseMessage)
{ {
std::cout << responseMessage; std::cout << responseMessage;
self->timer->startTimeout(1ms, [self] state->self->timer->startTimeout(1ms, [state]
{ self->log; }); { state->self->log(state); });
}); });
} }
Logger::Logger(Logger::PrivateTag, networking::Networking & net, const std::string & host)
: net(net), host(host)
{
loggingClient = LoggingClient::create(net, MAX_MESSAGE_SIZE);
timer = networking::time::Timer::create(net);
log();
}
} }
...@@ -7,8 +7,9 @@ int main() ...@@ -7,8 +7,9 @@ int main()
using namespace std::chrono_literals; using namespace std::chrono_literals;
float speed = 0.0f; float speed = 0.0f;
networking::Networking net; networking::Networking net;
const std::string host{"10.5.37.195"};
pc2car::CommandSender commandSender{net, "10.5.37.195"}; pc2car::CommandSender commandSender{net, host};
auto commandTimer = networking::time::Timer::create(net); auto commandTimer = networking::time::Timer::create(net);
commandTimer->startPeriodicTimeout( commandTimer->startPeriodicTimeout(
1s, 1s,
...@@ -18,7 +19,8 @@ int main() ...@@ -18,7 +19,8 @@ int main()
speed += 1.0f; speed += 1.0f;
}); });
auto logger = pc::Logger::create(net, "10.5.37.195"); auto logger = pc::Logger::create(net, host);
logger->start();
for (;;); for (;;);
return 0; return 0;
......
...@@ -29,6 +29,7 @@ class Logging : public nodelet::Nodelet ...@@ -29,6 +29,7 @@ class Logging : public nodelet::Nodelet
public: public:
static constexpr std::size_t PORT{10207}; static constexpr std::size_t PORT{10207};
static constexpr std::size_t MAX_MESSAGE_SIZE{1024}; static constexpr std::size_t MAX_MESSAGE_SIZE{1024};
static constexpr std::size_t MAX_BUFFER_SIZE{0x100000}; // 1MB
void onInit() override; void onInit() override;
......
...@@ -14,15 +14,18 @@ namespace car ...@@ -14,15 +14,18 @@ namespace car
constexpr std::size_t Logging::PORT; constexpr std::size_t Logging::PORT;
constexpr std::size_t Logging::MAX_MESSAGE_SIZE; constexpr std::size_t Logging::MAX_MESSAGE_SIZE;
constexpr std::size_t Logging::MAX_BUFFER_SIZE;
Logging::Logging(ros::NodeHandle & nh, std::string & name) Logging::Logging(ros::NodeHandle & nh, std::string & name)
: nh_(nh) : nh_(nh)
, name_(name) , name_(name)
, loggingBuffer(MAX_BUFFER_SIZE)
, loggingStream(&loggingBuffer) , loggingStream(&loggingBuffer)
{} {}
Logging::Logging() Logging::Logging()
: loggingStream(&loggingBuffer) : loggingBuffer(MAX_BUFFER_SIZE)
, loggingStream(&loggingBuffer)
{} {}
Logging::~Logging() Logging::~Logging()
......
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