Allow using shortened channel names in foxglove_websocket
This makes the websocket server's defaults consistent with log_to_mcap.
By using shortened channel names, we make ti easier to reuse layouts
across nodes (e.g., this way, the /piX prefix will be removed for
the channels available on the current pi being debugged).
Change-Id: Ief1f0c5a8932425017b4718ec9f9d2bae1de2c72
Signed-off-by: James Kuszmaul <jabukuszmaul@gmail.com>
diff --git a/aos/util/mcap_logger.cc b/aos/util/mcap_logger.cc
index 40e55f0..111d784 100644
--- a/aos/util/mcap_logger.cc
+++ b/aos/util/mcap_logger.cc
@@ -84,6 +84,21 @@
return schema;
}
+std::string ShortenedChannelName(const aos::Configuration *config,
+ const aos::Channel *channel,
+ std::string_view application_name,
+ const aos::Node *node) {
+ std::set<std::string> names =
+ configuration::GetChannelAliases(config, channel, application_name, node);
+ std::string_view shortest_name;
+ for (const std::string &name : names) {
+ if (shortest_name.empty() || name.size() < shortest_name.size()) {
+ shortest_name = name;
+ }
+ }
+ return std::string(shortest_name);
+}
+
namespace {
std::string_view CompressionName(McapLogger::Compression compression) {
switch (compression) {
@@ -354,15 +369,9 @@
channel->type()->string_view());
break;
case CanonicalChannelNames::kShortened: {
- std::set<std::string> names = configuration::GetChannelAliases(
- event_loop_->configuration(), channel, event_loop_->name(),
- event_loop_->node());
- std::string_view shortest_name;
- for (const std::string &name : names) {
- if (shortest_name.empty() || name.size() < shortest_name.size()) {
- shortest_name = name;
- }
- }
+ const std::string shortest_name =
+ ShortenedChannelName(event_loop_->configuration(), channel,
+ event_loop_->name(), event_loop_->node());
if (shortest_name != channel->name()->string_view()) {
VLOG(1) << "Shortening " << channel->name()->string_view() << " "
<< channel->type()->string_view() << " to " << shortest_name;