mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-22 22:42:05 +08:00
c++ replay: get socket name from capnp::Schema (#22367)
* get socket name from canp::Schema * use vector
This commit is contained in:
@@ -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<const char *> s;
|
||||
auto event_struct = capnp::Schema::from<cereal::Event>().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<capnp::DynamicStruct::Reader>(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}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QThread>
|
||||
#include <set>
|
||||
|
||||
#include <capnp/dynamic.h>
|
||||
#include "cereal/visionipc/visionipc_server.h"
|
||||
@@ -55,7 +54,7 @@ protected:
|
||||
// messaging
|
||||
SubMaster *sm;
|
||||
PubMaster *pm;
|
||||
std::set<std::string> socks;
|
||||
std::vector<const char*> sockets_;
|
||||
VisionIpcServer *vipc_server = nullptr;
|
||||
std::unique_ptr<Route> route_;
|
||||
bool load_dcam = false, load_ecam = false;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <QDebug>
|
||||
#include <QEventLoop>
|
||||
#include <QString>
|
||||
#include <set>
|
||||
#include <future>
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
Reference in New Issue
Block a user