mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 04:43:34 +08:00
uavcan_dynamic_node_id_server - colored events
This commit is contained in:
@@ -217,9 +217,12 @@ enum class CLIColor : unsigned
|
|||||||
Blue = 34,
|
Blue = 34,
|
||||||
Magenta = 35,
|
Magenta = 35,
|
||||||
Cyan = 36,
|
Cyan = 36,
|
||||||
|
White = 37,
|
||||||
Default = 39
|
Default = 39
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CLIColor getColorHash(unsigned value) { return CLIColor(31 + value % 7); }
|
||||||
|
|
||||||
class CLIColorizer
|
class CLIColorizer
|
||||||
{
|
{
|
||||||
const CLIColor color_;
|
const CLIColor color_;
|
||||||
@@ -269,6 +272,7 @@ void redraw(const uavcan_linux::NodePtr& node,
|
|||||||
{
|
{
|
||||||
const char* event_name = "";
|
const char* event_name = "";
|
||||||
char event_count_str[10] = { };
|
char event_count_str[10] = { };
|
||||||
|
CLIColor event_color = CLIColor::Default;
|
||||||
|
|
||||||
if (next_relevant_event_index < relevant_events.size())
|
if (next_relevant_event_index < relevant_events.size())
|
||||||
{
|
{
|
||||||
@@ -276,10 +280,13 @@ void redraw(const uavcan_linux::NodePtr& node,
|
|||||||
event_name = uavcan::dynamic_node_id_server::IEventTracer::getEventName(e.first);
|
event_name = uavcan::dynamic_node_id_server::IEventTracer::getEventName(e.first);
|
||||||
std::snprintf(event_count_str, sizeof(event_count_str) - 1U, "%llu",
|
std::snprintf(event_count_str, sizeof(event_count_str) - 1U, "%llu",
|
||||||
static_cast<unsigned long long>(e.second.count));
|
static_cast<unsigned long long>(e.second.count));
|
||||||
|
event_color = getColorHash(static_cast<unsigned>(e.first));
|
||||||
}
|
}
|
||||||
next_relevant_event_index++;
|
next_relevant_event_index++;
|
||||||
|
|
||||||
std::printf(" | %-29s %-9s\n", event_name, event_count_str);
|
std::printf(" | ");
|
||||||
|
CLIColorizer izer(event_color);
|
||||||
|
std::printf("%-29s %-9s\n", event_name, event_count_str);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto render_top_str = [&](const char* local_state_name, const char* local_state_value, CLIColor color)
|
const auto render_top_str = [&](const char* local_state_name, const char* local_state_value, CLIColor color)
|
||||||
@@ -446,7 +453,9 @@ void redraw(const uavcan_linux::NodePtr& node,
|
|||||||
i < num_events_to_render && i < static_cast<int>(event_tracer.getNumEvents());
|
i < num_events_to_render && i < static_cast<int>(event_tracer.getNumEvents());
|
||||||
i++)
|
i++)
|
||||||
{
|
{
|
||||||
std::printf("%s\n", event_tracer.getEventByIndex(i).toString().c_str());
|
const auto e = event_tracer.getEventByIndex(i);
|
||||||
|
CLIColorizer colorizer(getColorHash(static_cast<unsigned>(e.code)));
|
||||||
|
std::printf("%s\n", e.toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fflush(stdout);
|
std::fflush(stdout);
|
||||||
|
|||||||
Reference in New Issue
Block a user