mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
调试预制舱通讯协议修改数据解析
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include "common/JsonN.h"
|
||||
#include "common/Spdlogger.h"
|
||||
#include "AppData.h"
|
||||
#include "protocol/MqttEntity.h"
|
||||
|
||||
AppOption Config::option;
|
||||
|
||||
@@ -20,106 +19,49 @@ bool Config::init(std::string filename)
|
||||
}
|
||||
spdlog::info("[config] load config file success, filename={}", filename);
|
||||
|
||||
JSON::read(jsonroot, "debug", option.debug);
|
||||
JSON::read(jsonroot, "weburl", option.webSrvUrl);
|
||||
JSON::read(jsonroot, "launchdate", option.lunchDate);
|
||||
|
||||
|
||||
if (jsonroot.contains("database"))
|
||||
{
|
||||
njson& json = jsonroot.at("database");
|
||||
njson json = jsonroot.at("database");
|
||||
JSON::read(json, "host", option.database.host);
|
||||
JSON::read(json, "port", option.database.port);
|
||||
JSON::read(json, "user", option.database.user);
|
||||
JSON::read(json, "passwd", option.database.passwd);
|
||||
JSON::read(json, "dbname", option.database.dbname);
|
||||
|
||||
spdlog::info("[config] parse database success. host={}", option.database.host);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[config] parse database failed: not found.");
|
||||
spdlog::info("[config] parse database failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("http"))
|
||||
{
|
||||
njson& json = jsonroot.at("http");
|
||||
JSON::read(json, "token", option.http.useToken);
|
||||
njson json = jsonroot.at("http");
|
||||
std:string token;
|
||||
JSON::read(json, "token", token);
|
||||
option.http.useToken = !token.empty();
|
||||
JSON::read(json, "port", option.http.port);
|
||||
JSON::read(json, "encryption", option.http.encryption);
|
||||
JSON::read(json, "encryptKey", option.http.encryptKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[config] parse http failed: not found.");
|
||||
spdlog::info("[config] parse http failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("mqtt"))
|
||||
{
|
||||
njson& json = jsonroot.at("mqtt");
|
||||
njson json = jsonroot.at("mqtt");
|
||||
JSON::read(json, "host", option.mqtt.host);
|
||||
JSON::read(json, "username", option.mqtt.username);
|
||||
JSON::read(json, "password", option.mqtt.password);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[config] parse mqtt failed: not found.");
|
||||
spdlog::info("[config] parse mqtt failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("view"))
|
||||
{
|
||||
njson& json = jsonroot["view"];
|
||||
JSON::read(json, "latitude", option.view.latitude);
|
||||
JSON::read(json, "longitude", option.view.longitude);
|
||||
JSON::read(json, "altitude", option.view.altitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[config] parse view failed: not found.");
|
||||
}
|
||||
JSON::read(jsonroot, "weburl", option.webSrvUrl);
|
||||
JSON::read(jsonroot, "launchdate", option.lunchDate);
|
||||
|
||||
if (jsonroot.contains("video"))
|
||||
{
|
||||
njson& json = jsonroot["video"];
|
||||
for (auto& item: json.items())
|
||||
{
|
||||
auto& key = item.key();
|
||||
auto& jsonItem = item.value();
|
||||
auto& itemVideo = option.mapVideo[key];
|
||||
JSON::read(jsonItem, "host", itemVideo.host);
|
||||
JSON::read(jsonItem, "port", itemVideo.port);
|
||||
JSON::read(jsonItem, "user", itemVideo.user);
|
||||
JSON::read(jsonItem, "passwd", itemVideo.passwd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[config] parse video failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("topic"))
|
||||
{
|
||||
njson& json = jsonroot["topic"];
|
||||
for (auto& item: json.items())
|
||||
{
|
||||
auto& key = item.key();
|
||||
auto& jsonItem = item.value();
|
||||
auto& info = MqttClient::s_mapTopicInfo[key];
|
||||
info.name = key;
|
||||
JSON::read(jsonItem, "deviceType", info.deviceType);
|
||||
JSON::read(jsonItem, "polling", info.polling);
|
||||
JSON::read(jsonItem, "enabled", info.enabled);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
AppOption::VideoInfo* Config::getVideoInfo(std::string name)
|
||||
{
|
||||
auto iter = option.mapVideo.find(name);
|
||||
if (iter!=option.mapVideo.end())
|
||||
{
|
||||
return &(iter->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user