diff --git a/module/lf.cpp b/module/lf.cpp index 0eb9316..ccb17ab 100644 --- a/module/lf.cpp +++ b/module/lf.cpp @@ -6,6 +6,7 @@ LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent) util = addr; this->ui = ui; + configPattern = new QRegularExpression("(\\d+)|Yes|No"); } void LF::read() @@ -45,3 +46,89 @@ void LF::tune() util->execCMD("lf tune"); // TODO: if freq is set, append it as a parameter Util::gotoRawTab(); } + +void LF::getConfig() +{ + QRegularExpressionMatch reMatch; + QString result; + QStringList resultList; + QStringList symbolList = + { + "divisor", + "bps", + "bits per sample", + "decimation", + "averaging", + "trigger threshold", + "samples to skip" + }; + int offset; + QStringList configList = {"", "", "", "", "", "", ""}; + result = util->execCMDWithOutput("hw status", 400); // not all output from "hw status will be processed". + result = result.right(result.length() - result.indexOf("LF Sampling config")); + offset = result.indexOf("samples to skip"); + offset = result.indexOf("\r\n", offset); + result = result.mid(0, offset + 2); + qDebug() << "LF CONFIG GET\n" << result; + resultList = result.split("\r\n"); + for(int i = 0; i < resultList.length(); i++) + { + for(int j = 0; j < symbolList.length(); j++) + { + if(!configList[j].isEmpty()) + continue; + offset = resultList[i].indexOf(symbolList[j]); + if(offset != -1) + { + reMatch = configPattern->match(resultList[i]); + qDebug() << "finded: " << resultList[i]; + if(!reMatch.hasMatch()) + continue; + qDebug() << "captured: " << reMatch.captured(); + configList[j] = reMatch.captured(); + break; + } + } + } + qDebug() << "configList: " << configList; + currConfig.divisor = configList[0].toUInt(); + currConfig.decimation = configList[3].toUInt(); + currConfig.triggerThreshold = configList[5].toUInt(); + currConfig.samplesToSkip = configList[6].toUInt(); + if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) + { + currConfig.bitPerSample = configList[1].toUInt(); + currConfig.averaging = (configList[4] == "1"); + } + else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) + { + currConfig.bitPerSample = configList[2].toUInt(); + currConfig.averaging = (configList[4] == "Yes"); + } + syncWithUI(); +} + +void LF::setConfig() +{ + +} + +float LF::divisor2Freq(uint8_t divisor) +{ + return (12000.0 / (divisor + 1.0)); +} + +uint8_t LF::freq2Divisor(float freq) +{ + return ((uint16_t)(12000.0 / freq + 0.5) - 1); // uint16_t for (divisor + 1) = 256 +} + +void LF::syncWithUI() +{ + ui->LF_Conf_freqDivisorBox->setValue(currConfig.divisor); + ui->LF_Conf_bitPerSampleBox->setValue(currConfig.bitPerSample); + ui->LF_Conf_decimationBox->setValue(currConfig.decimation); + ui->LF_Conf_averagingBox->setChecked(currConfig.averaging); + ui->LF_Conf_thresholdBox->setValue(currConfig.triggerThreshold); + ui->LF_Conf_skipsBox->setValue(currConfig.samplesToSkip); +} diff --git a/module/lf.h b/module/lf.h index fca7f9f..581ae1c 100644 --- a/module/lf.h +++ b/module/lf.h @@ -12,15 +12,31 @@ class LF : public QObject public: explicit LF(Ui::MainWindow *ui, Util *addr, QWidget *parent = nullptr); + struct Config + { + uint8_t divisor; + uint8_t bitPerSample; + uint8_t decimation; + bool averaging; + uint8_t triggerThreshold; + uint16_t samplesToSkip; + }; + void read(); void sniff(); void search(); void tune(); + void getConfig(); + void setConfig(); + static float divisor2Freq(uint8_t divisor); + static uint8_t freq2Divisor(float freq); private: QWidget* parent; Ui::MainWindow *ui; Util* util; - + Config currConfig; + QRegularExpression* configPattern; + void syncWithUI(); signals: }; diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index faec518..4151d06 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -1251,7 +1251,7 @@ void MainWindow::onLFfreqConfChanged(int value, bool isCustomized) if(isCustomized) ui->LF_Conf_freqOtherButton->setChecked(true); - ui->LF_Conf_freqLabel->setText(QString("Actural Freq: %1kHz").arg(12000.0 / (value + 1.0), 0, 'f', 3)); + ui->LF_Conf_freqLabel->setText(QString("Actural Freq: %1kHz").arg(LF::divisor2Freq(value), 0, 'f', 3)); ui->LF_Conf_freqDivisorBox->setValue(value); ui->LF_Conf_freqSlider->setValue(value); @@ -1334,3 +1334,8 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) { contextMenu->exec(event->globalPos()); } + +void MainWindow::on_LF_Conf_getButton_clicked() +{ + lf->getConfig(); +} diff --git a/ui/mainwindow.h b/ui/mainwindow.h index beef663..a4954dd 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -197,6 +197,8 @@ private slots: void on_LF_Op_sniffButton_clicked(); + void on_LF_Conf_getButton_clicked(); + private: Ui::MainWindow* ui; QButtonGroup* MFCardTypeBtnGroup; diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index c837607..d7cfa04 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -136,7 +136,7 @@ - 0 + 1 @@ -1442,10 +1442,14 @@ You might need a modified LF antenna if the freq is not 125k/134k. - + + + 65535 + + - + 1 @@ -1689,7 +1693,7 @@ On Iceman/RRG repo, press the button on PM3 to stop measuring - Sniff low frequency signal wit LF field OFF. + Sniff low frequency signal with LF field OFF. Use this to get raw data from a reader or the communication between a tag and a reader.