mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-21 22:12:05 +08:00
Cabana: show frequency column in message table (#26189)
* show frequency column in message table * add comments
This commit is contained in:
@@ -97,6 +97,12 @@ bool CANMessages::eventFilter(const Event *event) {
|
||||
}
|
||||
|
||||
current_sec = (event->mono_time - replay->routeStartTime()) / (double)1e9;
|
||||
if (counters_begin_sec > current_sec) {
|
||||
// clear counters
|
||||
counters.clear();
|
||||
counters_begin_sec = current_sec;
|
||||
}
|
||||
|
||||
auto can_events = event->event.getCan();
|
||||
for (const auto &c : can_events) {
|
||||
QString id = QString("%1:%2").arg(c.getSrc()).arg(c.getAddress(), 1, 16);
|
||||
@@ -108,6 +114,12 @@ bool CANMessages::eventFilter(const Event *event) {
|
||||
data.ts = current_sec;
|
||||
data.bus_time = c.getBusTime();
|
||||
data.dat.append((char *)c.getDat().begin(), c.getDat().size());
|
||||
|
||||
auto &count = counters[id];
|
||||
data.count = ++count;
|
||||
if (double delta = (current_sec - counters_begin_sec); delta > 0) {
|
||||
data.freq = count / delta;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_sec < prev_update_sec || (current_sec - prev_update_sec) > 1.0 / settings.fps) {
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
#include "tools/replay/replay.h"
|
||||
|
||||
struct CanData {
|
||||
double ts;
|
||||
uint16_t bus_time;
|
||||
double ts = 0.;
|
||||
uint32_t count = 0;
|
||||
uint32_t freq = 0;
|
||||
uint16_t bus_time = 0;
|
||||
QByteArray dat;
|
||||
};
|
||||
|
||||
@@ -57,7 +59,6 @@ signals:
|
||||
public:
|
||||
QMap<QString, std::deque<CanData>> can_msgs;
|
||||
std::unique_ptr<QHash<QString, std::deque<CanData>>> received_msgs = nullptr;
|
||||
QHash<QString, uint32_t> counters;
|
||||
|
||||
protected:
|
||||
void process(QHash<QString, std::deque<CanData>> *);
|
||||
@@ -66,6 +67,7 @@ protected:
|
||||
|
||||
std::atomic<double> current_sec = 0.;
|
||||
std::atomic<bool> seeking = false;
|
||||
|
||||
double begin_sec = 0;
|
||||
double end_sec = 0;
|
||||
double event_begin_sec = 0;
|
||||
@@ -73,6 +75,9 @@ protected:
|
||||
bool is_zoomed = false;
|
||||
QString routeName;
|
||||
Replay *replay = nullptr;
|
||||
|
||||
double counters_begin_sec = std::numeric_limits<double>::max();
|
||||
QHash<QString, uint32_t> counters;
|
||||
};
|
||||
|
||||
inline QString toHex(const QByteArray &dat) {
|
||||
|
||||
@@ -112,23 +112,25 @@ void MessagesWidget::loadDBCFromFingerprint() {
|
||||
|
||||
QVariant MessageListModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return (QString[]){"Name", "ID", "Count", "Bytes"}[section];
|
||||
return (QString[]){"Name", "ID", "Freq", "Count", "Bytes"}[section];
|
||||
return {};
|
||||
}
|
||||
|
||||
QVariant MessageListModel::data(const QModelIndex &index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
const auto &m = msgs[index.row()];
|
||||
auto &can_data = can->lastMessage(m->id);
|
||||
switch (index.column()) {
|
||||
case 0: return m->name;
|
||||
case 1: return m->id;
|
||||
case 2: return can->counters[m->id];
|
||||
case 3: return toHex(can->lastMessage(m->id).dat);
|
||||
case 2: return can_data.freq;
|
||||
case 3: return can_data.count;
|
||||
case 4: return toHex(can_data.dat);
|
||||
}
|
||||
} else if (role == Qt::UserRole) {
|
||||
return msgs[index.row()]->id;
|
||||
} else if (role == Qt::FontRole) {
|
||||
if (index.column() == 3) {
|
||||
if (index.column() == columnCount() - 1) {
|
||||
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||
}
|
||||
}
|
||||
@@ -164,8 +166,18 @@ bool MessageListModel::updateMessages(bool sort) {
|
||||
return sort_order == Qt::AscendingOrder ? l->id < r->id : l->id > r->id;
|
||||
});
|
||||
} else if (sort_column == 2) {
|
||||
// sort by frequency
|
||||
std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) {
|
||||
uint32_t lcount = can->counters[l->id], rcount = can->counters[r->id];
|
||||
uint32_t lfreq = can->lastMessage(l->id).freq;
|
||||
uint32_t rfreq = can->lastMessage(r->id).freq;
|
||||
bool ret = lfreq < rfreq || (lfreq == rfreq && l->id < r->id);
|
||||
return sort_order == Qt::AscendingOrder ? ret : !ret;
|
||||
});
|
||||
} else if (sort_column == 3) {
|
||||
// sort by count
|
||||
std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) {
|
||||
uint32_t lcount = can->lastMessage(l->id).count;
|
||||
uint32_t rcount = can->lastMessage(r->id).count;
|
||||
bool ret = lcount < rcount || (lcount == rcount && l->id < r->id);
|
||||
return sort_order == Qt::AscendingOrder ? ret : !ret;
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ Q_OBJECT
|
||||
public:
|
||||
MessageListModel(QObject *parent) : QAbstractTableModel(parent) {}
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override { return 4; }
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override { return 5; }
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override { return msgs.size(); }
|
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
|
||||
Reference in New Issue
Block a user