From ec2b03473c9e9459c96d16ac73eb4365d07620b7 Mon Sep 17 00:00:00 2001 From: baocm Date: Wed, 21 Jan 2026 11:49:35 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=E6=8B=A6=E8=BD=A6?= =?UTF-8?q?=E5=99=A8=E9=94=81=E5=AE=9A=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/utils.hpp | 14 ++++++++++++ gatectrl/Subscriber.cxx | 48 +++++++++++++++++++++++++---------------- mqttdds/Publisher.cxx | 12 +++++++++++ 3 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 common/utils.hpp diff --git a/common/utils.hpp b/common/utils.hpp new file mode 100644 index 0000000..bc25538 --- /dev/null +++ b/common/utils.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include +#include +#include + +std::filesystem::path getExeDir() +{ + char buf[PATH_MAX] = {0}; + ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf)-1); + return std::filesystem::path(std::string(buf, len)).parent_path(); +} \ No newline at end of file diff --git a/gatectrl/Subscriber.cxx b/gatectrl/Subscriber.cxx index a48f9b8..6eb439b 100644 --- a/gatectrl/Subscriber.cxx +++ b/gatectrl/Subscriber.cxx @@ -36,6 +36,7 @@ #include "msg.hpp" #include "DEBUG.hpp" +#include "utils.hpp" using namespace eprosima::fastdds::dds; @@ -215,33 +216,42 @@ void SubscriberApp::run(std::shared_ptr handler) MsgData::BarCommandUpdate_queue_.pop(); lock.unlock(); std::vector port; - if (cmd.FrontBarEnable() == true) + if (!std::filesystem::exists(getExeDir() / "frontbar.lock")) { - if (cmd.FrontBarSignalUp() == 1) + if (cmd.FrontBarEnable() == true) { - port.push_back("FrontBarUp"); - handler->new_bar_state.FrontBarState = 1; - } - else if (cmd.FrontBarSignalDown() == 1) - { - port.push_back("FrontBarDown"); - handler->new_bar_state.FrontBarState = 2; + if (cmd.FrontBarSignalUp() == 1) + { + port.push_back("FrontBarUp"); + handler->new_bar_state.FrontBarState = 1; + } + else if (cmd.FrontBarSignalDown() == 1) + { + port.push_back("FrontBarDown"); + handler->new_bar_state.FrontBarState = 2; + } } } - if (cmd.BackBarEnable() == true) + if (!std::filesystem::exists(getExeDir() / "backbar.lock")) { - if (cmd.BackBarSignalUp() == 1) - { - port.push_back("BackBarUp"); - handler->new_bar_state.BackBarState = 1; - } - else if (cmd.BackBarSignalDown() == 1) + if (cmd.BackBarEnable() == true) { - port.push_back("BackBarDown"); - handler->new_bar_state.BackBarState = 2; + if (cmd.BackBarSignalUp() == 1) + { + port.push_back("BackBarUp"); + handler->new_bar_state.BackBarState = 1; + } + else if (cmd.BackBarSignalDown() == 1) + { + port.push_back("BackBarDown"); + handler->new_bar_state.BackBarState = 2; + } } } - handler->CtrlBar(port); + if (!port.empty()) + { + handler->CtrlBar(port); + } } else if(!MsgData::LightsCommandUpdate_queue_.empty()) { diff --git a/mqttdds/Publisher.cxx b/mqttdds/Publisher.cxx index 2f414c4..07deee4 100644 --- a/mqttdds/Publisher.cxx +++ b/mqttdds/Publisher.cxx @@ -37,6 +37,7 @@ #include "json.hpp" #include "msg.hpp" #include "DEBUG.hpp" +#include "utils.hpp" using namespace eprosima::fastdds::dds; using json = nlohmann::json; @@ -463,6 +464,17 @@ void PublisherApp::run(std::shared_ptr dev) bar_ctrl(ctrl); } } + else if (topic.find("barrier/frontlock") != std::string::npos) + { + if (cmd["value"] == 1) + { + std::ofstream(getExeDir() / "frontbar.lock") << getpid(); + } + else + { + std::filesystem::remove(getExeDir() / "frontbar.lock"); + } + } else if (topic.find("light/frontsignal") != std::string::npos) { if (cmd["value"] == 1)