Skip to content

Commit

Permalink
Refactor multiplexed signal display logic #451
Browse files Browse the repository at this point in the history
  • Loading branch information
driftregion committed Jan 25, 2022
1 parent 37e8ad5 commit e4dc8e9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
14 changes: 9 additions & 5 deletions canframemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,29 +537,33 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
{
tempString.append(" <" + msg->name + ">\n");
if (msg->comment.length() > 1) tempString.append(msg->comment + "\n");
std::map<DBC_SIGNAL, QString> displayValues;
for (int j = 0; j < msg->sigHandler->getCount(); j++)
{
QString sigString;
DBC_SIGNAL* sig = msg->sigHandler->findSignalByIdx(j);

if ( (sig->multiplexParent == nullptr) && sig->processAsText(thisFrame, sigString))
{
tempString.append(sigString);
tempString.append("\n");
displayValues.emplace(*sig, sigString);
if (sig->isMultiplexor)
{
qDebug() << "Multiplexor. Diving into the tree";
tempString.append(sig->processSignalTree(thisFrame));
sig->processAvailableSignals(thisFrame, displayValues);
}
}
else if (sig->isMultiplexed && overwriteDups) //wasn't in this exact frame but is in the message. Use cached value
{
bool isInteger = false;
if (sig->valType == UNSIGNED_INT || sig->valType == SIGNED_INT) isInteger = true;
tempString.append(sig->makePrettyOutput(sig->cachedValue.toDouble(), sig->cachedValue.toLongLong(), true, isInteger));
tempString.append("\n");
displayValues.emplace(*sig, sig->makePrettyOutput(sig->cachedValue.toDouble(), sig->cachedValue.toLongLong(), true, isInteger));
}
}

for (const auto &kv: displayValues) {
tempString.append(kv.second);
tempString.append("\n");
}
}
}
return tempString;
Expand Down
32 changes: 32 additions & 0 deletions dbc/dbc_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,38 @@ QString DBC_SIGNAL::processSignalTree(const CANFrame &frame)
return build;
}

void DBC_SIGNAL::processAvailableSignals(const CANFrame &frame, std::map<DBC_SIGNAL, QString> &displayValues)
{
std::map<DBC_SIGNAL, QString> out;
int val;
if (!this->processAsInt(frame, val))
{
qDebug() << "Could not process multiplexor as an integer.";
return;
}
qDebug() << val;

foreach (DBC_SIGNAL *sig, multiplexedChildren)
{
if ( (val >= sig->multiplexLowValue) && (val <= sig->multiplexHighValue) )
{
qDebug() << "Found match for multiplex value range - " << sig->name;
QString sigString;
if (sig->processAsText(frame, sigString))
{
qDebug() << "Returned value: " << sigString;
displayValues[*sig] = sigString;
if (sig->isMultiplexor)
{
qDebug() << "Spelunkin!";
sig->processSignalTree(frame);
}
}
}
}
return;
}

/*
The way that the DBC file format works is kind of weird... For intel format signals you count up
from the start bit to the end bit which is (startbit + signallength - 1). At each point
Expand Down
1 change: 1 addition & 0 deletions dbc/dbc_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class DBC_SIGNAL
bool getValueString(int64_t intVal, QString &outString);
QString makePrettyOutput(double floatVal, int64_t intVal, bool outputName = true, bool isInteger = false);
QString processSignalTree(const CANFrame &frame);
void processAvailableSignals(const CANFrame &frame, std::map<DBC_SIGNAL, QString> &displayValues);
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
bool isSignalInMessage(const CANFrame &frame);
Expand Down

0 comments on commit e4dc8e9

Please sign in to comment.