#include #include "experimentsettingform.h" #include "ui_experimentsettingform.h" #include "protocol.h" #include "dataparser.h" #include "serialport.h" #include "global.h" #include "filemanager.h" #include "logger.h" QString extractObjectName(const QString& fullObjectName) { return fullObjectName.mid(4); // 去掉前 4 个字符("ui->") } #define SET_OBJECT_NAME(WIDGET) \ WIDGET->setObjectName(extractObjectName(#WIDGET)) ExperimentSettingForm::ExperimentSettingForm(QWidget *parent) : QWidget(parent), ui(new Ui::ExperimentSettingForm) { ui->setupUi(this); uiReset(); connect(ui->checkBox_phase_2, &QCheckBox::clicked, this, &ExperimentSettingForm::slotPhase2StateChanged); connect(ui->checkBox_phase_3, &QCheckBox::clicked, this, &ExperimentSettingForm::slotPhase3StateChanged); connect(ui->checkBox_phase_4, &QCheckBox::clicked, this, &ExperimentSettingForm::slotPhase4StateChanged); connect(ui->checkBox_phase_5, &QCheckBox::clicked, this, &ExperimentSettingForm::slotPhase5StateChanged); connect(ui->checkBox_phase_6, &QCheckBox::clicked, this, &ExperimentSettingForm::slotPhase6StateChanged); // connect(ui->pushButton_connect_to_device,&QPushButton::clicked, // this,&ExperimentSettingForm::slotConnectToDevice); connect(ui->pushButton_cancel, &QPushButton::clicked, this, &ExperimentSettingForm::slotCancel); } ExperimentSettingForm::~ExperimentSettingForm() { delete ui; } void ExperimentSettingForm::uiReset() { // init data and status. // default value ui->phase_1_cutoff_temp->setText("0"); ui->phase_2_cutoff_temp->setText("0"); ui->phase_3_cutoff_temp->setText("0"); ui->phase_4_cutoff_temp->setText("0"); ui->phase_5_cutoff_temp->setText("0"); ui->phase_6_cutoff_temp->setText("0"); ui->phase_1_scan_rate->setText("0"); ui->phase_2_scan_rate->setText("0"); ui->phase_3_scan_rate->setText("0"); ui->phase_4_scan_rate->setText("0"); ui->phase_5_scan_rate->setText("0"); ui->phase_6_scan_rate->setText("0"); ui->phase_1_constant_temp->setText("0"); ui->phase_2_constant_temp->setText("0"); ui->phase_3_constant_temp->setText("0"); ui->phase_4_constant_temp->setText("0"); ui->phase_5_constant_temp->setText("0"); ui->phase_6_constant_temp->setText("0"); ui->comboBox_phase_1_atmosphere->setCurrentIndex(0); ui->comboBox_phase_2_atmosphere->setCurrentIndex(0); ui->comboBox_phase_3_atmosphere->setCurrentIndex(0); ui->comboBox_phase_4_atmosphere->setCurrentIndex(0); ui->comboBox_phase_5_atmosphere->setCurrentIndex(0); ui->comboBox_phase_6_atmosphere->setCurrentIndex(0); // default enable ui->checkBox_phase_1->setChecked(true); ui->checkBox_phase_1->setEnabled(false); ui->phase_2_cutoff_temp->setEnabled(false); ui->phase_3_cutoff_temp->setEnabled(false); ui->phase_4_cutoff_temp->setEnabled(false); ui->phase_5_cutoff_temp->setEnabled(false); ui->phase_6_cutoff_temp->setEnabled(false); ui->phase_2_scan_rate->setEnabled(false); ui->phase_3_scan_rate->setEnabled(false); ui->phase_4_scan_rate->setEnabled(false); ui->phase_5_scan_rate->setEnabled(false); ui->phase_6_scan_rate->setEnabled(false); ui->phase_2_constant_temp->setEnabled(false); ui->phase_3_constant_temp->setEnabled(false); ui->phase_4_constant_temp->setEnabled(false); ui->phase_5_constant_temp->setEnabled(false); ui->phase_6_constant_temp->setEnabled(false); ui->comboBox_phase_2_atmosphere->setEnabled(false); ui->comboBox_phase_3_atmosphere->setEnabled(false); ui->comboBox_phase_4_atmosphere->setEnabled(false); ui->comboBox_phase_5_atmosphere->setEnabled(false); ui->comboBox_phase_6_atmosphere->setEnabled(false); ui->radioButton_OIT_not->setChecked(true); ui->checkBox_phase_2->setTristate(false); ui->checkBox_phase_3->setTristate(false); ui->checkBox_phase_4->setTristate(false); ui->checkBox_phase_5->setTristate(false); ui->checkBox_phase_6->setTristate(false); //set objectName SET_OBJECT_NAME(ui->checkBox_phase_1); SET_OBJECT_NAME(ui->checkBox_phase_2); SET_OBJECT_NAME(ui->checkBox_phase_3); SET_OBJECT_NAME(ui->checkBox_phase_4); SET_OBJECT_NAME(ui->checkBox_phase_5); SET_OBJECT_NAME(ui->checkBox_phase_6); SET_OBJECT_NAME(ui->phase_1_cutoff_temp); SET_OBJECT_NAME(ui->phase_2_cutoff_temp); SET_OBJECT_NAME(ui->phase_3_cutoff_temp); SET_OBJECT_NAME(ui->phase_4_cutoff_temp); SET_OBJECT_NAME(ui->phase_5_cutoff_temp); SET_OBJECT_NAME(ui->phase_6_cutoff_temp); SET_OBJECT_NAME(ui->phase_1_scan_rate); SET_OBJECT_NAME(ui->phase_2_scan_rate); SET_OBJECT_NAME(ui->phase_3_scan_rate); SET_OBJECT_NAME(ui->phase_4_scan_rate); SET_OBJECT_NAME(ui->phase_5_scan_rate); SET_OBJECT_NAME(ui->phase_6_scan_rate); SET_OBJECT_NAME(ui->phase_1_constant_temp); SET_OBJECT_NAME(ui->phase_2_constant_temp); SET_OBJECT_NAME(ui->phase_3_constant_temp); SET_OBJECT_NAME(ui->phase_4_constant_temp); SET_OBJECT_NAME(ui->phase_5_constant_temp); SET_OBJECT_NAME(ui->phase_6_constant_temp); SET_OBJECT_NAME(ui->comboBox_phase_1_atmosphere); SET_OBJECT_NAME(ui->comboBox_phase_2_atmosphere); SET_OBJECT_NAME(ui->comboBox_phase_3_atmosphere); SET_OBJECT_NAME(ui->comboBox_phase_4_atmosphere); SET_OBJECT_NAME(ui->comboBox_phase_5_atmosphere); SET_OBJECT_NAME(ui->comboBox_phase_6_atmosphere); SET_OBJECT_NAME(ui->radioButton_OIT_not); SET_OBJECT_NAME(ui->comboBox_initial_atmosphere); } void ExperimentSettingForm::uiSetPhaseEnable(const int index) { switch (index) { case 1: ui->checkBox_phase_1->setTristate(true); ui->phase_1_cutoff_temp->setEnabled(true); ui->phase_1_scan_rate->setEnabled(true); ui->phase_1_constant_temp->setEnabled(true); ui->comboBox_phase_1_atmosphere->setEnabled(true); break; case 2: ui->checkBox_phase_2->setTristate(true); ui->phase_2_cutoff_temp->setEnabled(true); ui->phase_2_scan_rate->setEnabled(true); ui->phase_3_constant_temp->setEnabled(true); ui->comboBox_phase_1_atmosphere->setEnabled(true); break; case 3: ui->checkBox_phase_1->setTristate(true); ui->phase_1_cutoff_temp->setEnabled(true); ui->phase_1_scan_rate->setEnabled(true); ui->phase_1_constant_temp->setEnabled(true); ui->comboBox_phase_1_atmosphere->setEnabled(true); break; case 4: ui->checkBox_phase_1->setTristate(true); ui->phase_1_cutoff_temp->setEnabled(true); ui->phase_1_scan_rate->setEnabled(true); ui->phase_1_constant_temp->setEnabled(true); ui->comboBox_phase_1_atmosphere->setEnabled(true); break; case 5: ui->checkBox_phase_1->setTristate(true); ui->phase_1_cutoff_temp->setEnabled(true); ui->phase_1_scan_rate->setEnabled(true); ui->phase_1_constant_temp->setEnabled(true); ui->comboBox_phase_1_atmosphere->setEnabled(true); break; case 6: ui->checkBox_phase_1->setTristate(true); ui->phase_1_cutoff_temp->setEnabled(true); ui->phase_1_scan_rate->setEnabled(true); ui->phase_1_constant_temp->setEnabled(true); ui->comboBox_phase_1_atmosphere->setEnabled(true); break; default: break; } } void ExperimentSettingForm::slotPhase2StateChanged(int state) { qDebug() << "slotPhase2StateChanged:" << state; if (state == Qt::PartiallyChecked) { ui->phase_2_cutoff_temp->setEnabled(true); ui->phase_2_scan_rate->setEnabled(true); ui->phase_2_constant_temp->setEnabled(true); ui->comboBox_phase_2_atmosphere->setEnabled(true); } else { if (ui->checkBox_phase_3->isChecked()) { ui->checkBox_phase_2->setCheckState(Qt::Checked); } else { ui->phase_2_cutoff_temp->setEnabled(false); ui->phase_2_scan_rate->setEnabled(false); ui->phase_2_constant_temp->setEnabled(false); ui->comboBox_phase_2_atmosphere->setEnabled(false); } } } void ExperimentSettingForm::slotPhase3StateChanged(int state) { if (state == Qt::PartiallyChecked) { if (ui->checkBox_phase_2->isChecked()) { ui->phase_3_cutoff_temp->setEnabled(true); ui->phase_3_scan_rate->setEnabled(true); ui->phase_3_constant_temp->setEnabled(true); ui->comboBox_phase_3_atmosphere->setEnabled(true); } else { ui->checkBox_phase_3->setChecked(false); } } else { if (ui->checkBox_phase_4->isChecked()) { ui->checkBox_phase_3->setChecked(true); } else { ui->phase_3_cutoff_temp->setEnabled(false); ui->phase_3_scan_rate->setEnabled(false); ui->phase_3_constant_temp->setEnabled(false); ui->comboBox_phase_3_atmosphere->setEnabled(false); } } } void ExperimentSettingForm::slotPhase4StateChanged(int state) { if (state == Qt::PartiallyChecked) { if (ui->checkBox_phase_3->isChecked()) { ui->phase_4_cutoff_temp->setEnabled(true); ui->phase_4_scan_rate->setEnabled(true); ui->phase_4_constant_temp->setEnabled(true); ui->comboBox_phase_4_atmosphere->setEnabled(true); } else { ui->checkBox_phase_4->setChecked(false); } } else { ui->phase_4_cutoff_temp->setEnabled(false); ui->phase_4_scan_rate->setEnabled(false); ui->phase_4_constant_temp->setEnabled(false); ui->comboBox_phase_4_atmosphere->setEnabled(false); } } void ExperimentSettingForm::slotPhase5StateChanged(int state) { if (state == Qt::PartiallyChecked) { if (ui->checkBox_phase_4->isChecked()) { ui->phase_5_cutoff_temp->setEnabled(true); ui->phase_5_scan_rate->setEnabled(true); ui->phase_5_constant_temp->setEnabled(true); ui->comboBox_phase_5_atmosphere->setEnabled(true); } else { ui->checkBox_phase_5->setChecked(false); } } else { ui->phase_5_cutoff_temp->setEnabled(false); ui->phase_5_scan_rate->setEnabled(false); ui->phase_5_constant_temp->setEnabled(false); ui->comboBox_phase_5_atmosphere->setEnabled(false); } } void ExperimentSettingForm::slotPhase6StateChanged(int state) { if (state == Qt::PartiallyChecked) { if (ui->checkBox_phase_5->isChecked()) { ui->phase_6_cutoff_temp->setEnabled(true); ui->phase_6_scan_rate->setEnabled(true); ui->phase_6_constant_temp->setEnabled(true); ui->comboBox_phase_6_atmosphere->setEnabled(true); } else { ui->checkBox_phase_6->setChecked(false); } } else { ui->phase_6_cutoff_temp->setEnabled(false); ui->phase_6_scan_rate->setEnabled(false); ui->phase_6_constant_temp->setEnabled(false); ui->comboBox_phase_6_atmosphere->setEnabled(false); } } void ExperimentSettingForm::on_pushButton_deliverData_clicked() { QVector phaseVtr; { Phase phase; phase.onoff = ui->checkBox_phase_1->checkState()?1:0; phase.cutoff_temp = ui->phase_1_cutoff_temp->text().toFloat(); phase.temp_flow = ui->phase_1_scan_rate->text().toFloat(); phase.constant_temp_time_min = (uint16_t)ui->phase_1_constant_temp->text().toInt(); // phase.gas = ui->comboBox_phase_1_atmosphere->currentIndex(); phase.gas = GasType::N2; phaseVtr.push_back(phase); } { Phase phase; phase.onoff = ui->checkBox_phase_2->checkState()?1:0; phase.cutoff_temp = ui->phase_2_cutoff_temp->text().toFloat(); phase.temp_flow = ui->phase_2_scan_rate->text().toFloat(); phase.constant_temp_time_min = (uint16_t)ui->phase_2_constant_temp->text().toInt(); // phase.gas = ui->comboBox_phase_1_atmosphere->currentIndex(); phase.gas = GasType::N2; phaseVtr.push_back(phase); } { Phase phase; phase.onoff = ui->checkBox_phase_3->checkState()?1:0; phase.cutoff_temp = ui->phase_3_cutoff_temp->text().toFloat(); phase.temp_flow = ui->phase_3_scan_rate->text().toFloat(); phase.constant_temp_time_min = (uint16_t)ui->phase_3_constant_temp->text().toInt(); phase.gas = GasType::N2; phaseVtr.push_back(phase); } { Phase phase; phase.onoff = ui->checkBox_phase_4->checkState()?1:0; phase.cutoff_temp = ui->phase_4_cutoff_temp->text().toFloat(); phase.temp_flow = ui->phase_4_scan_rate->text().toFloat(); phase.constant_temp_time_min = (uint16_t)ui->phase_4_constant_temp->text().toInt(); // phase.gas = ui->comboBox_phase_1_atmosphere->currentIndex(); phase.gas = GasType::N2; phaseVtr.push_back(phase); } { Phase phase; phase.onoff = ui->checkBox_phase_5->checkState()?1:0; phase.cutoff_temp = ui->phase_5_cutoff_temp->text().toFloat(); phase.temp_flow = ui->phase_5_scan_rate->text().toFloat(); phase.constant_temp_time_min = (uint16_t)ui->phase_5_constant_temp->text().toInt(); // phase.gas = ui->comboBox_phase_1_atmosphere->currentIndex(); phase.gas = GasType::N2; phaseVtr.push_back(phase); } { Phase phase; phase.onoff = ui->checkBox_phase_6->checkState()?1:0; phase.cutoff_temp = ui->phase_6_cutoff_temp->text().toFloat(); phase.temp_flow = ui->phase_6_scan_rate->text().toFloat(); phase.constant_temp_time_min = (uint16_t)ui->phase_6_constant_temp->text().toInt(); // phase.gas = ui->comboBox_phase_1_atmosphere->currentIndex(); phase.gas = GasType::N2; phaseVtr.push_back(phase); } // Global::ExperimentInfo& ei = Global::_experimentInfo; ei.sampleName = ui->sampleNameLineEdit->text(); ei.sampleWeight = ui->sampleWeightLineEdit->text(); ei.date = ui->dateTimeLineEdit->text(); ei.experimentor = ui->userLineEdit->text(); #if 0 ei.phaseVtr = phaseVtr; if(ui->radioButton_OIT->isChecked()){ ei.testType = Global::TestType::OIT; } else if(ui->radioButton_OIT_not->isChecked()){ ei.testType = Global::TestType::NoneOIT; } ei.initialAtmosPhere = (GasType)(ui->comboBox_phase_1_atmosphere->currentIndex()); #endif // initial data. QByteArray initialBa; if(ui->radioButton_OIT->isChecked()){ initialBa.append((char)0); }else{ initialBa.append((char)1); } char index = ui->comboBox_initial_atmosphere->currentIndex(); initialBa.append(index); // QByteArray ba = DataParser::setExperimentInfo(phaseVtr,initialBa); qDebug() << "ba size:" << ba.size(); emit sigDeliverData(ba); hide(); } void ExperimentSettingForm::slotCancel() { hide(); } void ExperimentSettingForm::slotPhaseCheck() { if (sender() == ui->checkBox_phase_2) { if (ui->checkBox_phase_2->isChecked()) { ui->phase_2_cutoff_temp->setEnabled(true); ui->phase_2_scan_rate->setEnabled(true); ui->phase_2_constant_temp->setEnabled(true); ui->comboBox_phase_2_atmosphere->setEnabled(true); } else { ui->phase_2_cutoff_temp->setEnabled(false); ui->phase_2_scan_rate->setEnabled(false); ui->phase_2_constant_temp->setEnabled(false); ui->comboBox_phase_2_atmosphere->setEnabled(false); } } else if (sender() == ui->checkBox_phase_3) { if (ui->checkBox_phase_3->isChecked()) { ui->phase_3_cutoff_temp->setEnabled(true); ui->phase_3_scan_rate->setEnabled(true); ui->phase_3_constant_temp->setEnabled(true); ui->comboBox_phase_3_atmosphere->setEnabled(true); } else { ui->phase_3_cutoff_temp->setEnabled(false); ui->phase_3_scan_rate->setEnabled(false); ui->phase_3_constant_temp->setEnabled(false); ui->comboBox_phase_3_atmosphere->setEnabled(false); } } else if (sender() == ui->checkBox_phase_4) { if (ui->checkBox_phase_4->isChecked()) { ui->phase_4_cutoff_temp->setEnabled(true); ui->phase_4_scan_rate->setEnabled(true); ui->phase_4_constant_temp->setEnabled(true); ui->comboBox_phase_4_atmosphere->setEnabled(true); } else { ui->phase_4_cutoff_temp->setEnabled(false); ui->phase_4_scan_rate->setEnabled(false); ui->phase_4_constant_temp->setEnabled(false); ui->comboBox_phase_4_atmosphere->setEnabled(false); } } } void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba) { logde<<"----------------------- recv"; QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数 qDebug() << "slotRecvPhaseInfo hex:" << hexData; QByteArray localba = ba; SerialPortProtocol *spp = (SerialPortProtocol *)localba.data(); u8 *data = spp->data_buf; int phaseSize = spp->len / PHASE_BYTE_SIZE; QVector phaseVtr; for (int i = 0; i < phaseSize; i++) { #if 0 Phase *phase = (Phase *)(data + i * PHASE_BYTE_SIZE); phaseVtr.push_back(*phase); #endif #if 0 u8* localData = data + i * PHASE_BYTE_SIZE; int index = 0; Phase phase; phase.onoff = *(localData + index); index += 1; phase.cutoff_temp = (float)*(localData + index); index += 4; phase.temp_flow = (float)*(localData + index); index += 4; phase.constant_temp_time_min = (u16)*(localData + index); index += 2; // phase.gas = (int)*(localData + index); int gasType= (u8)*(localData + index); switch(gasType){ case GasType::NC: phase.gas = GasType::NC; break; case GasType::N2: phase.gas = GasType::N2; break; case GasType::O2: phase.gas = GasType::O2; break; default: break; } phaseVtr.push_back(phase); #endif uint8_t* localData = data + i * PHASE_BYTE_SIZE; int index = 0; Phase phase; // 解析 onoff // phase.onoff = *(localData + index); memcpy(&phase.onoff, localData + index, sizeof(uint8_t)); index += sizeof(uint8_t); // 解析 cutoff_temp memcpy(&phase.cutoff_temp, localData + index, sizeof(float)); index += sizeof(float); // 解析 temp_flow memcpy(&phase.temp_flow, localData + index, sizeof(float)); index += sizeof(float); // 解析 constant_temp_time_min memcpy(&phase.constant_temp_time_min, localData + index, sizeof(uint16_t)); index += sizeof(uint16_t); // 解析 gas uint8_t gasType = *(localData + index); switch (gasType) { case NC: phase.gas = NC; break; case N2: phase.gas = N2; break; case O2: phase.gas = O2; break; default: phase.gas = NC; // 默认值,表示未知类型 break; } phaseVtr.push_back(phase); } Global::_experimentInfo.phaseVtr = phaseVtr; //ui update // logde<<"phaseVtr size:"<(this->findChild(checkBoxName)); if (checkBox_phase) { checkBox_phase->setChecked(true); // qDebug()<<"found..."; }else{ // qDebug()<<"not found..."; } QString cutOffTempLineEditName = QString("phase_%1_cutoff_temp").arg(i); QLineEdit *cutOffTempLineEdit = qobject_cast(this->findChild(cutOffTempLineEditName)); if(cutOffTempLineEdit){ cutOffTempLineEdit->setText(QString::number(phase.cutoff_temp,'f',3)); cutOffTempLineEdit->setEnabled(true); } QString scanRateLineEditName = QString("phase_%1_scan_rate").arg(i); QLineEdit *scanRateLineEdit = qobject_cast(this->findChild(scanRateLineEditName)); if(scanRateLineEdit){ scanRateLineEdit->setText(QString::number(phase.temp_flow,'f',3)); scanRateLineEdit->setEnabled(true); } QString constantTempLineEditName = QString("phase_%1_constant_temp").arg(i); QLineEdit *constantTempLineEdit = qobject_cast(this->findChild(constantTempLineEditName)); if(constantTempLineEdit){ constantTempLineEdit->setText(QString::number(phase.constant_temp_time_min)); constantTempLineEdit->setEnabled(true); } QString atmoshpereComboBoxName = QString("comboBox_phase_%1_atmosphere").arg(i); QComboBox *atmoshpereComboBox = qobject_cast(this->findChild(atmoshpereComboBoxName)); if(atmoshpereComboBox){ atmoshpereComboBox->setCurrentIndex(phase.gas % 256); atmoshpereComboBox->setEnabled(true); } } // // radioButton_OIT_not // radioButton_OIT // comboBox_initial_atmosphere u8 *oitValue = (data + 72); logde<<"oit value:"<<(int)*oitValue; if(*oitValue){ ui->radioButton_OIT->setChecked(false); ui->radioButton_OIT_not->setChecked(true); #if 0 QString oitRadioButtonName("radioButton_OIT"); QRadioButton *oitRadioButton = qobject_cast(this->findChild(oitRadioButtonName)); if(oitRadioButton){ oitRadioButton->setChecked(true); } #endif }else{ ui->radioButton_OIT->setChecked(true); ui->radioButton_OIT_not->setChecked(false); #if 0 QString oitNotRadioButtonName("radioButton_OIT_not"); QRadioButton *oitNotRadioButton = qobject_cast(this->findChild(oitNotRadioButtonName)); if(oitNotRadioButton){ oitNotRadioButton->setChecked(true); } #endif } u8 *initAtmosphereValue = (data + 73); logde<<"initAtmosphereValue:"<< (int)(*initAtmosphereValue); ui->comboBox_initial_atmosphere->setCurrentIndex((int)*initAtmosphereValue); #if 0 QString initialAtmosphereComboBoxObjectName("comboBox_initial_atmosphere"); QComboBox *initialAtmosphereComboBox = qobject_cast(this->findChild(initialAtmosphereComboBoxObjectName)); if(initialAtmosphereComboBox){ initialAtmosphereComboBox->setCurrentIndex(*initAtmosphereValue); } #endif }