#include <qdebug.h>
#include "realtimedataform.h"
#include "ui_realtimedataform.h"

RealTimeDataForm::RealTimeDataForm(QWidget *parent) : QWidget(parent),
    ui(new Ui::RealTimeDataForm)
{
    ui->setupUi(this);
    setWindowTitle("实时数据窗口");
}

RealTimeDataForm::~RealTimeDataForm()
{
    delete ui;
}

void RealTimeDataForm::slotRevCommonData(const CommonData &data)
{
#if 0
    qDebug()<<"rev-------------------------";
    // 格式化输出 double 类型，保留三位小数
    QString formattedSampleTemp = QString::number(data.sample_temp, 'f', 3);
    qDebug() << "sample temp:" << formattedSampleTemp;

    QString formattedColdTemp = QString::number(data.cold_temp, 'f', 3);
    qDebug() << "cold temp:" << formattedColdTemp;
#endif
    // 异常信息
    /**
     * @brief abnormalStr
     *  0：空闲状态
        1：加热运行
        2：恒温运行
        3：冷却中
        4：升温速率自整定
     */

    QString abnormalStr = "正常";

    switch (data.hardware_err)
    {
    case 0:
        abnormalStr = "正常";
        break;
    case 1:
        abnormalStr = "冷端温度错误";
        break;
    case 2:
        abnormalStr = "采集板卡错误";
        break;
    case 3:
        abnormalStr = "样品温度错误";
        break;
    case 4:
        abnormalStr = "DSC错误";
        break;
    case 5:
        abnormalStr = "加热模块错误";
        break;
    default:
        break;
    }
    ui->abnormalLineEdit->setText(abnormalStr);
    // 运行状态
    QString runTypeStr = "空闲状态";
    switch (data.run_type)
    {
    case 0:
        runTypeStr = "空闲状态";
        break;
    case 1:
        runTypeStr = "加热运行";
        break;
    case 2:
        runTypeStr = "恒温运行";
        break;
    case 3:
        runTypeStr = "冷却中";
        break;
    case 4:
        runTypeStr = "升温速率自整定";
        break;
    default:
        break;
    }
    ui->runStatusLineEdit->setText(runTypeStr);
    // 当前阶段
    ui->currentStageLineEdit->setText(QString::number(data.current_phase));
    // 累计运行时间
    ui->addruntimeLineEdit->setText(QString::number(data.add_run_time, 'f', 3));
    // 恒温时间
    ui->constantTempTimeLineEdit->setText(QString::number(data.add_constan_temp_time, 'f', 3));
    // 温度
    ui->tempLineEdit->setText(QString::number(data.sample_temp, 'f', 3));
    // DSC
    ui->dSCMwLineEdit->setText(QString::number(data.dsc, 'f', 3));
    // 样品质量
    ui->weightLineEdit->setText("--");
    // 通氧时间
    ui->oxyTimeLineEdit->setText("--");
    // 扫描速率
    ui->scanRateLineEdit->setText("--");
    // 当前气氛
    QString gasName;
    switch(data.current_gas){
    case GasType::NC:
        gasName = "NC";
        break;
    case GasType::N2:
        gasName = "N2";
        break;
    case GasType::O2:
        gasName = "O2";
        break;
    default:
        gasName = "NC";
        break;
    }
    ui->currentAtmosphereLineEdit->setText(gasName);
}
