You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
#ifndef WEIGHUI_DDS_SUBSCRIBER_HPP
|
|
#define WEIGHUI_DDS_SUBSCRIBER_HPP
|
|
|
|
#include <atomic>
|
|
#include <condition_variable>
|
|
#include <memory>
|
|
#include <mutex>
|
|
|
|
#include <fastdds/dds/domain/DomainParticipant.hpp>
|
|
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
|
|
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
|
|
#include <fastdds/dds/topic/TypeSupport.hpp>
|
|
|
|
#include "WeighingDDSTypePubSubTypes.hpp"
|
|
|
|
class DdsSubscriberApp : public eprosima::fastdds::dds::DataReaderListener
|
|
{
|
|
public:
|
|
DdsSubscriberApp(const int& domain_id);
|
|
virtual ~DdsSubscriberApp();
|
|
|
|
void on_data_available(eprosima::fastdds::dds::DataReader* reader) override;
|
|
void on_subscription_matched(
|
|
eprosima::fastdds::dds::DataReader* reader,
|
|
const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override;
|
|
|
|
void run();
|
|
void stop();
|
|
|
|
private:
|
|
bool is_stopped();
|
|
|
|
std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
|
|
eprosima::fastdds::dds::DomainParticipant* participant_;
|
|
eprosima::fastdds::dds::Subscriber* subscriber_;
|
|
|
|
eprosima::fastdds::dds::Topic* weightinfook_topic_;
|
|
eprosima::fastdds::dds::DataReader* weightinfook_reader_;
|
|
eprosima::fastdds::dds::TypeSupport weightinfook_type_;
|
|
|
|
// WeightInfoError 主题订阅 (Warning 主题, 弹窗样式与 WeightInfoOk 完全一致)
|
|
eprosima::fastdds::dds::Topic* weightinfoerror_topic_;
|
|
eprosima::fastdds::dds::DataReader* weightinfoerror_reader_;
|
|
eprosima::fastdds::dds::TypeSupport weightinfoerror_type_;
|
|
|
|
eprosima::fastdds::dds::Topic* summary_topic_;
|
|
eprosima::fastdds::dds::DataReader* summary_reader_;
|
|
eprosima::fastdds::dds::TypeSupport summary_type_;
|
|
|
|
// 实时重量 (weigh 程序发布)
|
|
eprosima::fastdds::dds::Topic* scaleinfo_topic_;
|
|
eprosima::fastdds::dds::DataReader* scaleinfo_reader_;
|
|
eprosima::fastdds::dds::TypeSupport scaleinfo_type_;
|
|
|
|
std::atomic<bool> stop_;
|
|
uint32_t period_ms_ = 100;
|
|
mutable std::mutex terminate_cv_mtx_;
|
|
std::condition_variable terminate_cv_;
|
|
};
|
|
|
|
#endif |