修复 bug

master
lzq 2025-09-04 17:31:25 +08:00
parent 9f7bcfc330
commit 5534eb5e87
6 changed files with 42 additions and 36 deletions

View File

@ -29,9 +29,17 @@
"topic": "/device/eddb943a-70e9fd81/message/up/snapshot", "topic": "/device/eddb943a-70e9fd81/message/up/snapshot",
"qos": 0 "qos": 0
}, },
{
"topic": "/device/eddb943a-70e9fd81/message/down/snapshot/reply",
"qos": 0
},
{ {
"topic": "/device/0122310d-75bdca05/message/up/snapshot", "topic": "/device/0122310d-75bdca05/message/up/snapshot",
"qos": 0 "qos": 0
},
{
"topic": "/device/0122310d-75bdca05/message/down/snapshot/reply",
"qos": 0
} }
] ]
}, },

View File

@ -46,26 +46,26 @@ namespace zsy
} }
} }
if (list == nullptr || list->size() == 0) if (list == nullptr || list->empty())
{ {
return; return;
} }
for (const auto &fn_ptr: *list)
threadPool->submit([list, name, data]
{ {
for (auto fn_ptr: *list) try
{ {
try (*fn_ptr.get())(Event(name, data));
{ } catch (const std::exception &e)
(*fn_ptr.get())(Event(name, data)); {
} catch (const std::exception &e) LOGGER_ERROR("事件处理异常:{} {}", name, e.what());
{ } catch (...)
LOGGER_ERROR("事件处理异常:{} {}", name, e.what()); {
}catch (...) LOGGER_ERROR("事件处理异常:{}", name);
{
LOGGER_ERROR("事件处理异常:{}", name);
}
} }
}); }
/*threadPool->submit([list, name, data]
{
});*/
} }
} // zsy } // zsy

View File

@ -17,11 +17,11 @@ namespace zsy
15 15
); );
file_sink->set_level(spdlog::level::info); 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<spdlog::sinks::stdout_color_sink_mt>(); const auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::info); 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}; spdlog::sinks_init_list sinks = {console_sink, file_sink};
auto logger = std::make_shared<spdlog::logger>("zsy", sinks); auto logger = std::make_shared<spdlog::logger>("zsy", sinks);

View File

@ -3,11 +3,12 @@
#include "barrier/generic_barrier.h" #include "barrier/generic_barrier.h"
#include "platform_scale/generic_platform_scale.h" #include "platform_scale/generic_platform_scale.h"
#include "sound_column/generic_sound_column.h" #include "sound_column/generic_sound_column.h"
#include "vidicon/generic_vidicon.h" // #include "vidicon/generic_vidicon.h"
// #include "vidicon/barrier_vidicon.h" #include "vidicon/barrier_vidicon.h"
namespace zsy { namespace zsy
void DeviceHolder::initBarriers(std::vector<BarrierProperties> &configs) {
void DeviceHolder::initBarriers(std::vector<BarrierProperties> &configs)
{ {
for (auto &config: configs) for (auto &config: configs)
{ {
@ -39,8 +40,8 @@ namespace zsy {
{ {
for (auto &config: configs) for (auto &config: configs)
{ {
vidicons.emplace(config.sn, std::make_shared<GenericVidicon>(config)); // vidicons.emplace(config.sn, std::make_shared<GenericVidicon>(config));
// vidicons.emplace(config.sn, std::make_shared<BarrierVidicon>(config)); vidicons.emplace(config.sn, std::make_shared<BarrierVidicon>(config));
} }
} }
@ -86,5 +87,4 @@ namespace zsy {
auto sn = map.at("vidicon"); auto sn = map.at("vidicon");
return vidicons.contains(sn) ? vidicons.at(sn) : nullptr; return vidicons.contains(sn) ? vidicons.at(sn) : nullptr;
} }
} // zsy } // zsy

View File

@ -94,11 +94,11 @@ namespace zsy
try try
{ {
LOGGER_INFO("正在读取地磅数据,设备名称:{}", config.name); LOGGER_INFO("正在读取地磅数据,设备名称:{}", config.name);
if (status != 1) /*if (status != 1)
{ {
LOGGER_INFO("无法称重,地磅状态:{}", status); LOGGER_INFO("无法称重,地磅状态:{}", status);
return 0.0; return 0.0;
} }*/
int retry_count = 0; int retry_count = 0;
while ((serialPort->status.load() == 3 || serialPort->readStatus.load() == 3) && retry_count < 10) 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) if (serialPort->status.load() == 3 || serialPort->readStatus.load() == 3)
{ {
LOGGER_ERROR("无法称重,串口异常,重试失败"); LOGGER_ERROR("无法称重,串口异常,重试失败");
status = 1; /*status = 1;*/
return 0.0; return 0.0;
} }
status = 2; /*status = 2;*/
LOGGER_INFO("正在称重..."); LOGGER_INFO("正在称重...");
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
auto processor = static_cast<GenericPlatformScaleProcessor *>(serialPort->processor); auto processor = static_cast<GenericPlatformScaleProcessor *>(serialPort->processor);
@ -128,22 +128,21 @@ namespace zsy
if (count >= 10) if (count >= 10)
{ {
LOGGER_ERROR("称重失败,连续 {} 次未稳定", count); LOGGER_ERROR("称重失败,连续 {} 次未稳定", count);
status = 1; /*status = 1;*/
return 0.0; return 0.0;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); std::this_thread::sleep_for(std::chrono::milliseconds(3000));
} }
auto res = processor->weight.load(); auto res = processor->weight.load();
LOGGER_INFO("称重完成:{} KG", res); LOGGER_INFO("称重完成:{} KG", res);
status = 1; /*status = 1;*/
return res; return res;
} catch (std::exception &e) } catch (std::exception &e)
{ {
LOGGER_ERROR("称重失败:{}", e.what()); LOGGER_ERROR("称重失败:{}", e.what());
status = 4; status = 4;
return 0.0; return 0.0;
} } catch (...)
catch (...)
{ {
LOGGER_ERROR("未知异常,称重失败"); LOGGER_ERROR("未知异常,称重失败");
status = 4; status = 4;

View File

@ -32,7 +32,7 @@ namespace zsy
} catch (const std::exception &e) } catch (const std::exception &e)
{ {
LOGGER_ERROR("图片保存失败"); LOGGER_ERROR("图片保存失败");
}catch (...) } catch (...)
{ {
LOGGER_ERROR("未知异常,图片保存失败"); LOGGER_ERROR("未知异常,图片保存失败");
} }
@ -90,7 +90,7 @@ namespace zsy
{ {
"payload", { "payload", {
{"type", "snapshot"}, {"type", "snapshot"},
{"body", {}}, {"body", nlohmann::json::object()},
} }
} }
}; };
@ -141,8 +141,7 @@ namespace zsy
{ {
LOGGER_ERROR("摄像机拍照失败:{}", e.what()); LOGGER_ERROR("摄像机拍照失败:{}", e.what());
return nullptr; return nullptr;
} } catch (...)
catch (...)
{ {
LOGGER_ERROR("未知异常,摄像机拍照失败"); LOGGER_ERROR("未知异常,摄像机拍照失败");
return nullptr; return nullptr;