diff --git a/CMakeLists.txt b/CMakeLists.txt index 577a581..e37f32c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,17 +44,20 @@ target_link_libraries(System_lib fastcdr fastdds) # ) # Core Application. +set(PROGRAM_MODULE "Core") add_executable(Core core/main.cxx core/Publisher.cxx core/Subscriber.cxx ) +target_compile_definitions(Core PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") target_include_directories(Core PRIVATE core) target_link_libraries(Core fastcdr fastdds System_lib ) # GateCtrl Application. +set(PROGRAM_MODULE "GateCtrl") add_executable(GateCtrl gatectrl/main.cxx gatectrl/Publisher.cxx @@ -62,6 +65,7 @@ add_executable(GateCtrl gatectrl/MsgHandler.cxx common/CanMsgHandler.cxx ) +target_compile_definitions(GateCtrl PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") target_include_directories(GateCtrl PRIVATE gatectrl) target_link_libraries(GateCtrl fastcdr fastdds System_lib @@ -81,18 +85,21 @@ target_link_libraries(GateCtrl fastcdr fastdds # ) # HttpServer Application. +set(PROGRAM_MODULE "HttpServer") add_executable(HttpServer httpserver/main.cxx httpserver/Publisher.cxx httpserver/Subscriber.cxx httpserver/httpserver.cxx ) +target_compile_definitions(HttpServer PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") target_include_directories(HttpServer PRIVATE httpserver) target_link_libraries(HttpServer fastcdr fastdds System_lib ) # Print Application. +set(PROGRAM_MODULE "Print") add_executable(Print print/main.cxx print/Publisher.cxx @@ -101,12 +108,14 @@ add_executable(Print common/SerialMsgHandler.cxx lib/strcode.cpp ) +target_compile_definitions(Print PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") target_include_directories(Print PRIVATE print) target_link_libraries(Print fastcdr fastdds System_lib ) # Weigh Application. +set(PROGRAM_MODULE "Weigh") add_executable(Weigh weigh/main.cxx weigh/Publisher.cxx @@ -115,17 +124,20 @@ add_executable(Weigh weigh/WeightStabilityDetector.cxx common/SerialMsgHandler.cxx ) +target_compile_definitions(Weigh PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") target_include_directories(Weigh PRIVATE weigh) target_link_libraries(Weigh fastcdr fastdds System_lib ) # MqttDds Application. +set(PROGRAM_MODULE "MqttDds") add_executable(MqttDds mqttdds/main.cxx mqttdds/Publisher.cxx mqttdds/Subscriber.cxx ) +target_compile_definitions(MqttDds PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") target_include_directories(MqttDds PRIVATE mqttdds) target_link_libraries(MqttDds fastcdr fastdds System_lib PahoMqttCpp::paho-mqttpp3 diff --git a/common/DEBUG.hpp b/common/DEBUG.hpp new file mode 100644 index 0000000..2129ebe --- /dev/null +++ b/common/DEBUG.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +// 使用CMake定义的模块名 +#ifndef PROGRAM_MODULE_NAME + #define PROGRAM_MODULE_NAME "DefaultApp" +#endif + +// 使用CMake设置的模块名 +#define DEBUG(...) std::cout << "[" << PROGRAM_MODULE_NAME << "] " << __VA_ARGS__ << std::endl diff --git a/core/Publisher.cxx b/core/Publisher.cxx index 53530a2..d2c2900 100644 --- a/core/Publisher.cxx +++ b/core/Publisher.cxx @@ -35,6 +35,7 @@ #include "SystemPubSubTypes.hpp" #include "msg.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -219,7 +220,7 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher matched."); cv_.notify_one(); } else if (info.current_count_change == -1) @@ -228,12 +229,11 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for PublicationMatchedStatus current count change"); } } @@ -273,7 +273,7 @@ bool PublisherApp::bar_ctrl(const std::map& ctrl) } } - std::cout << "send bar ctrl cmd" << std::endl; + DEBUG("send bar ctrl cmd"); bar_writer_->write(&cmd); return true; @@ -311,7 +311,7 @@ bool PublisherApp::light_ctrl(const std::map& ctrl) } } - std::cout << "send light ctrl cmd" << std::endl; + DEBUG("send light ctrl cmd"); light_writer_->write(&cmd); return true; @@ -325,7 +325,7 @@ bool PublisherApp::print_receipt(const std::map& msg) for (auto &m : req.msg()) { - std::cout << "first: " << m.first << " second: " << m.second << std::endl; + DEBUG("first: " << m.first << " second: " << m.second); } print_writer_->write(&req); @@ -350,8 +350,8 @@ void PublisherApp::run() DdsMsgData::LicenseSnapUpdate_queue_.pop(); dds_lock.unlock(); - std::cout << "车牌: " << info.License() << std::endl; - std::cout << "类型: " << info.NewTag() << std::endl; + DEBUG("车牌: " << info.License()); + DEBUG("类型: " << info.NewTag()); if (license_no == "") { @@ -364,11 +364,11 @@ void PublisherApp::run() DdsMsgData::ScaleInfo_queue_.pop(); dds_lock.unlock(); - std::cout << "有车: " << info.HasVehicle() << std::endl; - std::cout << "稳定: " << info.WeightOK() << std::endl; - std::cout << "设备状态: " << info.State() << std::endl; - std::cout << "实时重量: " << info.Value() << std::endl; - std::cout << "稳定重量: " << info.StableValue() << std::endl; + DEBUG("有车: " << info.HasVehicle()); + DEBUG("稳定: " << info.WeightOK()); + DEBUG("设备状态: " << info.State()); + DEBUG("实时重量: " << info.Value()); + DEBUG("稳定重量: " << info.StableValue()); if (info.WeightOK() == 1) { @@ -391,8 +391,8 @@ void PublisherApp::run() DdsMsgData::BarUpdate_queue_.pop(); dds_lock.unlock(); - std::cout << "前拦车器状态: " << info.FrontBarState() << std::endl; - std::cout << "后拦车器状态: " << info.BackBarState() << std::endl; + DEBUG("前拦车器状态: " << info.FrontBarState()); + DEBUG("后拦车器状态: " << info.BackBarState()); } else if (!DdsMsgData::LightsUpdate_queue_.empty()) { @@ -400,8 +400,8 @@ void PublisherApp::run() DdsMsgData::LightsUpdate_queue_.pop(); dds_lock.unlock(); - std::cout << "前红绿灯状态: " << info.FrontLEDState() << std::endl; - std::cout << "后红绿灯状态: " << info.BackLEDState() << std::endl; + DEBUG("前红绿灯状态: " << info.FrontLEDState()); + DEBUG("后红绿灯状态: " << info.BackLEDState()); } else if (!DdsMsgData::InfraredUpdate_queue_.empty()) { @@ -409,8 +409,8 @@ void PublisherApp::run() DdsMsgData::InfraredUpdate_queue_.pop(); dds_lock.unlock(); - std::cout << "前红外对射状态: " << info.FrontResistanceSignal() << std::endl; - std::cout << "后红外对射状态: " << info.BackResistanceSignal() << std::endl; + DEBUG("前红外对射状态: " << info.FrontResistanceSignal()); + DEBUG("后红外对射状态: " << info.BackResistanceSignal()); } else if (!DdsMsgData::WeightInfoOk_queue_.empty()) { @@ -474,7 +474,7 @@ void PublisherApp::run() { if ((stable_weight != 0) && (license_no != "")) { - std::cout << "send summary" << std::endl; + DEBUG("send summary"); WeighingSystem::SummaryUpdate info; info.License() = license_no; info.StableValue() = stable_weight; diff --git a/core/Subscriber.cxx b/core/Subscriber.cxx index e4a646e..0c222f1 100644 --- a/core/Subscriber.cxx +++ b/core/Subscriber.cxx @@ -35,6 +35,7 @@ #include "SystemPubSubTypes.hpp" #include "msg.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -336,16 +337,15 @@ void SubscriberApp::on_subscription_matched( { if (info.current_count_change == 1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber matched."); } else if (info.current_count_change == -1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for SubscriptionMatchedStatus current count change"); } } @@ -354,7 +354,7 @@ void SubscriberApp::on_data_available( { SampleInfo info; std::string topic_name = reader->get_topicdescription()->get_name(); - std::cout << topic_name << std::endl; + DEBUG(topic_name << " Topic receviced."); if (topic_name == "BarUpdate") { diff --git a/core/main.cxx b/core/main.cxx index ba178e9..8fdbf2a 100644 --- a/core/main.cxx +++ b/core/main.cxx @@ -31,8 +31,8 @@ #include "Subscriber.hpp" #include "Publisher.hpp" -#include "mqtt/async_client.h" #include "msg.hpp" +#include "DEBUG.hpp" #define VERSION "v1.0" @@ -80,7 +80,6 @@ int main(int argc, char** argv) auto ret = EXIT_SUCCESS; std::shared_ptr sub; std::shared_ptr pub; - std::shared_ptr dev = nullptr; int domain_id = 0; @@ -89,7 +88,6 @@ int main(int argc, char** argv) if (strcmp(argv[i], "--domain") == 0 && i + 1 < argc) { domain_id = atoi(argv[++i]); - mqtt_id = std::string("core_") + std::string(argv[i]); } else if (strcmp(argv[i], "--version") == 0) { @@ -123,7 +121,7 @@ int main(int argc, char** argv) std::thread sub_thread(&SubscriberApp::run, sub); std::thread pub_thread(&PublisherApp::run, pub); - std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl; + DEBUG("Program is running. Please press Ctrl+C to stop at any time."); stop_handler = [&](int signum) { diff --git a/gatectrl/MsgHandler.cxx b/gatectrl/MsgHandler.cxx index 3bc0c14..78625a2 100644 --- a/gatectrl/MsgHandler.cxx +++ b/gatectrl/MsgHandler.cxx @@ -5,6 +5,7 @@ #include #include #include "MsgHandler.hpp" +#include "DEBUG.hpp" MsgHandler::MsgHandler() : fd(-1) { @@ -218,15 +219,15 @@ int MsgHandler::ParseDeviceMsg(std::vector& data) switch(data[1]) { case 0x50: - std::cout << "can gpio open success" << std::endl; + DEBUG("can gpio open success"); ret = 0; break; case 0x51: - std::cout << "can gpio write success" << std::endl; + DEBUG("can gpio write success"); break; ret = 0; case 0x52: - std::cout << "gpio change" << std::endl; + DEBUG("gpio change"); for (auto &p : this->iomap.imap) { p.second.second = data[p.second.first+2]; diff --git a/gatectrl/Publisher.cxx b/gatectrl/Publisher.cxx index d639102..39a8ac9 100644 --- a/gatectrl/Publisher.cxx +++ b/gatectrl/Publisher.cxx @@ -37,6 +37,7 @@ #include "msg.hpp" #include "MsgHandler.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -190,7 +191,7 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher matched."); cv_.notify_one(); } else if (info.current_count_change == -1) @@ -199,12 +200,11 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for PublicationMatchedStatus current count change"); } } diff --git a/gatectrl/Subscriber.cxx b/gatectrl/Subscriber.cxx index 528b43d..a48f9b8 100644 --- a/gatectrl/Subscriber.cxx +++ b/gatectrl/Subscriber.cxx @@ -35,6 +35,7 @@ #include "SystemPubSubTypes.hpp" #include "msg.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -150,16 +151,15 @@ void SubscriberApp::on_subscription_matched( { if (info.current_count_change == 1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber matched."); } else if (info.current_count_change == -1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for SubscriptionMatchedStatus current count change"); } } @@ -168,7 +168,7 @@ void SubscriberApp::on_data_available( { SampleInfo info; std::string topic_name = reader->get_topicdescription()->get_name(); - std::cout << topic_name << std::endl; + DEBUG(topic_name << " Topic receviced."); if (topic_name == "BarCommandUpdate") { diff --git a/gatectrl/main.cxx b/gatectrl/main.cxx index 2fdfa5f..ddfcd49 100644 --- a/gatectrl/main.cxx +++ b/gatectrl/main.cxx @@ -32,6 +32,7 @@ #include "Publisher.hpp" #include "CanMsgHandler.hpp" #include "msg.hpp" +#include "DEBUG.hpp" #define VERSION "v1.0" @@ -153,7 +154,7 @@ int main(int argc, char** argv) std::thread sub_thread(&SubscriberApp::run, sub, dev); std::thread pub_thread(&PublisherApp::run, pub, dev); - std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl; + DEBUG("Program is running. Please press Ctrl+C to stop at any time."); stop_handler = [&](int signum) { diff --git a/httpserver/Publisher.cxx b/httpserver/Publisher.cxx index 19cc26d..0b47d14 100644 --- a/httpserver/Publisher.cxx +++ b/httpserver/Publisher.cxx @@ -35,6 +35,7 @@ #include "SystemPubSubTypes.hpp" #include "json.hpp" +#include "DEBUG.hpp" using json = nlohmann::json; using namespace eprosima::fastdds::dds; @@ -127,7 +128,7 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher matched."); cv_.notify_one(); } else if (info.current_count_change == -1) @@ -136,12 +137,11 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for PublicationMatchedStatus current count change"); } } @@ -155,7 +155,7 @@ void PublisherApp::run(std::shared_ptr handler) if (handler->PostMsg.empty() != true) { json j = json::parse(handler->PostMsg); - std::cout << "车牌: " << j["AlarmInfoPlate"]["result"]["PlateResult"]["license"] << std::endl; + DEBUG("车牌: " << j["AlarmInfoPlate"]["result"]["PlateResult"]["license"]); WeighingSystem::LicenseSnapUpdate info; info.License() = j["AlarmInfoPlate"]["result"]["PlateResult"]["license"]; diff --git a/httpserver/Subscriber.cxx b/httpserver/Subscriber.cxx index f0cc5a3..a60c03b 100644 --- a/httpserver/Subscriber.cxx +++ b/httpserver/Subscriber.cxx @@ -34,6 +34,7 @@ #include "SystemPubSubTypes.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; SubscriberApp::SubscriberApp( @@ -111,16 +112,15 @@ void SubscriberApp::on_subscription_matched( { if (info.current_count_change == 1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber matched."); } else if (info.current_count_change == -1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for SubscriptionMatchedStatus current count change"); } } @@ -129,6 +129,8 @@ void SubscriberApp::on_data_available( { WeighingSystem::LicenseSnapUpdate sample_; SampleInfo info; + std::string topic_name = reader->get_topicdescription()->get_name(); + DEBUG(topic_name << " Topic receviced."); while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&sample_, &info))) { if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) diff --git a/httpserver/main.cxx b/httpserver/main.cxx index 65eb144..61d7a79 100644 --- a/httpserver/main.cxx +++ b/httpserver/main.cxx @@ -32,6 +32,7 @@ #include "Publisher.hpp" #include "httpserver.hpp" +#include "DEBUG.hpp" #define VERSION "v1.0.0" @@ -121,7 +122,7 @@ int main(int argc, char** argv) std::thread pub_thread(&PublisherApp::run, pub, dev); - std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl; + DEBUG("Program is running. Please press Ctrl+C to stop at any time."); stop_handler = [&](int signum) { diff --git a/mqttdds/Publisher.cxx b/mqttdds/Publisher.cxx index 2e4f691..5b41e29 100644 --- a/mqttdds/Publisher.cxx +++ b/mqttdds/Publisher.cxx @@ -36,6 +36,7 @@ #include "SystemPubSubTypes.hpp" #include "json.hpp" #include "msg.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; using json = nlohmann::json; @@ -221,7 +222,7 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher matched."); cv_.notify_one(); } else if (info.current_count_change == -1) @@ -230,12 +231,11 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for PublicationMatchedStatus current count change"); } } @@ -275,7 +275,7 @@ bool PublisherApp::bar_ctrl(const std::map& ctrl) } } - std::cout << "send bar ctrl cmd" << std::endl; + DEBUG("send bar ctrl cmd"); bar_writer_->write(&cmd); return true; @@ -313,7 +313,7 @@ bool PublisherApp::light_ctrl(const std::map& ctrl) } } - std::cout << "send light ctrl cmd" << std::endl; + DEBUG("send light ctrl cmd"); light_writer_->write(&cmd); return true; @@ -327,7 +327,7 @@ bool PublisherApp::print_receipt(const std::map& msg) for (auto &m : req.msg()) { - std::cout << "first: " << m.first << " second: " << m.second << std::endl; + DEBUG("first: " << m.first << " second: " << m.second); } print_writer_->write(&req); @@ -349,8 +349,8 @@ void PublisherApp::run(std::shared_ptr dev) DdsMsgData::LicenseSnapUpdate_queue_.pop(); dds_lock.unlock(); - // std::cout << "车牌: " << info.License() << std::endl; - // std::cout << "类型: " << info.NewTag() << std::endl; + // DEBUG("车牌: " << info.License()); + // DEBUG("类型: " << info.NewTag()); } else if (!DdsMsgData::ScaleInfo_queue_.empty()) { @@ -358,11 +358,11 @@ void PublisherApp::run(std::shared_ptr dev) DdsMsgData::ScaleInfo_queue_.pop(); dds_lock.unlock(); - // std::cout << "有车: " << info.HasVehicle() << std::endl; - // std::cout << "稳定: " << info.WeightOK() << std::endl; - // std::cout << "设备状态: " << info.State() << std::endl; - // std::cout << "实时重量: " << info.Value() << std::endl; - // std::cout << "稳定重量: " << info.StableValue() << std::endl; + // DEBUG("有车: " << info.HasVehicle()); + // DEBUG("稳定: " << info.WeightOK()); + // DEBUG("设备状态: " << info.State()); + // DEBUG("实时重量: " << info.Value()); + // DEBUG("稳定重量: " << info.StableValue()); } else if (!DdsMsgData::BarUpdate_queue_.empty()) { @@ -370,8 +370,8 @@ void PublisherApp::run(std::shared_ptr dev) DdsMsgData::BarUpdate_queue_.pop(); dds_lock.unlock(); - // std::cout << "前拦车器状态: " << info.FrontBarState() << std::endl; - // std::cout << "后拦车器状态: " << info.BackBarState() << std::endl; + // DEBUG("前拦车器状态: " << info.FrontBarState()); + // DEBUG("后拦车器状态: " << info.BackBarState()); if (dev != nullptr) { @@ -394,8 +394,8 @@ void PublisherApp::run(std::shared_ptr dev) DdsMsgData::LightsUpdate_queue_.pop(); dds_lock.unlock(); - // std::cout << "前红绿灯状态: " << info.FrontLEDState() << std::endl; - // std::cout << "后红绿灯状态: " << info.BackLEDState() << std::endl; + // DEBUG("前红绿灯状态: " << info.FrontLEDState()); + // DEBUG("后红绿灯状态: " << info.BackLEDState()); if (dev != nullptr) { @@ -418,8 +418,8 @@ void PublisherApp::run(std::shared_ptr dev) DdsMsgData::InfraredUpdate_queue_.pop(); dds_lock.unlock(); - // std::cout << "前红外对射状态: " << info.FrontResistanceSignal() << std::endl; - // std::cout << "后红外对射状态: " << info.BackResistanceSignal() << std::endl; + // DEBUG("前红外对射状态: " << info.FrontResistanceSignal()); + // DEBUG("后红外对射状态: " << info.BackResistanceSignal()); if (dev != nullptr) { diff --git a/mqttdds/Subscriber.cxx b/mqttdds/Subscriber.cxx index 92992ee..48cd7e3 100644 --- a/mqttdds/Subscriber.cxx +++ b/mqttdds/Subscriber.cxx @@ -35,6 +35,7 @@ #include "SystemPubSubTypes.hpp" #include "msg.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -274,16 +275,15 @@ void SubscriberApp::on_subscription_matched( { if (info.current_count_change == 1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber matched."); } else if (info.current_count_change == -1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for SubscriptionMatchedStatus current count change"); } } @@ -292,7 +292,7 @@ void SubscriberApp::on_data_available( { SampleInfo info; std::string topic_name = reader->get_topicdescription()->get_name(); - std::cout << topic_name << std::endl; + DEBUG(topic_name << " Topic receviced."); if (topic_name == "BarUpdate") { diff --git a/mqttdds/main.cxx b/mqttdds/main.cxx index 57c46cf..be1cb7d 100644 --- a/mqttdds/main.cxx +++ b/mqttdds/main.cxx @@ -33,6 +33,7 @@ #include "mqtt/async_client.h" #include "msg.hpp" +#include "DEBUG.hpp" #define VERSION "v1.0" @@ -220,7 +221,7 @@ int main(int argc, char** argv) std::thread sub_thread(&SubscriberApp::run, sub, dev); std::thread pub_thread(&PublisherApp::run, pub, dev); - std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl; + DEBUG("Program is running. Please press Ctrl+C to stop at any time."); stop_handler = [&](int signum) { diff --git a/print/Publisher.cxx b/print/Publisher.cxx index 4453e3d..0b1dced 100644 --- a/print/Publisher.cxx +++ b/print/Publisher.cxx @@ -37,6 +37,7 @@ #include "msg.hpp" #include "MsgHandler.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -122,7 +123,7 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher matched."); cv_.notify_one(); } else if (info.current_count_change == -1) @@ -131,12 +132,11 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for PublicationMatchedStatus current count change"); } } @@ -153,13 +153,12 @@ void PublisherApp::run(std::shared_ptr handler) MsgData::PrintReq_queue_.pop(); lock.unlock(); - std::cout << "index: " << req.index() << std::endl; handler->HandleDdsMsg(req.msg()); - InternalSystem::PrintRsp rsp; - rsp.index() = req.index(); - rsp.msg() = "success"; - writer_->write(&rsp); + // InternalSystem::PrintRsp rsp; + // rsp.index() = req.index(); + // rsp.msg() = "success"; + // writer_->write(&rsp); } else { diff --git a/print/Subscriber.cxx b/print/Subscriber.cxx index e4b179e..96d2f30 100644 --- a/print/Subscriber.cxx +++ b/print/Subscriber.cxx @@ -35,6 +35,7 @@ #include "SystemPubSubTypes.hpp" #include "msg.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -113,16 +114,15 @@ void SubscriberApp::on_subscription_matched( { if (info.current_count_change == 1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber matched."); } else if (info.current_count_change == -1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for SubscriptionMatchedStatus current count change"); } } @@ -131,7 +131,7 @@ void SubscriberApp::on_data_available( { SampleInfo info; std::string topic_name = reader->get_topicdescription()->get_name(); - std::cout << topic_name << std::endl; + DEBUG(topic_name << " Topic receviced."); if (topic_name == "PrintReq") { diff --git a/print/main.cxx b/print/main.cxx index 7db34eb..39c6ee1 100644 --- a/print/main.cxx +++ b/print/main.cxx @@ -32,6 +32,7 @@ #include "Publisher.hpp" #include "SerialMsgHandler.hpp" #include "msg.hpp" +#include "DEBUG.hpp" #define VERSION "v1.0" @@ -145,7 +146,7 @@ int main(int argc, char** argv) std::thread pub_thread(&PublisherApp::run, pub, dev); - std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl; + DEBUG("Program is running. Please press Ctrl+C to stop at any time."); stop_handler = [&](int signum) { diff --git a/weigh/Publisher.cxx b/weigh/Publisher.cxx index e3638ad..c835bcf 100644 --- a/weigh/Publisher.cxx +++ b/weigh/Publisher.cxx @@ -38,6 +38,7 @@ #include "msg.hpp" #include "MsgHandler.hpp" #include "WeightStabilityDetector.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -129,7 +130,7 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher matched."); cv_.notify_one(); } else if (info.current_count_change == -1) @@ -138,12 +139,11 @@ void PublisherApp::on_publication_matched( std::lock_guard lock(mutex_); matched_ = info.current_count; } - std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl; + DEBUG(writer->get_topic()->get_name() << " Publisher unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for PublicationMatchedStatus current count change"); } } @@ -252,7 +252,7 @@ void PublisherApp::run(std::shared_ptr handler) info.WeightOK() = 1; info.Value() = weight/1000; info.StableValue() = weight/1000; - std::cout << "STABLE WEIGHT: " << detector.getStableWeight() << " kg" << std::endl; + DEBUG("STABLE WEIGHT: " << detector.getStableWeight() << " kg"); } else { diff --git a/weigh/Subscriber.cxx b/weigh/Subscriber.cxx index 37b95b8..66ab606 100644 --- a/weigh/Subscriber.cxx +++ b/weigh/Subscriber.cxx @@ -35,6 +35,7 @@ #include "SystemPubSubTypes.hpp" #include "msg.hpp" +#include "DEBUG.hpp" using namespace eprosima::fastdds::dds; @@ -119,16 +120,15 @@ void SubscriberApp::on_subscription_matched( { if (info.current_count_change == 1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber matched."); } else if (info.current_count_change == -1) { - std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl; + DEBUG(reader->get_topicdescription()->get_name() << " Subscriber unmatched."); } else { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + DEBUG(info.current_count_change << " is not a valid value for SubscriptionMatchedStatus current count change"); } } @@ -137,7 +137,7 @@ void SubscriberApp::on_data_available( { SampleInfo info; std::string topic_name = reader->get_topicdescription()->get_name(); - std::cout << topic_name << std::endl; + DEBUG(topic_name << " Topic receviced."); if (topic_name == "ScaleCommand") { diff --git a/weigh/main.cxx b/weigh/main.cxx index 388492d..8d52f66 100644 --- a/weigh/main.cxx +++ b/weigh/main.cxx @@ -32,6 +32,7 @@ #include "Publisher.hpp" #include "SerialMsgHandler.hpp" #include "msg.hpp" +#include "DEBUG.hpp" #define VERSION "v1.0" @@ -152,7 +153,7 @@ int main(int argc, char** argv) std::thread pub_thread(&PublisherApp::run, pub, dev); - std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl; + DEBUG("Program is running. Please press Ctrl+C to stop at any time."); stop_handler = [&](int signum) {