TSI_Config/tachometer.cpp

71 lines
2.6 KiB
C++

#include "tachometer.h"
#include "ui_tachometer.h"
#include <QDebug>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include <QJsonArray>
Tachometer::Tachometer(int slot_no_,QWidget *parent)
: QDialog(parent)
, ui(new Ui::Tachometer)
{
ui->setupUi(this);
ui->widget_body->setProperty("flag", "body");
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();
}
Tachometer::~Tachometer()
{
delete ui;
}
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()
{
}