振动板卡添加继电器配置

This commit is contained in:
zhangsheng 2026-04-09 16:06:40 +08:00
parent 033bb1c02d
commit 13510306d8
5 changed files with 149 additions and 48 deletions

View File

@ -558,13 +558,49 @@ int ConfigMgr::Save(QString & file_path) {
channel_item.insert("fail",ptr->variables_[cid].fail); channel_item.insert("fail",ptr->variables_[cid].fail);
} }
slot_item[QString::number(cid + 1)] = channel_item; slot_item[QString::number(cid + 1)] = channel_item;
slot_item["dc_output"] = dc_output; slot_item["dc_output"] = dc_output;
} }
slot_item["version"] = 1; if (card_type_[i] == kCardVibSingle ||
slot_item["relative_number"] = base_ptr->relative_number; card_type_[i] == kCardVibTMRPrimary) {
slot_item["group"] = base_ptr->group; std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
}else{ if (ptr != nullptr) {
QJsonObject relay_item;
for (int ch = 0; ch < RELAY_COUNT; ++ch) {
QJsonObject channel_item;
if (ptr->single_relay[ch].vote) {
channel_item.insert("count_vote",ptr->single_relay[ch].count_vote);
QJsonArray array_logic;
for (int var = 0 ; var < 10; ++var) {
if (ptr->single_relay[ch].logic[var] != "") {
array_logic.append(ptr->single_relay[ch].logic[var]);
channel_item.insert("active", ptr->single_relay[ch].active);
channel_item.insert("group",ptr->single_relay[ch].group);
channel_item.insert("logic_vote", array_logic);
channel_item.insert("vote",ptr->single_relay[ch].vote);
}
}
} else {
if (ptr->single_relay[ch].logic_expression != "") {
channel_item.insert("logic_expression", ptr->single_relay[ch].logic_expression);
channel_item.insert("vote",ptr->single_relay[ch].vote);
channel_item.insert("active", ptr->single_relay[ch].active);
channel_item.insert("group",ptr->single_relay[ch].group);
}
}
if (!channel_item.isEmpty()) {
relay_item[QString::number(ch + 1)] = channel_item;
}
}
if (!relay_item.isEmpty()) {
slot_item["relay"] = relay_item;
}
}
}
slot_item["version"] = 1;
slot_item["relative_number"] = base_ptr->relative_number;
slot_item["group"] = base_ptr->group;
}else{
for(int ch = 0;ch < RELAY_COUNT;++ch){ for(int ch = 0;ch < RELAY_COUNT;++ch){
QJsonObject channel_item; QJsonObject channel_item;
if(card_type_[i] == kCardRelaySingle){ if(card_type_[i] == kCardRelaySingle){
@ -1051,6 +1087,26 @@ void ConfigMgr::Load(QString filename) {
} }
} }
} }
QJsonObject relay_obj = temp_obj["relay"].toObject();
if (!relay_obj.isEmpty()) {
for (int j = 0; j < RELAY_COUNT; ++j) {
channel = relay_obj[QString::number(j + 1)].toObject();
if(channel.isEmpty())
continue;
if(channel["vote"].toBool()){
vib_data->single_relay[j].count_vote = channel["count_vote"].toInt();
vib_data->single_relay[j].vote = channel["vote"].toBool();
QJsonArray array_logic = channel["logic_vote"].toArray();
for(int var = 0;var < array_logic.size();++var){
vib_data->single_relay[j].logic[var] = array_logic[var].toString();
}
}else{
vib_data->single_relay[j].logic_expression = channel["logic_expression"].toString();
}
vib_data->single_relay[j].active = channel["active"].toBool();
vib_data->single_relay[j].group = channel["group"].toInt();
}
}
cards_.push_back(vib_data); cards_.push_back(vib_data);
} else if (card_type_[i] == kCardSpeedSingle || } else if (card_type_[i] == kCardSpeedSingle ||
card_type_[i] == kCardSpeedTMRPrimary) { card_type_[i] == kCardSpeedTMRPrimary) {

View File

@ -1123,7 +1123,7 @@ void MainWindow::MoveSubCard(int slot){
void MainWindow::VibRealy(int slot){ void MainWindow::VibRealy(int slot){
slot_no = slot; slot_no = slot;
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if(base_ptr != nullptr){ if(base_ptr == nullptr){
QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("当前板卡为空板卡!")); QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("当前板卡为空板卡!"));
return ; return ;
} }
@ -1131,6 +1131,9 @@ void MainWindow::VibRealy(int slot){
QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("请选择振动板卡进行配置!")); QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("请选择振动板卡进行配置!"));
return ; return ;
} }
SingleRelay *single_relay = new SingleRelay(slot_no, base_ptr->card_type_);
single_relay->setWindowModality(Qt::ApplicationModal);
single_relay->show();
} }
void MainWindow::readData(const QByteArray &data) { void MainWindow::readData(const QByteArray &data) {
qDebug() << "Received from server:" << data; qDebug() << "Received from server:" << data;

View File

@ -14,6 +14,11 @@ SingleRelay::SingleRelay(int slot,CardType cardtype,QWidget *parent)
car_type = cardtype; car_type = cardtype;
ui->label_slot_no->setText(QString::number(slot_no)); ui->label_slot_no->setText(QString::number(slot_no));
ui->comboBox_relay_ch->setView(new QListView()); ui->comboBox_relay_ch->setView(new QListView());
if (car_type == kCardVibSingle) {
for (int i = ui->comboBox_relay_ch->count() - 1; i >= 4; --i) {
ui->comboBox_relay_ch->removeItem(i);
}
}
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available); QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available);
list_widget_available = new QListWidget(); list_widget_available = new QListWidget();
@ -95,17 +100,33 @@ void SingleRelay::Init(){
} }
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) { if (base_ptr == nullptr) {
// do nothing or use template to init it. if (car_type == kCardVibSingle) {
relay_data = std::make_shared<SingleRelayData>(); vib_data = std::make_shared<VibrationData>();
relay_data->card_type_ = car_type; vib_data->card_type_ = car_type;
relay_data->slot_ = slot_no; vib_data->slot_ = slot_no;
ConfigMgr::Instance()->AddCard(relay_data); ConfigMgr::Instance()->AddCard(vib_data);
} else {
// do nothing or use template to init it.
relay_data = std::make_shared<SingleRelayData>();
relay_data->card_type_ = car_type;
relay_data->slot_ = slot_no;
ConfigMgr::Instance()->AddCard(relay_data);
}
return; return;
} }
relay_data = std::dynamic_pointer_cast<SingleRelayData>(base_ptr); if (base_ptr->card_type_ == kCardVibSingle) {
vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
} else {
relay_data = std::dynamic_pointer_cast<SingleRelayData>(base_ptr);
}
qDebug() << "logic" <<relay_data->single_relay[current_index].logic_expression; SingleRelayS *relay = relayArray();
qDebug() << "active" <<relay_data->single_relay[current_index].active << "index" << current_index; if (!relay) {
return;
}
qDebug() << "logic" << relay[current_index].logic_expression;
qDebug() << "active" << relay[current_index].active << "index" << current_index;
for(int i = 0 ; i < SLOT_NUM ; i++){ for(int i = 0 ; i < SLOT_NUM ; i++){
std::shared_ptr<CardBase> cardbase_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1); std::shared_ptr<CardBase> cardbase_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1);
@ -148,20 +169,27 @@ void SingleRelay::Init(){
cardbase_ptr->card_type_ == kCardSpeedSingle){ cardbase_ptr->card_type_ == kCardSpeedSingle){
} }
} }
if(!relay_data->single_relay[current_index].logic_expression.isEmpty()){ if(!relay[current_index].logic_expression.isEmpty()){
setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic_expression); setExpressionToTreeView(treeView_relay, relay[current_index].logic_expression);
} }
if(!relay_data->single_relay[current_index].logic[vote_current_index].isEmpty()){ if(!relay[current_index].logic[vote_current_index].isEmpty()){
setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic[vote_current_index]); setExpressionToTreeView(treeView_relay, relay[current_index].logic[vote_current_index]);
} }
qDebug() << "relay_data->single_relay[current_index].active" << relay_data->single_relay[current_index].active; qDebug() << "relay_data->single_relay[current_index].active" << relay[current_index].active;
ui->checkBox_active->setChecked(relay_data->single_relay[current_index].active); ui->checkBox_active->setChecked(relay[current_index].active);
ui->comboBox_group->setCurrentIndex(relay_data->single_relay[current_index].group - 1); ui->comboBox_group->setCurrentIndex(relay[current_index].group - 1);
ui->lineEdit_vote_count->setText(QString::number(relay_data->single_relay[current_index].count_vote)); ui->lineEdit_vote_count->setText(QString::number(relay[current_index].count_vote));
ui->checkBox_vote->setChecked(relay_data->single_relay[current_index].vote); ui->checkBox_vote->setChecked(relay[current_index].vote);
on_checkBox_vote_clicked(relay_data->single_relay[current_index].vote); on_checkBox_vote_clicked(relay[current_index].vote);
} }
SingleRelayS* SingleRelay::relayArray() {
if (vib_data) {
return vib_data->single_relay;
}
return relay_data ? relay_data->single_relay : nullptr;
}
void SingleRelay::on_pushButton_cancel_clicked() { void SingleRelay::on_pushButton_cancel_clicked() {
this->close(); this->close();
} }
@ -268,6 +296,9 @@ QString SingleRelay::buildLogicExpression(QStandardItem *item) {
} }
void SingleRelay::on_pushButton_confirm_clicked() void SingleRelay::on_pushButton_confirm_clicked()
{ {
SingleRelayS *relay = relayArray();
if (!relay) return;
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model()); QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model());
if (!model) return; if (!model) return;
@ -285,15 +316,15 @@ void SingleRelay::on_pushButton_confirm_clicked()
return; return;
} }
if(ui->checkBox_vote->isChecked()){ if(ui->checkBox_vote->isChecked()){
relay_data->single_relay[current_index].logic[ui->comboBox_vote_group->currentIndex()] = finalExpr; relay[current_index].logic[ui->comboBox_vote_group->currentIndex()] = finalExpr;
relay_data->single_relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt();
}else{ }else{
relay_data->single_relay[current_index].logic_expression = finalExpr; relay[current_index].logic_expression = finalExpr;
} }
relay_data->single_relay[current_index].active = ui->checkBox_active->isChecked(); relay[current_index].active = ui->checkBox_active->isChecked();
relay_data->single_relay[current_index].vote = ui->checkBox_vote->isChecked(); relay[current_index].vote = ui->checkBox_vote->isChecked();
relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1; relay[current_index].group = ui->comboBox_group->currentIndex() + 1;
relay_data->single_relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt();
qDebug() << "逻辑表达式:" << finalExpr ; qDebug() << "逻辑表达式:" << finalExpr ;
this->close(); this->close();
} }
@ -301,6 +332,9 @@ void SingleRelay::onComboBoxIndexChanged(int index){
qDebug()<< "[SingleRelay]:index " << index; qDebug()<< "[SingleRelay]:index " << index;
SingleRelayS *relay = relayArray();
if (!relay) return;
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model()); QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model());
if (!model) return; if (!model) return;
QStandardItem *root = model->invisibleRootItem(); QStandardItem *root = model->invisibleRootItem();
@ -318,25 +352,25 @@ void SingleRelay::onComboBoxIndexChanged(int index){
} }
qDebug() << "finalExpr" << finalExpr; qDebug() << "finalExpr" << finalExpr;
if(ui->checkBox_vote->isChecked()){ if(ui->checkBox_vote->isChecked()){
relay_data->single_relay[current_index].logic[vote_current_index] = finalExpr; relay[current_index].logic[vote_current_index] = finalExpr;
if(relay_data->single_relay[index].logic[0] != "") if(relay[index].logic[0] != "")
setExpressionToTreeView(treeView_relay, relay_data->single_relay[index].logic[ui->comboBox_vote_group->currentIndex()]); setExpressionToTreeView(treeView_relay, relay[index].logic[ui->comboBox_vote_group->currentIndex()]);
else else
model_Relay->clear(); model_Relay->clear();
}else{ }else{
relay_data->single_relay[current_index].logic_expression = finalExpr; relay[current_index].logic_expression = finalExpr;
if(relay_data->single_relay[index].logic_expression != "") if(relay[index].logic_expression != "")
setExpressionToTreeView(treeView_relay, relay_data->single_relay[index].logic_expression); setExpressionToTreeView(treeView_relay, relay[index].logic_expression);
else else
model_Relay->clear(); model_Relay->clear();
} }
relay_data->single_relay[current_index].vote = ui->checkBox_vote->isChecked(); relay[current_index].vote = ui->checkBox_vote->isChecked();
relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1; relay[current_index].group = ui->comboBox_group->currentIndex() + 1;
relay_data->single_relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt();
current_index = index; current_index = index;
qDebug() << "active" << relay_data->single_relay[index].active; qDebug() << "active" << relay[index].active;
ui->checkBox_active->setChecked(relay_data->single_relay[index].active); ui->checkBox_active->setChecked(relay[index].active);
ui->lineEdit_vote_count->setText(QString::number(relay_data->single_relay[index].count_vote)); ui->lineEdit_vote_count->setText(QString::number(relay[index].count_vote));
} }
ExprNode* SingleRelay::parseExpression(const QString& expr, int& pos) { ExprNode* SingleRelay::parseExpression(const QString& expr, int& pos) {
@ -522,6 +556,9 @@ void SingleRelay::on_checkBox_vote_clicked(bool checked)
void SingleRelay::on_comboBox_vote_group_currentIndexChanged(int index) void SingleRelay::on_comboBox_vote_group_currentIndexChanged(int index)
{ {
SingleRelayS *relay = relayArray();
if (!relay) return;
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model()); QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model());
if (!model) return; if (!model) return;
QStandardItem *root = model->invisibleRootItem(); QStandardItem *root = model->invisibleRootItem();
@ -538,9 +575,9 @@ void SingleRelay::on_comboBox_vote_group_currentIndexChanged(int index)
return; return;
} }
qDebug() << "finalExpr" << finalExpr << index; qDebug() << "finalExpr" << finalExpr << index;
relay_data->single_relay[current_index].logic[vote_current_index] = finalExpr; relay[current_index].logic[vote_current_index] = finalExpr;
if(relay_data->single_relay[current_index].logic[index] != "") if(relay[current_index].logic[index] != "")
setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic[index]); setExpressionToTreeView(treeView_relay, relay[current_index].logic[index]);
else else
model_Relay->clear(); model_Relay->clear();
vote_current_index = index; vote_current_index = index;

