@@ -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+
365494void MainWindow::slotProgWriteCompleted (int status)
366495{
367496 disconnect (prog, SIGNAL (writeChipProgress (quint64)), this ,
0 commit comments