diff --git a/bus_protocols/isotp_handler.cpp b/bus_protocols/isotp_handler.cpp index 3dbcfd8..5d8e559 100644 --- a/bus_protocols/isotp_handler.cpp +++ b/bus_protocols/isotp_handler.cpp @@ -18,6 +18,8 @@ ISOTP_HANDLER::ISOTP_HANDLER() { useExtendedAddressing = false; isReceiving = false; + + connect(&frameTimer, SIGNAL(timeout()), this, SLOT(frameTimerTick())); } void ISOTP_HANDLER::setExtendedAddressing(bool mode) @@ -61,7 +63,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector data) for (int i = 0; i < frame.data[0]; i++) frame.data[i + 1] = data[i]; CANConManager::getInstance()->sendFrame(frame); } - else //need to send a multi-part ISO_TP message - no flow control possible right now. TODO - Add flow control + else //need to send a multi-part ISO_TP message - Respects timing and frame number based flow control { frame.bus = bus; frame.ID = ID; @@ -72,6 +74,11 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector data) frame.data[1] = data.length() & 0xFF; for (int i = 0; i < 6; i++) frame.data[2 + i] = data[currByte++]; CANConManager::getInstance()->sendFrame(frame); + //Queue up the rest of the frames + waitingForFlow = true; + frameTimer.setInterval(200); //wait a while for the flow frame to come in + frameTimer.setTimerType(Qt::PreciseTimer); + frameTimer.start(); while (currByte < data.length()) { for (int b = 0; b < 8; b++) frame.data[b] = 0xAA; @@ -81,7 +88,8 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector data) if (bytesToGo > 7) bytesToGo = 7; for (int i = 0; i < bytesToGo; i++) frame.data[1 + i] = data[currByte++]; frame.len = 8; - CANConManager::getInstance()->sendFrame(frame); + sendingFrames.append(frame); + //CANConManager::getInstance()->sendFrame(frame); } } } @@ -100,7 +108,7 @@ void ISOTP_HANDLER::updatedFrames(int numFrames) { for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { - //processFrame(modelFrames->at(i)); + //processFrame(modelFrames->at(i)); //accepting these frames in rapidFrames instead } } } @@ -114,7 +122,9 @@ void ISOTP_HANDLER::rapidFrames(const CANConnection* conn, const QVectorsendFrame(frame); + if (framesUntilFlow > -1) framesUntilFlow--; + if (framesUntilFlow == 0) //stop sending and wait for another flow control message + { + frameTimer.stop(); //we absolutely will not send anything until other side says to. + waitingForFlow = true; + } + } + else //no more frames to send + { + frameTimer.stop(); + } + } + else //while waiting for a flow frame we didn't get one during timeout period. Try to send anyway with default timeout + { + waitingForFlow = false; + frameTimer.setInterval(20); //pretty slow sending which should be OK as a default + } +} + +void ISOTP_HANDLER::setProcessAll(bool state) +{ + processAll = state; +} + +void ISOTP_HANDLER::addID(uint32_t id) +{ + isoIDs[id] = true; +} + +void ISOTP_HANDLER::removeID(uint32_t id) +{ + isoIDs.remove(id); +} + +void ISOTP_HANDLER::clearAllIDs() +{ + isoIDs.clear(); +} + diff --git a/bus_protocols/isotp_handler.h b/bus_protocols/isotp_handler.h index 5d22c21..cce3628 100644 --- a/bus_protocols/isotp_handler.h +++ b/bus_protocols/isotp_handler.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "can_structs.h" #include "mainwindow.h" #include "canframemodel.h" @@ -19,19 +20,30 @@ public: static ISOTP_HANDLER* getInstance(); void setReception(bool mode); //set whether to accept and forward frames or not void sendISOTPFrame(int bus, int ID, QVector data); + void setProcessAll(bool state); + void addID(uint32_t id); + void removeID(uint32_t id); + void clearAllIDs(); public slots: void updatedFrames(int); void rapidFrames(const CANConnection* conn, const QVector& pFrames); + void frameTimerTick(); signals: - void newISOMessage(ISOTP_MESSAGE &msg); + void newISOMessage(ISOTP_MESSAGE msg); private: QList messageBuffer; + QList sendingFrames; + QMap isoIDs; const QVector *modelFrames; bool useExtendedAddressing; bool isReceiving; + bool waitingForFlow; + int framesUntilFlow; + bool processAll; + QTimer frameTimer; void processFrame(const CANFrame &frame); void checkNeedFlush(uint64_t ID); diff --git a/bus_protocols/uds_handler.cpp b/bus_protocols/uds_handler.cpp index 112eb06..9aa4070 100644 --- a/bus_protocols/uds_handler.cpp +++ b/bus_protocols/uds_handler.cpp @@ -150,7 +150,7 @@ UDS_HANDLER::UDS_HANDLER() useExtendedAddressing = false; } -void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE &msg) +void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg) { qDebug() << "UDS handler got ISOTP frame"; UDS_MESSAGE udsMsg; @@ -195,13 +195,13 @@ void UDS_HANDLER::setReception(bool mode) if (isReceiving) { - connect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE&)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE&))); + connect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE))); ISOTP_HANDLER::getInstance()->setReception(true); //must enable ISOTP reception too. qDebug() << "Enabling reception of ISO-TP frames in UDS handler"; } else { - disconnect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE&)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE&))); + disconnect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE))); //can't disable ISOTP reception because something else might be using it. qDebug() << "Disabling reception of ISOTP frames in UDS handler"; } @@ -264,3 +264,25 @@ QString UDS_HANDLER::getNegativeResponseLong(int respCode) return QString(); } +//Little shim functions that drop straight through to the ISO_TP handler +void UDS_HANDLER::setProcessAllIDs(bool state) +{ + ISOTP_HANDLER::getInstance()->setProcessAll(state); +} + +void UDS_HANDLER::addID(uint32_t id) +{ + ISOTP_HANDLER::getInstance()->addID(id); +} + +void UDS_HANDLER::removeID(uint32_t id) +{ + ISOTP_HANDLER::getInstance()->removeID(id); +} + +void UDS_HANDLER::clearAllIDs() +{ + ISOTP_HANDLER::getInstance()->clearAllIDs(); +} + + diff --git a/bus_protocols/uds_handler.h b/bus_protocols/uds_handler.h index 8e745a3..e2133bb 100644 --- a/bus_protocols/uds_handler.h +++ b/bus_protocols/uds_handler.h @@ -89,16 +89,20 @@ public: static UDS_HANDLER* getInstance(); void setReception(bool mode); //set whether to accept and forward frames or not void sendUDSFrame(const UDS_MESSAGE &msg); + void setProcessAllIDs(bool state); + void addID(uint32_t id); + void removeID(uint32_t id); + void clearAllIDs(); QString getServiceShortDesc(int service); QString getServiceLongDesc(int service); QString getNegativeResponseShort(int respCode); QString getNegativeResponseLong(int respCode); public slots: - void gotISOTPFrame(ISOTP_MESSAGE &msg); + void gotISOTPFrame(ISOTP_MESSAGE msg); signals: - void newUDSMessage(UDS_MESSAGE &msg); + void newUDSMessage(UDS_MESSAGE msg); private: QList messageBuffer; diff --git a/frameplaybackwindow.cpp b/frameplaybackwindow.cpp index 10e8dd4..45db837 100644 --- a/frameplaybackwindow.cpp +++ b/frameplaybackwindow.cpp @@ -36,6 +36,7 @@ FramePlaybackWindow::FramePlaybackWindow(const QVector *frames, QWidge modelFrames = frames; playbackTimer = new QTimer(); + playbackTimer->setTimerType(Qt::PreciseTimer); currentPosition = 0; playbackActive = false; @@ -499,7 +500,7 @@ void FramePlaybackWindow::btnSelectNoneClick() } void FramePlaybackWindow::timerTriggered() -{ +{ sendingBuffer.clear(); for (int count = 0; count < ui->spinBurstSpeed->value(); count++) { diff --git a/framesenderwindow.cpp b/framesenderwindow.cpp index e91d12b..1108e20 100644 --- a/framesenderwindow.cpp +++ b/framesenderwindow.cpp @@ -23,6 +23,7 @@ FrameSenderWindow::FrameSenderWindow(const QVector *frames, QWidget *p modelFrames = frames; intervalTimer = new QTimer(); + intervalTimer->setTimerType(Qt::PreciseTimer); intervalTimer->setInterval(1); QStringList headers; @@ -45,7 +46,7 @@ FrameSenderWindow::FrameSenderWindow(const QVector *frames, QWidget *p connect(ui->btnDisableAll, SIGNAL(clicked(bool)), this, SLOT(disableAll())); connect(ui->btnEnableAll, SIGNAL(clicked(bool)), this, SLOT(enableAll())); connect(ui->btnLoadGrid, SIGNAL(clicked(bool)), this, SLOT(loadGrid())); - connect(ui->btnSaveGrid, SIGNAL(clicked(bool)), this, SLOT(saveGrid())); + connect(ui->btnSaveGrid, SIGNAL(clicked(bool)), this, SLOT(saveGrid())); connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); intervalTimer->start(); @@ -56,7 +57,7 @@ FrameSenderWindow::~FrameSenderWindow() { delete ui; - intervalTimer->stop(); + intervalTimer->stop(); delete intervalTimer; } @@ -110,7 +111,7 @@ void FrameSenderWindow::updatedFrames(int numFrames) buildFrameCache(); } else //just got some new frames. See if they are relevant. - { + { if (numFrames > modelFrames->count()) return; qDebug() << "New frames in sender window"; //run through the supposedly new frames in order @@ -134,7 +135,7 @@ void FrameSenderWindow::processIncomingFrame(CANFrame *frame) { for (int sd = 0; sd < sendingData.count(); sd++) { - if (sendingData[sd].triggers.count() == 0) continue; + if (sendingData[sd].triggers.count() == 0) continue; for (int trig = 0; trig < sendingData[sd].triggers.count(); trig++) { Trigger *thisTrigger = &sendingData[sd].triggers[trig]; diff --git a/re/isotp_interpreterwindow.cpp b/re/isotp_interpreterwindow.cpp index 54ccd52..3a1bc45 100644 --- a/re/isotp_interpreterwindow.cpp +++ b/re/isotp_interpreterwindow.cpp @@ -11,6 +11,9 @@ ISOTP_InterpreterWindow::ISOTP_InterpreterWindow(const QVector *frames decoder = ISOTP_HANDLER::getInstance(); + decoder->setReception(true); + decoder->setProcessAll(true); + connect(MainWindow::getReference(), &MainWindow::framesUpdated, this, &ISOTP_InterpreterWindow::updatedFrames); connect(MainWindow::getReference(), &MainWindow::framesUpdated, decoder, &ISOTP_HANDLER::updatedFrames); connect(decoder, &ISOTP_HANDLER::newISOMessage, this, &ISOTP_InterpreterWindow::newISOMessage); @@ -123,7 +126,7 @@ void ISOTP_InterpreterWindow::showDetailView() } -void ISOTP_InterpreterWindow::newISOMessage(ISOTP_MESSAGE &msg) +void ISOTP_InterpreterWindow::newISOMessage(ISOTP_MESSAGE msg) { int rowNum; QString tempString; diff --git a/re/isotp_interpreterwindow.h b/re/isotp_interpreterwindow.h index 354cef0..5430ef2 100644 --- a/re/isotp_interpreterwindow.h +++ b/re/isotp_interpreterwindow.h @@ -21,7 +21,7 @@ public: void showEvent(QShowEvent*); private slots: - void newISOMessage(ISOTP_MESSAGE &msg); + void newISOMessage(ISOTP_MESSAGE msg); void showDetailView(); void updatedFrames(int); diff --git a/re/udsscanwindow.cpp b/re/udsscanwindow.cpp index b2088b0..6c9100b 100644 --- a/re/udsscanwindow.cpp +++ b/re/udsscanwindow.cpp @@ -19,6 +19,7 @@ UDSScanWindow::UDSScanWindow(const QVector *frames, QWidget *parent) : waitTimer->setInterval(100); UDS_HANDLER::getInstance()->setReception(true); + UDS_HANDLER::getInstance()->setProcessAllIDs(true); connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); connect(UDS_HANDLER::getInstance(), &UDS_HANDLER::newUDSMessage, this, &UDSScanWindow::gotUDSReply); @@ -317,7 +318,7 @@ void UDSScanWindow::updatedFrames(int numFrames) } } -void UDSScanWindow::gotUDSReply(UDS_MESSAGE &msg) +void UDSScanWindow::gotUDSReply(UDS_MESSAGE msg) { QString result; QString serviceShortName; diff --git a/re/udsscanwindow.h b/re/udsscanwindow.h index 33bea56..b89498f 100644 --- a/re/udsscanwindow.h +++ b/re/udsscanwindow.h @@ -23,7 +23,7 @@ public: private slots: void updatedFrames(int numFrames); - void gotUDSReply(UDS_MESSAGE &msg); + void gotUDSReply(UDS_MESSAGE msg); void scanUDS(); void saveResults(); void timeOut();