Skip to content

Commit

Permalink
cabana: remove dependence on opendbc (commaai#30329)
Browse files Browse the repository at this point in the history
* remove dependence on opendbc

* move into function
  • Loading branch information
deanlee authored Nov 3, 2023
1 parent 0788573 commit bf932c6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 61 deletions.
10 changes: 3 additions & 7 deletions tools/cabana/SConscript
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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]

Expand Down
2 changes: 0 additions & 2 deletions tools/cabana/dbc/dbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <QMetaType>
#include <QString>

#include "opendbc/can/common_dbc.h"

const QString UNTITLED = "untitled";
const QString DEFAULT_NODE_NAME = "XXX";
Expand Down Expand Up @@ -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<std::string> allDBCNames() { return get_dbc_names(); }
inline QString doubleToString(double value) { return QString::number(value, 'g', std::numeric_limits<double>::digits10); }
25 changes: 14 additions & 11 deletions tools/cabana/mainwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QJsonObject>
#include <QMenuBar>
#include <QMessageBox>
#include <QResizeEvent>
Expand All @@ -24,6 +25,7 @@
#include "tools/replay/replay.h"

MainWindow::MainWindow() : QMainWindow() {
loadFingerprints();
createDockWindows();
setCentralWidget(center_widget = new CenterWidget(this));
createActions();
Expand Down Expand Up @@ -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 */
Expand All @@ -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"));
Expand All @@ -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(); });
Expand Down
3 changes: 3 additions & 0 deletions tools/cabana/mainwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QProgressBar>
#include <QSplitter>
#include <QStatusBar>
#include <set>

#include "tools/cabana/chart/chartswidget.h"
#include "tools/cabana/dbc/dbcmanager.h"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -84,6 +86,7 @@ public slots:
QProgressBar *progress_bar;
QLabel *status_label;
QJsonDocument fingerprint_to_dbc;
std::set<QString> opendbc_names;
QSplitter *video_splitter = nullptr;
enum { MAX_RECENT_FILES = 15 };
QAction *recent_files_acts[MAX_RECENT_FILES] = {};
Expand Down
41 changes: 0 additions & 41 deletions tools/cabana/tests/test_cabana.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#include "opendbc/can/common.h"
#undef INFO
#include "catch2/catch.hpp"
#include "tools/replay/logreader.h"
Expand Down Expand Up @@ -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::pair<uint32_t, QString>, std::vector<double>> 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<SignalValue> 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
Expand Down

0 comments on commit bf932c6

Please sign in to comment.