#ifndef FAST_DDS_GENERATED__PUBLISHERAPP_HPP #define FAST_DDS_GENERATED__PUBLISHERAPP_HPP #include #include #include #include #include #include #include #include "MsgHandler.hpp" class PublisherApp : public eprosima::fastdds::dds::DataWriterListener,public eprosima::fastdds::dds::DataReaderListener { public: PublisherApp( const int& domain_id); ~PublisherApp(); //! Publisher matched method void on_publication_matched( eprosima::fastdds::dds::DataWriter* writer, const eprosima::fastdds::dds::PublicationMatchedStatus& info) override; //! Run publisher void run(std::shared_ptr handler); //! Trigger the end of execution void stop(); 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 PublishSummaryUpdate(const std::string& cardId, float weightTon); //void CheckAndPublishSummary(); void CheckAndPublishSummary(std::shared_ptr handler); void RestoreAutoFind(); private: //! Return the current state of execution bool is_stopped(); bool is_infrared_blocked(); // ← 新增这一行 bool has_pending_send(); // ← 新增这一行(可选,统一判断) std::shared_ptr factory_; eprosima::fastdds::dds::DomainParticipant* participant_; eprosima::fastdds::dds::Publisher* publisher_; eprosima::fastdds::dds::Topic* topic_; eprosima::fastdds::dds::DataWriter* writer_; eprosima::fastdds::dds::TypeSupport type_; std::condition_variable cv_; int32_t matched_; std::mutex mutex_; const uint32_t period_ms_ = 100; uint16_t samples_sent_; std::atomic stop_; // ── SummaryUpdate 发布者 ── eprosima::fastdds::dds::Publisher* summary_publisher_; eprosima::fastdds::dds::Topic* summary_topic_; eprosima::fastdds::dds::DataWriter* summary_writer_; eprosima::fastdds::dds::TypeSupport summary_type_; // ── ScaleInfo 订阅者 ── eprosima::fastdds::dds::Subscriber* scale_subscriber_; eprosima::fastdds::dds::Topic* scale_topic_; eprosima::fastdds::dds::DataReader* scale_reader_; eprosima::fastdds::dds::TypeSupport scale_type_; // ── 新增:等待重量用的状态变量 ── float stable_weight_ = 0.0f; bool has_weight_ = false; float default_weight_ = 0.0f; // 默认重量(当没有稳定重量时使用) // ── InfraredUpdate 订阅者 ── eprosima::fastdds::dds::Subscriber* infrared_subscriber_; eprosima::fastdds::dds::Topic* infrared_topic_; eprosima::fastdds::dds::DataReader* infrared_reader_; eprosima::fastdds::dds::TypeSupport infrared_type_; // ── 最新红外状态缓存 ── bool front_blocked_ = false; // 前红外当前是否被遮挡 bool back_blocked_ = false; // 后红外当前是否被遮挡 std::mutex infrared_mtx_; // ── 用于在 on_data_available 里区分 reader 的 topic ── ← 新增 std::mutex reader_topic_mtx_; std::string scale_topic_name_; std::string infrared_topic_name_; bool write_test_done_ = false; // 写卡测试是否完成 bool write_test_started_ = false; // 是否已经开始写卡测试 bool write_read_pending_ = false; // 写入完成后,等待再次刷卡验证的标志 // 新增:保留历史重量帧(跨循环累积) std::vector recentValues_; const size_t MAX_RECENT_FRAMES_ = 10; // 用于 SummaryUpdate 发布 bool summary_pending_; std::string pending_card_id_; std::mutex summary_mtx_; std::condition_variable summary_cv_; }; #endif // FAST_DDS_GENERATED__PUBLISHERAPP_HPP