@@ -41,6 +41,7 @@ const QString MainWindow::MANUAL_STRING = "<a href=\"%1\">" + tr("User Manual")
4141const QString MainWindow::BLE_MANUAL_URL = " https://raw.githubusercontent.com/mooltipass/minible/master/MooltipassMiniBLEUserManual.pdf" ;
4242const QString MainWindow::MINI_MANUAL_URL = " https://raw.githubusercontent.com/limpkin/mooltipass/master/user_manual_mini.pdf" ;
4343const QString MainWindow::BUNDLE_OUTDATED_TEXT = tr(" New bundle update available <a href=\" https://www.themooltipass.com/updates/index.php?sn=%1&bundlev=%2\" >here.</a>" );
44+ const QString MainWindow::SERIAL_STR_START = " MOOLTIP" ;
4445
4546void MainWindow::initHelpLabels ()
4647{
@@ -130,6 +131,11 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
130131 ui->labelAboutAuxMCU ->setText (tr (" Aux MCU version:" ));
131132 ui->labelAboutMainMCU ->setText (tr (" Main MCU version:" ));
132133
134+ ui->widgetNotFlashedWarning ->hide ();
135+ ui->labelNotFlashedWarningIcon ->setPixmap (AppGui::qtAwesome ()->icon (fa::warning).pixmap (QSize (20 , 20 )));
136+ ui->labelSerialNumberIncorrect ->setStyleSheet (" QLabel {color: blue;}" );
137+ connect (ui->labelSerialNumberIncorrect , &ClickableLabel::clicked, this , &MainWindow::onIncorrectSerialNumberClicked);
138+
133139 ui->pbBleBattery ->setStyleSheet (" border: 1px solid black" );
134140 ui->pbBleBattery ->hide ();
135141
@@ -484,6 +490,7 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
484490 connect (wsClient, &WSClient::fwVersionChanged, this , &MainWindow::updateSerialInfos);
485491 connect (wsClient, &WSClient::hwSerialChanged, this , &MainWindow::updateSerialInfos);
486492 connect (wsClient, &WSClient::hwMemoryChanged, this , &MainWindow::updateSerialInfos);
493+ connect (wsClient, &WSClient::platformSerialChanged, this , &MainWindow::updateSerialInfos);
487494 connect (wsClient, &WSClient::bundleVersionChanged, this , &MainWindow::displayBundleVersion);
488495 connect (wsClient, &WSClient::bundleVersionChanged, this , &MainWindow::sendRequestNotes);
489496 connect (wsClient, &WSClient::bundleVersionChanged, this , &MainWindow::onBundleVersionChanged);
@@ -628,6 +635,8 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
628635
629636 connect (wsClient, &WSClient::bleNameChanged, this , &MainWindow::onBleNameChanged);
630637
638+ connect (wsClient, &WSClient::serialNumberChanged, this , &MainWindow::onSerialNumberChanged);
639+
631640 wsClient->settingsHelper ()->setMainWindow (this );
632641#ifdef Q_OS_WIN
633642 const auto keyboardLayoutWidth = 150 ;
@@ -957,14 +966,24 @@ void MainWindow::updateSerialInfos() {
957966 if (connected)
958967 {
959968 ui->labelAboutFwVersValue ->setText (wsClient->get_fwVersion ());
960- ui->labelAbouHwSerialValue ->setText (wsClient->get_hwSerial () > 0 ? QString::number (wsClient->get_hwSerial ()) : NONE_STRING );
969+ auto serialNum = QString::number (wsClient->get_hwSerial ());
970+ ui->labelAbouHwSerialValue ->setText (wsClient->get_hwSerial () > 0 ? serialNum : NONE_STRING );
961971 ui->labelAbouHwMemoryValue ->setText (wsClient->get_hwMemory () > 0 ? tr (" %1Mb" ).arg (wsClient->get_hwMemory ()): NONE_STRING );
962972 displayMCUVersion (wsClient->isMPBLE ());
963973 // When ble is detected not displaying fw version
964974 ui->labelAboutFwVers ->setVisible (!wsClient->isMPBLE ());
965975 ui->labelAboutFwVersValue ->setVisible (!wsClient->isMPBLE ());
966976 ui->label_UserManual ->setText (MANUAL_STRING .arg (wsClient->isMPBLE () ? BLE_MANUAL_URL : MINI_MANUAL_URL ));
967977 ui->label_UserManual ->show ();
978+ if (wsClient->isMPBLE () && serialNum > STARTING_NOT_FLASHED_SERIAL &&
979+ wsClient->get_hwSerial () != wsClient->get_platformSerial ())
980+ {
981+ ui->widgetNotFlashedWarning ->show ();
982+ }
983+ else
984+ {
985+ ui->widgetNotFlashedWarning ->hide ();
986+ }
968987 }
969988 else
970989 {
@@ -977,6 +996,7 @@ void MainWindow::updateSerialInfos() {
977996 wsClient->set_auxMCUVersion (NONE_STRING );
978997 wsClient->set_mainMCUVersion (NONE_STRING );
979998 wsClient->set_bundleVersion (0 );
999+ wsClient->set_platformSerial (0 );
9801000 ui->label_UserManual ->hide ();
9811001 }
9821002}
@@ -1923,6 +1943,46 @@ void MainWindow::fillInitialCurrentCategories()
19231943 ui->comboBoxBleCurrentCategory ->blockSignals (false );
19241944}
19251945
1946+ bool MainWindow::validateSerialString (const QString &serialStr, uint &serialNum)
1947+ {
1948+ /*
1949+ * Correct serial string: MOOLTIPXXXXY,
1950+ * XXXX is the new serial number
1951+ * Y is a char which is 'A' + (XXXX)%26
1952+ */
1953+
1954+ const int serialStartSize = SERIAL_STR_START .size ();
1955+ const int serialStringSize = serialStartSize + SERIAL_NUM_LENGTH + 1 ;
1956+ if (serialStr.size () != serialStringSize)
1957+ {
1958+ qCritical () << " Serial string has an incorrect size" ;
1959+ return false ;
1960+ }
1961+
1962+ if (!serialStr.startsWith (SERIAL_STR_START ))
1963+ {
1964+ qCritical () << " Serial string is not started with " << SERIAL_STR_START ;
1965+ return false ;
1966+ }
1967+ QString serialPart = serialStr.mid (serialStartSize, SERIAL_NUM_LENGTH );
1968+ bool ok = false ;
1969+ serialNum = serialPart.toUInt (&ok);
1970+ if (!ok)
1971+ {
1972+ qCritical () << " Serial number part is not a number" ;
1973+ return false ;
1974+ }
1975+
1976+ int hash = serialStr.toStdString ()[serialStringSize - 1 ] - ' A' ;
1977+ if (hash != serialNum % Common::ALPHABET_SIZE )
1978+ {
1979+ serialNum = 0 ;
1980+ qCritical () << " Incorrect hash in serial string" ;
1981+ return false ;
1982+ }
1983+ return true ;
1984+ }
1985+
19261986void MainWindow::on_toolButton_clearBackupFilePath_released ()
19271987{
19281988 ui->lineEdit_dbBackupFilePath ->clear ();
@@ -2405,3 +2465,48 @@ void MainWindow::onBleNameChanged(const QString &name)
24052465 ui->lineEditBleName ->setText (name);
24062466 checkSettingsChanged ();
24072467}
2468+
2469+ void MainWindow::onIncorrectSerialNumberClicked ()
2470+ {
2471+ bool ok = false ;
2472+ QString serialNumStr = QInputDialog::getText (this , tr (" Incorrect Serial Number" ),
2473+ tr (" It looks like your device serial number doesn't match the one present on your device's case.\n " ) +
2474+ tr (" Please reach out to support@themooltipass.com for the right code to enter below" ),
2475+ QLineEdit::Normal, " " , &ok);
2476+ if (ok)
2477+ {
2478+ uint serialNum = 0 ;
2479+ if (validateSerialString (serialNumStr, serialNum))
2480+ {
2481+ wsClient->sendSetSerialNumber (serialNum);
2482+ }
2483+ else
2484+ {
2485+ qCritical () << " The entered serial number is incorrect: " << serialNumStr;
2486+ QMessageBox::critical (this , tr (" Incorrect Serial Number" ),
2487+ tr (" The entered serial number is incorrect!" ));
2488+ }
2489+ }
2490+ }
2491+
2492+ void MainWindow::onSerialNumberChanged (bool success, int serialNumber)
2493+ {
2494+ auto title = tr (" Serial number change" );
2495+ if (success)
2496+ {
2497+ wsClient->set_hwSerial (serialNumber);
2498+ if (wsClient->get_hwSerial () == wsClient->get_platformSerial ())
2499+ {
2500+ QMessageBox::information (this , title, tr (" Set serial number successfully." ));
2501+ ui->widgetNotFlashedWarning ->hide ();
2502+ }
2503+ else
2504+ {
2505+ QMessageBox::critical (this , title, tr (" Serial number still does not match platform serial." ));
2506+ }
2507+ }
2508+ else
2509+ {
2510+ QMessageBox::critical (this , title, tr (" Set serial number failed." ));
2511+ }
2512+ }
0 commit comments