Files
giesCANne/filterutility.cpp
T
mjuhanne 428b19c5c4 - Save DBC file configuration when changed, and restore it when restarting the application (no need for manual entry everytime app is launched)
- Add GMLAN 29bit filtering feature. In addition to J1939 matching, it is now possible to match DBC messages using only the Arbitration Id (bits 14-26 of CAN Address), since  Priority id (higher bits) and Sender Id (lowest 13 bits) are not relevant when interpreting the CAN message content. This allows to use the excellent GM Global A DBC files on https://github.com/commaai/opendbc. Just remember to select the "GMLAN" matching criteria on DBC File manager.
- Add "Filter labeling" feature. Using loaded DBC files, it matches the filter Ids with DBC messages and shows them in filter windows. Labeling works in the main window (no need to set "Frame interpret" on, since this is a separate feature), as well as in Flow view, Frame data analysis, Playback and Fuzzzing windows. This makes it so much easier to concentrate on those CAN messages that matter. To use this feature, select global "Label filters using messages from DBC files" on Main Configuration page, and then enable the feature on individual DBC files (on DBC file manager) as needed. This is needed if there's overlap in CAN addresses between DBC files, and because the filter labeler cannot tell apart anymore which Filter ID is associated to which bus, it might label them incorrectly. But usually it's ok to just enable the labeling with all the DBC files.
- In Frame data analysis window, in addition to J1939 decoding show also GMLAN (Priority bits, Arbitration Id, Sender Id) decoding.
- FilterUtility static class used for centralized ListWidgetItem creation and for other helper functions
- DBC handler: To allow setting bus numbers even before connection is configured, do not enforce "valid" bus numbers
2019-08-11 23:16:02 +03:00

80 lines
2.4 KiB
C++

#include "utility.h"
#include "filterutility.h"
#include "dbc/dbchandler.h"
#include <QSettings>
uint32_t FilterUtility::getIdAsInt( QListWidgetItem * item )
{
return Utility::ParseStringToNum(getId(item));
}
QString FilterUtility::getId( QString itemText )
{
if (itemText.contains(" "))
// Strip away the filter label
return itemText.left(itemText.indexOf(" "));
else
return itemText;
}
QString FilterUtility::getId( QListWidgetItem * item )
{
return getId(item->text());
}
uint32_t FilterUtility::getGMLanArbitrationId(uint32_t id)
{
return (id >> 13) & 0x1FFF;
}
uint32_t FilterUtility::getGMLanPriorityBits(uint32_t id)
{
return (id >> 26) & 0x7;
}
uint32_t FilterUtility::getGMLanSenderId(uint32_t id)
{
return id & 0x1FFF;
}
QListWidgetItem * FilterUtility::createCheckableFilterItem(uint32_t id, bool checked, QListWidget* parent)
{
QListWidgetItem * thisItem = createFilterItem(id,parent);
thisItem->setFlags(thisItem->flags() | Qt::ItemIsUserCheckable);
if (checked)
thisItem->setCheckState(Qt::Checked);
else
thisItem->setCheckState(Qt::Unchecked);
return thisItem;
}
QListWidgetItem * FilterUtility::createFilterItem(uint32_t id, QListWidget* parent)
{
QSettings settings;
DBCHandler * dbcHandler = DBCHandler::getReference();
QListWidgetItem *thisItem = new QListWidgetItem(parent);
QString filterItemName = Utility::formatCANID(id);
if (settings.value("Main/FilterLabeling", false).toBool())
{
// Filter labeling (show interpreted frame names next to the CAN addr ID)
MatchingCriteria_t matchingCriteria;
DBC_MESSAGE *msg = dbcHandler->findMessageForFilter(id,&matchingCriteria);
if (msg != NULL)
{
filterItemName.append(" ");
filterItemName.append(msg->name);
// Create tooltip to show the whole name just in case it's too long to fit in the filter window.
// Also if the matching criteria is set to GMLAN, show the Arbitration ID as well
QString tooltip;
if (matchingCriteria == GMLAN)
tooltip.append("0x" + QString::number(FilterUtility::getGMLanArbitrationId(id), 16).toUpper().rightJustified(4,'0') + ": ");
tooltip.append(msg->name);
thisItem->setToolTip(tooltip);
}
}
thisItem->setText(filterItemName);
return thisItem;
}