From 15538a98926f70720230bf0c535b4819224a2afc Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 23 Feb 2021 17:56:16 +0800 Subject: [PATCH] LF: Support write LF config When setting LF freq, the "lf config" and "hw setlfdivisor" will both be called. Change some UI --- module/lf.cpp | 39 +- module/lf.h | 14 +- ui/mainwindow.cpp | 24 + ui/mainwindow.h | 4 + ui/mainwindow.ui | 1085 ++++++++++++++++++++++++--------------------- 5 files changed, 661 insertions(+), 505 deletions(-) diff --git a/module/lf.cpp b/module/lf.cpp index ccb17ab..075bf54 100644 --- a/module/lf.cpp +++ b/module/lf.cpp @@ -1,5 +1,7 @@ #include "lf.h" +const LF::Config LF::defaultConfig; + LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent) { this->parent = parent; @@ -7,6 +9,7 @@ LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent) this->ui = ui; configPattern = new QRegularExpression("(\\d+)|Yes|No"); + currConfig = defaultConfig; } void LF::read() @@ -43,7 +46,7 @@ void LF::tune() if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) util->execCMD("hw tune l"); else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) - util->execCMD("lf tune"); // TODO: if freq is set, append it as a parameter + util->execCMD("lf tune --divisor " + QString::number(currConfig.divisor)); Util::gotoRawTab(); } @@ -108,9 +111,39 @@ void LF::getConfig() syncWithUI(); } -void LF::setConfig() +void LF::setConfig(LF::Config config) { + currConfig = config; + if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) + { + util->execCMDWithOutput(QString("lf config") + + " q " + QString::number(currConfig.divisor) + + " b " + QString::number(currConfig.bitPerSample) + + " d " + QString::number(currConfig.decimation) + + " a " + QString(currConfig.averaging ? "1" : "0") + + " t " + QString::number(currConfig.triggerThreshold) + + " s " + QString::number(currConfig.samplesToSkip), + 500); + util->execCMDWithOutput("hw setlfdivisor " + QString::number(currConfig.divisor), 500); + } + else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) + { + util->execCMDWithOutput(QString("lf config") + + " -a " + QString(currConfig.averaging ? "1" : "0") + + " -b " + QString::number(currConfig.bitPerSample) + + " --dec " + QString::number(currConfig.decimation) + + " --divisor " + QString::number(currConfig.divisor) + + " -s " + QString::number(currConfig.samplesToSkip) + + " -t " + QString::number(currConfig.triggerThreshold), + 500); + util->execCMDWithOutput("hw setlfdivisor -d " + QString::number(currConfig.divisor), 500); + } +} +void LF::resetConfig() +{ + setConfig(defaultConfig); + getConfig(); } float LF::divisor2Freq(uint8_t divisor) @@ -125,7 +158,7 @@ uint8_t LF::freq2Divisor(float freq) void LF::syncWithUI() { - ui->LF_Conf_freqDivisorBox->setValue(currConfig.divisor); + ui->LF_Conf_freqDivisorBox->setValue(currConfig.divisor); // will trigger valueChanged() ui->LF_Conf_bitPerSampleBox->setValue(currConfig.bitPerSample); ui->LF_Conf_decimationBox->setValue(currConfig.decimation); ui->LF_Conf_averagingBox->setChecked(currConfig.averaging); diff --git a/module/lf.h b/module/lf.h index 581ae1c..e361a12 100644 --- a/module/lf.h +++ b/module/lf.h @@ -22,14 +22,26 @@ public: uint16_t samplesToSkip; }; + static constexpr Config defaultConfig = + { + 95, + 8, + 1, + true, + 0, + 0 + }; + void read(); void sniff(); void search(); void tune(); void getConfig(); - void setConfig(); + void setConfig(LF::Config config); + void resetConfig(); static float divisor2Freq(uint8_t divisor); static uint8_t freq2Divisor(float freq); + private: QWidget* parent; Ui::MainWindow *ui; diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 4151d06..ffc2df1 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -1337,5 +1337,29 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) void MainWindow::on_LF_Conf_getButton_clicked() { + setState(false); lf->getConfig(); + setState(true); +} + +void MainWindow::on_LF_Conf_setButton_clicked() +{ + LF::Config config; + setState(false); + config.divisor = ui->LF_Conf_freqDivisorBox->value(); + config.bitPerSample = ui->LF_Conf_bitPerSampleBox->value(); + config.decimation = ui->LF_Conf_decimationBox->value(); + config.averaging = ui->LF_Conf_averagingBox->isChecked(); + config.triggerThreshold = ui->LF_Conf_thresholdBox->value(); + config.samplesToSkip = ui->LF_Conf_skipsBox->value(); + lf->setConfig(config); + Util::gotoRawTab(); + setState(true); +} + +void MainWindow::on_LF_Conf_resetButton_clicked() +{ + setState(false); + lf->resetConfig(); + setState(true); } diff --git a/ui/mainwindow.h b/ui/mainwindow.h index a4954dd..0909979 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -199,6 +199,10 @@ private slots: void on_LF_Conf_getButton_clicked(); + void on_LF_Conf_setButton_clicked(); + + void on_LF_Conf_resetButton_clicked(); + private: Ui::MainWindow* ui; QButtonGroup* MFCardTypeBtnGroup; diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index d7cfa04..4e62cae 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -21,7 +21,7 @@ - + 0 0 @@ -136,7 +136,7 @@ - 1 + 4 @@ -1211,512 +1211,613 @@ true - LF/Data + LF - - - - 10 - 10 - 431 - 341 - - - - LF Config - - - - 2 - - - 2 - - - 5 - - - 2 - - - 2 - - - - - Frequency - - - - 5 - - - 2 - - - 5 - - - 2 - - - 2 + + + + + + + LF Config - - - - - - - 0 - 0 - - - - 125k - - - true - - - - - - - - 0 - 0 - - - - 134k - - - - - - - - 0 - 0 - - - - other - - - - - - - Divisor: - - - - - - - 19 - - - 255 + + + 2 + + + 2 + + + 5 + + + 2 + + + 2 + + + + + Frequency + + + + 5 - - 95 + + 2 - - - - - - Actural Freq: 125.000kHz + + 5 - - - - - - Qt::Horizontal + + 2 - - - 40 - 20 - + + 2 - - - - - - - - 19 - - - 255 - - - 95 - - - Qt::Horizontal - - - - - - - Note: -You might need a modified LF antenna if the freq is not 125k/134k. - - - true - - - - - - - - - - - - - - Bit per sample: - - - - - - - Decimation: - + + + + + + + 0 + 0 + + + + 125k + + + true + + + + + + + + 0 + 0 + + + + 134k + + + + + + + + 0 + 0 + + + + other + + + + + + + Divisor: + + + + + + + 19 + + + 255 + + + 95 + + + + + + + Actural Freq: 125.000kHz + + + + + + + Qt::Horizontal + + + + + + + + + 19 + + + 255 + + + 95 + + + Qt::Horizontal + + + + + + + Note: +You might need a modified LF antenna if the freq is not 125k/134k. +When setting the freq, the "hw setlfdivisor" will also be called. + + + true + + + + - - - - 1 - - - 8 - - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Bit per sample: + + + + + + + Decimation: + + + + + + + 1 + + + 8 + + + + + + + Averaging: + + + + + + + + + + + + + + Trigger threshold: + + + + + + + 128 + + + + + + + Samples to skip: + + + + + + + 65535 + + + + + + + 1 + + + 8 + + + 8 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - - Averaging: - - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 20 + 0 + + + + Get + + + + + + + + 0 + 0 + + + + + 20 + 0 + + + + Set + + + + + + + Reset + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - - - - + + + + + + + LF Operation + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + Search + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + + + + + + + 0 + 0 + + + + Read and search for valid known tag. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + - - - - Trigger threshold: + + + + Qt::Horizontal - - - - 128 - - + + + + + + + + Read + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + + + + + + + 0 + 0 + + + + Sniff low frequency signal with LF field ON. +Use this to get raw data from a tag. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + - - - - Samples to skip: + + + + Qt::Horizontal - - - - 65535 - - + + + + + + + + Tune + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + + + + + + + 0 + 0 + + + + Measure LF antenna tuning. +If the antenna voltage has a obvious drop after putting card on the antenna, it is likely that the tag is a LF tag. +On Iceman/RRG repo, press the button on PM3 to stop measuring + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + - - - - 1 - - - 8 - - - 8 + + + + Qt::Horizontal - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - - 20 - 0 - - - - Get - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 20 - 0 - - - - Set - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 500 - 30 - 311 - 361 - - - - LF Operation - - - - - - - - Search - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Read and search for valid known tag. - - - true - - - - - - - - - Read - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Sniff low frequency signal with LF field ON. -Use this to get raw data from a tag. - - - true - - - - - - - - - Tune - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Measure LF antenna tuning. -If the antenna voltage has a obvious drop after putting card on the antenna, it is likely that the tag is a LF tag. -On Iceman/RRG repo, press the button on PM3 to stop measuring - - - true - - - - - - - - - Sniff - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Sniff low frequency signal with LF field OFF. + + + + + + + + Sniff + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + + + + + + + 0 + 0 + + + + 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. - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 502 + 0 + + + + + @@ -2093,12 +2194,6 @@ or "-p <port> -f" Qt::Horizontal - - - 40 - 20 - - @@ -2111,12 +2206,6 @@ or "-p <port> -f" Qt::Vertical - - - 20 - 40 - - @@ -2126,12 +2215,6 @@ or "-p <port> -f" Qt::Horizontal - - - 40 - 20 - -