XNSim/XNMonitor/ModelTopicMonitor/GroundHandlingMonitor.cpp
2025-04-28 12:25:20 +08:00

97 lines
3.0 KiB
C++
Executable File

/**
* @file GroundHandlingMonitor.cpp
* @author jinchao
* @brief 地操模型主题监控类实现
* @version 1.0
* @date 2025-03-10
*
* @copyright Copyright (c) 2025 COMAC
*
*/
#include "GroundHandlingMonitor.h"
#include "../TopicManager/TopicManager.h"
#include <QDebug>
#include <QVariant>
GroundHandlingMonitor::GroundHandlingMonitor(QObject *parent) : TopicMonitor(parent)
{
//初始化输入接口
inputInterface = new XNSim::ATA04::GroundHandling_input_Interface(this);
//初始化输出接口
outputInterface = new XNSim::ATA04::GroundHandling_output_Interface(this);
//初始化心跳接口
heartbeatInterface = new XNSim::ATA04::GroundHandling_heartbeat_Interface(this);
}
GroundHandlingMonitor::~GroundHandlingMonitor()
{
//释放输入接口
if (inputInterface)
delete inputInterface;
//释放输出接口
if (outputInterface)
delete outputInterface;
//释放心跳接口
if (heartbeatInterface)
delete heartbeatInterface;
}
bool GroundHandlingMonitor::startMonitoring(const QString &topicName)
{
if (topicName == "XNSim::ATA04::GroundHandling_input") {
//注册输入主题订阅
TopicManager::Instance()->registerSubscriber<XNSim::ATA04::GroundHandling_inputPubSubType>(
topicName, std::bind(&XNSim::ATA04::GroundHandling_input_Interface::inputDataListener,
inputInterface, std::placeholders::_1));
m_MonitorStatus[topicName] = 1;
return true;
} else if (topicName == "XNSim::ATA04::GroundHandling_output") {
//注册输出主题订阅
TopicManager::Instance()->registerSubscriber<XNSim::ATA04::GroundHandling_outputPubSubType>(
topicName, std::bind(&XNSim::ATA04::GroundHandling_output_Interface::outputDataListener,
outputInterface, std::placeholders::_1));
m_MonitorStatus[topicName] = 1;
return true;
} else if (topicName == "XNSim::ATA04::GroundHandling_heartbeat") {
//注册心跳主题订阅
TopicManager::Instance()
->registerSubscriber<XNSim::ATA04::GroundHandling_heartbeatPubSubType>(
topicName,
std::bind(&XNSim::ATA04::GroundHandling_heartbeat_Interface::heartbeatListener,
heartbeatInterface, std::placeholders::_1));
m_MonitorStatus[topicName] = 1;
return true;
}
return false;
}
void GroundHandlingMonitor::stopMonitoring(const QString &topicName)
{
if (m_MonitorStatus.contains(topicName)) {
//注销主题订阅
TopicManager::Instance()->unregisterSubscriber(topicName);
//更新监控状态
m_MonitorStatus[topicName] = 0;
}
}
QString GroundHandlingMonitor::getData(const QString &topicName, const QString &varName)
{
if (topicName == "XNSim::ATA04::GroundHandling_input") {
//获取输入数据
return inputInterface->getData(varName);
} else if (topicName == "XNSim::ATA04::GroundHandling_output") {
//获取输出数据
return outputInterface->getData(varName);
} else if (topicName == "XNSim::ATA04::GroundHandling_heartbeat") {
//获取心跳数据
return heartbeatInterface->getData(varName);
}
return QString();
}
bool GroundHandlingMonitor::injectData(const QString &varName, double value)
{
return true;
}