From 0215b49775d8a6ad8f2c59971af0c0565ce9d374 Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Sun, 3 Aug 2014 08:44:24 -0400 Subject: [PATCH] Plugins: Removal of FreeEMS Plugin out into its own repository at http://github.com/malcom2073/emstune-freeems/ --- plugins/freeems/datafield.cpp | 109 -- plugins/freeems/datafield.h | 79 - plugins/freeems/emsdata.cpp | 1114 ------------- plugins/freeems/emsdata.h | 162 -- plugins/freeems/feconfigdata.cpp | 187 --- plugins/freeems/feconfigdata.h | 65 - plugins/freeems/fedatapacketdecoder.cpp | 236 --- plugins/freeems/fedatapacketdecoder.h | 51 - plugins/freeems/fememorymetadata.cpp | 371 ----- plugins/freeems/fememorymetadata.h | 81 - plugins/freeems/ferawdata.cpp | 60 - plugins/freeems/ferawdata.h | 32 - plugins/freeems/fetable2ddata.cpp | 355 ---- plugins/freeems/fetable2ddata.h | 97 -- plugins/freeems/fetable3ddata.cpp | 366 ----- plugins/freeems/fetable3ddata.h | 105 -- plugins/freeems/freeems.pro | 108 -- plugins/freeems/freeemscomms.cpp | 1985 ----------------------- plugins/freeems/freeemscomms.h | 254 --- plugins/freeems/memorylocation.cpp | 128 -- plugins/freeems/memorylocation.h | 65 - plugins/freeems/packet.h | 64 - plugins/freeems/packetdecoder.cpp | 491 ------ plugins/freeems/packetdecoder.h | 42 - plugins/freeems/serialport.cpp | 181 --- plugins/freeems/serialport.h | 84 - plugins/freeems/serialrxthread.cpp | 299 ---- plugins/freeems/serialrxthread.h | 56 - 28 files changed, 7227 deletions(-) delete mode 100644 plugins/freeems/datafield.cpp delete mode 100644 plugins/freeems/datafield.h delete mode 100644 plugins/freeems/emsdata.cpp delete mode 100644 plugins/freeems/emsdata.h delete mode 100644 plugins/freeems/feconfigdata.cpp delete mode 100644 plugins/freeems/feconfigdata.h delete mode 100644 plugins/freeems/fedatapacketdecoder.cpp delete mode 100644 plugins/freeems/fedatapacketdecoder.h delete mode 100644 plugins/freeems/fememorymetadata.cpp delete mode 100644 plugins/freeems/fememorymetadata.h delete mode 100644 plugins/freeems/ferawdata.cpp delete mode 100644 plugins/freeems/ferawdata.h delete mode 100644 plugins/freeems/fetable2ddata.cpp delete mode 100644 plugins/freeems/fetable2ddata.h delete mode 100644 plugins/freeems/fetable3ddata.cpp delete mode 100644 plugins/freeems/fetable3ddata.h delete mode 100644 plugins/freeems/freeems.pro delete mode 100644 plugins/freeems/freeemscomms.cpp delete mode 100644 plugins/freeems/freeemscomms.h delete mode 100644 plugins/freeems/memorylocation.cpp delete mode 100644 plugins/freeems/memorylocation.h delete mode 100644 plugins/freeems/packet.h delete mode 100644 plugins/freeems/packetdecoder.cpp delete mode 100644 plugins/freeems/packetdecoder.h delete mode 100644 plugins/freeems/serialport.cpp delete mode 100644 plugins/freeems/serialport.h delete mode 100644 plugins/freeems/serialrxthread.cpp delete mode 100644 plugins/freeems/serialrxthread.h diff --git a/plugins/freeems/datafield.cpp b/plugins/freeems/datafield.cpp deleted file mode 100644 index 63e92a9..0000000 --- a/plugins/freeems/datafield.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/************************************************************************************** - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License and GNU General Public License for * - * more details. * - * * - * You should have received a copy of the GNU Lesser General Public License * - * along with this program; if not, write to Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * * - *------------------------------------------------------------------------------------* - * * - * BSD 3-Clause License Usage * - * Alternatively, this file may also be used under the terms of the * - * BSD 3-Clause license, detailed below: * - * * - * Redistribution and use in source and binary forms, with or without * - * modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright * - * notice, this list of conditions and the following disclaimer. * - * * Redistributions in binary form must reproduce the above copyright * - * notice, this list of conditions and the following disclaimer in the * - * documentation and/or other materials provided with the distribution. * - * * Neither the name EMStudio nor the * - * names of its contributors may be used to endorse or promote products * - * derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * - * DISCLAIMED. IN NO EVENT SHALL MICHAEL CARPENTER BE LIABLE FOR ANY * - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************************/ - -#include "datafield.h" -#include -DataField::DataField() -{ -} -DataField::DataField(QString shortname,QString description,int offset,int size,double div,double addoffset,double min,double max,bool isFlags,int bit) -{ - m_offset = offset; - m_size = size; - m_div = div; - m_name = shortname; - m_description = description; - m_min = min; - m_max = max; - m_addoffset = addoffset; - m_isFlags = isFlags; - m_bit = bit; -} -bool DataField::flagValue(QByteArray *payload, bool *value) -{ - if (!m_isFlags) - { - return false; - } - if (payload->size() >= m_offset+m_size) - { - unsigned int val = 0; - for (int i=0;iat(m_offset+i)) << (8*(m_size-(i+1))); - } - *value = (m_bit & val); - return true; - } - return false; -} - -bool DataField::getValue(QByteArray *payload,double *value,bool translatebeforescale) -{ - if (payload->size() >= m_offset+m_size) - { - float val = 0; - for (int i=0;iat(m_offset+i)) << (8*(m_size-(i+1))); - } - if (translatebeforescale) - { - *value = (val + m_addoffset) * m_div; - return true; - } - else - { - *value = (val / m_div) + m_addoffset; - return true; - } - } - return false; -} diff --git a/plugins/freeems/datafield.h b/plugins/freeems/datafield.h deleted file mode 100644 index 597621d..0000000 --- a/plugins/freeems/datafield.h +++ /dev/null @@ -1,79 +0,0 @@ -/************************************************************************************** - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License and GNU General Public License for * - * more details. * - * * - * You should have received a copy of the GNU Lesser General Public License * - * along with this program; if not, write to Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * * - *------------------------------------------------------------------------------------* - * * - * BSD 3-Clause License Usage * - * Alternatively, this file may also be used under the terms of the * - * BSD 3-Clause license, detailed below: * - * * - * Redistribution and use in source and binary forms, with or without * - * modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright * - * notice, this list of conditions and the following disclaimer. * - * * Redistributions in binary form must reproduce the above copyright * - * notice, this list of conditions and the following disclaimer in the * - * documentation and/or other materials provided with the distribution. * - * * Neither the name EMStudio nor the * - * names of its contributors may be used to endorse or promote products * - * derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * - * DISCLAIMED. IN NO EVENT SHALL MICHAEL CARPENTER BE LIABLE FOR ANY * - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************************/ - -#ifndef DATAFIELD_H -#define DATAFIELD_H -#include -class DataField -{ -public: - DataField(); - DataField(QString shortname,QString description,int offset,int size,double div,double addoffset=0,double min=0,double max=0,bool isFlags=false,int bit=0); - bool getValue(QByteArray *payload,double *value,bool translatebeforescale = false); - QString description() { return m_description; } - QString name() { return m_name; } - bool isFlag() { return m_isFlags; } - bool flagValue(QByteArray *payload, bool *value); - int offset() { return m_offset; } - int size() { return m_size; } -private: - QString m_name; - QString m_description; - bool m_isFlags; - int m_bit; - int m_offset; - int m_size; - float m_div; - float m_addoffset; - float m_min; - float m_max; -}; - -#endif // DATAFIELD_H diff --git a/plugins/freeems/emsdata.cpp b/plugins/freeems/emsdata.cpp deleted file mode 100644 index ac645b6..0000000 --- a/plugins/freeems/emsdata.cpp +++ /dev/null @@ -1,1114 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ -#include "emsdata.h" -#include "QsLog.h" - -EmsData::EmsData() : QObject() -{ - m_interrogationInProgress = false; - m_checkEmsDataInUse = false; -} -QByteArray EmsData::getLocalRamBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_ramMemoryList[i]->data(); - } - } - return QByteArray(); -} - -QByteArray EmsData::getLocalFlashBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_flashMemoryList[i]->data(); - } - } - return QByteArray(); -} -QByteArray EmsData::getDeviceRamBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_deviceRamMemoryList[i]->data(); - } - } - return QByteArray(); -} - -QByteArray EmsData::getDeviceFlashBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_deviceFlashMemoryList[i]->data(); - } - } - return QByteArray(); -} - -bool EmsData::hasDeviceRamBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return true; - } - } - return false; -} -bool EmsData::hasLocalRamBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return true; - } - } - return false; -} -void EmsData::setLocalRamBlock(unsigned short id,QByteArray data) -{ - for (int i=0;ilocationid == id) - { - m_ramMemoryList[i]->setData(data); - return; - } - } -} - -void EmsData::setDeviceRamBlock(unsigned short id,QByteArray data) -{ - for (int i=0;ilocationid == id) - { - m_deviceRamMemoryList[i]->setData(data); - return; - } - } -} - -void EmsData::setLocalFlashBlock(unsigned short id,QByteArray data) -{ - for (int i=0;ilocationid == id) - { - m_flashMemoryList[i]->setData(data); - return; - } - } -} - -bool EmsData::hasLocalFlashBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return true; - } - } - return false; -} -bool EmsData::hasDeviceFlashBlock(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return true; - } - } - return false; -} -void EmsData::populateDeviceRamAndFlashParents() -{ - for (int i=0;ihasParent && m_deviceFlashMemoryList[i]->getParent() == 0) - { - for (int j=0;jparent== m_deviceFlashMemoryList[j]->locationid) - { - m_deviceFlashMemoryList[i]->setParent(m_deviceFlashMemoryList[j]); - } - } - } - } - for (int i=0;ihasParent && m_deviceRamMemoryList[i]->getParent() == 0) - { - for (int j=0;jparent== m_deviceRamMemoryList[j]->locationid) - { - m_deviceRamMemoryList[i]->setParent(m_deviceRamMemoryList[j]); - } - } - } - } - - - for (int i=0;ihasParent && m_duplicateFlashMemoryList[i]->getParent() == 0) - { - for (int j=0;jparent== m_duplicateFlashMemoryList[j]->locationid) - { - m_duplicateFlashMemoryList[i]->setParent(m_duplicateFlashMemoryList[j]); - } - } - } - } - for (int i=0;ihasParent && m_duplicateRamMemoryList[i]->getParent() == 0) - { - for (int j=0;jparent== m_duplicateRamMemoryList[j]->locationid) - { - m_duplicateRamMemoryList[i]->setParent(m_duplicateRamMemoryList[j]); - } - } - } - } - -} - -void EmsData::setDeviceFlashBlock(unsigned short id,QByteArray data) -{ - for (int i=0;ilocationid == id) - { - m_deviceFlashMemoryList[i]->setData(data); - return; - } - } -} - -void EmsData::clearAllMemory() -{ - m_deviceFlashMemoryList.clear(); - m_deviceRamMemoryList.clear(); - m_flashMemoryList.clear(); - m_ramMemoryList.clear(); -} -void EmsData::addDeviceRamBlock(MemoryLocation *loc) -{ - m_deviceRamMemoryList.append(loc); - m_duplicateRamMemoryList.append(new MemoryLocation(*loc)); -} - -void EmsData::addLocalFlashBlock(MemoryLocation *loc) -{ - m_flashMemoryList.append(loc); -} - -void EmsData::addLocalRamBlock(MemoryLocation *loc) -{ - m_ramMemoryList.append(loc); -} - -void EmsData::addDeviceFlashBlock(MemoryLocation *loc) -{ - m_deviceFlashMemoryList.append(loc); - m_duplicateFlashMemoryList.append(new MemoryLocation(*loc)); -} -QList EmsData::getChildrenOfLocalRamLocation(unsigned short id) -{ - QList retVal; - for (int i=0;ihasParent) - { - if (m_ramMemoryList[i]->parent == id) - { - retVal.append(m_ramMemoryList[i]->locationid); - } - } - } - return retVal; -} - -unsigned short EmsData::getParentOfLocalRamLocation(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_ramMemoryList[i]->parent; - } - } - return 0; -} -bool EmsData::localRamHasParent(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_ramMemoryList[i]->hasParent; - } - } - return false; -} -bool EmsData::localRamHasChildren(unsigned short id) -{ - for (int i=0;ihasParent && m_ramMemoryList[i]->parent == id) - { - return true; - } - } - return false; -} - -QList EmsData::getChildrenOfLocalFlashLocation(unsigned short id) -{ - QList retVal; - for (int i=0;ihasParent) - { - if (m_flashMemoryList[i]->parent == id) - { - retVal.append(m_flashMemoryList[i]->locationid); - } - } - } - return retVal; -} - -unsigned short EmsData::getParentOfLocalFlashLocation(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_flashMemoryList[i]->parent; - } - } - return 0; -} -bool EmsData::localFlashHasParent(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_flashMemoryList[i]->hasParent; - } - } - return false; -} -bool EmsData::localFlashHasChildren(unsigned short id) -{ - for (int i=0;ihasParent && m_flashMemoryList[i]->parent == id) - { - return true; - } - } - return false; -} - - -QList EmsData::getTopLevelDeviceFlashLocations() -{ - QList retval; - for (int i=0;ihasParent) - { - retval.append(m_deviceFlashMemoryList[i]->locationid); - } - } - return retval; -} -void EmsData::populateLocalRamAndFlash() -{ - if (m_ramMemoryList.size() == 0) - { - //Internal ram list is empty. Let's fill it. - for (int i=0;ihasParent) - { - for (int j=0;jparent== m_ramMemoryList[j]->locationid) - { - m_ramMemoryList[i]->setParent(m_ramMemoryList[j]); - } - } - } - } - } - if (m_flashMemoryList.size() == 0) - { - for (int i=0;ihasParent) - { - for (int j=0;jparent== m_flashMemoryList[j]->locationid) - { - m_flashMemoryList[i]->setParent(m_flashMemoryList[j]); - } - } - } - } - } -} -QList EmsData::getTopLevelUniqueLocationIdList() -{ - QList retval; - for (int i=0;ihasParent) - { - retval.append(m_deviceRamMemoryList[i]->locationid); - } - } - for (int i=0;ihasParent && !retval.contains(m_deviceFlashMemoryList[i]->locationid)) - { - retval.append(m_deviceFlashMemoryList[i]->locationid); - } - } - return retval; - - -} -QList EmsData::getUniqueLocationIdList() -{ - QList retval; - for (int i=0;ilocationid); - } - for (int i=0;ilocationid)) - { - retval.append(m_deviceFlashMemoryList[i]->locationid); - } - } - return retval; -} - -QList EmsData::getTopLevelDeviceRamLocations() -{ - QList retval; - for (int i=0;ihasParent) - { - retval.append(m_deviceRamMemoryList[i]->locationid); - } - } - return retval; -} - -QString EmsData::serialize(unsigned short id,bool isram) -{ - QString val = ""; - QByteArray block; - if (isram) - { - block = getDeviceRamBlock(id); - } - else - { - block = getDeviceFlashBlock(id); - } - for (int j=0;jlocationid = locationid; - loc->size = info.size; - loc->ramAddress = info.ramaddress; - loc->ramPage = info.rampage; - loc->flashAddress = info.flashaddress; - loc->flashPage = info.flashpage; - loc->isReadOnly = info.isReadOnly; - if (info.hasParent) - { - loc->parent = info.parent; - loc->hasParent = true; - } - else - { - loc->hasParent = false; - } - loc->isRam = true; - loc->isFlash = true; - if (!hasDeviceFlashBlock(locationid)) - { - addDeviceFlashBlock(new MemoryLocation(*loc)); - } - if (!hasDeviceRamBlock(locationid)) - { - addDeviceRamBlock(loc); - } - else - { - delete loc; - } - - } - else if (info.isFlash) - { - MemoryLocation *loc = new MemoryLocation(); - loc->locationid = locationid; - loc->size = info.size; - loc->flashAddress = info.flashaddress; - loc->flashPage = info.flashpage; - loc->isReadOnly = info.isReadOnly; - if (info.hasParent) - { - loc->parent = info.parent; - loc->hasParent = true; - } - else - { - loc->hasParent = false; - } - loc->isRam = false; - loc->isFlash = true; - if (!hasDeviceFlashBlock(locationid)) - { - addDeviceFlashBlock(loc); - } - else - { - delete loc; - } - - } - else if (info.isRam) - { - MemoryLocation *loc = new MemoryLocation(); - loc->locationid = locationid; - loc->size = info.size; - loc->ramAddress = info.ramaddress; - loc->ramPage = info.rampage; - loc->isReadOnly = info.isReadOnly; - if (info.hasParent) - { - loc->parent = info.parent; - loc->hasParent = true; - } - else - { - loc->hasParent = false; - } - loc->isRam = true; - loc->isFlash = false; - if (!hasDeviceRamBlock(locationid)) - { - addDeviceRamBlock(loc); - } - else - { - delete loc; - } - - } - else - { - } - /*if (flags.contains(FreeEmsComms::BLOCK_IS_RAM) && flags.contains((FreeEmsComms::BLOCK_IS_FLASH))) - { - MemoryLocation *loc = new MemoryLocation(); - loc->locationid = locationid; - loc->size = size; - if (flags.contains(FreeEmsComms::BLOCK_HAS_PARENT)) - { - loc->parent = parent; - loc->hasParent = true; - } - loc->isRam = true; - loc->isFlash = true; - loc->ramAddress = ramaddress; - loc->ramPage = rampage; - loc->flashAddress = flashaddress; - loc->flashPage = flashpage; - //m_deviceRamMemoryList.append(loc); - emsData->addDeviceRamBlock(loc); - emsData->addDeviceFlashBlock(new MemoryLocation(*loc)); - //m_flashMemoryList.append(new MemoryLocation(*loc)); - //m_deviceFlashMemoryList.append(new MemoryLocation(*loc)); - - } - else if (flags.contains(FreeEmsComms::BLOCK_IS_FLASH)) - { - MemoryLocation *loc = new MemoryLocation(); - loc->locationid = locationid; - loc->size = size; - if (flags.contains(FreeEmsComms::BLOCK_HAS_PARENT)) - { - loc->parent = parent; - loc->hasParent = true; - } - loc->isFlash = true; - loc->isRam = false; - loc->flashAddress = flashaddress; - loc->flashPage = flashpage; - //m_deviceFlashMemoryList.append(loc); - emsData->addDeviceFlashBlock(loc); - } - else if (flags.contains(FreeEmsComms::BLOCK_IS_RAM)) - { - MemoryLocation *loc = new MemoryLocation(); - loc->locationid = locationid; - loc->size = size; - if (flags.contains(FreeEmsComms::BLOCK_HAS_PARENT)) - { - loc->parent = parent; - loc->hasParent = true; - } - loc->isRam = true; - loc->isFlash = false; - loc->ramAddress = ramaddress; - loc->ramPage = rampage; - //m_deviceRamMemoryList.append(loc); - emsData->addDeviceRamBlock(loc); - }*/ -} - - -void EmsData::ramBlockUpdate(unsigned short locationid, QByteArray header, QByteArray payload) -{ - Q_UNUSED(header) - QLOG_TRACE() << "Ram Block retrieved:" << "0x" + QString::number(locationid,16).toUpper(); - QList configlist = m_memoryMetaData->getConfigMetaData(QString::number(locationid,16).toUpper()); - for (int i=0;ilocationid = locationid; - block->header = header; - block->data = payload; - //m_flashRawBlockList.append(block); - m_deviceRamRawBlockList.append(block);*/ - } - else - { - //Check to see if it's supposed to be a table, and if so, check size - if (!verifyMemoryBlock(locationid,header,payload)) - { - //QMessageBox::information(this,"Error","RAM Location ID 0x" + QString::number(locationid,16).toUpper() + " should be 1024 sized, but it is " + QString::number(payload.size()) + ". This should never happen"); - QLOG_ERROR() << "RAM Location ID 0x" + QString::number(locationid,16).toUpper() + " should be 1024 sized, but it is " + QString::number(payload.size()) + ". This should never happen"; - return; - } - if (getDeviceRamBlock(locationid).isEmpty()) - { - //This should not happen - QLOG_ERROR() << "Ram block on device while ram block on tuner is empty! This should not happen" << "0x" + QString::number(locationid,16).toUpper(); - QLOG_ERROR() << "Current block size:" << getDeviceRamBlock(locationid).size(); - setLocalRamBlock(locationid,payload); - setDeviceRamBlock(locationid,payload); - } - else - { - if (m_interrogationInProgress) - { - //checkEmsData->setDeviceRamBlock(locationid,payload); - for (int i=0;ilocationid == locationid) - { - m_duplicateRamMemoryList[i]->setData(payload); - break; - } - } - m_checkEmsDataInUse = true; - } - else - { - if (getDeviceRamBlock(locationid) != payload) - { - QLOG_ERROR() << "Ram block on device does not match ram block on tuner! This should ONLY happen during a manual update!"; - QLOG_ERROR() << "Tuner ram size:" << getDeviceRamBlock(locationid).size(); - setDeviceRamBlock(locationid,payload); - } - if (payload != getLocalRamBlock(locationid)) - { - QLOG_ERROR() << "Ram block on device does not match ram block on tuner! This means local data is out of date!"; - //We need to prompt the user, local ram is out of date. - if (isLocalRamDirty(locationid)) - { - QLOG_ERROR() << "Ram block is marked dirty"; - setLocalRamBlock(locationid,payload); - markLocalRamLocationClean(locationid); - } - else - { - MemoryLocation *ram= getLocalRamBlockInfo(locationid); - if (ram) - { - if (!ram->isReadOnly) - { - //Don't mark read only as dirty, we don't care. - m_dirtyLocalRamMemoryList.append(QPair(locationid,payload)); - emit localRamLocationDirty(locationid); - } - } - else - { - //No memory location, don't do anything - } - } - } - else - { - QLOG_ERROR() << "Ram block on device matches ram block on tuner"; - } - } - } - //updateDataWindows(locationid); - emit updateRequired(locationid); - } - return; -} - -void EmsData::flashBlockUpdate(unsigned short locationid, QByteArray header, QByteArray payload) -{ - QLOG_TRACE() << "Flash Block retrieved:" << "0x" + QString::number(locationid,16).toUpper(); - Q_UNUSED(header) - for (int l=0;l configlist = m_memoryMetaData->getConfigMetaData(QString::number(childid,16).toUpper()); - QLOG_TRACE() << "Location" << QString::number(childid,16).toUpper() << "Size:" << configlist.size(); - for (int i=0;isetDeviceFlashBlock(locationid,payload); - for (int i=0;ilocationid == locationid) - { - m_duplicateFlashMemoryList[i]->setData(payload); - break; - } - } - m_checkEmsDataInUse = true; - } - else - { - if (getDeviceFlashBlock(locationid) != payload) - { - QLOG_ERROR() << "Flash block in memory does not match flash block on tuner! This should not happen!"; - QLOG_ERROR() << "Flash size:" << getDeviceFlashBlock(locationid).size(); - QLOG_ERROR() << "Flash ID:" << "0x" + QString::number(locationid,16).toUpper(); - setDeviceFlashBlock(locationid,payload); - } - if (getLocalFlashBlock(locationid) != payload) - { - if(isLocalFlashDirty(locationid)) - { - setLocalFlashBlock(locationid,payload); - markLocalFlashLocationClean(locationid); - } - else - { - //We have incoming memory, when wedidn't know it was dirty. - //Emit a signal to let the user know there is a descrepancy that needs - //to be accepted, or rejected (in which case, rewritten to the ECU) - m_dirtyLocalFlashMemoryList.append(QPair(locationid,payload)); - emit localFlashLocationDirty(locationid); - } - - } - } - } - } - emit updateRequired(locationid); - //updateDataWindows(locationid); - return; -} -void EmsData::ramBytesLocalUpdate(unsigned short locationid,unsigned short offset,unsigned short size,QByteArray data) -{ - if (!hasLocalRamBlock(locationid)) - { - QLOG_WARN() << "Write requested when there is no local ram block!"; - return; - } - if (getLocalRamBlock(locationid).mid(offset,size) == data) - { - QLOG_WARN() << "Data in application ram memory unchanged, no reason to send write for single value"; - return; - } - QLOG_TRACE() << "Updating ram locationid" << locationid << "with" << data.size() << "bytes at offset" << offset; - setLocalRamBlock(locationid,getLocalRamBlock(locationid).replace(offset,size,data)); - //emit updateRequired(locationid); - emit ramBlockUpdateRequest(locationid,offset,size,data); -} - -void EmsData::flashBytesLocalUpdate(unsigned short locationid,unsigned short offset,unsigned short size,QByteArray data) -{ - if (!hasLocalFlashBlock(locationid)) - { - QLOG_ERROR() << "Requested flash update for locationid" << locationid << "but location has no flash!"; - return; - } - if (getLocalFlashBlock(locationid).mid(offset,size) == data) - { - QLOG_WARN() << "Data in application flash memory unchanged, no reason to send write for single value"; - return; - } - QLOG_TRACE() << "Updating flash locationid" << locationid << "with" << data.size() << "bytes at offset" << offset; - setLocalFlashBlock(locationid,getLocalFlashBlock(locationid).replace(offset,size,data)); - //emit updateRequired(locationid); - emit flashBlockUpdateRequest(locationid,offset,size,data); //don't emit a signal for flash updates, those are always manual. -} - -bool EmsData::verifyMemoryBlock(unsigned short locationid,QByteArray header,QByteArray payload) -{ - Q_UNUSED(header) - if (m_memoryMetaData->has2DMetaData(locationid)) - { - if ((unsigned int)payload.size() != m_memoryMetaData->get2DMetaData(locationid).size) - { - return false; - } - else - { - return true; - } - } - if (m_memoryMetaData->has3DMetaData(locationid)) - { - if ((unsigned int)payload.size() != m_memoryMetaData->get3DMetaData(locationid).size) - { - return false; - } - else - { - return true; - } - } - //If we get here, the table does not exist in meta data - return true; - -} - - -QList EmsData::getDuplicateTopLevelDeviceFlashLocations() -{ - if (!m_checkEmsDataInUse) - { - return QList(); - } - QList retval; - for (int i=0;idata() != getDeviceFlashBlock(m_duplicateFlashMemoryList[i]->locationid)) && !m_duplicateFlashMemoryList[i]->hasParent) - { - retval.append(m_duplicateFlashMemoryList[i]->locationid); - } - } - return retval; -} - -QList EmsData::getDuplicateTopLevelDeviceRamLocations() -{ - if (!m_checkEmsDataInUse) - { - return QList(); - } - QList retval; - for (int i=0;idata() != getDeviceRamBlock(m_duplicateRamMemoryList[i]->locationid)) && !m_duplicateRamMemoryList[i]->hasParent) - { - retval.append(m_duplicateRamMemoryList[i]->locationid); - } - } - return retval; -} -double EmsData::calcAxis(int val,QList > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=0;j > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=metadata.size()-1;j>=0;j--) - { - if (metadata[j].first == "add") - { - newval -= metadata[j].second; - } - else if (metadata[j].first == "sub") - { - newval += metadata[j].second; - } - else if (metadata[j].first == "mult") - { - newval /= metadata[j].second; - } - else if (metadata[j].first == "div") - { - newval *= metadata[j].second; - } - } - return (int)newval; -} -MemoryLocation* EmsData::getLocalRamBlockInfo(unsigned short locationid) -{ - for (int i=0;ilocationid == locationid) - { - return m_ramMemoryList[i]; - } - } - return 0; -} -MemoryLocation* EmsData::getLocalFlashBlockInfo(unsigned short locationid) -{ - for (int i=0;ilocationid == locationid) - { - return m_flashMemoryList[i]; - } - } - return 0; -} -void EmsData::markLocalFlashLocationDirty(unsigned short location,unsigned short offset,unsigned short size) -{ - MemoryLocation *flash = getLocalFlashBlockInfo(location); - if (flash) - { - if (size == 0) - { - size = flash->size; - } - for (int i=flash->flashAddress+offset;i<(flash->flashAddress+offset) + size;i++) - { - flash->setByteDirty(i); - } - } -} -void EmsData::markLocalFlashLocationClean(unsigned short locationid) -{ - MemoryLocation *flash = getLocalFlashBlockInfo(locationid); - if (flash) - { - for (int i=flash->flashAddress;iflashAddress+flash->size;i++) - { - flash->setByteClean(i); - } - } -} - -void EmsData::markLocalRamLocationDirty(unsigned short location,unsigned short offset,unsigned short size) -{ - MemoryLocation *ram= getLocalRamBlockInfo(location); - if (ram) - { - if (ram->isReadOnly) - { - //Don't mark read only as dirty, we don't care. - return; - } - if (size == 0) - { - size = ram->size; - } - for (int i=ram->ramAddress+offset;i<(ram->ramAddress+offset) + size;i++) - { - ram->setByteDirty(i); - } - } -} -void EmsData::markLocalRamLocationClean(unsigned short locationid) -{ - MemoryLocation *ram= getLocalRamBlockInfo(locationid); - if (ram) - { - for (int i=ram->ramAddress;iramAddress+ram->size;i++) - { - ram->setByteClean(i); - } - } -} -bool EmsData::isLocalRamDirty(unsigned short locationid) -{ - MemoryLocation *ram= getLocalRamBlockInfo(locationid); - if (ram) - { - return ram->isDirty(); - } - return false; -} - -bool EmsData::isLocalFlashDirty(unsigned short locationid) -{ - MemoryLocation *flash = getLocalFlashBlockInfo(locationid); - if (flash) - { - return flash->isDirty(); - } - return false; -} diff --git a/plugins/freeems/emsdata.h b/plugins/freeems/emsdata.h deleted file mode 100644 index 1a90134..0000000 --- a/plugins/freeems/emsdata.h +++ /dev/null @@ -1,162 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#ifndef EMSDATA_H -#define EMSDATA_H -#include -#include -#include - -#include "configblock.h" -#include "memorylocation.h" -#include "memorymetadata.h" -#include "memorylocationinfo.h" -#include "readonlyramblock.h" -#include "configdata.h" - -class EmsData : public QObject -{ - Q_OBJECT -public: - EmsData(); - bool hasLocalRamBlock(unsigned short id); - void setLocalRamBlock(unsigned short id,QByteArray data); - QByteArray getLocalRamBlock(unsigned short id); - void addLocalRamBlock(MemoryLocation *loc); - - bool hasDeviceRamBlock(unsigned short id); - void setDeviceRamBlock(unsigned short id,QByteArray data); - QByteArray getDeviceFlashBlock(unsigned short id); - void addDeviceFlashBlock(MemoryLocation *loc); - - bool hasLocalFlashBlock(unsigned short id); - void setLocalFlashBlock(unsigned short id,QByteArray data); - QByteArray getLocalFlashBlock(unsigned short id); - void addLocalFlashBlock(MemoryLocation *loc); - - bool hasDeviceFlashBlock(unsigned short id); - void setDeviceFlashBlock(unsigned short id,QByteArray data); - QByteArray getDeviceRamBlock(unsigned short id); - void addDeviceRamBlock(MemoryLocation *loc); - - QList getChildrenOfLocalRamLocation(unsigned short id); - unsigned short getParentOfLocalRamLocation(unsigned short id); - bool localRamHasParent(unsigned short id); - bool localRamHasChildren(unsigned short id); - - QList getChildrenOfLocalFlashLocation(unsigned short id); - unsigned short getParentOfLocalFlashLocation(unsigned short id); - bool localFlashHasParent(unsigned short id); - bool localFlashHasChildren(unsigned short id); - - QString serialize(unsigned short id,bool isram); - - void populateLocalRamAndFlash(); - void populateDeviceRamAndFlashParents(); - QList getTopLevelDeviceFlashLocations(); - QList getTopLevelDeviceRamLocations(); - - - QList getDuplicateTopLevelDeviceFlashLocations(); - QList getDuplicateTopLevelDeviceRamLocations(); - - void passLocationInfo(unsigned short locationid,MemoryLocationInfo info); - - void clearAllMemory(); - - void setMetaData(MemoryMetaData *data) { m_memoryMetaData = data; } - - void setInterrogation(bool inprogress) { m_interrogationInProgress = inprogress; } - - bool isReadOnlyRamBlock(unsigned short locationid) - { - for (int i=0;ilocationid == locationid) - { - if (m_deviceRamMemoryList[i]->isReadOnly) - { - return true; - } - else - { - return false; - } - } - } - return false; - } - QList getTopLevelUniqueLocationIdList(); - QList getUniqueLocationIdList(); - MemoryLocation* getLocalRamBlockInfo(unsigned short locationid); - MemoryLocation* getLocalFlashBlockInfo(unsigned short locationid); - - void markLocalFlashLocationDirty(unsigned short location,unsigned short offset,unsigned short size); - void markLocalFlashLocationClean(unsigned short locationid); - void markLocalRamLocationDirty(unsigned short location,unsigned short offset,unsigned short size); - void markLocalRamLocationClean(unsigned short locationid); - bool isLocalRamDirty(unsigned short locationid); - bool isLocalFlashDirty(unsigned short locationid); - QList > getDirtyFlashLocations() { return m_dirtyLocalFlashMemoryList; } - QList > getDirtyRamLocations() { return m_dirtyLocalRamMemoryList; } - void clearDirtyRamLocations() { m_dirtyLocalRamMemoryList.clear(); } - void clearDirtyFlashLocations() { m_dirtyLocalFlashMemoryList.clear(); } - - -private: - bool m_checkEmsDataInUse; - bool m_interrogationInProgress; - MemoryMetaData *m_memoryMetaData; - QMap > m_configBlockMap; - QMap m_readOnlyMetaDataMap; - QList m_ramMemoryList; - QList m_flashMemoryList; - QList m_deviceFlashMemoryList; - QList m_deviceRamMemoryList; - QList m_duplicateFlashMemoryList; - QList m_duplicateRamMemoryList; - QList m_tempMemoryList; - QList m_table3DMetaData; - QList m_table2DMetaData; - QList m_configMetaData; - QList m_readOnlyMetaData; - QMap m_errorMap; - QList > m_dirtyLocalFlashMemoryList; - QList > m_dirtyLocalRamMemoryList; - bool verifyMemoryBlock(unsigned short locationid,QByteArray header,QByteArray payload); - double calcAxis(int val,QList > metadata); - int backConvertAxis(double val,QList > metadata); - -signals: - void updateRequired(unsigned short locationid); - void ramBlockUpdateRequest(unsigned short locationid,unsigned short offset,unsigned short size,QByteArray data); - void flashBlockUpdateRequest(unsigned short locationid,unsigned short offset,unsigned short size,QByteArray data); - void configRecieved(ConfigBlock,QVariant); - void localFlashLocationDirty(unsigned short locationid); - void localRamLocationDirty(unsigned short locationid); -public slots: - void ramBlockUpdate(unsigned short locationid, QByteArray header, QByteArray payload); - void flashBlockUpdate(unsigned short locationid, QByteArray header, QByteArray payload); - void ramBytesLocalUpdate(unsigned short locationid,unsigned short offset,unsigned short size,QByteArray data); - void flashBytesLocalUpdate(unsigned short locationid,unsigned short offset,unsigned short size,QByteArray data); -}; - -#endif // EMSDATA_H diff --git a/plugins/freeems/feconfigdata.cpp b/plugins/freeems/feconfigdata.cpp deleted file mode 100644 index 9f2cdcb..0000000 --- a/plugins/freeems/feconfigdata.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include "feconfigdata.h" -#include "QsLog.h" -FEConfigData::FEConfigData() : ConfigData() -{ - m_value = QVariant((double)0); -} -FEConfigData::FEConfigData(QString name,QString type, QString override,unsigned short locationid, unsigned short size,unsigned short elementsize,unsigned short offset, QList > calc) : ConfigData() -{ - m_name = name; - m_typeString = type; - m_sizeOverride = override; - m_locationId = locationid; - m_size = size; - m_elementSize = elementsize; - m_offset = offset; - m_calc = calc; - //Size of element is the number of bytes per value - //size is the number of values (1 for value, 1+ for array); - -} -QVariant FEConfigData::value() -{ - //QLOG_DEBUG() << "value requested for" << m_name << ":" << m_value; - return m_value; -} -void FEConfigData::setValue(QVariant value) -{ - if (m_typeString == "value") - { - double dval = value.toDouble(); - unsigned short usval = reverseCalcAxis(dval,m_calc); - QByteArray data; - for (int i=0;i> (((m_elementSize-1)-i)*8)); - } - emit saveSingleDataToFlash(m_locationId,m_offset,m_elementSize,data); - } - else if (m_typeString == "array") - { - //It will be a list of doubles? - QVariantList list = value.toList(); - QByteArray data; - for (int i=0;i> (((m_elementSize-1)-j)*8)); - } - } - if (data.size() < m_size) - { - //We're only editing the first part of the array. - } - emit saveSingleDataToFlash(m_locationId,m_offset,data.size(),data); - } -} - -void FEConfigData::setData(QByteArray data) -{ - if (m_typeString == "value") - { - if (data.size() >= (m_offset + m_elementSize)) - { - QByteArray newdata = data.mid(m_offset,m_elementSize); - unsigned long val = 0; - for (int i=0;i > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=0;j > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=metadata.size()-1;j>=0;j--) - { - if (metadata[j].first == "add") - { - newval -= metadata[j].second; - } - else if (metadata[j].first == "sub") - { - newval += metadata[j].second; - } - else if (metadata[j].first == "mult") - { - newval /= metadata[j].second; - } - else if (metadata[j].first == "div") - { - newval *= metadata[j].second; - } - } - return (unsigned short)newval; -} diff --git a/plugins/freeems/feconfigdata.h b/plugins/freeems/feconfigdata.h deleted file mode 100644 index e8c20f2..0000000 --- a/plugins/freeems/feconfigdata.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef FECONFIGDATA_H -#define FECONFIGDATA_H - -#include "configdata.h" -#include -#include -#include - -class FEConfigData : public ConfigData -{ - Q_OBJECT -public: - FEConfigData(); - FEConfigData(QString name,QString type, QString override,unsigned short locationid, unsigned short size,unsigned short elementsize,unsigned short offset, QList > calc); - - void setName(QString name) { m_name = name; } - void setType(QString type) { m_typeString = type; } - void setSizeOverride(QString override) { m_sizeOverride = override; } - void setSizeOverrideMult(double mult) { m_sizeOverrideMult = mult; } - void setLocationId(unsigned short locationid) { m_locationId = locationid; } - void setSize(unsigned short size) { m_size = size; } - void setElementSize(unsigned short size) { m_elementSize = size; } - void setOffset(unsigned short offset) { m_offset = offset; } - void setCalc(QList > calc) { m_calc = calc; } - QString name() { return m_name; } - QString typeString() { return m_typeString; } - Type type() { return VALUE; } - QString sizeOverride() { return m_sizeOverride; } - double sizeOverrideMult() { return m_sizeOverrideMult; } - unsigned short locationId() { return m_locationId; } - unsigned short offset() { return m_offset; } - unsigned short size() { return m_size; } - unsigned short elementSize() { return m_elementSize; } - QList > calc() { return m_calc; } - int elements() { return m_size / m_elementSize; } - QVariant value(); - void setData(QByteArray data); - void setValue(QVariant value); - double calcAxis(unsigned short val,QList > metadata); - unsigned short reverseCalcAxis(double val,QList > metadata); - QStringList getEnumValues(); - void setEnumValues(QStringList values); - void setEnumBits(int min,int max); - int getMinEnumBit(); - int getMaxEnumBit(); - void saveToFlash(); -private: - QVariant m_value; - QString m_name; - QString m_typeString; - QString m_sizeOverride; - double m_sizeOverrideMult; - unsigned short m_locationId; - unsigned short m_size; - unsigned short m_elementSize; - unsigned short m_offset; - QList > m_calc; -signals: - void update(); - void saveSingleDataToFlash(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - void saveSingleDataToRam(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - -}; - -#endif // FECONFIGDATA_H diff --git a/plugins/freeems/fedatapacketdecoder.cpp b/plugins/freeems/fedatapacketdecoder.cpp deleted file mode 100644 index 2e1c4fe..0000000 --- a/plugins/freeems/fedatapacketdecoder.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "fedatapacketdecoder.h" -#include -#include -#include -#include "QsLog.h" - -FEDataPacketDecoder::FEDataPacketDecoder() : DataPacketDecoder() -{ - loadDataFieldsFromValues(); -} - -void FEDataPacketDecoder::decodePayloadPacket(QByteArray header,QByteArray payload) -{ - Q_UNUSED(header) - decodePayload(payload); -} - -void FEDataPacketDecoder::decodePayload(QByteArray payload) -{ - QVariantMap m_valueMap; - for (int i=0;i newval) - { - QLOG_WARN() << "B: Packets lost! At least:" << (255 - m_currentEcuClock) + newval << "packets"; - } - else - { - QLOG_WARN() << "C: Packets lost! At least:" << newval - m_currentEcuClock << "packets"; - } - - } - } - m_currentEcuClock = newval; - } - } - emit payloadDecoded(m_valueMap); -} -int FEDataPacketDecoder::fieldSize() -{ - return m_dataFieldList.size(); -} - -/*DataField FEDataPacketDecoder::getField(int num) -{ - if (num >=0 && num < m_dataFieldList.size()) - { - return m_dataFieldList[num]; - } - return DataField(); -}*/ -QString FEDataPacketDecoder::getFieldName(int num) -{ - if (num >=0 && num < m_dataFieldList.size()) - { - return m_dataFieldList[num].name(); - } - return ""; -} - -QString FEDataPacketDecoder::getFieldDescription(int num) -{ - if (num >=0 && num < m_dataFieldList.size()) - { - return m_dataFieldList[num].description(); - } - return ""; -} - -void FEDataPacketDecoder::loadDataFieldsFromValues() -{ - // CoreVars - m_dataFieldList.append(DataField("IAT","Intake Air Temperature",0,2,100,-273.15)); - m_dataFieldList.append(DataField("CHT","Coolant/Head Temperature",2,2,100,-273.15)); - m_dataFieldList.append(DataField("TPS","Throttle Position Sensor",4,2,640.0)); - m_dataFieldList.append(DataField("EGO","Exhaust Gas Oxygen",6,2,32768.0)); - m_dataFieldList.append(DataField("MAP","Manifold Air Pressure",8,2,100.0)); - m_dataFieldList.append(DataField("AAP","Ambient Atmosphere Pressure",10,2,100.0)); - m_dataFieldList.append(DataField("BRV","Battery Reference Voltage",12,2,1000.0)); - m_dataFieldList.append(DataField("MAT","Manifold Air Temperature",14,2,100.0,-273.15)); - m_dataFieldList.append(DataField("EGO2","Exhaust Gas Oxygen 2",16,2,32768.0)); - m_dataFieldList.append(DataField("IAP","Intercooler Absolute Pressure",18,2,100.0)); - m_dataFieldList.append(DataField("MAF","Mass Air Flow",20,2,204.8)); - m_dataFieldList.append(DataField("DMAP","Delta Map",22,2,1.0)); - m_dataFieldList.append(DataField("DTPS","Delta TPS",24,2,1.0)); - m_dataFieldList.append(DataField("RPM","Engine Speed",26,2,2.0)); - m_dataFieldList.append(DataField("DRPM","Delta RPM",28,2,1.0)); - m_dataFieldList.append(DataField("DDRPM","Delta Delta RPM",30,2,1.0)); - - // DerivedVars - m_dataFieldList.append(DataField("LoadMain","Configurable Unit of Load",32,2,512.0)); - m_dataFieldList.append(DataField("VEMain","Volumentric Efficiency",34,2,512.0)); - m_dataFieldList.append(DataField("Lambda","Integral Lambda",36,2,32768.0)); - m_dataFieldList.append(DataField("AirFlow","AirFlow for Alpha-N",38,2,640.0)); - m_dataFieldList.append(DataField("densityAndFuel","raw Intermediate",40,2,1.0)); - m_dataFieldList.append(DataField("BasePW","Raw PW Before corrections",42,2,1250)); - m_dataFieldList.append(DataField("ETE","Engine Temp Enrichment Percentage",44,2,16384.0/100.0)); - m_dataFieldList.append(DataField("TFCTotal","Total Transient Fuel Corrections",46,2,1250)); // Needs to be signed short / int16 - m_dataFieldList.append(DataField("EffectivePW","Actual PW of fuel delivery",48,2,1250.0)); - m_dataFieldList.append(DataField("IDT","PW duration before fuel flow begins",50,2,1250.0)); - m_dataFieldList.append(DataField("RefPW","Reference electrical PW",52,2,1250.0)); - m_dataFieldList.append(DataField("Advance","Ignition advance",54,2,50.0)); - m_dataFieldList.append(DataField("Dwell","Dwell period",56,2,1250.0)); - - // KeyUserDebug - m_dataFieldList.append(DataField("tempClock","Once per datalog message",58,1,1.0)); - m_dataFieldList.append(DataField("spareChar","Unused at this time",59,1,1.0)); - - // TODO bits: - m_dataFieldList.append(DataField("coreStatusA","Duplicate",60,1,1.0,0,true)); // Needs flags - m_dataFieldList.append(DataField("decoderFlags","Various decoder state flags",61,1,1.0,0,true)); // Needs flags - - // Flaggable flags - m_dataFieldList.append(DataField("callsToUISRs","to ensure we aren't accidentally triggering unused ISRs.",62,2,1.0,0,0,0,true,0)); - m_dataFieldList.append(DataField("lowVoltageConditions","low voltage conditions.",62,2,1.0,0,0,0,true,1)); - m_dataFieldList.append(DataField("decoderSyncLosses","Number of times cam, crank or combustion sync is lost.",62,2,1.0,0,0,0,true,2)); - m_dataFieldList.append(DataField("spare","spare",62,2,1.0,0,0,0,true,3)); - m_dataFieldList.append(DataField("decoderSyncStateClears","Sync loss called when not synced yet, thus discarding data and preventing sync.",62,2,1.0,0,0,0,true,4)); - m_dataFieldList.append(DataField("serialNoiseErrors","Incremented when noise is detected",62,2,1.0,0,0,0,true,5)); - m_dataFieldList.append(DataField("serialFramingErrors","Incremented when a framing error occurs",62,2,1.0,0,0,0,true,6)); - m_dataFieldList.append(DataField("serialParityErrors","Incremented when a parity error occurs",62,2,1.0,0,0,0,true,7)); - m_dataFieldList.append(DataField("serialOverrunErrors","Incremented when overrun occurs (count available in KeyUserDebug below",62,2,1.0,0,0,0,true,8)); - m_dataFieldList.append(DataField("serialEscapePairMismatches","Incremented when an escape is found but not followed by an escapee",62,2,1.0,0,0,0,true,9)); - m_dataFieldList.append(DataField("serialStartsInsideAPacket","Incremented when a start byte is found inside a packet",62,2,1.0,0,0,0,true,10)); - m_dataFieldList.append(DataField("serialPacketsOverLength","Incremented when the buffer fills up before the end",62,2,1.0,0,0,0,true,11)); - m_dataFieldList.append(DataField("serialChecksumMismatches","Incremented when calculated checksum did not match the received one",62,2,1.0,0,0,0,true,12)); - m_dataFieldList.append(DataField("serialPacketsUnderLength","Incremented when a packet is found that is too short",62,2,1.0,0,0,0,true,13)); - m_dataFieldList.append(DataField("commsDebugMessagesNotSent","Incremented when a debug message can't be sent due to the TX buffer",62,2,1.0,0,0,0,true,14)); - m_dataFieldList.append(DataField("commsErrorMessagesNotSent","Incremented when an error message can't be sent due to the TX buffer",62,2,1.0,0,0,0,true,15)); - - m_dataFieldList.append(DataField("currentEvent","Which input event was last",64,1,1.0)); - m_dataFieldList.append(DataField("syncLostWithThisID","UID for reason beind loss of sync",65,1,1.0)); - m_dataFieldList.append(DataField("syncLostOnThisEvent","Where in the input pattern sync was lost",66,1,1.0)); - m_dataFieldList.append(DataField("syncCaughtOnThisevent","Where in the input pattern sync was recovered",67,1,1.0)); - m_dataFieldList.append(DataField("syncResetCalls","Sum of losses, corrections, and state clears",68,1,1.0)); - m_dataFieldList.append(DataField("primaryTeethSeen","",69,1,1.0)); - m_dataFieldList.append(DataField("secondaryTeethSeen","",70,1,1.0)); - m_dataFieldList.append(DataField("serialOverrunErrorsCount","",71,1,1.0)); //These three have "Count" added to the end of the name to avoid conflict with flags above. - m_dataFieldList.append(DataField("serialHardwareErrorsCount","",72,1,1.0)); - m_dataFieldList.append(DataField("serialAndCommsCodeErrorsCount","",73,1,1.0)); - m_dataFieldList.append(DataField("inputEventTimeTolerance","",74,2,1.0)); - m_dataFieldList.append(DataField("zsp10","",76,2,1.0)); - m_dataFieldList.append(DataField("zsp9","",78,2,1.0)); - m_dataFieldList.append(DataField("zsp8","",80,2,1.0)); - m_dataFieldList.append(DataField("zsp7","",82,2,1.0)); - m_dataFieldList.append(DataField("zsp6","",84,2,1.0)); - m_dataFieldList.append(DataField("zsp5","",86,2,1.0)); - m_dataFieldList.append(DataField("zsp4","",88,2,1.0)); - m_dataFieldList.append(DataField("zsp3","",90,2,1.0)); - m_dataFieldList.append(DataField("clockInMilliSeconds","Clock in milliseconds",92,2,1.0)); - m_dataFieldList.append(DataField("clock8thMssInMillis","Clock in 8th milliseconds",94,2,8.0)); - m_dataFieldList.append(DataField("ignitionLimiterFlags","",96,1,1.0)); // Needs flags - m_dataFieldList.append(DataField("injectionLimiterFlags","",97,1,1.0)); // Needs flags -} diff --git a/plugins/freeems/fedatapacketdecoder.h b/plugins/freeems/fedatapacketdecoder.h deleted file mode 100644 index 2c3d9bc..0000000 --- a/plugins/freeems/fedatapacketdecoder.h +++ /dev/null @@ -1,51 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#ifndef FEDATAPACKETDECODER_H -#define FEDATAPACKETDECODER_H - -#include -#include -#include -#include "datafield.h" -#include "datapacketdecoder.h" -class FEDataPacketDecoder : public DataPacketDecoder -{ - Q_OBJECT -public: - FEDataPacketDecoder(); - int fieldSize(); - //DataField getField(int num); - QString getFieldName(int num); - QString getFieldDescription(int num); -private: - void loadDataFieldsFromValues(); - QList m_dataFieldList; - short m_currentEcuClock; -signals: - void payloadDecoded(QVariantMap data); - void resetDetected(int missedPackets); -public slots: - void decodePayload(QByteArray payload); - void decodePayloadPacket(QByteArray,QByteArray); -}; - -#endif // FEDATAPACKETDECODER_H diff --git a/plugins/freeems/fememorymetadata.cpp b/plugins/freeems/fememorymetadata.cpp deleted file mode 100644 index 8bba39b..0000000 --- a/plugins/freeems/fememorymetadata.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "fememorymetadata.h" -#include -#include -#include -#include -#include -#include "QsLog.h" - -FEMemoryMetaData::FEMemoryMetaData() -{ -} - -bool FEMemoryMetaData::parseMetaData(QString json) -{ - QJson::Parser parser; - QVariant top = parser.parse(json.toStdString().c_str()); - if (!top.isValid()) - { - QString errormsg = QString("Error parsing JSON from config file on line number: ") + QString::number(parser.errorLine()) + " error text: " + parser.errorString(); - //QLOG_FATAL() << "Error parsing JSON"; - //QLOG_FATAL() << "Line number:" << parser.errorLine() << "error text:" << parser.errorString(); - //QLOG_FATAL() << "Start Json"; - //QLOG_FATAL() << "Json:" << json; - //QLOG_FATAL() << "End Json"; - return false; - } - QVariantMap topmap = top.toMap(); - QVariantMap errormap = topmap["errormap"].toMap(); - QVariantMap::iterator i = errormap.begin(); - while (i != errormap.end()) - { - bool ok = false; - m_errorMap[i.value().toString().mid(2).toInt(&ok,16)] = i.key(); - i++; - } - - QVariantMap ramvars = topmap["ramvars"].toMap(); - i = ramvars.begin(); - while (i != ramvars.end()) - { - bool ok = false; - unsigned short locid = i.key().mid(2).toInt(&ok,16); - m_readOnlyMetaDataMap[locid] = ReadOnlyRamBlock(); - QVariantMap locidlist = i.value().toMap(); - QString title = locidlist["title"].toString(); - m_readOnlyMetaDataMap[locid].title = title; - QVariantList locidmap = locidlist["vars"].toList(); - int offset = 0; - for (int j=0;j > xcalclist; - QList > ycalclist; - QList > zcalclist; - for (int j=0;j(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); - } - for (int j=0;j(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); - } - for (int j=0;j(zcalc[j].toMap()["type"].toString(),zcalc[j].toMap()["value"].toDouble())); - } - - bool ok = false; - meta.locationId = id.mid(2).toInt(&ok,16); - meta.tableTitle = i.key(); - meta.xAxisCalc = xcalclist; - meta.xAxisTitle = xtitle; - meta.xDp = xdp.toInt(); - meta.yAxisCalc = ycalclist; - meta.yAxisTitle = ytitle; - meta.yDp = ydp.toInt(); - meta.zAxisCalc = zcalclist; - meta.zAxisTitle = ztitle; - meta.zDp = zdp.toInt(); - meta.size = size; - meta.valid = true; - meta.xHighlight = xhighlight; - meta.yHighlight = yhighlight; - for (int i=0;i > xcalclist; - QList > ycalclist; - - for (int j=0;j(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); - } - for (int j=0;j(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); - } - bool ok = false; - meta.locationId = id.mid(2).toInt(&ok,16); - meta.tableTitle = i.key(); - meta.xAxisCalc = xcalclist; - meta.xAxisTitle = xtitle; - meta.xDp = xdp.toInt(); - meta.yAxisCalc = ycalclist; - meta.yAxisTitle = ytitle; - meta.yDp = ydp.toInt(); - meta.size = size; - meta.valid = true; - meta.xHighlight = xhighlight; - for (int i=0;i > FEMemoryMetaData::configMetaData() -{ - return m_configMetaData; -} - -const QList FEMemoryMetaData::getConfigMetaData(QString name) -{ - if (m_configMetaData.contains(name)) - { - return m_configMetaData[name]; - } - else - { - return QList(); - } -} diff --git a/plugins/freeems/fememorymetadata.h b/plugins/freeems/fememorymetadata.h deleted file mode 100644 index 6447095..0000000 --- a/plugins/freeems/fememorymetadata.h +++ /dev/null @@ -1,81 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#ifndef FEMEMORYMETADATA_H -#define FEMEMORYMETADATA_H -#include -#include -#include "memorymetadata.h" -#include "table2dmetadata.h" -#include "table3dmetadata.h" -#include "readonlyramdata.h" -#include "lookupmetadata.h" -#include "readonlyramblock.h" -#include "menusetup.h" - -class FEMemoryMetaData : public MemoryMetaData -{ -public: - FEMemoryMetaData(); - bool loadMetaDataFromFile(QStringList searchpaths); - const QMap errorMap() { return m_errorMap; } - void setMenuMetaData(MenuSetup menu) { m_menuMetaData = menu; } - void passConfigData(QMap > block) { m_configMetaData = block; } - - - bool has2DMetaData(unsigned short locationid); - const QList table2DMetaData() { return m_table2DMetaData; } - const Table2DMetaData get2DMetaData(unsigned short locationid); - - bool has3DMetaData(unsigned short locationid); - const QList table3DMetaData() { return m_table3DMetaData; } - const Table3DMetaData get3DMetaData(unsigned short locationid); - - bool hasRORMetaData(unsigned short locationid); - const ReadOnlyRamData getRORMetaData(unsigned short locationid); - - bool hasLookupMetaData(unsigned short locationid); - const LookupMetaData getLookupMetaData(unsigned short locationid); - - bool hasConfigMetaData(QString name); - const QMap > configMetaData(); - const QList getConfigMetaData(QString name); - - const MenuSetup menuMetaData() { return m_menuMetaData; } - - const QString getErrorString(unsigned short code); - -private: - MenuSetup m_menuMetaData; - QMap > m_configMetaData; - bool parseMetaData(QString json); - QMap m_errorMap; - QMap m_lookupMetaData; - QList m_readOnlyMetaData; - QMap m_readOnlyMetaDataMap; - QList m_table3DMetaData; - QList m_table2DMetaData; - -}; - -#endif // FEMEMORYMETADATA_H - - diff --git a/plugins/freeems/ferawdata.cpp b/plugins/freeems/ferawdata.cpp deleted file mode 100644 index 2656f2f..0000000 --- a/plugins/freeems/ferawdata.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "ferawdata.h" - -FERawData::FERawData() -{ -} -void FERawData::setData(unsigned short locationid,bool isflashonly,QByteArray payload) -{ - m_isFlashOnly = isflashonly; - m_data = payload; - m_locationId = locationid; - emit update(); -} -void FERawData::updateValue(QByteArray data) -{ - m_data = data; - if (m_isFlashOnly) - { - emit saveSingleDataToFlash(m_locationId,0,m_data.size(),m_data); - } - else - { - emit saveSingleDataToRam(m_locationId,0,m_data.size(),m_data); - } - emit update(); -} - -QByteArray FERawData::data() -{ - return m_data; -} - -unsigned short FERawData::locationId() -{ - return m_locationId; -} - -bool FERawData::isFlashOnly() -{ - return m_isFlashOnly; -} -void FERawData::updateFromFlash() -{ - if (m_isFlashOnly) - { - emit requestBlockFromFlash(m_locationId,0,0); - } -} - -void FERawData::updateFromRam() -{ - if (!m_isFlashOnly) - { - emit requestBlockFromRam(m_locationId,0,0); - } -} - -void FERawData::saveRamToFlash() -{ - -} diff --git a/plugins/freeems/ferawdata.h b/plugins/freeems/ferawdata.h deleted file mode 100644 index fc3323f..0000000 --- a/plugins/freeems/ferawdata.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef FERAWDATA_H -#define FERAWDATA_H - -#include "rawdata.h" - -class FERawData : public RawData -{ - Q_OBJECT -public: - FERawData(); - void setData(unsigned short locationid,bool isflashonly,QByteArray payload); - QByteArray data(); - unsigned short locationId(); - bool isFlashOnly(); - void updateValue(QByteArray data); -private: - QByteArray m_data; - bool m_isFlashOnly; - unsigned short m_locationId; -signals: - void update(); - void saveSingleDataToFlash(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - void saveSingleDataToRam(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - void requestBlockFromRam(unsigned short locationid,unsigned short offset,unsigned short size); - void requestBlockFromFlash(unsigned short locationid,unsigned short offset,unsigned short size); -public slots: - void updateFromFlash(); //Trigger a flash update, if table is in ram, it copies from flash to ram, and sends a request to the ECU - void updateFromRam(); //Trigger a ram udpate. Requests table from the ECU from ram - void saveRamToFlash(); -}; - -#endif // FERAWDATA_H diff --git a/plugins/freeems/fetable2ddata.cpp b/plugins/freeems/fetable2ddata.cpp deleted file mode 100644 index 45c5ca8..0000000 --- a/plugins/freeems/fetable2ddata.cpp +++ /dev/null @@ -1,355 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "fetable2ddata.h" -#include -FETable2DData::FETable2DData() : Table2DData() -{ - m_writesEnabled = true; - m_acccessMutex = new QMutex(); -} -void FETable2DData::writeWholeLocation(bool ram) -{ - if (ram) - { - emit saveSingleDataToRam(m_locationId,0,data().size(),data()); - } - else - { - emit saveSingleDataToFlash(m_locationId,0,data().size(),data()); - } -} -void FETable2DData::setWritesEnabled(bool enabled) -{ - m_writesEnabled = enabled; -} -void FETable2DData::reCalcAxisData() -{ - //QMutexLocker locker(m_acccessMutex); -/* m_axis.append(xdouble); - m_values.append(ydouble);*/ - m_minActualXAxis = calcAxis(65535,m_metaData.xAxisCalc); - m_minActualYAxis = calcAxis(65535,m_metaData.yAxisCalc); - m_maxActualXAxis = calcAxis(-65535,m_metaData.xAxisCalc); - m_maxActualYAxis = calcAxis(-65535,m_metaData.yAxisCalc); - for (int i=0;i m_maxActualXAxis) - { - m_maxActualXAxis = m_axis[i]; - } - if (m_axis[i] < m_minActualXAxis) - { - m_minActualXAxis = m_axis[i]; - } - - } - for (int i=0;i m_maxActualYAxis) - { - m_maxActualYAxis = m_values[i]; - } - if (m_values[i] < m_minActualYAxis) - { - m_minActualYAxis = m_values[i]; - } - } -} - -void FETable2DData::setData(unsigned short locationid, bool isflashonly,QByteArray payload,Table2DMetaData metadata,bool signedData) -{ - m_acccessMutex->lock(); - m_dataSize = payload.size(); - m_isSignedData = signedData; - m_isFlashOnly = isflashonly; - m_metaData = metadata; - m_maxCalcedXAxis = calcAxis(65535,metadata.xAxisCalc); - m_maxCalcedYAxis = calcAxis(65535,metadata.yAxisCalc); - m_minCalcedXAxis = calcAxis(-65535,metadata.xAxisCalc); - m_minCalcedYAxis = calcAxis(-65535,metadata.yAxisCalc); - - //Reverse the min and max, so we can figure them out based on real data - m_minActualXAxis = calcAxis(65535,metadata.xAxisCalc); - m_minActualYAxis = calcAxis(65535,metadata.yAxisCalc); - m_maxActualXAxis = calcAxis(-65535,metadata.xAxisCalc); - m_maxActualYAxis = calcAxis(-65535,metadata.yAxisCalc); - m_locationId = locationid; - m_axis.clear(); - m_values.clear(); - - for (int i=0;i m_maxActualXAxis) - { - m_maxActualXAxis = xdouble; - } - if (xdouble < m_minActualXAxis) - { - m_minActualXAxis = xdouble; - } - - if (ydouble > m_maxActualYAxis) - { - m_maxActualYAxis = ydouble; - } - if (ydouble < m_minActualYAxis) - { - m_minActualYAxis = ydouble; - } - - m_axis.append(xdouble); - m_values.append(ydouble); - } - m_acccessMutex->unlock(); - emit update(); -} -double FETable2DData::maxActualXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxActualXAxis; -} - -double FETable2DData::maxActualYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxActualYAxis; -} - -double FETable2DData::minActualXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minActualXAxis; -} - -double FETable2DData::minActualYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minActualYAxis; -} -double FETable2DData::maxCalcedXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxCalcedXAxis; -} - -double FETable2DData::maxCalcedYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxCalcedYAxis; -} - -double FETable2DData::minCalcedXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minCalcedXAxis; -} - -double FETable2DData::minCalcedYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minCalcedYAxis; -} - -QList FETable2DData::axis() -{ - QMutexLocker locker(m_acccessMutex); - return m_axis; -} - -QList FETable2DData::values() -{ - QMutexLocker locker(m_acccessMutex); - return m_values; -} -int FETable2DData::columns() -{ - QMutexLocker locker(m_acccessMutex); - return m_axis.size(); -} - -int FETable2DData::rows() -{ - QMutexLocker locker(m_acccessMutex); - return 2; -} - -void FETable2DData::setCell(int row, int column,double newval) -{ - QMutexLocker locker(m_acccessMutex); - //New value has been accepted. Let's write it. - //offset = column + (row * 32), size == 2 - //QLOG_DEBUG() << "Update:" << row << column << newval; - short val = 0; - if (row == 0) - { - val = backConvertAxis(newval,m_metaData.xAxisCalc); - m_axis.replace(column,newval); - } - else if (row == 1) - { - - val = backConvertAxis(newval,m_metaData.yAxisCalc); - m_values.replace(column,newval); - } - /* if (signedData) - { - xdouble = calcAxis((short)x,metadata.xAxisCalc); - ydouble = calcAxis((short)y,metadata.yAxisCalc); - } - else - { - xdouble = calcAxis(x,metadata.xAxisCalc); - ydouble = calcAxis(y,metadata.yAxisCalc); - } -*/ - QByteArray data; - if (m_isSignedData) - { - data.append((char)((val >> 8) & 0xFF)); - data.append((char)(val & 0xFF)); - } - else - { - data.append((char)((((unsigned short)val) >> 8) & 0xFF)); - data.append((char)(((unsigned short)val) & 0xFF)); - } - reCalcAxisData(); - if (!m_isFlashOnly) - { - if (m_writesEnabled) - { - if (m_metaData.valid) - { - emit saveSingleDataToRam(m_locationId,(column*2)+(row * (m_metaData.size / 2.0)),2,data); - } - else - { - emit saveSingleDataToRam(m_locationId,(column*2)+(row * (m_dataSize / 2.0)),2,data); - } - } - } -} - -QByteArray FETable2DData::data() -{ - QMutexLocker locker(m_acccessMutex); - QByteArray data; - for (int i=0;i> 8) & 0xFF)); - data.append((char)(val & 0xFF)); - } - for (int i=0;i> 8) & 0xFF)); - data.append((char)(val & 0xFF)); - } - return data; -} -double FETable2DData::calcAxis(int val,QList > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=0;j > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=metadata.size()-1;j>=0;j--) - { - if (metadata[j].first == "add") - { - newval -= metadata[j].second; - } - else if (metadata[j].first == "sub") - { - newval += metadata[j].second; - } - else if (metadata[j].first == "mult") - { - newval /= metadata[j].second; - } - else if (metadata[j].first == "div") - { - newval *= metadata[j].second; - } - } - return (unsigned short)newval; -} -void FETable2DData::updateFromFlash() -{ - //emit requestBlockFromFlash(m_locationId,0,0); - emit requestRamUpdateFromFlash(m_locationId); -} - -void FETable2DData::updateFromRam() -{ - //emit requestRamUpdateFromFlash(m_locationId); - emit requestBlockFromRam(m_locationId,0,0); -} -void FETable2DData::saveRamToFlash() -{ - emit requestFlashUpdateFromRam(m_locationId); -} diff --git a/plugins/freeems/fetable2ddata.h b/plugins/freeems/fetable2ddata.h deleted file mode 100644 index f8e08af..0000000 --- a/plugins/freeems/fetable2ddata.h +++ /dev/null @@ -1,97 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#ifndef FETABLE2DDATA_H -#define FETABLE2DDATA_H -#include -#include -#include -#include -#include - -#include "table2ddata.h" -#include "table2dmetadata.h" - -class FETable2DData : public Table2DData -{ - Q_OBJECT -public: - FETable2DData(); - void setData(unsigned short locationid,bool isflashonly, QByteArray payload,Table2DMetaData metadata,bool signedData); - QByteArray data(); - double maxActualXAxis(); - double maxActualYAxis(); - double minActualXAxis(); - double minActualYAxis(); - double maxCalcedXAxis(); - double maxCalcedYAxis(); - double minCalcedXAxis(); - double minCalcedYAxis(); - QString axisLabel() { return ""; } - QString valueLabel() { return ""; } - - QList axis(); - QList values(); - int columns(); - int rows(); - void setCell(int row, int column,double newval); - void setWritesEnabled(bool enabled); - void writeWholeLocation(bool ram); - bool isRam() { return !m_isFlashOnly; } - double calcAxis(int val,QList > metadata); - int backConvertAxis(double val,QList > metadata); -private: - QMutex *m_acccessMutex; - unsigned short m_dataSize; - bool m_isSignedData; - bool m_isFlashOnly; - bool m_writesEnabled; - double m_maxActualXAxis; - double m_maxActualYAxis; - double m_minActualXAxis; - double m_minActualYAxis; - double m_maxCalcedXAxis; - double m_maxCalcedYAxis; - double m_minCalcedXAxis; - double m_minCalcedYAxis; - - Table2DMetaData m_metaData; - unsigned short m_locationId; - QList m_axis; - QList m_values; - QString m_axisLabel; - QString m_valuesLabel; - void reCalcAxisData(); -signals: - void saveSingleDataToFlash(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - void saveSingleDataToRam(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - void requestBlockFromRam(unsigned short locationid,unsigned short offset,unsigned short size); - void requestBlockFromFlash(unsigned short locationid,unsigned short offset,unsigned short size); - void update(); - void requestRamUpdateFromFlash(unsigned short locationid); - void requestFlashUpdateFromRam(unsigned short locationid); -public slots: - void updateFromFlash(); //Trigger a flash update, if table is in ram, it copies from flash to ram, and sends a request to the ECU - void updateFromRam(); //Trigger a ram udpate. Requests table from the ECU from ram - void saveRamToFlash(); -}; - -#endif // FETABLE2DDATA_H diff --git a/plugins/freeems/fetable3ddata.cpp b/plugins/freeems/fetable3ddata.cpp deleted file mode 100644 index 27bdc1a..0000000 --- a/plugins/freeems/fetable3ddata.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "fetable3ddata.h" -#include "QsLog.h" - -FETable3DData::FETable3DData() : Table3DData() -{ - m_writesEnabled = true; - m_acccessMutex = new QMutex(); -} -void FETable3DData::setData(unsigned short locationid,bool isflashonly, QByteArray data) -{ - m_acccessMutex->lock(); - Q_UNUSED(locationid) - m_isFlashOnly = isflashonly; - m_xAxis.clear(); - m_yAxis.clear(); - m_values.clear(); - unsigned short xaxissize = (((unsigned char)data[0]) << 8) + (unsigned char)data[1]; - unsigned short yaxissize = (((unsigned char)data[2]) << 8) + (unsigned char)data[3]; - QLOG_DEBUG() << "XAxis:" << xaxissize; - QLOG_DEBUG() << "YAxis:" << yaxissize; - - - m_maxCalcedXAxis = calcAxis(65535,m_metaData.xAxisCalc); - m_maxCalcedYAxis = calcAxis(65535,m_metaData.yAxisCalc); - m_maxCalcedValue = calcAxis(65535,m_metaData.zAxisCalc); - - m_minCalcedXAxis = calcAxis(0,m_metaData.xAxisCalc); - m_minCalcedYAxis = calcAxis(0,m_metaData.yAxisCalc); - m_minCalcedValue = calcAxis(0,m_metaData.zAxisCalc); - - for (int i=0;i currrow; - for (int x=0;xunlock(); - emit update(); -} - -void FETable3DData::setData(unsigned short locationid,bool isflashonly,QByteArray data,Table3DMetaData metadata) -{ - m_locationId = locationid; - m_metaData = metadata; - m_isFlashOnly = isflashonly; - setData(locationid,isflashonly,data); -} -double FETable3DData::maxCalcedXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxCalcedXAxis; -} - -double FETable3DData::maxCalcedYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxCalcedYAxis; -} - -double FETable3DData::maxCalcedValue() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxCalcedValue; -} -double FETable3DData::minCalcedXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minCalcedXAxis; -} - -double FETable3DData::minCalcedYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minCalcedYAxis; -} - -double FETable3DData::minCalcedValue() -{ - QMutexLocker locker(m_acccessMutex); - return m_minCalcedValue; -} - - -double FETable3DData::maxActualXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxActualXAxis; -} - -double FETable3DData::maxActualYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxActualYAxis; -} - -double FETable3DData::maxActualValue() -{ - QMutexLocker locker(m_acccessMutex); - return m_maxActualValue; -} -double FETable3DData::minActualXAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minActualXAxis; -} - -double FETable3DData::minActualYAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_minActualYAxis; -} - -double FETable3DData::minActualValue() -{ - QMutexLocker locker(m_acccessMutex); - return m_minActualValue; -} -void FETable3DData::setXAxis(int index,double val) -{ - QMutexLocker locker(m_acccessMutex); - QByteArray data; - unsigned short newval = backConvertAxis(val,m_metaData.xAxisCalc); - data.append((char)((newval >> 8) & 0xFF)); - data.append((char)(newval & 0xFF)); - if (!m_isFlashOnly) - { - if (m_writesEnabled) - { - emit saveSingleDataToRam(m_locationId,4+(index*2),2,data); - } - m_xAxis[index] = val; - } -} -void FETable3DData::writeWholeLocation(bool ram) -{ - if (ram) - { - emit saveSingleDataToRam(m_locationId,0,data().size(),data()); - } - else - { - emit saveSingleDataToFlash(m_locationId,0,data().size(),data()); - } -} - -void FETable3DData::setYAxis(int index,double val) -{ - QMutexLocker locker(m_acccessMutex); - QByteArray data; - unsigned short newval = backConvertAxis(val,m_metaData.yAxisCalc); - data.append((char)((newval >> 8) & 0xFF)); - data.append((char)(newval & 0xFF)); - if (!m_isFlashOnly) - { - if (m_writesEnabled) - { - emit saveSingleDataToRam(m_locationId,58+(index*2),2,data); - } - m_yAxis[index] = val; - } -} - -void FETable3DData::setCell(int yIndex, int xIndex,double val) -{ - QMutexLocker locker(m_acccessMutex); - QByteArray data; - unsigned short newval = backConvertAxis(val,m_metaData.zAxisCalc); - data.append((char)((newval >> 8) & 0xFF)); - data.append((char)(newval & 0xFF)); - if (!m_isFlashOnly) - { - if (m_writesEnabled) - { - emit saveSingleDataToRam(m_locationId,100+(xIndex*2)+(yIndex * (m_xAxis.size()*2)),2,data); - } - m_values[yIndex][xIndex] = val; - } -} -void FETable3DData::setWritesEnabled(bool enabled) -{ - m_writesEnabled = enabled; -} - -QByteArray FETable3DData::data() -{ - QMutexLocker locker(m_acccessMutex); - QByteArray data; - - unsigned short xaxissize = m_xAxis.size(); - data.append((char)((xaxissize>> 8) & 0xFF)); - data.append((char)(xaxissize & 0xFF)); - - unsigned short yaxissize = m_yAxis.size(); - data.append((char)((yaxissize>> 8) & 0xFF)); - data.append((char)(yaxissize & 0xFF)); - for (int i=0;i> 8) & 0xFF)); - data.append((char)(val & 0xFF)); - } - for (int i=data.size();i<58;i++) - { - data.append((char)0x00); - } - for (int i=0;i> 8) & 0xFF)); - data.append((char)(val & 0xFF)); - } - for (int i=data.size();i<100;i++) - { - data.append((char)0x00); - } - for (int i=0;i> 8) & 0xFF)); - data.append((char)(val & 0xFF)); - } - } - for (int i=data.size();i<1024;i++) - { - data.append((char)0x00); - } - return data; -} - -QList FETable3DData::yAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_yAxis; -} - -QList FETable3DData::xAxis() -{ - QMutexLocker locker(m_acccessMutex); - return m_xAxis; -} - -QList > FETable3DData::values() -{ - QMutexLocker locker(m_acccessMutex); - return m_values; -} - -int FETable3DData::columns() -{ - QMutexLocker locker(m_acccessMutex); - return m_xAxis.size(); -} - -int FETable3DData::rows() -{ - QMutexLocker locker(m_acccessMutex); - return m_yAxis.size(); -} -double FETable3DData::calcAxis(int val,QList > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=0;j > metadata) -{ - if (metadata.size() == 0) - { - return val; - } - double newval = val; - for (int j=metadata.size()-1;j>=0;j--) - { - if (metadata[j].first == "add") - { - newval -= metadata[j].second; - } - else if (metadata[j].first == "sub") - { - newval += metadata[j].second; - } - else if (metadata[j].first == "mult") - { - newval /= metadata[j].second; - } - else if (metadata[j].first == "div") - { - newval *= metadata[j].second; - } - } - return (unsigned short)newval; -} -void FETable3DData::updateFromFlash() -{ - //emit requestBlockFromFlash(m_locationId,0,0); - emit requestRamUpdateFromFlash(m_locationId); -} - -void FETable3DData::updateFromRam() -{ - //emit requestRamUpdateFromFlash(m_locationId); - emit requestBlockFromRam(m_locationId,0,0); -} -void FETable3DData::saveRamToFlash() -{ - emit requestFlashUpdateFromRam(m_locationId); -} diff --git a/plugins/freeems/fetable3ddata.h b/plugins/freeems/fetable3ddata.h deleted file mode 100644 index 72ed0a1..0000000 --- a/plugins/freeems/fetable3ddata.h +++ /dev/null @@ -1,105 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#ifndef FETABLE3DDATA_H -#define FETABLE3DDATA_H - -#include -#include - -#include "table3ddata.h" -#include "table3dmetadata.h" - -class FETable3DData : public Table3DData -{ - Q_OBJECT -public: - FETable3DData(); - void setData(unsigned short locationid,bool isflashonly,QByteArray payload,Table3DMetaData metadata); - void setData(unsigned short locationid,bool isflashonly,QByteArray payload); - QByteArray data(); - QList xAxis(); - QList yAxis(); - QList > values(); - int columns(); - int rows(); - void setCell(int row, int column,double val); - void setXAxis(int column,double val); - void setYAxis(int row,double val); - double maxActualXAxis(); - double maxActualYAxis(); - double maxActualValue(); - double minActualYAxis(); - double minActualXAxis(); - double minActualValue(); - double maxCalcedXAxis(); - double maxCalcedYAxis(); - double maxCalcedValue(); - double minCalcedXAxis(); - double minCalcedYAxis(); - double minCalcedValue(); - void setWritesEnabled(bool enabled); - void writeWholeLocation(bool ram); - bool isRam() { return !m_isFlashOnly; } - double calcAxis(int val,QList > metadata); - int backConvertAxis(double val,QList > metadata); -private: - QMutex *m_acccessMutex; - bool m_writesEnabled; - bool m_isFlashOnly; - unsigned short m_locationId; - QList m_xAxis; - QList m_yAxis; - QList > m_values; - QString xAxisLabel; - QString yAxisLabel; - QString valuesLabel; - double m_maxCalcedXAxis; - double m_maxCalcedYAxis; - double m_maxCalcedValue; - - double m_minCalcedXAxis; - double m_minCalcedYAxis; - double m_minCalcedValue; - - double m_maxActualXAxis; - double m_maxActualYAxis; - double m_maxActualValue; - - double m_minActualXAxis; - double m_minActualYAxis; - double m_minActualValue; - Table3DMetaData m_metaData; -signals: - void saveSingleDataToFlash(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - void saveSingleDataToRam(unsigned short locationid,unsigned short offset, unsigned short size,QByteArray data); - void requestBlockFromRam(unsigned short locationid,unsigned short offset,unsigned short size); - void requestBlockFromFlash(unsigned short locationid,unsigned short offset,unsigned short size); - void update(); - void requestRamUpdateFromFlash(unsigned short locationid); - void requestFlashUpdateFromRam(unsigned short locationid); -public slots: - void updateFromFlash(); //Trigger a flash update, if table is in ram, it copies from flash to ram, and sends a request to the ECU - void updateFromRam(); //Trigger a ram udpate. Requests table from the ECU from ram - void saveRamToFlash(); -}; - -#endif // FETABLE3DDATA_H diff --git a/plugins/freeems/freeems.pro b/plugins/freeems/freeems.pro deleted file mode 100644 index 80a71cc..0000000 --- a/plugins/freeems/freeems.pro +++ /dev/null @@ -1,108 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Sat Feb 16 17:37:58 2013 -###################################################################### - -TEMPLATE = lib - -DEPENDPATH += . -INCLUDEPATH += . ../../core/src -CONFIG += plugin rtti exceptions -OBJECTS_DIR = obj -MOC_DIR = obj -UI_DIR = obj -include (../../core/QsLog/QsLog.pri) -include(../../serialport/apmserial.pri) -QT -= gui -INCLUDEPATH += $$PWD/../../lib/core -DEPENDPATH += $$PWD/../../lib/core - -gittouch.commands = touch freeems.pro -QMAKE_EXTRA_TARGETS += gittouch -POST_TARGETDEPS += gittouch - - -win32-x-g++ { #Linux based crossplatform 32bit build - TARGET = ../../../core/plugins/freeemsplugin - win32:QMAKE_LFLAGS += -shared - message("Building for win32-x-g++") - INCLUDEPATH += /home/michael/QtWin32/libs/qjson/include - LIBS += -L/home/michael/QtWin32/libs/qjson/lib -lqjson - LIBS += -L/home/michael/QtWin32/lib - DEFINES += GIT_COMMIT=$$system(git describe --dirty=-DEV --always) - DEFINES += GIT_HASH=$$system(git log -n 1 --pretty=format:%H) - DEFINES += GIT_DATE=\""$$system(date)"\" - QMAKE_LFLAGS += -static-libgcc -static-libstdc++ -} else:win64-x-g++ { #Linux based crossplatform 64bit build - TARGET = ../../../core/plugins/freeemsplugin - win32:QMAKE_LFLAGS += -shared - message("Building for win64-x-g++") - INCLUDEPATH += /home/michael/QtWin64/libs/qjson/include - LIBS += -L/home/michael/QtWin64/libs/qjson/lib -lqjson - LIBS += -L/home/michael/QtWin64/lib - DEFINES += GIT_COMMIT=$$system(git describe --dirty=-DEV --always) - DEFINES += GIT_HASH=$$system(git log -n 1 --pretty=format:%H) - DEFINES += GIT_DATE=\""$$system(date)"\" - QMAKE_LFLAGS += -static-libgcc -static-libstdc++ -} else:win32 { #Windows based mingw build - TARGET = ../../../core/plugins/freeemsplugin - win32:QMAKE_LFLAGS += -shared - message("Building for win32-g++") - INCLUDEPATH += C:/libs/qjson/include - LIBS += -LC:/libs/qjson/lib -lqjson.dll - DEFINES += GIT_COMMIT=$$system(\"c:/program files (x86)/git/bin/git.exe\" describe --dirty=-DEV --always) - DEFINES += GIT_HASH=$$system(\"c:/program files (x86)/git/bin/git.exe\" log -n 1 --pretty=format:%H) - QMAKE_LFLAGS += -static-libgcc -static-libstdc++ -} else:mac { - TARGET = ../../core/plugins/freeemsplugi - INCLUDEPATH += /opt/local/include - LIBS += -L/opt/local/lib -lqjson - DEFINES += GIT_COMMIT=$$system(git describe --dirty=-DEV --always) - DEFINES += GIT_HASH=$$system(git log -n 1 --pretty=format:%H) - DEFINES += GIT_DATE=\""$$system(date)"\" -} else:unix { - TARGET = ../../core/plugins/freeemsplugin - target.path = /usr/share/emstudio/plugins - INSTALLS += target - DEFINES += GIT_COMMIT=$$system(git describe --dirty=-DEV --always) - DEFINES += GIT_HASH=$$system(git log -n 1 --pretty=format:%H) - DEFINES += GIT_DATE=\""$$system(date)"\" -} - -# Input -HEADERS += datapacketdecoder.h \ - table2ddata.h \ - table3ddata.h \ - ../../lib/core/configdata.h \ - tabledata.h \ - emscomms.h \ - memorymetadata.h \ - fedatapacketdecoder.h \ - fetable2ddata.h \ - datafield.h \ - fetable3ddata.h \ - freeemscomms.h \ - serialport.h \ - serialrxthread.h \ - fememorymetadata.h \ - datafield.h \ - memorylocation.h \ - emsdata.h \ - rawdata.h \ - ferawdata.h \ - packetdecoder.h \ - packet.h \ - feconfigdata.h - -SOURCES += fedatapacketdecoder.cpp \ - fetable2ddata.cpp \ - fetable3ddata.cpp \ - freeemscomms.cpp \ - serialport.cpp \ - serialrxthread.cpp \ - fememorymetadata.cpp \ - datafield.cpp \ - memorylocation.cpp \ - emsdata.cpp \ - ferawdata.cpp \ - packetdecoder.cpp \ - feconfigdata.cpp diff --git a/plugins/freeems/freeemscomms.cpp b/plugins/freeems/freeemscomms.cpp deleted file mode 100644 index 7760ad1..0000000 --- a/plugins/freeems/freeemscomms.cpp +++ /dev/null @@ -1,1985 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "freeemscomms.h" -#include -#include -#include -#include -#include -#include -#include "fetable2ddata.h" -#include "fetable3ddata.h" -#include "feconfigdata.h" -#include "QsLog.h" - -FreeEmsComms::FreeEmsComms(QObject *parent) : EmsComms(parent) -{ - qRegisterMetaType >("QList"); - qRegisterMetaType >("QList"); - qRegisterMetaType("SerialPortStatus"); - qRegisterMetaType("ConfigBlock"); - qRegisterMetaType >("QMap"); - rxThread = 0; - //serialPort = new SerialPort(this); - //connect(serialPort,SIGNAL(dataWritten(QByteArray)),this,SLOT(dataLogWrite(QByteArray))); - m_isConnected = false; - - dataPacketDecoder = new FEDataPacketDecoder(); - connect(dataPacketDecoder,SIGNAL(payloadDecoded(QVariantMap)),this,SIGNAL(dataLogPayloadDecoded(QVariantMap))); - connect(dataPacketDecoder,SIGNAL(resetDetected(int)),this,SIGNAL(resetDetected(int))); - m_metaDataParser = new FEMemoryMetaData(); - //m_metaDataParser->loadMetaDataFromFile("freeems.config.json"); - m_packetDecoder = new PacketDecoder(this); - connect(m_packetDecoder,SIGNAL(locationIdInfo(MemoryLocationInfo)),this,SLOT(locationIdInfoRec(MemoryLocationInfo))); - connect(m_packetDecoder,SIGNAL(packetAcked(unsigned short,QByteArray,QByteArray)),this,SLOT(packetAckedRec(unsigned short,QByteArray,QByteArray))); - connect(m_packetDecoder,SIGNAL(packetNaked(unsigned short,QByteArray,QByteArray,unsigned short)),this,SLOT(packetNakedRec(unsigned short,QByteArray,QByteArray,unsigned short))); - connect(m_packetDecoder,SIGNAL(locationIdList(QList)),this,SLOT(locationIdListRec(QList))); - connect(m_packetDecoder,SIGNAL(ramBlockUpdatePacket(QByteArray,QByteArray)),this,SLOT(ramBlockUpdateRec(QByteArray,QByteArray))); - connect(m_packetDecoder,SIGNAL(flashBlockUpdatePacket(QByteArray,QByteArray)),this,SLOT(flashBlockUpdateRec(QByteArray,QByteArray))); - connect(m_packetDecoder,SIGNAL(dataLogPayloadReceived(QByteArray,QByteArray)),this,SIGNAL(dataLogPayloadReceived(QByteArray,QByteArray))); - connect(m_packetDecoder,SIGNAL(dataLogPayloadReceived(QByteArray,QByteArray)),dataPacketDecoder,SLOT(decodePayloadPacket(QByteArray,QByteArray))); - connect(m_packetDecoder,SIGNAL(dataLogPayloadReceived(QByteArray,QByteArray)),this,SLOT(dataLogPayloadReceivedRec(QByteArray,QByteArray))); - connect(m_packetDecoder,SIGNAL(compilerVersion(QString)),this,SLOT(compilerVersion(QString))); - connect(m_packetDecoder,SIGNAL(decoderName(QString)),this,SLOT(decoderName(QString))); - connect(m_packetDecoder,SIGNAL(firmwareBuild(QString)),this,SLOT(firmwareBuild(QString))); - connect(m_packetDecoder,SIGNAL(firmwareVersion(QString)),this,SLOT(firmwareVersion(QString))); - connect(m_packetDecoder,SIGNAL(interfaceVersion(QString)),this,SLOT(interfaceVersion(QString))); - connect(m_packetDecoder,SIGNAL(operatingSystem(QString)),this,SLOT(operatingSystem(QString))); - connect(m_packetDecoder,SIGNAL(builtByName(QString)),this,SLOT(builtByName(QString))); - connect(m_packetDecoder,SIGNAL(supportEmail(QString)),this,SLOT(supportEmail(QString))); - connect(m_packetDecoder,SIGNAL(benchTestReply(unsigned short,unsigned char)),this,SIGNAL(benchTestReply(unsigned short,unsigned char))); - - m_lastdatalogTimer = new QTimer(this); - connect(m_lastdatalogTimer,SIGNAL(timeout()),this,SLOT(datalogTimerTimeout())); - m_lastdatalogTimer->start(500); //Every half second, check to see if we've timed out on datalogs. - - m_waitingForResponse = false; - m_logsEnabled = false; - m_lastDatalogUpdateEnabled = false; - m_logInFile=0; - m_logOutFile=0; - m_logInOutFile=0; - m_debugLogsEnabled = false; - m_waitingForRamWrite=false; - m_waitingForFlashWrite=false; - m_sequenceNumber = 1; - m_blockFlagList.append(BLOCK_HAS_PARENT); - m_blockFlagList.append(BLOCK_IS_RAM); - m_blockFlagList.append(BLOCK_IS_FLASH); - m_blockFlagList.append(BLOCK_IS_INDEXABLE); - m_blockFlagList.append(BLOCK_IS_READ_ONLY); - m_blockFlagList.append(BLOCK_GETS_VERIFIED); - m_blockFlagList.append(BLOCK_FOR_BACKUP_RESTORE); - m_blockFlagList.append(BLOCK_SPARE_7); - m_blockFlagList.append(BLOCK_SPARE_8); - m_blockFlagList.append(BLOCK_SPARE_9); - m_blockFlagList.append(BLOCK_SPARE_10); - m_blockFlagList.append(BLOCK_IS_2D_SIGNED_TABLE); - m_blockFlagList.append(BLOCK_IS_2D_TABLE); - m_blockFlagList.append(BLOCK_IS_MAIN_TABLE); - m_blockFlagList.append(BLOCK_IS_LOOKUP_DATA); - m_blockFlagList.append(BLOCK_IS_CONFIGURATION); - - - m_blockFlagToNameMap[BLOCK_HAS_PARENT] = "Parent"; - m_blockFlagToNameMap[BLOCK_IS_RAM] = "Is Ram"; - m_blockFlagToNameMap[BLOCK_IS_FLASH] = "Is Flash"; - m_blockFlagToNameMap[BLOCK_IS_INDEXABLE] = "Is Indexable"; - m_blockFlagToNameMap[BLOCK_IS_READ_ONLY] = "Is Read Only"; - m_blockFlagToNameMap[BLOCK_FOR_BACKUP_RESTORE] = "For Backup"; - m_blockFlagToNameMap[BLOCK_GETS_VERIFIED] = "Is Verified"; - m_blockFlagToNameMap[BLOCK_IS_2D_TABLE] = "2D Table"; - m_blockFlagToNameMap[BLOCK_IS_2D_SIGNED_TABLE] = "2D Signed Table"; - m_blockFlagToNameMap[BLOCK_IS_MAIN_TABLE] = "3D Table"; - m_blockFlagToNameMap[BLOCK_IS_LOOKUP_DATA] = "Lookup Table"; - m_blockFlagToNameMap[BLOCK_IS_CONFIGURATION] = "Configuration"; - m_interrogateInProgress = false; - m_interogateComplete = false; - m_interrogateIdListComplete = false; - m_interrogateIdInfoComplete = false; - m_interrogateTotalCount=0; - emsData.setMetaData(m_metaDataParser); - connect(&emsData,SIGNAL(updateRequired(unsigned short)),this,SIGNAL(deviceDataUpdated(unsigned short))); - connect(&emsData,SIGNAL(ramBlockUpdateRequest(unsigned short,unsigned short,unsigned short,QByteArray)),this,SLOT(updateBlockInRam(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(&emsData,SIGNAL(flashBlockUpdateRequest(unsigned short,unsigned short,unsigned short,QByteArray)),this,SLOT(updateBlockInFlash(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(&emsData,SIGNAL(updateRequired(unsigned short)),this,SLOT(locationIdUpdate(unsigned short))); - connect(&emsData,SIGNAL(configRecieved(ConfigBlock,QVariant)),this,SIGNAL(configRecieved(ConfigBlock,QVariant))); - connect(&emsData,SIGNAL(localRamLocationDirty(unsigned short)),this,SLOT(ramLocationMarkedDirty(unsigned short))); - connect(&emsData,SIGNAL(localFlashLocationDirty(unsigned short)),this,SLOT(flashLocationMarkedDirty(unsigned short))); - - - QFile dialogFile("menuconfig.json"); - if (!dialogFile.open(QIODevice::ReadOnly)) - { - return; - } - QByteArray dialogfiledata = dialogFile.readAll(); - dialogFile.close(); - QJson::Parser parser; - bool ok = false; - QVariant resultvariant = parser.parse(dialogfiledata,&ok); - - QVariantMap topmap = resultvariant.toMap(); - QVariantList dialogslist = topmap["dialogs"].toList(); - MenuSetup menu; - for (int i=0;i > configmap; - for (int i=0;isetName(configitemmap["name"].toString()); - block->setType(configitemmap["type"].toString()); - block->setElementSize(configitemmap["sizeofelement"].toInt()); - block->setSize(configitemmap["size"].toInt()); - block->setOffset(configitemmap["offset"].toInt()); - QList > parsedcalclist; - QVariantList calclist = configitemmap["calc"].toList(); - for (int j=0;j(calcitemmap["type"].toString(),calcitemmap["value"].toDouble())); - } - block->setCalc(parsedcalclist); - - //configitemmap["calc"]; - block->setSizeOverride(configitemmap["sizeoverride"].toString()); - bool ok = false; - block->setLocationId(configitemmap["locationid"].toString().toInt(&ok,16)); - QString locid = configitemmap["locationid"].toString(); - - unsigned short locidint = locid.mid(2).toInt(&ok,16); - - if (!ok) - { - //Invalid location id conversion, bad JSON file? - } - else - { - if (!m_locIdToConfigListMap.contains(locidint)) - { - m_locIdToConfigListMap[locidint] = QList(); - } - m_locIdToConfigListMap[locidint].append(block); - } - if (m_configMap.contains(block->name())) - { - //Block already exists! - } - else - { - m_configMap[block->name()] = block; - } - } - - //m_metaDataParser->passConfigData(configmap); - m_metaDataParser->setMenuMetaData(menu); - - -} -void FreeEmsComms::writeAllRamToRam() -{ - QList ramlist = emsData.getTopLevelDeviceRamLocations(); - - for (int i=0;iapplicationDirPath()); - if (!dir.mkpath(m_logsDirectory)) - { - emit error("Unable to create log directory. Data will NOT be logged until this is fixed!"); - } - } - m_logInFile = new QFile(m_logsDirectory + "/" + m_logsFilename + ".bin"); - m_logInFile->open(QIODevice::ReadWrite | QIODevice::Truncate); - if (m_debugLogsEnabled) - { - m_logInOutFile = new QFile(m_logsDirectory + "/" + m_logsFilename + ".both.bin"); - m_logInOutFile->open(QIODevice::ReadWrite | QIODevice::Truncate); - m_logOutFile = new QFile(m_logsDirectory + "/" + m_logsFilename + ".toecu.bin"); - m_logOutFile->open(QIODevice::ReadWrite | QIODevice::Truncate); - } -} - -void FreeEmsComms::connectSerial(QString port,int baud) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = SERIAL_CONNECT; - req.addArg(port); - req.addArg(baud,sizeof(baud)); - m_reqList.append(req); -} - -void FreeEmsComms::loadLog(QString filename) -{ - Q_UNUSED(filename); -} - -void FreeEmsComms::playLog() -{ -} -void FreeEmsComms::setLogsEnabled(bool enabled) -{ - if (m_logsEnabled && !enabled) - { - m_logInFile->close(); - delete m_logInFile; - m_logInFile=0; - - if (m_debugLogsEnabled) - { - m_logInOutFile->close(); - delete m_logInOutFile; - m_logInOutFile=0; - - m_logOutFile->close(); - delete m_logOutFile; - m_logOutFile=0; - } - } - else if (!m_logsEnabled && enabled) - { - if (m_isConnected) - { - //If we're connected, open logs. Otherwise, don't as they will be open next time we connect. - openLogs(); - } - } - m_logsEnabled = enabled; -} -void FreeEmsComms::setlogsDebugEnabled(bool enabled) -{ - if (m_logsEnabled && enabled && !m_debugLogsEnabled) - { - if (!QDir(m_logsDirectory).exists()) - { - QDir dir(QCoreApplication::instance()->applicationDirPath()); - if (!dir.mkpath(m_logsDirectory)) - { - emit error("Unable to create log directory. Data will NOT be logged until this is fixed!"); - } - } - m_logInOutFile = new QFile(m_logsDirectory + "/" + m_logsFilename + ".both.bin"); - m_logInOutFile->open(QIODevice::ReadWrite | QIODevice::Truncate); - m_logOutFile = new QFile(m_logsDirectory + "/" + m_logsFilename + ".toecu.bin"); - m_logOutFile->open(QIODevice::ReadWrite | QIODevice::Truncate); - } - else if (m_logsEnabled && !enabled && m_debugLogsEnabled) - { - m_logInOutFile->close(); - m_logInOutFile->deleteLater(); - m_logInOutFile=0; - m_logOutFile->close(); - m_logOutFile->deleteLater(); - m_logOutFile=0; - } - m_debugLogsEnabled = enabled; -} - -void FreeEmsComms::setLogDirectory(QString dir) -{ - m_logsDirectory = dir; -} - -void FreeEmsComms::setPort(QString portname) -{ - Q_UNUSED(portname) - //serialPort->setPort(portname); -} - -void FreeEmsComms::setBaud(int baudrate) -{ - Q_UNUSED(baudrate) - //serialPort->setBaud(baudrate); -} -int FreeEmsComms::burnBlockFromRamToFlash(unsigned short location,unsigned short offset, unsigned short size) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = BURN_BLOCK_FROM_RAM_TO_FLASH; - req.addArg(location,sizeof(location)); - req.addArg(offset,sizeof(offset)); - req.addArg(size,sizeof(size)); - req.sentRequest = true; - req.hasReply = true; - req.sequencenumber = m_sequenceNumber; - m_sequenceNumber++; - m_reqList.append(req); - - if (size == 0) - { - size = emsData.getLocalRamBlock(location).size(); - } - - for (int i=emsData.getLocalRamBlockInfo(location)->ramAddress + offset;iramAddress+offset+size;i++) - { - if (m_dirtyRamAddresses.contains(i)) - { - m_dirtyRamAddresses.removeOne(i); - } - } - if (m_dirtyRamAddresses.size() == 0) - { - emit memoryClean(); - } - /*if (m_dirtyLocationIds.contains(location)) - { - m_dirtyLocationIds.removeOne(location); - if (m_dirtyLocationIds.size() == 0) - { - emit memoryClean(); - } - }*/ - return m_sequenceNumber-1; -} -int FreeEmsComms::enableDatalogStream() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = UPDATE_BLOCK_IN_RAM; - req.addArg(0x9000,2); - req.addArg(0,2); - req.addArg(1,2); - req.addArg(QByteArray().append((char)0x01)); - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - req.hasLength = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} - -int FreeEmsComms::disableDatalogStream() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = UPDATE_BLOCK_IN_RAM; - req.addArg(0x9000,2); - req.addArg(0,2); - req.addArg(1,2); - req.addArg(QByteArray().append((char)0x00)); - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} - -int FreeEmsComms::updateBlockInRam(unsigned short location,unsigned short offset, unsigned short size,QByteArray data) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = UPDATE_BLOCK_IN_RAM; - req.addArg(location,sizeof(location)); - req.addArg(offset,sizeof(offset)); - req.addArg(size,sizeof(size)); - req.addArg(data); - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - m_sequenceNumber++; - m_reqList.append(req); - - emsData.markLocalRamLocationDirty(location,offset,size); - - if (emsData.getLocalRamBlockInfo(location)->isFlash) - { - unsigned short ramaddress = emsData.getLocalRamBlockInfo(location)->ramAddress; - for (int i=ramaddress+offset;isize; - //emsData.getLocalRamBlockInfo(location)->ramAddress; - - //We mark it dirty, so it will be silently replaced. - if (mark) - { - emsData.markLocalFlashLocationDirty(location,offset,size); - } - - /*if (emsData.getLocalRamBlockInfo(location)) - { - emsData.markLocalRamLocationClean(location,offset,size); - - for (int i=emsData.getLocalRamBlockInfo(location)->ramAddress + offset;iramAddress+offset+size;i++) - { - if (m_dirtyRamAddresses.contains(i)) - { - m_dirtyRamAddresses.removeOne(i); - } - } - if (m_dirtyRamAddresses.size() == 0) - { - emit memoryClean(); - } - }*/ - return m_sequenceNumber-1; -} -int FreeEmsComms::retrieveBlockFromRam(unsigned short location, unsigned short offset, unsigned short size,bool mark) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = RETRIEVE_BLOCK_IN_RAM; - req.addArg(location,sizeof(location)); - req.addArg(offset,sizeof(offset)); - req.addArg(size,sizeof(size)); - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - m_sequenceNumber++; - m_reqList.append(req); - if (mark) - { - emsData.markLocalRamLocationDirty(location,offset,size); - } - return m_sequenceNumber-1; -} -int FreeEmsComms::getInterfaceVersion() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = GET_INTERFACE_VERSION; - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -int FreeEmsComms::getFirmwareVersion() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = GET_FIRMWARE_VERSION; - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -int FreeEmsComms::getMaxPacketSize() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = GET_MAX_PACKET_SIZE; - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -int FreeEmsComms::echoPacket(QByteArray packet) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = ECHO_PACKET; - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - req.hasLength = true; - req.addArg(packet); - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -int FreeEmsComms::startBenchTest(unsigned char eventspercycle,unsigned short numcycles,unsigned short ticksperevent,QVariantList pineventmask,QVariantList pinmode) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = BENCHTEST; - req.addArg(0x01,sizeof(char)); - req.addArg(eventspercycle,sizeof(eventspercycle)); - req.addArg(numcycles,sizeof(numcycles)); - req.addArg(ticksperevent,sizeof(ticksperevent)); - for (int i=0;i 255) || (pineventmask[i].toInt() < 0)) - { - return -1; - } - req.addArg((unsigned char)pineventmask[i].toInt(),1); - } - for (int i=0;i 65535)) - { - return -1; - } - req.addArg((unsigned short)pinmode[i].toInt(),2); - } - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - req.hasLength = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -int FreeEmsComms::stopBenchTest() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = BENCHTEST; - req.addArg(0x00,sizeof(char)); - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - req.hasLength = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -int FreeEmsComms::bumpBenchTest(unsigned char cyclenum) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = BENCHTEST; - req.addArg(0x02,sizeof(char)); - req.addArg(cyclenum,sizeof(cyclenum)); - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - req.hasReply = true; - req.hasLength = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} - -int FreeEmsComms::getLocationIdInfo(unsigned short locationid) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = GET_LOCATION_ID_INFO; - req.sequencenumber = m_sequenceNumber; - req.addArg(locationid,sizeof(locationid)); - req.sentRequest = true; - req.hasReply = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} - -int FreeEmsComms::getLocationIdList(unsigned char listtype, unsigned short listmask) -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = GET_LOCATION_ID_LIST; - req.sequencenumber = m_sequenceNumber; - req.addArg(listtype,sizeof(listtype)); - req.addArg(listmask,sizeof(listmask)); - req.sentRequest = true; - req.hasReply = true; - req.hasLength = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} - -int FreeEmsComms::softReset() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = SOFT_RESET; - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -int FreeEmsComms::hardReset() -{ - QMutexLocker locker(&m_reqListMutex); - RequestClass req; - req.type = HARD_RESET; - req.sequencenumber = m_sequenceNumber; - req.sentRequest = true; - m_sequenceNumber++; - m_reqList.append(req); - return m_sequenceNumber-1; -} -bool FreeEmsComms::sendPacket(RequestClass request) -{ - if (!request.hasReply) - { - return sendPacket(request.type,request.args,request.argsize,request.hasLength); - } - QMutexLocker locker(&m_waitingInfoMutex); - if (!m_waitingForResponse) - { - m_waitingForResponse = true; - m_timeoutMsecs = QDateTime::currentDateTime().currentMSecsSinceEpoch(); - m_currentWaitingRequest = request; - m_payloadWaitingForResponse = request.type; - if (request.type == UPDATE_BLOCK_IN_RAM) - { - m_waitingForRamWrite = true; - } - if (request.type == UPDATE_BLOCK_IN_FLASH) - { - m_waitingForFlashWrite = true; - } - if (!sendPacket(request.type,request.args,request.argsize,request.hasLength)) - { - return false; - } - return true; - } - return false; - -} - -bool FreeEmsComms::sendPacket(unsigned short payloadid,QList arglist,QList argsizelist,bool haslength) -{ - if (arglist.size() != argsizelist.size()) - { - return false; - } - QByteArray header; - QByteArray payload; - for (int i=0;i> 8) & 0xFF)); - payload.append((unsigned char)((arg) & 0xFF)); - } - else if (argsizelist[i] == 4) - { - unsigned int arg = arglist[i].toInt(); - payload.append((unsigned char)((arg >> 24) & 0xFF)); - payload.append((unsigned char)((arg >> 16) & 0xFF)); - payload.append((unsigned char)((arg >> 8) & 0xFF)); - payload.append((unsigned char)((arg) & 0xFF)); - } - } - else if (arglist[i].type() == QVariant::ByteArray) - { - //Data packet - QByteArray arg = arglist[i].toByteArray(); - payload.append(arg); - } - else if (arglist[i].type() == QVariant::String) - { - QByteArray arg = arglist[i].toString().toAscii(); - payload.append(arg); - } - } - if (haslength) - { - header.append((unsigned char)0x01); //Length, no seq no nak - header.append((unsigned char)((payloadid >> 8) & 0xFF)); - header.append((unsigned char)((payloadid) & 0xFF)); - header.append((char)(payload.length() >> 8) & 0xFF); - header.append((char)(payload.length()) & 0xFF); - } - else - { - header.append((char)0x00); //No Length, no seq no nak - header.append((char)((payloadid >> 8) & 0xFF)); - header.append((char)((payloadid) & 0xFF)); - } - QLOG_TRACE() << "About to send packet"; - if (serialPort->writeBytes(generatePacket(header,payload)) < 0) - { - return false; - } - QLOG_TRACE() << "Sent packet" << "0x" + QString::number(payloadid,16).toUpper() << header.size() << payload.size(); - emit packetSent(payloadid,header,payload); - return true; -} - -QByteArray FreeEmsComms::generatePacket(QByteArray header,QByteArray payload) -{ - QByteArray packet; - packet.append((char)0xAA); - unsigned char checksum = 0; - for (int i=0;isetInterByteSendDelay(milliseconds); -} - -void FreeEmsComms::run() -{ - m_terminateLoop = false; - bool serialconnected = false; - serialPort = new SerialPort(); - connect(serialPort,SIGNAL(dataWritten(QByteArray)),this,SLOT(dataLogWrite(QByteArray))); - while (!m_terminateLoop) - { - m_reqListMutex.lock(); - m_threadReqList.append(m_reqList); - m_reqList.clear(); - m_reqListMutex.unlock(); - for (int i=0;iisSerialMonitor(m_threadReqList[i].args[0].toString()); - if (errortype != NONE) - { - QLOG_ERROR() << "Unable to verify ECU"; - QString errorstr = "UNKNOWN ERROR"; - if (errortype == UNABLE_TO_CONNECT) - { - errorstr = "Unable to open serial port " + m_threadReqList[i].args[0].toString() + " Please ensure no other application has the port open and that the port exists!"; - } - else if (errortype == UNABLE_TO_LOCK) - { - errorstr = "Unable to open serial port " + m_threadReqList[i].args[0].toString() + " because another compatible application has locked it. Please close all serial port related applications and try again."; - } - else if (errortype == UNABLE_TO_WRITE) - { - errorstr = "Unable to open serial port " + m_threadReqList[i].args[0].toString() + " Please ensure no other application has the port open and that the port exists!"; - } - else if (errortype == UNABLE_TO_READ) - { - errorstr = "Unable to read from serial port " + m_threadReqList[i].args[0].toString() + ". This is likely an error with your serial port driver. Please disconnect and reconnect the device and try again"; - } - else if (errortype == SM_MODE) - { - //TODO Fix this when we have the ability to reset SM mode - errorstr = "Unable to connect to ECU. SerialMonitor mode detected! Please remove SM jumper, reset the ECU and click retry!"; - } - emit error(errortype,errorstr); - serialconnected = false; - emit disconnected(); - //On a disconnect, we are going to be deleting this thread, so go ahead and quit out; - //return; - m_threadReqList.removeAt(i); - i--; - continue; - } - emit debugVerbose("SERIAL_CONNECT"); - int errornum = 0; - if ((errornum = serialPort->openPort(m_threadReqList[i].args[0].toString(),m_threadReqList[i].args[1].toInt()))) - { - if (errornum == -1) - { - emit error(UNABLE_TO_CONNECT,"Unable to open serial port " + m_threadReqList[i].args[0].toString() + " Please ensure no other application has the port open and that the port exists!"); - QLOG_ERROR() << "Unable to connect to COM port"; - } - else if (errornum == -2) - { - emit error(UNABLE_TO_LOCK,"Unable to open serial port " + m_threadReqList[i].args[0].toString() + " due to another freeems application locking the port. Please close all other freeems related applications and try again."); - QLOG_ERROR() << "Unable to connect to COM port due to process lock"; - } - m_threadReqList.removeAt(i); - i--; - emit disconnected(); - continue; - } - QLOG_INFO() << "Serial connected!"; - rxThread = new SerialRXThread(); - connect(rxThread,SIGNAL(incomingPacket(QByteArray)),this,SLOT(parseEverything(QByteArray)),Qt::DirectConnection); - connect(rxThread,SIGNAL(dataRead(QByteArray)),this,SLOT(dataLogRead(QByteArray)),Qt::DirectConnection); - connect(rxThread,SIGNAL(portGone()),this,SLOT(rxThreadPortGone()),Qt::DirectConnection); - - //Before we finish emitting the fact that we are connected, let's verify this is a freeems system we are talking to. - if (!sendPacket(GET_FIRMWARE_VERSION)) - { - QLOG_FATAL() << "Error writing packet. Quitting thread"; - return; - } - int dataattempts = 0; - int nodataattempts=0; - bool good = false; - bool nodata = true; - while (dataattempts < 50 && !good && nodataattempts < 4) - { - QByteArray result = rxThread->readSinglePacket(serialPort); - if (result.size() > 0) - { - dataattempts++; - nodata = false; - - Packet p = m_packetDecoder->parseBuffer(result); - if (!p.isValid) - { - emit decoderFailure(result); - } - if (p.isValid && p.payloadid == GET_FIRMWARE_VERSION+1) - { - //We're good! - good = true; - } - } - else - { - nodataattempts++; - } - } - if (!good) - { - QString errorstr = ""; - SerialPortStatus errortype = NONE; - if (nodata) - { - errorstr = "Unable to communicate with ECU, Serial port is unresponsive. Please verify your FreeEMS Board is plugged in, powered up, and all serial settings are properly set."; - errortype = (SerialPortStatus)NO_DAT; - } - else - { - errorstr = "Unable to communicate with FreeEMS, corrupt data received. Please verify serial settings, in particular double check the baud rate."; - errortype = (SerialPortStatus)INVALID_DATA; - } - emit error(errortype,errorstr); - serialconnected = false; - serialPort->closePort(); - emit disconnected(); - //On a disconnect, we are going to be deleting this thread, so go ahead and quit out; - QLOG_FATAL() << "Error communicating with ECU!!!"; - //return; - m_threadReqList.removeAt(i); - i--; - continue; - } - - serialconnected = true; - emit debug("Connected to serial port"); - m_isConnected = true; - openLogs(); - emit connected(); - m_threadReqList.removeAt(i); - i--; - rxThread->start(serialPort); - - } - else if (!serialconnected) - { - continue; - } - else if (m_threadReqList[i].type == SERIAL_DISCONNECT) - { - emit debugVerbose("SERIAL_DISCONNECT"); - rxThread->stop(); - rxThread->wait(500); - //rxThread->terminate(); - delete rxThread; - rxThread = 0; - - serialPort->closePort(); - //delete serialPort; - //serialPort = new SerialPort(); - //connect(serialPort,SIGNAL(dataWritten(QByteArray)),this,SLOT(dataLogWrite(QByteArray))); - serialconnected = false; - emit disconnected(); - m_threadReqList.removeAt(i); - i--; - } - else if (m_threadReqList[i].type == INTERROGATE_START) - { - int seq = getFirmwareVersion(); - emit interrogateTaskStart("Ecu Info FW Version",seq); - m_interrogatePacketList.append(seq); - - seq = getInterfaceVersion(); - emit interrogateTaskStart("Ecu Info Interface Version",seq); - m_interrogatePacketList.append(seq); - - seq = getCompilerVersion(); - emit interrogateTaskStart("Ecu Info Compiler Version",seq); - m_interrogatePacketList.append(seq); - - seq = getDecoderName(); - emit interrogateTaskStart("Ecu Info Decoder Name",seq); - m_interrogatePacketList.append(seq); - - seq = getFirmwareBuildDate(); - emit interrogateTaskStart("Ecu Info Firmware Build Date",seq); - m_interrogatePacketList.append(seq); - - seq = getMaxPacketSize(); - emit interrogateTaskStart("Ecu Info Max Packet Size",seq); - m_interrogatePacketList.append(seq); - - seq = getOperatingSystem(); - emit interrogateTaskStart("Ecu Info Operating System",seq); - m_interrogatePacketList.append(seq); - - seq = getBuiltByName(); - emit interrogateTaskStart("Ecu Info Built By Name",seq); - m_interrogatePacketList.append(seq); - - seq = getSupportEmail(); - emit interrogateTaskStart("Ecu Info Support Email",seq); - m_interrogatePacketList.append(seq); - - seq = getLocationIdList(0x00,0x00); - emit interrogateTaskStart("Ecu Info Location ID List",seq); - m_interrogatePacketList.append(seq); - - m_interrogateTotalCount=8; - m_threadReqList.removeAt(i); - i--; - continue; - } - else if (false) - { - serialPort->writeBytes(QByteArray()); - break; - } - } - if (m_threadReqList.size() == 0) - { - msleep(10); - } - - m_waitingInfoMutex.lock(); - if (((QDateTime::currentDateTime().currentMSecsSinceEpoch() - m_timeoutMsecs) > 500) && m_waitingForResponse) - { - //5 seconds - QLOG_WARN() << "TIMEOUT waiting for response to payload:" << "0x" + QString::number(m_payloadWaitingForResponse,16).toUpper() << "Sequence:" << m_currentWaitingRequest.sequencenumber; - if (m_currentWaitingRequest.retryCount >= 2) - { - QLOG_ERROR() << "No retries left!"; - emit commandTimedOut(m_currentWaitingRequest.sequencenumber); - if (m_interrogateInProgress) - { - if (m_interrogatePacketList.contains(m_currentWaitingRequest.sequencenumber)) - { - //Interrogate command failed!! - emit interrogateTaskFail(m_currentWaitingRequest.sequencenumber); - m_interrogatePacketList.removeOne(m_currentWaitingRequest.sequencenumber); - emit interrogationProgress(m_interrogateTotalCount - m_interrogatePacketList.size(),m_interrogateTotalCount); - sendNextInterrogationPacket(); - } - } - m_waitingForResponse = false; - } - else - { - QLOG_WARN() << "Retrying"; - m_waitingForResponse = false; - m_currentWaitingRequest.retryCount++; - m_threadReqList.insert(0,m_currentWaitingRequest); - } - //TODO: Requeue the command for retry. - } - m_waitingInfoMutex.unlock(); - } - QLOG_DEBUG() << "Exiting FreeEMSComms Thread!!!!"; - if (rxThread) - { - rxThread->stop(); - rxThread->wait(500); - delete rxThread; - rxThread = 0; - } -} -void FreeEmsComms::rxThreadPortGone() -{ - disconnectSerial(); - emit error("Serial port has disappeared. Save your tune (File->Save tune) then ensure the device is still connected and powered, then reconnect"); -} - -void FreeEmsComms::sendNextInterrogationPacket() -{ - if (m_interrogatePacketList.size() == 0) - { - if (!m_interrogateIdListComplete) - { - QLOG_DEBUG() << "Interrogation ID List complete" << m_locationIdList.size() << "entries"; - if (m_locationIdList.size() == 0) - { - //Things have gone terribly wrong here. - //Throw out what we have, and allow interrogation to complete. - emit interrogationProgress(m_interrogateTotalCount - m_interrogatePacketList.size(),m_interrogateTotalCount); - emit interrogationComplete(); - emit interrogationData(m_interrogationMetaDataMap); - m_interrogateInProgress = false; - return; - } - m_interrogateIdListComplete = true; - m_interrogateTotalCount += m_locationIdList.size(); - for (int i=0;i ramlist = emsData.getTopLevelDeviceRamLocations(); - QList flashlist = emsData.getTopLevelDeviceFlashLocations(); - m_interrogateTotalCount += ramlist.size() + flashlist.size(); - if (ramlist.size() == 0 && flashlist.size() == 0) - { - //Things have gone terribly wrong here. - //Throw out what we have, and allow interrogation to complete. - emit interrogationProgress(m_interrogateTotalCount - m_interrogatePacketList.size(),m_interrogateTotalCount); - emit interrogationComplete(); - emit interrogationData(m_interrogationMetaDataMap); - m_interrogateInProgress = false; - return; - } - for (int i=0;i::const_iterator i=m_interrogationMetaDataMap.constBegin();i!=m_interrogationMetaDataMap.constEnd();i++) - { - top[i.key()] = i.value(); - } - /*top["firmwareversion"] = emsinfo.firmwareVersion; - top["interfaceversion"] = emsinfo.interfaceVersion; - top["compilerversion"] = emsinfo.compilerVersion; - top["firmwarebuilddate"] = emsinfo.firmwareBuildDate; - top["decodername"] = emsinfo.decoderName; - top["operatingsystem"] = emsinfo.operatingSystem; - top["emstudiohash"] = emsinfo.emstudioHash; - top["emstudiocommit"] = emsinfo.emstudioCommit;*/ - - if (m_logsEnabled) - { - QFile *settingsFile = new QFile(m_logsDirectory + "/" + m_logsFilename + ".meta.json"); - settingsFile->open(QIODevice::ReadWrite); - settingsFile->write(jsonSerializer.serialize(top)); - settingsFile->close(); - } - //deviceDataUpdated(unsigned short) - } - } -} - -bool FreeEmsComms::sendSimplePacket(unsigned short payloadid) -{ - m_waitingForResponse = true; - m_timeoutMsecs = QDateTime::currentDateTime().currentMSecsSinceEpoch(); - QByteArray header; - QByteArray payload; - header.append((char)0x00); - header.append((char)((payloadid << 8) & 0xFF)); - header.append((char)(payloadid & 0xFF)); - m_payloadWaitingForResponse = payloadid; - if (serialPort->writeBytes(generatePacket(header,payload)) < 0) - { - QLOG_FATAL() << "Error writing packet. Quitting thread"; - return false; - } - return true; -} - -void FreeEmsComms::packetNakedRec(unsigned short payloadid,QByteArray header,QByteArray payload,unsigned short errornum) -{ - QMutexLocker locker(&m_waitingInfoMutex); - if (m_waitingForResponse) - { - if (m_interrogateInProgress) - { - if (m_interrogatePacketList.contains(m_currentWaitingRequest.sequencenumber)) - { - //Interrogate command failed!! - emit interrogateTaskFail(m_currentWaitingRequest.sequencenumber); - m_interrogatePacketList.removeOne(m_currentWaitingRequest.sequencenumber); - emit interrogationProgress(m_interrogateTotalCount - m_interrogatePacketList.size(),m_interrogateTotalCount); - sendNextInterrogationPacket(); - { - if (m_payloadWaitingForResponse == GET_LOCATION_ID_LIST) - { - - } - } - } - else - { - } - } - if (m_waitingForFlashWrite) - { - m_waitingForFlashWrite = false; - unsigned short locid = m_currentWaitingRequest.args[0].toUInt(); - emsData.setLocalFlashBlock(locid,emsData.getDeviceFlashBlock(locid)); - if (m_2dTableMap.contains(locid)) - { - m_2dTableMap[locid]->setData(locid,!emsData.hasLocalRamBlock(locid),emsData.getLocalFlashBlock(locid),m_metaDataParser->get2DMetaData(locid),false); - } - if (m_3dTableMap.contains(locid)) - { - m_3dTableMap[locid]->setData(locid,!emsData.hasLocalRamBlock(locid),emsData.getLocalFlashBlock(locid),m_metaDataParser->get3DMetaData(locid)); - } - if (m_rawDataMap.contains(locid)) - { - if (emsData.hasLocalRamBlock(locid)) - { - m_rawDataMap[locid]->setData(locid,false,emsData.getLocalRamBlock(locid)); - } - else - { - m_rawDataMap[locid]->setData(locid,true,emsData.getLocalFlashBlock(locid)); - } - } - if (m_locIdToConfigListMap.contains(locid)) - { - for (int i=0;isetData(emsData.getLocalFlashBlock(locid)); - } - } - } - if (m_waitingForRamWrite) - { - m_waitingForRamWrite = false; - unsigned short locid = m_currentWaitingRequest.args[0].toUInt(); - emsData.setLocalRamBlock(locid,emsData.getDeviceRamBlock(locid)); - if (m_2dTableMap.contains(locid)) - { - m_2dTableMap[locid]->setData(locid,!emsData.hasLocalRamBlock(locid),emsData.getLocalRamBlock(locid),m_metaDataParser->get2DMetaData(locid),false); - } - if (m_3dTableMap.contains(locid)) - { - m_3dTableMap[locid]->setData(locid,!emsData.hasLocalRamBlock(locid),emsData.getLocalRamBlock(locid),m_metaDataParser->get3DMetaData(locid)); - } - if (m_rawDataMap.contains(locid)) - { - if (emsData.hasLocalRamBlock(locid)) - { - m_rawDataMap[locid]->setData(locid,false,emsData.getLocalRamBlock(locid)); - } - else - { - m_rawDataMap[locid]->setData(locid,true,emsData.getLocalFlashBlock(locid)); - } - } - if (m_locIdToConfigListMap.contains(locid)) - { - for (int i=0;isetData(emsData.getLocalRamBlock(locid)); - } - } - - unsigned short offset = m_currentWaitingRequest.args[1].toUInt(); - unsigned short size = m_currentWaitingRequest.args[2].toUInt(); - unsigned short ramaddress = emsData.getLocalRamBlockInfo(locid)->ramAddress; - for (int i=ramaddress+offset;i 1500) - { - //It's been 1.5 seconds since our last datalog. We've likely either reset, or stopped responding. - m_isSilent = true; - m_lastDatalogUpdateEnabled = false; - emit emsSilenceStarted(m_lastDatalogTime); - } -} -Table2DData* FreeEmsComms::get2DTableData(unsigned short locationid) -{ - if (!m_2dTableMap.contains(locationid)) - { - //This is an error condition - return 0; - } - return m_2dTableMap[locationid]; - -} - -Table3DData* FreeEmsComms::get3DTableData(unsigned short locationid) -{ - if (!m_3dTableMap.contains(locationid)) - { - //This is an error condition - return 0; - } - return m_3dTableMap[locationid]; -} -Table2DData* FreeEmsComms::get2DTableData(QString locationname) -{ - bool ok = false; - unsigned short locid = locationname.toInt(&ok,16); - if (!ok) - { - return 0; - } - if (!m_2dTableMap.contains(locid)) - { - return 0; - } - return m_2dTableMap.value(locid); -} - -Table3DData* FreeEmsComms::get3DTableData(QString locationname) -{ - bool ok = false; - unsigned short locid = locationname.toInt(&ok,16); - if (!ok) - { - return 0; - } - if (!m_3dTableMap.contains(locid)) - { - return 0; - } - return m_3dTableMap.value(locid); -} - -RawData* FreeEmsComms::getRawData(unsigned short locationid) -{ - if (!m_rawDataMap.contains(locationid)) - { - //This is an error condition - return 0; - } - return m_rawDataMap[locationid]; -} -ConfigData* FreeEmsComms::getConfigData(QString name) -{ - if (!m_configMap.contains(name)) - { - return 0; - } - return m_configMap[name]; -} -QList FreeEmsComms::getConfigList() -{ - return m_configMap.keys(); -} - -void FreeEmsComms::locationIdListRec(QList locationidlist) -{ - m_locationIdList.clear(); - for (int i=0;i updatelist; - updatelist.append(locationid); - if (emsData.localFlashHasParent(locationid)) - { - updatelist.append(emsData.getParentOfLocalFlashLocation(locationid)); - } - if (emsData.localRamHasParent(locationid)) - { - updatelist.append(emsData.getParentOfLocalRamLocation(locationid)); - } - if (emsData.localFlashHasChildren(locationid)) - { - updatelist.append(emsData.getChildrenOfLocalFlashLocation(locationid)); - } - if (emsData.localRamHasChildren(locationid)) - { - updatelist.append(emsData.getChildrenOfLocalRamLocation(locationid)); - } - - for (int i=0;isetData(updatelist[i],!emsData.hasDeviceRamBlock(updatelist[i]),emsData.getDeviceRamBlock(updatelist[i]),m_metaDataParser->get2DMetaData(updatelist[i]),false); - } - if (m_3dTableMap.contains(updatelist[i])) - { - m_3dTableMap[updatelist[i]]->setData(updatelist[i],!emsData.hasDeviceRamBlock(updatelist[i]),emsData.getDeviceRamBlock(updatelist[i]),m_metaDataParser->get3DMetaData(updatelist[i])); - } - if (m_rawDataMap.contains(updatelist[i])) - { - if (emsData.hasLocalRamBlock(updatelist[i])) - { - m_rawDataMap[updatelist[i]]->setData(updatelist[i],false,emsData.getLocalRamBlock(updatelist[i])); - } - else - { - m_rawDataMap[updatelist[i]]->setData(updatelist[i],true,emsData.getLocalFlashBlock(updatelist[i])); - } - } - - if (m_locIdToConfigListMap.contains(updatelist[i])) - { - for (int j=0;jsetData(emsData.getLocalFlashBlock(updatelist[i])); - } - } - } -} -void FreeEmsComms::copyFlashToRam(unsigned short locationid) -{ - emsData.setLocalRamBlock(locationid,emsData.getLocalFlashBlock(locationid)); - if (m_2dTableMap.contains(locationid)) - { - m_2dTableMap[locationid]->setData(locationid,!emsData.hasLocalRamBlock(locationid),emsData.getLocalRamBlock(locationid),m_metaDataParser->get2DMetaData(locationid),false); - } - if (m_3dTableMap.contains(locationid)) - { - m_3dTableMap[locationid]->setData(locationid,!emsData.hasLocalRamBlock(locationid),emsData.getLocalRamBlock(locationid),m_metaDataParser->get3DMetaData(locationid)); - } - if (m_rawDataMap.contains(locationid)) - { - if (emsData.hasLocalRamBlock(locationid)) - { - m_rawDataMap[locationid]->setData(locationid,false,emsData.getLocalRamBlock(locationid)); - } - else - { - m_rawDataMap[locationid]->setData(locationid,true,emsData.getLocalFlashBlock(locationid)); - } - } - - if (m_locIdToConfigListMap.contains(locationid)) - { - for (int i=0;isetData(emsData.getLocalRamBlock(locationid)); - } - } - updateBlockInRam(locationid,0,emsData.getLocalFlashBlock(locationid).size(),emsData.getLocalFlashBlock(locationid)); - - for (int i=emsData.getLocalRamBlockInfo(locationid)->ramAddress;iramAddress+emsData.getLocalRamBlockInfo(locationid)->size;i++) - { - if (m_dirtyRamAddresses.contains(i)) - { - m_dirtyRamAddresses.removeOne(i); - } - } - if (m_dirtyRamAddresses.size() == 0) - { - emit memoryClean(); - } -} - -void FreeEmsComms::copyRamToFlash(unsigned short locationid) -{ - emsData.setLocalFlashBlock(locationid,emsData.getLocalRamBlock(locationid)); - emsData.setDeviceFlashBlock(locationid,emsData.getDeviceRamBlock(locationid)); - burnBlockFromRamToFlash(locationid,0,0); -} - -void FreeEmsComms::dataLogWrite(QByteArray buffer) -{ - if (m_logsEnabled) - { - if (m_debugLogsEnabled) - { - m_logOutFile->write(buffer); - m_logInOutFile->write(buffer); - } - } -} - - -void FreeEmsComms::dataLogRead(QByteArray buffer) -{ - if (m_logsEnabled) - { - m_logInFile->write(buffer); - if (m_debugLogsEnabled) - { - m_logInOutFile->write(buffer); - } - } -} - -void FreeEmsComms::parseEverything(QByteArray buffer) -{ - Packet p = m_packetDecoder->parseBuffer(buffer); - if (!p.isValid) - { - emit decoderFailure(buffer); - } - else - { - m_packetDecoder->parsePacket(p); - //parsePacket(p); - } -} -void FreeEmsComms::ramBlockUpdateRec(QByteArray header,QByteArray payload) -{ - if (m_currentWaitingRequest.args.size() == 0) - { - QLOG_ERROR() << "ERROR! Current waiting packet's arg size is zero1!!"; - QLOG_ERROR() << "0x" + QString::number(m_currentWaitingRequest.type,16).toUpper(); - //QLOG_ERROR() << "0x" + QString::number(payloadid,16).toUpper(); - } - unsigned short locationid = m_currentWaitingRequest.args[0].toInt(); - emsData.ramBlockUpdate(locationid,header,payload); -} - -void FreeEmsComms::flashBlockUpdateRec(QByteArray header,QByteArray payload) -{ - if (m_currentWaitingRequest.args.size() == 0) - { - QLOG_ERROR() << "ERROR! Current waiting packet's arg size is zero1!!"; - QLOG_ERROR() << "0x" + QString::number(m_currentWaitingRequest.type,16).toUpper(); - //QLOG_ERROR() << "0x" + QString::number(payloadid,16).toUpper(); - } - unsigned short locationid = m_currentWaitingRequest.args[0].toInt(); - emsData.flashBlockUpdate(locationid,header,payload); -} - -void FreeEmsComms::locationIdInfoRec(MemoryLocationInfo info) -{ - if (m_currentWaitingRequest.args.size() == 0) - { - QLOG_ERROR() << "ERROR! Current waiting packet's arg size is zero1!!"; - QLOG_ERROR() << "0x" + QString::number(m_currentWaitingRequest.type,16).toUpper(); - //QLOG_ERROR() << "0x" + QString::number(payloadid,16).toUpper(); - } - unsigned short locationid = m_currentWaitingRequest.args[0].toInt(); - info.locationid = locationid; - emit locationIdInfo(locationid,info); - emsData.passLocationInfo(locationid,info); - QLOG_DEBUG() << "Got memory location:" << info.locationid; - if (info.type == DATA_TABLE_2D) - { - Table2DData *data = new FETable2DData(); - connect(data,SIGNAL(saveSingleDataToRam(unsigned short,unsigned short,unsigned short,QByteArray)),&emsData,SLOT(ramBytesLocalUpdate(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(data,SIGNAL(saveSingleDataToFlash(unsigned short,unsigned short,unsigned short,QByteArray)),&emsData,SLOT(flashBytesLocalUpdate(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(data,SIGNAL(requestBlockFromRam(unsigned short,unsigned short,unsigned short)),this,SLOT(retrieveBlockFromRam(unsigned short,unsigned short,unsigned short))); - connect(data,SIGNAL(requestBlockFromFlash(unsigned short,unsigned short,unsigned short)),this,SLOT(retrieveBlockFromFlash(unsigned short,unsigned short,unsigned short))); - connect(data,SIGNAL(requestRamUpdateFromFlash(unsigned short)),this,SLOT(copyFlashToRam(unsigned short))); - connect(data,SIGNAL(requestFlashUpdateFromRam(unsigned short)),this,SLOT(copyRamToFlash(unsigned short))); - m_2dTableMap[locationid] = data; - } - else if (info.type == DATA_TABLE_3D) - { - Table3DData *data = new FETable3DData(); - connect(data,SIGNAL(saveSingleDataToRam(unsigned short,unsigned short,unsigned short,QByteArray)),&emsData,SLOT(ramBytesLocalUpdate(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(data,SIGNAL(saveSingleDataToFlash(unsigned short,unsigned short,unsigned short,QByteArray)),&emsData,SLOT(flashBytesLocalUpdate(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(data,SIGNAL(requestBlockFromRam(unsigned short,unsigned short,unsigned short)),this,SLOT(retrieveBlockFromRam(unsigned short,unsigned short,unsigned short))); - connect(data,SIGNAL(requestBlockFromFlash(unsigned short,unsigned short,unsigned short)),this,SLOT(retrieveBlockFromFlash(unsigned short,unsigned short,unsigned short))); - connect(data,SIGNAL(requestRamUpdateFromFlash(unsigned short)),this,SLOT(copyFlashToRam(unsigned short))); - connect(data,SIGNAL(requestFlashUpdateFromRam(unsigned short)),this,SLOT(copyRamToFlash(unsigned short))); - m_3dTableMap[locationid] = data; - } - else - { - RawData *data = new FERawData(); - connect(data,SIGNAL(saveSingleDataToRam(unsigned short,unsigned short,unsigned short,QByteArray)),&emsData,SLOT(ramBytesLocalUpdate(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(data,SIGNAL(saveSingleDataToFlash(unsigned short,unsigned short,unsigned short,QByteArray)),&emsData,SLOT(flashBytesLocalUpdate(unsigned short,unsigned short,unsigned short,QByteArray))); - connect(data,SIGNAL(requestBlockFromRam(unsigned short,unsigned short,unsigned short)),this,SLOT(retrieveBlockFromRam(unsigned short,unsigned short,unsigned short))); - connect(data,SIGNAL(requestBlockFromFlash(unsigned short,unsigned short,unsigned short)),this,SLOT(retrieveBlockFromFlash(unsigned short,unsigned short,unsigned short))); - m_rawDataMap[locationid] = data; - } -} -void FreeEmsComms::ramLocationMarkedDirty(unsigned short locationid) -{ - emit ramLocationDirty(locationid); -} - -void FreeEmsComms::flashLocationMarkedDirty(unsigned short locationid) -{ - emit flashLocationDirty(locationid); - -} -void FreeEmsComms::acceptLocalChanges() -{ - for (int i=0;i -#include -#include -#include -#include -#include -#include "serialport.h" -#include "serialrxthread.h" -#include "emscomms.h" -#include "fedatapacketdecoder.h" -#include "fememorymetadata.h" -#include "table3ddata.h" -#include "table2ddata.h" -#include "emsdata.h" -#include "ferawdata.h" -#include "packet.h" -#include "packetdecoder.h" -#include "feconfigdata.h" - -class FreeEmsComms : public EmsComms -{ - Q_OBJECT - Q_INTERFACES(EmsComms) -public: - FreeEmsComms(QObject *parent = 0); - ~FreeEmsComms(); - QString getPluginCompat() { return QString("FREEEMS"); } - DataPacketDecoder *getDecoder(); - MemoryMetaData *getMetaParser(); - Table3DData *getNew3DTableData(); - Table2DData *getNew2DTableData(); - void passLogger(QsLogging::Logger *log); - void stop() { m_terminateLoop = true; } - void setLogsEnabled(bool enabled); - void setLogDirectory(QString dir); - void setPort(QString portname); - void setBaud(int baudrate); - void setLogFileName(QString filename); - bool sendPacket(unsigned short payloadid,QList arglist=QList(),QList argsizelist=QList(),bool haslength=false); - int getLocationIdInfo(unsigned short locationid); - int getInterfaceVersion(); - int getFirmwareVersion(); - int getMaxPacketSize(); - int getDecoderName(); - int getFirmwareBuildDate(); - int getCompilerVersion(); - int getSupportEmail(); - int getBuiltByName(); - int getOperatingSystem(); - int echoPacket(QByteArray packet); - Q_INVOKABLE int startBenchTest(unsigned char eventspercycle,unsigned short numcycles,unsigned short ticksperevent,QVariantList pineventmask,QVariantList pinmode); - Q_INVOKABLE int stopBenchTest(); - Q_INVOKABLE int bumpBenchTest(unsigned char cyclenum); - int getLocationIdList(unsigned char listtype, unsigned short listmask); - int softReset(); - int hardReset(); - bool sendSimplePacket(unsigned short payload); - void connectSerial(QString port,int baud); - void disconnectSerial(); - void loadLog(QString filename); - void playLog(); - void startInterrogation(); - QByteArray generatePacket(QByteArray header,QByteArray payload); - void setInterByteSendDelay(int milliseconds); - void setlogsDebugEnabled(bool enabled); - void verifyRamFromDevice(quint64 checksum); - int enableDatalogStream(); - int disableDatalogStream(); - Table2DData* get2DTableData(unsigned short locationid); - Table3DData* get3DTableData(unsigned short locationid); - Table2DData* get2DTableData(QString locationname); - Table3DData* get3DTableData(QString locationname); - RawData* getRawData(unsigned short locationid); - ConfigData* getConfigData(QString name); - QList getConfigList(); - void writeAllRamToRam(); - void acceptLocalChanges(); - void rejectLocalChanges(); -protected: - void run(); -private: - - - - - class RequestClass - { - public: - RequestClass() - { - retryCount=0; - hasLength = false; - hasReply = false; - sentRequest = false; - } - bool sentRequest; //If the request can be directly passed to attemptSendPacket to be sent to the ECU. - - unsigned char retryCount; - bool hasLength; - bool hasReply; - RequestType type; - QList args; - QList argsize; - int sequencenumber; - void addArg(QVariant arg,int size=0) { args.append(arg); argsize.append(size);} - }; - bool m_isSilent; - quint64 m_lastDatalogTime; - QTimer *m_lastdatalogTimer; - bool m_lastDatalogUpdateEnabled; - bool m_isConnected; - FEDataPacketDecoder *dataPacketDecoder; - FEMemoryMetaData *m_metaDataParser; - bool m_debugLogsEnabled; - QMap m_blockFlagToNameMap; - bool m_terminateLoop; - QMutex m_waitingInfoMutex; - SerialRXThread *rxThread; - bool sendPacket(RequestClass request); - qint64 m_timeoutMsecs; - QList m_blockFlagList; - int m_sequenceNumber; - QMutex m_reqListMutex; - QList m_reqList; - QList m_threadReqList; - SerialPort *serialPort; - bool m_waitingForResponse; - bool m_logsEnabled; - QString m_logsDirectory; - QString m_logsFilename; - unsigned int m_payloadWaitingForResponse; - RequestClass m_currentWaitingRequest; - QFile *m_logInFile; - QFile *m_logOutFile; - QFile *m_logInOutFile; - void openLogs(); - bool m_interrogateInProgress; - bool m_interrogateIdListComplete; - bool m_interrogateIdInfoComplete; - bool m_interogateComplete; - bool m_waitingForRamWrite; - bool m_waitingForFlashWrite; - QList m_interrogatePacketList; - int m_interrogateTotalCount; - QList m_locationIdList; - EmsData emsData; - QMap m_2dTableMap; - QMap m_3dTableMap; - QMap m_rawDataMap; - QMap > m_locIdToConfigListMap; - QMap m_configMap; - PacketDecoder *m_packetDecoder; - QMap m_interrogationMetaDataMap; - void sendNextInterrogationPacket(); - QList m_dirtyRamAddresses; -signals: - void packetSent(unsigned short locationid,QByteArray header,QByteArray payload); - void packetAcked(unsigned short locationid,QByteArray header,QByteArray payload); - void packetNaked(unsigned short locationid,QByteArray header,QByteArray payload,unsigned short errornum); - void decoderFailure(QByteArray packet); - void connected(); - void disconnected(); - void locationIdList(QList idlist); - void locationIdInfo(unsigned short locationid,MemoryLocationInfo info); - void ramBlockRetrieved(unsigned short locationid, QByteArray header,QByteArray payload); - void flashBlockRetrieved(unsigned short locationid,QByteArray header,QByteArray payload); - void dataLogPayloadReceived(QByteArray header,QByteArray payload); - void debugVerbose(QString msg); - void unknownPacket(QByteArray header,QByteArray payload); - void debug(QString msg); - void error(QString msg); - void error(SerialPortStatus error,QString msg = QString()); - void commandSuccessful(int sequencenumber); - void commandFailed(int sequencenumber,unsigned short errornum); - void commandTimedOut(int sequencenumber); - void emsSilenceStarted(qint64 lastdatalogtime); - void emsSilenceBroken(); - void interrogateTaskStart(QString task, int sequence); - void interrogateTaskSucceed(int sequence); - void interrogateTaskFail(int sequence); - void interrogationProgress(int current, int total); - void interrogationComplete(); - void deviceDataUpdated(unsigned short locationid); - void interrogationData(QMap datamap); - void dataLogPayloadDecoded(QVariantMap data); - void resetDetected(int missedPackets); - void configRecieved(ConfigBlock,QVariant); - void memoryDirty(); - void memoryClean(); - void benchTestReply(unsigned short countRemaining,unsigned char currentEvent); - void flashLocationDirty(unsigned short locationid); - void ramLocationDirty(unsigned short locationid); -public slots: - int updateBlockInRam(unsigned short location,unsigned short offset, unsigned short size,QByteArray data); - int updateBlockInFlash(unsigned short location,unsigned short offset, unsigned short size,QByteArray data); - int retrieveBlockFromRam(unsigned short location, unsigned short offset, unsigned short size,bool mark=true); - int retrieveBlockFromFlash(unsigned short location, unsigned short offset, unsigned short size,bool mark=true); - int burnBlockFromRamToFlash(unsigned short location,unsigned short offset, unsigned short size); -private slots: - void dataLogPayloadReceivedRec(QByteArray header,QByteArray payload); - void ramBlockUpdateRec(QByteArray header,QByteArray payload); - void rxThreadPortGone(); - void ramLocationMarkedDirty(unsigned short locationid); - void flashLocationMarkedDirty(unsigned short locationid); - void flashBlockUpdateRec(QByteArray header,QByteArray payload); - void packetNakedRec(unsigned short payloadid,QByteArray header,QByteArray payload,unsigned short errornum); - void packetAckedRec(unsigned short payloadid,QByteArray header,QByteArray payload); - void locationIdInfoRec(MemoryLocationInfo info); - void locationIdListRec(QList locationidlist); - void datalogTimerTimeout(); - void dataLogWrite(QByteArray buffer); - void dataLogRead(QByteArray buffer); - void parseEverything(QByteArray buffer); - //Packet parseBuffer(QByteArray buffer); - void locationIdUpdate(unsigned short locationid); - void copyFlashToRam(unsigned short locationid); - void copyRamToFlash(unsigned short locationid); - void decoderName(QString name); - void firmwareBuild(QString date); - void compilerVersion(QString version); - void operatingSystem(QString os); - void interfaceVersion(QString version); - void firmwareVersion(QString version); - void builtByName(QString name); - void supportEmail(QString email); - - -}; - -#endif // FREEEMSCOMMS_H diff --git a/plugins/freeems/memorylocation.cpp b/plugins/freeems/memorylocation.cpp deleted file mode 100644 index d8f8c3b..0000000 --- a/plugins/freeems/memorylocation.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "memorylocation.h" -#include "QsLog.h" - -MemoryLocation::MemoryLocation() -{ - m_parent = 0; - parent=0; - hasParent = false; -} -void MemoryLocation::addChild(MemoryLocation *child) -{ - m_childList.append(child); -} -void MemoryLocation::setParent(MemoryLocation *parent) -{ - m_parent = parent; -} -void MemoryLocation::childChanged(MemoryLocation *child,QByteArray data) -{ - unsigned short childinparent=0; - if (isRam) - { - childinparent = child->ramAddress - this->ramAddress; - } - else - { - childinparent = child->flashAddress - this->flashAddress; - } - if (data.size() != child->size) - { - QLOG_ERROR() << "Error. Child tried to replace memory location not equal to its own size! Data size: " << data.size() << "Child size:" << child->size; - } - m_data.replace(childinparent,data.length(),data); -} -void MemoryLocation::setByteDirty(unsigned short offset) -{ - if (!m_dirty.contains(offset)) - { - m_dirty.append(offset); - } -} - -void MemoryLocation::setByteClean(unsigned short offset) -{ - if (m_dirty.contains(offset)) - { - m_dirty.removeOne(offset); - } -} - -bool MemoryLocation::MemoryLocation::isDirty() -{ - if (m_dirty.size() == 0) - { - return false; - } - else - { - return true; - } -} - -QByteArray MemoryLocation::data(MemoryLocation *child) -{ - unsigned short childinparent=0; - if (isRam) - { - childinparent = child->ramAddress - this->ramAddress; - } - else - { - childinparent = child->flashAddress - this->flashAddress; - } - return m_data.mid(childinparent,child->size); -} -bool MemoryLocation::isEmpty() -{ - if (this->data().size() == 0) - { - return true; - } - return false; -} - -QByteArray MemoryLocation::data() -{ - if (m_parent) - { - return m_parent->data(this); - } - else - { - return m_data; - } -} - -void MemoryLocation::setData(QByteArray data) -{ - if (m_parent) - { - m_parent->childChanged(this,data); - } - else - { - m_data = data; - } -} diff --git a/plugins/freeems/memorylocation.h b/plugins/freeems/memorylocation.h deleted file mode 100644 index c253031..0000000 --- a/plugins/freeems/memorylocation.h +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#ifndef MEMORYLOCATION_H -#define MEMORYLOCATION_H - -#include - -class MemoryLocation -{ -public: - explicit MemoryLocation(); - bool isFlash; - bool isRam; - bool hasParent; - bool isReadOnly; - int type; - unsigned short parent; - unsigned short ramPage; - unsigned short ramAddress; - unsigned short flashPage; - unsigned short flashAddress; - unsigned short size; - unsigned short locationid; - void addChild(MemoryLocation *child); - void setParent(MemoryLocation *parent); - MemoryLocation *getParent() { return m_parent; } - void setData(QByteArray data); - bool isEmpty(); - void childChanged(MemoryLocation *child,QByteArray data); - QByteArray data(MemoryLocation *child); - QByteArray data(); - void setByteDirty(unsigned short offset); - void setByteClean(unsigned short offset); - bool isDirty(); -private: - QByteArray m_data; - QList m_dirty; - QList m_childList; - MemoryLocation *m_parent; -signals: - -public slots: - -}; - -#endif // MEMORYLOCATION_H diff --git a/plugins/freeems/packet.h b/plugins/freeems/packet.h deleted file mode 100644 index 96c487f..0000000 --- a/plugins/freeems/packet.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef PACKET_H -#define PACKET_H - -enum LocationIdFlags -{ - BLOCK_HAS_PARENT=0x0001, - BLOCK_IS_RAM=0x0002, - BLOCK_IS_FLASH=0x0004, - BLOCK_IS_INDEXABLE=0x0008, - BLOCK_IS_READ_ONLY=0x0010, - BLOCK_GETS_VERIFIED=0x0020, - BLOCK_FOR_BACKUP_RESTORE=0x0040, - BLOCK_SPARE_7=0x0080, - BLOCK_SPARE_8=0x0100, - BLOCK_SPARE_9=0x0200, - BLOCK_SPARE_10=0x0400, - BLOCK_IS_2D_SIGNED_TABLE=0x0800, - BLOCK_IS_2D_TABLE=0x1000, - BLOCK_IS_MAIN_TABLE=0x2000, - BLOCK_IS_LOOKUP_DATA=0x4000, - BLOCK_IS_CONFIGURATION=0x8000 -}; -enum RequestType -{ - GET_INTERFACE_VERSION=0x0000, - GET_FIRMWARE_VERSION=0x0002, - GET_MAX_PACKET_SIZE=0x0004, - ECHO_PACKET=0x0006, - SOFT_RESET=0x0008, - HARD_RESET=0x000A, - UPDATE_BLOCK_IN_RAM=0x0100, - UPDATE_BLOCK_IN_FLASH=0x0102, - RETRIEVE_BLOCK_IN_RAM=0x0104, - RETRIEVE_BLOCK_IN_FLASH=0x0106, - BURN_BLOCK_FROM_RAM_TO_FLASH=0x0108, - BENCHTEST=0x8888, - GET_LOCATION_ID_LIST=0xDA5E, - GET_DECODER_NAME=0xEEEE, - GET_FIRMWARE_BUILD_DATE=0xEEF0, - GET_COMPILER_VERSION=0xEEF2, - GET_OPERATING_SYSTEM=0xEEF4, - GET_BUILT_BY_NAME=0xEEF6, - GET_SUPPORT_EMAIL=0xEEF8, - GET_LOCATION_ID_INFO=0xF8E0, - SERIAL_CONNECT=0xFFFF01, - SERIAL_DISCONNECT=0xFFFF02, - INTERROGATE_START=0xFFFF03 -}; - -class Packet -{ -public: - Packet(bool valid = true) { isValid = valid; } - bool isNAK; - bool isValid; - QByteArray header; - QByteArray payload; - unsigned short payloadid; - unsigned short length; - bool haslength; - bool hasseq; - unsigned short sequencenum; -}; -#endif // PACKET_H diff --git a/plugins/freeems/packetdecoder.cpp b/plugins/freeems/packetdecoder.cpp deleted file mode 100644 index 7f37378..0000000 --- a/plugins/freeems/packetdecoder.cpp +++ /dev/null @@ -1,491 +0,0 @@ -#include "packetdecoder.h" -#include "QsLog.h" -#include -#include "memorylocationinfo.h" - -#define NAK 0x02 - -PacketDecoder::PacketDecoder(QObject *parent) : QObject(parent) -{ - m_blockFlagList.append(BLOCK_HAS_PARENT); - m_blockFlagList.append(BLOCK_IS_RAM); - m_blockFlagList.append(BLOCK_IS_FLASH); - m_blockFlagList.append(BLOCK_IS_INDEXABLE); - m_blockFlagList.append(BLOCK_IS_READ_ONLY); - m_blockFlagList.append(BLOCK_GETS_VERIFIED); - m_blockFlagList.append(BLOCK_FOR_BACKUP_RESTORE); - m_blockFlagList.append(BLOCK_SPARE_7); - m_blockFlagList.append(BLOCK_SPARE_8); - m_blockFlagList.append(BLOCK_SPARE_9); - m_blockFlagList.append(BLOCK_SPARE_10); - m_blockFlagList.append(BLOCK_IS_2D_SIGNED_TABLE); - m_blockFlagList.append(BLOCK_IS_2D_TABLE); - m_blockFlagList.append(BLOCK_IS_MAIN_TABLE); - m_blockFlagList.append(BLOCK_IS_LOOKUP_DATA); - m_blockFlagList.append(BLOCK_IS_CONFIGURATION); - - - m_blockFlagToNameMap[BLOCK_HAS_PARENT] = "Parent"; - m_blockFlagToNameMap[BLOCK_IS_RAM] = "Is Ram"; - m_blockFlagToNameMap[BLOCK_IS_FLASH] = "Is Flash"; - m_blockFlagToNameMap[BLOCK_IS_INDEXABLE] = "Is Indexable"; - m_blockFlagToNameMap[BLOCK_IS_READ_ONLY] = "Is Read Only"; - m_blockFlagToNameMap[BLOCK_FOR_BACKUP_RESTORE] = "For Backup"; - m_blockFlagToNameMap[BLOCK_GETS_VERIFIED] = "Is Verified"; - m_blockFlagToNameMap[BLOCK_IS_2D_TABLE] = "2D Table"; - m_blockFlagToNameMap[BLOCK_IS_2D_SIGNED_TABLE] = "2D Signed Table"; - m_blockFlagToNameMap[BLOCK_IS_MAIN_TABLE] = "3D Table"; - m_blockFlagToNameMap[BLOCK_IS_LOOKUP_DATA] = "Lookup Table"; - m_blockFlagToNameMap[BLOCK_IS_CONFIGURATION] = "Configuration"; -} - - -Packet PacketDecoder::parseBuffer(QByteArray buffer) -{ - if (buffer.size() <= 2) - { - - QLOG_ERROR() << "Not long enough to even contain a header!"; - //emit decoderFailure(buffer); - return Packet(false); - } - - - Packet retval; - QByteArray header; - //Parse the packet here - int headersize = 3; - int iloc = 0; - bool seq = false; - bool len = false; - if (buffer[iloc] & 0x100) - { - //Has header - seq = true; - headersize += 1; - } - if (buffer[iloc] & 0x1) - { - //Has length - len = true; - headersize += 2; - } - header = buffer.mid(0,headersize); - iloc++; - unsigned int payloadid = (unsigned int)buffer[iloc] << 8; - - payloadid += (unsigned char)buffer[iloc+1]; - retval.payloadid = payloadid; - iloc += 2; - if (seq) - { - iloc += 1; - retval.hasseq = true; - } - else - { - retval.hasseq = false; - } - QByteArray payload; - if (len) - { - retval.haslength = true; - unsigned int length = buffer[iloc] << 8; - length += (unsigned char)buffer[iloc+1]; - retval.length = length; - iloc += 2; - if ((unsigned int)buffer.length() > (unsigned int)(length + iloc)) - { - QLOG_ERROR() << "Packet length should be:" << length + iloc << "But it is" << buffer.length(); - //emit decoderFailure(buffer); - return Packet(false); - } - payload.append(buffer.mid(iloc,length)); - } - else - { - retval.haslength = false; - payload.append(buffer.mid(iloc),(buffer.length()-iloc)); - } - QString output; - for (int i=0;i= 3) - { - return retval; - } - else - { - return Packet(false); - } -} -void PacketDecoder::parsePacket(Packet parsedPacket) -{ - if (parsedPacket.isValid) - { - //QMutexLocker locker(&m_waitingInfoMutex); - unsigned short payloadid = parsedPacket.payloadid; - - //if (m_isSilent) - //{ - // emit emsSilenceBroken(); - // m_isSilent = false; - //} - if (payloadid == 0x0191) - { //Datalog packet - - if (parsedPacket.isNAK) - { - //NAK - } - else - { - emit dataLogPayloadReceived(parsedPacket.header,parsedPacket.payload); - } - } - else if (payloadid == 0xEEEF) - { - //Decoder - if (!(parsedPacket.isNAK)) - { - emit decoderName(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0xEEF1) - { - //Firmware build date - if (!(parsedPacket.isNAK)) - { - emit firmwareBuild(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0xEEF3) - { - //Compiler Version - if (!(parsedPacket.isNAK)) - { - emit compilerVersion(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0xEEF5) - { - //Operating System - if (!(parsedPacket.isNAK)) - { - emit operatingSystem(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0xEEF7) - { - //Built By Name - if (!(parsedPacket.isNAK)) - { - emit builtByName(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0xEEF9) - { - //Support Email - if (!(parsedPacket.isNAK)) - { - emit supportEmail(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0xDA5F) - { - //Location ID List - if (parsedPacket.isNAK) - { - } - else - { - //TODO double check to make sure that there aren't an odd number of items here... - QLOG_DEBUG() << "Location ID List"; - QString details = "Details: {"; - for (int j=0;j locationidlist; - for (int j=0;j flaglist; - if (parsedPacket.payload.size() >= 2) - { - MemoryLocationInfo info; - unsigned short test = parsedPacket.payload[0] << 8; - unsigned short parent; - unsigned char rampage; - unsigned char flashpage; - unsigned short ramaddress; - unsigned short flashaddress; - unsigned short size; - test += parsedPacket.payload[1]; - - for (int j=0;j(m_blockFlagToNameMap[m_blockFlagList[j]],"true")); - } - } - else - { - if (m_blockFlagToNameMap.contains(m_blockFlagList[j])) - { - info.propertymap.append(QPair(m_blockFlagToNameMap[m_blockFlagList[j]],"false")); - } - } - } - parent = ((unsigned char)parsedPacket.payload[2]) << 8; - parent += (unsigned char)parsedPacket.payload[3]; - rampage = (unsigned char)parsedPacket.payload[4]; - flashpage = (unsigned char)parsedPacket.payload[5]; - ramaddress = ((unsigned char)parsedPacket.payload[6]) << 8; - ramaddress += (unsigned char)parsedPacket.payload[7]; - flashaddress = ((unsigned char)parsedPacket.payload[8]) << 8; - flashaddress += (unsigned char)parsedPacket.payload[9]; - size = ((unsigned char)parsedPacket.payload[10]) << 8; - size += (unsigned char)parsedPacket.payload[11]; - - //info.locationid = locationid; - info.parent = parent; - info.ramaddress = ramaddress; - info.rampage = rampage; - info.flashaddress = flashaddress; - info.flashpage = flashpage; - info.rawflags = test; - info.size = size; - - info.propertymap.append(QPair("parent","0x" + QString::number(parent,16).toUpper())); - info.propertymap.append(QPair("rampage","0x" + QString::number(rampage,16).toUpper())); - info.propertymap.append(QPair("flashpage","0x" + QString::number(flashpage,16).toUpper())); - info.propertymap.append(QPair("ramaddress","0x" + QString::number(ramaddress,16).toUpper())); - info.propertymap.append(QPair("flashaddress","0x" + QString::number(flashaddress,16).toUpper())); - info.propertymap.append(QPair("size","0x" + QString::number(size,16).toUpper())); - - if (flaglist.contains(BLOCK_IS_RAM)) - { - info.isRam = true; - } - else - { - info.isRam = false; - } - if (flaglist.contains(BLOCK_IS_FLASH)) - { - info.isFlash = true; - } - else - { - info.isFlash = false; - } - if (flaglist.contains(BLOCK_HAS_PARENT)) - { - info.hasParent = true; - } - else - { - info.hasParent = false; - } - if (flaglist.contains(BLOCK_IS_READ_ONLY)) - { - info.isReadOnly = true; - } - if (flaglist.contains(BLOCK_IS_2D_TABLE)) - { - info.type = DATA_TABLE_2D; - } - else if (flaglist.contains(BLOCK_IS_2D_SIGNED_TABLE)) - { - info.type = DATA_TABLE_2D_SIGNED; - } - else if (flaglist.contains(BLOCK_IS_MAIN_TABLE)) - { - info.type = DATA_TABLE_3D; - } - else if (flaglist.contains(BLOCK_IS_CONFIGURATION)) - { - info.type = DATA_CONFIG; - } - else if (flaglist.contains(BLOCK_IS_LOOKUP_DATA)) - { - info.type = DATA_TABLE_LOOKUP; - } - else - { - info.type = DATA_UNDEFINED; - } - emit locationIdInfo(info); - //emsData.passLocationInfo(locationid,info); - - } - - - } - } - else if (payloadid == 0x0001) //Interface version response - { - //Handle interface version - if (parsedPacket.isNAK) - { - //NAK - QLOG_ERROR() << "IFACE VERSION NAK"; - } - else - { - emit interfaceVersion(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0x0003) //Firmware version response - { - if (parsedPacket.isNAK) - { - //NAK - QLOG_ERROR() << "FIRMWARE VERSION NAK"; - } - else - { - emit firmwareVersion(QString(parsedPacket.payload)); - } - } - else if (payloadid == 0x0107) - { - if (parsedPacket.isNAK) - { - } - else - { - //unsigned short locid = m_currentWaitingRequest.args[0].toUInt(); - //emit flashBlockRetrieved(locid,parsedPacket.header,parsedPacket.payload); - //emsData.flashBlockUpdate(locid,parsedPacket.header,parsedPacket.payload); - emit flashBlockUpdatePacket(parsedPacket.header,parsedPacket.payload); - } - } - else if (payloadid == 0x0105) - { - if (parsedPacket.isNAK) - { - } - else - { - //Block from ram is here. - //unsigned short locid = m_currentWaitingRequest.args[0].toUInt(); - //emit ramBlockRetrieved(locid,parsedPacket.header,parsedPacket.payload); - //emsData.ramBlockUpdate(locid,parsedPacket.header,parsedPacket.payload); - emit ramBlockUpdatePacket(parsedPacket.header,parsedPacket.payload); - } - } - else if (payloadid == BENCHTEST+1) - { - if (!parsedPacket.isNAK) - { - if (parsedPacket.payload.size() == 3) - { - unsigned short count = 0; - count += ((unsigned char)parsedPacket.payload.at(0)) << 8; - count += ((unsigned char)parsedPacket.payload.at(1)); - unsigned char event = 0; - event = ((unsigned char)parsedPacket.payload.at(2)); - emit benchTestReply(count,event); - } - } - } - else - { - emit unknownPacket(parsedPacket.header,parsedPacket.payload); - } - if (payloadid == 0x0191) - { - //m_lastDatalogUpdateEnabled = true; - //m_lastDatalogTime = QDateTime::currentMSecsSinceEpoch(); - - //Need to pull sequence number out of here - } - else - { - if (parsedPacket.isNAK) - { - unsigned short errornum = ((unsigned char)parsedPacket.payload[0]) << 8; - errornum += ((unsigned char)parsedPacket.payload[1]); - emit packetNaked(payloadid,parsedPacket.header,parsedPacket.payload,errornum); - return; - } - emit packetAcked(payloadid,parsedPacket.header,parsedPacket.payload); - - } - - - } - else - { - QLOG_FATAL() << "Header size is only" << parsedPacket.header.length() << "! THIS SHOULD NOT HAPPEN!"; - QString headerstring = ""; - QString packetstring = ""; - for (int i=0;i -#include "packet.h" -#include "memorylocationinfo.h" -#include - -class PacketDecoder : public QObject -{ - Q_OBJECT -public: - explicit PacketDecoder(QObject *parent = 0); - Packet parseBuffer(QByteArray buffer); -public slots: - void parsePacket(Packet parsedPacket); -private: - QList m_blockFlagList; - QMap m_blockFlagToNameMap; -signals: - void decoderName(QString name); - void firmwareBuild(QString version); - void compilerVersion(QString version); - void operatingSystem(QString version); - void dataLogPayloadReceived(QByteArray header,QByteArray payload); - void interfaceVersion(QString version); - void firmwareVersion(QString version); - void builtByName(QString name); - void supportEmail(QString email); - void unknownPacket(QByteArray header,QByteArray payload); - void commandSuccessful(int sequencenum); - void commandFailed(int sequencenum,unsigned short errornum); - void packetNaked(unsigned short payloadid,QByteArray header,QByteArray payload,unsigned short errornum); - void packetAcked(unsigned short payloadid,QByteArray header,QByteArray payload); - void locationIdList(QList locationidlist); - void locationIdInfo(MemoryLocationInfo info); - void flashBlockUpdatePacket(QByteArray header,QByteArray payload); - void ramBlockUpdatePacket(QByteArray header,QByteArray payload); - void benchTestReply(unsigned short countRemaining,unsigned char currentEvent); -}; - -#endif // PACKETDECODER_H diff --git a/plugins/freeems/serialport.cpp b/plugins/freeems/serialport.cpp deleted file mode 100644 index 3aa8826..0000000 --- a/plugins/freeems/serialport.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "serialport.h" -#include -#include -#include -#include "QsLog.h" - -SerialPort::SerialPort(QObject *parent) : QObject(parent) -{ - m_serialLockMutex = new QMutex(); - m_interByteSendDelay=0; - m_inpacket = false; - m_inescape = false; - m_packetErrorCount=0; - m_serialPort = new QSerialPort(); -} -void SerialPort::setPort(QString portname) -{ - m_portName = portname; -} -void SerialPort::setBaud(int baudrate) -{ - m_baud = baudrate; -} - -SerialPortStatus SerialPort::isSerialMonitor(QString portname) -{ - if (openPort(portname,115200,false) < 0) - { - return NONE; - } - int retry = 0; - - while (retry++ <= 3) - { - //m_port->clear(); - //m_port->flush(); - //m_privBuffer.clear(); - writeBytes(QByteArray().append(0x0D)); - QByteArray verifybuf; - int verifylen = readBytes(&verifybuf,3,1000); - qDebug() << "Verify len:" << verifylen; - if ((unsigned char)verifybuf[0] == 0xE0) - { - if ((unsigned char)verifybuf[2] == 0x3E) - { - qDebug() << "In SM mode"; - closePort(); - return SM_MODE; - } - } - else if ((unsigned char)verifybuf[0] == 0xE1) - { - if ((unsigned char)verifybuf[2] == 0x3E) - { - qDebug() << "In SM mode two"; - closePort(); - return SM_MODE; - } - } - else - { - //Likely not in SM mode - //qDebug() << "Bad return:" << QString::number((unsigned char)verifybuf[0],16) << QString::number((unsigned char)verifybuf[2],16); - } - } - //Timed out. - closePort(); - return NONE; -} - -void SerialPort::setInterByteSendDelay(int milliseconds) -{ - m_interByteSendDelay = milliseconds; -} - -int SerialPort::readBytes(QByteArray *array, int maxlen,int timeout) -{ - QMutexLocker locker(m_serialLockMutex); - if (m_privBuffer.size() >= maxlen) - { - *array = m_privBuffer.mid(0,maxlen); - m_privBuffer.remove(0,maxlen); - return maxlen; - } - while (m_serialPort->waitForReadyRead(timeout)) - { - m_privBuffer.append(m_serialPort->readAll()); - if (m_privBuffer.size() >= maxlen) - { - *array = m_privBuffer.mid(0,maxlen); - m_privBuffer.remove(0,maxlen); - return maxlen; - } - } - return 0; -} - -int SerialPort::writeBytes(QByteArray packet) -{ - QMutexLocker locker(m_serialLockMutex); - if (m_interByteSendDelay > 0) - { - for (int i=0;iwrite(QByteArray().append(packet.at(i))) == -1) - { - //TODO: Error here - QLOG_ERROR() << "Serial write error" << m_serialPort->errorString(); - return -1; - } - m_serialPort->waitForBytesWritten(1); //Verify. - //usleep(m_interByteSendDelay * 1000); - } - - } - else - { - if (m_serialPort->write(packet) == -1) - { - QLOG_ERROR() << "Serial write error" << m_serialPort->errorString(); - return -1; - } - m_serialPort->waitForBytesWritten(1); //Verify. - } - return packet.size(); - -} - -void SerialPort::closePort() -{ - QLOG_DEBUG() << "SerialPort::closePort thread:" << QThread::currentThread(); - m_serialPort->close(); - //delete m_serialPort; - m_privBuffer.clear(); -} - -int SerialPort::openPort(QString portName,int baudrate,bool oddparity) -{ - //QLOG_DEBUG() << "SerialPort::openPort thread:" << QThread::currentThread(); - //m_serialPort = new QSerialPort(); - m_portName = portName; - m_serialPort->setPortName(portName); - if (!m_serialPort->open(QIODevice::ReadWrite)) - { - return -1; - } - m_serialPort->setBaudRate(baudrate); - if (oddparity) - { - m_serialPort->setParity(QSerialPort::OddParity); - } - else - { - m_serialPort->setParity(QSerialPort::NoParity); - } - return 0; -} diff --git a/plugins/freeems/serialport.h b/plugins/freeems/serialport.h deleted file mode 100644 index 51402c4..0000000 --- a/plugins/freeems/serialport.h +++ /dev/null @@ -1,84 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#ifndef SERIALPORT_H -#define SERIALPORT_H -#include -#include -#include -#include -#include -#include -#include "serialportstatus.h" -#include "memorylocationinfo.h" -#ifdef Q_OS_WIN -//#include -#else -//#define HANDLE int -//#include -//#include -//#include -//#include -//#include -//#include -#endif -#include "qserialport.h" - -class SerialPort : public QObject -{ - Q_OBJECT -public: - SerialPort(QObject *parent=0); - SerialPortStatus isSerialMonitor(QString portname); - void setPort(QString portname); - void setBaud(int baudrate); - int openPort(QString portName,int baudrate,bool oddparity = true); - void closePort(); - int writeBytes(QByteArray bytes); - //int readBytes(unsigned char *buf,int maxlen); - int readBytes(QByteArray *array, int maxlen,int timeout=0); - int bufferSize() { return m_queuedMessages.size(); } - void setInterByteSendDelay(int milliseconds); - QString portName() { return m_portName; } -private: - QSerialPort *m_serialPort; - QByteArray m_privBuffer; - QMutex *m_serialLockMutex; - void openLogs(); - unsigned int m_packetErrorCount; - bool m_logsEnabled; - QString m_logDirectory; - bool m_inpacket; - bool m_inescape; - int m_interByteSendDelay; - QList m_queuedMessages; - QByteArray m_buffer; - QString m_logFileName; - QString m_portName; - int m_baud; - //HANDLE m_portHandle; - -signals: - void parseBuffer(QByteArray buffer); - void dataWritten(QByteArray data); -}; - -#endif // SERIALPORT_H diff --git a/plugins/freeems/serialrxthread.cpp b/plugins/freeems/serialrxthread.cpp deleted file mode 100644 index 1558e1e..0000000 --- a/plugins/freeems/serialrxthread.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/************************************************************************************ - * EMStudio - Open Source ECU tuning software * - * Copyright (C) 2013 Michael Carpenter (malcom2073@gmail.com) * - * * - * This file is a part of EMStudio * - * * - * EMStudio is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, version * - * 2.1 of the License. * - * * - * EMStudio is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ************************************************************************************/ - -#include "serialrxthread.h" -#include -#include -#include "QsLog.h" - -SerialRXThread::SerialRXThread(QObject *parent) : QThread(parent) -{ - m_terminate = false; -} -void SerialRXThread::start(SerialPort *serialport) -{ - m_serialPort = serialport; - QThread::start(); -} -SerialRXThread::~SerialRXThread() -{ - m_terminate = true; - //this->terminate(); - //this->wait(1000); -} -QByteArray SerialRXThread::readSinglePacket(SerialPort *port) -{ - - QByteArray qbuf; - int len = 0; - bool m_inpacket = false; - bool m_inescape = false; - QByteArray qbuffer; - int attempts = 0; //This allows for a 2 second timeout. - while (attempts <= 50) - { - len = port->readBytes(&qbuf,1); - if (len < 0) - { - QLOG_DEBUG() << "Timeout"; - } - else if (len == 0) - { - //This should be an error - QLOG_DEBUG() << "Nothing to read:" << attempts; - msleep(10); //Need a sleep now, due to select timeout. - attempts++; - continue; - } - else - { - unsigned char buf = (unsigned char)qbuf.at(0); - if (buf == 0xAA) - { - if (m_inpacket) - { - //Start byte in the middle of a packet - //Clear out the buffer and start fresh - m_inescape = false; - QLOG_DEBUG() << "Buffer error" << qbuffer.size(); - qbuffer.clear(); - } - //Start of packet - m_inpacket = true; - } - else if (buf == 0xCC && m_inpacket) - { - //End of packet - m_inpacket = false; - - //New Location of checksum - unsigned char sum = 0; - for (int i=0;i 1500) - { - //Every second, check that the port still exists. - msecs = QDateTime::currentMSecsSinceEpoch(); - bool found = false; - foreach(QSerialPortInfo info,QSerialPortInfo::availablePorts()) - { - if (m_serialPort->portName().contains(info.portName())) - { - found = true; - } - } - if (!found) - { - emit portGone(); - return; - } - - } - readlen = m_serialPort->readBytes(&buffer,100); - if (readlen < 0) - { - //Nothing on the port - QLOG_DEBUG() << "Timeout"; - } - if (readlen == 0) - { - //This should be an error - msleep(10); //Need a sleep now, due to select timeout. - continue; - } - for (int i=0;i(buffer[i]); - if (buf == 0xAA) - { - if (m_inpacket) - { - //Start byte in the middle of a packet - //Clear out the buffer and start fresh - m_inescape = false; - QByteArray bufToEmit; - bufToEmit.append(0xAA); - QByteArray nbuffer(qbuffer); - nbuffer.replace(0xBB,QByteArray().append(0xBB).append(0x44)); - nbuffer.replace(0xAA,QByteArray().append(0xBB).append(0x55)); - nbuffer.replace(0xCC,QByteArray().append(0xBB).append(0x33)); - bufToEmit.append(nbuffer); - bufToEmit.append(0xCC); - emit dataRead(bufToEmit); - QLOG_DEBUG() << "Buffer error" << qbuffer.size(); - qbuffer.clear(); - m_packetErrorCount++; - } - //Start of packet - m_inpacket = true; - } - else if (buf == 0xCC && m_inpacket) - { - //End of packet - m_inpacket = false; - - //New Location of checksum - unsigned char sum = 0; - for (int i=0;i -#include -#include "serialport.h" -#ifndef Q_OS_WIN -#define HANDLE int -#endif -#ifdef Q_OS_WIN -#include -#endif -class SerialRXThread : public QThread -{ - Q_OBJECT -public: - explicit SerialRXThread(QObject *parent = 0); - QByteArray readSinglePacket(SerialPort *port); - ~SerialRXThread(); - void start(SerialPort *serialport); - void stop() { m_terminate = true; } -private: - bool m_terminate; - SerialPort *m_serialPort; -protected: - void run(); -signals: - void incomingPacket(QByteArray packet); - void dataRead(QByteArray data); - void portGone(); -public slots: - -}; - -#endif // SERIALRXTHREAD_H