Skip to content

Commit

Permalink
improve ecu control
Browse files Browse the repository at this point in the history
  • Loading branch information
DowJhob committed Jan 21, 2022
1 parent 9b5e5e4 commit 4b7e603
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 212 deletions.
4 changes: 2 additions & 2 deletions livemap.pro
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ SOURCES += src/main.cpp\
src/DMA-proto/jcsbanksDMA.cpp \
src/DMA-proto/stockDMA.cpp \
src/comm-device-interface/op20.cpp \
src/ecuManager.cpp \
src/widgets/ecuManager.cpp \
src/wideband/op20wb.cpp \
src/DMA-proto/pollhelper.cpp \
src/deviceNativeFilter.cpp \
Expand Down Expand Up @@ -104,7 +104,7 @@ HEADERS += src/mainwindow.h \
src/DMA-proto/proto-manager.h \
src/abstract-memory.h \
src/comm-device-interface/devicemanager.h \
src/ecuManager.h \
src/widgets/ecuManager.h \
src/wideband/op20wb.h \
src/DMA-proto/pollhelper.h \
src/DMA-proto/evoX-DMA.h \
Expand Down
11 changes: 0 additions & 11 deletions src/DMA-proto/DMA-proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ DMA_proto::~DMA_proto()
// qDebug() << "~ECU_interface";
}

bool DMA_proto::getECU(QString romID)
{
if (!_ecu_definition.fromFile(_ecu_definition.SearchFiles(QApplication::applicationDirPath() + "/xml/", romID)))
{
//delete _ecu_definition;
qDebug() << "XML NOT FOUND!!!!!!!!!!!!!!!!!!!!!!!!!";
return false;
}
return true;
}

void DMA_proto::directDMAwrite(abstractMemoryScaled memory)
{
qDebug()<< "DMA_proto::directDMAwrite" << memory.toHex(':');
Expand Down
15 changes: 8 additions & 7 deletions src/DMA-proto/DMA-proto.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ECU_INTERFACE_H
#define ECU_INTERFACE_H
#ifndef DMAPROTO_H
#define DMAPROTO_H

#include <QApplication>
#include <QObject>
Expand All @@ -9,7 +9,7 @@
#include <QtEndian>
#include <QElapsedTimer>

#include <src/ecu/ecu-definition.h>
#include "../abstract-memory.h"

#include "../comm-device-interface/comm-device-interface.h"

Expand All @@ -29,14 +29,14 @@ class DMA_proto : public pollHelper
Q_OBJECT
public:
comm_device_interface **devComm = nullptr;
ecu_definition _ecu_definition;
QVector<mutParam> RAM_MUT;
quint32 RAM_MUT_addr;

DMA_proto();
//explicit DMA_proto(comm_device_interface **devComm = nullptr);
virtual ~DMA_proto();

void setCommDev(comm_device_interface **devComm = nullptr);
bool getECU(QString romID);

virtual bool connect() = 0;

Expand All @@ -50,9 +50,10 @@ public slots:
virtual void startLog() = 0;
virtual void stopLog() = 0;

private slots:
virtual void poll() = 0;

private slots:

private:

//Protocol protocol;
Expand All @@ -64,4 +65,4 @@ private slots:

};

