2024-12-17 18:53:41 +08:00
|
|
|
#include "tachometer.h"
|
|
|
|
#include "ui_tachometer.h"
|
2025-03-21 10:42:24 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonParseError>
|
|
|
|
#include <QJsonArray>
|
2024-12-17 18:53:41 +08:00
|
|
|
|
2025-03-21 10:42:24 +08:00
|
|
|
Tachometer::Tachometer(int slot_no_,QWidget *parent)
|
2024-12-17 18:53:41 +08:00
|
|
|
: QDialog(parent)
|
|
|
|
, ui(new Ui::Tachometer)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2025-03-11 16:42:00 +08:00
|
|
|
ui->widget_body->setProperty("flag", "body");
|
2025-03-21 10:42:24 +08:00
|
|
|
slot_no = slot_no_;
|
|
|
|
QString slot = QString("%1").arg(slot_no);
|
|
|
|
|
|
|
|
QString filePath_tachometer = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\tachometer.json").arg(slot_no);
|
|
|
|
readJsonFile(filePath_tachometer);
|
|
|
|
Init();
|
2024-12-17 18:53:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Tachometer::~Tachometer()
|
|
|
|
{
|
2025-03-21 10:42:24 +08:00
|
|
|
|
2024-12-17 18:53:41 +08:00
|
|
|
delete ui;
|
|
|
|
}
|
2025-03-21 10:42:24 +08:00
|
|
|
void Tachometer::readJsonFile(const QString &filePath)
|
|
|
|
{
|
|
|
|
QFile file(filePath);
|
|
|
|
if(!file.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
qDebug() << "Could not open file for reading";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QByteArray saveData = file.readAll();
|
|
|
|
QJsonParseError json_error;
|
|
|
|
QJsonDocument parse_doucment = QJsonDocument::fromJson(saveData, &json_error);
|
|
|
|
if(json_error.error != QJsonParseError::NoError)
|
|
|
|
{
|
|
|
|
qDebug() << "json error!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QJsonObject json_obj = parse_doucment.object();
|
|
|
|
QJsonArray chan_array = json_obj["chan"].toArray();
|
|
|
|
for(int i = 0; i < chan_array.size(); i++){
|
|
|
|
QJsonObject temp_obj = chan_array[i].toObject();
|
|
|
|
tachometer_variables[i].id = temp_obj["id"].toInt();
|
|
|
|
tachometer_variables[i].active = temp_obj["active"].toBool();
|
|
|
|
QJsonArray voltage_range_array = temp_obj["normal_voltage_range"].toArray();
|
|
|
|
tachometer_variables[i].normal_voltage_high = voltage_range_array[1].toDouble();
|
|
|
|
tachometer_variables[i].normal_voltage_low = voltage_range_array[0].toDouble();
|
|
|
|
tachometer_variables[i].threshold = temp_obj["threshold"].toDouble();
|
|
|
|
tachometer_variables[i].hysteresis = temp_obj["hysteresis"].toDouble();
|
|
|
|
tachometer_variables[i].events_per_revolution = temp_obj["events_per_revolution"].toInt();
|
|
|
|
tachometer_variables[i].record_output = temp_obj["record_output"].toString();
|
|
|
|
tachometer_variables[i].two_ma_clamp = temp_obj["two_ma_clamp"].toBool();
|
|
|
|
tachometer_variables[i].alert_latching = temp_obj["alert_latching"].toBool();
|
|
|
|
tachometer_variables[i].overspeed_latching = temp_obj["overspeed_latching"].toBool();
|
|
|
|
tachometer_variables[i].normal_latching = temp_obj["normal_latching"].toBool();
|
|
|
|
tachometer_variables[i].alert_response_time = temp_obj["alert_response_time"].toInt();
|
|
|
|
tachometer_variables[i].danger_response_time = temp_obj["danger_response_time"].toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void Tachometer::Init()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|