Skip to content

Commit

Permalink
Qt: Add "verify" action.
Browse files Browse the repository at this point in the history
Change-Id: Ie1a98e0134e09b53268e52c97e643a217addd92e
  • Loading branch information
7134956 authored and bbogush committed May 14, 2023
1 parent c1f5e29 commit bf47988
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
129 changes: 129 additions & 0 deletions qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
SLOT(slotProgErase()));
connect(ui->actionRead, SIGNAL(triggered()), this,
SLOT(slotProgRead()));
connect(ui->actionVerify, SIGNAL(triggered()), this,
SLOT(slotProgVerify()));
connect(ui->actionWrite, SIGNAL(triggered()), this,
SLOT(slotProgWrite()));
connect(ui->actionReadBadBlocks, SIGNAL(triggered()), this,
Expand Down Expand Up @@ -130,6 +132,7 @@ void MainWindow::setUiStateSelected(bool isSelected)
ui->actionErase->setEnabled(isSelected);
ui->actionRead->setEnabled(isSelected);
ui->actionWrite->setEnabled(isSelected);
ui->actionVerify->setEnabled(isSelected);
ui->actionReadBadBlocks->setEnabled(isSelected);

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

void MainWindow::slotProgVerifyCompleted(quint64 readBytes)
{
disconnect(prog, SIGNAL(readChipProgress(quint64)), this,
SLOT(slotProgVerifyProgress(quint64)));
disconnect(prog, SIGNAL(readChipCompleted(quint64)), this,
SLOT(slotProgVerifyCompleted(quint64)));

ui->filePathLineEdit->setDisabled(false);
ui->selectFilePushButton->setDisabled(false);

setProgress(100);
workFile.close();
buffer.clear();

qInfo() << readBytes << " bytes read. Verify end." ;
}

void MainWindow::slotProgVerifyProgress(quint64 progress)
{
uint32_t progressPercent;

progressPercent = progress * 100ULL / areaSize;
setProgress(progressPercent);

QVector<uint8_t> cmpBuffer;
cmpBuffer.resize(buffer.size());

qint64 readSize = workFile.read((char *)cmpBuffer.data(), buffer.size());

if (readSize < 0)
{
qCritical() << "Failed to read file";
}
else if (readSize == 0)
{
qCritical() << "File read 0 byte";
}

for(uint32_t i = 0; i < readSize; i++)
{
if(cmpBuffer.at(i) != buffer.at(i))
{
uint64_t block = progress / ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
+ ui->firstSpinBox->text().toULongLong(nullptr, 10) - 1;
uint64_t byte = progress - ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
+ ui->firstSpinBox->text().toULongLong(nullptr, 10)
* ui->blockSizeValueLabel->text().toULongLong(nullptr, 16) + i;
qCritical() << "Wrong block: " << QString("%1").arg(block)
<< ", Wrong byte addr: "
<< QString("0x%1").arg(byte, 8, 16, QLatin1Char( '0' ));
break;
}
}

buffer.clear();
}

void MainWindow::slotProgVerify()
{
int index;
QString chipName;

workFile.setFileName(ui->filePathLineEdit->text());
if (!workFile.open(QIODevice::ReadOnly))
{
qCritical() << "Failed to open compare file:" << ui->filePathLineEdit->text() << ", error:" <<
workFile.errorString();
return;
}
if (!workFile.size())
{
qInfo() << "Compare file is empty";
return;
}

index = ui->chipSelectComboBox->currentIndex();
if (index <= CHIP_INDEX_DEFAULT)
{
qInfo() << "Chip is not selected";
return;
}

chipName = ui->chipSelectComboBox->currentText();
pageSize = prog->isIncSpare() ?
currentChipDb->extendedPageSizeGetByName(chipName) :
currentChipDb->pageSizeGetByName(chipName);
if (!pageSize)
{
qInfo() << "Chip page size is unknown";
return;
}

quint64 start_address =
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
* ui->firstSpinBox->value();

areaSize = workFile.size();

if (areaSize % pageSize)
{
areaSize = (areaSize / pageSize + 1) * pageSize;
}

quint64 setSize =
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
* (ui->lastSpinBox->value() + 1) - start_address;

if (setSize < areaSize)
areaSize = setSize;

qInfo() << "Reading data ...";
setProgress(0);

connect(prog, SIGNAL(readChipCompleted(quint64)), this,
SLOT(slotProgVerifyCompleted(quint64)));
connect(prog, SIGNAL(readChipProgress(quint64)), this,
SLOT(slotProgVerifyProgress(quint64)));

ui->filePathLineEdit->setDisabled(true);
ui->selectFilePushButton->setDisabled(true);

buffer.clear();

prog->readChip(&buffer, start_address, areaSize, true);
}

void MainWindow::slotProgWriteCompleted(int status)
{
disconnect(prog, SIGNAL(writeChipProgress(quint64)), this,
Expand Down
3 changes: 3 additions & 0 deletions qt/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private slots:
void slotProgReadDeviceIdCompleted(quint64 status);
void slotProgReadCompleted(quint64 readBytes);
void slotProgReadProgress(quint64 progress);
void slotProgVerifyCompleted(quint64 readBytes);
void slotProgVerifyProgress(quint64 progress);
void slotProgWriteCompleted(int status);
void slotProgWriteProgress(quint64 progress);
void slotProgEraseCompleted(quint64 status);
Expand All @@ -74,6 +76,7 @@ public slots:
void slotProgReadDeviceId();
void slotProgErase();
void slotProgRead();
void slotProgVerify();
void slotProgWrite();
void slotProgReadBadBlocks();
void slotSelectChip(int selectedChipNum);
Expand Down
9 changes: 9 additions & 0 deletions qt/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
<addaction name="actionErase"/>
<addaction name="actionRead"/>
<addaction name="actionWrite"/>
<addaction name="actionVerify"/>
<addaction name="actionReadBadBlocks"/>
</widget>
<widget class="QMenu" name="menuProgrammer">
Expand Down Expand Up @@ -408,6 +409,14 @@
<property name="text">
<string>Programmer</string>
</property>
</action>
<action name="actionVerify">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Verify</string>
</property>
</action>
<action name="actionReadBadBlocks">
<property name="enabled">
Expand Down

0 comments on commit bf47988

Please sign in to comment.