From 793ca672e3ce4d66466fd3dc5d6626ccf52637c1 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 18 Aug 2024 20:54:53 +0800 Subject: [PATCH] update --- app_protocols/apperrorcode/apperrorcode.hpp | 2 ++ appsrc/appbase/appevent/app_event.hpp | 20 --------------- appsrc/appbase/appevent/app_events.hpp | 4 +++ appsrc/appbase/appevent/app_promopt_event.hpp | 4 +-- .../appbase/appevent/app_warning_promopt_event.hpp | 10 ++++---- appsrc/appbase/appevent/iapp_event.hpp | 20 +++++++++++++++ appsrc/appsetting/project_port/project_port.cpp | 16 ++++++++++++ appsrc/appsetting/project_port/project_port.hpp | 1 + appsrc/baseservice/app_event_bus.cpp | 29 +++++++++++++++++++++- appsrc/baseservice/app_event_bus.hpp | 16 ++++++++---- appsrc/baseservice/baseservice.hpp | 3 ++- .../disinfection_ctrl_service.cpp | 17 +++++++++++++ 12 files changed, 108 insertions(+), 34 deletions(-) delete mode 100644 appsrc/appbase/appevent/app_event.hpp create mode 100644 appsrc/appbase/appevent/app_events.hpp create mode 100644 appsrc/appbase/appevent/iapp_event.hpp diff --git a/app_protocols/apperrorcode/apperrorcode.hpp b/app_protocols/apperrorcode/apperrorcode.hpp index cf0a123..b87f263 100644 --- a/app_protocols/apperrorcode/apperrorcode.hpp +++ b/app_protocols/apperrorcode/apperrorcode.hpp @@ -79,6 +79,8 @@ typedef enum { kappe_sensor_is_pre_hearting = 10027, // 传感器正在预热 kappe_disinfection_state_is_wrong = 10028, // 消毒状态错误 + + } apperror_t; } diff --git a/appsrc/appbase/appevent/app_event.hpp b/appsrc/appbase/appevent/app_event.hpp deleted file mode 100644 index 326343a..0000000 --- a/appsrc/appbase/appevent/app_event.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -namespace iflytop { -using namespace std; -class AppEvent { - public: - AppEvent(/* args */) {} - virtual ~AppEvent() {} -}; - -} // namespace ifytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/app_events.hpp b/appsrc/appbase/appevent/app_events.hpp new file mode 100644 index 0000000..533532a --- /dev/null +++ b/appsrc/appbase/appevent/app_events.hpp @@ -0,0 +1,4 @@ +#pragma once +#include "app_promopt_event.hpp" +#include "app_warning_promopt_event.hpp" +#include "iapp_event.hpp" diff --git a/appsrc/appbase/appevent/app_promopt_event.hpp b/appsrc/appbase/appevent/app_promopt_event.hpp index 6f8b986..69f98be 100644 --- a/appsrc/appbase/appevent/app_promopt_event.hpp +++ b/appsrc/appbase/appevent/app_promopt_event.hpp @@ -1,7 +1,7 @@ -#include "app_event.hpp" +#include "iapp_event.hpp" namespace iflytop { -class AppPromoptEvent : public AppEvent { +class AppPromoptEvent : public IAppEvent { private: string message; diff --git a/appsrc/appbase/appevent/app_warning_promopt_event.hpp b/appsrc/appbase/appevent/app_warning_promopt_event.hpp index 007bb5c..70ea6b0 100644 --- a/appsrc/appbase/appevent/app_warning_promopt_event.hpp +++ b/appsrc/appbase/appevent/app_warning_promopt_event.hpp @@ -1,14 +1,14 @@ #pragma once -#include "app_event.hpp" +#include "iapp_event.hpp" namespace iflytop { -class AppWarningPromoptEvent : public AppEvent { +class AppWarningPromoptEvent : public IAppEvent { private: - string message; + int ecode; public: - AppWarningPromoptEvent(string message) : message(message) {} + AppWarningPromoptEvent(int ecode) : ecode(ecode) {} virtual ~AppWarningPromoptEvent() {} - string getMessage() { return message; } + int getEcode() { return ecode; } }; } // namespace iflytop \ No newline at end of file diff --git a/appsrc/appbase/appevent/iapp_event.hpp b/appsrc/appbase/appevent/iapp_event.hpp new file mode 100644 index 0000000..0712f2b --- /dev/null +++ b/appsrc/appbase/appevent/iapp_event.hpp @@ -0,0 +1,20 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace iflytop { +using namespace std; +class IAppEvent { + public: + IAppEvent(/* args */) {} + virtual ~IAppEvent() {} +}; + +} // namespace ifytop \ No newline at end of file diff --git a/appsrc/appsetting/project_port/project_port.cpp b/appsrc/appsetting/project_port/project_port.cpp index e88abd9..f9fb948 100644 --- a/appsrc/appsetting/project_port/project_port.cpp +++ b/appsrc/appsetting/project_port/project_port.cpp @@ -222,3 +222,19 @@ int32_t ProjectPort::getExtH2O2SensorNum() { } return 0; } + +bool ProjectPort::isHasDisinfectantBucket() { + if (isLageSpaceDM()) { + return true; + } + if (isSmallSpaceDM()) { + return true; + } + if (isPipeDM()) { + return true; + } + if (isDrawBarDM()) { + return false; + } + return false; +} diff --git a/appsrc/appsetting/project_port/project_port.hpp b/appsrc/appsetting/project_port/project_port.hpp index bf3e777..f67cc3e 100644 --- a/appsrc/appsetting/project_port/project_port.hpp +++ b/appsrc/appsetting/project_port/project_port.hpp @@ -104,6 +104,7 @@ class ProjectPort { int32_t getExtH2O2SensorNum(); // int emptyPipeSprayPumpRPM = 700; int32_t getEmptyPipeSprayPumpRPM(); + bool isHasDisinfectantBucket(); private: void initProjectSetting(int projectTypeInt); diff --git a/appsrc/baseservice/app_event_bus.cpp b/appsrc/baseservice/app_event_bus.cpp index a782e7c..a0e17ca 100644 --- a/appsrc/baseservice/app_event_bus.cpp +++ b/appsrc/baseservice/app_event_bus.cpp @@ -1 +1,28 @@ -#include "app_event_bus.hpp" \ No newline at end of file +#include "app_event_bus.hpp" + +using namespace iflytop; + +void AppEventBus::initialize() { + m_eventBusThread.reset(new Thread("appEventBus", [this]() { + while (true) { + shared_ptr event; + { + lock_guard lock(m_eventQueueMutex); + if (m_eventQueue.size() > 0) { + event = m_eventQueue.front(); + m_eventQueue.pop_front(); + } + } + if (event) { + onEvent(event); + } else { + this_thread::sleep_for(chrono::milliseconds(10)); + } + } + })); +} + +void AppEventBus::push(shared_ptr event) { + lock_guard lock(m_eventQueueMutex); + m_eventQueue.push_back(event); +} \ No newline at end of file diff --git a/appsrc/baseservice/app_event_bus.hpp b/appsrc/baseservice/app_event_bus.hpp index 50976ce..f8b7d28 100644 --- a/appsrc/baseservice/app_event_bus.hpp +++ b/appsrc/baseservice/app_event_bus.hpp @@ -12,17 +12,23 @@ // #include "appbase/appbase.hpp" -#include "appbase/appevent/app_event.hpp" +#include "appbase/appevent/app_events.hpp" #include "appsetting/appsetting.hpp" + + // namespace iflytop { class AppEventBus : public enable_shared_from_this { THISCLASS(AppEventBus); - bool isInitialized = false; + bool isInitialized = false; + unique_ptr m_eventBusThread; + + list> m_eventQueue; + mutex m_eventQueueMutex; public: - nod::signal)> onEvent; + nod::signal)> onEvent; public: static AppEventBus* ins() { @@ -34,10 +40,10 @@ class AppEventBus : public enable_shared_from_this { return &instance; } - void push(shared_ptr event) {} + void push(shared_ptr event) ; private: - void initialize() {} + void initialize() ; }; } // namespace iflytop diff --git a/appsrc/baseservice/baseservice.hpp b/appsrc/baseservice/baseservice.hpp index ea33585..9c04ee6 100644 --- a/appsrc/baseservice/baseservice.hpp +++ b/appsrc/baseservice/baseservice.hpp @@ -2,9 +2,10 @@ #include "appbase/appbase.hpp" #include "appsetting/appsetting.hpp" // +#include "app_event_bus.hpp" #include "appcomponents/canchannel/transmit_disinfection_can_master.hpp" #include "db/db_service.hpp" #include "devicestate/device_state_service.hpp" #include "front_msg_processer/front_msg_processer.hpp" #include "iflytop_front_end_service/iflytop_front_end_service.hpp" -#include "udisk_mgr_service.hpp" +#include "udisk_mgr_service.hpp" \ No newline at end of file diff --git a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp index 8568f7d..79d500f 100644 --- a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp +++ b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp @@ -189,6 +189,14 @@ void DisinfectionCtrlService::checkBeforeStart() { if (m_thread->isWaitingForJoin()) { THROW_APP_EXCEPTION(err::kappe_disinfection_state_is_wrong, ""); } + + if (dics->WaterSensor_readDeviceBottom()) { + THROW_APP_EXCEPTION(err::kappe_the_bottom_of_the_device_has_water, ""); + } + + if (dics->WaterSensor_readEvaporationBin()) { + THROW_APP_EXCEPTION(err::kappe_the_evaporation_bin_has_water, ""); + } } void DisinfectionCtrlService::startWorkThread() { @@ -475,6 +483,15 @@ void DisinfectionCtrlService::processStateDisinfection(DisinfectionEvent* event) */ changeToNextState(); } + // AppEventBus + if (PORT.isHasDisinfectantBucket()) { + if (dwus->getWeight() < 10) { + logger->error("DisinfectantBucket is empty"); + AppEventBus::ins()->push(make_shared(err::kappe_disinfectant_insufficient)); + changeToNextState(); + } + } + tryLogState(false); // 检查是否消毒完成