mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
调试修改MQTT通讯解析
This commit is contained in:
@@ -1,62 +1,57 @@
|
||||
#include "DataStruct.h"
|
||||
#include "common/JsonN.h"
|
||||
#include "common/Utils.h"
|
||||
|
||||
void EMSYX::fromJson(const std::string& str)
|
||||
std::string REGAddrOffset(std::string addr, int offset)
|
||||
{
|
||||
njson jsonroot;
|
||||
auto ret = JSON::parse(str, jsonroot);
|
||||
if (!ret) { return; }
|
||||
JSON::read(jsonroot, "mcu", mcu);
|
||||
JSON::read(jsonroot, "pcs", pcs);
|
||||
JSON::read(jsonroot, "electMeterMainPoint", electMeterMainPoint);
|
||||
JSON::read(jsonroot, "electMeter", electMeter);
|
||||
JSON::read(jsonroot, "fireSystem", fireSystem);
|
||||
JSON::read(jsonroot, "ups", ups);
|
||||
JSON::read(jsonroot, "temHumMainPoint", temHumMainPoint);
|
||||
JSON::read(jsonroot, "temHum", temHum);
|
||||
JSON::read(jsonroot, "aircMainPoint", aircMainPoint);
|
||||
JSON::read(jsonroot, "airc", airc);
|
||||
JSON::read(jsonroot, "controlDryContact", controlDryContact);
|
||||
JSON::read(jsonroot, "statusDryContact", statusDryContact);
|
||||
JSON::read(jsonroot, "bcuMain", bcuMain);
|
||||
JSON::read(jsonroot, "pcuMain", pcuMain);
|
||||
JSON::read(jsonroot, "electMeterMain", electMeterMain);
|
||||
JSON::read(jsonroot, "fireSystemMain", fireSystemMain);
|
||||
JSON::read(jsonroot, "upsMain", upsMain);
|
||||
JSON::read(jsonroot, "temHumMain", temHumMain);
|
||||
JSON::read(jsonroot, "aircMain", aircMain);
|
||||
JSON::read(jsonroot, "emu", emu);
|
||||
JSON::read(jsonroot, "chillerMain", chillerMain);
|
||||
JSON::read(jsonroot, "chillerMainPoint", chillerMainPoint);
|
||||
JSON::read(jsonroot, "chiller", chiller);
|
||||
unsigned int val;
|
||||
std::stringstream ss;
|
||||
ss << std::hex << addr;
|
||||
ss >> val;
|
||||
return Utils::toHexStr(val + offset);
|
||||
}
|
||||
|
||||
std::string EMSYX::toJson()
|
||||
std::map<std::string, std::map<std::string, RegAddrUnit>> REGAddr::s_mapReg;
|
||||
|
||||
|
||||
void REGAddr::load(std::string filename)
|
||||
{
|
||||
njson jsonroot;
|
||||
jsonroot["bms"] = bms;
|
||||
jsonroot["bcu"] = bcu;
|
||||
jsonroot["mcu"] = mcu;
|
||||
jsonroot["pcs"] = pcs;
|
||||
jsonroot["electMeterMainPoint"] = electMeterMainPoint;
|
||||
jsonroot["electMeter"] = electMeter;
|
||||
jsonroot["fireSystem"] = fireSystem;
|
||||
jsonroot["ups"] = ups;
|
||||
jsonroot["temHumMainPoint"] = temHumMainPoint;
|
||||
jsonroot["temHum"] = temHum;
|
||||
jsonroot["aircMainPoint"] = aircMainPoint;
|
||||
jsonroot["airc"] = airc;
|
||||
jsonroot["controlDryContact"] = controlDryContact;
|
||||
jsonroot["statusDryContact"] = statusDryContact;
|
||||
jsonroot["bcuMain"] = bcuMain;
|
||||
jsonroot["pcuMain"] = pcuMain;
|
||||
jsonroot["electMeterMain"] = electMeterMain;
|
||||
jsonroot["fireSystemMain"] = fireSystemMain;
|
||||
jsonroot["upsMain"] = upsMain;
|
||||
jsonroot["temHumMain"] = temHumMain;
|
||||
jsonroot["aircMain"] = aircMain;
|
||||
jsonroot["emu"] = emu;
|
||||
jsonroot["chillerMain"] = chillerMain;
|
||||
jsonroot["chillerMainPoint"] = chillerMainPoint;
|
||||
jsonroot["chiller"] = chiller;
|
||||
return jsonroot.dump();
|
||||
njson json;
|
||||
JSON::load(filename, json);
|
||||
|
||||
// 遍历 JSON 对象
|
||||
for (auto& jsonitem : json.items())
|
||||
{
|
||||
std::string name = jsonitem.key();
|
||||
auto& jsonnodeItem = jsonitem.value();
|
||||
//int count = jsonnodeItem["count"];
|
||||
auto jsonaddrs = jsonnodeItem["addr"];
|
||||
|
||||
auto& mapItem = s_mapReg[name];
|
||||
int size = 0;
|
||||
for (int i = 0; i<2; ++i)
|
||||
{
|
||||
for (auto& item : jsonaddrs)
|
||||
{
|
||||
std::string addr = item["key"];
|
||||
mapItem[addr] = RegAddrUnit(addr, item["datatype"], item["remark"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for (auto& item: s_mapReg["EMS_YC"])
|
||||
//{
|
||||
// auto& unit = item.second;
|
||||
// spdlog::info("[{}]={}, {}", unit.key, unit.datatype, unit.remark);
|
||||
//}
|
||||
}
|
||||
|
||||
std::map<std::string, RegAddrUnit>* REGAddr::getRegMap(std::string name)
|
||||
{
|
||||
auto iter = s_mapReg.find(name);
|
||||
if (iter != s_mapReg.end())
|
||||
{
|
||||
return &(iter->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user