Skip to content

Commit 369f7d4

Browse files
pd0wmtwilsonco
authored andcommitted
cabana: add button to suppress highlighted bytes (commaai#27131)
1 parent d0fe117 commit 369f7d4

8 files changed

+91
-21
lines changed

tools/cabana/historylog.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ QVariant HistoryLogModel::data(const QModelIndex &index, int role) const {
1717
}
1818
return show_signals ? QString::number(m.sig_values[index.column() - 1]) : toHex(m.data);
1919
} else if (role == Qt::UserRole && index.column() == 1 && !show_signals) {
20-
return HexColors::toVariantList(m.colors);
20+
return ChangeTracker::toVariantList(m.colors);
2121
}
2222
return {};
2323
}
@@ -142,7 +142,8 @@ std::deque<HistoryLogModel::Message> HistoryLogModel::fetchData(uint64_t from_ti
142142
auto msgs = fetchData(first, events->rend(), min_time);
143143
if (update_colors && min_time > 0) {
144144
for (auto it = msgs.rbegin(); it != msgs.rend(); ++it) {
145-
it->colors = hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
145+
hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
146+
it->colors = hex_colors.colors;
146147
}
147148
}
148149
return msgs;
@@ -152,7 +153,8 @@ std::deque<HistoryLogModel::Message> HistoryLogModel::fetchData(uint64_t from_ti
152153
auto msgs = fetchData(first, events->end(), 0);
153154
if (update_colors) {
154155
for (auto it = msgs.rbegin(); it != msgs.rend(); ++it) {
155-
it->colors = hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
156+
hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
157+
it->colors = hex_colors.colors;
156158
}
157159
}
158160
return msgs;

tools/cabana/historylog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public slots:
5353
std::deque<Message> fetchData(uint64_t from_time, uint64_t min_time = 0);
5454

5555
QString msg_id;
56-
HexColors hex_colors;
56+
ChangeTracker hex_colors;
5757
bool has_more_data = true;
5858
const int batch_size = 50;
5959
int filter_sig_idx = -1;

tools/cabana/messageswidget.cc

+61-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "tools/cabana/messageswidget.h"
22

3+
#include <QApplication>
34
#include <QFontDatabase>
5+
#include <QHBoxLayout>
46
#include <QLineEdit>
5-
#include <QVBoxLayout>
67
#include <QPainter>
7-
#include <QApplication>
8+
#include <QPushButton>
9+
#include <QVBoxLayout>
810

911
#include "tools/cabana/dbcmanager.h"
1012

@@ -28,9 +30,16 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
2830
table_widget->sortByColumn(0, Qt::AscendingOrder);
2931
table_widget->horizontalHeader()->setStretchLastSection(true);
3032
table_widget->verticalHeader()->hide();
31-
3233
main_layout->addWidget(table_widget);
3334

35+
// suppress
36+
QHBoxLayout *suppress_layout = new QHBoxLayout();
37+
suppress_add = new QPushButton("Suppress Highlighted");
38+
suppress_clear = new QPushButton();
39+
suppress_layout->addWidget(suppress_add);
40+
suppress_layout->addWidget(suppress_clear);
41+
main_layout->addLayout(suppress_layout);
42+
3443
// signals/slots
3544
QObject::connect(filter, &QLineEdit::textChanged, model, &MessageListModel::setFilterString);
3645
QObject::connect(can, &AbstractStream::msgsReceived, model, &MessageListModel::msgsReceived);
@@ -46,6 +55,16 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
4655
}
4756
}
4857
});
58+
QObject::connect(suppress_add, &QPushButton::clicked, [=]() {
59+
model->suppress();
60+
updateSuppressedButtons();
61+
});
62+
QObject::connect(suppress_clear, &QPushButton::clicked, [=]() {
63+
model->clearSuppress();
64+
updateSuppressedButtons();
65+
});
66+
67+
updateSuppressedButtons();
4968
}
5069

5170
void MessagesWidget::selectMessage(const QString &msg_id) {
@@ -54,6 +73,17 @@ void MessagesWidget::selectMessage(const QString &msg_id) {
5473
}
5574
}
5675

76+
void MessagesWidget::updateSuppressedButtons() {
77+
if (model->suppressed_bytes.empty()) {
78+
suppress_clear->setEnabled(false);
79+
suppress_clear->setText("Clear Suppressed");
80+
} else {
81+
suppress_clear->setEnabled(true);
82+
suppress_clear->setText(QString("Clear Suppressed (%1)").arg(model->suppressed_bytes.size()));
83+
}
84+
}
85+
86+
5787
// MessageListModel
5888

5989
QVariant MessageListModel::headerData(int section, Qt::Orientation orientation, int role) const {
@@ -75,7 +105,16 @@ QVariant MessageListModel::data(const QModelIndex &index, int role) const {
75105
case 4: return toHex(can_data.dat);
76106
}
77107
} else if (role == Qt::UserRole && index.column() == 4) {
78-
return HexColors::toVariantList(can_data.colors);
108+
QList<QVariant> colors;
109+
for (int i = 0; i < can_data.dat.size(); i++){
110+
if (suppressed_bytes.contains({id, i})) {
111+
colors.append(QColor(255, 255, 255, 0));
112+
} else {
113+
colors.append(can_data.colors[i]);
114+
}
115+
}
116+
return colors;
117+
79118
}
80119
return {};
81120
}
@@ -157,3 +196,21 @@ void MessageListModel::sort(int column, Qt::SortOrder order) {
157196
sortMessages();
158197
}
159198
}
199+
200+
void MessageListModel::suppress() {
201+
const double cur_ts = can->currentSec();
202+
203+
for (auto &id : msgs) {
204+
auto &can_data = can->lastMessage(id);
205+
for (int i = 0; i < can_data.dat.size(); i++) {
206+
const double dt = cur_ts - can_data.last_change_t[i];
207+
if (dt < 2.0) {
208+
suppressed_bytes.insert({id, i});
209+
}
210+
}
211+
}
212+
}
213+
214+
void MessageListModel::clearSuppress() {
215+
suppressed_bytes.clear();
216+
}

