Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor multiplexed signal display logic #450

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions canframemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,29 +537,35 @@ 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 (int j = 0; j < msg->sigHandler->getCount(); j++)
{
DBC_SIGNAL* sig = msg->sigHandler->findSignalByIdx(j);
tempString.append(displayValues[*sig]);
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