Skip to content

Commit

Permalink
Fixes for RawDataView to properly operate on hex data locations
Browse files Browse the repository at this point in the history
  • Loading branch information
malcom2073 committed Oct 13, 2013
1 parent adc267e commit f7d941b
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 49 deletions.
23 changes: 18 additions & 5 deletions core/src/rawdataview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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.
}
1 change: 1 addition & 0 deletions core/src/rawdataview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions lib/core/rawdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
93 changes: 74 additions & 19 deletions plugins/freeems/emsdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,16 @@ QList<unsigned short> EmsData::getChildrenOfLocalRamLocation(unsigned short id)
return retVal;
}

QList<unsigned short> EmsData::getParentOfLocalRamLocation(unsigned short id)
unsigned short EmsData::getParentOfLocalRamLocation(unsigned short id)
{
QList<unsigned short> retVal;

for (int i=0;i<m_ramMemoryList.size();i++)
{
if (m_ramMemoryList[i]->locationid == id)
{
retVal.append(m_ramMemoryList[i]->parent);
return m_ramMemoryList[i]->parent;
}
}
return retVal;
return 0;
}
bool EmsData::localRamHasParent(unsigned short id)
{
Expand All @@ -293,6 +291,69 @@ bool EmsData::localRamHasParent(unsigned short id)
}
return false;
}
bool EmsData::localRamHasChildren(unsigned short id)
{
for (int i=0;i<m_ramMemoryList.size();i++)
{
if (m_ramMemoryList[i]->hasParent && m_ramMemoryList[i]->parent == id)
{
return true;
}
}
return false;
}

QList<unsigned short> EmsData::getChildrenOfLocalFlashLocation(unsigned short id)
{
QList<unsigned short> retVal;
for (int i=0;i<m_flashMemoryList.size();i++)
{
if (m_flashMemoryList[i]->hasParent)
{
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;i<m_flashMemoryList.size();i++)
{
if (m_flashMemoryList[i]->locationid == id)
{
return m_flashMemoryList[i]->parent;
}
}
return 0;
}
bool EmsData::localFlashHasParent(unsigned short id)
{
for (int i=0;i<m_flashMemoryList.size();i++)
{
if (m_flashMemoryList[i]->locationid == id)
{
return m_flashMemoryList[i]->hasParent;
}
}
return false;
}
bool EmsData::localFlashHasChildren(unsigned short id)
{
for (int i=0;i<m_flashMemoryList.size();i++)
{
if (m_flashMemoryList[i]->hasParent && m_flashMemoryList[i]->parent == id)
{
return true;
}
}
return false;
}


QList<unsigned short> EmsData::getTopLevelDeviceFlashLocations()
{
QList<unsigned short> retval;
Expand Down Expand Up @@ -402,17 +463,6 @@ QList<unsigned short> EmsData::getTopLevelDeviceRamLocations()
return retval;
}

bool EmsData::localRamHasChildren(unsigned short id)
{
for (int i=0;i<m_flashMemoryList.size();i++)
{
if (m_flashMemoryList[i]->locationid == id)
{
return m_flashMemoryList[i]->hasParent;
}
}
return false;
}
QString EmsData::serialize(unsigned short id,bool isram)
{
QString val = "";
Expand Down Expand Up @@ -722,26 +772,31 @@ 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);
}

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 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)
Expand Down
7 changes: 6 additions & 1 deletion plugins/freeems/emsdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ class EmsData : public QObject
void addDeviceRamBlock(MemoryLocation *loc);

QList<unsigned short> getChildrenOfLocalRamLocation(unsigned short id);
QList<unsigned short> getParentOfLocalRamLocation(unsigned short id);
unsigned short getParentOfLocalRamLocation(unsigned short id);
bool localRamHasParent(unsigned short id);
bool localRamHasChildren(unsigned short id);

QList<unsigned short> 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();
Expand Down
24 changes: 12 additions & 12 deletions plugins/freeems/fememorymetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -135,7 +135,7 @@ bool FEMemoryMetaData::parseMetaData(QString json)
QList<QPair<QString,double> > zcalclist;
for (int j=0;j<xcalc.size();j++)
{
QLOG_DEBUG() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
//QLOG_DEBUG() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
}
for (int j=0;j<ycalc.size();j++)
Expand Down Expand Up @@ -168,7 +168,7 @@ bool FEMemoryMetaData::parseMetaData(QString json)
if (m_table3DMetaData[i].locationId == meta.locationId)
{
//Error, already exists;
QLOG_DEBUG() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file";
//QLOG_DEBUG() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file";
return false;
}
}
Expand All @@ -192,7 +192,7 @@ bool FEMemoryMetaData::parseMetaData(QString json)

for (int j=0;j<xcalc.size();j++)
{
QLOG_DEBUG() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
//QLOG_DEBUG() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
}
for (int j=0;j<ycalc.size();j++)
Expand All @@ -216,7 +216,7 @@ bool FEMemoryMetaData::parseMetaData(QString json)
if (m_table2DMetaData[i].locationId == meta.locationId)
{
//Error, already exists;
QLOG_FATAL() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file";
//QLOG_FATAL() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file";
return false;
}
}
Expand All @@ -229,15 +229,15 @@ bool FEMemoryMetaData::parseMetaData(QString json)

bool FEMemoryMetaData::loadMetaDataFromFile(QString filestr)
{
QLOG_DEBUG() << "Loading config file from:" << filestr;
//QLOG_DEBUG() << "Loading config file from:" << filestr;
QFile file(filestr);
if (!file.open(QIODevice::ReadOnly))
{
return false;
//Can't open the file.
}
QByteArray filebytes = file.readAll();
QLOG_DEBUG() << "Loaded:" << filebytes.size() << "chars from config file";
//QLOG_DEBUG() << "Loaded:" << filebytes.size() << "chars from config file";
file.close();
return parseMetaData(filebytes);
}
Expand Down
23 changes: 21 additions & 2 deletions plugins/freeems/ferawdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ void FERawData::setData(unsigned short locationid,bool isflashonly,QByteArray pa
void FERawData::updateValue(QByteArray data)
{
m_data = data;
emit update();
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()
Expand All @@ -39,3 +38,23 @@ 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()
{

}
7 changes: 7 additions & 0 deletions plugins/freeems/ferawdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FERawData : public RawData
QByteArray data();
unsigned short locationId();
bool isFlashOnly();
void updateValue(QByteArray data);
private:
QByteArray m_data;
bool m_isFlashOnly;
Expand All @@ -20,6 +21,12 @@ class FERawData : public RawData
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
Loading

0 comments on commit f7d941b

Please sign in to comment.