tools/cabana/messageswidget.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
#include <QAbstractTableModel>
44
#include <QHeaderView>
5-
#include <QTableView>
5+
#include <QSet>
66
#include <QStyledItemDelegate>
7+
#include <QTableView>
78

89
#include "tools/cabana/streams/abstractstream.h"
910

@@ -20,7 +21,10 @@ Q_OBJECT
2021
void setFilterString(const QString &string);
2122
void msgsReceived(const QHash<QString, CanData> *new_msgs = nullptr);
2223
void sortMessages();
24+
void suppress();
25+
void clearSuppress();
2326
QStringList msgs;
27+
QSet<std::pair<QString, int>> suppressed_bytes;
2428

2529
private:
2630
QString filter_str;
@@ -36,6 +40,7 @@ class MessagesWidget : public QWidget {
3640
void selectMessage(const QString &message_id);
3741
QByteArray saveHeaderState() const { return table_widget->horizontalHeader()->saveState(); }
3842
bool restoreHeaderState(const QByteArray &state) const { return table_widget->horizontalHeader()->restoreState(state); }
43+
void updateSuppressedButtons();
3944

4045
signals:
4146
void msgSelectionChanged(const QString &message_id);
@@ -44,4 +49,7 @@ class MessagesWidget : public QWidget {
4449
QTableView *table_widget;
4550
QString current_msg_id;
4651
MessageListModel *model;
52+
QPushButton *suppress_add;
53+
QPushButton *suppress_clear;
54+
4755
};

tools/cabana/streams/abstractstream.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void AbstractStream::process(QHash<QString, CanData> *messages) {
1919

2020
bool AbstractStream::updateEvent(const Event *event) {
2121
static std::unique_ptr new_msgs = std::make_unique<QHash<QString, CanData>>();
22-
static QHash<QString, HexColors> hex_colors;
22+
static QHash<QString, ChangeTracker> change_trackers;
2323
static double prev_update_ts = 0;
2424

2525
if (event->which == cereal::Event::Which::CAN) {
@@ -42,7 +42,9 @@ bool AbstractStream::updateEvent(const Event *event) {
4242
if (double delta = (current_sec - counters_begin_sec); delta > 0) {
4343
data.freq = data.count / delta;
4444
}
45-
data.colors = hex_colors[id].compute(data.dat, data.ts, data.freq);
45+
change_trackers[id].compute(data.dat, data.ts, data.freq);
46+
data.colors = change_trackers[id].colors;
47+
data.last_change_t = change_trackers[id].last_change_t;
4648
}
4749

4850
double ts = millis_since_boot();

tools/cabana/streams/abstractstream.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct CanData {
1717
uint32_t freq = 0;
1818
QByteArray dat;
1919
QVector<QColor> colors;
20+
QVector<double> last_change_t;
2021
};
2122

2223
class AbstractStream : public QObject {

tools/cabana/util.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static QColor blend(QColor a, QColor b) {
1010
return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2, (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
1111
}
1212

13-
const QVector<QColor> &HexColors::compute(const QByteArray &dat, double ts, uint32_t freq) {
13+
void ChangeTracker::compute(const QByteArray &dat, double ts, uint32_t freq) {
1414
if (prev_dat.size() != dat.size()) {
1515
colors.resize(dat.size());
1616
last_change_t.resize(dat.size());
@@ -45,16 +45,15 @@ const QVector<QColor> &HexColors::compute(const QByteArray &dat, double ts, uint
4545
}
4646

4747
prev_dat = dat;
48-
return colors;
4948
}
5049

51-
void HexColors::clear() {
50+
void ChangeTracker::clear() {
5251
prev_dat.clear();
5352
last_change_t.clear();
5453
colors.clear();
5554
}
5655

57-
QList<QVariant> HexColors::toVariantList(const QVector<QColor> &colors) {
56+
QList<QVariant> ChangeTracker::toVariantList(const QVector<QColor> &colors) {
5857
QList<QVariant> ret;
5958
ret.reserve(colors.size());
6059
for (auto &c : colors) ret.append(c);

tools/cabana/util.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
#include <QStyledItemDelegate>
88
#include <QVector>
99

10-
class HexColors {
10+
class ChangeTracker {
1111
public:
12-
const QVector<QColor> &compute(const QByteArray &dat, double ts, uint32_t freq);
13-
static QList<QVariant> toVariantList(const QVector<QColor> &colors);
14-
void clear();
12+
void compute(const QByteArray &dat, double ts, uint32_t freq);
13+
static QList<QVariant> toVariantList(const QVector<QColor> &colors);
14+
void clear();
15+
16+
QVector<double> last_change_t;
17+
QVector<QColor> colors;
1518

1619
private:
1720
const int periodic_threshold = 10;
1821
const int start_alpha = 128;
1922
const float fade_time = 2.0;
2023
QByteArray prev_dat;
21-
QVector<double> last_change_t;
22-
QVector<QColor> colors;
2324
};
2425

2526
class MessageBytesDelegate : public QStyledItemDelegate {

0 commit comments

Comments
 (0)