99 lines
3.1 KiB
C++
Executable File
99 lines
3.1 KiB
C++
Executable File
/**
|
|
* @file WeightBalanceMonitor.cpp
|
|
* @author jinchao
|
|
* @brief 质量模型主题监控类实现
|
|
* @version 1.0
|
|
* @date 2025-03-10
|
|
*
|
|
* @copyright Copyright (c) 2025 COMAC
|
|
*
|
|
*/
|
|
#include "WeightBalanceMonitor.h"
|
|
#include "../TopicManager/TopicManager.h"
|
|
#include <QDebug>
|
|
#include <QVariant>
|
|
|
|
WeightBalanceMonitor::WeightBalanceMonitor(QObject *parent) : TopicMonitor(parent)
|
|
{
|
|
//初始化输入接口
|
|
inputInterface = new XNSim::ATA04::WeightBalance_input_Interface();
|
|
//初始化输出接口
|
|
outputInterface = new XNSim::ATA04::WeightBalance_output_Interface();
|
|
//初始化心跳接口
|
|
heartbeatInterface = new XNSim::ATA04::WeightBalance_heartbeat_Interface();
|
|
}
|
|
|
|
WeightBalanceMonitor::~WeightBalanceMonitor()
|
|
{
|
|
//释放输入接口
|
|
if (inputInterface)
|
|
delete inputInterface;
|
|
//释放输出接口
|
|
if (outputInterface)
|
|
delete outputInterface;
|
|
//释放心跳接口
|
|
if (heartbeatInterface)
|
|
delete heartbeatInterface;
|
|
}
|
|
|
|
bool WeightBalanceMonitor::startMonitoring(const QString &topicName)
|
|
{
|
|
if (topicName == "XNSim::ATA04::WeightBalance_input") {
|
|
//注册输入主题订阅
|
|
TopicManager::Instance()->registerSubscriber<XNSim::ATA04::WeightBalance_inputPubSubType>(
|
|
"XNSim::ATA04::WeightBalance_input",
|
|
std::bind(&XNSim::ATA04::WeightBalance_input_Interface::inputDataListener,
|
|
inputInterface, std::placeholders::_1));
|
|
m_MonitorStatus["XNSim::ATA04::WeightBalance_input"] = 1;
|
|
return true;
|
|
} else if (topicName == "XNSim::ATA04::WeightBalance_output") {
|
|
//注册输出主题订阅
|
|
TopicManager::Instance()->registerSubscriber<XNSim::ATA04::WeightBalance_outputPubSubType>(
|
|
"XNSim::ATA04::WeightBalance_output",
|
|
std::bind(&XNSim::ATA04::WeightBalance_output_Interface::outputDataListener,
|
|
outputInterface, std::placeholders::_1));
|
|
m_MonitorStatus["XNSim::ATA04::WeightBalance_output"] = 1;
|
|
return true;
|
|
} else if (topicName == "XNSim::ATA04::WeightBalance_heartbeat") {
|
|
//注册心跳主题订阅
|
|
TopicManager::Instance()
|
|
->registerSubscriber<XNSim::ATA04::WeightBalance_heartbeatPubSubType>(
|
|
"XNSim::ATA04::WeightBalance_heartbeat",
|
|
std::bind(&XNSim::ATA04::WeightBalance_heartbeat_Interface::heartbeatListener,
|
|
heartbeatInterface, std::placeholders::_1));
|
|
m_MonitorStatus["XNSim::ATA04::WeightBalance_heartbeat"] = 1;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void WeightBalanceMonitor::stopMonitoring(const QString &topicName)
|
|
{
|
|
if (m_MonitorStatus.contains(topicName)) {
|
|
//注销主题订阅
|
|
TopicManager::Instance()->unregisterSubscriber(topicName);
|
|
//更新监控状态
|
|
m_MonitorStatus[topicName] = 0;
|
|
}
|
|
}
|
|
|
|
bool WeightBalanceMonitor::injectData(const QString &varName, double value)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
QString WeightBalanceMonitor::getData(const QString &topicName, const QString &varName)
|
|
{
|
|
if (topicName == "XNSim::ATA04::WeightBalance_input") {
|
|
//获取输入数据
|
|
return inputInterface->getData(varName);
|
|
} else if (topicName == "XNSim::ATA04::WeightBalance_output") {
|
|
//获取输出数据
|
|
return outputInterface->getData(varName);
|
|
} else if (topicName == "XNSim::ATA04::WeightBalance_heartbeat") {
|
|
//获取心跳数据
|
|
return heartbeatInterface->getData(varName);
|
|
}
|
|
return QString();
|
|
}
|