diff --git a/appsrc/appbase/appbean/dm_gas_path.cpp b/appsrc/appbase/appbean/dm_gas_path.cpp new file mode 100644 index 0000000..6e8875d --- /dev/null +++ b/appsrc/appbase/appbean/dm_gas_path.cpp @@ -0,0 +1,2 @@ +#include "dm_gas_path.hpp" +DMGasPath_ZENUM_IMPL \ No newline at end of file diff --git a/appsrc/appbase/appbean/dm_gas_path.hpp b/appsrc/appbase/appbean/dm_gas_path.hpp new file mode 100644 index 0000000..76ff622 --- /dev/null +++ b/appsrc/appbase/appbean/dm_gas_path.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "iflytop/core/components/zenum_template/zenum_template.hpp" + +#define DMGasPath_ZENUM_IMPL ZENUM_IMPL(DMGasPath, DMGasPath_LIST) +#define DMGasPath_LIST(type, marco) /**/ \ + marco(type, disinfection) /*消毒*/ \ + marco(type, degradation) /*降解*/ \ + marco(type, dehumidification) /*除湿*/ + +ZENUM_DECLAR(DMGasPath, DMGasPath_LIST); diff --git a/appsrc/appconfig/basic/zappversion.hpp b/appsrc/appconfig/basic/zappversion.hpp index 28179c2..d22cfad 100644 --- a/appsrc/appconfig/basic/zappversion.hpp +++ b/appsrc/appconfig/basic/zappversion.hpp @@ -1,3 +1,3 @@ #pragma once -#define VERSION "3.2.2" +#define VERSION "3.2.3" #define PROJECT_NAME "TRANSMIT_DM" \ No newline at end of file diff --git a/appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.cpp b/appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.cpp index 84c81ea..ee97483 100644 --- a/appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.cpp +++ b/appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.cpp @@ -154,9 +154,9 @@ void IflytopFrontEndService::onMessageCallback(weak_ptr webSocket, sh logger->error(" Wait time(ms) : {}", msg->errorInfo.wait_time); logger->error(" HTTP Status : {}", msg->errorInfo.http_status); } else if (msg->type == ix::WebSocketMessageType::Ping) { - logger->debug("WebSocket ping received"); + logger->info("WebSocket ping received"); } else if (msg->type == ix::WebSocketMessageType::Pong) { - logger->debug("WebSocket pong received"); + logger->info("WebSocket pong received"); } else { logger->warn("Unknown WebSocket message type: {}", static_cast(msg->type)); } @@ -165,6 +165,10 @@ void IflytopFrontEndService::processRxMessage(weak_ptr webSocket, str string msgtext = rxmsg; json message; + if (rxmsg == "{\"type\":\"ping\"}") { + return; + } + try { shared_ptr ws = webSocket.lock(); if (!ws) { @@ -174,13 +178,22 @@ void IflytopFrontEndService::processRxMessage(weak_ptr webSocket, str json command = json::parse(msgtext); json receipt; - receipt["messageId"] = command["messageId"]; - receipt["ackcode"] = 0; - receipt["messageType"] = "Ack"; - receipt["timeStamp"] = duration_cast(system_clock::now().time_since_epoch()).count(); + try { - onMessage(webSocket, command, receipt); - ws->sendText(receipt.dump(1)); + if (command["messageType"] == "Ping") { + receipt["messageType"] = "Pong"; + receipt["messageId"] = command["messageId"]; + receipt["timeStamp"] = duration_cast(system_clock::now().time_since_epoch()).count(); + ws->sendText(receipt.dump()); + } else { + receipt["messageId"] = command["messageId"]; + receipt["ackcode"] = 0; + receipt["messageType"] = "Ack"; + receipt["timeStamp"] = duration_cast(system_clock::now().time_since_epoch()).count(); + onMessage(webSocket, command, receipt); + ws->sendText(receipt.dump(1)); + } + } catch (const detail::parse_error& e) { // json parse error logger->error("process rx json failed,exception:{},{}", e.what(), msgtext); diff --git a/appsrc/service/app_core.cpp b/appsrc/service/app_core.cpp index ad86d7a..1546a63 100644 --- a/appsrc/service/app_core.cpp +++ b/appsrc/service/app_core.cpp @@ -56,6 +56,7 @@ void AppCore::initialize() { REG_ENUM_TYPE(ProjectTypeEnum, ProjectTypeEnum::getEnumStrList()); REG_ENUM_TYPE(H2O2SensorType, H2O2SensorType::getEnumStrList()); REG_ENUM_TYPE(PressureUint, PressureUint::getEnumStrList()); + REG_ENUM_TYPE(DMGasPath, DMGasPath::getEnumStrList()); installEcodeInfo(); @@ -100,6 +101,7 @@ void AppCore::initialize() { BUILD_AND_REG_SERRVICE(H2O2SensorMgr); // + BUILD_AND_REG_SERRVICE(DMGasPathMgrService); BUILD_AND_REG_SERRVICE(PipelinePressureControl); BUILD_AND_REG_SERRVICE(UDiskMgrService); // diff --git a/appsrc/service/app_core.hpp b/appsrc/service/app_core.hpp index 82336a1..367a744 100644 --- a/appsrc/service/app_core.hpp +++ b/appsrc/service/app_core.hpp @@ -17,6 +17,7 @@ #include "appconfig/appconfig.hpp" #include "baseservice/front_msg_processer/front_msg_processer.hpp" #include "service/hardware/device_io_ctrl_service.hpp" +#include "service/dm_gas_path_mgr_service.hpp" /** * @brief diff --git a/appsrc/service/dm_gas_path_mgr_service.cpp b/appsrc/service/dm_gas_path_mgr_service.cpp new file mode 100644 index 0000000..fab91f2 --- /dev/null +++ b/appsrc/service/dm_gas_path_mgr_service.cpp @@ -0,0 +1,58 @@ +#include "dm_gas_path_mgr_service.hpp" + +using namespace iflytop; + +#define RECORD_PERIOD 3000 // 1 second + +void DMGasPathMgrService::initialize() { + // 注册所有的H2O2传感器 + // + stateUpdateThread.reset(new Thread("FERDC-stateUpdateThread", [this]() { + while (!ThisThread().getExitFlag()) { + try { + stateUpdateThreadFunc(); + } catch (const std::exception& e) { + logger->error("stateUpdateThread error:{}", e.what()); + } + ThisThread().sleepForMs(RECORD_PERIOD); + } + })); + + AppEventBus::ins()->onEvent.connect([this](shared_ptr event) { + if (dynamic_pointer_cast(event)) { + stateUpdateThread->wake(); + } + }); + + REG_CLASS("气路通道控制服务"); + REG_EXTFN(selectChannel, void(DMGasPath), dmGasPath); + REG_EXTFN_DISPNAME(selectChannel, "选择通道"); +} + +/** + * @brief 传感器数值上报 + */ +void DMGasPathMgrService::stateUpdateThreadFunc() { + ThisThread thisThread; + + std::lock_guard lock(lock_); + json report; + + report["gasPathSwitcher"]["isOnline"] = isOnline; + report["path"] = dmGasPath; + + SEND_CLASS_REPORT(thisClass.className, "stateUpdate", report); +} + +void DMGasPathMgrService::setOnlineState(shared_ptr cxt, bool isOnline) { + std::lock_guard lock(lock_); + logger->info("setOnlineState:{}", isOnline); + this->isOnline = isOnline; +} + +void DMGasPathMgrService::selectChannel(shared_ptr cxt, DMGasPath dmGasPath) { + std::lock_guard lock(lock_); + logger->info("selectChannel:{}", dmGasPath.toString()); + this->dmGasPath = dmGasPath; + stateUpdateThread->wake(); +} diff --git a/appsrc/service/dm_gas_path_mgr_service.hpp b/appsrc/service/dm_gas_path_mgr_service.hpp new file mode 100644 index 0000000..019e09a --- /dev/null +++ b/appsrc/service/dm_gas_path_mgr_service.hpp @@ -0,0 +1,34 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "appbase/appbean/dm_gas_path.hpp" +#include "baseservice/baseservice.hpp" +#include "service/hardware/disinfectant_weight_update_service.hpp" + +namespace iflytop { +class DMGasPathMgrService : public enable_shared_from_this { + THISCLASS(DMGasPathMgrService); + + unique_ptr stateUpdateThread; + DMGasPath dmGasPath = DMGasPath::disinfection; + bool isOnline = false; + std::recursive_mutex lock_; + + public: + void initialize(); + + private: + void selectChannel(shared_ptr cxt, DMGasPath dmGasPath); + void setOnlineState(shared_ptr cxt, bool isOnline); + void stateUpdateThreadFunc(); +}; + +} // namespace iflytop diff --git a/appsrc/service/hardware/dm_exch_selector_driver.cpp b/appsrc/service/hardware/dm_exch_selector_driver.cpp new file mode 100644 index 0000000..e69de29 diff --git a/appsrc/service/hardware/dm_exch_selector_driver.hpp b/appsrc/service/hardware/dm_exch_selector_driver.hpp new file mode 100644 index 0000000..9077d06 --- /dev/null +++ b/appsrc/service/hardware/dm_exch_selector_driver.hpp @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +#include "baseservice/baseservice.hpp" +#include "baseservice/db/device_ext_setting_dao.hpp" +#include "device_io_ctrl_service.hpp" +namespace iflytop { +using namespace std; + +class ExChSelectorCtrlService { + private: + /* data */ + public: + ExChSelectorCtrlService(/* args */); + ~ExChSelectorCtrlService(); + + void initialize(); + +}; + +} // namespace iflytop \ No newline at end of file