From de6fac81e279f0b32b8d6f38102cb37c5625662d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=AE=81?= <20824939+driftregion@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:57:00 +0800 Subject: [PATCH] Refactor multiplexed signal display logic #447 --- canframemodel.cpp | 14 +++++++++----- dbc/dbc_classes.cpp | 32 ++++++++++++++++++++++++++++++++ dbc/dbc_classes.h | 1 + 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index e053044d..6601f42f 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -537,6 +537,7 @@ 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 displayValues; for (int j = 0; j < msg->sigHandler->getCount(); j++) { QString sigString; @@ -544,22 +545,25 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const 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; diff --git a/dbc/dbc_classes.cpp b/dbc/dbc_classes.cpp index 5467b4f7..72a275df 100644 --- a/dbc/dbc_classes.cpp +++ b/dbc/dbc_classes.cpp @@ -89,6 +89,38 @@ QString DBC_SIGNAL::processSignalTree(const CANFrame &frame) return build; } +void DBC_SIGNAL::processAvailableSignals(const CANFrame &frame, std::map &displayValues) +{ + std::map 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 diff --git a/dbc/dbc_classes.h b/dbc/dbc_classes.h index fd085c2b..51477793 100644 --- a/dbc/dbc_classes.h +++ b/dbc/dbc_classes.h @@ -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 &displayValues); DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name); DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx); bool isSignalInMessage(const CANFrame &frame);