Skip to content

Commit bf47988

Browse files
7134956bbogush
authored andcommitted
Qt: Add "verify" action.
Change-Id: Ie1a98e0134e09b53268e52c97e643a217addd92e
1 parent c1f5e29 commit bf47988

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

qt/main_window.cpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
8181
SLOT(slotProgErase()));
8282
connect(ui->actionRead, SIGNAL(triggered()), this,
8383
SLOT(slotProgRead()));
84+
connect(ui->actionVerify, SIGNAL(triggered()), this,
85+
SLOT(slotProgVerify()));
8486
connect(ui->actionWrite, SIGNAL(triggered()), this,
8587
SLOT(slotProgWrite()));
8688
connect(ui->actionReadBadBlocks, SIGNAL(triggered()), this,
@@ -130,6 +132,7 @@ void MainWindow::setUiStateSelected(bool isSelected)
130132
ui->actionErase->setEnabled(isSelected);
131133
ui->actionRead->setEnabled(isSelected);
132134
ui->actionWrite->setEnabled(isSelected);
135+
ui->actionVerify->setEnabled(isSelected);
133136
ui->actionReadBadBlocks->setEnabled(isSelected);
134137

135138
ui->firstSpinBox->setEnabled(isSelected);
@@ -362,6 +365,132 @@ void MainWindow::slotProgRead()
362365
prog->readChip(&buffer, start_address, areaSize, true);
363366
}
364367

368+
void MainWindow::slotProgVerifyCompleted(quint64 readBytes)
369+
{
370+
disconnect(prog, SIGNAL(readChipProgress(quint64)), this,
371+
SLOT(slotProgVerifyProgress(quint64)));
372+
disconnect(prog, SIGNAL(readChipCompleted(quint64)), this,
373+
SLOT(slotProgVerifyCompleted(quint64)));
374+
375+
ui->filePathLineEdit->setDisabled(false);
376+
ui->selectFilePushButton->setDisabled(false);
377+
378+
setProgress(100);
379+
workFile.close();
380+
buffer.clear();
381+
382+
qInfo() << readBytes << " bytes read. Verify end." ;
383+
}
384+
385+
void MainWindow::slotProgVerifyProgress(quint64 progress)
386+
{
387+
uint32_t progressPercent;
388+
389+
progressPercent = progress * 100ULL / areaSize;
390+
setProgress(progressPercent);
391+
392+
QVector<uint8_t> cmpBuffer;
393+
cmpBuffer.resize(buffer.size());
394+
395+
qint64 readSize = workFile.read((char *)cmpBuffer.data(), buffer.size());
396+
397+
if (readSize < 0)
398+
{
399+
qCritical() << "Failed to read file";
400+
}
401+
else if (readSize == 0)
402+
{
403+
qCritical() << "File read 0 byte";
404+
}
405+
406+
for(uint32_t i = 0; i < readSize; i++)
407+
{
408+
if(cmpBuffer.at(i) != buffer.at(i))
409+
{
410+
uint64_t block = progress / ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
411+
+ ui->firstSpinBox->text().toULongLong(nullptr, 10) - 1;
412+
uint64_t byte = progress - ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
413+
+ ui->firstSpinBox->text().toULongLong(nullptr, 10)
414+
* ui->blockSizeValueLabel->text().toULongLong(nullptr, 16) + i;
415+
qCritical() << "Wrong block: " << QString("%1").arg(block)
416+
<< ", Wrong byte addr: "
417+
<< QString("0x%1").arg(byte, 8, 16, QLatin1Char( '0' ));
418+
break;
419+
}
420+
}
421+
422+
buffer.clear();
423+
}
424+
425+
void MainWindow::slotProgVerify()
426+
{
427+
int index;
428+
QString chipName;
429+
430+
workFile.setFileName(ui->filePathLineEdit->text());
431+
if (!workFile.open(QIODevice::ReadOnly))
432+
{
433+
qCritical() << "Failed to open compare file:" << ui->filePathLineEdit->text() << ", error:" <<
434+
workFile.errorString();
435+
return;
436+
}
437+
if (!workFile.size())
438+
{
439+
qInfo() << "Compare file is empty";
440+
return;
441+
}
442+
443+
index = ui->chipSelectComboBox->currentIndex();
444+
if (index <= CHIP_INDEX_DEFAULT)
445+
{
446+
qInfo() << "Chip is not selected";
447+
return;
448+
}
449+
450+
chipName = ui->chipSelectComboBox->currentText();
451+
pageSize = prog->isIncSpare() ?
452+
currentChipDb->extendedPageSizeGetByName(chipName) :
453+
currentChipDb->pageSizeGetByName(chipName);
454+
if (!pageSize)
455+
{
456+
qInfo() << "Chip page size is unknown";
457+
return;
458+
}
459+
460+
quint64 start_address =
461+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
462+
* ui->firstSpinBox->value();
463+
464+
areaSize = workFile.size();
465+
466+
if (areaSize % pageSize)
467+
{
468+
areaSize = (areaSize / pageSize + 1) * pageSize;
469+
}
470+
471+
quint64 setSize =
472+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
473+
* (ui->lastSpinBox->value() + 1) - start_address;
474+
475+
if (setSize < areaSize)
476+
areaSize = setSize;
477+
478+
qInfo() << "Reading data ...";
479+
setProgress(0);
480+
481+
connect(prog, SIGNAL(readChipCompleted(quint64)), this,
482+
SLOT(slotProgVerifyCompleted(quint64)));
483+
connect(prog, SIGNAL(readChipProgress(quint64)), this,
484+
SLOT(slotProgVerifyProgress(quint64)));
485+
486+
ui->filePathLineEdit->setDisabled(true);
487+
ui->selectFilePushButton->setDisabled(true);
488+
489+
buffer.clear();
490+
491+
prog->readChip(&buffer, start_address, areaSize, true);
492+
}
493+
365494
void MainWindow::slotProgWriteCompleted(int status)
366495
{
367496
disconnect(prog, SIGNAL(writeChipProgress(quint64)), this,

qt/main_window.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ private slots:
5555
void slotProgReadDeviceIdCompleted(quint64 status);
5656
void slotProgReadCompleted(quint64 readBytes);
5757
void slotProgReadProgress(quint64 progress);
58+
void slotProgVerifyCompleted(quint64 readBytes);
59+
void slotProgVerifyProgress(quint64 progress);
5860
void slotProgWriteCompleted(int status);
5961
void slotProgWriteProgress(quint64 progress);
6062
void slotProgEraseCompleted(quint64 status);
@@ -74,6 +76,7 @@ public slots:
7476
void slotProgReadDeviceId();
7577
void slotProgErase();
7678
void slotProgRead();
79+
void slotProgVerify();
7780
void slotProgWrite();
7881
void slotProgReadBadBlocks();
7982
void slotSelectChip(int selectedChipNum);

qt/main_window.ui

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
<addaction name="actionErase"/>
319319
<addaction name="actionRead"/>
320320
<addaction name="actionWrite"/>
321+
<addaction name="actionVerify"/>
321322
<addaction name="actionReadBadBlocks"/>
322323
</widget>
323324
<widget class="QMenu" name="menuProgrammer">
@@ -408,6 +409,14 @@
408409
<property name="text">
409410
<string>Programmer</string>
410411
</property>
412+
</action>
413+
<action name="actionVerify">
414+
<property name="enabled">
415+
<bool>false</bool>
416+
</property>
417+
<property name="text">
418+
<string>Verify</string>
419+
</property>
411420
</action>
412421
<action name="actionReadBadBlocks">
413422
<property name="enabled">

0 commit comments

Comments
 (0)