dynamic find bit

pull/26918/head
deanlee 3 years ago
parent cb88b3ed65
commit 82cd21ac86
  1. 38
      tools/cabana/tools/findsimilarbits.cc
  2. 6
      tools/cabana/tools/findsimilarbits.h

@ -25,14 +25,28 @@ FindSimilarBitsDlg::FindSimilarBitsDlg(QWidget *parent) : QDialog(parent) {
} }
bus_combo->model()->sort(0); bus_combo->model()->sort(0);
bus_combo->setCurrentIndex(0); bus_combo->setCurrentIndex(0);
msg_cb = new QComboBox(this);
for (auto &[address, msg] : dbc()->messages()) {
msg_cb->addItem(msg.name, address);
}
msg_cb->model()->sort(0);
msg_cb->setCurrentIndex(0);
byte_idx_sb = new QSpinBox(this);
byte_idx_sb->setRange(0, 63);
bit_idx_sb = new QSpinBox(this);
bit_idx_sb->setRange(0, 7);
form_layout->addWidget(new QLabel("Bus")); form_layout->addWidget(new QLabel("Bus"));
form_layout->addWidget(bus_combo); form_layout->addWidget(bus_combo);
form_layout->addWidget(msg_cb);
form_layout->addWidget(new QLabel("Byte Index"));
form_layout->addWidget(byte_idx_sb);
form_layout->addWidget(new QLabel("Bit Index"));
form_layout->addWidget(bit_idx_sb);
bit_combo = new QComboBox(this);
bit_combo->addItems({"0", "1"});
bit_combo->setCurrentIndex(1);
form_layout->addWidget(new QLabel("Bit"));
form_layout->addWidget(bit_combo);
min_msgs = new QLineEdit(this); min_msgs = new QLineEdit(this);
min_msgs->setValidator(new QIntValidator(this)); min_msgs->setValidator(new QIntValidator(this));
@ -56,7 +70,8 @@ FindSimilarBitsDlg::FindSimilarBitsDlg(QWidget *parent) : QDialog(parent) {
void FindSimilarBitsDlg::find() { void FindSimilarBitsDlg::find() {
search_btn->setEnabled(false); search_btn->setEnabled(false);
table->clear(); table->clear();
auto msg_mismatched = calcBits(bus_combo->currentText().toUInt(), bit_combo->currentIndex(), min_msgs->text().toInt()); uint32_t selected_address = msg_cb->currentData().toUInt();
auto msg_mismatched = calcBits(bus_combo->currentText().toUInt(), selected_address, byte_idx_sb->value(), bit_idx_sb->value(), min_msgs->text().toInt());
table->setRowCount(msg_mismatched.size()); table->setRowCount(msg_mismatched.size());
table->setColumnCount(6); table->setColumnCount(6);
table->setHorizontalHeaderLabels({"address", "byte idx", "bit idx", "mismatches", "total", "perc%"}); table->setHorizontalHeaderLabels({"address", "byte idx", "bit idx", "mismatches", "total", "perc%"});
@ -72,18 +87,25 @@ void FindSimilarBitsDlg::find() {
search_btn->setEnabled(true); search_btn->setEnabled(true);
} }
QList<FindSimilarBitsDlg::mismatched_struct> FindSimilarBitsDlg::calcBits(uint8_t bus, int bit_to_find, int min_msgs_cnt) { QList<FindSimilarBitsDlg::mismatched_struct> FindSimilarBitsDlg::calcBits(uint8_t bus, uint32_t selected_address, int byte_idx, int bit_idx, int min_msgs_cnt) {
QHash<uint32_t, QVector<uint32_t>> mismatches; QHash<uint32_t, QVector<uint32_t>> mismatches;
QHash<uint32_t, uint32_t> msg_count; QHash<uint32_t, uint32_t> msg_count;
auto events = can->events(); auto events = can->events();
qDebug() << bus << selected_address << byte_idx << bit_idx;
int bit_to_find = -1;
for (auto e : *events) { for (auto e : *events) {
if (e->which == cereal::Event::Which::CAN) { if (e->which == cereal::Event::Which::CAN) {
for (const auto &c : e->event.getCan()) { for (const auto &c : e->event.getCan()) {
if (c.getSrc() == bus) { if (c.getSrc() == bus) {
const auto dat = c.getDat();
uint32_t address = c.getAddress(); uint32_t address = c.getAddress();
if (address == selected_address && dat.size() > byte_idx) {
bit_to_find = ((dat[byte_idx] >> (7 - bit_idx)) & 1) != 0;
}
++msg_count[address]; ++msg_count[address];
if (bit_to_find == -1) continue;
auto &mismatched = mismatches[address]; auto &mismatched = mismatches[address];
const auto dat = c.getDat();
if (mismatched.size() < dat.size() * 8) { if (mismatched.size() < dat.size() * 8) {
mismatched.resize(dat.size() * 8); mismatched.resize(dat.size() * 8);
} }

@ -3,6 +3,7 @@
#include <QComboBox> #include <QComboBox>
#include <QDialog> #include <QDialog>
#include <QLineEdit> #include <QLineEdit>
#include <QSpinBox>
#include <QTableWidget> #include <QTableWidget>
class FindSimilarBitsDlg : public QDialog { class FindSimilarBitsDlg : public QDialog {
@ -13,11 +14,12 @@ private:
struct mismatched_struct { struct mismatched_struct {
uint32_t address, byte_idx, bit_idx, mismatches, total, perc; uint32_t address, byte_idx, bit_idx, mismatches, total, perc;
}; };
QList<mismatched_struct> calcBits(uint8_t bus, int bit_to_find, int min_msgs_cnt); QList<mismatched_struct> calcBits(uint8_t bus, uint32_t selected_address, int byte_idx, int bit_idx, int min_msgs_cnt);
void find(); void find();
QTableWidget *table; QTableWidget *table;
QComboBox *bus_combo, *bit_combo; QComboBox *bus_combo, *msg_cb;
QSpinBox *byte_idx_sb, *bit_idx_sb;
QPushButton *search_btn; QPushButton *search_btn;
QLineEdit *min_msgs; QLineEdit *min_msgs;
}; };

Loading…
Cancel
Save