LF: Support write LF config

When setting LF freq, the "lf config" and "hw setlfdivisor" will both be called.
Change some UI
pull/33/head
wh201906 4 years ago
parent 466cd0ecc1
commit 15538a9892

@ -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);

@ -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;

@ -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);
}

@ -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;

@ -21,7 +21,7 @@
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -136,7 +136,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
<number>4</number>
</property>
<widget class="QWidget" name="mifareTab">
<attribute name="title">
@ -1211,17 +1211,13 @@
<bool>true</bool>
</property>
<attribute name="title">
<string>LF/Data</string>
<string>LF</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_22">
<item>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QGroupBox" name="LF_configGroupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>431</width>
<height>341</height>
</rect>
</property>
<property name="title">
<string>LF Config</string>
</property>
@ -1338,12 +1334,6 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
@ -1368,7 +1358,8 @@
<widget class="QLabel" name="label_22">
<property name="text">
<string>Note:
You might need a modified LF antenna if the freq is not 125k/134k.</string>
You might need a modified LF antenna if the freq is not 125k/134k.
When setting the freq, the &quot;hw setlfdivisor&quot; will also be called.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -1380,6 +1371,19 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<spacer name="horizontalSpacer_18">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
@ -1480,6 +1484,19 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<spacer name="horizontalSpacer_17">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="LF_Conf_getButton">
<property name="sizePolicy">
@ -1499,19 +1516,6 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="LF_Conf_setButton">
<property name="sizePolicy">
@ -1531,38 +1535,56 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</property>
</widget>
</item>
</layout>
<item>
<widget class="QPushButton" name="LF_Conf_resetButton">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>500</x>
<y>30</y>
<width>311</width>
<height>361</height>
</rect>
</property>
<property name="title">
<string>LF Operation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_27">
<item>
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QPushButton" name="LF_Op_searchButton">
<property name="text">
@ -1571,15 +1593,12 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_16">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
</spacer>
</item>
@ -1587,16 +1606,36 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</item>
<item>
<widget class="QLabel" name="label_24">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Read and search for valid known tag.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_21">
<item>
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
<widget class="QPushButton" name="LF_Op_readButton">
<property name="text">
@ -1605,15 +1644,12 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
</spacer>
</item>
@ -1621,17 +1657,37 @@ You might need a modified LF antenna if the freq is not 125k/134k.</string>
</item>
<item>
<widget class="QLabel" name="label_25">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sniff low frequency signal with LF field ON.
Use this to get raw data from a tag.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_26">
<item>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QPushButton" name="LF_Op_tuneButton">
<property name="text">
@ -1640,15 +1696,12 @@ Use this to get raw data from a tag.</string>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_15">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
</spacer>
</item>
@ -1656,18 +1709,38 @@ Use this to get raw data from a tag.</string>
</item>
<item>
<widget class="QLabel" name="label_26">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>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</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_25">
<item>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<widget class="QPushButton" name="LF_Op_sniffButton">
<property name="text">
@ -1676,15 +1749,12 @@ On Iceman/RRG repo, press the button on PM3 to stop measuring</string>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_14">
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
</spacer>
</item>
@ -1692,31 +1762,62 @@ On Iceman/RRG repo, press the button on PM3 to stop measuring</string>
</item>
<item>
<widget class="QLabel" name="label_27">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>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.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_19">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>502</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="t55xxTab">
<attribute name="title">
@ -2093,12 +2194,6 @@ or &quot;-p &lt;port&gt; -f&quot;</string>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
@ -2111,12 +2206,6 @@ or &quot;-p &lt;port&gt; -f&quot;</string>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
@ -2126,12 +2215,6 @@ or &quot;-p &lt;port&gt; -f&quot;</string>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>

Loading…
Cancel
Save