From 5534eb5e875b616db20c9445e2e727891d350a97 Mon Sep 17 00:00:00 2001 From: lzq Date: Thu, 4 Sep 2025 17:31:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/niu_neng.json | 8 +++++ src/common/event_manager.cpp | 30 +++++++++---------- src/common/logging.cpp | 4 +-- src/device_holder.cpp | 14 ++++----- src/platform_scale/generic_platform_scale.cpp | 15 +++++----- src/vidicon/barrier_vidicon.cpp | 7 ++--- 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/config/niu_neng.json b/config/niu_neng.json index 4b75f0d..89c95ae 100644 --- a/config/niu_neng.json +++ b/config/niu_neng.json @@ -29,9 +29,17 @@ "topic": "/device/eddb943a-70e9fd81/message/up/snapshot", "qos": 0 }, + { + "topic": "/device/eddb943a-70e9fd81/message/down/snapshot/reply", + "qos": 0 + }, { "topic": "/device/0122310d-75bdca05/message/up/snapshot", "qos": 0 + }, + { + "topic": "/device/0122310d-75bdca05/message/down/snapshot/reply", + "qos": 0 } ] }, diff --git a/src/common/event_manager.cpp b/src/common/event_manager.cpp index d0f32a0..cc5f85a 100644 --- a/src/common/event_manager.cpp +++ b/src/common/event_manager.cpp @@ -46,26 +46,26 @@ namespace zsy } } - if (list == nullptr || list->size() == 0) + if (list == nullptr || list->empty()) { return; } - - threadPool->submit([list, name, data] + for (const auto &fn_ptr: *list) { - for (auto fn_ptr: *list) + try { - try - { - (*fn_ptr.get())(Event(name, data)); - } catch (const std::exception &e) - { - LOGGER_ERROR("事件处理异常:{} {}", name, e.what()); - }catch (...) - { - LOGGER_ERROR("事件处理异常:{}", name); - } + (*fn_ptr.get())(Event(name, data)); + } catch (const std::exception &e) + { + LOGGER_ERROR("事件处理异常:{} {}", name, e.what()); + } catch (...) + { + LOGGER_ERROR("事件处理异常:{}", name); } - }); + } + /*threadPool->submit([list, name, data] + { + + });*/ } } // zsy diff --git a/src/common/logging.cpp b/src/common/logging.cpp index 98339d2..21c3f79 100644 --- a/src/common/logging.cpp +++ b/src/common/logging.cpp @@ -17,11 +17,11 @@ namespace zsy 15 ); file_sink->set_level(spdlog::level::info); - file_sink->set_pattern("%Y-%m-%d %H:%M:%S.%e %=7l %=10t %-40s [%-64! %10#]: %v"); + file_sink->set_pattern("%Y-%m-%d %H:%M:%S.%e %=7l %=10t %s [%! %#]: %v"); const auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::info); - console_sink->set_pattern("%Y-%m-%d %H:%M:%S.%e %=7l %=10t %-40s [%-64! %10#]: %v"); + console_sink->set_pattern("%Y-%m-%d %H:%M:%S.%e %=7l %=10t %s [%! %#]: %v"); spdlog::sinks_init_list sinks = {console_sink, file_sink}; auto logger = std::make_shared("zsy", sinks); diff --git a/src/device_holder.cpp b/src/device_holder.cpp index 05a77fd..ad2e96d 100644 --- a/src/device_holder.cpp +++ b/src/device_holder.cpp @@ -3,11 +3,12 @@ #include "barrier/generic_barrier.h" #include "platform_scale/generic_platform_scale.h" #include "sound_column/generic_sound_column.h" -#include "vidicon/generic_vidicon.h" -// #include "vidicon/barrier_vidicon.h" +// #include "vidicon/generic_vidicon.h" +#include "vidicon/barrier_vidicon.h" -namespace zsy { - void DeviceHolder::initBarriers(std::vector &configs) +namespace zsy +{ + void DeviceHolder::initBarriers(std::vector &configs) { for (auto &config: configs) { @@ -39,8 +40,8 @@ namespace zsy { { for (auto &config: configs) { - vidicons.emplace(config.sn, std::make_shared(config)); - // vidicons.emplace(config.sn, std::make_shared(config)); + // vidicons.emplace(config.sn, std::make_shared(config)); + vidicons.emplace(config.sn, std::make_shared(config)); } } @@ -86,5 +87,4 @@ namespace zsy { auto sn = map.at("vidicon"); return vidicons.contains(sn) ? vidicons.at(sn) : nullptr; } - } // zsy \ No newline at end of file diff --git a/src/platform_scale/generic_platform_scale.cpp b/src/platform_scale/generic_platform_scale.cpp index c43aca9..48d736c 100644 --- a/src/platform_scale/generic_platform_scale.cpp +++ b/src/platform_scale/generic_platform_scale.cpp @@ -94,11 +94,11 @@ namespace zsy try { LOGGER_INFO("正在读取地磅数据,设备名称:{}", config.name); - if (status != 1) + /*if (status != 1) { LOGGER_INFO("无法称重,地磅状态:{}", status); return 0.0; - } + }*/ int retry_count = 0; while ((serialPort->status.load() == 3 || serialPort->readStatus.load() == 3) && retry_count < 10) @@ -113,11 +113,11 @@ namespace zsy if (serialPort->status.load() == 3 || serialPort->readStatus.load() == 3) { LOGGER_ERROR("无法称重,串口异常,重试失败"); - status = 1; + /*status = 1;*/ return 0.0; } - status = 2; + /*status = 2;*/ LOGGER_INFO("正在称重..."); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); auto processor = static_cast(serialPort->processor); @@ -128,22 +128,21 @@ namespace zsy if (count >= 10) { LOGGER_ERROR("称重失败,连续 {} 次未稳定", count); - status = 1; + /*status = 1;*/ return 0.0; } std::this_thread::sleep_for(std::chrono::milliseconds(3000)); } auto res = processor->weight.load(); LOGGER_INFO("称重完成:{} KG", res); - status = 1; + /*status = 1;*/ return res; } catch (std::exception &e) { LOGGER_ERROR("称重失败:{}", e.what()); status = 4; return 0.0; - } - catch (...) + } catch (...) { LOGGER_ERROR("未知异常,称重失败"); status = 4; diff --git a/src/vidicon/barrier_vidicon.cpp b/src/vidicon/barrier_vidicon.cpp index 251cc3d..0f4b59d 100644 --- a/src/vidicon/barrier_vidicon.cpp +++ b/src/vidicon/barrier_vidicon.cpp @@ -32,7 +32,7 @@ namespace zsy } catch (const std::exception &e) { LOGGER_ERROR("图片保存失败"); - }catch (...) + } catch (...) { LOGGER_ERROR("未知异常,图片保存失败"); } @@ -90,7 +90,7 @@ namespace zsy { "payload", { {"type", "snapshot"}, - {"body", {}}, + {"body", nlohmann::json::object()}, } } }; @@ -141,8 +141,7 @@ namespace zsy { LOGGER_ERROR("摄像机拍照失败:{}", e.what()); return nullptr; - } - catch (...) + } catch (...) { LOGGER_ERROR("未知异常,摄像机拍照失败"); return nullptr;