diff --git a/tools/cabana/SConscript b/tools/cabana/SConscript index 46958f14e5986e..d557b3af8093c0 100644 --- a/tools/cabana/SConscript +++ b/tools/cabana/SConscript @@ -1,10 +1,7 @@ -import os -Import('env', 'qt_env', 'arch', 'common', 'messaging', 'visionipc', 'replay_lib', - 'cereal', 'transformations', 'widgets') +Import('qt_env', 'arch', 'common', 'messaging', 'visionipc', 'replay_lib', 'cereal', 'widgets') base_frameworks = qt_env['FRAMEWORKS'] -base_libs = [common, messaging, cereal, visionipc, transformations, 'zmq', - 'capnp', 'kj', 'm', 'ssl', 'crypto', 'pthread'] + qt_env["LIBS"] +base_libs = [common, messaging, cereal, visionipc, 'qt_util', 'zmq', 'capnp', 'kj', 'm', 'ssl', 'crypto', 'pthread'] + qt_env["LIBS"] if arch == "Darwin": base_frameworks.append('OpenCL') @@ -18,8 +15,7 @@ else: qt_libs = ['qt_util'] + base_libs cabana_env = qt_env.Clone() -cabana_env["LIBPATH"] += ['../../opendbc/can'] -cabana_libs = [widgets, cereal, messaging, visionipc, replay_lib, 'panda', 'libdbc_static', 'avutil', 'avcodec', 'avformat', 'bz2', 'curl', 'yuv', 'usb-1.0'] + qt_libs +cabana_libs = [widgets, cereal, messaging, visionipc, replay_lib, 'panda', 'avutil', 'avcodec', 'avformat', 'bz2', 'curl', 'yuv', 'usb-1.0'] + qt_libs opendbc_path = '-DOPENDBC_FILE_PATH=\'"%s"\'' % (cabana_env.Dir("../../opendbc").abspath) cabana_env['CXXFLAGS'] += [opendbc_path] diff --git a/tools/cabana/dbc/dbc.h b/tools/cabana/dbc/dbc.h index bfb26c2842ed35..e07903e6807b48 100644 --- a/tools/cabana/dbc/dbc.h +++ b/tools/cabana/dbc/dbc.h @@ -10,7 +10,6 @@ #include #include -#include "opendbc/can/common_dbc.h" const QString UNTITLED = "untitled"; const QString DEFAULT_NODE_NAME = "XXX"; @@ -120,5 +119,4 @@ class Msg { double get_raw_value(const uint8_t *data, size_t data_size, const cabana::Signal &sig); void updateMsbLsb(cabana::Signal &s); inline int flipBitPos(int start_bit) { return 8 * (start_bit / 8) + 7 - start_bit % 8; } -inline std::vector allDBCNames() { return get_dbc_names(); } inline QString doubleToString(double value) { return QString::number(value, 'g', std::numeric_limits::digits10); } diff --git a/tools/cabana/mainwin.cc b/tools/cabana/mainwin.cc index 0053b08fd29bfe..71e5ade9bb5cf5 100644 --- a/tools/cabana/mainwin.cc +++ b/tools/cabana/mainwin.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include "tools/replay/replay.h" MainWindow::MainWindow() : QMainWindow() { + loadFingerprints(); createDockWindows(); setCentralWidget(center_widget = new CenterWidget(this)); createActions(); @@ -56,12 +58,6 @@ MainWindow::MainWindow() : QMainWindow() { qInfo() << QString::fromStdString(msg); }); - // load fingerprints - QFile json_file(QApplication::applicationDirPath() + "/dbc/car_fingerprint_to_dbc.json"); - if (json_file.open(QIODevice::ReadOnly)) { - fingerprint_to_dbc = QJsonDocument::fromJson(json_file.readAll()); - } - setStyleSheet(QString(R"(QMainWindow::separator { width: %1px; /* when vertical */ height: %1px; /* when horizontal */ @@ -77,6 +73,16 @@ MainWindow::MainWindow() : QMainWindow() { QObject::connect(StreamNotifier::instance(), &StreamNotifier::streamStarted, this, &MainWindow::streamStarted); } +void MainWindow::loadFingerprints() { + QFile json_file(QApplication::applicationDirPath() + "/dbc/car_fingerprint_to_dbc.json"); + if (json_file.open(QIODevice::ReadOnly)) { + fingerprint_to_dbc = QJsonDocument::fromJson(json_file.readAll()); + auto dbc_names = fingerprint_to_dbc.object().toVariantMap().values(); + std::transform(dbc_names.begin(), dbc_names.end(), std::inserter(opendbc_names, opendbc_names.begin()), + [](const auto &name) { return name.toString(); }); + } +} + void MainWindow::createActions() { // File menu QMenu *file_menu = menuBar()->addMenu(tr("&File")); @@ -102,11 +108,8 @@ void MainWindow::createActions() { file_menu->addSeparator(); QMenu *load_opendbc_menu = file_menu->addMenu(tr("Load DBC from commaai/opendbc")); // load_opendbc_menu->setStyleSheet("QMenu { menu-scrollable: true; }"); - auto dbc_names = allDBCNames(); - std::sort(dbc_names.begin(), dbc_names.end()); - for (const auto &name : dbc_names) { - QString dbc_name = QString::fromStdString(name); - load_opendbc_menu->addAction(dbc_name, [=]() { loadDBCFromOpendbc(dbc_name); }); + for (const auto &dbc_name : opendbc_names) { + load_opendbc_menu->addAction(dbc_name, [this, name = dbc_name]() { loadDBCFromOpendbc(name); }); } file_menu->addAction(tr("Load DBC From Clipboard"), [=]() { loadFromClipboard(); }); diff --git a/tools/cabana/mainwin.h b/tools/cabana/mainwin.h index bbbe8730cb7c67..2b1c9912719209 100644 --- a/tools/cabana/mainwin.h +++ b/tools/cabana/mainwin.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "tools/cabana/chart/chartswidget.h" #include "tools/cabana/dbc/dbcmanager.h" @@ -50,6 +51,7 @@ public slots: void saveFile(DBCFile *dbc_file); void saveFileAs(DBCFile *dbc_file); void saveFileToClipboard(DBCFile *dbc_file); + void loadFingerprints(); void loadFromClipboard(SourceSet s = SOURCE_ALL, bool close_all = true); void autoSave(); void cleanupAutoSaveFile(); @@ -84,6 +86,7 @@ public slots: QProgressBar *progress_bar; QLabel *status_label; QJsonDocument fingerprint_to_dbc; + std::set opendbc_names; QSplitter *video_splitter = nullptr; enum { MAX_RECENT_FILES = 15 }; QAction *recent_files_acts[MAX_RECENT_FILES] = {}; diff --git a/tools/cabana/tests/test_cabana.cc b/tools/cabana/tests/test_cabana.cc index 791dfd1329ecee..f6884a2dc990f9 100644 --- a/tools/cabana/tests/test_cabana.cc +++ b/tools/cabana/tests/test_cabana.cc @@ -1,5 +1,4 @@ -#include "opendbc/can/common.h" #undef INFO #include "catch2/catch.hpp" #include "tools/replay/logreader.h" @@ -29,46 +28,6 @@ TEST_CASE("DBCFile::generateDBC") { } } -TEST_CASE("Parse can messages") { - DBCManager dbc(nullptr); - dbc.open({0}, "toyota_new_mc_pt_generated"); - CANParser can_parser(0, "toyota_new_mc_pt_generated", {}, {}); - - LogReader log; - REQUIRE(log.load(TEST_RLOG_URL, nullptr, {}, true)); - REQUIRE(log.events.size() > 0); - for (auto e : log.events) { - if (e->which == cereal::Event::Which::CAN) { - std::map, std::vector> values_1; - for (const auto &c : e->event.getCan()) { - const auto msg = dbc.msg({.source = c.getSrc(), .address = c.getAddress()}); - if (c.getSrc() == 0 && msg) { - for (auto sig : msg->getSignals()) { - double val = get_raw_value((uint8_t *)c.getDat().begin(), c.getDat().size(), *sig); - values_1[{c.getAddress(), sig->name}].push_back(val); - } - } - } - - can_parser.UpdateCans(e->mono_time, e->event.getCan()); - std::vector values_2; - can_parser.query_latest(values_2); - for (auto &[key, v1] : values_1) { - bool found = false; - for (auto &v2 : values_2) { - if (v2.address == key.first && key.second == v2.name.c_str()) { - REQUIRE(v2.all_values.size() == v1.size()); - REQUIRE(v2.all_values == v1); - found = true; - break; - } - } - REQUIRE(found); - } - } - } -} - TEST_CASE("parse_dbc") { QString content = R"( BO_ 160 message_1: 8 EON