diff --git a/selfdrive/ui/replay/replay.cc b/selfdrive/ui/replay/replay.cc index f16abcdc3d..f6cb0f832b 100644 --- a/selfdrive/ui/replay/replay.cc +++ b/selfdrive/ui/replay/replay.cc @@ -12,11 +12,14 @@ Replay::Replay(QString route, QStringList allow, QStringList block, SubMaster *sm_, bool dcam, bool ecam, QObject *parent) : sm(sm_), load_dcam(dcam), load_ecam(ecam), QObject(parent) { std::vector s; + auto event_struct = capnp::Schema::from().asStruct(); + sockets_.resize(event_struct.getUnionFields().size()); for (const auto &it : services) { if ((allow.size() == 0 || allow.contains(it.name)) && !block.contains(it.name)) { s.push_back(it.name); - socks.insert(it.name); + uint16_t which = event_struct.getFieldByName(it.name).getProto().getDiscriminantValue(); + sockets_[which] = it.name; } } qDebug() << "services " << s; @@ -208,12 +211,7 @@ void Replay::stream() { cur_which = evt->which; cur_mono_time_ = evt->mono_time; - std::string type; - KJ_IF_MAYBE(e_, static_cast(evt->event).which()) { - type = e_->getProto().getName(); - } - - if (socks.find(type) != socks.end()) { + if (cur_which < sockets_.size() && sockets_[cur_which] != nullptr) { int current_ts = (cur_mono_time_ - route_start_ts_) / 1e9; if ((current_ts - last_print) > 5.0) { last_print = current_ts; @@ -263,9 +261,9 @@ void Replay::stream() { } else { if (sm == nullptr) { auto bytes = evt->bytes(); - pm->send(type.c_str(), (capnp::byte *)bytes.begin(), bytes.size()); + pm->send(sockets_[cur_which], (capnp::byte *)bytes.begin(), bytes.size()); } else { - sm->update_msgs(nanos_since_boot(), {{type, evt->event}}); + sm->update_msgs(nanos_since_boot(), {{sockets_[cur_which], evt->event}}); } } } diff --git a/selfdrive/ui/replay/replay.h b/selfdrive/ui/replay/replay.h index b2bca2eaeb..abfac773e3 100644 --- a/selfdrive/ui/replay/replay.h +++ b/selfdrive/ui/replay/replay.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include "cereal/visionipc/visionipc_server.h" @@ -55,7 +54,7 @@ protected: // messaging SubMaster *sm; PubMaster *pm; - std::set socks; + std::vector sockets_; VisionIpcServer *vipc_server = nullptr; std::unique_ptr route_; bool load_dcam = false, load_ecam = false; diff --git a/selfdrive/ui/replay/tests/test_replay.cc b/selfdrive/ui/replay/tests/test_replay.cc index af2a8cae6c..9ede3a0323 100644 --- a/selfdrive/ui/replay/tests/test_replay.cc +++ b/selfdrive/ui/replay/tests/test_replay.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "catch2/catch.hpp"