mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
/*
|
|
* Copyright (C) 2015 Pavel Kirienko <pavel.kirienko@gmail.com>
|
|
*/
|
|
|
|
#include <uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp>
|
|
#include <uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp>
|
|
#include <uavcan_linux/uavcan_linux.hpp>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include "debug.hpp"
|
|
|
|
int main(int argc, const char** argv)
|
|
{
|
|
(void)argc;
|
|
(void)argv;
|
|
try
|
|
{
|
|
ENFORCE(0 == std::system("mkdir -p /tmp/uavcan_posix/dynamic_node_id_server"));
|
|
|
|
/*
|
|
* Event tracer test
|
|
*/
|
|
{
|
|
using namespace uavcan::dynamic_node_id_server;
|
|
|
|
const std::string event_log_file("/tmp/uavcan_posix/dynamic_node_id_server/event.log");
|
|
|
|
uavcan_posix::dynamic_node_id_server::FileEventTracer tracer;
|
|
ENFORCE(0 <= tracer.init(event_log_file.c_str()));
|
|
|
|
// Adding a line
|
|
static_cast<IEventTracer&>(tracer).onEvent(TraceError, 123456);
|
|
ENFORCE(0 == std::system(("cat " + event_log_file).c_str()));
|
|
|
|
// Removing the log file
|
|
ENFORCE(0 == std::system(("rm -f " + event_log_file).c_str()));
|
|
|
|
// Adding another line
|
|
static_cast<IEventTracer&>(tracer).onEvent(TraceError, 789123);
|
|
ENFORCE(0 == std::system(("cat " + event_log_file).c_str()));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
catch (const std::exception& ex)
|
|
{
|
|
std::cerr << "Exception: " << ex.what() << std::endl;
|
|
return 1;
|
|
}
|
|
}
|