|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include "lf.h"
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
|
|
|
|
const LF::Config LF::defaultConfig;
|
|
|
|
|
const LF::LFConfig LF::defaultLFConfig;
|
|
|
|
|
|
|
|
|
|
LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent)
|
|
|
|
|
{
|
|
|
|
@ -8,142 +9,122 @@ LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent)
|
|
|
|
|
util = addr;
|
|
|
|
|
this->ui = ui;
|
|
|
|
|
|
|
|
|
|
configPattern = new QRegularExpression("(\\d+)|Yes|No");
|
|
|
|
|
currConfig = defaultConfig;
|
|
|
|
|
LFconfigPattern = new QRegularExpression("(\\d+)|Yes|No");
|
|
|
|
|
currLFConfig = defaultLFConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LF::read()
|
|
|
|
|
{
|
|
|
|
|
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
|
|
|
|
|
util->execCMD("lf read");
|
|
|
|
|
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
|
|
|
|
|
util->execCMD("lf read -v");
|
|
|
|
|
QVariantMap config = configMap["read"].toMap();
|
|
|
|
|
util->execCMD(config["cmd"].toString());
|
|
|
|
|
Util::gotoRawTab();
|
|
|
|
|
util->execCMD("data plot");
|
|
|
|
|
util->execCMD(config["show cmd"].toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LF::sniff()
|
|
|
|
|
{
|
|
|
|
|
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
|
|
|
|
|
util->execCMD("lf snoop");
|
|
|
|
|
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
|
|
|
|
|
util->execCMD("lf sniff -v");
|
|
|
|
|
QVariantMap config = configMap["sniff"].toMap();
|
|
|
|
|
util->execCMD(config["cmd"].toString());
|
|
|
|
|
Util::gotoRawTab();
|
|
|
|
|
util->execCMD("data plot");
|
|
|
|
|
util->execCMD(config["show cmd"].toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LF::search()
|
|
|
|
|
{
|
|
|
|
|
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
|
|
|
|
|
util->execCMD("lf search u");
|
|
|
|
|
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
|
|
|
|
|
util->execCMD("lf search -u");
|
|
|
|
|
QVariantMap config = configMap["search"].toMap();
|
|
|
|
|
util->execCMD(config["cmd"].toString());
|
|
|
|
|
Util::gotoRawTab();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 --divisor " + QString::number(currConfig.divisor));
|
|
|
|
|
QVariantMap config = configMap["tune"].toMap();
|
|
|
|
|
QString cmd = config["cmd"].toString();
|
|
|
|
|
cmd.replace("<divisor>", QString::number(currLFConfig.divisor));
|
|
|
|
|
util->execCMD(cmd);
|
|
|
|
|
Util::gotoRawTab();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LF::getConfig()
|
|
|
|
|
bool LF::getLFConfig_helper(const QVariantMap& map, QString& str, int* result)
|
|
|
|
|
{
|
|
|
|
|
int len;
|
|
|
|
|
QString flag = map["flag"].toString();
|
|
|
|
|
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("\n", offset);
|
|
|
|
|
result = result.mid(0, offset + 2);
|
|
|
|
|
qDebug() << "LF CONFIG GET\n" << result;
|
|
|
|
|
resultList = result.split("\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)
|
|
|
|
|
if(!str.contains(flag))
|
|
|
|
|
return false;
|
|
|
|
|
len = str.length() - (str.indexOf(flag) + flag.length());
|
|
|
|
|
str = str.right(len);
|
|
|
|
|
if(map.contains("replace"))
|
|
|
|
|
{
|
|
|
|
|
currConfig.bitPerSample = configList[1].toUInt();
|
|
|
|
|
currConfig.averaging = (configList[4] == "1");
|
|
|
|
|
}
|
|
|
|
|
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
|
|
|
|
|
QVariantMap table = map["replace"].toMap();
|
|
|
|
|
for(auto it = table.begin(); it != table.end(); it++)
|
|
|
|
|
{
|
|
|
|
|
currConfig.bitPerSample = configList[2].toUInt();
|
|
|
|
|
currConfig.averaging = (configList[4] == "Yes");
|
|
|
|
|
str.replace(it.key(), it.value().toString());
|
|
|
|
|
}
|
|
|
|
|
syncWithUI();
|
|
|
|
|
}
|
|
|
|
|
reMatch = QRegularExpression(map["pattern"].toString()).match(str);
|
|
|
|
|
if(!reMatch.hasMatch())
|
|
|
|
|
return false;
|
|
|
|
|
*result = reMatch.captured().toInt();
|
|
|
|
|
qDebug() << *result;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
void LF::getLFConfig()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
QRegularExpressionMatch reMatch;
|
|
|
|
|
QString result;
|
|
|
|
|
QStringList resultList;
|
|
|
|
|
int start, end, temp;
|
|
|
|
|
QVariantMap config = configMap["get config"].toMap();
|
|
|
|
|
QString cmd = config["cmd"].toString();
|
|
|
|
|
result = util->execCMDWithOutput(cmd, 400);
|
|
|
|
|
start = result.indexOf(config["field start"].toString());
|
|
|
|
|
end = result.indexOf(config["field end"].toString());
|
|
|
|
|
result = result.mid(start, end - start);
|
|
|
|
|
resultList = result.split("\n", Qt::SkipEmptyParts);
|
|
|
|
|
qDebug() << "LF CONFIG GET\n" << resultList;
|
|
|
|
|
for(auto it = resultList.begin(); it != resultList.end(); it++)
|
|
|
|
|
{
|
|
|
|
|
if(getLFConfig_helper(config["divisor"].toMap(), *it, &temp))
|
|
|
|
|
currLFConfig.divisor = temp;
|
|
|
|
|
else if(getLFConfig_helper(config["bits per sample"].toMap(), *it, &temp))
|
|
|
|
|
currLFConfig.bitsPerSample = temp;
|
|
|
|
|
else if(getLFConfig_helper(config["decimation"].toMap(), *it, &temp))
|
|
|
|
|
currLFConfig.decimation = temp;
|
|
|
|
|
else if(getLFConfig_helper(config["averaging"].toMap(), *it, &temp))
|
|
|
|
|
currLFConfig.averaging = (bool)temp;
|
|
|
|
|
else if(getLFConfig_helper(config["trigger threshold"].toMap(), *it, &temp))
|
|
|
|
|
currLFConfig.triggerThreshold = temp;
|
|
|
|
|
else if(getLFConfig_helper(config["samples to skip"].toMap(), *it, &temp))
|
|
|
|
|
currLFConfig.samplesToSkip = temp;
|
|
|
|
|
}
|
|
|
|
|
syncWithUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LF::resetConfig()
|
|
|
|
|
void LF::setLFConfig(LF::LFConfig lfconfig)
|
|
|
|
|
{
|
|
|
|
|
currLFConfig = lfconfig;
|
|
|
|
|
QVariantMap config = configMap["set config"].toMap();
|
|
|
|
|
QString cmd = config["cmd"].toString();
|
|
|
|
|
cmd.replace("<divisor>", QString::number(currLFConfig.divisor));
|
|
|
|
|
cmd.replace("<bits per sample>", QString::number(currLFConfig.bitsPerSample));
|
|
|
|
|
cmd.replace("<decimation>", QString::number(currLFConfig.decimation));
|
|
|
|
|
cmd.replace("<averaging>", currLFConfig.averaging ? "1" : "0");
|
|
|
|
|
cmd.replace("<trigger threshold>", QString::number(currLFConfig.triggerThreshold));
|
|
|
|
|
cmd.replace("<samples to skip>", QString::number(currLFConfig.samplesToSkip));
|
|
|
|
|
util->execCMDWithOutput(cmd, 500);
|
|
|
|
|
cmd = config["divisor cmd"].toString();
|
|
|
|
|
cmd.replace("<divisor>", QString::number(currLFConfig.divisor));
|
|
|
|
|
util->execCMDWithOutput(cmd, 500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LF::resetLFConfig()
|
|
|
|
|
{
|
|
|
|
|
setConfig(defaultConfig);
|
|
|
|
|
getConfig();
|
|
|
|
|
setLFConfig(defaultLFConfig);
|
|
|
|
|
getLFConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float LF::divisor2Freq(uint8_t divisor)
|
|
|
|
@ -158,10 +139,16 @@ uint8_t LF::freq2Divisor(float freq)
|
|
|
|
|
|
|
|
|
|
void LF::syncWithUI()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
ui->LF_Conf_thresholdBox->setValue(currConfig.triggerThreshold);
|
|
|
|
|
ui->LF_Conf_skipsBox->setValue(currConfig.samplesToSkip);
|
|
|
|
|
ui->LF_LFConf_freqDivisorBox->setValue(currLFConfig.divisor); // will trigger valueChanged()
|
|
|
|
|
ui->LF_LFConf_bitsPerSampleBox->setValue(currLFConfig.bitsPerSample);
|
|
|
|
|
ui->LF_LFConf_decimationBox->setValue(currLFConfig.decimation);
|
|
|
|
|
ui->LF_LFConf_averagingBox->setChecked(currLFConfig.averaging);
|
|
|
|
|
ui->LF_LFConf_thresholdBox->setValue(currLFConfig.triggerThreshold);
|
|
|
|
|
ui->LF_LFConf_skipsBox->setValue(currLFConfig.samplesToSkip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LF::setConfigMap(const QVariantMap& configMap)
|
|
|
|
|
{
|
|
|
|
|
this->configMap = configMap;
|
|
|
|
|
qDebug() << configMap;
|
|
|
|
|
}
|
|
|
|
|