#endif // ECU_INTERFACE_H
#endif // DMAPROTO_H
14 changes: 7 additions & 7 deletions src/DMA-proto/jcsbanksDMA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ void jcsbanksDMA::startLog()
{
qDebug()<<"=========== jcsbanksDMA::startLog ================";

for( int i = 0; i < _ecu_definition.RAM_MUT.size() ; ++i )
for( int i = 0; i < RAM_MUT.size() ; ++i )
{
_ecu_definition.RAM_MUT[i].offset = readSize;
readSize += _ecu_definition.RAM_MUT[i].scaling.getElementSize();
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(_ecu_definition.RAM_MUT.size());
scaledRAM_MUTvalue.resize(RAM_MUT.size());

pollTimer->start();

Expand All @@ -88,12 +88,12 @@ void jcsbanksDMA::stopLog()
void jcsbanksDMA::poll()
{
//qDebug() << "jcsbanksDMA::poll" ;
abstractMemoryScaled a = indirectDMAread(_ecu_definition.RAM_MUT_addr, readSize);
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 < _ecu_definition.RAM_MUT.size() ; i++ )
for( int i = 0; i < RAM_MUT.size() ; i++ )
{
scaledRAM_MUTvalue[i] = a.toFloatOffset( &_ecu_definition.RAM_MUT[i].scaling, _ecu_definition.RAM_MUT[i].offset );
scaledRAM_MUTvalue[i] = a.toFloatOffset( &RAM_MUT[i].scaling, RAM_MUT[i].offset );
}
emit logReady(scaledRAM_MUTvalue);
}
Expand Down
24 changes: 12 additions & 12 deletions src/DMA-proto/pollhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

pollHelper::pollHelper() //: QObject(parent)
{
QThread *this_thread = new QThread();
QObject::connect(this_thread, &QThread::started, this, [this](){
pollTimer = new QTimer(this);
pollTimer->setInterval(50);
QObject::connect(pollTimer, &QTimer::timeout, this, &pollHelper::poll);
}
);
// //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); // Когда остановим поток удалим его
moveToThread(this_thread);
this_thread->start();
// QThread *this_thread = new QThread();
// QObject::connect(this_thread, &QThread::started, this, [this](){
// pollTimer = new QTimer(this);
// pollTimer->setInterval(50);
// QObject::connect(pollTimer, &QTimer::timeout, this, &pollHelper::poll);
// }
// );
// // //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); // Когда остановим поток удалим его
// moveToThread(this_thread);
// this_thread->start();
}

//void pollHelper::startLog()
Expand Down
3 changes: 2 additions & 1 deletion src/DMA-proto/pollhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public slots:
virtual void startLog() = 0;
virtual void stopLog() = 0;

virtual void poll() = 0;

private:

private slots:
virtual void poll() = 0;

signals:
void logReady(QVector<float>);
Expand Down
164 changes: 154 additions & 10 deletions src/ecu/ecu-definition.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
#include "ecu-definition.h"

ecu_definition::ecu_definition(){}
ecuDefinition::ecuDefinition()
{
QThread *this_thread = new QThread();
QObject::connect(this_thread, &QThread::started, this, [this](){
pollTimer = new QTimer(this);
pollTimer->setInterval(50);
}
);
// //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); // Когда остановим поток удалим его
moveToThread(this_thread);
this_thread->start();
}

ecu_definition::~ecu_definition(){
ecuDefinition::~ecuDefinition(){
for(auto c : qAsConst(RAMtables))
{
delete c;
}
}

bool ecu_definition::fromFile(QString filename)
bool ecuDefinition::fromFile(QString filename)
{
// Открываем конфиг:
QFile* file = new QFile(filename);
Expand All @@ -20,7 +33,12 @@ bool ecu_definition::fromFile(QString filename)
return true;
}

QString ecu_definition::SearchFiles(QString path, QString CalID) // Для поиска файлов в каталоге
bool ecuDefinition::fromROMID(QString ROMID)
{
return fromFile(getFile(QApplication::applicationDirPath() + "/xml/", ROMID));
}

QString ecuDefinition::getFile(QString path, QString CalID) // Для поиска файлов в каталоге
{
// Пытаемся найти правильные файлы, в текущем каталоге
QStringList listFiles = QDir(path).entryList((CalID + "*.xml ").split(" "), QDir::Files); //выборка файлов по маскам
Expand All @@ -31,7 +49,134 @@ QString ecu_definition::SearchFiles(QString path, QString CalID) // Для
return path + listFiles.at(0);
}

void ecu_definition::_parser(QIODevice *device)
void ecuDefinition::setComDev(comm_device_interface *_devComm)
{
devComm = _devComm;

if (devComm == nullptr )
{
// все интерфесы отключены, сделай что нибудь!!!!
pollTimer->stop();
}
else
ECUproto->setCommDev(&devComm);
}

void ecuDefinition::setDMAproto(DMA_proto *_ECUproto)
{
ECUproto = _ECUproto;
_ECUproto->setCommDev(&devComm);
connect(pollTimer, &QTimer::timeout, this, &ecuDefinition::poll);
}

bool ecuDefinition::connectECU()
{
qDebug() << "=========== ecuDefinition::connectECU ================" << devComm;
if (!ECUproto->connect())
{
emit Log("failure get ECU connect " + QString::number( devComm->getBaudRate()));
return false;
}
QByteArray a = ECUproto->directDMAread( 0xF52, 4); //читаем номер калибровки
if ( a.isEmpty() )
{
emit Log("failure get ECU rom id");
return false;
}
QString romID = QString::number( qFromBigEndian<quint32>(a.data()), 16 );
emit Log("romID: " + romID);
//emit Log("CurrDir: " + QApplication::applicationDirPath());
//===================================================================================================
if (!fromROMID(romID))
{
(*ECUproto->devComm)->close();
qDebug() << "XML NOT FOUND!!!!!!!!!!!!!!!!!!!!!!!!!";
emit Log("xml not found");
return false;
}
ECUproto->RAM_MUT = RAM_MUT;
ECUproto->RAM_MUT_addr = RAM_MUT_addr;
//==================================================================================================
emit ecu_connected();
// переберем все описания таблиц
for ( Map *tab : qAsConst(RAMtables) )
{
emit create_table( getMap(tab) );
}
startLog();
return true;
}

void ecuDefinition::disConnectECU()
{
qDebug() << "=========== ecuDefinition::disConnectECU ================";
pollTimer->stop();
QThread::msleep(1000); // костыль
devComm->close();
}

void ecuDefinition::RAMreset()
{
qDebug() << "ecuManager::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);
}

void ecuDefinition::updateRAM(abstractMemoryScaled memory)
{
qDebug()<< "ecuManager::updateRAM" << memory.toHex(':');
QMetaObject::invokeMethod(ECUproto, "directDMAwrite", Qt::QueuedConnection,
Q_ARG(abstractMemoryScaled, memory));
// ECUproto->directDMAwrite(memory);
}

mapDefinition *ecuDefinition::getMap(Map *declMap)
{
//qDebug()<<"ECU_interface::getMap"<<declMap->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 ecuDefinition::startLog()
{
qDebug()<<"=========== ecuDefinition::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());
pollTimer->start();
}

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++ )
{
scaledRAM_MUTvalue[i] = a.toFloatOffset( &RAM_MUT[i].scaling, RAM_MUT[i].offset );
}
emit logReady(scaledRAM_MUTvalue);
}

void ecuDefinition::_parser(QIODevice *device)
{
QString errorStr;
int errorLine;
Expand Down Expand Up @@ -78,7 +223,7 @@ void ecu_definition::_parser(QIODevice *device)

}

void ecu_definition::getMUTparam(const QDomElement &element)
void ecuDefinition::getMUTparam(const QDomElement &element)
{
QDomNode node = element.firstChild();
while (!node.isNull())
Expand All @@ -90,22 +235,21 @@ void ecu_definition::getMUTparam(const QDomElement &element)
_mut_param.scaling = scaling_qmap.value(el.attribute("scaling"));

_mut_param.number = el.attribute("number").toInt(nullptr, 16);
++RAM_MUT_count;
//++RAM_MUT_count;
RAM_MUT.insert(_mut_param.number, _mut_param );
}
node = node.nextSibling();
}
}


void ecu_definition::getLivemap(const QDomElement &element)
void ecuDefinition::getLivemap(const QDomElement &element)
{
Map *mainTableDeclaration = new Map;
mainTableDeclaration->fromXML(element);
RAMtables.insert(mainTableDeclaration->Name, mainTableDeclaration);
}

void ecu_definition::getScaling(const QDomElement &el)
void ecuDefinition::getScaling(const QDomElement &el)
{
Scaling sc(el);
scaling_qmap.insert(sc.name, sc);
Expand Down
Loading

0 comments on commit 4b7e603

Please sign in to comment.