add codes.

This commit is contained in:
pandx 2025-04-01 15:03:59 +08:00
parent 576fe1ffd1
commit eaed2efaa5
13 changed files with 560 additions and 391 deletions

View File

@ -6,6 +6,10 @@
#include <QJsonObject>
#include <QFile>
#include "data_config.h"
#include "vibrationdata.h"
#include "config_mgr.h"
Acceleration::Acceleration(int slot_no_, int channel_, bool active, QWidget *parent) :
QWidget(parent),
ui(new Ui::Acceleration) {
@ -21,10 +25,10 @@ Acceleration::Acceleration(int slot_no_, int channel_, bool active, QWidget *par
} else {
ui->label_active->setText("(停用)");
}
QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_filter);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_variables);
// QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
// readJsonFile(filePath_filter);
// QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
// readJsonFile(filePath_variables);
Init();
}
@ -162,75 +166,8 @@ void Acceleration::on_checkBox_2x_ampl_toggled(bool checked) {
ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(false);
}
void Acceleration::readJsonFile(const QString &filePath) {
// 创建文件对象
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for reading:" << filePath;
return;
}
QString content = file.readAll();
file.close();
QByteArray jsonData = content.toUtf8();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) {
qDebug() << "Cannot parse JSON document";
return;
}
if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
qDebug() << "JSON document is not an object or an array";
return;
}
QJsonObject json_obj = jsonDoc.object();
if (filePath.contains("filter_")) {
QJsonArray filter_array = json_obj["filter"].toArray();
for (int i = 0; i < filter_array.size(); i++) {
QJsonObject temp_obj = filter_array[i].toObject();
filter[i].type = temp_obj["type"].toString();
filter[i].low = temp_obj["low"].toInt();
filter[i].high = temp_obj["high"].toInt();
filter[i].checked = temp_obj["checked"].toBool();
}
} else if (filePath.contains("acceleration_variables_")) {
QJsonArray variables_array = json_obj["variables"].toArray();
for (int i = 0; i < variables_array.size(); i++) {
QJsonObject temp_obj = variables_array[i].toObject();
variables[i].type = temp_obj["type"].toString();
if (variables[i].type == "direct") {
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
} else if (variables[i].type == "bias_volt") {
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].bias_voltage = temp_obj["bias_voltage"].toInt();
} else if (variables[i].type == "1x_ampl") {
variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].toDouble();
} else if (variables[i].type == "2x_ampl") {
variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].toDouble();
}
}
QJsonObject delay_obj = json_obj["delay"].toObject();
delay.alert = delay_obj["alert"].toInt();
delay.danger = delay_obj["danger"].toDouble();
delay.active_100ms = delay_obj["100ms"].toBool();
alert_variables.rms_active = json_obj["rms_active"].toBool();
alert_variables.integrate_active = json_obj["integrate_active"].toBool();
alert_variables.alert_latching = json_obj["alert_latching"].toBool();
alert_variables.danger_latching = json_obj["danger_latching"].toBool();
alert_variables.timed_ok = json_obj["timed_ok"].toBool();
alert_variables.recorder_output = json_obj["recorder_output"].toInt();
alert_variables.two_ma_clamp = json_obj["two_ma_clamp"].toBool();
alert_variables.trip_multiply = json_obj["trip_multiply"].toDouble();
alert_variables.comparision = json_obj["comparision"].toString();
alert_variables.comparision_percentage = json_obj["comparision_percentage"].toInt();
}
}
void Acceleration::Init() {
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
for (int i = 0; i < 3; i++) {
if (filter[i].checked) {
if (filter[i].type == "band_pass") {
@ -378,24 +315,24 @@ void Acceleration::on_pushButton_confirm_clicked() {
variables_obj.insert("slot", slot_no);
variables_obj.insert("id", channel);
variables_obj.insert("version", 1);
QJsonDocument jsonDoc_filter(filter_obj);
QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath;
return;
}
file.write(jsonDoc_filter.toJson());
file.close();
QJsonDocument jsonDoc_variables(variables_obj);
filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
file.setFileName(filePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath;
return;
}
file.write(jsonDoc_variables.toJson());
file.close();
// QJsonDocument jsonDoc_filter(filter_obj);
// QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
// QFile file(filePath);
// if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
// qDebug() << "Cannot open file for writing:" << filePath;
// return;
// }
// file.write(jsonDoc_filter.toJson());
// file.close();
// QJsonDocument jsonDoc_variables(variables_obj);
// filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
// file.setFileName(filePath);
// if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
// qDebug() << "Cannot open file for writing:" << filePath;
// return;
// }
// file.write(jsonDoc_variables.toJson());
// file.close();
this->close();
}

View File

@ -31,12 +31,12 @@ class Acceleration : public QWidget {
private:
Ui::Acceleration *ui;
Filter filter[3];
Dealy delay;
Variables variables[4];
Alert_Variables alert_variables;
// Filter filter[3];
// Dealy delay;
// Variables variables[4];
// Alert_Variables alert_variables;
void readJsonFile(const QString &filePath);
// void readJsonFile(const QString &filePath);
void Init();
};

View File

@ -2,30 +2,30 @@
#define CARDBASE_H
#include "data_config.h"
#ifdef NAME
#undef NAME
#endif
#define NAME(x) (x, #x)
//#ifdef NAME
// #undef NAME
//#endif
//#define NAME(x) (x, #x)
class CardBase {
public:
CardBase() {}
~CardBase() {}
void FromJson(const Json::Value &cfg) {
version_ = cfg["version"].asInt();
slot_ = cfg["slot"].asInt();
card_type_ = static_cast<CardType>(cfg["type"].asInt());
}
// void FromJson(const Json::Value &cfg) {
// version_ = cfg["version"].asInt();
// slot_ = cfg["slot"].asInt();
// card_type_ = static_cast<CardType>(cfg["type"].asInt());
// }
Json::Value ToJson() {
Json::Value ch;
ch[NAME(version)] = version_;
ch[NAME(slot)] = slot_;
ch[NAME(type)] = card_type_;
return ch;
}
// Json::Value ToJson() {
// Json::Value ch;
// ch[NAME(version)] = version_;
// ch[NAME(slot)] = slot_;
// ch[NAME(type)] = card_type_;
// return ch;
// }
protected:
// protected:
int version_;
int slot_; // 从1~15
CardType card_type_;
@ -35,14 +35,14 @@ class VariableBase {
public:
VariableBase() {}
~VariableBase() {}
// TODO: fromjson, tojson
int id_;
VibChannelType type_;
Delay delay_;
DirectImpl direct_;
XImpl x1_;
XImpl x2_;
RecorderOut recorder_out_;
Delay delay_;
};
// 位移

View File

@ -13,11 +13,190 @@ ConfigMgr::~ConfigMgr() {
}
void ConfigMgr::Save() {
QJsonObject doc_obj;
doc_obj["version"] = 1;
int slot = 0;
QJsonArray card_type;
for (int i = 0; i < SLOT_NUM; ++i) {
if (card_type_[i] == kCardNone) {
continue;
}
QJsonObject card_item;
slot = i + 1;
card_item["type"] = card_type_[i];
card_item["slot"] = slot;
card_type.append(card_item);
if (card_type_[i] != kCardVibSingle &&
card_type_[i] != kCardVibTMRPrimary &&
card_type_[i] != kCardSpeedSingle &&
card_type_[i] != kCardSpeedTMRPrimary &&
card_type_[i] != kCardKeyphase &&
card_type_[i] != kCardRelaySingle &&
card_type_[i] != kCardRelayTMRPrimary) {
continue;
}
// process slot
QJsonObject slot_item;
if (card_type_[i] != kCardRelaySingle &&
card_type_[i] != kCardRelayTMRPrimary) {
for (int cid = 0; cid < CHANNEL_COUNT; ++cid) {
QJsonObject channel_item;
if (card_type_[i] == kCardVibSingle ||
card_type_[i] == kCardVibTMRPrimary) {
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot);
if (base_ptr == nullptr) {
continue;
}
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
channel_item["standby"] = ptr->base_config_[cid].standby;
channel_item["active"] = ptr->base_config_[cid].active;
channel_item["rack_type"] = 0; // TODO:
channel_item["channel_type"] = ptr->base_config_[cid].channel_type;
channel_item["transducer_id"] = ptr->base_config_[cid].transducer_id;
channel_item["scale_factor"] = ptr->base_config_[cid].scale_factor;
channel_item["sampling_rate"] = ptr->base_config_[cid].sampling_rate;
QJsonArray voltage_range;
voltage_range.append(ptr->base_config_[cid].normal_voltage_low);
voltage_range.append(ptr->base_config_[cid].normal_voltage_high);
channel_item["normal_voltage_range"] = voltage_range;
// filter
QJsonArray filter;
QJsonObject low_pass;
low_pass["low"] = ptr->filter_[cid].filter[0].low;
low_pass["high"] = ptr->filter_[cid].filter[0].high;
low_pass["checked"] = ptr->filter_[cid].filter[0].checked;
filter.append(low_pass);
QJsonObject high_pass;
high_pass["low"] = ptr->filter_[cid].filter[1].low;
high_pass["high"] = ptr->filter_[cid].filter[1].high;
high_pass["checked"] = ptr->filter_[cid].filter[1].checked;
filter.append(high_pass);
QJsonObject band_pass;
band_pass["low"] = ptr->filter_[cid].filter[2].low;
band_pass["high"] = ptr->filter_[cid].filter[2].high;
band_pass["checked"] = ptr->filter_[cid].filter[2].checked;
filter.append(band_pass);
channel_item["filter"] = filter;
// variables
QJsonObject variables;
std::shared_ptr<VariableBase> base_channel_ptr = ptr->GetChannelPtr(cid + 1);
if (base_channel_ptr->type_ == kVibRadial) {
std::shared_ptr<RadialVariable> radial_ptr = std::dynamic_pointer_cast<RadialVariable>(base_channel_ptr);
QJsonObject direct;
QJsonObject x1;
QJsonObject x2;
QJsonObject recorder_out;
QJsonObject delay;
QJsonObject not1x;
QJsonObject smax;
QJsonArray latching;
direct["full_scale_range"] = radial_ptr->direct_.full_scale_range;
direct["clamp_value"] = radial_ptr->direct_.clamp_value;
direct["custom"] = radial_ptr->direct_.custom;
variables["direct"] = direct;
x1["checked"] = radial_ptr->x1_.checked;
x1["full_scale_range"] = radial_ptr->x1_.full_scale_range;
x1["clamp_value"] = radial_ptr->x1_.clamp_value;
x1["custom"] = radial_ptr->x1_.custom;
x1["phase_lag"] = radial_ptr->x1_.phase_lag;
variables["x1"] = x1;
x2["checked"] = radial_ptr->x2_.checked;
x2["full_scale_range"] = radial_ptr->x2_.full_scale_range;
x2["clamp_value"] = radial_ptr->x2_.clamp_value;
x2["custom"] = radial_ptr->x2_.custom;
x2["phase_lag"] = radial_ptr->x2_.phase_lag;
variables["x2"] = x2;
recorder_out["recorder_output"] = radial_ptr->recorder_out_.recorder_output;
recorder_out["two_ma_clamp"] = radial_ptr->recorder_out_.two_ma_clamp;
recorder_out["trip_multiply"] = radial_ptr->recorder_out_.trip_multiply;
recorder_out["comparision"] = radial_ptr->recorder_out_.comparision;
recorder_out["percentage"] = radial_ptr->recorder_out_.percentage;
variables["recorder_out"] = recorder_out;
delay["alert"] = radial_ptr->delay_.alert;
delay["danger"] = radial_ptr->delay_.danger;
delay["active_100ms"] = radial_ptr->delay_.active_100ms;
variables["delay"] = delay;
not1x["checked"] = radial_ptr->not1x_.checked;
not1x["full_scale_range"] = radial_ptr->not1x_.full_scale_range;
not1x["clamp_value"] = radial_ptr->not1x_.clamp_value;
not1x["custom"] = radial_ptr->not1x_.custom;
variables["not1x"] = not1x;
smax["checked"] = radial_ptr->smax_.checked;
smax["full_scale_range"] = radial_ptr->smax_.full_scale_range;
smax["clamp_value"] = radial_ptr->smax_.clamp_value;
smax["custom"] = radial_ptr->smax_.custom;
variables["smax"] = smax;
latching.append(radial_ptr->alert_latching_);
latching.append(radial_ptr->danger_latching_);
variables["latching"] = latching;
} else {
std::shared_ptr<AccVelVariable> av_ptr = std::dynamic_pointer_cast<AccVelVariable>(base_channel_ptr);
QJsonObject direct;
QJsonObject x1;
QJsonObject x2;
QJsonObject recorder_out;
QJsonObject delay;
QJsonArray latching;
direct["full_scale_range"] = av_ptr->direct_.full_scale_range;
direct["clamp_value"] = av_ptr->direct_.clamp_value;
direct["custom"] = av_ptr->direct_.custom;
variables["direct"] = direct;
x1["checked"] = av_ptr->x1_.checked;
x1["full_scale_range"] = av_ptr->x1_.full_scale_range;
x1["clamp_value"] = av_ptr->x1_.clamp_value;
x1["custom"] = av_ptr->x1_.custom;
x1["phase_lag"] = av_ptr->x1_.phase_lag;
variables["x1"] = x1;
x2["checked"] = av_ptr->x2_.checked;
x2["full_scale_range"] = av_ptr->x2_.full_scale_range;
x2["clamp_value"] = av_ptr->x2_.clamp_value;
x2["custom"] = av_ptr->x2_.custom;
x2["phase_lag"] = av_ptr->x2_.phase_lag;
variables["x2"] = x2;
QJsonObject rms_integrate;
rms_integrate["rms_active"] = av_ptr->rms_active_;
rms_integrate["integrate_active"] = av_ptr->integrate_active_;
variables["rms_integrate"] = rms_integrate;
recorder_out["recorder_output"] = av_ptr->recorder_out_.recorder_output;
recorder_out["two_ma_clamp"] = av_ptr->recorder_out_.two_ma_clamp;
recorder_out["trip_multiply"] = av_ptr->recorder_out_.trip_multiply;
recorder_out["comparision"] = av_ptr->recorder_out_.comparision;
recorder_out["percentage"] = av_ptr->recorder_out_.percentage;
variables["recorder_out"] = recorder_out;
delay["alert"] = av_ptr->delay_.alert;
delay["danger"] = av_ptr->delay_.danger;
delay["active_100ms"] = av_ptr->delay_.active_100ms;
variables["delay"] = delay;
latching.append(av_ptr->alert_latching_);
latching.append(av_ptr->danger_latching_);
latching.append(av_ptr->timed_ok_);
variables["latching"] = latching;
}
channel_item["variable"] = variables;
} else {
// TODO: save speed, keyphase
}
slot_item[QString::number(cid + 1)] = channel_item;
}
} else {
// TODO: save relay data
}
doc_obj[QString::number(slot)] = slot_item;
}
doc_obj["card_type"] = card_type;
// TODO: show success message box
QJsonDocument jsonDoc;
jsonDoc.setObject(doc_obj);
QFile file(filename_);
file.open(QIODevice::WriteOnly);
file.write(jsonDoc.toJson());
file.close();
}
void ConfigMgr::Load(QString filename) {
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// TODO: show message box
qDebug() << "Cannot open file for reading:" << filename;
return;
}
@ -26,13 +205,16 @@ void ConfigMgr::Load(QString filename) {
QByteArray jsonData = content.toUtf8();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) {
// TODO: show message box
qDebug() << "Cannot parse JSON document";
return;
}
if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
// TODO: show message box
qDebug() << "JSON document is not an object or an array";
return;
}
filename_ = filename;
QJsonObject json_obj = jsonDoc.object();
// parse card_type
QJsonArray card_type = json_obj["card_type"].toArray();
@ -64,8 +246,7 @@ void ConfigMgr::Load(QString filename) {
vib_data->base_config_[j].rack_type = channel["rack_type"].toInt();
// vib_data->base_config_[j].tmr_group = channel["tmr_group"].toString();
vib_data->base_config_[j].channel_type = channel["channel_type"].toInt();
memset(vib_data->base_config_[j].transducer_name, 0, 32);
memcpy(vib_data->base_config_[j].transducer_name, channel["transducer_name"].toString().toStdString().c_str(), channel["transducer_name"].toString().length());
vib_data->base_config_[j].transducer_id = channel["transducer_id"].toInt();
vib_data->base_config_[j].scale_factor = channel["scale_factor"].toDouble();
vib_data->base_config_[j].sampling_rate = channel["sampling_rate"].toInt();
QJsonArray voltage_range_array = channel["normal_voltage_range"].toArray();
@ -83,15 +264,88 @@ void ConfigMgr::Load(QString filename) {
QJsonObject tmp_variable = channel["variable"].toObject();
switch (vib_data->base_config_[j].channel_type) {
case kVibRadial: {
std::shared_ptr<RadialVariable> radial_variable = std::make_shared<RadialVariable>();
radial_variable->id_ = j + 1;
vib_data->variables_.push_back(radial_variable);
std::shared_ptr<RadialVariable> variable = std::make_shared<RadialVariable>();
variable->id_ = j + 1;
QJsonObject direct = tmp_variable["direct"].toObject();
variable->direct_.full_scale_range = direct["full_scale_range"].toInt();
variable->direct_.clamp_value = direct["clamp_value"].toDouble();
variable->direct_.custom = direct["custom"].toDouble();
QJsonObject x1 = tmp_variable["x1"].toObject();
variable->x1_.checked = x1["checked"].toBool();
variable->x1_.full_scale_range = x1["full_scale_range"].toInt();
variable->x1_.clamp_value = x1["clamp_value"].toDouble();
variable->x1_.custom = x1["custom"].toDouble();
variable->x1_.phase_lag = x1["phase_lag"].toInt();
QJsonObject x2 = tmp_variable["x2"].toObject();
variable->x2_.checked = x2["checked"].toBool();
variable->x2_.full_scale_range = x2["full_scale_range"].toInt();
variable->x2_.clamp_value = x2["clamp_value"].toDouble();
variable->x2_.custom = x2["custom"].toDouble();
variable->x2_.phase_lag = x2["phase_lag"].toInt();
QJsonObject recorder_out = tmp_variable["recorder_out"].toObject();
variable->recorder_out_.recorder_output = recorder_out["recorder_output"].toInt();
variable->recorder_out_.two_ma_clamp = recorder_out["two_ma_clamp"].toBool();
variable->recorder_out_.trip_multiply = recorder_out["trip_multiply"].toDouble();
variable->recorder_out_.comparision = recorder_out["comparision"].toInt();
variable->recorder_out_.percentage = recorder_out["percentage"].toInt();
QJsonObject delay = tmp_variable["delay"].toObject();
variable->delay_.alert = delay["alert"].toInt();
variable->delay_.danger = delay["danger"].toDouble();
variable->delay_.active_100ms = delay["active_100ms"].toBool();
QJsonObject not1x = tmp_variable["not1x"].toObject();
variable->not1x_.checked = not1x["checked"].toBool();
variable->not1x_.full_scale_range = not1x["full_scale_range"].toInt();
variable->not1x_.clamp_value = not1x["clamp_value"].toDouble();
variable->not1x_.custom = not1x["custom"].toDouble();
QJsonObject smax = tmp_variable["smax"].toObject();
variable->smax_.checked = smax["checked"].toBool();
variable->smax_.full_scale_range = smax["full_scale_range"].toInt();
variable->smax_.clamp_value = smax["clamp_value"].toDouble();
variable->smax_.custom = smax["custom"].toDouble();
QJsonObject latching = tmp_variable["latching"].toObject();
variable->alert_latching_ = latching["alert"].toBool();
variable->danger_latching_ = latching["danger"].toBool();
vib_data->variables_.push_back(variable);
break;
}
case kVibVelocity:
case kVibAcc: {
std::shared_ptr<AccVelVariable> acc_vel_variable = std::make_shared<AccVelVariable>();
vib_data->variables_.push_back(acc_vel_variable);
std::shared_ptr<AccVelVariable> variable = std::make_shared<AccVelVariable>();
variable->id_ = j + 1;
QJsonObject direct = tmp_variable["direct"].toObject();
variable->direct_.full_scale_range = direct["full_scale_range"].toInt();
variable->direct_.clamp_value = direct["clamp_value"].toDouble();
variable->direct_.custom = direct["custom"].toDouble();
QJsonObject x1 = tmp_variable["x1"].toObject();
variable->x1_.checked = x1["checked"].toBool();
variable->x1_.full_scale_range = x1["full_scale_range"].toInt();
variable->x1_.clamp_value = x1["clamp_value"].toDouble();
variable->x1_.custom = x1["custom"].toDouble();
variable->x1_.phase_lag = x1["phase_lag"].toInt();
QJsonObject x2 = tmp_variable["x2"].toObject();
variable->x2_.checked = x2["checked"].toBool();
variable->x2_.full_scale_range = x2["full_scale_range"].toInt();
variable->x2_.clamp_value = x2["clamp_value"].toDouble();
variable->x2_.custom = x2["custom"].toDouble();
variable->x2_.phase_lag = x2["phase_lag"].toInt();
QJsonObject rms_integrate = tmp_variable["rms_integrate"].toObject();
variable->rms_active_ = rms_integrate["rms_active"].toBool();
variable->integrate_active_ = rms_integrate["integrate_active"].toBool();
QJsonObject recorder_out = tmp_variable["recorder_out"].toObject();
variable->recorder_out_.recorder_output = recorder_out["recorder_output"].toInt();
variable->recorder_out_.two_ma_clamp = recorder_out["two_ma_clamp"].toBool();
variable->recorder_out_.trip_multiply = recorder_out["trip_multiply"].toDouble();
variable->recorder_out_.comparision = recorder_out["comparision"].toInt();
variable->recorder_out_.percentage = recorder_out["percentage"].toInt();
QJsonObject delay = tmp_variable["delay"].toObject();
variable->delay_.alert = delay["alert"].toInt();
variable->delay_.danger = delay["danger"].toDouble();
variable->delay_.active_100ms = delay["active_100ms"].toBool();
QJsonObject latching = tmp_variable["latching"].toObject();
variable->alert_latching_ = latching["alert"].toBool();
variable->danger_latching_ = latching["danger"].toBool();
variable->timed_ok_ = latching["timed_ok"].toBool();
vib_data->variables_.push_back(variable);
break;
}
}
@ -100,3 +354,16 @@ void ConfigMgr::Load(QString filename) {
}
}
}
std::shared_ptr<CardBase> ConfigMgr::GetSlotPtr(int slot) {
for (auto &item : cards_) {
if (item->slot_ == slot) {
return item;
}
}
return nullptr;
}
void ConfigMgr::AddCard(std::shared_ptr<CardBase> ptr) {
cards_.push_back(ptr);
}

View File

@ -22,7 +22,10 @@ class ConfigMgr {
~ConfigMgr();
void Save();
void Load(QString filename);
std::shared_ptr<CardBase> GetSlotPtr(int slot);
void AddCard(std::shared_ptr<CardBase> ptr);
private:
QString filename_;
int card_type_[15];
std::vector<std::shared_ptr<CardBase>> cards_;
};

View File

@ -77,9 +77,9 @@ typedef struct {
bool standby;
bool active;
int rack_type; // VibRackType
char tmr_group[32];
// char tmr_group[32];
int channel_type; // VibChannelType
char transducer_name[32];
int transducer_id;
float scale_factor;
int sampling_rate; // VibSamplingRate
float normal_voltage_low;
@ -113,14 +113,14 @@ typedef struct {
} Variables;
typedef struct {
int full_sacle_range;
int full_scale_range;
float clamp_value;
float custom;
} DirectImpl;
typedef struct {
bool checked;
int full_sacle_range;
int full_scale_range;
float clamp_value;
float custom;
int phase_lag;
@ -128,7 +128,7 @@ typedef struct {
typedef struct {
bool checked;
int full_sacle_range;
int full_scale_range;
float clamp_value;
float custom;
} RadialImpl;
@ -156,8 +156,8 @@ typedef struct {
int recorder_output;
bool two_ma_clamp;
float trip_multiply;
QString comparision;
int comparision_percentage;
int comparision;
int percentage;
} RecorderOut;
typedef struct {

View File

@ -28,11 +28,11 @@ class Radial_vibration : public QWidget {
private:
Ui::Radial_vibration *ui;
Filter filter[3];
Dealy delay;
Variables variables[6];
Alert_Variables alert_variables;
void readJsonFile(const QString &filePath);
// Filter filter[3];
// Dealy delay;
// Variables variables[6];
// Alert_Variables alert_variables;
// void readJsonFile(const QString &filePath);
void Init();
};

View File

@ -9,6 +9,9 @@
#include "acceleration.h"
#include "velocity.h"
#include "radial_vibration.h"
#include "data_config.h"
#include "config_mgr.h"
#include "vibrationdata.h"
Seismic_monitor::Seismic_monitor(int slot, QWidget *parent) :
QWidget(parent),
@ -30,239 +33,191 @@ Seismic_monitor::Seismic_monitor(int slot, QWidget *parent) :
slot_no = slot;
QString slot_no_ = QString("%1").arg(slot_no);
ui->label_slot_no->setText(slot_no_);
QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\seismic_monitor_slot.json").arg(slot_no);
readJsonFile(filePath);
// QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\seismic_monitor_slot.json").arg(slot_no);
// readJsonFile(filePath);
Init();
}
Seismic_monitor::~Seismic_monitor() {
delete ui;
}
void Seismic_monitor::readJsonFile(const QString &filePath) {
// 创建文件对象
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for reading:" << filePath;
return;
}
QString content = file.readAll();
file.close();
QByteArray jsonData = content.toUtf8();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) {
qDebug() << "Cannot parse JSON document";
return;
}
if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
qDebug() << "JSON document is not an object or an array";
return;
}
QJsonObject json_obj = jsonDoc.object();
card_type = json_obj["card_type"].toInt();
QJsonArray chan_array = json_obj["chan"].toArray();
for (int i = 0; i < chan_array.size(); i++) {
QJsonObject temp_obj = chan_array[i].toObject();
seismic_monitor[i].id = temp_obj["id"].toInt();
// seismic_monitor[i].channel_name = temp_obj["channle_name"].toString();
seismic_monitor[i].standby = temp_obj["standby"].toBool();
seismic_monitor[i].active = temp_obj["active"].toBool();
seismic_monitor[i].rack_type = temp_obj["rack_type"].toInt();
seismic_monitor[i].tmr_group = temp_obj["tmr_group"].toString();
seismic_monitor[i].channel_type = temp_obj["channel_type"].toInt();
seismic_monitor[i].transducer_name = temp_obj["transducer_name"].toString();
seismic_monitor[i].scale_factor = temp_obj["scale_factor"].toDouble();
seismic_monitor[i].sampling_rate = temp_obj["sampling_rate"].toInt();
QJsonArray voltage_range_array = temp_obj["normal_voltage_range"].toArray();
seismic_monitor[i].normal_voltage_low = voltage_range_array[0].toDouble();
seismic_monitor[i].normal_voltage_high = voltage_range_array[1].toDouble();
}
QFile file_transducer(QCoreApplication::applicationDirPath() + QString("\\config\\transducer.json"));
if (!file_transducer.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for reading:" << filePath;
return;
}
QString content_transducer = file_transducer.readAll();
file_transducer.close();
QByteArray jsonData2 = content_transducer.toUtf8();
QJsonDocument jsonDoc2 = QJsonDocument::fromJson(jsonData2);
if (jsonDoc2.isNull()) {
qDebug() << "Cannot parse JSON document";
return;
}
if (!jsonDoc2.isObject() && !jsonDoc2.isArray()) {
qDebug() << "JSON document is not an object or an array";
return;
}
QJsonArray json_array = jsonDoc2.array();
for (int var = 0; var < json_array.size(); ++var) {
Transducer transducer;
QJsonObject temp_obj = json_array[var].toObject();
transducer.transducer_name = temp_obj["transducer_name"].toString();
transducer.scale_factor = temp_obj["scale_factor"].toDouble();
vec_transducer.push_back(transducer);
}
}
//void Seismic_monitor::readJsonFile(const QString &filePath) {
// // 创建文件对象
// QFile file(filePath);
// if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// qDebug() << "Cannot open file for reading:" << filePath;
// return;
// }
// QString content = file.readAll();
// file.close();
// QByteArray jsonData = content.toUtf8();
// QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
// if (jsonDoc.isNull()) {
// qDebug() << "Cannot parse JSON document";
// return;
// }
// if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
// qDebug() << "JSON document is not an object or an array";
// return;
// }
// QJsonObject json_obj = jsonDoc.object();
// card_type = json_obj["card_type"].toInt();
// QJsonArray chan_array = json_obj["chan"].toArray();
// for (int i = 0; i < chan_array.size(); i++) {
// QJsonObject temp_obj = chan_array[i].toObject();
// seismic_monitor[i].id = temp_obj["id"].toInt();
//// seismic_monitor[i].channel_name = temp_obj["channle_name"].toString();
// seismic_monitor[i].standby = temp_obj["standby"].toBool();
// seismic_monitor[i].active = temp_obj["active"].toBool();
// seismic_monitor[i].rack_type = temp_obj["rack_type"].toInt();
// seismic_monitor[i].tmr_group = temp_obj["tmr_group"].toString();
// seismic_monitor[i].channel_type = temp_obj["channel_type"].toInt();
// seismic_monitor[i].transducer_name = temp_obj["transducer_name"].toString();
// seismic_monitor[i].scale_factor = temp_obj["scale_factor"].toDouble();
// seismic_monitor[i].sampling_rate = temp_obj["sampling_rate"].toInt();
// QJsonArray voltage_range_array = temp_obj["normal_voltage_range"].toArray();
// seismic_monitor[i].normal_voltage_low = voltage_range_array[0].toDouble();
// seismic_monitor[i].normal_voltage_high = voltage_range_array[1].toDouble();
// }
// QFile file_transducer(QCoreApplication::applicationDirPath() + QString("\\config\\transducer.json"));
// if (!file_transducer.open(QIODevice::ReadOnly | QIODevice::Text)) {
// qDebug() << "Cannot open file for reading:" << filePath;
// return;
// }
// QString content_transducer = file_transducer.readAll();
// file_transducer.close();
// QByteArray jsonData2 = content_transducer.toUtf8();
// QJsonDocument jsonDoc2 = QJsonDocument::fromJson(jsonData2);
// if (jsonDoc2.isNull()) {
// qDebug() << "Cannot parse JSON document";
// return;
// }
// if (!jsonDoc2.isObject() && !jsonDoc2.isArray()) {
// qDebug() << "JSON document is not an object or an array";
// return;
// }
// QJsonArray json_array = jsonDoc2.array();
// for (int var = 0; var < json_array.size(); ++var) {
// Transducer transducer;
// QJsonObject temp_obj = json_array[var].toObject();
// transducer.transducer_name = temp_obj["transducer_name"].toString();
// transducer.scale_factor = temp_obj["scale_factor"].toDouble();
// vec_transducer.push_back(transducer);
// }
//}
void Seismic_monitor::Init() {
for (int var = 0; var < vec_transducer.size(); ++var) {
ui->comboBox_transducer_name_1->addItem(vec_transducer[var].transducer_name);
ui->comboBox_transducer_name_2->addItem(vec_transducer[var].transducer_name);
ui->comboBox_transducer_name_3->addItem(vec_transducer[var].transducer_name);
ui->comboBox_transducer_name_4->addItem(vec_transducer[var].transducer_name);
// for (int var = 0; var < vec_transducer.size(); ++var) {
// ui->comboBox_transducer_name_1->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_2->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_3->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_4->addItem(vec_transducer[var].transducer_name);
// }
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
// do nothing or use template to init it.
std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
ConfigMgr::Instance()->AddCard(vib_data);
UpdateData(vib_data);
return;
}
for (int i = 0; i < CHANNLE_COUNT; i++) {
if (seismic_monitor[i].id == 1) {
qDebug() << seismic_monitor[i].channel_type ;
// if (seismic_monitor[i].channel_type == "acceleration") {
// ui->comboBox_chan_type_1->setCurrentText("加速度");
// } else if (seismic_monitor[i].channel_type == "velocity") {
// ui->comboBox_chan_type_1->setCurrentText("速度");
// } else if (seismic_monitor[i].channel_type == "proximeter") {
// ui->comboBox_chan_type_1->setCurrentText("位移");
// }
ui->comboBox_chan_type_1->setCurrentIndex(seismic_monitor[i].channel_type);
//ui->comboBox_transducer_name_1->setText(seismic_monitor[i].transducer_name);
ui->doubleSpinBox_scale_factor_1->setValue(seismic_monitor[i].scale_factor);
ui->checkBox_enable_1->setCheckable(seismic_monitor[i].active);
ui->doubleSpinBox_low_1->setValue(seismic_monitor[i].normal_voltage_low);
ui->doubleSpinBox_high_1->setValue(seismic_monitor[i].normal_voltage_high);
// if (seismic_monitor[i].sample_rate == "32000") {
// ui->comboBox_sample_rate_1->setCurrentText("32 k");
// }
ui->comboBox_sample_rate_1->setCurrentIndex(seismic_monitor[i].sampling_rate);
}
if (seismic_monitor[i].id == 2) {
// if (seismic_monitor[i].channel_type == "acceleration") {
// ui->comboBox_chan_type_2->setCurrentText("加速度");
// } else if (seismic_monitor[i].channel_type == "velocity") {
// ui->comboBox_chan_type_2->setCurrentText("速度");
// } else if (seismic_monitor[i].channel_type == "proximeter") {
// ui->comboBox_chan_type_2->setCurrentText("位移");
// }
ui->comboBox_chan_type_2->setCurrentIndex(seismic_monitor[i].channel_type);
//ui->comboBox_transducer_name_2->setText(seismic_monitor[i].transducer_name);
ui->doubleSpinBox_scale_factor_2->setValue(seismic_monitor[i].scale_factor);
ui->checkBox_enable_2->setCheckable(seismic_monitor[i].active);
ui->doubleSpinBox_low_2->setValue(seismic_monitor[i].normal_voltage_low);
ui->doubleSpinBox_high_2->setValue(seismic_monitor[i].normal_voltage_high);
// if (seismic_monitor[i].sample_rate == "32000") {
// ui->comboBox_sample_rate_2->setCurrentText("32 k");
// }
ui->comboBox_sample_rate_2->setCurrentIndex(seismic_monitor[i].sampling_rate);
}
if (seismic_monitor[i].id == 3) {
// if (seismic_monitor[i].channel_type == "acceleration") {
// ui->comboBox_chan_type_3->setCurrentText("加速度");
// } else if (seismic_monitor[i].channel_type == "velocity") {
// ui->comboBox_chan_type_3->setCurrentText("速度");
// } else if (seismic_monitor[i].channel_type == "proximeter") {
// ui->comboBox_chan_type_3->setCurrentText("位移");
// }
ui->comboBox_chan_type_3->setCurrentIndex(seismic_monitor[i].channel_type);
//ui->lineEdit_transducer_name_3->setText(seismic_monitor[i].transducer_name);
ui->doubleSpinBox_scale_factor_3->setValue(seismic_monitor[i].scale_factor);
ui->checkBox_enable_3->setCheckable(seismic_monitor[i].active);
ui->doubleSpinBox_low_3->setValue(seismic_monitor[i].normal_voltage_low);
ui->doubleSpinBox_high_3->setValue(seismic_monitor[i].normal_voltage_high);
// if (seismic_monitor[i].sample_rate == "32000") {
// ui->comboBox_sample_rate_3->setCurrentText("32 k");
// }
ui->comboBox_sample_rate_3->setCurrentIndex(seismic_monitor[i].sampling_rate);
}
if (seismic_monitor[i].id == 4) {
// if (seismic_monitor[i].channel_type == "acceleration") {
// ui->comboBox_chan_type_4->setCurrentText("加速度");
// } else if (seismic_monitor[i].channel_type == "velocity") {
// ui->comboBox_chan_type_4->setCurrentText("速度");
// } else if (seismic_monitor[i].channel_type == "proximeter") {
// ui->comboBox_chan_type_4->setCurrentText("位移");
// }
ui->comboBox_chan_type_4->setCurrentIndex(seismic_monitor[i].channel_type);
//ui->lineEdit_transducer_name_4->setText(seismic_monitor[i].transducer_name);
ui->doubleSpinBox_scale_factor_4->setValue(seismic_monitor[i].scale_factor);
ui->checkBox_enable_4->setCheckable(seismic_monitor[i].active);
ui->doubleSpinBox_low_4->setValue(seismic_monitor[i].normal_voltage_low);
ui->doubleSpinBox_high_4->setValue(seismic_monitor[i].normal_voltage_high);
// if (seismic_monitor[i].sample_rate == "32000") {
// ui->comboBox_sample_rate_4->setCurrentText("32 k");
// }
ui->comboBox_sample_rate_4->setCurrentIndex(seismic_monitor[i].sampling_rate);
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
for (int i = 0; i < CHANNEL_COUNT; i++) {
if (i + 1 == 1) {
qDebug() << vib_data->base_config_[i].channel_type ;
ui->comboBox_chan_type_1->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_1->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_1->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_1->setCheckable(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_1->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_1->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_1->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
} else if (i + 1 == 2) {
ui->comboBox_chan_type_2->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_2->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_2->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_2->setCheckable(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_2->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_2->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_2->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
} else if (i + 1 == 3) {
ui->comboBox_chan_type_3->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_3->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_3->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_3->setCheckable(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_3->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_3->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_3->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
} else if (i + 1 == 4) {
ui->comboBox_chan_type_4->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_4->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_4->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_4->setCheckable(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_4->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_4->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_4->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
}
}
}
void Seismic_monitor::UpdateData(std::shared_ptr<VibrationData> vib_data) {
for (int var = 0; var < CHANNEL_COUNT; ++var) {
if (var + 1 == 1) {
vib_data->base_config_[var].standby = ui->checkBox_standby_1->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_1->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_1->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_1->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_1->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_1->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_1->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_1->value();
} else if (var + 1 == 2) {
vib_data->base_config_[var].standby = ui->checkBox_standby_1->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_2->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_2->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_2->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_2->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_2->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_2->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_2->value();
} else if (var + 1 == 3) {
vib_data->base_config_[var].standby = ui->checkBox_standby_2->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_3->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_3->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_3->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_3->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_3->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_3->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_3->value();
} else if (var + 1 == 4) {
vib_data->base_config_[var].standby = ui->checkBox_standby_2->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_4->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_4->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_4->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_4->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_4->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_4->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_4->value();
}
}
}
void Seismic_monitor::on_pushButton_confirm_clicked() {
for (int var = 0; var < CHANNLE_COUNT; ++var) {
if (seismic_monitor[var].id == 1) {
seismic_monitor[var].transducer_name = ui->comboBox_transducer_name_1->currentText();
seismic_monitor[var].scale_factor = ui->doubleSpinBox_scale_factor_1->value();
seismic_monitor[var].active = ui->checkBox_enable_1->isChecked();
// if (ui->comboBox_sample_rate_1->currentText() == "32 k") {
// seismic_monitor[var].sample_rate = "32000";
// }
seismic_monitor[var].sampling_rate = ui->comboBox_sample_rate_1->currentIndex();
seismic_monitor[var].normal_voltage_low = ui->doubleSpinBox_low_1->value();
seismic_monitor[var].normal_voltage_high = ui->doubleSpinBox_high_1->value();
} else if (seismic_monitor[var].id == 2) {
seismic_monitor[var].transducer_name = ui->comboBox_transducer_name_2->currentText();
seismic_monitor[var].scale_factor = ui->doubleSpinBox_scale_factor_2->value();
seismic_monitor[var].active = ui->checkBox_enable_2->isChecked();
// if (ui->comboBox_sample_rate_2->currentText() == "32 k") {
// seismic_monitor[var].sample_rate = "32000";
// }
seismic_monitor[var].sampling_rate = ui->comboBox_sample_rate_2->currentIndex();
seismic_monitor[var].normal_voltage_low = ui->doubleSpinBox_low_2->value();
seismic_monitor[var].normal_voltage_high = ui->doubleSpinBox_high_2->value();
} else if (seismic_monitor[var].id == 3) {
seismic_monitor[var].transducer_name = ui->comboBox_transducer_name_3->currentText();
seismic_monitor[var].scale_factor = ui->doubleSpinBox_scale_factor_3->value();
seismic_monitor[var].active = ui->checkBox_enable_3->isChecked();
// if (ui->comboBox_sample_rate_3->currentText() == "32 k") {
// seismic_monitor[var].sample_rate = "32000";
// }
seismic_monitor[var].sampling_rate = ui->comboBox_sample_rate_3->currentIndex();
seismic_monitor[var].normal_voltage_low = ui->doubleSpinBox_low_3->value();
seismic_monitor[var].normal_voltage_high = ui->doubleSpinBox_high_3->value();
} else if (seismic_monitor[var].id == 4) {
seismic_monitor[var].transducer_name = ui->comboBox_transducer_name_4->currentText();
seismic_monitor[var].scale_factor = ui->doubleSpinBox_scale_factor_4->value();
seismic_monitor[var].active = ui->checkBox_enable_4->isChecked();
// if (ui->comboBox_sample_rate_4->currentText() == "32 k") {
// seismic_monitor[var].sample_rate = "32000";
// }
seismic_monitor[var].sampling_rate = ui->comboBox_sample_rate_4->currentIndex();
seismic_monitor[var].normal_voltage_low = ui->doubleSpinBox_low_4->value();
seismic_monitor[var].normal_voltage_high = ui->doubleSpinBox_high_4->value();
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
qCritical() << " should not be here";
// std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
// ConfigMgr::Instance()->AddCard(vib_data);
// UpdateData(vib_data);
return;
}
}
QJsonObject monitor_obj, item_obj;
QJsonArray chan_array;
for (int i = 0; i < CHANNLE_COUNT; i++) {
item_obj["id"] = seismic_monitor[i].id;
item_obj["channel_name"] = seismic_monitor[i].channel_name;
item_obj["standby"] = seismic_monitor[i].standby;
item_obj["active"] = seismic_monitor[i].active;
item_obj["rack_type"] = seismic_monitor[i].rack_type;
item_obj["tmr_group"] = seismic_monitor[i].tmr_group;
item_obj["channel_type"] = seismic_monitor[i].channel_type;
item_obj["transducer_name"] = seismic_monitor[i].transducer_name;
item_obj["scale_factor"] = seismic_monitor[i].scale_factor;
item_obj["sampling_rate"] = seismic_monitor[i].sampling_rate;
QJsonArray normal_voltage_array;
normal_voltage_array.append(seismic_monitor[i].normal_voltage_low);
normal_voltage_array.append(seismic_monitor[i].normal_voltage_high);
item_obj["normal_voltage_range"] = normal_voltage_array;
chan_array.append(item_obj);
}
monitor_obj["chan"] = chan_array;
monitor_obj["slot"] = slot_no;
monitor_obj["version"] = 1;
monitor_obj["card_type"] = kCardVibSingle;
QJsonDocument jsonDoc;
jsonDoc.setObject(monitor_obj);
QString file_name = QString("\\config\\%1\\seismic_monitor_slot.json").arg(slot_no);
QFile file(QCoreApplication::applicationDirPath() + file_name);
file.open(QIODevice::WriteOnly);
file.write(jsonDoc.toJson());
file.close();
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
UpdateData(vib_data);
this->close();
}
@ -428,4 +383,3 @@ void Seismic_monitor::on_comboBox_transducer_name_4_currentTextChanged(const QSt
}
}
}

View File

@ -3,21 +3,21 @@
#include <QWidget>
#include "data_config.h"
#include "vibrationdata.h"
namespace Ui {
class Seismic_monitor;
}
class Seismic_monitor : public QWidget
{
class Seismic_monitor : public QWidget {
Q_OBJECT
public:
explicit Seismic_monitor(int slot,QWidget *parent = nullptr);
public:
explicit Seismic_monitor(int slot, QWidget *parent = nullptr);
~Seismic_monitor();
int slot_no;
int channel;
private slots:
private slots:
void on_pushButton_confirm_clicked();
void on_pushButton_set_default_clicked();
@ -48,12 +48,12 @@ private slots:
void on_comboBox_transducer_name_4_currentTextChanged(const QString &arg1);
private:
private:
Ui::Seismic_monitor *ui;
void UpdateData(std::shared_ptr<VibrationData> vib_data);
int card_type;
void readJsonFile(const QString &filePath);
SeismicMonitor seismic_monitor[CHANNLE_COUNT];
// void readJsonFile(const QString &filePath);
// SeismicMonitor seismic_monitor[CHANNLE_COUNT];
QVector<Transducer> vec_transducer;
void Init();
};

View File

@ -463,7 +463,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
@ -630,7 +630,7 @@
<item>
<widget class="QLabel" name="label_unit_1">
<property name="text">
<string>mv/ m/s^2</string>
<string>v/mm</string>
</property>
</widget>
</item>
@ -852,7 +852,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
@ -1016,7 +1016,7 @@
<item>
<widget class="QLabel" name="label_unit_2">
<property name="text">
<string>mv/ m/s^2</string>
<string>v/mm</string>
</property>
</widget>
</item>
@ -1283,7 +1283,7 @@
</size>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
@ -1414,7 +1414,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
@ -1578,7 +1578,7 @@
<item>
<widget class="QLabel" name="label_unit_3">
<property name="text">
<string>mv/ m/s^2</string>
<string>v/mm</string>
</property>
</widget>
</item>
@ -1788,7 +1788,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
@ -1952,7 +1952,7 @@
<item>
<widget class="QLabel" name="label_unit_4">
<property name="text">
<string>mv/ m/s^2</string>
<string>v/mm</string>
</property>
</widget>
</item>

View File

@ -28,12 +28,12 @@ class Velocity : public QWidget {
private:
Ui::Velocity *ui;
Filter filter[3];
Dealy delay;
Variables variables[4];
Alert_Variables alert_variables;
// Filter filter[3];
// Dealy delay;
// Variables variables[4];
// Alert_Variables alert_variables;
void readJsonFile(const QString &filePath);
// void readJsonFile(const QString &filePath);
void Init();
};

View File

@ -1,6 +1,13 @@
#include "vibrationdata.h"
VibrationData::VibrationData()
{
VibrationData::VibrationData() {
}
std::shared_ptr<VariableBase> VibrationData::GetChannelPtr(int cid) {
for (auto &item : variables_) {
if (item->id_ == cid) {
return item;
}
}
return nullptr;
}

View File

@ -8,19 +8,20 @@
class VibrationData : public CardBase {
public:
VibrationData();
void FromJson(const Json::Value &cfg) {
version_ = cfg["version"].asInt();
slot_ = cfg["slot"].asInt();
card_type_ = static_cast<CardType>(cfg["type"].asInt());
}
// void FromJson(const Json::Value &cfg) {
// version_ = cfg["version"].asInt();
// slot_ = cfg["slot"].asInt();
// card_type_ = static_cast<CardType>(cfg["type"].asInt());
// }
Json::Value ToJson() {
Json::Value ch;
ch[NAME(version)] = version_;
ch[NAME(slot)] = slot_;
ch[NAME(type)] = card_type_;
return ch;
}
// Json::Value ToJson() {
// Json::Value ch;
// ch[NAME(version)] = version_;
// ch[NAME(slot)] = slot_;
// ch[NAME(type)] = card_type_;
// return ch;
// }
std::shared_ptr<VariableBase> GetChannelPtr(int cid);
// private:
SeismicMonitor base_config_[CHANNEL_COUNT];
AllFilter filter_[CHANNEL_COUNT];