diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index 8a6e5da..3388047 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -291,6 +291,10 @@ QString SocketCANd::decodeFrames(QString data, int busNum) if(frameParsed.length() < 4) { qDebug() << "Received frame doesn't contain any data: " << data; + + //todo + //this is not totally true, ive seen frames come through that look like < frame 1F020240 1664924225.371291 > + //if we found the closing token but theres no data then remove the message from the buffer return data; } diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index 2415bd5..53982e3 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -358,9 +358,11 @@ void DBCMainEditor::onRebaseMessages() node = dbcFile->findNodeByName(idString); nodeRebaseEditor->setFileIdx(fileIdx); nodeRebaseEditor->setNodeRef(node); - nodeRebaseEditor->refreshView(); - nodeRebaseEditor->setModal(true); - nodeRebaseEditor->show(); + if(nodeRebaseEditor->refreshView()) + { + nodeRebaseEditor->setModal(true); + nodeRebaseEditor->show(); + } } void DBCMainEditor::onDuplicateNode() @@ -376,10 +378,12 @@ void DBCMainEditor::onDuplicateNode() idString = firstCol->text(0).split(" ")[0]; node = dbcFile->findNodeByName(idString); nodeDuplicateEditor->setFileIdx(fileIdx); - nodeDuplicateEditor->setNodeRef(node); - nodeDuplicateEditor->refreshView(); - nodeDuplicateEditor->setModal(true); - nodeDuplicateEditor->show(); + nodeDuplicateEditor->setNodeRef(node); + if(nodeDuplicateEditor->refreshView()) + { + nodeDuplicateEditor->setModal(true); + nodeDuplicateEditor->show(); + } } /* diff --git a/dbc/dbcnodeduplicateeditor.cpp b/dbc/dbcnodeduplicateeditor.cpp index c2a3164..0c5b546 100644 --- a/dbc/dbcnodeduplicateeditor.cpp +++ b/dbc/dbcnodeduplicateeditor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "helpwindow.h" #include "utility.h" @@ -18,58 +19,87 @@ DBCNodeDuplicateEditor::DBCNodeDuplicateEditor(QWidget *parent) : dbcHandler = DBCHandler::getReference(); dbcNode = nullptr; - connect(ui->btnDuplicate, &QPushButton::pressed, - [=]() + connect(ui->btnDuplicate, &QPushButton::pressed, + [=]() + { + if (dbcNode == nullptr) return; + if (lowestMsgId > 0x1FFFFFFFul) return; + + uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text()); + + if(newBase <= 0 || newBase > 0x1FFFFFFFul) { - if (dbcNode == nullptr) return; - if (lowestMsgId > 0x1FFFFFFFul) return; + QMessageBox::question(this, "Invalid Address", "The new address is outside of the valid range.", + QMessageBox::Ok); + return; + } - uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text()); + if(newBase == lowestMsgId) + { + QMessageBox::question(this, "Invalid Address", "The new address is the same as the original.", + QMessageBox::Ok); + return; + } - if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId) + uint rebaseDiff = newBase - lowestMsgId; + + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + QMessageBox::question(this, "No Messages", "The node has no messages to duplicate.", + QMessageBox::Ok); + return; + } + + if(ui->lineNodeName->text().isEmpty()) + { + QMessageBox::question(this, "No Name", "The new node needs a name before it can be created.", + QMessageBox::Ok); + return; + } + + QString newNodeName = ui->lineNodeName->text(); + emit createNode(newNodeName); + + DBC_NODE *nodePtr = dbcFile->findNodeByName(newNodeName); + + if(nodePtr == nullptr) + { + QMessageBox::question(this, "Node Invalid", "There was an problem identifying the selected node.", + QMessageBox::Ok); + return; + } + + for (int i=0; iID + rebaseDiff; + + if(newMsgId < 0 || newMsgId > 0x1FFFFFFFul) { - uint rebaseDiff = newBase - lowestMsgId; - - QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); - if(messagesForNode.count() == 0) - { - return; - } - - if(ui->lineNodeName->text().isEmpty()) - { - //tell! - return; - } - - QString newNodeName = ui->lineNodeName->text(); - emit createNode(newNodeName); - - DBC_NODE *nodePtr = dbcFile->findNodeByName(newNodeName); - - if(nodePtr == nullptr) - { - //uhoh - return; - } - - for (int i=0; iID + rebaseDiff; - emit cloneMessageToNode(nodePtr, messagesForNode[i], newMsgId); - } - - dbcFile->setDirtyFlag(); - emit nodeAdded(); + QMessageBox::question(this, "Invalid Address Range", "The new starting address would cause a message to be outside of the valid address range.", + QMessageBox::Ok); + return; } - }); + } - connect(ui->btnCancel, &QPushButton::pressed, - [=]() + for (int i=0; iID + rebaseDiff; + emit cloneMessageToNode(nodePtr, messagesForNode[i], newMsgId); + } + dbcFile->setDirtyFlag(); + emit nodeAdded(); - }); + this->close(); + + }); + + connect(ui->btnCancel, &QPushButton::pressed, + [=]() + { + this->close(); + }); installEventFilter(this); } @@ -144,19 +174,20 @@ void DBCNodeDuplicateEditor::showEvent(QShowEvent* event) refreshView(); } -void DBCNodeDuplicateEditor::refreshView() +bool DBCNodeDuplicateEditor::refreshView() { + ui->lineNewBaseId->setText(""); + if(dbcNode) { QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + lowestMsgId = 0xFFFFFFFF; + if(messagesForNode.count() == 0) { - //?? - + return false; } - lowestMsgId = 0xFFFFFFFF; - for (int i=0; iID < lowestMsgId) @@ -165,7 +196,9 @@ void DBCNodeDuplicateEditor::refreshView() ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); ui->lineNodeName->setText(dbcNode->name + QString("_Copy")); + + return true; } - //generateSampleText(); + return false; } diff --git a/dbc/dbcnodeduplicateeditor.h b/dbc/dbcnodeduplicateeditor.h index 9a29a93..57610bd 100644 --- a/dbc/dbcnodeduplicateeditor.h +++ b/dbc/dbcnodeduplicateeditor.h @@ -19,7 +19,7 @@ public: void showEvent(QShowEvent*); void setNodeRef(DBC_NODE *node); void setFileIdx(int idx); - void refreshView(); + bool refreshView(); signals: void updatedTreeInfo(DBC_MESSAGE *msg); diff --git a/dbc/dbcnoderebaseeditor.cpp b/dbc/dbcnoderebaseeditor.cpp index 5a8f6bb..8ce105d 100644 --- a/dbc/dbcnoderebaseeditor.cpp +++ b/dbc/dbcnoderebaseeditor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "helpwindow.h" #include "utility.h" @@ -18,60 +19,78 @@ DBCNodeRebaseEditor::DBCNodeRebaseEditor(QWidget *parent) : dbcHandler = DBCHandler::getReference(); dbcNode = nullptr; - connect(ui->btnDoRebase, &QPushButton::pressed, - [=]() + connect(ui->btnDoRebase, &QPushButton::pressed, + [=]() + { + if (dbcNode == nullptr) { - if (dbcNode == nullptr) return; - if (lowestMsgId > 0x1FFFFFFFul) return; + QMessageBox::question(this, "Node Invalid", "There was an problem identifying the selected node.", + QMessageBox::Ok); + return; + } - uint newBase = Utility::ParseStringToNum(ui->lineEdit->text()); + if (lowestMsgId > 0x1FFFFFFFul) + { + QMessageBox::question(this, "No Valid Messages", "The node has no valid messages to change.", + QMessageBox::Ok); + return; + } - if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId) + uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text()); + + if(newBase <= 0 || newBase > 0x1FFFFFFFul) + { + QMessageBox::question(this, "Invalid Address", "The new address is outside of the valid range.", + QMessageBox::Ok); + return; + } + + if(newBase == lowestMsgId) + { + QMessageBox::question(this, "Invalid Address", "The new address is the same as the original.", + QMessageBox::Ok); + return; + } + + uint rebaseDiff = newBase - lowestMsgId; + + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + QMessageBox::question(this, "No Messages", "The node has no messages to change.", + QMessageBox::Ok); + return; + } + + for (int i=0; iID + rebaseDiff; + + if(newMsgId < 0 || newMsgId > 0x1FFFFFFFul) { - uint rebaseDiff = newBase - lowestMsgId; - - QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); - if(messagesForNode.count() == 0) - { - return; - } - - for (int i=0; iID += rebaseDiff; - emit updatedTreeInfo(messagesForNode[i]); - } - - dbcFile->setDirtyFlag(); + QMessageBox::question(this, "Invalid Address Range", "The new starting address would cause a message to be outside of the valid address range.", + QMessageBox::Ok); + return; } + } - - }); - - connect(ui->btnCancel, &QPushButton::pressed, - [=]() + for (int i=0; iID += rebaseDiff; + emit updatedTreeInfo(messagesForNode[i]); + } + dbcFile->setDirtyFlag(); - }); + this->close(); -// connect(ui->lineOriginalBaseId, &QLineEdit::editingFinished, -// [=]() -// { -// if (dbcNode == nullptr) return; -// if (dbcNode->comment != ui->lineComment->text()) dbcFile->setDirtyFlag(); -// dbcNode->comment = ui->lineComment->text(); -// emit updatedTreeInfo(dbcNode); -// }); + }); -// connect(ui->lineMsgName, &QLineEdit::editingFinished, -// [=]() -// { -// if (dbcNode == nullptr) return; -// if (dbcNode->name != ui->lineMsgName->text()) dbcFile->setDirtyFlag(); -// dbcNode->name = ui->lineMsgName->text(); -// emit updatedTreeInfo(dbcNode); -// }); + connect(ui->btnCancel, &QPushButton::pressed, + [=]() + { + this->close(); + }); installEventFilter(this); } @@ -146,19 +165,20 @@ void DBCNodeRebaseEditor::showEvent(QShowEvent* event) refreshView(); } -void DBCNodeRebaseEditor::refreshView() +bool DBCNodeRebaseEditor::refreshView() { + ui->lineNewBaseId->setText(""); + if(dbcNode) { QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + lowestMsgId = 0xFFFFFFFF; + if(messagesForNode.count() == 0) { - //?? - + return false; } - lowestMsgId = 0xFFFFFFFF; - for (int i=0; iID < lowestMsgId) @@ -167,7 +187,9 @@ void DBCNodeRebaseEditor::refreshView() ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); ui->lineNodeName->setText(dbcNode->name); + + return true; } - //generateSampleText(); + return false; } diff --git a/dbc/dbcnoderebaseeditor.h b/dbc/dbcnoderebaseeditor.h index 8e787f0..26f1645 100644 --- a/dbc/dbcnoderebaseeditor.h +++ b/dbc/dbcnoderebaseeditor.h @@ -19,7 +19,7 @@ public: void showEvent(QShowEvent*); void setNodeRef(DBC_NODE *node); void setFileIdx(int idx); - void refreshView(); + bool refreshView(); signals: void updatedTreeInfo(DBC_MESSAGE *msg); diff --git a/ui/dbcnodeduplicateeditor.ui b/ui/dbcnodeduplicateeditor.ui index a07c435..b236251 100644 --- a/ui/dbcnodeduplicateeditor.ui +++ b/ui/dbcnodeduplicateeditor.ui @@ -7,11 +7,17 @@ 0 0 314 - 193 + 144 + + + 0 + 0 + + - Dialog + Duplicate Node @@ -41,7 +47,14 @@ - + + + true + + + true + + diff --git a/ui/dbcnoderebaseeditor.ui b/ui/dbcnoderebaseeditor.ui index ddcfbe1..3c043cc 100644 --- a/ui/dbcnoderebaseeditor.ui +++ b/ui/dbcnoderebaseeditor.ui @@ -7,11 +7,17 @@ 0 0 303 - 159 + 148 + + + 0 + 0 + + - Dialog + Rebase All Node Messages @@ -31,7 +37,14 @@ - + + + true + + + true + + @@ -41,7 +54,14 @@ - + + + true + + + true + + @@ -51,7 +71,7 @@ - +