Skip to content

Commit de6fac8

Browse files
committed
Refactor multiplexed signal display logic #447
1 parent 37e8ad5 commit de6fac8

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

canframemodel.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -537,29 +537,33 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
537537
{
538538
tempString.append(" <" + msg->name + ">\n");
539539
if (msg->comment.length() > 1) tempString.append(msg->comment + "\n");
540+
std::map<DBC_SIGNAL, QString> displayValues;
540541
for (int j = 0; j < msg->sigHandler->getCount(); j++)
541542
{
542543
QString sigString;
543544
DBC_SIGNAL* sig = msg->sigHandler->findSignalByIdx(j);
544545

545546
if ( (sig->multiplexParent == nullptr) && sig->processAsText(thisFrame, sigString))
546547
{
547-
tempString.append(sigString);
548-
tempString.append("\n");
548+
displayValues.emplace(*sig, sigString);
549549
if (sig->isMultiplexor)
550550
{
551551
qDebug() << "Multiplexor. Diving into the tree";
552-
tempString.append(sig->processSignalTree(thisFrame));
552+
sig->processAvailableSignals(thisFrame, displayValues);
553553
}
554554
}
555555
else if (sig->isMultiplexed && overwriteDups) //wasn't in this exact frame but is in the message. Use cached value
556556
{
557557
bool isInteger = false;
558558
if (sig->valType == UNSIGNED_INT || sig->valType == SIGNED_INT) isInteger = true;
559-
tempString.append(sig->makePrettyOutput(sig->cachedValue.toDouble(), sig->cachedValue.toLongLong(), true, isInteger));
560-
tempString.append("\n");
559+
displayValues.emplace(*sig, sig->makePrettyOutput(sig->cachedValue.toDouble(), sig->cachedValue.toLongLong(), true, isInteger));
561560
}
562561
}
562+
563+
for (const auto &kv: displayValues) {
564+
tempString.append(kv.second);
565+
tempString.append("\n");
566+
}
563567
}
564568
}
565569
return tempString;

dbc/dbc_classes.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,38 @@ QString DBC_SIGNAL::processSignalTree(const CANFrame &frame)
8989
return build;
9090
}
9191

92+
void DBC_SIGNAL::processAvailableSignals(const CANFrame &frame, std::map<DBC_SIGNAL, QString> &displayValues)
93+
{
94+
std::map<DBC_SIGNAL, QString> out;
95+
int val;
96+
if (!this->processAsInt(frame, val))
97+
{
98+
qDebug() << "Could not process multiplexor as an integer.";
99+
return;
100+
}
101+
qDebug() << val;
102+
103+
foreach (DBC_SIGNAL *sig, multiplexedChildren)
104+
{
105+
if ( (val >= sig->multiplexLowValue) && (val <= sig->multiplexHighValue) )
106+
{
107+
qDebug() << "Found match for multiplex value range - " << sig->name;
108+
QString sigString;
109+
if (sig->processAsText(frame, sigString))
110+
{
111+
qDebug() << "Returned value: " << sigString;
112+
displayValues[*sig] = sigString;
113+
if (sig->isMultiplexor)
114+
{
115+
qDebug() << "Spelunkin!";
116+
sig->processSignalTree(frame);
117+
}
118+
}
119+
}
120+
}
121+
return;
122+
}
123+
92124
/*
93125
The way that the DBC file format works is kind of weird... For intel format signals you count up
94126
from the start bit to the end bit which is (startbit + signallength - 1). At each point

dbc/dbc_classes.h

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class DBC_SIGNAL
118118
bool getValueString(int64_t intVal, QString &outString);
119119
QString makePrettyOutput(double floatVal, int64_t intVal, bool outputName = true, bool isInteger = false);
120120
QString processSignalTree(const CANFrame &frame);
121+
void processAvailableSignals(const CANFrame &frame, std::map<DBC_SIGNAL, QString> &displayValues);
121122
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
122123
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
123124
bool isSignalInMessage(const CANFrame &frame);

0 commit comments

Comments
 (0)