From d550fa79a0f1f15562737465fcf40704c2d7f2c8 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Thu, 13 Feb 2020 22:01:06 -0500 Subject: [PATCH] Changed a lot of pointer references to const (it's more correct and fixes a weird problem), fixed a problem with JSON to DBC, a few other fixes --- bus_protocols/isotp_handler.cpp | 15 ++++----- bus_protocols/uds_handler.cpp | 6 ++-- canframemodel.cpp | 3 +- connections/canconnection.h | 7 ++++ connections/serialbusconnection.cpp | 6 ++-- dbc/dbchandler.cpp | 2 +- firmwareuploaderwindow.cpp | 2 +- framefileio.cpp | 50 ++++++++++++++--------------- framesenderwindow.cpp | 2 +- mainwindow.cpp | 4 +-- re/filecomparatorwindow.cpp | 6 ++-- re/flowviewwindow.cpp | 8 ++--- re/frameinfowindow.cpp | 6 ++-- re/isotp_interpreterwindow.cpp | 4 +-- re/sniffer/snifferitem.cpp | 4 +-- re/udsscanwindow.cpp | 5 ++- scriptcontainer.cpp | 5 ++- utility.h | 3 ++ 18 files changed, 76 insertions(+), 62 deletions(-) diff --git a/bus_protocols/isotp_handler.cpp b/bus_protocols/isotp_handler.cpp index d56477c..4293699 100644 --- a/bus_protocols/isotp_handler.cpp +++ b/bus_protocols/isotp_handler.cpp @@ -59,12 +59,13 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data) lastSenderID = ID; lastSenderBus = bus; + frame.bus = bus; + frame.setFrameId(ID); + if (ID > 0x7FF) frame.setExtendedFrameFormat(true); + else frame.setExtendedFrameFormat(false); + if (data.length() < 8) { - frame.bus = bus; - frame.setFrameId(ID); - if (ID > 0x7FF) frame.setExtendedFrameFormat(true); - else frame.setExtendedFrameFormat(false); QByteArray bytes(8,0); bytes.resize(8); bytes[0] = data.length(); @@ -74,10 +75,6 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data) } else //need to send a multi-part ISO_TP message - Respects timing and frame number based flow control { - frame.bus = bus; - frame.setFrameId(ID); - if (ID > 0x7FF) frame.setExtendedFrameFormat(true); - else frame.setExtendedFrameFormat(false); QByteArray bytes(8, 0); bytes[0] = 0x10 + (data.length() / 256); bytes[1] = data.length() & 0xFF; @@ -159,7 +156,7 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame) //int offset; ISOTP_MESSAGE msg; ISOTP_MESSAGE *pMsg; - unsigned char *data = reinterpret_cast(frame.payload().data()); + const unsigned char *data = reinterpret_cast(frame.payload().constData()); //int dataLen = frame.payload().count(); frameType = 0; diff --git a/bus_protocols/uds_handler.cpp b/bus_protocols/uds_handler.cpp index e0fb085..29bbb47 100644 --- a/bus_protocols/uds_handler.cpp +++ b/bus_protocols/uds_handler.cpp @@ -177,7 +177,7 @@ UDS_HANDLER::~UDS_HANDLER() void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg) { qDebug() << "UDS handler got ISOTP frame"; - unsigned char *data = reinterpret_cast(msg.payload().data()); + const unsigned char *data = reinterpret_cast(msg.payload().constData()); int dataLen = msg.payload().count(); UDS_MESSAGE udsMsg; udsMsg.bus = msg.bus; @@ -258,6 +258,8 @@ void UDS_HANDLER::sendUDSFrame(const UDS_MESSAGE &msg) data.append(msg.payload()); isoHandler->sendISOTPFrame(msg.bus, msg.frameId(), data); + //qDebug() << "Data sending: " << data; + qDebug() << "Sent UDS service: " << getServiceShortDesc(msg.service) << " on bus " << msg.bus; } @@ -327,7 +329,7 @@ QString UDS_HANDLER::getDetailedMessageAnalysis(const UDS_MESSAGE &msg) bool isResponse = true; int dataSize; int addrSize; - unsigned char *data = reinterpret_cast(msg.payload().data()); + const unsigned char *data = reinterpret_cast(msg.payload().constData()); int dataLen = msg.payload().length(); if (msg.isErrorReply) diff --git a/canframemodel.cpp b/canframemodel.cpp index 167f822..486a1da 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -360,7 +360,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const thisFrame = filteredFrames.at(index.row()); - unsigned char *data = reinterpret_cast(thisFrame.payload().data()); + const unsigned char *data = reinterpret_cast(thisFrame.payload().constData()); int dataLen = thisFrame.payload().count(); if (role == Qt::BackgroundColorRole) @@ -551,6 +551,7 @@ void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false) mutex.lock(); CANFrame tempFrame; tempFrame = frame; + tempFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, tempFrame.timeStamp().microSeconds() - timeOffset)); lastUpdateNumFrames++; diff --git a/connections/canconnection.h b/connections/canconnection.h index a450134..38d1160 100644 --- a/connections/canconnection.h +++ b/connections/canconnection.h @@ -77,6 +77,12 @@ public: */ CANCon::status getStatus(); + /** + * @brief setConsoleOutput + * @param state - set whether to send debugging info to the console or not + */ + void setConsoleOutput(bool state); + signals: /*not implemented yet */ @@ -194,6 +200,7 @@ public slots: protected: int mNumBuses; //protected to allow connected device to figure out how many buses are available QVector mBusData; + bool mConsoleOutput; //send debugging info to the console? //determine if the passed frame is part of a filter or not. void checkTargettedFrame(CANFrame &frame); diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index 72e1e90..bda07f8 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -119,6 +119,8 @@ bool SerialBusConnection::piSendFrame(const CANFrame& pFrame) return false; if (!mDev_p) return false; + qDebug() << "Data bytes at lowlevel: " << pFrame.payload().toBase64(); + return mDev_p->writeFrame(pFrame); } @@ -179,7 +181,7 @@ void SerialBusConnection::framesReceived() continue; /* check frame */ - if (recFrame.payload().length() <= 8) { + //if (recFrame.payload().length() <= 8) { CANFrame* frame_p = getQueue().get(); if(frame_p) { frame_p->setPayload(recFrame.payload()); @@ -241,7 +243,7 @@ void SerialBusConnection::framesReceived() /* enqueue frame */ getQueue().queue(); - } + //} #if 0 else qDebug() << "can't get a frame, ERROR"; diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index b2bc9ef..0393e36 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -1556,7 +1556,7 @@ DBCFile* DBCHandler::loadJSONFile(int idx) { qDebug() << iter.key(); DBC_MESSAGE msg; - msg.ID = static_cast(iter->toObject().find("origin_id").value().toInt()); + msg.ID = static_cast(iter->toObject().find("message_id").value().toInt()); msg.name = QString(iter.key().toUtf8()); msg.len = static_cast(iter->toObject().find("length_bytes").value().toInt()); msg.sender = thisFile->findNodeByIdx(0); diff --git a/firmwareuploaderwindow.cpp b/firmwareuploaderwindow.cpp index 6480e25..44571d3 100644 --- a/firmwareuploaderwindow.cpp +++ b/firmwareuploaderwindow.cpp @@ -77,7 +77,7 @@ void FirmwareUploaderWindow::updatedFrames(int numFrames) void FirmwareUploaderWindow::gotTargettedFrame(CANFrame frame) { - unsigned char *data = reinterpret_cast(frame.payload().data()); + const unsigned char *data = reinterpret_cast(frame.payload().constData()); int dataLen = frame.payload().count(); qDebug() << "FUW: Got targetted frame with id " << frame.frameId(); diff --git a/framefileio.cpp b/framefileio.cpp index 741d8b1..c5a8439 100644 --- a/framefileio.cpp +++ b/framefileio.cpp @@ -947,7 +947,7 @@ bool FrameFileIO::saveCRTDFile(QString filename, const QVector* frames QFile *outFile = new QFile(filename); int lineCounter = 0; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -971,7 +971,7 @@ bool FrameFileIO::saveCRTDFile(QString filename, const QVector* frames } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); outFile->write(QString::number(frame->timeStamp().microSeconds() / 1000000.0, 'f', 6).toUtf8()); @@ -1346,7 +1346,7 @@ bool FrameFileIO::saveCanalyzerASC(QString filename, const QVector* fr int lineCounter = 0; int64_t offsetTime = frames->at(0).timeStamp().microSeconds(); - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -1383,7 +1383,7 @@ bool FrameFileIO::saveCanalyzerASC(QString filename, const QVector* fr } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); uint64_t timeStamp = (frame->timeStamp().microSeconds() - offsetTime) / 1000000ull; @@ -1614,7 +1614,7 @@ bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector* f QFile *outFile = new QFile(filename); int lineCounter = 0; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -1637,7 +1637,7 @@ bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector* f } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); outFile->write(QString::number(frame->timeStamp().microSeconds()).toUtf8()); @@ -1720,7 +1720,7 @@ bool FrameFileIO::closeContinuousNative() bool FrameFileIO::writeContinuousNative(const QVector* frames, int beginningFrame) { - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -1729,7 +1729,7 @@ bool FrameFileIO::writeContinuousNative(const QVector* frames, int beg for (int c = beginningFrame; c < frames->count(); c++) { frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); continuousFile.write(QString::number(frame->timeStamp().microSeconds()).toUtf8()); @@ -1880,7 +1880,7 @@ bool FrameFileIO::saveGenericCSVFile(QString filename, const QVector* QFile *outFile = new QFile(filename); int lineCounter = 0; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -1903,7 +1903,7 @@ bool FrameFileIO::saveGenericCSVFile(QString filename, const QVector* } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); outFile->write(QString::number(frame->frameId(), 16).toUpper().rightJustified(8, '0').toUtf8()); @@ -2086,7 +2086,7 @@ bool FrameFileIO::saveLogFile(QString filename, const QVector* frames) QDateTime timestamp, tempStamp; int lineCounter = 0; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -2124,7 +2124,7 @@ bool FrameFileIO::saveLogFile(QString filename, const QVector* frames) } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); tempStamp = QDateTime::fromMSecsSinceEpoch(frame->timeStamp().microSeconds() / 1000); @@ -2282,7 +2282,7 @@ bool FrameFileIO::saveIXXATFile(QString filename, const QVector* frame QDateTime timestamp, tempStamp; int lineCounter = 0; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -2313,7 +2313,7 @@ bool FrameFileIO::saveIXXATFile(QString filename, const QVector* frame } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); tempStamp = QDateTime::fromMSecsSinceEpoch(frame->timeStamp().microSeconds() / 1000); @@ -2418,7 +2418,7 @@ bool FrameFileIO::loadCANDOFile(QString filename, QVector* frames) } data = inFile->read(12); - unsigned char *uData = reinterpret_cast(data.data()); + const unsigned char *uData = reinterpret_cast(data.constData()); thisFrame.bus = 0; thisFrame.isReceived = true; @@ -2460,7 +2460,7 @@ bool FrameFileIO::saveCANDOFile(QString filename, const QVector* frame int id; qint64 ms; - unsigned char *inData; + const unsigned char *inData; int inDataLen; const CANFrame *frame; @@ -2492,7 +2492,7 @@ bool FrameFileIO::saveCANDOFile(QString filename, const QVector* frame } frame = &frames->at(c); - inData = reinterpret_cast(frame->payload().data()); + inData = reinterpret_cast(frame->payload().constData()); inDataLen = frame->payload().count(); for (int j = 0; j < 8; j++) data[4 + j] = (char)0xFF; @@ -2660,7 +2660,7 @@ bool FrameFileIO::saveMicrochipFile(QString filename, const QVector* f QDateTime timestamp, tempStamp; int lineCounter = 0; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -2691,7 +2691,7 @@ bool FrameFileIO::saveMicrochipFile(QString filename, const QVector* f } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); outFile->write(QString::number((frame->timeStamp().microSeconds() / 1000)).toUtf8()); @@ -2875,7 +2875,7 @@ bool FrameFileIO::saveTraceFile(QString filename, const QVector * fram int64_t tempTime; int tempTimePiece; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -2918,7 +2918,7 @@ bool FrameFileIO::saveTraceFile(QString filename, const QVector * fram } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); //1F D3 3F FF 08 FF E0 CB @@ -2970,7 +2970,7 @@ bool FrameFileIO::saveCanDumpFile(QString filename, const QVector * fr int lineCounter = 0; double tempTime; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -2991,7 +2991,7 @@ bool FrameFileIO::saveCanDumpFile(QString filename, const QVector * fr } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); outFile->write("("); @@ -3599,7 +3599,7 @@ bool FrameFileIO::saveCabanaFile(QString filename, const QVector* fram QFile *outFile = new QFile(filename); int lineCounter = 0; - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -3622,7 +3622,7 @@ bool FrameFileIO::saveCabanaFile(QString filename, const QVector* fram } frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); double tempTimeStamp = frame->timeStamp().microSeconds(); diff --git a/framesenderwindow.cpp b/framesenderwindow.cpp index d107428..2d17b36 100644 --- a/framesenderwindow.cpp +++ b/framesenderwindow.cpp @@ -792,7 +792,7 @@ void FrameSenderWindow::updateGridRow(int idx) int gridLine = idx; QString dataString; QTableWidgetItem *item = ui->tableSender->item(gridLine, 9); - unsigned char *data = reinterpret_cast(temp->payload().data()); + const unsigned char *data = reinterpret_cast(temp->payload().constData()); int dataLen = temp->payload().length(); if (item == nullptr) item = new QTableWidgetItem(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 678e603..99bab53 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -729,7 +729,7 @@ void MainWindow::saveDecodedTextFile(QString filename) QFile *outFile = new QFile(filename); const QVector *frames = model->getFilteredListReference(); - unsigned char *data; + const unsigned char *data; int dataLen; const CANFrame *frame; @@ -743,7 +743,7 @@ Data Bytes: 88 10 00 13 BB 00 06 00 for (int c = 0; c < frames->count(); c++) { frame = &frames->at(c); - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().count(); QString builderString; diff --git a/re/filecomparatorwindow.cpp b/re/filecomparatorwindow.cpp index c85cc8c..8525470 100644 --- a/re/filecomparatorwindow.cpp +++ b/re/filecomparatorwindow.cpp @@ -123,7 +123,7 @@ void FileComparatorWindow::calculateDetails() QTreeWidgetItem *interestedOnlyBase, *referenceOnlyBase = nullptr, *sharedBase, *bitmapBaseInterested, *bitmapBaseReference = nullptr; QTreeWidgetItem *valuesBase, *detail, *sharedItem, *valuesInterested, *valuesReference = nullptr; uint64_t tmp; - unsigned char *data; + const unsigned char *data; int dataLen; bool uniqueInterested = ui->ckUniqueToInterested->isChecked(); @@ -154,7 +154,7 @@ void FileComparatorWindow::calculateDetails() for (int x = 0; x < interestedFrames.count(); x++) { CANFrame frame = interestedFrames.at(x); - data = reinterpret_cast(frame.payload().data()); + data = reinterpret_cast(frame.payload().constData()); dataLen = frame.payload().count(); if (interestedIDs.contains(frame.frameId())) //if we saw this ID before then add to the QList in there @@ -201,7 +201,7 @@ void FileComparatorWindow::calculateDetails() for (int x = 0; x < referenceFrames.count(); x++) { CANFrame frame = referenceFrames.at(x); - data = reinterpret_cast(frame.payload().data()); + data = reinterpret_cast(frame.payload().constData()); dataLen = frame.payload().count(); if (referenceIDs.contains(frame.frameId())) //if we saw this ID before then add to the QList in there diff --git a/re/flowviewwindow.cpp b/re/flowviewwindow.cpp index c247290..3cab711 100644 --- a/re/flowviewwindow.cpp +++ b/re/flowviewwindow.cpp @@ -397,7 +397,7 @@ void FlowViewWindow::updatedFrames(int numFrames) { QVectornewX[8]; QVectornewY[8]; - unsigned char *data; + const unsigned char *data; int dataLen = 0; const CANFrame *thisFrame; @@ -436,7 +436,7 @@ void FlowViewWindow::updatedFrames(int numFrames) for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = &modelFrames->at(i); - data = reinterpret_cast(thisFrame->payload().data()); + data = reinterpret_cast(thisFrame->payload().constData()); dataLen = thisFrame->payload().length(); if (!foundID.contains(thisFrame->frameId())) @@ -502,7 +502,7 @@ void FlowViewWindow::createGraph(int byteNum) { int tempVal; float minval=1000000, maxval = -100000; - unsigned char *data; + const unsigned char *data; int dataLen = 0; const CANFrame *frame; @@ -520,7 +520,7 @@ void FlowViewWindow::createGraph(int byteNum) for (int j = 0; j < numEntries; j++) { frame = &frameCache[j]; - data = reinterpret_cast(frame->payload().data()); + data = reinterpret_cast(frame->payload().constData()); dataLen = frame->payload().length(); tempVal = data[byteNum]; diff --git a/re/frameinfowindow.cpp b/re/frameinfowindow.cpp index db954b4..fa5e8a9 100644 --- a/re/frameinfowindow.cpp +++ b/re/frameinfowindow.cpp @@ -278,7 +278,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) if (thisFrame.frameId() == static_cast(targettedID)) frameCache.append(thisFrame); } - unsigned char *data = reinterpret_cast(frameCache.at(0).payload().data()); + const unsigned char *data = reinterpret_cast(frameCache.at(0).payload().constData()); int dataLen = frameCache.at(0).payload().length(); ui->treeDetails->clear(); @@ -367,7 +367,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) } for (int j = 0; j < 64; j++) bitfieldHistogram[j] = 0; - data = reinterpret_cast(frameCache.at(0).payload().data()); + data = reinterpret_cast(frameCache.at(0).payload().constData()); dataLen = frameCache.at(0).payload().length(); for (int c = 0; c < dataLen; c++) @@ -383,7 +383,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) //then find all data points for (int j = 0; j < frameCache.count(); j++) { - data = reinterpret_cast(frameCache.at(j).payload().data()); + data = reinterpret_cast(frameCache.at(j).payload().constData()); dataLen = frameCache.at(j).payload().length(); byteGraphX.append(j); diff --git a/re/isotp_interpreterwindow.cpp b/re/isotp_interpreterwindow.cpp index d73e5d6..f18eafd 100644 --- a/re/isotp_interpreterwindow.cpp +++ b/re/isotp_interpreterwindow.cpp @@ -208,7 +208,7 @@ void ISOTP_InterpreterWindow::showDetailView() msg = &messages[rowNum]; - unsigned char *data = reinterpret_cast(msg->payload().data()); + const unsigned char *data = reinterpret_cast(msg->payload().constData()); int dataLen = msg->payload().length(); if (msg->reportedLength != dataLen) @@ -266,7 +266,7 @@ void ISOTP_InterpreterWindow::newISOMessage(ISOTP_MESSAGE msg) int rowNum; QString tempString; - unsigned char *data = reinterpret_cast(msg.payload().data()); + const unsigned char *data = reinterpret_cast(msg.payload().constData()); int dataLen = msg.payload().length(); if ((msg.reportedLength != dataLen) && !ui->cbShowIncomplete->isChecked()) return; diff --git a/re/sniffer/snifferitem.cpp b/re/sniffer/snifferitem.cpp index 54bb1b6..1194ee9 100644 --- a/re/sniffer/snifferitem.cpp +++ b/re/sniffer/snifferitem.cpp @@ -6,7 +6,7 @@ SnifferItem::SnifferItem(const CANFrame& pFrame, quint32 seq): mID(pFrame.frameId()) { - unsigned char *data = reinterpret_cast(pFrame.payload().data()); + const unsigned char *data = reinterpret_cast(pFrame.payload().constData()); int dataLen = pFrame.payload().length(); for (int i = 0; i < 0; i++) { @@ -117,7 +117,7 @@ void SnifferItem::update(const CANFrame& pFrame, quint32 timeSeq, bool mute) mLastTime = mCurrentTime; mCurrSeqVal = timeSeq; - unsigned char *data = reinterpret_cast(pFrame.payload().data()); + const unsigned char *data = reinterpret_cast(pFrame.payload().constData()); int dataLen = pFrame.payload().length(); /* copy new value */ diff --git a/re/udsscanwindow.cpp b/re/udsscanwindow.cpp index ecb4623..cf060d8 100644 --- a/re/udsscanwindow.cpp +++ b/re/udsscanwindow.cpp @@ -354,7 +354,7 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE msg) int offset = ui->spinReplyOffset->value(); UDS_MESSAGE sentFrame; bool gotReply = false; - unsigned char *data = reinterpret_cast(msg.payload().data()); + const unsigned char *data = reinterpret_cast(msg.payload().constData()); int dataLen = msg.payload().length(); int numSending = sendingFrames.length(); @@ -488,6 +488,9 @@ void UDSScanWindow::sendNextMsg() else { waitTimer->stop(); + udsHandler->setReception(false); + udsHandler->setProcessAllIDs(false); + udsHandler->setFlowCtrl(false); ui->btnScan->setText("Start Scan"); currentlyRunning = false; } diff --git a/scriptcontainer.cpp b/scriptcontainer.cpp index f3fa836..30969be 100644 --- a/scriptcontainer.cpp +++ b/scriptcontainer.cpp @@ -255,7 +255,7 @@ void CANScriptHelper::gotTargettedFrame(const CANFrame &frame) if (!gotFrameFunction.isCallable()) return; //nothing to do if we can't even call the function //qDebug() << "Got frame in script interface"; - unsigned char *data = reinterpret_cast(frame.payload().data()); + const unsigned char *data = reinterpret_cast(frame.payload().constData()); int dataLen = frame.payload().length(); for (int i = 0; i < filters.length(); i++) @@ -310,14 +310,13 @@ void ISOTPScriptHelper::sendISOTP(QJSValue bus, QJSValue id, QJSValue length, QJ msg.setFrameId(id.toUInt()); msg.payload().resize(length.toInt()); - unsigned char *data = reinterpret_cast(msg.payload().data()); int dataLen = msg.payload().length(); if (!dataBytes.isArray()) qDebug() << "data isn't an array"; for (int i = 0; i < dataLen; i++) { - data[i] = static_cast(dataBytes.property(i).toInt()); + msg.payload()[i] = static_cast(dataBytes.property(i).toInt()); } msg.bus = bus.toInt(); diff --git a/utility.h b/utility.h index 8160aa7..090b0a3 100644 --- a/utility.h +++ b/utility.h @@ -185,6 +185,9 @@ public: int64_t result = 0; int bit; + int maxBytes = (startBit + sigSize) / 8; + if (data.size() < maxBytes) return 0; + if (littleEndian) { bit = startBit;