View File

@ -14,6 +14,7 @@
namespace Ui { namespace Ui {
class SingleRelay; class SingleRelay;
} }
class VibrationData;
class SingleRelay : public QDialog { class SingleRelay : public QDialog {
Q_OBJECT Q_OBJECT
@ -45,12 +46,14 @@ private:
QTreeView *treeView_relay; QTreeView *treeView_relay;
QStandardItemModel *model_Relay; QStandardItemModel *model_Relay;
std::shared_ptr<SingleRelayData> relay_data = nullptr; std::shared_ptr<SingleRelayData> relay_data = nullptr;
std::shared_ptr<VibrationData> vib_data = nullptr;
int current_index; int current_index;
int vote_current_index; int vote_current_index;
QMap<QString, QString> channelNameMap; QMap<QString, QString> channelNameMap;
void Init(); void Init();
void buildTreeFromExpression(QTreeView *treeView, const QString &expr); void buildTreeFromExpression(QTreeView *treeView, const QString &expr);
SingleRelayS* relayArray();
ExprNode* parseExpression(const QString& expr, int& pos); ExprNode* parseExpression(const QString& expr, int& pos);
QStandardItem* buildItemTree(ExprNode* node); QStandardItem* buildItemTree(ExprNode* node);
void setExpressionToTreeView(QTreeView* treeView, const QString& expr); void setExpressionToTreeView(QTreeView* treeView, const QString& expr);

View File

@ -20,6 +20,8 @@ class VibrationData : public CardBase {
VibAlertDanger alert_danger[CHANNEL_COUNT]; VibAlertDanger alert_danger[CHANNEL_COUNT];
VibAlertDangerPress alert_danger_press[CHANNEL_COUNT]; VibAlertDangerPress alert_danger_press[CHANNEL_COUNT];
DCOutput dc_output[CHANNEL_COUNT]; DCOutput dc_output[CHANNEL_COUNT];
SingleRelayS single_relay[RELAY_COUNT];
}; };
#endif // VIBRATIONDATA_H #endif // VIBRATIONDATA_H