|
|
@@ -1,12 +1,15 @@
|
|
|
#include "sender_base.h"
|
|
|
#include "simple_mq.h"
|
|
|
#include "variable_defs.h"
|
|
|
+#include "utility.hpp"
|
|
|
|
|
|
#include <boost/asio/post.hpp>
|
|
|
|
|
|
+#include <fmt/chrono.h>
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
|
#include <deque>
|
|
|
+#include <fstream>
|
|
|
#include <mutex>
|
|
|
|
|
|
using boost::asio::io_context;
|
|
|
@@ -25,8 +28,17 @@ struct sender_base::impl {
|
|
|
std::unique_ptr<io_context> ctx;
|
|
|
bool waiting_idr = false;
|
|
|
|
|
|
+ std::ofstream log_file;
|
|
|
+
|
|
|
impl() {
|
|
|
ctx = std::make_unique<io_context>();
|
|
|
+
|
|
|
+ // create log file if requested
|
|
|
+ if (mq().query_variable<bool>(SENDER_ENABLE_LOG)) {
|
|
|
+ auto file_name = fmt::format("log_{:%Y_%m_%d_%H_%M_%S}.csv",
|
|
|
+ std::chrono::system_clock::now());
|
|
|
+ log_file.open(file_name);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void clear_frame_list() {
|
|
|
@@ -84,6 +96,11 @@ struct sender_base::impl {
|
|
|
post(*ctx, [this] { handle_frames(); });
|
|
|
}
|
|
|
|
|
|
+ void log_frame_sent(uint64_t frame_id) {
|
|
|
+ if (!log_file.is_open()) return;
|
|
|
+ log_file << fmt::format("{},{}\n", frame_id, system_timestamp());
|
|
|
+ }
|
|
|
+
|
|
|
};
|
|
|
|
|
|
sender_base::sender_base()
|
|
|
@@ -112,4 +129,8 @@ void sender_base::run() {
|
|
|
SPDLOG_INFO("Frame sender started.");
|
|
|
pimpl->ctx->run();
|
|
|
SPDLOG_INFO("Frame sender stopped.");
|
|
|
+}
|
|
|
+
|
|
|
+void sender_base::log_frame_sent(uint64_t frame_id) {
|
|
|
+ pimpl->log_frame_sent(frame_id);
|
|
|
}
|