138 lines
3.9 KiB
C++
138 lines
3.9 KiB
C++
#include "canidcalc.h"
|
|
#include "ui_canidcalc.h"
|
|
|
|
CanIdCalc::CanIdCalc(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::CanIdCalc)
|
|
{
|
|
ui->setupUi(this);
|
|
CanId.ID_All = 0;
|
|
CanIdModbus.ID_All = 0;
|
|
ui->StrAdrBox->setValue(0);
|
|
on_DataTypeBox_currentIndexChanged(0);
|
|
}
|
|
|
|
CanIdCalc::~CanIdCalc()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void CanIdCalc::on_DataTypeBox_currentIndexChanged(int index)
|
|
{
|
|
isModbus = false;
|
|
ui->SensorTypeBox->clear();
|
|
ui->SensorTypeBox->setEnabled(true);
|
|
ui->SensorIdBox->setEnabled(true);
|
|
ui->SensorTypeLabel->show();
|
|
ui->SensorTypeBox->show();
|
|
ui->StrAdrLabel->hide();
|
|
ui->StrAdrBox->hide();
|
|
ui->SensorTypeLabel->setText("Sensor Type");
|
|
ui->SensorIdLabel->setText("Sensor ID");
|
|
ui->SensorIdBox->setMaximum(2047);
|
|
ui->SensorIdBox->setValue(CanId.Fields.SensorID);
|
|
CanId.Fields.DataType = index;
|
|
CanIdModbus.Fields.DataType = index;
|
|
switch (index) {
|
|
case 0:
|
|
ui->SensorTypeBox->addItem("Статус");
|
|
ui->SensorTypeBox->addItem("Запрос на вкл/выкл");
|
|
ui->SensorTypeBox->addItem("Рестарт устройств");
|
|
ui->SensorTypeBox->addItem("Установка времени");
|
|
break;
|
|
case 1:
|
|
ui->SensorTypeBox->addItem("Аварии");
|
|
ui->SensorTypeBox->addItem("Предупреждения");
|
|
ui->SensorTypeBox->addItem("Управляющие сигналы");
|
|
ui->SensorTypeBox->addItem("Флаги");
|
|
ui->SensorTypeBox->addItem("Рестарт устройства");
|
|
ui->SensorTypeBox->addItem("Изменение режима работы устройства");
|
|
ui->SensorTypeBox->addItem("Перечень параметров");
|
|
break;
|
|
case 2:
|
|
ui->SensorTypeBox->addItem("Универсальный запрос");
|
|
ui->SensorTypeBox->addItem("Уставки");
|
|
ui->SensorTypeBox->addItem("Напряжение");
|
|
ui->SensorTypeBox->addItem("Ток");
|
|
ui->SensorTypeBox->addItem("Температура");
|
|
break;
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
isModbus = true;
|
|
ui->SensorTypeLabel->hide();
|
|
ui->SensorTypeBox->hide();
|
|
ui->StrAdrLabel->show();
|
|
ui->StrAdrBox->show();
|
|
ui->SensorIdLabel->setText("Кол-во регистров");
|
|
ui->SensorIdBox->setMaximum(255);
|
|
ui->SensorIdBox->setValue(CanIdModbus.Fields.CountReg);
|
|
on_StrAdrBox_valueChanged(ui->StrAdrBox->value());
|
|
break;
|
|
case 7:
|
|
CanId.Fields.DataType = 0xF;
|
|
ui->SensorTypeBox->addItem("Пульс");
|
|
ui->SensorTypeBox->setEnabled(false);
|
|
ui->SensorIdBox->setEnabled(false);
|
|
ui->SensorIdBox->setValue(0);
|
|
break;
|
|
}
|
|
id_Calc();
|
|
}
|
|
|
|
void CanIdCalc::on_SensorTypeBox_currentIndexChanged(int index)
|
|
{
|
|
CanId.Fields.SensorType = index;
|
|
id_Calc();
|
|
}
|
|
|
|
void CanIdCalc::on_SensorIdBox_valueChanged(int arg1)
|
|
{
|
|
CanId.Fields.SensorID = arg1;
|
|
CanIdModbus.Fields.CountReg = arg1;
|
|
id_Calc();
|
|
}
|
|
|
|
void CanIdCalc::on_DeviceIdBox_valueChanged(int arg1)
|
|
{
|
|
CanId.Fields.Device = arg1;
|
|
CanIdModbus.Fields.Device = arg1;
|
|
id_Calc();
|
|
}
|
|
|
|
void CanIdCalc::id_Calc()
|
|
{
|
|
if(isModbus)
|
|
{
|
|
ui->ResultLine->setText(QStringLiteral("%1").arg(CanIdModbus.ID_All, 8, 16, QLatin1Char('0')).toUpper());
|
|
}
|
|
else
|
|
{
|
|
ui->ResultLine->setText(QStringLiteral("%1").arg(CanId.ID_All, 8, 16, QLatin1Char('0')).toUpper());
|
|
}
|
|
}
|
|
|
|
void CanIdCalc::on_StrAdrBox_valueChanged(int arg1)
|
|
{
|
|
CanIdModbus.Fields.StrAdr = arg1;
|
|
id_Calc();
|
|
}
|
|
|
|
void CanIdCalc::on_routeBox_stateChanged(int arg1)
|
|
{
|
|
switch (arg1) {
|
|
case Qt::Unchecked:
|
|
ui->routeBox->setText("Master");
|
|
CanId.Fields.Route = 0;
|
|
CanIdModbus.Fields.Route = 0;
|
|
break;
|
|
case Qt::Checked:
|
|
ui->routeBox->setText("Slave");
|
|
CanId.Fields.Route = 1;
|
|
CanIdModbus.Fields.Route = 1;
|
|
break;
|
|
}
|
|
id_Calc();
|
|
}
|