From 93b4a24b8bca06fa3d6139c14c52c1132624dfcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A8?= =?UTF-8?q?=D1=82=D0=B5=D0=B9=D0=B1=D0=B5=D0=B7=D0=B0=D0=BD=D0=B4=D1=82?= Date: Thu, 9 Oct 2025 12:03:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BB=D0=B0=D0=B4=D0=BE=D1=87=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit note: крашится в static компиле --- M3KTE_TERM/M3KTE_TERM.pro | 8 +- M3KTE_TERM/adcgraphdialog.cpp | 540 +++++++++++++++++ M3KTE_TERM/adcgraphdialog.h | 88 +++ M3KTE_TERM/adcgraphdialog.ui | 171 ++++++ M3KTE_TERM/debugTerminalDialog.ui | 916 +++++++++++++++++++++++++++++ M3KTE_TERM/debugterminaldialog.cpp | 824 ++++++++++++++++++++++++++ M3KTE_TERM/debugterminaldialog.h | 224 +++++++ M3KTE_TERM/m3kte.cpp | 68 ++- M3KTE_TERM/m3kte.h | 5 + M3KTE_TERM/m3kte.ui | 14 +- 10 files changed, 2855 insertions(+), 3 deletions(-) create mode 100644 M3KTE_TERM/adcgraphdialog.cpp create mode 100644 M3KTE_TERM/adcgraphdialog.h create mode 100644 M3KTE_TERM/adcgraphdialog.ui create mode 100644 M3KTE_TERM/debugTerminalDialog.ui create mode 100644 M3KTE_TERM/debugterminaldialog.cpp create mode 100644 M3KTE_TERM/debugterminaldialog.h diff --git a/M3KTE_TERM/M3KTE_TERM.pro b/M3KTE_TERM/M3KTE_TERM.pro index 07b0401..ba6bb12 100644 --- a/M3KTE_TERM/M3KTE_TERM.pro +++ b/M3KTE_TERM/M3KTE_TERM.pro @@ -5,7 +5,7 @@ QT += serialbus widgets requires(qtConfig(combobox)) QT += serialport qtConfig(modbus-serialport): QT += serialport - +QT += charts greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 @@ -25,6 +25,8 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + adcgraphdialog.cpp \ + debugterminaldialog.cpp \ devicesettingsdialog.cpp \ lineringer.cpp \ main.cpp \ @@ -35,6 +37,8 @@ SOURCES += \ writeregistermodel.cpp HEADERS += \ + adcgraphdialog.h \ + debugterminaldialog.h \ devicesettingsdialog.h \ lineringer.h \ m3kte.h \ @@ -44,6 +48,8 @@ HEADERS += \ writeregistermodel.h FORMS += \ + adcgraphdialog.ui \ + debugTerminalDialog.ui \ devicesettingsdialog.ui \ lineringer.ui \ m3kte.ui \ diff --git a/M3KTE_TERM/adcgraphdialog.cpp b/M3KTE_TERM/adcgraphdialog.cpp new file mode 100644 index 0000000..8838398 --- /dev/null +++ b/M3KTE_TERM/adcgraphdialog.cpp @@ -0,0 +1,540 @@ +#include "adcgraphdialog.h" +#include "ui_adcgraphdialog.h" +#include +#include +#include +#include +#include // Добавить этот include +#include // Добавить этот include + +// Адреса регистров для АЦП +#define REG_ADC_ZERO 555 +#define REG_ADC_ONE_VOLT 556 +#define REG_STABLE_START 557 +#define REG_STABLE_END 558 +#define REG_TE_NUMBER 564 +#define REG_ADC_BUFFER_START 571 +#define REG_ADC_BUFFER_END 1070 + +AdcGraphDialog::AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent) : + QDialog(parent), + ui(new Ui::AdcGraphDialog), + m_modbusDevice(modbusDevice), + m_updateTimer(new QTimer(this)), + m_boardId(-1), + m_boardAddress(-1), + m_teNumber(-1), + m_adcZero(0), + m_adcOneVolt(4096), + m_series(new QLineSeries()), + m_chart(new QChart()), + m_stableStartLine(new QLineSeries()), + m_stableEndLine(new QLineSeries()), + m_stableStartIndex(-1), + m_stableEndIndex(-1), + m_startAddress(0), + m_registerCount(100) +{ + ui->setupUi(this); + + // Настройка основного графика + m_series->setName("АЦП данные"); + m_chart->addSeries(m_series); + + // Настройка линий стабильного участка + m_stableStartLine->setName("Начало стаб. участка"); + m_stableStartLine->setColor(Qt::red); + m_stableStartLine->setPen(QPen(Qt::red, 2, Qt::DashLine)); + m_chart->addSeries(m_stableStartLine); + + m_stableEndLine->setName("Конец стаб. участка"); + m_stableEndLine->setColor(Qt::green); + m_stableEndLine->setPen(QPen(Qt::green, 2, Qt::DashLine)); + m_chart->addSeries(m_stableEndLine); + + m_chart->setTitle("График АЦП"); + m_chart->legend()->setVisible(true); + m_chart->legend()->setAlignment(Qt::AlignTop); + + m_axisX = new QValueAxis(); + m_axisX->setTitleText("Отсчеты АЦП"); + m_axisX->setRange(0, m_registerCount); + m_chart->addAxis(m_axisX, Qt::AlignBottom); + m_series->attachAxis(m_axisX); + m_stableStartLine->attachAxis(m_axisX); + m_stableEndLine->attachAxis(m_axisX); + + m_axisY = new QValueAxis(); + m_axisY->setTitleText("Напряжение, В"); + m_axisY->setRange(-1.3, 1.3); + m_chart->addAxis(m_axisY, Qt::AlignLeft); + m_series->attachAxis(m_axisY); + m_stableStartLine->attachAxis(m_axisY); + m_stableEndLine->attachAxis(m_axisY); + + QChartView *chartView = new QChartView(m_chart); + chartView->setRenderHint(QPainter::Antialiasing); + + QVBoxLayout *layout = new QVBoxLayout(ui->plotWidget); + layout->addWidget(chartView); + + // Подключаем сигналы элементов управления диапазоном + connect(ui->startAddressSpinBox, QOverload::of(&QSpinBox::valueChanged), + this, &AdcGraphDialog::on_startAddressChanged); + connect(ui->registerCountSpinBox, QOverload::of(&QSpinBox::valueChanged), + this, &AdcGraphDialog::on_registerCountChanged); + connect(ui->rangeApplyButton, &QPushButton::clicked, + this, &AdcGraphDialog::on_rangeApplyClicked); + + connect(m_updateTimer, &QTimer::timeout, this, &AdcGraphDialog::onUpdateTimer); + connect(ui->closeBtn, &QPushButton::clicked, this, &AdcGraphDialog::on_closeBtn_clicked); +} + + + +AdcGraphDialog::~AdcGraphDialog() +{ + stopGraph(); + delete ui; +} + + + +void AdcGraphDialog::setModbusDevice(QModbusClient *device) +{ + m_modbusDevice = device; +} + +void AdcGraphDialog::readCalibrationValues() +{ + if (!m_modbusDevice || m_boardAddress == -1) return; + + // Читаем калибровочные значения (регистры 555 и 556) + QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_ADC_ZERO, 2); + + if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) { + if (!reply->isFinished()) { + connect(reply, &QModbusReply::finished, this, [this, reply]() { + if (reply->error() == QModbusDevice::NoError) { + const QModbusDataUnit result = reply->result(); + if (result.valueCount() >= 2) { + m_adcZero = result.value(0); + m_adcOneVolt = result.value(1); + qDebug() << "Calibration values - Zero:" << m_adcZero << "1V:" << m_adcOneVolt; + } + } else { + qDebug() << "Error reading calibration:" << reply->errorString(); + } + reply->deleteLater(); + }); + } else { + reply->deleteLater(); + } + } +} + +void AdcGraphDialog::readStableIndices() +{ + if (!m_modbusDevice || m_boardAddress == -1) return; + + // Читаем индексы стабильного участка (регистры 557 и 558) + QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_STABLE_START, 2); + + if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) { + if (!reply->isFinished()) { + connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onStableIndicesReady); + } else { + reply->deleteLater(); + } + } +} + +void AdcGraphDialog::onStableIndicesReady() +{ + auto *reply = qobject_cast(sender()); + if (!reply) return; + + if (reply->error() == QModbusDevice::NoError) { + const QModbusDataUnit result = reply->result(); + if (result.valueCount() >= 2) { + m_stableStartIndex = result.value(0); + m_stableEndIndex = result.value(1); + qDebug() << "Stable indices updated - Start:" << m_stableStartIndex << "End:" << m_stableEndIndex; + updateStableLines(); + + // Обновляем статистику с новыми индексами + updateStatisticsWithStableInfo(); + } + } else { + qDebug() << "Error reading stable indices:" << reply->errorString(); + } + + reply->deleteLater(); +} + +void AdcGraphDialog::updateStatistics() +{ + if (m_series->count() > 0) { + double min = 1000, max = -1000, sum = 0; + for (const QPointF &point : m_series->points()) { + double y = point.y(); + if (y < min) min = y; + if (y > max) max = y; + sum += y; + } + double avg = sum / m_series->count(); + + ui->minLabel->setText(QString::number(min, 'f', 3) + " В"); + ui->maxLabel->setText(QString::number(max, 'f', 3) + " В"); + ui->avgLabel->setText(QString::number(avg, 'f', 3) + " В"); + + // Обновляем информацию о стабильном участке + updateStatisticsWithStableInfo(); + } +} + + +void AdcGraphDialog::updateStatisticsWithStableInfo() +{ + if (m_series->count() > 0) { + // Обновляем информацию о стабильном участке в статистике + if (m_stableStartIndex >= m_startAddress && + m_stableStartIndex < m_startAddress + m_registerCount) { + int relativeIndex = m_stableStartIndex - m_startAddress; + ui->samplesLabel->setText( + QString("%1 отсч. (адр %2-%3) [стаб: %4]") + .arg(m_series->count()) + .arg(m_startAddress) + .arg(m_startAddress + m_registerCount - 1) + .arg(relativeIndex) + ); + } else { + ui->samplesLabel->setText( + QString("%1 отсч. (адр %2-%3)") + .arg(m_series->count()) + .arg(m_startAddress) + .arg(m_startAddress + m_registerCount - 1) + ); + } + } +} + + +void AdcGraphDialog::updateStableLines() +{ + // Очищаем предыдущие линии + m_stableStartLine->clear(); + m_stableEndLine->clear(); + + // Получаем текущий диапазон оси Y + double yMin = m_axisY->min(); + double yMax = m_axisY->max(); + + // Добавляем вертикальную линию для начала стабильного участка + // Учитываем текущий диапазон отображения + if (m_stableStartIndex >= m_startAddress && m_stableStartIndex < m_startAddress + m_registerCount) { + int relativeStartIndex = m_stableStartIndex - m_startAddress; + m_stableStartLine->append(relativeStartIndex, yMin); + m_stableStartLine->append(relativeStartIndex, yMax); + } + + // Добавляем вертикальную линию для конца стабильного участка + if (m_stableEndIndex >= m_startAddress && m_stableEndIndex < m_startAddress + m_registerCount) { + int relativeEndIndex = m_stableEndIndex - m_startAddress; + m_stableEndLine->append(relativeEndIndex, yMin); + m_stableEndLine->append(relativeEndIndex, yMax); + } +} + +void AdcGraphDialog::updateGraphRange() +{ + // Обновляем диапазон оси X + m_axisX->setRange(0, m_registerCount); + m_axisX->setTitleText(QString("Отсчеты АЦП (%1-%2)").arg(m_startAddress).arg(m_startAddress + m_registerCount - 1)); + + // Сбрасываем ось Y к разумному диапазону по умолчанию + m_axisY->setRange(-1.2, 1.2); + + // Обновляем линии стабильного участка с учетом нового диапазона + updateStableLines(); +} + +void AdcGraphDialog::readAdcDataAndIndices() +{ + if (!m_modbusDevice || m_boardAddress == -1) return; + + // Создаем один запрос для данных АЦП + индексов стабильности + // Адреса: данные АЦП (571+), индексы (557-558) + int start = m_startAddress + REG_ADC_BUFFER_START; + int count = m_registerCount; + + // Читаем индексы стабильности (557-558) и данные АЦП одним запросом + QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_STABLE_START, + count + (start - REG_STABLE_START)); + + qDebug() << "Reading combined data from address" << REG_STABLE_START << "count:" << unit.valueCount(); + + if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) { + if (!reply->isFinished()) { + connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onCombinedDataReady); + } else { + reply->deleteLater(); + } + } else { + qDebug() << "Failed to send combined data read request"; + } +} + + +void AdcGraphDialog::onCombinedDataReady() +{ + auto *reply = qobject_cast(sender()); + if (!reply) return; + + if (reply->error() == QModbusDevice::NoError) { + const QModbusDataUnit result = reply->result(); + + // Обрабатываем индексы стабильности (первые 2 регистра) + if (result.valueCount() >= 2) { + m_stableStartIndex = result.value(0); + m_stableEndIndex = result.value(1); + qDebug() << "Stable indices - Start:" << m_stableStartIndex << "End:" << m_stableEndIndex; + } + + // Обрабатываем данные АЦП (остальные регистры) + int adcDataStartIndex = (m_startAddress + REG_ADC_BUFFER_START) - REG_STABLE_START; + + // Очищаем предыдущие данные + m_series->clear(); + + // Добавляем новые точки и определяем диапазон + double minVoltage = 1000, maxVoltage = -1000; + for (int i = 0; i < m_registerCount; ++i) { + if (adcDataStartIndex + i < result.valueCount()) { + double voltage = convertAdcToVoltage(result.value(adcDataStartIndex + i)); + m_series->append(i, voltage); + + // Обновляем мин/макс для автоматического масштабирования + if (voltage < minVoltage) minVoltage = voltage; + if (voltage > maxVoltage) maxVoltage = voltage; + } + } + + // Обновляем график и статистику + updateYAxisRange(minVoltage, maxVoltage); + updateStableLines(); + updateStatistics(); + + } else { + qDebug() << "Error reading combined data:" << reply->errorString(); + } + + reply->deleteLater(); +} + + +void AdcGraphDialog::readAdcBuffer() +{ + if (!m_modbusDevice || m_boardAddress == -1) return; + + // Читаем выбранный диапазон буфера АЦП + QModbusDataUnit unit(QModbusDataUnit::InputRegisters, m_startAddress+REG_ADC_BUFFER_START, m_registerCount); + + qDebug() << "Reading ADC buffer from address" << m_startAddress << "count:" << m_registerCount; + + if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) { + if (!reply->isFinished()) { + connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onReadReady); + } else { + reply->deleteLater(); + } + } else { + qDebug() << "Failed to send ADC buffer read request"; + } +} + +void AdcGraphDialog::startGraph(int boardId, int teNumber) +{ + m_boardId = boardId; + m_teNumber = teNumber; + m_boardAddress = boardId + 1; + + setWindowTitle(QString("График АЦП - Плата %1, ТЭ %2 (адр %3-%4)") + .arg(boardId + 1) + .arg(teNumber) + .arg(m_startAddress) + .arg(m_startAddress + m_registerCount - 1)); + + // Очищаем предыдущие данные + m_series->clear(); + m_stableStartLine->clear(); + m_stableEndLine->clear(); + + // Обновляем диапазон графика + updateGraphRange(); + + readCalibrationValues(); // Калибровку оставляем отдельно (она редко меняется) + m_updateTimer->start(m_timeout); // Запускаем обновление +} + + +void AdcGraphDialog::setTimeout(int timeout) +{ + m_timeout = timeout; +} + +void AdcGraphDialog::stopGraph() +{ + m_updateTimer->stop(); + m_boardId = -1; + m_boardAddress = -1; + + // Отменяем все pending запросы Modbus + if (m_modbusDevice) { + m_modbusDevice->disconnect(this); // Отключаем все сигналы + } +} + +void AdcGraphDialog::onUpdateTimer() +{ + if (m_boardAddress == -1) return; + // Читаем и буфер АЦП, и индексы стабильности каждый период + readAdcDataAndIndices(); +} + +void AdcGraphDialog::onReadReady() +{ + auto *reply = qobject_cast(sender()); + if (!reply) return; + + if (reply->error() == QModbusDevice::NoError) { + const QModbusDataUnit result = reply->result(); + + // Очищаем предыдущие данные + m_series->clear(); + + // Добавляем новые точки и определяем диапазон + double minVoltage = 1000, maxVoltage = -1000; + for (int i = 0; i < result.valueCount(); ++i) { + double voltage = convertAdcToVoltage(result.value(i)); + m_series->append(i, voltage); + + // Обновляем мин/макс для автоматического масштабирования + if (voltage < minVoltage) minVoltage = voltage; + if (voltage > maxVoltage) maxVoltage = voltage; + } + + // Автоматически настраиваем диапазон оси Y + updateYAxisRange(minVoltage, maxVoltage); + + // Обновляем линии стабильного участка + updateStableLines(); + + // Обновляем статистику + if (m_series->count() > 0) { + double min = 1000, max = -1000, sum = 0; + for (const QPointF &point : m_series->points()) { + double y = point.y(); + if (y < min) min = y; + if (y > max) max = y; + sum += y; + } + double avg = sum / m_series->count(); + + ui->minLabel->setText(QString::number(min, 'f', 3) + " В"); + ui->maxLabel->setText(QString::number(max, 'f', 3) + " В"); + ui->avgLabel->setText(QString::number(avg, 'f', 3) + " В"); + + // Обновляем информацию о стабильном участке + updateStatisticsWithStableInfo(); + } + + } else { + qDebug() << "Error reading ADC buffer:" << reply->errorString(); + } + + reply->deleteLater(); +} + +void AdcGraphDialog::updateYAxisRange(double minVoltage, double maxVoltage) +{ + // Добавляем запас 10% к диапазону + double range = maxVoltage - minVoltage; + double margin = range * 0.1; + + double yMin = minVoltage - margin; + double yMax = maxVoltage + margin; + + // Если диапазон слишком маленький или слишком большой, устанавливаем разумные пределы + if ((range < 0.1) || ((maxVoltage > 0.5) && (minVoltage < -0.5))) + { + yMin = -1.5; + yMax = 1.5; + } + else if(maxVoltage > 0.5) { + yMin = -0.1; + yMax = 1.5; + } + else if(maxVoltage < 0.5) + { + yMin = -1.5; + yMax =0.1; + } + else + { + yMin = -1.5; + yMax = 1.5; + } + + // Ограничиваем разумными пределами + yMin = qMax(yMin, -5.0); // Не ниже -5В + yMax = qMin(yMax, 5.0); // Не выше 5В + + // Устанавливаем новый диапазон + m_axisY->setRange(yMin, yMax); + + // Обновляем линии стабильного участка с новым диапазоном + updateStableLines(); +} + + +double AdcGraphDialog::convertAdcToVoltage(quint16 adcValue) +{ + if (m_adcOneVolt == m_adcZero) return 0; + return (adcValue - m_adcZero) * 1.1 / (m_adcOneVolt - m_adcZero); +} + +void AdcGraphDialog::on_startAddressChanged(int value) +{ + m_startAddress = value; + qDebug() << "Start address changed to:" << value; +} + +void AdcGraphDialog::on_registerCountChanged(int value) +{ + m_registerCount = value; + qDebug() << "Register count changed to:" << value; +} + +void AdcGraphDialog::on_rangeApplyClicked() +{ + qDebug() << "Applying new range - Start:" << m_startAddress << "Count:" << m_registerCount; + updateGraphRange(); + + // Немедленно обновляем данные + if (m_boardAddress != -1) { + readAdcBuffer(); + } +} + +void AdcGraphDialog::on_closeBtn_clicked() +{ + stopGraph(); + reject(); // Или accept() в зависимости от логики +} + +void AdcGraphDialog::closeEvent(QCloseEvent *event) +{ + stopGraph(); + event->accept(); +} diff --git a/M3KTE_TERM/adcgraphdialog.h b/M3KTE_TERM/adcgraphdialog.h new file mode 100644 index 0000000..bb33d2a --- /dev/null +++ b/M3KTE_TERM/adcgraphdialog.h @@ -0,0 +1,88 @@ +#ifndef ADCGRAPHDIALOG_H +#define ADCGRAPHDIALOG_H + +#include +#include +#include +#include +#include + +QT_CHARTS_USE_NAMESPACE + +// Forward declaration +class QModbusClient; + +namespace Ui { +class AdcGraphDialog; +} + +class AdcGraphDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent = nullptr); + ~AdcGraphDialog(); + + void setModbusDevice(QModbusClient *device); + void startGraph(int boardId, int teNumber); + void stopGraph(); + void setTimeout(int timeout); + void readyClose(); + +protected: + void closeEvent(QCloseEvent *event) override; + +private slots: + void onUpdateTimer(); + void onReadReady(); + void onStableIndicesReady(); + void on_closeBtn_clicked(); + void on_startAddressChanged(int value); + void on_registerCountChanged(int value); + void on_rangeApplyClicked(); + +private: + Ui::AdcGraphDialog *ui; + QModbusClient *m_modbusDevice; + QTimer *m_updateTimer; + int m_boardId; + int m_boardAddress; + int m_teNumber; + int m_timeout; + + // Калибровочные значения + double m_adcZero; + double m_adcOneVolt; + + // Для отображения стабильного участка + QLineSeries *m_stableStartLine; + QLineSeries *m_stableEndLine; + int m_stableStartIndex; + int m_stableEndIndex; + + // Данные графика + QLineSeries *m_series; + QValueAxis *m_axisX; + QValueAxis *m_axisY; + QChart *m_chart; // Добавить указатель на chart + + // Управление диапазоном регистров + int m_startAddress; + int m_registerCount; + + void updateStatistics(); + void readAdcDataAndIndices(); + void onCombinedDataReady(); + void updateStatisticsWithStableInfo(); + void updateYAxisRange(double minVoltage, double maxVoltage); + void setupRangeControls(); + void updateGraphRange(); + void readStableIndices(); + void updateStableLines(); + void readCalibrationValues(); + void readAdcBuffer(); + double convertAdcToVoltage(quint16 adcValue); +}; + +#endif // ADCGRAPHDIALOG_H diff --git a/M3KTE_TERM/adcgraphdialog.ui b/M3KTE_TERM/adcgraphdialog.ui new file mode 100644 index 0000000..b5283ec --- /dev/null +++ b/M3KTE_TERM/adcgraphdialog.ui @@ -0,0 +1,171 @@ + + + AdcGraphDialog + + + + 0 + 0 + 800 + 600 + + + + График АЦП + + + + + + + + + Начальный адрес: + + + + + + + 0 + + + 500 + + + 0 + + + + + + + Количество: + + + + + + + 1 + + + 100 + + + 100 + + + + + + + Применить + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + Мин: + + + + + + + 0.000 В + + + + + + + Макс: + + + + + + + 0.000 В + + + + + + + Средн: + + + + + + + 0.000 В + + + + + + + Сэмплов: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Закрыть + + + + + + + + + + \ No newline at end of file diff --git a/M3KTE_TERM/debugTerminalDialog.ui b/M3KTE_TERM/debugTerminalDialog.ui new file mode 100644 index 0000000..7ddf223 --- /dev/null +++ b/M3KTE_TERM/debugTerminalDialog.ui @@ -0,0 +1,916 @@ + + + DebugTerminalDialog + + + + 0 + 0 + 1188 + 675 + + + + Dialog + + + + + + Плата 4 + + + + + + Вызов функций + + + + + + Опрос ТЭ + + + + + + + Непрерывный вызов калибр. и опроса + + + + + + + Калибровка + + + + + + + Генерация HardFault + + + + + + + Настройки по умолчанию + + + + + + + Сбросить все ключи + + + + + + + + + + Тест светодиодов + + + + + + Работа + + + + + + + Предупреждение + + + + + + + Авария + + + + + + + Связь + + + + + + + LED VH1 (Зеленый) + + + + + + + LED VH2 (Зеленый) + + + + + + + LED VH3 (Красный) + + + + + + + + + + ADC + + + + + + 65 + + + + + + + ТЭ + + + + + + + Открыть график + + + + + + + + + + Тест дискретных сигналов + + + + + + Предупреждение + + + + + + + Авария + + + + + + + Ошибка 5 Vsci + + + + + + + Работа + + + + + + + Ошибка 5 В + + + + + + + Ошибка 24 В + + + + + + + Ошибка 5 VA + + + + + + + + + + Тест ламп и дискретных сигналов + + + + + + + + + + Плата 3 + + + + + + Вызов функций + + + + + + Опрос ТЭ + + + + + + + Непрерывный вызов калибр. и опроса + + + + + + + Калибровка + + + + + + + Генерация HardFault + + + + + + + Настройки по умолчанию + + + + + + + Сбросить все ключи + + + + + + + + + + ADC + + + + + + 85 + + + + + + + ТЭ + + + + + + + Открыть график + + + + + + + + + + Тест светодиодов + + + + + + Работа + + + + + + + Предупреждение + + + + + + + Авария + + + + + + + Связь + + + + + + + LED VH1 (Зеленый) + + + + + + + LED VH2 (Зеленый) + + + + + + + LED VH3 (Красный) + + + + + + + + + + Тест дискретных сигналов + + + + + + Авария + + + + + + + Ошибка 5 Vsci + + + + + + + Предупреждение + + + + + + + Работа + + + + + + + Ошибка 5 В + + + + + + + Ошибка 24 В + + + + + + + Ошибка 5 VA + + + + + + + + + + Тест ламп и дискретных сигналов + + + + + + + + + + Плата 2 + + + + + + Вызов функций + + + + + + Калибровка + + + + + + + Настройки по умолчанию + + + + + + + Сбросить все ключи + + + + + + + Опрос ТЭ + + + + + + + Генерация HardFault + + + + + + + Непрерывный вызов калибр. и опроса + + + + + + + + + + ADC + + + + + + ТЭ + + + + + + + 85 + + + + + + + Открыть график + + + + + + + + + + Тест дискретных сигналов + + + + + + Ошибка 5 Vsci + + + + + + + Ошибка 24 В + + + + + + + Предупреждение + + + + + + + Работа + + + + + + + Ошибка 5 В + + + + + + + Авария + + + + + + + Ошибка 5 VA + + + + + + + + + + Тест светодиодов + + + + + + Работа + + + + + + + Предупреждение + + + + + + + Авария + + + + + + + Связь + + + + + + + LED VH1 (Зеленый) + + + + + + + LED VH2 (Зеленый) + + + + + + + LED VH3 (Красный) + + + + + + + + + + Тест ламп и дискретных сигналов + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + + + + + Плата 1 + + + + + + Вызов функций + + + + + + Опрос ТЭ + + + + + + + Непрерывный вызов калибр. и опроса + + + + + + + Калибровка + + + + + + + Генерация HardFault + + + + + + + Настройки по умолчанию + + + + + + + Сбросить все ключи + + + + + + + + + + Тест светодиодов + + + + + + Работа + + + + + + + Предупреждение + + + + + + + Авария + + + + + + + Связь + + + + + + + LED VH1 (Зеленый) + + + + + + + LED VH2 (Зеленый) + + + + + + + LED VH3 (Красный) + + + + + + + + + + ADC + + + + + + ТЭ + + + + + + + 85 + + + + + + + Открыть график + + + + + + + + + + Тест дискретных сигналов + + + + + + Ошибка 5 Vsci + + + + + + + Ошибка 24 В + + + + + + + Предупреждение + + + + + + + Ошибка 5 В + + + + + + + Работа + + + + + + + Авария + + + + + + + Ошибка 5 VA + + + + + + + + + + Тест ламп и дискретных сигналов + + + + + + + + + + + + buttonBox + accepted() + DebugTerminalDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DebugTerminalDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/M3KTE_TERM/debugterminaldialog.cpp b/M3KTE_TERM/debugterminaldialog.cpp new file mode 100644 index 0000000..6c338f4 --- /dev/null +++ b/M3KTE_TERM/debugterminaldialog.cpp @@ -0,0 +1,824 @@ +#include "debugterminaldialog.h" +#include "ui_debugTerminalDialog.h" +#include "adcgraphdialog.h" +#include +#include +#include +#include + +DebugTerminalDialog::DebugTerminalDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::DebugTerminalDialog), + m_adcGraphDialog(nullptr), + m_modbusDevice(nullptr) +{ + ui->setupUi(this); + initializeConnections(); + + // Создаем AdcGraphDialog с nullptr + m_adcGraphDialog = new AdcGraphDialog(nullptr, this); +} + +DebugTerminalDialog::~DebugTerminalDialog() +{ + delete ui; +} + +void DebugTerminalDialog::setModbusDevice(QModbusClient *device) +{ + m_modbusDevice = device; + if (m_adcGraphDialog && device) { + m_adcGraphDialog->setModbusDevice(device); + } +} + +void DebugTerminalDialog::showEvent(QShowEvent *event) +{ + QDialog::showEvent(event); + // При открытии окна записываем в коил 555 значение "1" + + resetAll(); + + writeCoil(0, COIL_DEBUG_MODE, 1); + writeCoil(1, COIL_DEBUG_MODE, 1); + writeCoil(2, COIL_DEBUG_MODE, 1); + writeCoil(3, COIL_DEBUG_MODE, 1); +} + +void DebugTerminalDialog::closeEvent(QCloseEvent *event) +{ + // При закрытии окна записываем в коил 555 значение "0" + writeCoil(0, COIL_DEBUG_MODE, 0); + writeCoil(1, COIL_DEBUG_MODE, 0); + writeCoil(2, COIL_DEBUG_MODE, 0); + writeCoil(3, COIL_DEBUG_MODE, 0); + QDialog::closeEvent(event); +} + +void DebugTerminalDialog::initializeConnections() +{ + // Подключаем кнопки OK и RestoreDefaults + connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &DebugTerminalDialog::on_buttonBox_clicked); + + // Подключаем все чекбоксы для платы 1 + connect(ui->continiusCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_continiusCallChkBox_1_stateChanged); + connect(ui->calibrateCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_calibrateCallChkBox_1_stateChanged); + connect(ui->pollTECallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_pollTECallChkBox_1_stateChanged); + connect(ui->resetKeyCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetKeyCallChkBox_1_stateChanged); + connect(ui->resetDefaultCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetDefaultCallChkBox_1_stateChanged); + connect(ui->getHardfaultCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_getHardfaultCallChkBox_1_stateChanged); + + + connect(ui->enableLedTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::enableLedTestChkBox_1_stateChanged); + + connect(ui->discWorkTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWorkTestChkBox_1_stateChanged); + connect(ui->discWarnTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWarnTestChkBox_1_stateChanged); + connect(ui->discErrTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErrTestChkBox_1_stateChanged); + + + connect(ui->discErr24TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr24TestChkBox_1_stateChanged); + ui->discErr24TestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true); + connect(ui->discErr5TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5TestChkBox_1_stateChanged); + ui->discErr5TestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true); + connect(ui->discErr5VsciTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VsciTestChkBox_1_stateChanged); + ui->discErr5VsciTestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true); + connect(ui->discErr5VATestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VATestChkBox_1_stateChanged); + ui->discErr5VATestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true); + + connect(ui->ledWorkTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWorkTestChkBox_1_stateChanged); + connect(ui->ledWarnTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWarnTestChkBox_1_stateChanged); + connect(ui->ledErrTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledErrTestChkBox_1_stateChanged); + connect(ui->ledConnectTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledConnectTestChkBox_1_stateChanged); + connect(ui->ledVH1TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH1TestChkBox_1_stateChanged); + connect(ui->ledVH2TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH2TestChkBox_1_stateChanged); + connect(ui->ledVH3TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH3TestChkBox_1_stateChanged); + + connect(ui->openADCBtn_1, &QPushButton::clicked, this, &DebugTerminalDialog::on_openADCBtn_1_clicked); + + // Подключаем все чекбоксы для платы 2 + connect(ui->continiusCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_continiusCallChkBox_2_stateChanged); + connect(ui->calibrateCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_calibrateCallChkBox_2_stateChanged); + connect(ui->pollTECallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_pollTECallChkBox_2_stateChanged); + connect(ui->resetKeyCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetKeyCallChkBox_2_stateChanged); + connect(ui->resetDefaultCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetDefaultCallChkBox_2_stateChanged); + connect(ui->getHardfaultCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_getHardfaultCallChkBox_2_stateChanged); + + connect(ui->enableLedTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::enableLedTestChkBox_2_stateChanged); + + connect(ui->discWorkTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWorkTestChkBox_2_stateChanged); + connect(ui->discWarnTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWarnTestChkBox_2_stateChanged); + connect(ui->discErrTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErrTestChkBox_2_stateChanged); + + connect(ui->discErr24TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr24TestChkBox_2_stateChanged); + ui->discErr24TestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true); + connect(ui->discErr5TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5TestChkBox_2_stateChanged); + ui->discErr5TestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true); + connect(ui->discErr5VsciTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VsciTestChkBox_2_stateChanged); + ui->discErr5VsciTestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true); + connect(ui->discErr5VATestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VATestChkBox_2_stateChanged); + ui->discErr5VATestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true); + + connect(ui->ledWorkTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWorkTestChkBox_2_stateChanged); + connect(ui->ledWarnTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWarnTestChkBox_2_stateChanged); + connect(ui->ledErrTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledErrTestChkBox_2_stateChanged); + connect(ui->ledConnectTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledConnectTestChkBox_2_stateChanged); + connect(ui->ledVH1TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH1TestChkBox_2_stateChanged); + connect(ui->ledVH2TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH2TestChkBox_2_stateChanged); + connect(ui->ledVH3TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH3TestChkBox_2_stateChanged); + + connect(ui->openADCBtn_2, &QPushButton::clicked, this, &DebugTerminalDialog::on_openADCBtn_2_clicked); + +} + + + + +void DebugTerminalDialog::updateConnectionStatus(int boardID, bool connected) +{ + // Обновляем визуальное отображение статуса соединения + // Можно изменить цвет рамки или добавить индикатор + Q_UNUSED(boardID); + Q_UNUSED(connected); + // Реализация по необходимости +} + + +void DebugTerminalDialog::on_buttonBox_clicked(QAbstractButton *button) +{ + switch (ui->buttonBox->buttonRole(button)) { + case QDialogButtonBox::ResetRole: + resetAll(); + break; + case QDialogButtonBox::AcceptRole: + accept(); + break; + default: + break; + } +} +// Реализация слотов для вызова функций платы 1 +void DebugTerminalDialog::on_continiusCallChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_CONTINUOUS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_calibrateCallChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_CALIBRATE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_pollTECallChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_POLL_TE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetKeyCallChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_RESET_KEYS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetDefaultCallChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_RESET_DEFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_getHardfaultCallChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_HARDFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +// Реализация слотов для теста дискретных сигналов платы 1 +void DebugTerminalDialog::enableLedTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_TEST_ENABLE, state == Qt::Checked ? 1 : 0); + ui->leds_1->setEnabled(state); + ui->discs_1->setEnabled(state); +} + +void DebugTerminalDialog::on_discWorkTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_DISC_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discWarnTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_DISC_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErrTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_DISC_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErr24TestChkBox_1_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5TestChkBox_1_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VsciTestChkBox_1_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VATestChkBox_1_stateChanged(int state){Q_UNUSED(state)} + +// Реализация слотов для теста светодиодов платы 1 +void DebugTerminalDialog::on_ledWorkTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledWarnTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledErrTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledConnectTestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_CONNECT_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH1TestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_VH1_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH2TestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_VH2_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH3TestChkBox_1_stateChanged(int state) +{ + writeCoil(0, COIL_LED_VH3_TEST, state == Qt::Checked ? 1 : 0); +} + + + + + + +// Реализация слотов для вызова функций платы 2 +void DebugTerminalDialog::on_continiusCallChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_CONTINUOUS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_calibrateCallChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_CALIBRATE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_pollTECallChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_POLL_TE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetKeyCallChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_RESET_KEYS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetDefaultCallChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_RESET_DEFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_getHardfaultCallChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_HARDFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +// Реализация слотов для теста дискретных сигналов платы 2 +void DebugTerminalDialog::enableLedTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_TEST_ENABLE, state == Qt::Checked ? 1 : 0); + ui->leds_2->setEnabled(state); + ui->discs_2->setEnabled(state); +} + +void DebugTerminalDialog::on_discWorkTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_DISC_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discWarnTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_DISC_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErrTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_DISC_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErr24TestChkBox_2_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5TestChkBox_2_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VsciTestChkBox_2_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VATestChkBox_2_stateChanged(int state){Q_UNUSED(state)} + +// Реализация слотов для теста светодиодов платы 2 +void DebugTerminalDialog::on_ledWorkTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledWarnTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledErrTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledConnectTestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_CONNECT_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH1TestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_VH1_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH2TestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_VH2_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH3TestChkBox_2_stateChanged(int state) +{ + writeCoil(1, COIL_LED_VH3_TEST, state == Qt::Checked ? 1 : 0); +} + + + + + + + + + + +// Реализация слотов для вызова функций платы 3 +void DebugTerminalDialog::on_continiusCallChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_CONTINUOUS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_calibrateCallChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_CALIBRATE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_pollTECallChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_POLL_TE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetKeyCallChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_RESET_KEYS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetDefaultCallChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_RESET_DEFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_getHardfaultCallChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_HARDFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +// Реализация слотов для теста дискретных сигналов платы 3 +void DebugTerminalDialog::enableLedTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_TEST_ENABLE, state == Qt::Checked ? 1 : 0); + ui->leds_3->setEnabled(state); + ui->discs_3->setEnabled(state); +} + +void DebugTerminalDialog::on_discWorkTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_DISC_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discWarnTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_DISC_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErrTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_DISC_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErr24TestChkBox_3_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5TestChkBox_3_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VsciTestChkBox_3_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VATestChkBox_3_stateChanged(int state){Q_UNUSED(state)} + +// Реализация слотов для теста светодиодов платы 3 +void DebugTerminalDialog::on_ledWorkTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledWarnTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledErrTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledConnectTestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_CONNECT_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH1TestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_VH1_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH2TestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_VH2_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH3TestChkBox_3_stateChanged(int state) +{ + writeCoil(2, COIL_LED_VH3_TEST, state == Qt::Checked ? 1 : 0); +} + + + + + +// Реализация слотов для вызова функций платы 4 +void DebugTerminalDialog::on_continiusCallChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_CONTINUOUS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_calibrateCallChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_CALIBRATE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_pollTECallChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_POLL_TE_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetKeyCallChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_RESET_KEYS_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_resetDefaultCallChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_RESET_DEFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_getHardfaultCallChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_HARDFAULT_CALL, state == Qt::Checked ? 1 : 0); +} + +// Реализация слотов для теста дискретных сигналов платы 4 +void DebugTerminalDialog::enableLedTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_TEST_ENABLE, state == Qt::Checked ? 1 : 0); + ui->leds_4->setEnabled(state); + ui->discs_4->setEnabled(state); +} + +void DebugTerminalDialog::on_discWorkTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_DISC_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discWarnTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_DISC_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErrTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_DISC_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_discErr24TestChkBox_4_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5TestChkBox_4_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VsciTestChkBox_4_stateChanged(int state){Q_UNUSED(state)} + +void DebugTerminalDialog::on_discErr5VATestChkBox_4_stateChanged(int state){Q_UNUSED(state)} + +// Реализация слотов для теста светодиодов платы 4 +void DebugTerminalDialog::on_ledWorkTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_WORK_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledWarnTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_WARN_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledErrTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_ERR_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledConnectTestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_CONNECT_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH1TestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_VH1_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH2TestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_VH2_TEST, state == Qt::Checked ? 1 : 0); +} + +void DebugTerminalDialog::on_ledVH3TestChkBox_4_stateChanged(int state) +{ + writeCoil(3, COIL_LED_VH3_TEST, state == Qt::Checked ? 1 : 0); +} + + + + +void DebugTerminalDialog::openAdc(int boardID, int teNumber) +{ + writeTENumber(boardID, teNumber); + // Создаем/обновляем AdcGraphDialog + if (!m_adcGraphDialog) { + m_adcGraphDialog = new AdcGraphDialog(m_modbusDevice, this); + } else { + m_adcGraphDialog->setModbusDevice(m_modbusDevice); + } + + if (m_adcGraphDialog) { + m_adcGraphDialog->startGraph(boardID, teNumber); + m_adcGraphDialog->show(); + m_adcGraphDialog->raise(); // Поднять окно на передний план + m_adcGraphDialog->activateWindow(); // Активировать окно + } + +} +void DebugTerminalDialog::setGraphUpdateInterval(int milliseconds) +{ + if (m_adcGraphDialog) { + m_adcGraphDialog->setTimeout(milliseconds); + } +} + + +void DebugTerminalDialog::on_openADCBtn_1_clicked() +{ + openAdc(0, ui->debugTENumSpinBox_1->value()); +} + + +void DebugTerminalDialog::on_openADCBtn_2_clicked() +{ + openAdc(1, ui->debugTENumSpinBox_2->value()); +} + + + +void DebugTerminalDialog::on_openADCBtn_3_clicked() +{ + openAdc(2, ui->debugTENumSpinBox_3->value()); +} + + + +void DebugTerminalDialog::on_openADCBtn_4_clicked() +{ + openAdc(3, ui->debugTENumSpinBox_4->value()); +} + + +void DebugTerminalDialog::writeCoil(int boardID, int coil, int value) +{ + QGroupBox* boardGroup = nullptr; + switch(boardID) { + case 0: boardGroup = ui->DbgPlate_1; break; // Плата 1 + case 1: boardGroup = ui->DbgPlate_2; break; // Плата 2 + case 2: boardGroup = ui->DbgPlate_3; break; // Плата 3 + case 3: boardGroup = ui->DbgPlate_4; break; // Плата 4 + default: return; + } + + if(!boardGroup->isEnabled()) + return; + + qDebug() << "Writing board" << boardID << "coil:" << coil << "value:" << value; + emit coilValueChanged(boardID, coil, value); +} + +void DebugTerminalDialog::writeTENumber(int boardId, int teNumber) +{ + if (!m_modbusDevice) { + qDebug() << "Modbus device not available for writing TE number"; + return; + } + + qDebug() << "Writing TE number" << teNumber << "to board" << boardId << "register" << REGISTER_TE_NUMB; + + // Отправляем сигнал для записи регистра + emit writeRegister(boardId, REGISTER_TE_NUMB, teNumber); +} + + +void DebugTerminalDialog::setBoardActive(int boardID, bool active) +{ + // Получаем групбокс для указанной платы + QGroupBox* boardGroup = nullptr; + switch(boardID) { + case 0: boardGroup = ui->DbgPlate_1; break; // Плата 1 + case 1: boardGroup = ui->DbgPlate_2; break; // Плата 2 + case 2: boardGroup = ui->DbgPlate_3; break; // Плата 3 + case 3: boardGroup = ui->DbgPlate_4; break; // Плата 4 + default: return; + } + + if (boardGroup) { + boardGroup->setEnabled(active); + // Можно добавить визуальное отличие неактивных плат + if (!active) { + boardGroup->setStyleSheet("QGroupBox { color: gray; }"); + } else { + boardGroup->setStyleSheet(""); // Сброс стиля + } + } +} + +void DebugTerminalDialog::updateBoardStates(bool activeBoards[4]) +{ + for (int i = 0; i < 4; i++) { + setBoardActive(i, activeBoards[i]); + } +} + +void DebugTerminalDialog::resetAll() +{ + // Сброс всех чекбоксов вызова функций + ui->continiusCallChkBox_1->setChecked(false); + ui->calibrateCallChkBox_1->setChecked(false); + ui->pollTECallChkBox_1->setChecked(false); + ui->resetKeyCallChkBox_1->setChecked(false); + ui->resetDefaultCallChkBox_1->setChecked(false); + ui->getHardfaultCallChkBox_1->setChecked(false); + + ui->enableLedTestChkBox_1->setChecked(false); + ui->leds_1->setEnabled(false); + ui->discs_1->setEnabled(false); + + ui->discWorkTestChkBox_1->setChecked(false); + // Сброс всех чекбоксов теста дискретных сигналов + ui->discWorkTestChkBox_1->setChecked(false); + ui->discWarnTestChkBox_1->setChecked(false); + ui->discErrTestChkBox_1->setChecked(false); + + // Сброс всех чекбоксов теста светодиодов + ui->ledWorkTestChkBox_1->setChecked(false); + ui->ledWarnTestChkBox_1->setChecked(false); + ui->ledErrTestChkBox_1->setChecked(false); + ui->ledConnectTestChkBox_1->setChecked(false); + ui->ledVH1TestChkBox_1->setChecked(false); + ui->ledVH2TestChkBox_1->setChecked(false); + ui->ledVH3TestChkBox_1->setChecked(false); + + // Сброс спинбоксов ТЭ + ui->debugTENumSpinBox_1->setValue(0); + + + + + + + + // Сброс всех чекбоксов вызова функций + ui->continiusCallChkBox_2->setChecked(false); + ui->calibrateCallChkBox_2->setChecked(false); + ui->pollTECallChkBox_2->setChecked(false); + ui->resetKeyCallChkBox_2->setChecked(false); + ui->resetDefaultCallChkBox_2->setChecked(false); + ui->getHardfaultCallChkBox_2->setChecked(false); + + ui->enableLedTestChkBox_2->setChecked(false); + ui->leds_2->setEnabled(false); + ui->discs_2->setEnabled(false); + + ui->discWorkTestChkBox_2->setChecked(false); + // Сброс всех чекбоксов теста дискретных сигналов + ui->discWorkTestChkBox_2->setChecked(false); + ui->discWarnTestChkBox_2->setChecked(false); + ui->discErrTestChkBox_2->setChecked(false); + + // Сброс всех чекбоксов теста светодиодов + ui->ledWorkTestChkBox_2->setChecked(false); + ui->ledWarnTestChkBox_2->setChecked(false); + ui->ledErrTestChkBox_2->setChecked(false); + ui->ledConnectTestChkBox_2->setChecked(false); + ui->ledVH1TestChkBox_2->setChecked(false); + ui->ledVH2TestChkBox_2->setChecked(false); + ui->ledVH3TestChkBox_2->setChecked(false); + + // Сброс спинбоксов ТЭ + ui->debugTENumSpinBox_2->setValue(0); + + + + + + // Сброс всех чекбоксов вызова функций + ui->continiusCallChkBox_3->setChecked(false); + ui->calibrateCallChkBox_3->setChecked(false); + ui->pollTECallChkBox_3->setChecked(false); + ui->resetKeyCallChkBox_3->setChecked(false); + ui->resetDefaultCallChkBox_3->setChecked(false); + ui->getHardfaultCallChkBox_3->setChecked(false); + + ui->enableLedTestChkBox_3->setChecked(false); + ui->leds_3->setEnabled(false); + ui->discs_3->setEnabled(false); + + ui->discWorkTestChkBox_3->setChecked(false); + // Сброс всех чекбоксов теста дискретных сигналов + ui->discWorkTestChkBox_3->setChecked(false); + ui->discWarnTestChkBox_3->setChecked(false); + ui->discErrTestChkBox_3->setChecked(false); + + // Сброс всех чекбоксов теста светодиодов + ui->ledWorkTestChkBox_3->setChecked(false); + ui->ledWarnTestChkBox_3->setChecked(false); + ui->ledErrTestChkBox_3->setChecked(false); + ui->ledConnectTestChkBox_3->setChecked(false); + ui->ledVH1TestChkBox_3->setChecked(false); + ui->ledVH2TestChkBox_3->setChecked(false); + ui->ledVH3TestChkBox_3->setChecked(false); + + // Сброс спинбоксов ТЭ + ui->debugTENumSpinBox_3->setValue(0); + + + + + + + + + // Сброс всех чекбоксов вызова функций + ui->continiusCallChkBox_4->setChecked(false); + ui->calibrateCallChkBox_4->setChecked(false); + ui->pollTECallChkBox_4->setChecked(false); + ui->resetKeyCallChkBox_4->setChecked(false); + ui->resetDefaultCallChkBox_4->setChecked(false); + ui->getHardfaultCallChkBox_4->setChecked(false); + + ui->enableLedTestChkBox_4->setChecked(false); + ui->leds_4->setEnabled(false); + ui->discs_4->setEnabled(false); + + ui->discWorkTestChkBox_4->setChecked(false); + // Сброс всех чекбоксов теста дискретных сигналов + ui->discWorkTestChkBox_4->setChecked(false); + ui->discWarnTestChkBox_4->setChecked(false); + ui->discErrTestChkBox_4->setChecked(false); + + // Сброс всех чекбоксов теста светодиодов + ui->ledWorkTestChkBox_4->setChecked(false); + ui->ledWarnTestChkBox_4->setChecked(false); + ui->ledErrTestChkBox_4->setChecked(false); + ui->ledConnectTestChkBox_4->setChecked(false); + ui->ledVH1TestChkBox_4->setChecked(false); + ui->ledVH2TestChkBox_4->setChecked(false); + ui->ledVH3TestChkBox_4->setChecked(false); + + // Сброс спинбоксов ТЭ + ui->debugTENumSpinBox_4->setValue(0); +} diff --git a/M3KTE_TERM/debugterminaldialog.h b/M3KTE_TERM/debugterminaldialog.h new file mode 100644 index 0000000..e44e7d1 --- /dev/null +++ b/M3KTE_TERM/debugterminaldialog.h @@ -0,0 +1,224 @@ +#ifndef DEBUGTERMINALDIALOG_H +#define DEBUGTERMINALDIALOG_H + +#include +#include +#include + +// Forward declarations вместо include +class M3KTE; +class AdcGraphDialog; + +// Дефайны для адресов коилов +#define COIL_DEBUG_MODE 555 + +#define COIL_CONTINUOUS_CALL 571 +#define COIL_CALIBRATE_CALL 572 +#define COIL_POLL_TE_CALL 573 +#define COIL_RESET_KEYS_CALL 574 +#define COIL_RESET_DEFAULT_CALL 576 +#define COIL_HARDFAULT_CALL 586 + +#define COIL_LED_TEST_ENABLE 587 + +// Тест дискретных сигналов +#define COIL_DISC_WORK_TEST 588 +#define COIL_DISC_WARN_TEST 589 +#define COIL_DISC_ERR_TEST 590 + +// Тест светодиодов +#define COIL_LED_CONNECT_TEST 591 +#define COIL_LED_WORK_TEST 592 +#define COIL_LED_WARN_TEST 593 +#define COIL_LED_ERR_TEST 594 +#define COIL_LED_VH1_TEST 595 +#define COIL_LED_VH2_TEST 596 +#define COIL_LED_VH3_TEST 597 + +// Адреса для чтения состояний ошибок питания +#define COIL_READ_ERR_24V 600 // Чтение ошибки 24В +#define COIL_READ_ERR_5V 601 // Чтение ошибки 5В +#define COIL_READ_ERR_5VSCI 602 // Чтение ошибки 5Vsci +#define COIL_READ_ERR_5VA 603 // Чтение ошибки 5VA + +#define REGISTER_TE_NUMB 564 + + + +namespace Ui { +class DebugTerminalDialog; +} + +class DebugTerminalDialog : public QDialog +{ + Q_OBJECT + +public: + explicit DebugTerminalDialog(QWidget *parent = nullptr); + ~DebugTerminalDialog(); + void updateConnectionStatus(int boardId, bool connected); + void setBoardActive(int boardId, bool active); + void updateBoardStates(bool activeBoards[4]); + void setModbusDevice(QModbusClient *device); + void setGraphUpdateInterval(int milliseconds); + +protected: + void showEvent(QShowEvent *event) override; + void closeEvent(QCloseEvent *event) override; + +private slots: + void on_buttonBox_clicked(QAbstractButton *button); + +// // Слоты для вызова функций +// void onFunctionCallChanged(int boardId, int coil, bool state); + +// // Слоты для теста дискретных сигналов +// void onDiscreteTestChanged(int boardId, int coil, bool state); + +// // Слоты для теста светодиодов +// void onLedTestChanged(int boardId, int coil, bool state); + +// // Слоты для ADC +// void onOpenADCGraphClicked(int boardId); + + // Плата 1 + void on_continiusCallChkBox_1_stateChanged(int state); + void on_calibrateCallChkBox_1_stateChanged(int state); + void on_pollTECallChkBox_1_stateChanged(int state); + void on_resetKeyCallChkBox_1_stateChanged(int state); + void on_resetDefaultCallChkBox_1_stateChanged(int state); + void on_getHardfaultCallChkBox_1_stateChanged(int state); + + void enableLedTestChkBox_1_stateChanged(int state); + + void on_discWorkTestChkBox_1_stateChanged(int state); + void on_discWarnTestChkBox_1_stateChanged(int state); + void on_discErrTestChkBox_1_stateChanged(int state); + void on_discErr24TestChkBox_1_stateChanged(int state); + void on_discErr5TestChkBox_1_stateChanged(int state); + void on_discErr5VsciTestChkBox_1_stateChanged(int state); + void on_discErr5VATestChkBox_1_stateChanged(int state); + + void on_ledWorkTestChkBox_1_stateChanged(int state); + void on_ledWarnTestChkBox_1_stateChanged(int state); + void on_ledErrTestChkBox_1_stateChanged(int state); + void on_ledConnectTestChkBox_1_stateChanged(int state); + void on_ledVH1TestChkBox_1_stateChanged(int state); + void on_ledVH2TestChkBox_1_stateChanged(int state); + void on_ledVH3TestChkBox_1_stateChanged(int state); + + void on_openADCBtn_1_clicked(); + + // Плата 2 + void on_continiusCallChkBox_2_stateChanged(int state); + void on_calibrateCallChkBox_2_stateChanged(int state); + void on_pollTECallChkBox_2_stateChanged(int state); + void on_resetKeyCallChkBox_2_stateChanged(int state); + void on_resetDefaultCallChkBox_2_stateChanged(int state); + void on_getHardfaultCallChkBox_2_stateChanged(int state); + + void enableLedTestChkBox_2_stateChanged(int state); + + void on_discWorkTestChkBox_2_stateChanged(int state); + void on_discWarnTestChkBox_2_stateChanged(int state); + void on_discErrTestChkBox_2_stateChanged(int state); + void on_discErr24TestChkBox_2_stateChanged(int state); + void on_discErr5TestChkBox_2_stateChanged(int state); + void on_discErr5VsciTestChkBox_2_stateChanged(int state); + void on_discErr5VATestChkBox_2_stateChanged(int state); + + void on_ledWorkTestChkBox_2_stateChanged(int state); + void on_ledWarnTestChkBox_2_stateChanged(int state); + void on_ledErrTestChkBox_2_stateChanged(int state); + void on_ledConnectTestChkBox_2_stateChanged(int state); + void on_ledVH1TestChkBox_2_stateChanged(int state); + void on_ledVH2TestChkBox_2_stateChanged(int state); + void on_ledVH3TestChkBox_2_stateChanged(int state); + + void on_openADCBtn_2_clicked(); + + + // Плата 3 + void on_continiusCallChkBox_3_stateChanged(int state); + void on_calibrateCallChkBox_3_stateChanged(int state); + void on_pollTECallChkBox_3_stateChanged(int state); + void on_resetKeyCallChkBox_3_stateChanged(int state); + void on_resetDefaultCallChkBox_3_stateChanged(int state); + void on_getHardfaultCallChkBox_3_stateChanged(int state); + + void enableLedTestChkBox_3_stateChanged(int state); + + void on_discWorkTestChkBox_3_stateChanged(int state); + void on_discWarnTestChkBox_3_stateChanged(int state); + void on_discErrTestChkBox_3_stateChanged(int state); + void on_discErr24TestChkBox_3_stateChanged(int state); + void on_discErr5TestChkBox_3_stateChanged(int state); + void on_discErr5VsciTestChkBox_3_stateChanged(int state); + void on_discErr5VATestChkBox_3_stateChanged(int state); + + void on_ledWorkTestChkBox_3_stateChanged(int state); + void on_ledWarnTestChkBox_3_stateChanged(int state); + void on_ledErrTestChkBox_3_stateChanged(int state); + void on_ledConnectTestChkBox_3_stateChanged(int state); + void on_ledVH1TestChkBox_3_stateChanged(int state); + void on_ledVH2TestChkBox_3_stateChanged(int state); + void on_ledVH3TestChkBox_3_stateChanged(int state); + + void on_openADCBtn_3_clicked(); + + // Плата 4 + void on_continiusCallChkBox_4_stateChanged(int state); + void on_calibrateCallChkBox_4_stateChanged(int state); + void on_pollTECallChkBox_4_stateChanged(int state); + void on_resetKeyCallChkBox_4_stateChanged(int state); + void on_resetDefaultCallChkBox_4_stateChanged(int state); + void on_getHardfaultCallChkBox_4_stateChanged(int state); + + void enableLedTestChkBox_4_stateChanged(int state); + + void on_discWorkTestChkBox_4_stateChanged(int state); + void on_discWarnTestChkBox_4_stateChanged(int state); + void on_discErrTestChkBox_4_stateChanged(int state); + void on_discErr24TestChkBox_4_stateChanged(int state); + void on_discErr5TestChkBox_4_stateChanged(int state); + void on_discErr5VsciTestChkBox_4_stateChanged(int state); + void on_discErr5VATestChkBox_4_stateChanged(int state); + + void on_ledWorkTestChkBox_4_stateChanged(int state); + void on_ledWarnTestChkBox_4_stateChanged(int state); + void on_ledErrTestChkBox_4_stateChanged(int state); + void on_ledConnectTestChkBox_4_stateChanged(int state); + void on_ledVH1TestChkBox_4_stateChanged(int state); + void on_ledVH2TestChkBox_4_stateChanged(int state); + void on_ledVH3TestChkBox_4_stateChanged(int state); + + void on_openADCBtn_4_clicked(); + + +signals: + void coilValueChanged(int boardID, int coil, int value); + void writeRegister(int boardID, int reg, int value); + +private: + Ui::DebugTerminalDialog *ui; + AdcGraphDialog *m_adcGraphDialog; + QModbusClient *m_modbusDevice; // Храним указатель здесь + + // Карты для хранения состояний + QMap m_functionCalls; // boardId -> coil -> state + QMap m_discreteTests; // boardId -> coil -> state + QMap m_ledTests; // boardId -> coil -> state + + // Номера ТЭ для каждой платы + int m_teNumbers[4] = {0, 0, 0, 0}; + + void initializeConnections(); + + void writeTENumber(int boardId, int teNumber); + void openAdc(int boardID, int teNumber); + void writeCoil(int boardID, int coil, int value); + void readCoil(int coil); + void resetAll(); +}; + +#endif // DEBUGTERMINALDIALOG_H diff --git a/M3KTE_TERM/m3kte.cpp b/M3KTE_TERM/m3kte.cpp index f3020d7..06827d9 100644 --- a/M3KTE_TERM/m3kte.cpp +++ b/M3KTE_TERM/m3kte.cpp @@ -16,6 +16,7 @@ #include #include #include +#include QWidget* init(QWidget *parent) { @@ -366,8 +367,10 @@ M3KTE::M3KTE(QWidget *parent) Boards[i].ModbusModelHoldingReg->setNumberOfValues(QString::number(85-(i/4*20))); } m_deviceSettingsDialog = new DeviceSettingsDialog(this); + m_debugTerminalDialog = new DebugTerminalDialog(this); m_regMultipleSettings = new MultipleSettings(this); modbusDevice = new QModbusRtuSerialMaster(this); + m_debugTerminalDialog->setModbusDevice(modbusDevice); m_lineRinger = new LineRinger(); Boards[0].boardScanners = new QTimer(); Boards[1].boardScanners = new QTimer(); @@ -395,6 +398,9 @@ M3KTE::M3KTE(QWidget *parent) Boards[2].adr = 3; Boards[3].adr = 4; } + bool activeBoards[4] = {false, false, false, false}; + m_debugTerminalDialog->updateBoardStates(activeBoards); + ui->M3kteRegSettings->setEnabled(false); ui->BSM_Warning->setEnabled(false); ui->BSM_Accident->setEnabled(false); @@ -532,6 +538,12 @@ void M3KTE::initActions() this, &M3KTE::onSelectedBoardChanged); connect(ui->writeTable, QOverload::of(&QComboBox::currentIndexChanged), this, &M3KTE::onWriteTableChanged); + connect(ui->DebugTerm, &QAction::triggered, m_debugTerminalDialog, &QWidget::show); + connect(m_debugTerminalDialog, &DebugTerminalDialog::coilValueChanged, + this, &M3KTE::writeSingleCoil); + connect(m_debugTerminalDialog, &DebugTerminalDialog::writeRegister, + this, &M3KTE::writeSingleRegister); + connect(ui->LineCall, &QAction::triggered, m_lineRinger, &QWidget::show); connect(ui->M3kteRegSettings, &QAction::triggered, m_regMultipleSettings, &QDialog::show); connect(m_regMultipleSettings, &MultipleSettings::write, this, &M3KTE::slotmultipleRegWrite); @@ -600,7 +612,8 @@ void M3KTE::onConnectClicked() ActiveDevices[i] = Boards[i].isActive; } ui->M3kteRegSettings->setEnabled(true); - m_deviceSettingsDialog->updateSettingsAfterConnection(m_settingsDialog->settings().baud, m_settingsDialog->settings().parity, tmp_adr, ActiveDevices); + m_deviceSettingsDialog->updateSettingsAfterConnection(m_settingsDialog->settings().baud, m_settingsDialog->settings().parity, tmp_adr, ActiveDevices); + m_debugTerminalDialog->updateBoardStates(ActiveDevices); ui->boardSelectBox->setCurrentIndex(0); ui->writeTable->setCurrentIndex(0); changeTable(0, 0); @@ -1199,6 +1212,7 @@ bool M3KTE::pingNetworkDevices() int tmp_adr = 1; bool isRun = false; bool *tmp_isRun = &isRun; + auto bar = new QProgressDialog(this); connect(bar, &QProgressDialog::canceled, this, [tmp_isRun]() { *tmp_isRun = true; @@ -1778,6 +1792,58 @@ void M3KTE::multipleRegWrite() } } +void M3KTE::writeSingleCoil(int boardId, int coilAddress, bool value) +{ + if (!modbusDevice || !Boards[boardId].isActive) + return; + + QModbusDataUnit unit(QModbusDataUnit::Coils, coilAddress, 1); + unit.setValue(0, value ? 1 : 0); + + if (auto *reply = modbusDevice->sendWriteRequest(unit, Boards[boardId].adr)) { + if (!reply->isFinished()) { + connect(reply, &QModbusReply::finished, this, [this, boardId, reply]() { + if (reply->error() != QModbusDevice::NoError) { + logError(tr("Плата %1 (ID %2)").arg(boardId+1).arg(Boards[boardId].adr), + reply->errorString(), ++Boards[boardId].error_TX, + "Single coil write"); + } + reply->deleteLater(); + }); + } else { + reply->deleteLater(); + } + } +} + +void M3KTE::writeSingleRegister(int boardID, int regAddress, quint16 value) +{ + if (!modbusDevice || !Boards[boardID].isActive) + return; + + m_debugTerminalDialog->setGraphUpdateInterval(m_deviceSettingsDialog->currentBoardTimer(boardID)); + + QModbusDataUnit unit(QModbusDataUnit::HoldingRegisters, regAddress, 1); + unit.setValue(0, value); + + if (auto *reply = modbusDevice->sendWriteRequest(unit, Boards[boardID].adr)) { + if (!reply->isFinished()) { + connect(reply, &QModbusReply::finished, this, [this, boardID, reply]() { + if (reply->error() != QModbusDevice::NoError) { + logError(tr("Плата %1 (ID %2)").arg(boardID+1).arg(Boards[boardID].adr), + reply->errorString(), ++Boards[boardID].error_TX, + "Single register write"); + } + reply->deleteLater(); + }); + } else { + reply->deleteLater(); + } + } +} + + + void M3KTE::selectPositionOnTree(unsigned int index) { ui->boardSelectBox->setCurrentIndex(index/85); diff --git a/M3KTE_TERM/m3kte.h b/M3KTE_TERM/m3kte.h index 4c7d789..d3a2a6b 100644 --- a/M3KTE_TERM/m3kte.h +++ b/M3KTE_TERM/m3kte.h @@ -7,6 +7,7 @@ #include #include "writeregistermodel.h" +#include "debugterminaldialog.h" #include "devicesettingsdialog.h" #include "multiplesettings.h" #include "scanboard.h" @@ -63,6 +64,8 @@ private: void applySettingsFromScan(QModbusReply *reply); void multipleRegWrite(); void multipleRegSend(); + void writeSingleCoil(int boardId, int coilAddress, bool value); + void writeSingleRegister(int boardId, int regAddress, quint16 value); bool autoBaudRateScan(); void selectPositionOnTree(unsigned index); signals: @@ -88,6 +91,7 @@ private slots: public: M3KTE(QWidget *parent = nullptr); ~M3KTE(); + QModbusClient* getModbusDevice() const { return modbusDevice; } private: Ui::M3KTE *ui; QTableWidget *loggerTable = nullptr; @@ -97,6 +101,7 @@ private: QModbusReply *lastRequest = nullptr; QModbusClient *modbusDevice = nullptr; DeviceSettingsDialog *m_deviceSettingsDialog = nullptr; + DebugTerminalDialog *m_debugTerminalDialog = nullptr; SettingsDialog *m_settingsDialog = nullptr; MultipleSettings *m_regMultipleSettings = nullptr; ScanBoard *m_scanBoard = nullptr; diff --git a/M3KTE_TERM/m3kte.ui b/M3KTE_TERM/m3kte.ui index 626a393..e01713b 100644 --- a/M3KTE_TERM/m3kte.ui +++ b/M3KTE_TERM/m3kte.ui @@ -7,7 +7,7 @@ 0 0 961 - 761 + 765 @@ -14644,9 +14644,16 @@ + + + Отладка + + + + @@ -14679,6 +14686,11 @@ Опрос линии + + + Открыть + +