Merge branch 'WIP' of github.com:collin80/SavvyCAN into WIP
This commit is contained in:
+31
-30
@@ -47,7 +47,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
|
||||
QString buildString;
|
||||
int startByte = startBit / 8;
|
||||
int bytes = signalSize / 8;
|
||||
for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]);
|
||||
for (int x = 0; x < bytes; x++) buildString.append(frame.payload().data()[startByte + x]);
|
||||
outString = buildString;
|
||||
cachedValue = outString;
|
||||
return true;
|
||||
@@ -56,7 +56,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
|
||||
//if this is a multiplexed signal then we have to see if it is even found in the current message
|
||||
if (isMultiplexed)
|
||||
{
|
||||
if (parentMessage->multiplexorSignal != NULL)
|
||||
if (parentMessage->multiplexorSignal != nullptr)
|
||||
{
|
||||
int val;
|
||||
if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false;
|
||||
@@ -68,7 +68,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
|
||||
if (valType == SIGNED_INT) isSigned = true;
|
||||
if (valType == SIGNED_INT || valType == UNSIGNED_INT)
|
||||
{
|
||||
result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned);
|
||||
result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned);
|
||||
endResult = ((double)result * factor) + bias;
|
||||
result = (int64_t)endResult;
|
||||
}
|
||||
@@ -79,19 +79,19 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
|
||||
//that the bytes that make up the integer are instead treated as having made up
|
||||
//a 32 bit single precision float. That's evil incarnate but it is very fast and small
|
||||
//in terms of new code.
|
||||
result = Utility::processIntegerSignal(frame.data, startBit, 32, false, false);
|
||||
result = Utility::processIntegerSignal(frame.payload(), startBit, 32, intelByteOrder, false);
|
||||
endResult = (*((float *)(&result)) * factor) + bias;
|
||||
}
|
||||
else //double precision float
|
||||
{
|
||||
if ( frame.len < 8 )
|
||||
if ( frame.payload().length() < 8 )
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
//like the above, this is rotten and evil and wrong in so many ways. Force
|
||||
//calculation of a 64 bit integer and then cast it into a double.
|
||||
result = Utility::processIntegerSignal(frame.data, 0, 64, false, false);
|
||||
result = Utility::processIntegerSignal(frame.payload(), 0, 64, intelByteOrder, false);
|
||||
endResult = (*((double *)(&result)) * factor) + bias;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue)
|
||||
//if this is a multiplexed signal then we have to see if it is even found in the current message
|
||||
if (isMultiplexed)
|
||||
{
|
||||
if (parentMessage->multiplexorSignal != NULL)
|
||||
if (parentMessage->multiplexorSignal != nullptr)
|
||||
{
|
||||
int val;
|
||||
if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false;
|
||||
@@ -155,15 +155,16 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue)
|
||||
}
|
||||
|
||||
if (valType == SIGNED_INT) isSigned = true;
|
||||
if ( frame.len*8 < (startBit+signalSize) )
|
||||
if ( static_cast<int>(frame.payload().length() * 8) < (startBit + signalSize) )
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned);
|
||||
|
||||
double endResult = ((double)result * factor) + bias;
|
||||
result = (int32_t)endResult;
|
||||
result = static_cast<int32_t>(Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned));
|
||||
|
||||
double endResult = (result * factor) + bias;
|
||||
result = static_cast<int32_t>(endResult);
|
||||
cachedValue = result;
|
||||
outValue = result;
|
||||
return true;
|
||||
@@ -187,7 +188,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
|
||||
//if this is a multiplexed signal then we have to see if it is even found in the current message
|
||||
if (isMultiplexed)
|
||||
{
|
||||
if (parentMessage->multiplexorSignal != NULL)
|
||||
if (parentMessage->multiplexorSignal != nullptr)
|
||||
{
|
||||
int val;
|
||||
if (!parentMessage->multiplexorSignal->processAsInt(frame, val)) return false;
|
||||
@@ -199,19 +200,19 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
|
||||
if (valType == SIGNED_INT) isSigned = true;
|
||||
if (valType == SIGNED_INT || valType == UNSIGNED_INT)
|
||||
{
|
||||
if ( frame.len*8 < (startBit+signalSize) )
|
||||
if ( frame.payload().length() * 8 < (startBit+signalSize) )
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned);
|
||||
result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned);
|
||||
endResult = ((double)result * factor) + bias;
|
||||
result = (int64_t)endResult;
|
||||
}
|
||||
/*TODO: It should be noted that the below floating point has not even been tested. For shame! Test it!*/
|
||||
else if (valType == SP_FLOAT)
|
||||
{
|
||||
if ( frame.len*8 < (startBit+32) )
|
||||
if ( frame.payload().length() * 8 < (startBit + 32) )
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
@@ -221,19 +222,19 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
|
||||
//that the bytes that make up the integer are instead treated as having made up
|
||||
//a 32 bit single precision float. That's evil incarnate but it is very fast and small
|
||||
//in terms of new code.
|
||||
result = Utility::processIntegerSignal(frame.data, startBit, 32, false, false);
|
||||
result = Utility::processIntegerSignal(frame.payload(), startBit, 32, false, false);
|
||||
endResult = (*((float *)(&result)) * factor) + bias;
|
||||
}
|
||||
else //double precision float
|
||||
{
|
||||
if ( frame.len < 8 )
|
||||
if ( frame.payload().length() < 8 )
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
//like the above, this is rotten and evil and wrong in so many ways. Force
|
||||
//calculation of a 64 bit integer and then cast it into a double.
|
||||
result = Utility::processIntegerSignal(frame.data, 0, 64, false, false);
|
||||
result = Utility::processIntegerSignal(frame.payload(), 0, 64, false, false);
|
||||
endResult = (*((double *)(&result)) * factor) + bias;
|
||||
}
|
||||
cachedValue = endResult;
|
||||
@@ -243,7 +244,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
|
||||
|
||||
DBC_ATTRIBUTE_VALUE *DBC_SIGNAL::findAttrValByName(QString name)
|
||||
{
|
||||
if (attributes.length() == 0) return NULL;
|
||||
if (attributes.length() == 0) return nullptr;
|
||||
for (int i = 0; i < attributes.length(); i++)
|
||||
{
|
||||
if (attributes[i].attrName.compare(name, Qt::CaseInsensitive) == 0)
|
||||
@@ -251,19 +252,19 @@ DBC_ATTRIBUTE_VALUE *DBC_SIGNAL::findAttrValByName(QString name)
|
||||
return &attributes[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE_VALUE *DBC_SIGNAL::findAttrValByIdx(int idx)
|
||||
{
|
||||
if (idx < 0) return NULL;
|
||||
if (idx >= attributes.count()) return NULL;
|
||||
if (idx < 0) return nullptr;
|
||||
if (idx >= attributes.count()) return nullptr;
|
||||
return &attributes[idx];
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE_VALUE *DBC_MESSAGE::findAttrValByName(QString name)
|
||||
{
|
||||
if (attributes.length() == 0) return NULL;
|
||||
if (attributes.length() == 0) return nullptr;
|
||||
for (int i = 0; i < attributes.length(); i++)
|
||||
{
|
||||
if (attributes[i].attrName.compare(name, Qt::CaseInsensitive) == 0)
|
||||
@@ -271,19 +272,19 @@ DBC_ATTRIBUTE_VALUE *DBC_MESSAGE::findAttrValByName(QString name)
|
||||
return &attributes[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE_VALUE *DBC_MESSAGE::findAttrValByIdx(int idx)
|
||||
{
|
||||
if (idx < 0) return NULL;
|
||||
if (idx >= attributes.count()) return NULL;
|
||||
if (idx < 0) return nullptr;
|
||||
if (idx >= attributes.count()) return nullptr;
|
||||
return &attributes[idx];
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE_VALUE *DBC_NODE::findAttrValByName(QString name)
|
||||
{
|
||||
if (attributes.length() == 0) return NULL;
|
||||
if (attributes.length() == 0) return nullptr;
|
||||
for (int i = 0; i < attributes.length(); i++)
|
||||
{
|
||||
if (attributes[i].attrName.compare(name, Qt::CaseInsensitive) == 0)
|
||||
@@ -291,12 +292,12 @@ DBC_ATTRIBUTE_VALUE *DBC_NODE::findAttrValByName(QString name)
|
||||
return &attributes[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE_VALUE *DBC_NODE::findAttrValByIdx(int idx)
|
||||
{
|
||||
if (idx < 0) return NULL;
|
||||
if (idx >= attributes.count()) return NULL;
|
||||
if (idx < 0) return nullptr;
|
||||
if (idx >= attributes.count()) return nullptr;
|
||||
return &attributes[idx];
|
||||
}
|
||||
|
||||
+139
-24
@@ -90,7 +90,7 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByID(uint32_t id)
|
||||
if (messages.count() == 0) return nullptr;
|
||||
for (int i = 0; i < messages.count(); i++)
|
||||
{
|
||||
if (isJ1939Handler)
|
||||
if (matchingCriteria == J1939)
|
||||
{
|
||||
// include data page and extended data page in the pgn
|
||||
uint32_t pgn = (id & 0x3FFFF00) >> 8;
|
||||
@@ -112,6 +112,13 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByID(uint32_t id)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (matchingCriteria == GMLAN)
|
||||
{
|
||||
// Match the bits 14-26 (Arbitration Id) of GMLAN 29bit header
|
||||
uint32_t arbId = id &0x3FFE000;
|
||||
if ( (arbId != 0) && (messages[i].ID & 0x3FFE000) == arbId )
|
||||
return &messages[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( messages[i].ID == id )
|
||||
@@ -206,29 +213,41 @@ int DBCMessageHandler::getCount()
|
||||
return messages.count();
|
||||
}
|
||||
|
||||
bool DBCMessageHandler::isJ1939()
|
||||
bool DBCMessageHandler::filterLabeling()
|
||||
{
|
||||
return isJ1939Handler;
|
||||
return filterLabelingEnabled;
|
||||
}
|
||||
|
||||
void DBCMessageHandler::setJ1939(bool j1939)
|
||||
void DBCMessageHandler::setFilterLabeling(bool filterLabeling)
|
||||
{
|
||||
isJ1939Handler = j1939;
|
||||
filterLabelingEnabled = filterLabeling;
|
||||
}
|
||||
|
||||
MatchingCriteria_t DBCMessageHandler::getMatchingCriteria()
|
||||
{
|
||||
return matchingCriteria;
|
||||
}
|
||||
|
||||
void DBCMessageHandler::setMatchingCriteria(MatchingCriteria_t _matchingCriteria)
|
||||
{
|
||||
matchingCriteria = _matchingCriteria;
|
||||
}
|
||||
|
||||
DBCFile::DBCFile()
|
||||
{
|
||||
messageHandler = new DBCMessageHandler;
|
||||
messageHandler->setJ1939(false);
|
||||
messageHandler->setMatchingCriteria(EXACT);
|
||||
messageHandler->setFilterLabeling(false);
|
||||
}
|
||||
|
||||
DBCFile::DBCFile(const DBCFile& cpy)
|
||||
DBCFile::DBCFile(const DBCFile& cpy) : QObject()
|
||||
{
|
||||
messageHandler = new DBCMessageHandler;
|
||||
for (int i = 0 ; i < cpy.messageHandler->getCount() ; i++)
|
||||
messageHandler->addMessage(*cpy.messageHandler->findMsgByIdx(i));
|
||||
|
||||
messageHandler->setJ1939(cpy.messageHandler->isJ1939());
|
||||
messageHandler->setMatchingCriteria(cpy.messageHandler->getMatchingCriteria());
|
||||
messageHandler->setFilterLabeling(cpy.messageHandler->filterLabeling());
|
||||
fileName = cpy.fileName;
|
||||
filePath = cpy.filePath;
|
||||
assocBuses = cpy.assocBuses;
|
||||
@@ -296,9 +315,10 @@ int DBCFile::getAssocBus()
|
||||
|
||||
void DBCFile::setAssocBus(int bus)
|
||||
{
|
||||
int numBuses = CANConManager::getInstance()->getNumBuses();
|
||||
if (bus < -1) return;
|
||||
if (bus >= numBuses) return;
|
||||
// To allow setting bus numbers even before connection is configured, do not enforce "valid" bus numbers
|
||||
//int numBuses = CANConManager::getInstance()->getNumBuses();
|
||||
//if (bus >= numBuses) return;
|
||||
assocBuses = bus;
|
||||
}
|
||||
|
||||
@@ -448,6 +468,14 @@ DBC_SIGNAL* DBCFile::parseSignalLine(QString line, DBC_MESSAGE *msg)
|
||||
case 4:
|
||||
sig.valType = STRING;
|
||||
break;
|
||||
case 5: //single point float in little endian
|
||||
sig.valType = SP_FLOAT;
|
||||
sig.intelByteOrder = true;
|
||||
break;
|
||||
case 6: //double point float in little endian
|
||||
sig.valType = DP_FLOAT;
|
||||
sig.intelByteOrder = true;
|
||||
break;
|
||||
}
|
||||
sig.factor = match.captured(6 + offset).toDouble();
|
||||
sig.bias = match.captured(7 + offset).toDouble();
|
||||
@@ -693,7 +721,8 @@ void DBCFile::loadFile(QString fileName)
|
||||
qDebug() << "Starting DBC load";
|
||||
dbc_nodes.clear();
|
||||
messageHandler->removeAllMessages();
|
||||
messageHandler->setJ1939(false);
|
||||
messageHandler->setMatchingCriteria(EXACT);
|
||||
messageHandler->setFilterLabeling(false);
|
||||
|
||||
DBC_NODE falseNode;
|
||||
falseNode.name = "Vector__XXX";
|
||||
@@ -887,14 +916,24 @@ void DBCFile::loadFile(QString fileName)
|
||||
fgAttr = findAttributeByName("GenMsgForegroundColor");
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE *j1939attr = findAttributeByName("isj1939dbc");
|
||||
if (j1939attr)
|
||||
DBC_ATTRIBUTE *mc_attr = findAttributeByName("matchingcriteria");
|
||||
if (mc_attr)
|
||||
{
|
||||
messageHandler->setJ1939(j1939attr->defaultValue > 0);
|
||||
messageHandler->setMatchingCriteria((MatchingCriteria_t)mc_attr->defaultValue.toInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
messageHandler->setJ1939(false);
|
||||
messageHandler->setMatchingCriteria(EXACT);
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE *fl_attr = findAttributeByName("filterlabeling");
|
||||
if (fl_attr)
|
||||
{
|
||||
messageHandler->setFilterLabeling(fl_attr->defaultValue.toInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
messageHandler->setFilterLabeling(false);
|
||||
}
|
||||
|
||||
QColor DefaultBG = QColor(bgAttr->defaultValue.toString());
|
||||
@@ -1202,10 +1241,12 @@ void DBCFile::saveFile(QString fileName)
|
||||
else msgOutput.append("0-");
|
||||
break;
|
||||
case SP_FLOAT:
|
||||
msgOutput.append("2-");
|
||||
if (sig->intelByteOrder) msgOutput.append("5-");
|
||||
else msgOutput.append("2-");
|
||||
break;
|
||||
case DP_FLOAT:
|
||||
msgOutput.append("3-");
|
||||
if (sig->intelByteOrder) msgOutput.append("6-");
|
||||
else msgOutput.append("3-");
|
||||
break;
|
||||
case STRING:
|
||||
msgOutput.append("4-");
|
||||
@@ -1402,7 +1443,16 @@ int DBCHandler::createBlankFile()
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "isj1939dbc";
|
||||
attr.name = "matchingcriteria";
|
||||
attr.valType = QINT;
|
||||
newFile.dbc_attributes.append(attr);
|
||||
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = 0;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "filterlabeling";
|
||||
attr.valType = QINT;
|
||||
newFile.dbc_attributes.append(attr);
|
||||
|
||||
@@ -1415,6 +1465,14 @@ int DBCHandler::createBlankFile()
|
||||
return loadedFiles.count();
|
||||
}
|
||||
|
||||
DBCFile* DBCHandler::loadDBCFile(QString filename)
|
||||
{
|
||||
DBCFile newFile;
|
||||
newFile.loadFile(filename);
|
||||
loadedFiles.append(newFile);
|
||||
return &loadedFiles.last();
|
||||
}
|
||||
|
||||
//the only reason to even bother sending the index is to see if
|
||||
//the user wants to replace an already loaded DBC.
|
||||
//Otherwise add a new one. Well, always add a new one.
|
||||
@@ -1440,11 +1498,8 @@ DBCFile* DBCHandler::loadDBCFile(int idx)
|
||||
{
|
||||
filename = dialog.selectedFiles()[0];
|
||||
//right now there is only one file type that can be loaded here so just do it.
|
||||
DBCFile newFile;
|
||||
newFile.loadFile(filename);
|
||||
loadedFiles.append(newFile);
|
||||
settings.setValue("DBC/LoadSaveDirectory", dialog.directory().path());
|
||||
return &loadedFiles.last();
|
||||
return loadDBCFile(filename);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -1650,7 +1705,7 @@ void DBCHandler::swapFiles(int pos1, int pos2)
|
||||
* Convenience function that encapsulates a whole lot of the details.
|
||||
* You give it a canbus frame and it'll tell you whether there is a loaded DBC file that can
|
||||
* interpret that frame for you.
|
||||
* Returns NULL if there is no message definition that matches.
|
||||
* Returns nullptr if there is no message definition that matches.
|
||||
*/
|
||||
DBC_MESSAGE* DBCHandler::findMessage(const CANFrame &frame)
|
||||
{
|
||||
@@ -1658,13 +1713,36 @@ DBC_MESSAGE* DBCHandler::findMessage(const CANFrame &frame)
|
||||
{
|
||||
if (loadedFiles[i].getAssocBus() == -1 || frame.bus == (unsigned int)loadedFiles[i].getAssocBus())
|
||||
{
|
||||
DBC_MESSAGE* msg = loadedFiles[i].messageHandler->findMsgByID(frame.ID);
|
||||
DBC_MESSAGE* msg = loadedFiles[i].messageHandler->findMsgByID(frame.frameId());
|
||||
if (msg != nullptr) return msg;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
// This function won't care which bus the DBC file is associated, but will return any message as long as ID matches and the file
|
||||
// has filter labeling enabled.
|
||||
// Returns the found message as well as the matching criteria (exact/J1939/GMLAN)
|
||||
// Used for quickly populating the Frame Filtering section with interpreted values
|
||||
DBC_MESSAGE* DBCHandler::findMessageForFilter(uint32_t id, MatchingCriteria_t * matchingCriteria)
|
||||
{
|
||||
for(int i = 0; i < loadedFiles.count(); i++)
|
||||
{
|
||||
if (loadedFiles[i].messageHandler->filterLabeling())
|
||||
{
|
||||
DBC_MESSAGE* msg = loadedFiles[i].messageHandler->findMsgByID(id);
|
||||
if (msg != nullptr)
|
||||
{
|
||||
*matchingCriteria = loadedFiles[i].messageHandler->getMatchingCriteria();
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* As above, a real shortcut function that searches all files in order to try to find a message with the given name
|
||||
*/
|
||||
@@ -1708,7 +1786,44 @@ DBCFile* DBCHandler::getFileByName(QString name)
|
||||
|
||||
DBCHandler::DBCHandler()
|
||||
{
|
||||
// Load previously saved DBC file settings
|
||||
QSettings settings;
|
||||
int filecount = settings.value("DBC/FileCount", 0).toInt();
|
||||
for (int i=0; i<filecount; i++)
|
||||
{
|
||||
QString filename = settings.value("DBC/Filename_" + QString(i),"").toString();
|
||||
DBCFile * file = loadDBCFile(filename);
|
||||
int bus = settings.value("DBC/AssocBus_" + QString(i),0).toInt();
|
||||
file->setAssocBus(bus);
|
||||
|
||||
MatchingCriteria_t matchingCriteria = (MatchingCriteria_t)settings.value("DBC/MatchingCriteria_" + QString(i),0).toInt();
|
||||
|
||||
DBC_ATTRIBUTE attr;
|
||||
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = matchingCriteria;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "matchingcriteria";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setMatchingCriteria(matchingCriteria);
|
||||
|
||||
bool filterLabeling = settings.value("DBC/FilterLabeling_" + QString(i),0).toBool();
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = filterLabeling;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "filterlabeling";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setFilterLabeling(filterLabeling);
|
||||
|
||||
qInfo() << "Loaded DBC file" << filename << " (bus:" << bus
|
||||
<< ", Matching Criteria:" << (int)matchingCriteria << "Filter labeling: " << (filterLabeling?"enabled":"disabled") << ")";
|
||||
}
|
||||
}
|
||||
|
||||
DBCHandler* DBCHandler::getReference()
|
||||
|
||||
+15
-3
@@ -5,6 +5,13 @@
|
||||
#include "dbc_classes.h"
|
||||
#include "can_structs.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EXACT,
|
||||
J1939,
|
||||
GMLAN
|
||||
} MatchingCriteria_t;
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* Finish coding up the decoupled design
|
||||
@@ -40,11 +47,14 @@ public:
|
||||
bool removeMessage(QString name);
|
||||
void removeAllMessages();
|
||||
int getCount();
|
||||
bool isJ1939();
|
||||
void setJ1939(bool j1939);
|
||||
MatchingCriteria_t getMatchingCriteria();
|
||||
void setMatchingCriteria(MatchingCriteria_t mc);
|
||||
void setFilterLabeling( bool labelFiltering );
|
||||
bool filterLabeling();
|
||||
private:
|
||||
QList<DBC_MESSAGE> messages;
|
||||
bool isJ1939Handler;
|
||||
MatchingCriteria_t matchingCriteria;
|
||||
bool filterLabelingEnabled;
|
||||
};
|
||||
|
||||
//technically there should be a node handler too but I'm sort of treating nodes as second class
|
||||
@@ -90,6 +100,7 @@ class DBCHandler: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DBCFile* loadDBCFile(QString filename);
|
||||
DBCFile* loadDBCFile(int);
|
||||
void saveDBCFile(int);
|
||||
void removeDBCFile(int);
|
||||
@@ -97,6 +108,7 @@ public:
|
||||
void swapFiles(int pos1, int pos2);
|
||||
DBC_MESSAGE* findMessage(const CANFrame &frame);
|
||||
DBC_MESSAGE* findMessage(const QString msgName);
|
||||
DBC_MESSAGE* findMessageForFilter(uint32_t id, MatchingCriteria_t * matchingCriteria);
|
||||
int getFileCount();
|
||||
DBCFile* getFileByIdx(int idx);
|
||||
DBCFile* getFileByName(QString name);
|
||||
|
||||
+152
-21
@@ -1,6 +1,8 @@
|
||||
#include "dbcloadsavewindow.h"
|
||||
#include "ui_dbcloadsavewindow.h"
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QMessageBox>
|
||||
#include <qevent.h>
|
||||
#include "helpwindow.h"
|
||||
#include "connections/canconmanager.h"
|
||||
|
||||
@@ -15,17 +17,47 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *p
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
inhibitCellProcessing = false;
|
||||
inhibitCellProcessing = true;
|
||||
|
||||
QStringList header;
|
||||
header << "Filename" << "Associated Bus" << "J1939";
|
||||
ui->tableFiles->setColumnCount(3);
|
||||
header << "Filename" << "Associated Bus" << "Matching criteria" << "Label filters";
|
||||
ui->tableFiles->setColumnCount(4);
|
||||
ui->tableFiles->setHorizontalHeaderLabels(header);
|
||||
ui->tableFiles->setColumnWidth(0, 265);
|
||||
ui->tableFiles->setColumnWidth(1, 125);
|
||||
ui->tableFiles->setColumnWidth(2, 80);
|
||||
ui->tableFiles->setColumnWidth(2, 120);
|
||||
ui->tableFiles->setColumnWidth(3, 90);
|
||||
ui->tableFiles->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
// Populate table
|
||||
for (int idx=0; idx<dbcHandler->getFileCount(); idx++)
|
||||
{
|
||||
DBCFile * file = dbcHandler->getFileByIdx(idx);
|
||||
ui->tableFiles->insertRow(ui->tableFiles->rowCount());
|
||||
ui->tableFiles->setItem(idx, 0, new QTableWidgetItem(file->getFullFilename()));
|
||||
QString bus = QString::number(file->getAssocBus() );
|
||||
ui->tableFiles->setItem(idx, 1, new QTableWidgetItem(bus));
|
||||
|
||||
QComboBox * mc_item = addMatchingCriteriaCombobox(idx);
|
||||
int mc = (int)file->messageHandler->getMatchingCriteria();
|
||||
mc_item->setCurrentIndex(mc);
|
||||
|
||||
QTableWidgetItem *item = new QTableWidgetItem("");
|
||||
ui->tableFiles->setItem(idx, 3, item);
|
||||
bool filterLabeling = file->messageHandler->filterLabeling();
|
||||
if (filterLabeling)
|
||||
{
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
|
||||
qDebug() << "Populate DBC table:" << file->getFullFilename() << " (bus:" << bus << " - Matching Criteria:" << mc
|
||||
<< "Filter labeling: " << (filterLabeling?"enabled":"disabled") << ")";
|
||||
}
|
||||
|
||||
connect(ui->btnEdit, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::editFile);
|
||||
connect(ui->btnLoad, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::loadFile);
|
||||
connect(ui->btnMoveDown, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::moveDown);
|
||||
@@ -40,15 +72,51 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *p
|
||||
editorWindow = new DBCMainEditor(frames, this);
|
||||
currentlyEditingFile = nullptr;
|
||||
|
||||
inhibitCellProcessing = false;
|
||||
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
QComboBox * DBCLoadSaveWindow::addMatchingCriteriaCombobox(int row)
|
||||
{
|
||||
QComboBox *item = new QComboBox();
|
||||
item->addItem("Exact");
|
||||
item->addItem("J1939");
|
||||
item->addItem("GMLAN");
|
||||
ui->tableFiles->setCellWidget(row, 2, item);
|
||||
connect(item, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
[this](int box_idx) { matchingCriteriaChanged(box_idx); } );
|
||||
return item;
|
||||
}
|
||||
|
||||
DBCLoadSaveWindow::~DBCLoadSaveWindow()
|
||||
{
|
||||
removeEventFilter(this);
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::updateSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
int filecount = ui->tableFiles->rowCount();
|
||||
settings.setValue("DBC/FileCount", filecount);
|
||||
for (int i=0; i<filecount; i++)
|
||||
{
|
||||
DBCFile * file = dbcHandler->getFileByIdx(i);
|
||||
if (file)
|
||||
{
|
||||
qDebug() << "Save DBC settings #" << i << " File: " << file->getFullFilename()
|
||||
<< "Bus: " << file->getAssocBus() << "MC: " << file->messageHandler->getMatchingCriteria()
|
||||
<< "Filter Labeling: " << (file->messageHandler->filterLabeling() ? "enabled" : "disabled");
|
||||
settings.setValue("DBC/Filename_" + QString(i), file->getFullFilename());
|
||||
settings.setValue("DBC/AssocBus_" + QString(i), file->getAssocBus());
|
||||
settings.setValue("DBC/MatchingCriteria_" + QString(i), file->messageHandler->getMatchingCriteria());
|
||||
settings.setValue("DBC/FilterLabeling_" + QString(i), file->messageHandler->filterLabeling());
|
||||
}
|
||||
}
|
||||
emit updatedDBCSettings();
|
||||
}
|
||||
|
||||
bool DBCLoadSaveWindow::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyRelease) {
|
||||
@@ -75,22 +143,34 @@ void DBCLoadSaveWindow::newFile()
|
||||
ui->tableFiles->setItem(idx, 0, new QTableWidgetItem("UNNAMEDFILE"));
|
||||
ui->tableFiles->setItem(idx, 1, new QTableWidgetItem("-1"));
|
||||
|
||||
QComboBox * mc_item = addMatchingCriteriaCombobox(idx);
|
||||
mc_item->setCurrentIndex(EXACT);
|
||||
|
||||
QTableWidgetItem *item = new QTableWidgetItem("");
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
ui->tableFiles->setItem(idx, 2, item);
|
||||
item->setCheckState(Qt::Checked);
|
||||
ui->tableFiles->setItem(idx, 3, item);
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::loadFile()
|
||||
{
|
||||
DBCFile *file = dbcHandler->loadDBCFile(-1);
|
||||
if(file) {
|
||||
inhibitCellProcessing=true;
|
||||
int idx = ui->tableFiles->rowCount();
|
||||
ui->tableFiles->insertRow(ui->tableFiles->rowCount());
|
||||
ui->tableFiles->setItem(idx, 0, new QTableWidgetItem(file->getFullFilename()));
|
||||
ui->tableFiles->setItem(idx, 1, new QTableWidgetItem("-1"));
|
||||
DBC_ATTRIBUTE *attr = file->findAttributeByName("isj1939dbc");
|
||||
|
||||
DBC_ATTRIBUTE *attr = file->findAttributeByName("matchingcriteria");
|
||||
QComboBox * mc_item = addMatchingCriteriaCombobox(idx);
|
||||
if (attr && attr->defaultValue > 0)
|
||||
{
|
||||
mc_item->setCurrentIndex(attr->defaultValue.toInt());
|
||||
}
|
||||
|
||||
attr = file->findAttributeByName("filterlabeling");
|
||||
QTableWidgetItem *item = new QTableWidgetItem("");
|
||||
ui->tableFiles->setItem(idx, 2, item);
|
||||
ui->tableFiles->setItem(idx, 3, item);
|
||||
if (attr && attr->defaultValue > 0)
|
||||
{
|
||||
item->setCheckState(Qt::Checked);
|
||||
@@ -99,6 +179,9 @@ void DBCLoadSaveWindow::loadFile()
|
||||
{
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
inhibitCellProcessing=false;
|
||||
|
||||
updateSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +237,7 @@ void DBCLoadSaveWindow::removeFile()
|
||||
dbcHandler->removeDBCFile(idx);
|
||||
ui->tableFiles->removeRow(idx);
|
||||
}
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::moveUp()
|
||||
@@ -162,6 +246,7 @@ void DBCLoadSaveWindow::moveUp()
|
||||
if (idx < 1) return;
|
||||
dbcHandler->swapFiles(idx - 1, idx);
|
||||
swapTableRows(true);
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::moveDown()
|
||||
@@ -171,6 +256,7 @@ void DBCLoadSaveWindow::moveDown()
|
||||
if (idx > (dbcHandler->getFileCount() - 2)) return;
|
||||
dbcHandler->swapFiles(idx, idx + 1);
|
||||
swapTableRows(false);
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::editFile()
|
||||
@@ -182,6 +268,43 @@ void DBCLoadSaveWindow::editFile()
|
||||
editorWindow->show();
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::matchingCriteriaChanged(int index)
|
||||
{
|
||||
if (inhibitCellProcessing) return;
|
||||
// We don't know which combobox changed, so we just update all of them
|
||||
for (int row=0; row<ui->tableFiles->rowCount(); row++)
|
||||
{
|
||||
DBCFile *file = dbcHandler->getFileByIdx(row);
|
||||
if (file)
|
||||
{
|
||||
QComboBox *item = (QComboBox*)ui->tableFiles->cellWidget(row, 2);
|
||||
MatchingCriteria_t matchingCriteria = (MatchingCriteria_t) item->currentIndex();
|
||||
DBC_ATTRIBUTE *attr = file->findAttributeByName("matchingcriteria");
|
||||
if (attr)
|
||||
{
|
||||
attr->defaultValue = matchingCriteria;
|
||||
file->messageHandler->setMatchingCriteria(matchingCriteria);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBC_ATTRIBUTE attr;
|
||||
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = matchingCriteria;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "matchingcriteria";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setMatchingCriteria(matchingCriteria);
|
||||
}
|
||||
}
|
||||
}
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
|
||||
void DBCLoadSaveWindow::cellChanged(int row, int col)
|
||||
{
|
||||
if (inhibitCellProcessing) return;
|
||||
@@ -190,39 +313,40 @@ void DBCLoadSaveWindow::cellChanged(int row, int col)
|
||||
DBCFile *file = dbcHandler->getFileByIdx(row);
|
||||
int bus = ui->tableFiles->item(row, col)->text().toInt();
|
||||
int numBuses = CANConManager::getInstance()->getNumBuses();
|
||||
if (bus > -2 && bus < numBuses)
|
||||
if (bus > -2)
|
||||
{
|
||||
file->setAssocBus(bus);
|
||||
}
|
||||
}
|
||||
else if (col == 2)
|
||||
updateSettings();
|
||||
}
|
||||
else if (col == 3) // labelfilters
|
||||
{
|
||||
DBCFile *file = dbcHandler->getFileByIdx(row);
|
||||
if (file)
|
||||
{
|
||||
//int isj1939dbc = ui->tableFiles->item(row, col)->text().toInt();
|
||||
bool isj1939dbc = ui->tableFiles->item(row, col)->checkState() == Qt::Checked;
|
||||
DBC_ATTRIBUTE *attr = file->findAttributeByName("isj1939dbc");
|
||||
bool labelFilters = ui->tableFiles->item(row, col)->checkState() == Qt::Checked;
|
||||
DBC_ATTRIBUTE *attr = file->findAttributeByName("filterlabeling");
|
||||
if (attr)
|
||||
{
|
||||
attr->defaultValue = isj1939dbc ? 1 : 0;
|
||||
file->messageHandler->setJ1939(isj1939dbc);
|
||||
attr->defaultValue = labelFilters ? 1 : 0;
|
||||
file->messageHandler->setFilterLabeling(labelFilters);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBC_ATTRIBUTE attr;
|
||||
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = isj1939dbc ? 1 : 0;
|
||||
attr.defaultValue = labelFilters ? 1 : 0;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "isj1939dbc";
|
||||
attr.name = "labelfilters";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setJ1939(isj1939dbc);
|
||||
file->messageHandler->setFilterLabeling(labelFilters);
|
||||
}
|
||||
}
|
||||
updateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,10 +369,17 @@ void DBCLoadSaveWindow::swapTableRows(bool up)
|
||||
QList<QTableWidgetItem*> sourceItems = takeRow(idx);
|
||||
QList<QTableWidgetItem*> destItems = takeRow(destIdx);
|
||||
|
||||
// QCombobox needs separate handling
|
||||
int sourceMC = ((QComboBox*)ui->tableFiles->cellWidget(idx,2))->currentIndex();
|
||||
int destMC = ((QComboBox*)ui->tableFiles->cellWidget(destIdx,2))->currentIndex();
|
||||
|
||||
// set back in reverse order
|
||||
setRow(idx, destItems);
|
||||
setRow(destIdx, sourceItems);
|
||||
|
||||
((QComboBox*)ui->tableFiles->cellWidget(idx,2))->setCurrentIndex(destMC);
|
||||
((QComboBox*)ui->tableFiles->cellWidget(destIdx,2))->setCurrentIndex(sourceMC);
|
||||
|
||||
inhibitCellProcessing = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTableWidget>
|
||||
#include <QComboBox>
|
||||
#include "dbchandler.h"
|
||||
#include "dbcmaineditor.h"
|
||||
|
||||
@@ -28,8 +29,12 @@ private slots:
|
||||
void editFile();
|
||||
void cellChanged(int row, int col);
|
||||
void cellDoubleClicked(int row, int col);
|
||||
void matchingCriteriaChanged(int index);
|
||||
void newFile();
|
||||
|
||||
signals:
|
||||
void updatedDBCSettings();
|
||||
|
||||
private:
|
||||
Ui::DBCLoadSaveWindow *ui;
|
||||
DBCHandler *dbcHandler;
|
||||
@@ -42,6 +47,8 @@ private:
|
||||
QList<QTableWidgetItem*> takeRow(int row);
|
||||
void setRow(int row, const QList<QTableWidgetItem*>& rowItems);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
void updateSettings();
|
||||
QComboBox * addMatchingCriteriaCombobox(int row);
|
||||
};
|
||||
|
||||
#endif // DBCLOADSAVEWINDOW_H
|
||||
|
||||
+16
-15
@@ -5,6 +5,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
#include <QColorDialog>
|
||||
#include <qevent.h>
|
||||
#include "helpwindow.h"
|
||||
|
||||
DBCMainEditor::DBCMainEditor( const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
@@ -193,7 +194,7 @@ void DBCMainEditor::onCellChangedNode(int row,int col)
|
||||
QString newName = ui->NodesTable->item(row, col)->text().simplified().replace(' ', '_');
|
||||
qDebug() << "new name: " << newName;
|
||||
if (newName.length() == 0) return;
|
||||
if (dbcFile->findNodeByName(newName) != NULL) //duplicates an existing node!
|
||||
if (dbcFile->findNodeByName(newName) != nullptr) //duplicates an existing node!
|
||||
{
|
||||
QMessageBox msg;
|
||||
msg.setParent(0);
|
||||
@@ -217,7 +218,7 @@ void DBCMainEditor::onCellChangedNode(int row,int col)
|
||||
{
|
||||
DBC_NODE *oldNode = dbcFile->findNodeByIdx(row);
|
||||
QString nodeName = ui->NodesTable->item(row, col)->text().simplified().replace(' ', '_');
|
||||
if (oldNode == NULL) return;
|
||||
if (oldNode == nullptr) return;
|
||||
if (row != 0) oldNode->name = nodeName;
|
||||
else nodeName = oldNode->name;
|
||||
inhibitCellChanged = true;
|
||||
@@ -230,7 +231,7 @@ void DBCMainEditor::onCellChangedNode(int row,int col)
|
||||
QString nodeName = ui->NodesTable->item(row, 0)->text().simplified().replace(' ', '_');
|
||||
qDebug() << "searching for node " << nodeName;
|
||||
DBC_NODE *thisNode = dbcFile->findNodeByName(nodeName);
|
||||
if (thisNode == NULL) return;
|
||||
if (thisNode == nullptr) return;
|
||||
thisNode->comment = ui->NodesTable->item(row, col)->text().simplified();
|
||||
qDebug() << "New comment: " << thisNode->comment;
|
||||
}
|
||||
@@ -240,15 +241,15 @@ void DBCMainEditor::onCellChangedNode(int row,int col)
|
||||
|
||||
void DBCMainEditor::onCellChangedMessage(int row,int col)
|
||||
{
|
||||
QTableWidgetItem* item = NULL;
|
||||
QTableWidgetItem* item = nullptr;
|
||||
bool ret = false;
|
||||
DBC_MESSAGE *msg = NULL;
|
||||
DBC_MESSAGE *msg = nullptr;
|
||||
uint msgID;
|
||||
|
||||
if (inhibitCellChanged) return;
|
||||
|
||||
DBC_NODE *node = dbcFile->findNodeByIdx(ui->NodesTable->currentRow());
|
||||
if (node == NULL)
|
||||
if (node == nullptr)
|
||||
{
|
||||
qDebug() << "No node set?!? This is bad!";
|
||||
return;
|
||||
@@ -271,7 +272,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
|
||||
ui->MessagesTable->item(row, 0)->setText("");
|
||||
return;
|
||||
}
|
||||
if (msg != NULL)
|
||||
if (msg != nullptr)
|
||||
{
|
||||
QMessageBox msg;
|
||||
msg.setParent(0);
|
||||
@@ -293,9 +294,9 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
|
||||
|
||||
for (int i = 0; i < referenceFrames->length(); i++)
|
||||
{
|
||||
if ((uint) referenceFrames->at(i).ID == msgID)
|
||||
if ((uint) referenceFrames->at(i).frameId() == msgID)
|
||||
{
|
||||
newMsg.len = referenceFrames->at(i).len;
|
||||
newMsg.len = referenceFrames->at(i).payload().length();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -328,7 +329,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
|
||||
{
|
||||
QString msgName = ui->MessagesTable->item(row, 1)->text().simplified().replace(' ', '_');
|
||||
if (msgName.length() == 0) return;
|
||||
if( ret && (msg!=NULL) )
|
||||
if( ret && (msg!=nullptr) )
|
||||
msg->name = msgName;
|
||||
break;
|
||||
}
|
||||
@@ -349,7 +350,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
|
||||
ui->MessagesTable->item(row, col)->setText(QString::number(msgLen));
|
||||
}
|
||||
|
||||
if( ret && (msg!=NULL) )
|
||||
if( ret && (msg!=nullptr) )
|
||||
msg->len = msgLen;
|
||||
break;
|
||||
}
|
||||
@@ -358,7 +359,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
|
||||
case 6: //comment
|
||||
{
|
||||
QString msgComment = ui->MessagesTable->item(row, col)->text().simplified();
|
||||
if( ret && (msgComment!=NULL) )
|
||||
if( ret && (msgComment!=nullptr) )
|
||||
msg->comment = msgComment;
|
||||
break;
|
||||
}
|
||||
@@ -376,7 +377,7 @@ void DBCMainEditor::onCellClickedNode(int row, int col)
|
||||
currRow = row;
|
||||
QTableWidgetItem *item = ui->NodesTable->item(currRow, 0);
|
||||
QString nodeName;
|
||||
if (item == NULL) return;
|
||||
if (item == nullptr) return;
|
||||
|
||||
nodeName = item->text();
|
||||
qDebug() << "Trying to find node with name " << nodeName;
|
||||
@@ -476,7 +477,7 @@ void DBCMainEditor::refreshNodesTable()
|
||||
|
||||
int rowIdx;
|
||||
|
||||
if (dbcFile->findNodeByName("Vector__XXX") == NULL)
|
||||
if (dbcFile->findNodeByName("Vector__XXX") == nullptr)
|
||||
{
|
||||
DBC_NODE newNode;
|
||||
newNode.name = "Vector__XXX";
|
||||
@@ -509,7 +510,7 @@ void DBCMainEditor::refreshMessagesTable(const DBC_NODE *node)
|
||||
|
||||
int rowIdx;
|
||||
|
||||
if (node != NULL)
|
||||
if (node != nullptr)
|
||||
{
|
||||
for (int x = 0; x < dbcFile->messageHandler->getCount(); x++)
|
||||
{
|
||||
|
||||
+27
-30
@@ -4,6 +4,7 @@
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
#include <QSettings>
|
||||
#include <qevent.h>
|
||||
#include "helpwindow.h"
|
||||
|
||||
DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
@@ -17,8 +18,8 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
qsrand(QDateTime::currentMSecsSinceEpoch());
|
||||
|
||||
dbcHandler = DBCHandler::getReference();
|
||||
dbcMessage = NULL;
|
||||
currentSignal = NULL;
|
||||
dbcMessage = nullptr;
|
||||
currentSignal = nullptr;
|
||||
|
||||
QStringList headers2;
|
||||
headers2 << "Value" << "Text";
|
||||
@@ -46,23 +47,21 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->cbIntelFormat, &QCheckBox::toggled,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
currentSignal->intelByteOrder = ui->cbIntelFormat->isChecked();
|
||||
if (currentSignal->valType == SP_FLOAT || currentSignal->valType == DP_FLOAT)
|
||||
currentSignal->intelByteOrder = false;
|
||||
fillSignalForm(currentSignal);
|
||||
});
|
||||
|
||||
connect(ui->comboReceiver, &QComboBox::currentTextChanged,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
currentSignal->receiver = dbcFile->findNodeByName(ui->comboReceiver->currentText());
|
||||
});
|
||||
connect(ui->comboType, &QComboBox::currentTextChanged,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
switch (ui->comboType->currentIndex())
|
||||
{
|
||||
case 0:
|
||||
@@ -73,13 +72,11 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
break;
|
||||
case 2:
|
||||
currentSignal->valType = SP_FLOAT;
|
||||
currentSignal->intelByteOrder = false;
|
||||
if (currentSignal->startBit > 39) currentSignal->startBit = 39;
|
||||
currentSignal->signalSize = 32;
|
||||
break;
|
||||
case 3:
|
||||
currentSignal->valType = DP_FLOAT;
|
||||
currentSignal->intelByteOrder = false;
|
||||
currentSignal->startBit = 7; //has to be!
|
||||
currentSignal->signalSize = 64;
|
||||
break;
|
||||
@@ -92,7 +89,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->txtBias, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
double temp;
|
||||
bool result;
|
||||
temp = ui->txtBias->text().toDouble(&result);
|
||||
@@ -102,7 +99,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->txtMaxVal, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
double temp;
|
||||
bool result;
|
||||
temp = ui->txtMaxVal->text().toDouble(&result);
|
||||
@@ -112,7 +109,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->txtMinVal, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
double temp;
|
||||
bool result;
|
||||
temp = ui->txtMinVal->text().toDouble(&result);
|
||||
@@ -121,7 +118,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->txtScale, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
double temp;
|
||||
bool result;
|
||||
temp = ui->txtScale->text().toDouble(&result);
|
||||
@@ -130,24 +127,24 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->txtComment, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
currentSignal->comment = ui->txtComment->text().simplified().replace(' ', '_');
|
||||
});
|
||||
|
||||
connect(ui->txtUnitName, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
currentSignal->unitName = ui->txtUnitName->text().simplified().replace(' ', '_');
|
||||
});
|
||||
connect(ui->txtBitLength, &QLineEdit::textChanged,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
int temp;
|
||||
temp = Utility::ParseStringToNum(ui->txtBitLength->text());
|
||||
if (temp < 0) return;
|
||||
if (temp > 63) return;
|
||||
if (temp < 1) return;
|
||||
if (temp > 64) return;
|
||||
if (currentSignal->valType != SP_FLOAT && currentSignal->valType != DP_FLOAT)
|
||||
currentSignal->signalSize = temp;
|
||||
fillSignalForm(currentSignal);
|
||||
@@ -155,7 +152,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->txtName, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
QString tempNameStr = ui->txtName->text().simplified().replace(' ', '_');
|
||||
if (tempNameStr.length() > 0) currentSignal->name = tempNameStr;
|
||||
//need to update the list too.
|
||||
@@ -165,7 +162,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
connect(ui->txtMultiplexValue, &QLineEdit::editingFinished,
|
||||
[=]()
|
||||
{
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
int temp;
|
||||
temp = Utility::ParseStringToNum(ui->txtMultiplexValue->text());
|
||||
//TODO: could look up the multiplexor and ensure that the value is within a range that the multiplexor could return
|
||||
@@ -179,7 +176,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
currentSignal->isMultiplexed = true;
|
||||
currentSignal->isMultiplexor = false;
|
||||
//if the set multiplexor for the message was this signal then clear it
|
||||
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = NULL;
|
||||
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -189,7 +186,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
if (state && currentSignal) //signal is now set as a multiplexed signal
|
||||
{
|
||||
//don't allow this signal to be a multiplexor if there is already one for this message.
|
||||
//if (dbcMessage->multiplexorSignal != currentSignal && dbcMessage->multiplexorSignal != NULL) return; //I spoke too soon above...
|
||||
//if (dbcMessage->multiplexorSignal != currentSignal && dbcMessage->multiplexorSignal != nullptr) return; //I spoke too soon above...
|
||||
currentSignal->isMultiplexed = false;
|
||||
currentSignal->isMultiplexor = true;
|
||||
//we just set that this is the multiplexor so update the message to show that as well.
|
||||
@@ -204,7 +201,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
|
||||
{
|
||||
currentSignal->isMultiplexed = false;
|
||||
currentSignal->isMultiplexor = false;
|
||||
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = NULL;
|
||||
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -286,7 +283,7 @@ void DBCSignalEditor::showEvent(QShowEvent* event)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
|
||||
currentSignal = NULL;
|
||||
currentSignal = nullptr;
|
||||
refreshSignalsList();
|
||||
}
|
||||
|
||||
@@ -422,7 +419,7 @@ void DBCSignalEditor::deleteCurrentSignal()
|
||||
{
|
||||
delete(ui->signalsList->item(currIdx));
|
||||
dbcMessage->sigHandler->removeSignal(currIdx);
|
||||
currentSignal = NULL;
|
||||
currentSignal = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +458,7 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig)
|
||||
{
|
||||
unsigned char bitpattern[8];
|
||||
|
||||
if (sig == NULL) {
|
||||
if (sig == nullptr) {
|
||||
ui->groupBox->setEnabled(false);
|
||||
ui->txtName->setText("");
|
||||
ui->txtBias->setText("");
|
||||
@@ -578,7 +575,7 @@ void DBCSignalEditor::fillValueTable(DBC_SIGNAL *sig)
|
||||
ui->valuesTable->clearContents();
|
||||
ui->valuesTable->setRowCount(0);
|
||||
|
||||
if (sig == NULL) {
|
||||
if (sig == nullptr) {
|
||||
ui->valuesTable->setEnabled(false);
|
||||
inhibitCellChanged = false;
|
||||
return;
|
||||
@@ -588,7 +585,7 @@ void DBCSignalEditor::fillValueTable(DBC_SIGNAL *sig)
|
||||
|
||||
for (int i = 0; i < sig->valList.count(); i++)
|
||||
{
|
||||
QTableWidgetItem *val = new QTableWidgetItem(Utility::formatNumber(sig->valList[i].value));
|
||||
QTableWidgetItem *val = new QTableWidgetItem(Utility::formatNumber((uint64_t)sig->valList[i].value));
|
||||
QTableWidgetItem *desc = new QTableWidgetItem(sig->valList[i].descript);
|
||||
rowIdx = ui->valuesTable->rowCount();
|
||||
ui->valuesTable->insertRow(rowIdx);
|
||||
@@ -606,7 +603,7 @@ void DBCSignalEditor::clickSignalList(int row)
|
||||
{
|
||||
//qDebug() << ui->signalsList->item(row)->text();
|
||||
|
||||
DBC_SIGNAL *thisSig = (row<0) ? NULL : dbcMessage->sigHandler->findSignalByName(ui->signalsList->item(row)->text());
|
||||
DBC_SIGNAL *thisSig = (row<0) ? nullptr : dbcMessage->sigHandler->findSignalByName(ui->signalsList->item(row)->text());
|
||||
currentSignal = thisSig;
|
||||
fillSignalForm(thisSig);
|
||||
fillValueTable(thisSig);
|
||||
@@ -615,7 +612,7 @@ void DBCSignalEditor::clickSignalList(int row)
|
||||
void DBCSignalEditor::bitfieldClicked(int x, int y)
|
||||
{
|
||||
int bit = (7 - x) + (y * 8);
|
||||
if (currentSignal == NULL) return;
|
||||
if (currentSignal == nullptr) return;
|
||||
currentSignal->startBit = bit;
|
||||
if (currentSignal->valType == SP_FLOAT)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user