From bf47988830dc56ba5d9253b04fdacef670d2cd20 Mon Sep 17 00:00:00 2001 From: Andrei Paulau <7134956@gmail.com> Date: Sun, 16 Apr 2023 16:58:47 +0300 Subject: [PATCH] Qt: Add "verify" action. Change-Id: Ie1a98e0134e09b53268e52c97e643a217addd92e --- qt/main_window.cpp | 129 +++++++++++++++++++++++++++++++++++++++++++++ qt/main_window.h | 3 ++ qt/main_window.ui | 9 ++++ 3 files changed, 141 insertions(+) diff --git a/qt/main_window.cpp b/qt/main_window.cpp index 9da934b..22b5e04 100644 --- a/qt/main_window.cpp +++ b/qt/main_window.cpp @@ -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, @@ -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); @@ -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 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, diff --git a/qt/main_window.h b/qt/main_window.h index 2717aaf..1e7d384 100644 --- a/qt/main_window.h +++ b/qt/main_window.h @@ -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); @@ -74,6 +76,7 @@ public slots: void slotProgReadDeviceId(); void slotProgErase(); void slotProgRead(); + void slotProgVerify(); void slotProgWrite(); void slotProgReadBadBlocks(); void slotSelectChip(int selectedChipNum); diff --git a/qt/main_window.ui b/qt/main_window.ui index 1edef92..8317596 100644 --- a/qt/main_window.ui +++ b/qt/main_window.ui @@ -318,6 +318,7 @@ + @@ -408,6 +409,14 @@ Programmer + + + + false + + + Verify +