修复问题
parent
02685679ef
commit
62ba7d9a11
|
@ -27,6 +27,7 @@ set(SOURCE_DIRS
|
||||||
src/barrier
|
src/barrier
|
||||||
src/sound_column
|
src/sound_column
|
||||||
src/http
|
src/http
|
||||||
|
src/controller
|
||||||
src/mqtt
|
src/mqtt
|
||||||
src/oss
|
src/oss
|
||||||
src/serial_port
|
src/serial_port
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
{
|
{
|
||||||
|
"name": "测试",
|
||||||
|
"delay": 0,
|
||||||
|
"daemon": false,
|
||||||
"httpSvr": {
|
"httpSvr": {
|
||||||
"port": 11000
|
"port": 11000
|
||||||
},
|
},
|
||||||
"oss": {
|
"oss": {
|
||||||
"endpoint": "oss-cn-shanghai.aliyuncs.com",
|
"endpoint": "localhost",
|
||||||
"bucketName": "tq-cdn",
|
"bucketName": "a",
|
||||||
"ak": "LTAI5t9ppUx8fkEnPwnNwmnx",
|
"ak": "a",
|
||||||
"sk": "uxrwL01P1Nw6M3YRFWoMIluY4swKwC"
|
"sk": "a"
|
||||||
},
|
},
|
||||||
"mqtts": [
|
"mqtts": [
|
||||||
{
|
{
|
||||||
|
@ -45,15 +48,15 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"reportSvr": {
|
"reportSvr": {
|
||||||
"server": "https://biz-api.jstqhj.cn:443",
|
"server": "http://127.0.0.1:11000",
|
||||||
"passUrl": "/api/site/report-car-pass?debug=1",
|
"passUrl": "/api/site/report-car-pass?debug=1",
|
||||||
"reportUrl": "/api/site/report-v2?debug=1"
|
"reportUrl": "/api/site/report-v2?debug=1"
|
||||||
},
|
},
|
||||||
"barriers": [
|
"barriers": [
|
||||||
{
|
{
|
||||||
"name": "进前置",
|
"name": "进前置",
|
||||||
"sn": "b11ceeb5-af42d80f",
|
"sn": "1",
|
||||||
"ip": "192.168.120.240",
|
"ip": "127.0.0.1",
|
||||||
"io": 0,
|
"io": 0,
|
||||||
"platformScale": "1",
|
"platformScale": "1",
|
||||||
"soundColumn": "1",
|
"soundColumn": "1",
|
||||||
|
@ -61,30 +64,30 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "进",
|
"name": "进",
|
||||||
"sn": "25ec7559-74125e77",
|
"sn": "2",
|
||||||
"ip": "192.168.120.235",
|
"ip": "127.0.0.1",
|
||||||
"io": 0,
|
"io": 0,
|
||||||
"platformScale": "1",
|
"platformScale": "1",
|
||||||
"soundColumn": "2",
|
"soundColumn": "1",
|
||||||
"vidicon": "1"
|
"vidicon": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "出前置",
|
"name": "出前置",
|
||||||
"sn": "351b2406-6fae5ab5",
|
"sn": "3",
|
||||||
"ip": "192.168.120.243",
|
"ip": "127.0.0.1",
|
||||||
"io": 0,
|
|
||||||
"platformScale": "1",
|
|
||||||
"soundColumn": "2",
|
|
||||||
"vidicon": "2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "出",
|
|
||||||
"sn": "34fc9ce5-8b091060",
|
|
||||||
"ip": "192.168.120.238",
|
|
||||||
"io": 0,
|
"io": 0,
|
||||||
"platformScale": "1",
|
"platformScale": "1",
|
||||||
"soundColumn": "1",
|
"soundColumn": "1",
|
||||||
"vidicon": "2"
|
"vidicon": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "出",
|
||||||
|
"sn": "4",
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"io": 0,
|
||||||
|
"platformScale": "1",
|
||||||
|
"soundColumn": "1",
|
||||||
|
"vidicon": "1"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"platformScales": [
|
"platformScales": [
|
||||||
|
@ -93,7 +96,7 @@
|
||||||
"name": "地磅",
|
"name": "地磅",
|
||||||
"sample": 20,
|
"sample": 20,
|
||||||
"port": "COM2",
|
"port": "COM2",
|
||||||
"baudRate": 1200,
|
"baudRate": 9600,
|
||||||
"byteSize": 8,
|
"byteSize": 8,
|
||||||
"parity": 0,
|
"parity": 0,
|
||||||
"stopBits": 0
|
"stopBits": 0
|
||||||
|
@ -103,32 +106,18 @@
|
||||||
{
|
{
|
||||||
"sn": "1",
|
"sn": "1",
|
||||||
"name": "音柱1",
|
"name": "音柱1",
|
||||||
"server": "http://192.168.120.246:80",
|
"server": "http://127.0.0.1:11000",
|
||||||
"path": "/v1/speech"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"sn": "2",
|
|
||||||
"name": "音柱2",
|
|
||||||
"server": "http://192.168.120.237:80",
|
|
||||||
"path": "/v1/speech"
|
"path": "/v1/speech"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"vidicons": [
|
"vidicons": [
|
||||||
{
|
{
|
||||||
"sn": "1",
|
"sn": "1",
|
||||||
"name": "摄像头1",
|
"name": "摄像头",
|
||||||
"ip": "192.168.120.245",
|
"ip": "",
|
||||||
"port": 8000,
|
"port": 8000,
|
||||||
"username": "admin",
|
"username": "",
|
||||||
"passwd": "gk147258"
|
"passwd": ""
|
||||||
},
|
|
||||||
{
|
|
||||||
"sn": "2",
|
|
||||||
"name": "摄像头2",
|
|
||||||
"ip": "192.168.120.244",
|
|
||||||
"port": 8000,
|
|
||||||
"username": "admin",
|
|
||||||
"passwd": "gk147258"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -16,6 +16,8 @@ namespace zsy
|
||||||
|
|
||||||
std::shared_ptr<DeviceHolder> Application::deviceHolder = nullptr;
|
std::shared_ptr<DeviceHolder> Application::deviceHolder = nullptr;
|
||||||
|
|
||||||
|
std::shared_ptr<Test> Application::test = nullptr;
|
||||||
|
|
||||||
void Application::loadConfig()
|
void Application::loadConfig()
|
||||||
{
|
{
|
||||||
LOGGER_INFO("正在加载配置文件:{}", configFile);
|
LOGGER_INFO("正在加载配置文件:{}", configFile);
|
||||||
|
@ -109,7 +111,7 @@ namespace zsy
|
||||||
LOGGER_INFO("等待...");
|
LOGGER_INFO("等待...");
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(appProperties.delay * 1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(appProperties.delay * 1000));
|
||||||
}
|
}
|
||||||
threadPool = std::make_shared<ThreadPool>();
|
threadPool = std::make_shared<ThreadPool>(4);
|
||||||
|
|
||||||
eventManager = std::make_shared<EventManager>(threadPool);
|
eventManager = std::make_shared<EventManager>(threadPool);
|
||||||
|
|
||||||
|
@ -122,6 +124,8 @@ namespace zsy
|
||||||
reportSvr = std::make_shared<ReportSvr>(config);
|
reportSvr = std::make_shared<ReportSvr>(config);
|
||||||
|
|
||||||
deviceHolder = std::make_shared<DeviceHolder>(config);
|
deviceHolder = std::make_shared<DeviceHolder>(config);
|
||||||
|
|
||||||
|
test = std::make_shared<Test>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::run()
|
void Application::run()
|
||||||
|
|
|
@ -5,19 +5,21 @@
|
||||||
#include "report_svr/report_svr.h"
|
#include "report_svr/report_svr.h"
|
||||||
#include "oss/oss.h"
|
#include "oss/oss.h"
|
||||||
#include "device_holder.h"
|
#include "device_holder.h"
|
||||||
|
#include "controller/test.h"
|
||||||
namespace zsy
|
namespace zsy
|
||||||
{
|
{
|
||||||
struct AppProperties
|
struct AppProperties
|
||||||
{
|
{
|
||||||
bool daemon{false};
|
bool daemon{false};
|
||||||
uint32_t delay{0};
|
uint32_t delay{0};
|
||||||
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void from_json(const nlohmann::json &j, AppProperties &o)
|
inline void from_json(const nlohmann::json &j, AppProperties &o)
|
||||||
{
|
{
|
||||||
PARSE_JSON(daemon, o.daemon);
|
PARSE_JSON(daemon, o.daemon);
|
||||||
PARSE_JSON(delay, o.delay);
|
PARSE_JSON(delay, o.delay);
|
||||||
|
PARSE_JSON(name, o.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Application
|
class Application
|
||||||
|
@ -50,6 +52,8 @@ namespace zsy
|
||||||
|
|
||||||
static std::shared_ptr<DeviceHolder> deviceHolder;
|
static std::shared_ptr<DeviceHolder> deviceHolder;
|
||||||
|
|
||||||
|
static std::shared_ptr<Test> test;
|
||||||
|
|
||||||
Application(const std::string &configFile);
|
Application(const std::string &configFile);
|
||||||
|
|
||||||
static void run();
|
static void run();
|
||||||
|
|
|
@ -46,94 +46,8 @@ namespace zsy
|
||||||
LOGGER_ERROR("未找到 MQTT 远程客户端");
|
LOGGER_ERROR("未找到 MQTT 远程客户端");
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::httpSvr->getEndpoint("/weight", [](const httplib::Request &req, httplib::Response &res)
|
|
||||||
{
|
|
||||||
nlohmann::json j;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto sn = req.get_param_value("sn");
|
|
||||||
double weight = Application::deviceHolder->getPlatformScale(sn)->reading();
|
|
||||||
j["结果"] = weight;
|
|
||||||
} catch (std::exception &e)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误", e.what());
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误");
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
res.set_content(j.dump(), "application/json");
|
|
||||||
});
|
|
||||||
|
|
||||||
Application::httpSvr->getEndpoint("/opendoor", [](const httplib::Request &req, httplib::Response &res)
|
|
||||||
{
|
|
||||||
nlohmann::json j;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto sn = req.get_param_value("sn");
|
|
||||||
Application::deviceHolder->getBarrier(sn)->open();
|
|
||||||
j["结果"] = "成功";
|
|
||||||
} catch (std::exception &e)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误", e.what());
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误");
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
res.set_content(j.dump(), "application/json");
|
|
||||||
});
|
|
||||||
|
|
||||||
Application::httpSvr->getEndpoint("/playvoice", [](const httplib::Request &req, httplib::Response &res)
|
|
||||||
{
|
|
||||||
nlohmann::json j;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto sn = req.get_param_value("sn");
|
|
||||||
Application::deviceHolder->getSoundColumn(sn)->play("欢迎光临");
|
|
||||||
j["结果"] = "成功";
|
|
||||||
} catch (std::exception &e)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误", e.what());
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误");
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
res.set_content(j.dump(), "application/json");
|
|
||||||
});
|
|
||||||
|
|
||||||
Application::httpSvr->getEndpoint("/photo", [](const httplib::Request &req, httplib::Response &res)
|
|
||||||
{
|
|
||||||
nlohmann::json j;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto sn = req.get_param_value("sn");
|
|
||||||
auto photograph = Application::deviceHolder->getVidicon(sn)->photograph();
|
|
||||||
j["结果"] = photograph;
|
|
||||||
} catch (std::exception &e)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误", e.what());
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("错误");
|
|
||||||
j["结果"] = "错误";
|
|
||||||
}
|
|
||||||
res.set_content(j.dump(), "application/json");
|
|
||||||
});
|
|
||||||
|
|
||||||
Application::httpSvr->postEndpoint("/plateRecognize", [](const httplib::Request &req, httplib::Response &res)
|
Application::httpSvr->postEndpoint("/plateRecognize", [](const httplib::Request &req, httplib::Response &res)
|
||||||
{
|
{
|
||||||
// static std::unordered_map<std::string, long long> cache;
|
|
||||||
// static std::mutex cacheMutex;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto body = req.body;
|
auto body = req.body;
|
||||||
|
@ -161,36 +75,6 @@ namespace zsy
|
||||||
res.set_content(R"({})", "application/json");
|
res.set_content(R"({})", "application/json");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
||||||
auto key = serialno + license;
|
|
||||||
long long time = ms + 60000 * 5;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(cacheMutex);
|
|
||||||
std::erase_if(cache, [time](const auto &pair)
|
|
||||||
{
|
|
||||||
return pair.second >= time;
|
|
||||||
});
|
|
||||||
if (cache.contains(key))
|
|
||||||
{
|
|
||||||
if (cache[key] < time)
|
|
||||||
{
|
|
||||||
res.set_content(R"({})", "application/json");
|
|
||||||
LOGGER_INFO("重复的车牌识别结果:{} {}", serialno, license);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache[key] = ms;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*std::jthread t1([imageFile,license, barrier = Application::deviceHolder->getBarrier(serialno)]
|
|
||||||
{
|
|
||||||
if (!barrier)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("未找到对应的道闸");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
barrier->resolveRecognizeResult(license, imageFile);
|
|
||||||
});*/
|
|
||||||
Application::threadPool->submit([imageFile,license, barrier = Application::deviceHolder->getBarrier(serialno)]
|
Application::threadPool->submit([imageFile,license, barrier = Application::deviceHolder->getBarrier(serialno)]
|
||||||
{
|
{
|
||||||
if (!barrier)
|
if (!barrier)
|
||||||
|
|
|
@ -102,9 +102,19 @@ namespace zsy
|
||||||
|
|
||||||
std::string DailyAndSizeSink::today()
|
std::string DailyAndSizeSink::today()
|
||||||
{
|
{
|
||||||
|
// 获取当前时间点
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
auto local_time = std::chrono::zoned_time{std::chrono::current_zone(), now};
|
time_t current_time = std::chrono::system_clock::to_time_t(now);
|
||||||
return std::format("{:%F}", local_time);
|
|
||||||
|
// 转换为本地时间
|
||||||
|
tm local_tm;
|
||||||
|
localtime_s(&local_tm, ¤t_time); // 安全版本的 localtime
|
||||||
|
|
||||||
|
// 格式化日期为 YYYY-MM-DD 格式
|
||||||
|
char buffer[11]; // 足够存储 "YYYY-MM-DD\0"
|
||||||
|
strftime(buffer, sizeof(buffer), "%F", &local_tm);
|
||||||
|
|
||||||
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t DailyAndSizeSink::lastIndex()
|
uint32_t DailyAndSizeSink::lastIndex()
|
||||||
|
|
|
@ -15,7 +15,6 @@ namespace zsy
|
||||||
{
|
{
|
||||||
class DailyAndSizeSink final : public spdlog::sinks::base_sink<std::mutex>
|
class DailyAndSizeSink final : public spdlog::sinks::base_sink<std::mutex>
|
||||||
{
|
{
|
||||||
bool init;
|
|
||||||
std::string basePath;
|
std::string basePath;
|
||||||
std::string baseFilename;
|
std::string baseFilename;
|
||||||
std::string baseExt;
|
std::string baseExt;
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace zsy
|
||||||
|
|
||||||
for (auto fn_ptr: *list)
|
for (auto fn_ptr: *list)
|
||||||
{
|
{
|
||||||
try
|
/*try
|
||||||
{
|
{
|
||||||
(*fn_ptr.get())(Event(name, data));
|
(*fn_ptr.get())(Event(name, data));
|
||||||
} catch (const std::exception &e)
|
} catch (const std::exception &e)
|
||||||
|
@ -47,8 +47,8 @@ namespace zsy
|
||||||
}catch (...)
|
}catch (...)
|
||||||
{
|
{
|
||||||
LOGGER_ERROR("事件处理异常:{}", name);
|
LOGGER_ERROR("事件处理异常:{}", name);
|
||||||
}
|
}*/
|
||||||
/*threadPool->submit([fn = fn_ptr.get(),name,data]
|
threadPool->submit([fn = fn_ptr.get(),name,data]
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ namespace zsy
|
||||||
{
|
{
|
||||||
LOGGER_ERROR("事件处理异常:{}", name);
|
LOGGER_ERROR("事件处理异常:{}", name);
|
||||||
}
|
}
|
||||||
});*/
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // zsy
|
} // zsy
|
||||||
|
|
|
@ -4,18 +4,21 @@
|
||||||
|
|
||||||
namespace zsy
|
namespace zsy
|
||||||
{
|
{
|
||||||
ThreadPool::ThreadPool(size_t threadCount):status(0)
|
ThreadPool::ThreadPool(size_t threadCount): status(0)
|
||||||
{
|
{
|
||||||
if (threadCount < 1) threadCount = 1;
|
if (threadCount < 1) threadCount = 1;
|
||||||
workers.reserve(threadCount);
|
workers.reserve(threadCount);
|
||||||
|
{
|
||||||
|
std::unique_lock lock(status_mtx);
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
for (size_t i = 0; i < threadCount; ++i)
|
for (size_t i = 0; i < threadCount; ++i)
|
||||||
{
|
{
|
||||||
workers.emplace_back([this](const std::stop_token &st)
|
workers.emplace_back([this](const std::stop_token &st)
|
||||||
|
|
||||||
{
|
{
|
||||||
while (!st.stop_requested())
|
while (!st.stop_requested())
|
||||||
{
|
{
|
||||||
|
std::function<void()> task;
|
||||||
{
|
{
|
||||||
std::unique_lock lock(queueMutex);
|
std::unique_lock lock(queueMutex);
|
||||||
taskCondition.wait(lock, st, [this]
|
taskCondition.wait(lock, st, [this]
|
||||||
|
@ -28,26 +31,23 @@ namespace zsy
|
||||||
LOGGER_INFO("已停止线程");
|
LOGGER_INFO("已停止线程");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::function<void()> &task = tasks.front();
|
task = std::move(tasks.front());
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (task) task();
|
|
||||||
} catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("任务执行失败: {}", e.what());
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
LOGGER_ERROR("未知异常,任务执行失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.pop();
|
tasks.pop();
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (task) task();
|
||||||
|
} catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("任务执行失败: {}", e.what());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("未知异常,任务执行失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
status = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool::~ThreadPool()
|
ThreadPool::~ThreadPool()
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
#include "test.h"
|
||||||
|
#include "application.h"
|
||||||
|
|
||||||
|
namespace zsy
|
||||||
|
{
|
||||||
|
Test::Test()
|
||||||
|
{
|
||||||
|
Application::httpSvr->postEndpoint("/api/site/report-car-pass", [this](const httplib::Request &req, httplib::Response &res)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
std::string data = R"({
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"car_number": "",
|
||||||
|
"type": 2,
|
||||||
|
"order_no": "",
|
||||||
|
"err_msg": "",
|
||||||
|
"scene": "",
|
||||||
|
"no_weight": false
|
||||||
|
}
|
||||||
|
})";
|
||||||
|
res.set_content(data, "application/json");
|
||||||
|
});
|
||||||
|
Application::httpSvr->postEndpoint("/api/site/report-v2", [this](const httplib::Request &req, httplib::Response &res)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
std::string data = R"({
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"car_number": "",
|
||||||
|
"order_no": "",
|
||||||
|
"lane_code": ""
|
||||||
|
}
|
||||||
|
})";
|
||||||
|
res.set_content(data, "application/json");
|
||||||
|
});
|
||||||
|
Application::httpSvr->postEndpoint("/v1/speech", [this](const httplib::Request &req, httplib::Response &res)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
std::string data = R"({
|
||||||
|
"code": 200,
|
||||||
|
"message": "播放成功"
|
||||||
|
})";
|
||||||
|
res.set_content(data, "application/json");
|
||||||
|
});
|
||||||
|
|
||||||
|
Application::httpSvr->getEndpoint("/weight", [](const httplib::Request &req, httplib::Response &res)
|
||||||
|
{
|
||||||
|
nlohmann::json j;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto sn = req.get_param_value("sn");
|
||||||
|
double weight = Application::deviceHolder->getPlatformScale(sn)->reading();
|
||||||
|
j["结果"] = weight;
|
||||||
|
} catch (std::exception &e)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误", e.what());
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误");
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
res.set_content(j.dump(), "application/json");
|
||||||
|
});
|
||||||
|
|
||||||
|
Application::httpSvr->getEndpoint("/opendoor", [](const httplib::Request &req, httplib::Response &res)
|
||||||
|
{
|
||||||
|
nlohmann::json j;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto sn = req.get_param_value("sn");
|
||||||
|
Application::deviceHolder->getBarrier(sn)->open();
|
||||||
|
j["结果"] = "成功";
|
||||||
|
} catch (std::exception &e)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误", e.what());
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误");
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
res.set_content(j.dump(), "application/json");
|
||||||
|
});
|
||||||
|
|
||||||
|
Application::httpSvr->getEndpoint("/play", [](const httplib::Request &req, httplib::Response &res)
|
||||||
|
{
|
||||||
|
nlohmann::json j;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto sn = req.get_param_value("sn");
|
||||||
|
Application::deviceHolder->getSoundColumn(sn)->play("欢迎光临");
|
||||||
|
j["结果"] = "成功";
|
||||||
|
} catch (std::exception &e)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误", e.what());
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误");
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
res.set_content(j.dump(), "application/json");
|
||||||
|
});
|
||||||
|
|
||||||
|
Application::httpSvr->getEndpoint("/photo", [](const httplib::Request &req, httplib::Response &res)
|
||||||
|
{
|
||||||
|
nlohmann::json j;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto sn = req.get_param_value("sn");
|
||||||
|
auto photograph = Application::deviceHolder->getVidicon(sn)->photograph();
|
||||||
|
j["结果"] = photograph;
|
||||||
|
} catch (std::exception &e)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误", e.what());
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("错误");
|
||||||
|
j["结果"] = "错误";
|
||||||
|
}
|
||||||
|
res.set_content(j.dump(), "application/json");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef TEST_H
|
||||||
|
#define TEST_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace zsy
|
||||||
|
{
|
||||||
|
class Test
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Test();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //TEST_H
|
|
@ -3,8 +3,8 @@
|
||||||
#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)
|
||||||
|
@ -39,8 +39,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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ namespace zsy
|
||||||
auto cli = Application::mqttCliHolder->localCli();
|
auto cli = Application::mqttCliHolder->localCli();
|
||||||
if (cli)
|
if (cli)
|
||||||
{
|
{
|
||||||
// std::unique_lock<std::mutex> lock(mtx);
|
|
||||||
hasNewContent.store(false);
|
hasNewContent.store(false);
|
||||||
imageContent = "";
|
imageContent = "";
|
||||||
cli->publish(topic, data, 0);
|
cli->publish(topic, data, 0);
|
||||||
|
@ -126,11 +125,8 @@ namespace zsy
|
||||||
|
|
||||||
const auto filename = "car_body_" + Snowflake::genIdStr() + ".jpg";
|
const auto filename = "car_body_" + Snowflake::genIdStr() + ".jpg";
|
||||||
std::string path = SysUtil::HOME_DIR + "\\temp\\" + filename;
|
std::string path = SysUtil::HOME_DIR + "\\temp\\" + filename;
|
||||||
LOGGER_INFO("解码前:{}", imageContent);
|
|
||||||
auto content = SysUtil::base64_decode(imageContent);
|
auto content = SysUtil::base64_decode(imageContent);
|
||||||
LOGGER_INFO("解码后:{}", content);
|
|
||||||
bool res = saveImageToFile(content, path);
|
bool res = saveImageToFile(content, path);
|
||||||
LOGGER_INFO("文件保存结果:{}", res);
|
|
||||||
return path;
|
return path;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace zsy
|
||||||
public:
|
public:
|
||||||
~BarrierVidicon() override;
|
~BarrierVidicon() override;
|
||||||
|
|
||||||
BarrierVidicon(const VidiconProperties &config);
|
explicit BarrierVidicon(const VidiconProperties &config);
|
||||||
|
|
||||||
std::string photograph() override;
|
std::string photograph() override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "test_vidicon.h"
|
||||||
|
|
||||||
|
namespace zsy {
|
||||||
|
std::string TestVidicon::photograph()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} // zsy
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef TEST_VIDICON_H
|
||||||
|
#define TEST_VIDICON_H
|
||||||
|
#include "vidicon.h"
|
||||||
|
|
||||||
|
namespace zsy
|
||||||
|
{
|
||||||
|
class TestVidicon : public Vidicon
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string photograph() override;
|
||||||
|
};
|
||||||
|
} // zsy
|
||||||
|
|
||||||
|
#endif //TEST_VIDICON_H
|
Loading…
Reference in New Issue