From c9880be2c59cd702fe47ed19b026a75299c33a79 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Mon, 11 Mar 2019 20:53:45 -0400 Subject: [PATCH] Add caching to the DBC signal system so that we can show all the signals in overwrite mode. --- canframemodel.cpp | 8 +++++++- dbc/dbc_classes.cpp | 24 +++++++++++++++--------- dbc/dbc_classes.h | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index d4108fa..e82238f 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -334,11 +334,17 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const for (int j = 0; j < msg->sigHandler->getCount(); j++) { QString sigString; - if (msg->sigHandler->findSignalByIdx(j)->processAsText(thisFrame, sigString)) + DBC_SIGNAL* sig = msg->sigHandler->findSignalByIdx(j); + if (sig->processAsText(thisFrame, sigString)) { tempString.append(sigString); tempString.append("\n"); } + else if (sig->isMultiplexed && overwriteDups) //wasn't in this exact frame but is in the message. Use cached value + { + tempString.append(sig->makePrettyOutput(sig->cachedValue.toDouble(), sig->cachedValue.toLongLong())); + tempString.append("\n"); + } } } } diff --git a/dbc/dbc_classes.cpp b/dbc/dbc_classes.cpp index 7d8f013..f9106e1 100644 --- a/dbc/dbc_classes.cpp +++ b/dbc/dbc_classes.cpp @@ -49,6 +49,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString) int bytes = signalSize / 8; for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]); outString = buildString; + cachedValue = outString; return true; } @@ -69,7 +70,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString) { result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned); endResult = ((double)result * factor) + bias; - result = (int64_t)endResult; + result = (int64_t)endResult; } else if (valType == SP_FLOAT) { @@ -94,6 +95,13 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString) endResult = (*((double *)(&result)) * factor) + bias; } + outString = makePrettyOutput(endResult, result); + cachedValue = endResult; + return true; +} + +QString DBC_SIGNAL::makePrettyOutput(double floatVal, int64_t intVal) +{ QString outputString; outputString = name + ": "; @@ -103,22 +111,20 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString) bool foundVal = false; for (int x = 0; x < valList.count(); x++) { - if (valList.at(x).value == result) + if (valList.at(x).value == intVal) { outputString += valList.at(x).descript; foundVal = true; break; } } - if (!foundVal) outputString += QString::number(endResult) + unitName; + if (!foundVal) outputString += QString::number(intVal) + unitName; } else //otherwise display the actual number and unit (if it exists) { - outputString += QString::number(endResult) + unitName; + outputString += QString::number(floatVal) + unitName; } - - outString = outputString; - return true; + return outputString; } //Works quite a bit like the above version but this one is cut down and only will return int32_t which is perfect for @@ -158,7 +164,7 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue) double endResult = ((double)result * factor) + bias; result = (int32_t)endResult; - + cachedValue = result; outValue = result; return true; } @@ -230,7 +236,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue) result = Utility::processIntegerSignal(frame.data, 0, 64, false, false); endResult = (*((double *)(&result)) * factor) + bias; } - + cachedValue = endResult; outValue = endResult; return true; } diff --git a/dbc/dbc_classes.h b/dbc/dbc_classes.h index d71544b..76fe85b 100644 --- a/dbc/dbc_classes.h +++ b/dbc/dbc_classes.h @@ -97,12 +97,14 @@ public: //TODO: this is sloppy. It shouldn't all be public! DBC_MESSAGE *parentMessage; QString unitName; QString comment; + QVariant cachedValue; QList attributes; QList valList; bool processAsText(const CANFrame &frame, QString &outString); bool processAsInt(const CANFrame &frame, int32_t &outValue); bool processAsDouble(const CANFrame &frame, double &outValue); + QString makePrettyOutput(double floatVal, int64_t intVal); DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name); DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx); };