From e830d07af540bbf1adf4aa4b7670423809074a2e Mon Sep 17 00:00:00 2001 From: DowJhob Date: Sun, 23 Jan 2022 15:17:05 +0700 Subject: [PATCH] fix thread interconnect --- mainwindow.ui | 39 ++++++++++---------------------- src/DMA-proto/jcsbanksDMA.cpp | 38 +++++++++++++++---------------- src/ecu/ecu-definition.cpp | 27 +++++++++++----------- src/mainwindow.cpp | 4 ++-- src/widgets/ecuManager.cpp | 42 +++++++++-------------------------- src/widgets/ecuManager.h | 3 +-- src/widgets/loggermanager.cpp | 8 ++++++- src/widgets/loggermanager.h | 6 ++++- 8 files changed, 69 insertions(+), 98 deletions(-) diff --git a/mainwindow.ui b/mainwindow.ui index f04ffe4..75bfb86 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -175,27 +175,15 @@ - + - - 0 + + 93 0 - - HowTo - - - - - - - 93 - 0 - - - - After pushing "Start" button program trying to connect controller + + After pushing "Start" button program trying to connect controller using MUT protocol. In success, program reads calibration numbers from controller's memory. By using calibration number, program searching for xml file in home folder. The name of file @@ -215,16 +203,13 @@ xdf file. John Banks: aka JCSBanks on http://evolutionM.net creator DMA logging for Mitsu. - - - Qt::PlainText - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - + + + Qt::PlainText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + diff --git a/src/DMA-proto/jcsbanksDMA.cpp b/src/DMA-proto/jcsbanksDMA.cpp index ce99117..314d104 100644 --- a/src/DMA-proto/jcsbanksDMA.cpp +++ b/src/DMA-proto/jcsbanksDMA.cpp @@ -64,38 +64,38 @@ void jcsbanksDMA::directDMAwrite(quint32 addr, char* buf, int lenght) void jcsbanksDMA::startLog() { - qDebug()<<"=========== jcsbanksDMA::startLog ================"; +// qDebug()<<"=========== jcsbanksDMA::startLog ================"; - for( int i = 0; i < RAM_MUT.size() ; ++i ) - { - RAM_MUT[i].offset = readSize; - readSize += RAM_MUT[i].scaling.getElementSize(); - //qDebug() << "dataLogger::start" << (*_ecu_definition)->RAM_MUT[i].scaling.name << (*_ecu_definition)->RAM_MUT[i].scaling.getElementSize(); - } - scaledRAM_MUTvalue.resize(RAM_MUT.size()); +// for( int i = 0; i < RAM_MUT.size() ; ++i ) +// { +// RAM_MUT[i].offset = readSize; +// readSize += RAM_MUT[i].scaling.getElementSize(); +// //qDebug() << "dataLogger::start" << (*_ecu_definition)->RAM_MUT[i].scaling.name << (*_ecu_definition)->RAM_MUT[i].scaling.getElementSize(); +// } +// scaledRAM_MUTvalue.resize(RAM_MUT.size()); - pollTimer->start(); +// pollTimer->start(); - //((pollHelper*)ECUproto)->startLog(); +// //((pollHelper*)ECUproto)->startLog(); } void jcsbanksDMA::stopLog() { qDebug()<<"=========== jcsbanksDMA::stopLog ================"; - pollTimer->stop(); +// pollTimer->stop(); } void jcsbanksDMA::poll() { //qDebug() << "jcsbanksDMA::poll" ; - abstractMemoryScaled a = indirectDMAread(RAM_MUT_addr, readSize); - //a[0] = abs(QCursor::pos().x())/10; - //a[1] = abs(QCursor::pos().y())/6; - for( int i = 0; i < RAM_MUT.size() ; i++ ) - { - scaledRAM_MUTvalue[i] = a.toFloatOffset( &RAM_MUT[i].scaling, RAM_MUT[i].offset ); - } - emit logReady(scaledRAM_MUTvalue); +// abstractMemoryScaled a = indirectDMAread(RAM_MUT_addr, readSize); +// //a[0] = abs(QCursor::pos().x())/10; +// //a[1] = abs(QCursor::pos().y())/6; +// for( int i = 0; i < RAM_MUT.size() ; i++ ) +// { +// scaledRAM_MUTvalue[i] = a.toFloatOffset( &RAM_MUT[i].scaling, RAM_MUT[i].offset ); +// } +// emit logReady(scaledRAM_MUTvalue); } void jcsbanksDMA::sendDMAcomand(char command, unsigned long addr, unsigned long count, char *buf) diff --git a/src/ecu/ecu-definition.cpp b/src/ecu/ecu-definition.cpp index e964b22..baa8a2e 100644 --- a/src/ecu/ecu-definition.cpp +++ b/src/ecu/ecu-definition.cpp @@ -9,13 +9,17 @@ ecuDefinition::ecuDefinition() } ); // //connect(this_thread, &QThread::started, this, &controller::loop, Qt::QueuedConnection); - QObject::connect(this, &QObject::destroyed, this_thread, &QThread::quit); // Когда удалим объект остановим поток - QObject::connect(this_thread, &QThread::finished, this_thread, &QThread::deleteLater); // Когда остановим поток удалим его + connect(this, &ecuDefinition::destroyed, this_thread, &QThread::quit); // Когда удалим объект остановим поток + connect(this, &ecuDefinition::destroyed, pollTimer, &QTimer::deleteLater); // Когда удалим объект остановим поток + connect(this_thread, &QThread::finished, this_thread, &QThread::deleteLater); // Когда остановим поток удалим его moveToThread(this_thread); this_thread->start(); } -ecuDefinition::~ecuDefinition(){ +ecuDefinition::~ecuDefinition() +{ + qDebug() << "=========== ~ecuDefinition ================"; + pollTimer->deleteLater(); for(auto c : qAsConst(RAMtables)) { delete c; @@ -117,26 +121,20 @@ void ecuDefinition::disConnectECU() void ecuDefinition::RAMreset() { - qDebug() << "ecuManager::RAMreset(addr::" << DEAD_var << ");"; + qDebug() << "ecuDefinition::RAMreset(addr::" << DEAD_var << ");"; quint16 r = 0x0000; - abstractMemoryScaled a = abstractMemoryScaled(QByteArray((char*)&r, 2)); - a.addr = DEAD_var; - QMetaObject::invokeMethod(ECUproto, "directDMAwrite", Qt::QueuedConnection, - Q_ARG(abstractMemoryScaled, a)); - //ECUproto->directDMAwrite(_ecu_definition->DEAD_var, (char*)&r, 2); + ECUproto->directDMAwrite(DEAD_var, (char*)&r, 2); } void ecuDefinition::updateRAM(abstractMemoryScaled memory) { - qDebug()<< "ecuManager::updateRAM" << memory.toHex(':'); - QMetaObject::invokeMethod(ECUproto, "directDMAwrite", Qt::QueuedConnection, - Q_ARG(abstractMemoryScaled, memory)); - // ECUproto->directDMAwrite(memory); + qDebug()<< "ecuDefinition::updateRAM" << memory.toHex(':'); + ECUproto->directDMAwrite(memory); } mapDefinition *ecuDefinition::getMap(Map *declMap) { - //qDebug()<<"ECU_interface::getMap"<Name; + //qDebug()<<"ecuDefinition::getMap"<Name; //if(declMap->rom_scaling._storagetype == Storagetype::undef || declMap->rom_scaling._storagetype == Storagetype::bloblist) // return &mapDefinition(); mapDefinition *defMap = new mapDefinition; @@ -167,6 +165,7 @@ void ecuDefinition::poll() { //qDebug() << "jcsbanksDMA::poll" ; abstractMemoryScaled a = ECUproto->indirectDMAread(RAM_MUT_addr, readSize); + //a[0] = abs(QCursor::pos().x())/10; //a[1] = abs(QCursor::pos().y())/6; for( int i = 0; i < RAM_MUT.size() ; i++ ) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index adb9cb0..fb021e7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -19,7 +19,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi //============================================================================= ui->tabWidget->addTab(&hexEdit, "Hex editor"); //============================================================================= - ui->tabWidget->addTab(&_loggerManager, "Logger"); + //ui->tabWidget->addTab(&_loggerManager, "Logger"); //============================================================================= connect(ui->treeWidget, &QTreeWidget::itemClicked, this, &MainWindow::itemChecks); statusBar()->showMessage("No interface", 0); @@ -104,7 +104,7 @@ void MainWindow::createMap(mapDefinition *dMap) mapWidget *table = new mapWidget(nullptr, dMap, &colormap); //connect(table->mapModel_, &mapModel::updateRAM, this, &MainWindow::updateRAM); - connect(table->mapModel_, &mapModel::updateRAM, &_ecuManager, &ecuManager::updateRAM); + connect(table->mapModel_, &mapModel::updateRAM, &_ecuManager, &ecuManager::updateRAM, Qt::QueuedConnection); //connect(this, &MainWindow::dataLog, table->mapTable, &mapView::logReady); connect(&_ecuManager, &ecuManager::logReady, table->mapTable, &mapView::logReady); diff --git a/src/widgets/ecuManager.cpp b/src/widgets/ecuManager.cpp index 622d39f..5ce31f8 100644 --- a/src/widgets/ecuManager.cpp +++ b/src/widgets/ecuManager.cpp @@ -15,7 +15,7 @@ ecuManager::ecuManager(QWidget *parent) : QToolBar(parent) connect(&ECUdef, &ecuDefinition::logReady, this, &ecuManager::logReady); - //setProto(0); + connect(this, &ecuManager::updateRAM, &ECUdef, &ecuDefinition::updateRAM); //============================================================================= a_start_action = addAction( QIcon( ":ico/connect.png" ), "Start", this, &ecuManager::startAction); @@ -23,16 +23,10 @@ ecuManager::ecuManager(QWidget *parent) : QToolBar(parent) addSeparator(); a_ramReset = addAction(QIcon( ":ico/Memory-Freer-icon.png" ), "RAM refresh", &ECUdef, &ecuDefinition::RAMreset); a_ramReset->setDisabled(true); - //a_logger = addAction( "Start", this, &MainWindow::logger_slot); - //a_logger->setDisabled(true); addSeparator(); - //QWidget* empty = new QWidget(this); - //empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); - //addWidget(empty); - //debug_action = ui->toolBar->addAction(QIcon( ":ico/screwdriver.png" ), "Debug", this, &MainWindow::debugButton_slot); - setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); + setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); setIconSize(QSize(200, 200)); } @@ -62,7 +56,7 @@ void ecuManager::setProto(DMA_proto *ECUproto) qDebug() << "=========== ecuManager::setProto ================"; this->ECUproto = ECUproto; ECUdef.setDMAproto(ECUproto); - connect(ECUproto, &DMA_proto::logReady, this, &ecuManager::logReady); + connect(ECUproto, &DMA_proto::logReady, this, &ecuManager::logReady, Qt::QueuedConnection); } void ecuManager::setLogRate(uint logRate) @@ -96,29 +90,13 @@ void ecuManager::startAction() } } -mapDefinition *ecuManager::getMap(Map *declMap) -{ - //qDebug()<<"ECU_interface::getMap"<Name; - //if(declMap->rom_scaling._storagetype == Storagetype::undef || declMap->rom_scaling._storagetype == Storagetype::bloblist) - // return &mapDefinition(); - mapDefinition *defMap = new mapDefinition; - defMap->declMap = declMap; - if(declMap->X_axis.addr != 0) - defMap->X_axis = ECUproto->directDMAread(declMap->X_axis.addr, declMap->X_axis.byteSize()); // читаем оси - if(declMap->Y_axis.addr != 0) - defMap->Y_axis = ECUproto->directDMAread(declMap->Y_axis.addr, declMap->Y_axis.byteSize()); - defMap->Map = ECUproto->directDMAread(declMap->addr, declMap->byteSize()); - //emit gettedMap(defMap); - return defMap; -} - -void ecuManager::updateRAM(abstractMemoryScaled memory) -{ - qDebug()<< "ecuManager::updateRAM" << memory.toHex(':'); - QMetaObject::invokeMethod(ECUproto, "directDMAwrite", Qt::QueuedConnection, - Q_ARG(abstractMemoryScaled, memory)); - // ECUproto->directDMAwrite(memory); -} +//void ecuManager::updateRAM(abstractMemoryScaled memory) +//{ +// qDebug()<< "ecuManager::updateRAM" << memory.toHex(':'); +// QMetaObject::invokeMethod(&ECUdef, "updateRAM", Qt::QueuedConnection, +// Q_ARG(abstractMemoryScaled, memory)); +// // ECUproto->directDMAwrite(memory); +//} void ecuManager::lockConnect(bool lockFlag) { diff --git a/src/widgets/ecuManager.h b/src/widgets/ecuManager.h index 0c1a8c0..1755903 100644 --- a/src/widgets/ecuManager.h +++ b/src/widgets/ecuManager.h @@ -34,7 +34,6 @@ public slots: void ecuConnected(); - void updateRAM(abstractMemoryScaled memory); void lockConnect(bool lockFlag); void lockReset(bool lockFlag); @@ -51,7 +50,6 @@ public slots: char* p_in_buff; char* p_out_buff; - mapDefinition *getMap(Map *declMap); private slots: void startAction(); @@ -61,6 +59,7 @@ private slots: void disConnectECUaction(); void create_table(mapDefinition*); + void updateRAM(abstractMemoryScaled memory); void Log(QString); void logReady(QVector); diff --git a/src/widgets/loggermanager.cpp b/src/widgets/loggermanager.cpp index 9846354..9b5f60b 100644 --- a/src/widgets/loggermanager.cpp +++ b/src/widgets/loggermanager.cpp @@ -1,6 +1,12 @@ #include "loggermanager.h" -loggerManager::loggerManager(QWidget *parent) : QWidget{parent} +loggerManager::loggerManager(QWidget *parent) : QMdiArea{parent} { setDisabled(true); + tileSubWindows(); + setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Preferred); + + setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); } + diff --git a/src/widgets/loggermanager.h b/src/widgets/loggermanager.h index c80e3de..7a2c353 100644 --- a/src/widgets/loggermanager.h +++ b/src/widgets/loggermanager.h @@ -2,13 +2,17 @@ #define LOGGERMANAGER_H #include +#include -class loggerManager : public QWidget +class loggerManager : public QMdiArea { Q_OBJECT public: explicit loggerManager(QWidget *parent = nullptr); +private: + //QMdiArea logMdiArea; + signals: };