Switched code around to better support high/low range for multiplexed

signals
This commit is contained in:
Collin Kidder
2021-02-23 22:14:43 -05:00
parent e00aa1150a
commit bcfaffbe5d
6 changed files with 72 additions and 74 deletions
+5 -11
View File
@@ -19,7 +19,8 @@ DBC_SIGNAL::DBC_SIGNAL()
isMultiplexor = false; isMultiplexor = false;
max = 1; max = 1;
min = 0; min = 0;
multiplexValue = 0; multiplexLowValue = 0;
multiplexHighValue = 0;
factor = 1.0; factor = 1.0;
intelByteOrder = false; intelByteOrder = false;
parentMessage = nullptr; parentMessage = nullptr;
@@ -30,13 +31,6 @@ DBC_SIGNAL::DBC_SIGNAL()
valType = DBC_SIG_VAL_TYPE::UNSIGNED_INT; valType = DBC_SIG_VAL_TYPE::UNSIGNED_INT;
} }
DBC_MULTIPLEX::DBC_MULTIPLEX()
{
lowerBound = 0;
upperBound = 0;
sig = nullptr;
}
/* /*
The way that the DBC file format works is kind of weird... For intel format signals you count up 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 from the start bit to the end bit which is (startbit + signallength - 1). At each point
@@ -91,7 +85,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
{ {
int val; int val;
if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false; if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false;
if (val != multiplexValue) return false; //signal not found in this message if (val != multiplexLowValue) return false; //signal not found in this message
} }
else return false; else return false;
} }
@@ -182,7 +176,7 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue)
{ {
int val; int val;
if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false; if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false;
if (val != multiplexValue) return false; //signal not found in this message if (val != multiplexLowValue) return false; //signal not found in this message
} }
else return false; else return false;
} }
@@ -225,7 +219,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
{ {
int val; int val;
if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false; if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false;
if (val != multiplexValue) return false; //signal not found in this message if (val != multiplexLowValue) return false; //signal not found in this message
} }
else return false; else return false;
} }
+3 -11
View File
@@ -85,15 +85,6 @@ public:
class DBC_MESSAGE; //forward reference so that DBC_SIGNAL can compile before we get to real definition of DBC_MESSAGE class DBC_MESSAGE; //forward reference so that DBC_SIGNAL can compile before we get to real definition of DBC_MESSAGE
class DBC_SIGNAL; class DBC_SIGNAL;
class DBC_MULTIPLEX
{
public:
int lowerBound, upperBound;
DBC_SIGNAL *sig;
DBC_MULTIPLEX();
};
class DBC_SIGNAL class DBC_SIGNAL
{ {
public: //TODO: this is sloppy. It shouldn't all be public! public: //TODO: this is sloppy. It shouldn't all be public!
@@ -103,7 +94,8 @@ public: //TODO: this is sloppy. It shouldn't all be public!
bool intelByteOrder; //true is obviously little endian. False is big endian bool intelByteOrder; //true is obviously little endian. False is big endian
bool isMultiplexor; bool isMultiplexor;
bool isMultiplexed; bool isMultiplexed;
int multiplexValue; int multiplexHighValue;
int multiplexLowValue;
DBC_SIG_VAL_TYPE valType; DBC_SIG_VAL_TYPE valType;
double factor; double factor;
double bias; double bias;
@@ -116,7 +108,7 @@ public: //TODO: this is sloppy. It shouldn't all be public!
QVariant cachedValue; QVariant cachedValue;
QList<DBC_ATTRIBUTE_VALUE> attributes; QList<DBC_ATTRIBUTE_VALUE> attributes;
QList<DBC_VAL_ENUM_ENTRY> valList; QList<DBC_VAL_ENUM_ENTRY> valList;
QList<DBC_MULTIPLEX> multiplexedChildren; QList<DBC_SIGNAL *> multiplexedChildren;
DBC_SIGNAL *multiplexParent; DBC_SIGNAL *multiplexParent;
DBC_SIGNAL(); DBC_SIGNAL();
+13 -16
View File
@@ -453,7 +453,8 @@ DBC_SIGNAL* DBCFile::parseSignalLine(QString line, DBC_MESSAGE *msg)
//bool isMultiplexed = false; //bool isMultiplexed = false;
DBC_SIGNAL sig; DBC_SIGNAL sig;
sig.multiplexValue = 0; sig.multiplexLowValue = 0;
sig.multiplexHighValue = 0;
sig.isMultiplexed = false; sig.isMultiplexed = false;
sig.isMultiplexor = false; sig.isMultiplexor = false;
@@ -476,7 +477,8 @@ DBC_SIGNAL* DBCFile::parseSignalLine(QString line, DBC_MESSAGE *msg)
qDebug() << "Multiplexed signal"; qDebug() << "Multiplexed signal";
//isMultiplexed = true; //isMultiplexed = true;
sig.isMultiplexed = true; sig.isMultiplexed = true;
sig.multiplexValue = match.captured(2).toInt(); sig.multiplexLowValue = match.captured(2).toInt();
sig.multiplexHighValue = sig.multiplexLowValue;
offset = 1; offset = 1;
} }
else else
@@ -488,7 +490,8 @@ DBC_SIGNAL* DBCFile::parseSignalLine(QString line, DBC_MESSAGE *msg)
qDebug() << "Extended Multiplexor Signal"; qDebug() << "Extended Multiplexor Signal";
sig.isMultiplexor = true; //we don't set the local isMultiplexor variable because this isn't the top level multiplexor sig.isMultiplexor = true; //we don't set the local isMultiplexor variable because this isn't the top level multiplexor
sig.isMultiplexed = true; //but, it is both a multiplexor and multiplexed sig.isMultiplexed = true; //but, it is both a multiplexor and multiplexed
sig.multiplexValue = match.captured(2).toInt(); sig.multiplexLowValue = match.captured(2).toInt();
sig.multiplexHighValue = sig.multiplexLowValue;
offset = 1; offset = 1;
} }
else else
@@ -605,11 +608,7 @@ bool DBCFile::parseSignalMultiplexValueLine(QString line)
if (parentSignal != nullptr) if (parentSignal != nullptr)
{ {
//now need to add "thisSignal" to the children multiplexed signals of "parentSignal" //now need to add "thisSignal" to the children multiplexed signals of "parentSignal"
DBC_MULTIPLEX mx; parentSignal->multiplexedChildren.append(thisSignal);
mx.lowerBound = match.captured(4).toInt();
mx.upperBound = match.captured(5).toInt();
mx.sig = thisSignal;
parentSignal->multiplexedChildren.append(mx);
thisSignal->multiplexParent = parentSignal; thisSignal->multiplexParent = parentSignal;
return true; return true;
} }
@@ -1102,11 +1101,7 @@ bool DBCFile::loadFile(QString fileName)
if (sig->isMultiplexed && (sig->multiplexParent == nullptr) ) if (sig->isMultiplexed && (sig->multiplexParent == nullptr) )
{ {
sig->multiplexParent = msg->multiplexorSignal; sig->multiplexParent = msg->multiplexorSignal;
DBC_MULTIPLEX mlt; msg->multiplexorSignal->multiplexedChildren.append(sig);
mlt.sig = sig;
mlt.lowerBound = sig->multiplexValue;
mlt.upperBound = mlt.lowerBound;
msg->multiplexorSignal->multiplexedChildren.append(mlt);
} }
} }
} }
@@ -1388,7 +1383,7 @@ bool DBCFile::saveFile(QString fileName)
if (sig->isMultiplexor) msgOutput.append(" M"); if (sig->isMultiplexor) msgOutput.append(" M");
if (sig->isMultiplexed) if (sig->isMultiplexed)
{ {
msgOutput.append(" m" + QString::number(sig->multiplexValue)); msgOutput.append(" m" + QString::number(sig->multiplexLowValue));
} }
msgOutput.append(" : " + QString::number(sig->startBit) + "|" + QString::number(sig->signalSize) + "@"); msgOutput.append(" : " + QString::number(sig->startBit) + "|" + QString::number(sig->signalSize) + "@");
@@ -1764,12 +1759,14 @@ DBCFile* DBCHandler::loadJSONFile(QString filename)
if (!sigObj.find("mux_id")->isUndefined()) if (!sigObj.find("mux_id")->isUndefined())
{ {
QJsonValue muxVal = sigObj.find("mux_id").value(); QJsonValue muxVal = sigObj.find("mux_id").value();
sig.multiplexValue = muxVal.toInt(); sig.multiplexLowValue = muxVal.toInt();
sig.multiplexHighValue = sig.multiplexLowValue;
sig.isMultiplexed = true; sig.isMultiplexed = true;
} }
else else
{ {
sig.multiplexValue = 0; sig.multiplexLowValue = 0;
sig.multiplexHighValue = 0;
} }
QJsonValue muxerVal = sigObj.find("is_muxer").value(); QJsonValue muxerVal = sigObj.find("is_muxer").value();
if (!muxerVal.isNull()) if (!muxerVal.isNull())
+4 -2
View File
@@ -363,7 +363,9 @@ QString DBCMainEditor::createSignalText(DBC_SIGNAL *sig)
QString sigInfo; QString sigInfo;
if (sig->isMultiplexed) if (sig->isMultiplexed)
{ {
sigInfo = "(" + QString::number(sig->multiplexValue) + ") "; sigInfo = "(" + QString::number(sig->multiplexLowValue);
if (sig->multiplexHighValue != sig->multiplexLowValue) sigInfo += "-" + QString::number(sig->multiplexHighValue);
sigInfo += ") ";
} }
sigInfo.append(sig->name); sigInfo.append(sig->name);
if (sig->comment.count() > 0) sigInfo.append(" - ").append(sig->comment); if (sig->comment.count() > 0) sigInfo.append(" - ").append(sig->comment);
@@ -386,7 +388,7 @@ void DBCMainEditor::processSignalToTree(QTreeWidgetItem *parent, DBC_SIGNAL *sig
{ {
for (int i = 0; i < sig->multiplexedChildren.count(); i++) for (int i = 0; i < sig->multiplexedChildren.count(); i++)
{ {
processSignalToTree(sigItem, sig->multiplexedChildren[i].sig); processSignalToTree(sigItem, sig->multiplexedChildren[i]);
} }
} }
} }
+31 -28
View File
@@ -180,15 +180,26 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
emit updatedTreeInfo(currentSignal); emit updatedTreeInfo(currentSignal);
}); });
connect(ui->txtMultiplexValue, &QLineEdit::editingFinished, connect(ui->txtMultiplexLow, &QLineEdit::editingFinished,
[=]() [=]()
{ {
if (currentSignal == nullptr) return; if (currentSignal == nullptr) return;
int temp; int temp;
temp = Utility::ParseStringToNum(ui->txtMultiplexValue->text()); temp = Utility::ParseStringToNum(ui->txtMultiplexLow->text());
if (currentSignal->multiplexValue != temp) dbcFile->setDirtyFlag(); if (currentSignal->multiplexLowValue != temp) dbcFile->setDirtyFlag();
//TODO: could look up the multiplexor and ensure that the value is within a range that the multiplexor could return //TODO: could look up the multiplexor and ensure that the value is within a range that the multiplexor could return
currentSignal->multiplexValue = temp; currentSignal->multiplexLowValue = temp;
});
connect(ui->txtMultiplexHigh, &QLineEdit::editingFinished,
[=]()
{
if (currentSignal == nullptr) return;
int temp;
temp = Utility::ParseStringToNum(ui->txtMultiplexHigh->text());
if (currentSignal->multiplexHighValue != temp) dbcFile->setDirtyFlag();
//TODO: could look up the multiplexor and ensure that the value is within a range that the multiplexor could return
currentSignal->multiplexHighValue = temp;
}); });
connect(ui->rbExtended, &QRadioButton::toggled, connect(ui->rbExtended, &QRadioButton::toggled,
@@ -201,7 +212,8 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
//an extended multi signal cannot be the root multiplexor for a message so make sure to remove it if it was. //an extended multi signal cannot be the root multiplexor for a message so make sure to remove it if it was.
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr; if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
} }
ui->txtMultiplexValue->setEnabled(currentSignal->isMultiplexed); ui->txtMultiplexLow->setEnabled(currentSignal->isMultiplexed);
ui->txtMultiplexHigh->setEnabled(currentSignal->isMultiplexed);
ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed); ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed);
dbcFile->setDirtyFlag(); dbcFile->setDirtyFlag();
}); });
@@ -216,7 +228,8 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
//if the set multiplexor for the message was this signal then clear it //if the set multiplexor for the message was this signal then clear it
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr; if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
} }
ui->txtMultiplexValue->setEnabled(currentSignal->isMultiplexed); ui->txtMultiplexLow->setEnabled(currentSignal->isMultiplexed);
ui->txtMultiplexHigh->setEnabled(currentSignal->isMultiplexed);
ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed); ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed);
dbcFile->setDirtyFlag(); dbcFile->setDirtyFlag();
}); });
@@ -233,7 +246,8 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
//we just set that this is the multiplexor so update the message to show that as well. //we just set that this is the multiplexor so update the message to show that as well.
dbcMessage->multiplexorSignal = currentSignal; dbcMessage->multiplexorSignal = currentSignal;
} }
ui->txtMultiplexValue->setEnabled(currentSignal->isMultiplexed); ui->txtMultiplexLow->setEnabled(currentSignal->isMultiplexed);
ui->txtMultiplexHigh->setEnabled(currentSignal->isMultiplexed);
ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed); ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed);
dbcFile->setDirtyFlag(); dbcFile->setDirtyFlag();
}); });
@@ -247,7 +261,8 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
currentSignal->isMultiplexor = false; currentSignal->isMultiplexor = false;
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr; if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
} }
ui->txtMultiplexValue->setEnabled(currentSignal->isMultiplexed); ui->txtMultiplexLow->setEnabled(currentSignal->isMultiplexed);
ui->txtMultiplexHigh->setEnabled(currentSignal->isMultiplexed);
ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed); ui->cbMultiplexParent->setEnabled(currentSignal->isMultiplexed);
dbcFile->setDirtyFlag(); dbcFile->setDirtyFlag();
}); });
@@ -259,26 +274,11 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
//add it to this one, update this signal's parent multiplexor //add it to this one, update this signal's parent multiplexor
DBC_SIGNAL *newSig = dbcMessage->sigHandler->findSignalByName(ui->cbMultiplexParent->currentText()); DBC_SIGNAL *newSig = dbcMessage->sigHandler->findSignalByName(ui->cbMultiplexParent->currentText());
DBC_SIGNAL *oldParent = currentSignal->multiplexParent; DBC_SIGNAL *oldParent = currentSignal->multiplexParent;
int low = currentSignal->multiplexValue;
int high = low;
if (newSig) if (newSig)
{ {
for (int i = 0; i < oldParent->multiplexedChildren.count(); i++) oldParent->multiplexedChildren.removeOne(currentSignal);
{
if (oldParent->multiplexedChildren[i].sig == currentSignal)
{
low = oldParent->multiplexedChildren[i].lowerBound;
high = oldParent->multiplexedChildren[i].upperBound;
oldParent->multiplexedChildren.removeAt(i);
break;
}
}
currentSignal->multiplexParent = newSig; currentSignal->multiplexParent = newSig;
DBC_MULTIPLEX mlt; newSig->multiplexedChildren.append(currentSignal);
mlt.lowerBound = low;
mlt.upperBound = high;
mlt.sig = currentSignal;
newSig->multiplexedChildren.append(mlt);
dbcFile->setDirtyFlag(); dbcFile->setDirtyFlag();
} }
}); });
@@ -441,7 +441,8 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig)
ui->txtMinVal->setText(""); ui->txtMinVal->setText("");
ui->txtScale->setText(""); ui->txtScale->setText("");
ui->txtUnitName->setText(""); ui->txtUnitName->setText("");
ui->txtMultiplexValue->setText(""); ui->txtMultiplexLow->setText("");
ui->txtMultiplexHigh->setText("");
ui->rbMultiplexed->setChecked(false); ui->rbMultiplexed->setChecked(false);
ui->rbMultiplexor->setChecked(false); ui->rbMultiplexor->setChecked(false);
ui->rbNotMulti->setChecked(true); ui->rbNotMulti->setChecked(true);
@@ -460,7 +461,8 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig)
ui->txtName->setText(sig->name); ui->txtName->setText(sig->name);
ui->txtBias->setText(QString::number(sig->bias)); ui->txtBias->setText(QString::number(sig->bias));
ui->txtBitLength->setText(QString::number(sig->signalSize)); ui->txtBitLength->setText(QString::number(sig->signalSize));
ui->txtMultiplexValue->setText(QString::number(sig->multiplexValue)); ui->txtMultiplexLow->setText(QString::number(sig->multiplexLowValue));
ui->txtMultiplexHigh->setText(QString::number(sig->multiplexHighValue));
ui->txtComment->setText(sig->comment); ui->txtComment->setText(sig->comment);
ui->txtMaxVal->setText(QString::number(sig->max)); ui->txtMaxVal->setText(QString::number(sig->max));
ui->txtMinVal->setText(QString::number(sig->min)); ui->txtMinVal->setText(QString::number(sig->min));
@@ -494,7 +496,8 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig)
} }
} }
ui->txtMultiplexValue->setEnabled(sig->isMultiplexed); ui->txtMultiplexLow->setEnabled(sig->isMultiplexed);
ui->txtMultiplexHigh->setEnabled(sig->isMultiplexed);
ui->cbMultiplexParent->setEnabled(sig->isMultiplexed); ui->cbMultiplexParent->setEnabled(sig->isMultiplexed);
memset(bitpattern, 0, 8); //clear it out first. memset(bitpattern, 0, 8); //clear it out first.
+16 -6
View File
@@ -190,33 +190,43 @@
<item row="10" column="0"> <item row="10" column="0">
<widget class="QLabel" name="label_15"> <widget class="QLabel" name="label_15">
<property name="text"> <property name="text">
<string>Multiplex Value</string> <string>Multiplex Low Value</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="1"> <item row="10" column="1">
<widget class="QLineEdit" name="txtMultiplexValue"/> <widget class="QLineEdit" name="txtMultiplexLow"/>
</item> </item>
<item row="12" column="0"> <item row="13" column="0">
<widget class="QLabel" name="label_13"> <widget class="QLabel" name="label_13">
<property name="text"> <property name="text">
<string>Comment:</string> <string>Comment:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="12" column="1"> <item row="13" column="1">
<widget class="QLineEdit" name="txtComment"/> <widget class="QLineEdit" name="txtComment"/>
</item> </item>
<item row="11" column="1"> <item row="12" column="1">
<widget class="QComboBox" name="cbMultiplexParent"/> <widget class="QComboBox" name="cbMultiplexParent"/>
</item> </item>
<item row="11" column="0"> <item row="12" column="0">
<widget class="QLabel" name="label_16"> <widget class="QLabel" name="label_16">
<property name="text"> <property name="text">
<string>Multiplex Parent</string> <string>Multiplex Parent</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="1">
<widget class="QLineEdit" name="txtMultiplexHigh"/>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Multiplex High Value</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>