From f7d941b8e88dec953f6623620cd7e84615f4e565 Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Sun, 13 Oct 2013 08:13:51 -0400 Subject: [PATCH] Fixes for RawDataView to properly operate on hex data locations --- core/src/rawdataview.cpp | 23 +++++-- core/src/rawdataview.h | 1 + lib/core/rawdata.h | 5 ++ plugins/freeems/emsdata.cpp | 93 ++++++++++++++++++++++------ plugins/freeems/emsdata.h | 7 ++- plugins/freeems/fememorymetadata.cpp | 24 +++---- plugins/freeems/ferawdata.cpp | 23 ++++++- plugins/freeems/ferawdata.h | 7 +++ plugins/freeems/freeemscomms.cpp | 49 ++++++++++++--- 9 files changed, 183 insertions(+), 49 deletions(-) diff --git a/core/src/rawdataview.cpp b/core/src/rawdataview.cpp index 9b1866d..d708e0b 100644 --- a/core/src/rawdataview.cpp +++ b/core/src/rawdataview.cpp @@ -25,6 +25,7 @@ RawDataView::RawDataView(bool isram, bool isflash,QWidget *parent) { Q_UNUSED(parent) + m_data = 0; ui.setupUi(this); connect(ui.saveFlashPushButton,SIGNAL(clicked()),this,SLOT(saveFlashButtonClicked())); connect(ui.saveRamPushButton,SIGNAL(clicked()),this,SLOT(saveRamButtonClicked())); @@ -57,18 +58,29 @@ void RawDataView::passDatalog(QVariantMap data) } bool RawDataView::setData(unsigned short locationid,DataBlock *data) { + if (m_data) + { + disconnect(m_data,SIGNAL(update()),this,SLOT(update())); + } m_data = (RawData*)(data); + connect(m_data,SIGNAL(update()),this,SLOT(update())); m_locationId = locationid; ui.hexEditor->setData(m_data->data()); ui.locationIdLabel->setText("0x" + QString::number(locationid,16).toUpper()); return true; } +void RawDataView::update() +{ + ui.hexEditor->setData(m_data->data()); +} + void RawDataView::loadRamButtonClicked() { if (QMessageBox::information(0,"Warning","Doing this will reload the block from ram, and wipe out any changes you may have made. Are you sure you want to do this?",QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { QLOG_DEBUG() << "Ok"; - emit reloadData(m_locationId,true); + m_data->updateFromRam(); + //emit reloadData(m_locationId,true); } else { @@ -82,7 +94,8 @@ void RawDataView::loadFlashButtonClicked() if (QMessageBox::information(0,"Warning","Doing this will reload the block from flash, and wipe out any changes you may have made. Are you sure you want to do this?",QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { QLOG_DEBUG() << "Ok"; - emit reloadData(m_locationId,false); + //emit reloadData(m_locationId,false); + m_data->updateFromFlash(); } else { @@ -95,11 +108,11 @@ RawDataView::~RawDataView() } void RawDataView::saveFlashButtonClicked() { - emit saveData(m_locationId,ui.hexEditor->data(),1); //0 for RAM, 1 for flash. - m_data->setData(m_locationId,false,ui.hexEditor->data()); + //emit saveData(m_locationId,ui.hexEditor->data(),1); //0 for RAM, 1 for flash. + m_data->updateValue(ui.hexEditor->data()); } void RawDataView::saveRamButtonClicked() { - emit saveData(m_locationId,ui.hexEditor->data(),0); //0 for RAM, 1 for flash. + //emit saveData(m_locationId,ui.hexEditor->data(),0); //0 for RAM, 1 for flash. } diff --git a/core/src/rawdataview.h b/core/src/rawdataview.h index 3fb1cc9..8f1c789 100644 --- a/core/src/rawdataview.h +++ b/core/src/rawdataview.h @@ -48,6 +48,7 @@ private slots: void saveRamButtonClicked(); void loadRamButtonClicked(); void loadFlashButtonClicked(); + void update(); signals: void saveData(unsigned short locationid,QByteArray data,int physicallocation); void reloadData(unsigned short locationid,bool isram); diff --git a/lib/core/rawdata.h b/lib/core/rawdata.h index 2a27a88..02075ad 100644 --- a/lib/core/rawdata.h +++ b/lib/core/rawdata.h @@ -11,5 +11,10 @@ class RawData : public DataBlock virtual QByteArray data() = 0; virtual unsigned short locationId()=0; virtual bool isFlashOnly()=0; + virtual void updateValue(QByteArray data)=0; +public slots: + virtual void saveRamToFlash()=0; + virtual void updateFromFlash()=0; + virtual void updateFromRam()=0; }; #endif // RAWDATA_H diff --git a/plugins/freeems/emsdata.cpp b/plugins/freeems/emsdata.cpp index 753d4f5..8963d27 100644 --- a/plugins/freeems/emsdata.cpp +++ b/plugins/freeems/emsdata.cpp @@ -269,18 +269,16 @@ QList EmsData::getChildrenOfLocalRamLocation(unsigned short id) return retVal; } -QList EmsData::getParentOfLocalRamLocation(unsigned short id) +unsigned short EmsData::getParentOfLocalRamLocation(unsigned short id) { - QList retVal; - for (int i=0;ilocationid == id) { - retVal.append(m_ramMemoryList[i]->parent); + return m_ramMemoryList[i]->parent; } } - return retVal; + return 0; } bool EmsData::localRamHasParent(unsigned short id) { @@ -293,6 +291,69 @@ bool EmsData::localRamHasParent(unsigned short id) } 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; @@ -402,17 +463,6 @@ QList EmsData::getTopLevelDeviceRamLocations() return retval; } -bool EmsData::localRamHasChildren(unsigned short id) -{ - for (int i=0;ilocationid == id) - { - return m_flashMemoryList[i]->hasParent; - } - } - return false; -} QString EmsData::serialize(unsigned short id,bool isram) { QString val = ""; @@ -722,10 +772,12 @@ void EmsData::ramBytesLocalUpdate(unsigned short locationid,unsigned short offse } if (getLocalRamBlock(locationid).mid(offset,size) == data) { - QLOG_WARN() << "Data in application memory unchanged, no reason to send write for single value"; + 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); } @@ -733,15 +785,18 @@ void EmsData::flashBytesLocalUpdate(unsigned short locationid,unsigned short off { 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 memory unchanged, no reason to send write for single value"; + 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 flashBlockUpdateRequest(locationid,offset,size,data); //don't emit a signal for flash updates, those are always manual. + //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) diff --git a/plugins/freeems/emsdata.h b/plugins/freeems/emsdata.h index 9f36981..a410143 100644 --- a/plugins/freeems/emsdata.h +++ b/plugins/freeems/emsdata.h @@ -56,10 +56,15 @@ class EmsData : public QObject void addDeviceRamBlock(MemoryLocation *loc); QList getChildrenOfLocalRamLocation(unsigned short id); - QList getParentOfLocalRamLocation(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(); diff --git a/plugins/freeems/fememorymetadata.cpp b/plugins/freeems/fememorymetadata.cpp index 2fe3be1..9a23f3a 100644 --- a/plugins/freeems/fememorymetadata.cpp +++ b/plugins/freeems/fememorymetadata.cpp @@ -37,11 +37,11 @@ bool FEMemoryMetaData::parseMetaData(QString json) 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"; + //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(); @@ -104,7 +104,7 @@ bool FEMemoryMetaData::parseMetaData(QString json) m_lookupMetaData[keyint] = meta; i++; } - QLOG_DEBUG() << m_readOnlyMetaData.size() << "Ram entries found"; + //QLOG_DEBUG() << m_readOnlyMetaData.size() << "Ram entries found"; QVariantMap tables = topmap["tables"].toMap(); i = tables.begin(); while (i != tables.end()) @@ -135,7 +135,7 @@ bool FEMemoryMetaData::parseMetaData(QString json) QList > zcalclist; for (int j=0;j(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j updatelist; + updatelist.append(locationid); + if (emsData.localFlashHasParent(locationid)) { - m_2dTableMap[locationid]->setData(locationid,!emsData.hasDeviceRamBlock(locationid),emsData.getDeviceRamBlock(locationid),m_metaDataParser->get2DMetaData(locationid),false); + updatelist.append(emsData.getParentOfLocalFlashLocation(locationid)); } - if (m_3dTableMap.contains(locationid)) + if (emsData.localRamHasParent(locationid)) { - m_3dTableMap[locationid]->setData(locationid,!emsData.hasDeviceRamBlock(locationid),emsData.getDeviceRamBlock(locationid),m_metaDataParser->get3DMetaData(locationid)); + updatelist.append(emsData.getParentOfLocalRamLocation(locationid)); } - if (m_rawDataMap.contains(locationid)) + if (emsData.localFlashHasChildren(locationid)) { - if (emsData.hasLocalRamBlock(locationid)) + updatelist.append(emsData.getChildrenOfLocalFlashLocation(locationid)); + } + if (emsData.localRamHasChildren(locationid)) + { + updatelist.append(emsData.getChildrenOfLocalRamLocation(locationid)); + } + + for (int i=0;isetData(locationid,false,emsData.getLocalRamBlock(locationid)); + m_2dTableMap[updatelist[i]]->setData(updatelist[i],!emsData.hasDeviceRamBlock(updatelist[i]),emsData.getDeviceRamBlock(updatelist[i]),m_metaDataParser->get2DMetaData(updatelist[i]),false); } - else + if (m_3dTableMap.contains(updatelist[i])) { - m_rawDataMap[locationid]->setData(locationid,true,emsData.getLocalFlashBlock(locationid)); + 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])); + } } } - } void FreeEmsComms::copyFlashToRam(unsigned short locationid) {