mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
修改设备显示信息的寄存器地址配置文件,修改服务端界面
This commit is contained in:
@@ -7,19 +7,8 @@
|
||||
#include "app/DataStruct.h"
|
||||
#include <unordered_set>
|
||||
|
||||
std::map<int, std::vector<DeviceParamAddr>> Device::s_mapDeviceAddrParam;
|
||||
std::map<int, std::vector<std::string>> Device::s_mapDeviceAddrCurve;
|
||||
|
||||
static std::vector<DeviceParamAddr>& GetDeviceParamAddrs(int deviceType)
|
||||
{
|
||||
static std::vector<DeviceParamAddr> vecAddrs = {};
|
||||
auto iter = Device::s_mapDeviceAddrParam.find(deviceType);
|
||||
if (iter != Device::s_mapDeviceAddrParam.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return vecAddrs;
|
||||
}
|
||||
|
||||
|
||||
static std::unordered_set<int> g_setCacheDeviceType = {3, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110};
|
||||
static bool CheckCacheType(int type)
|
||||
@@ -35,46 +24,6 @@ std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
}
|
||||
|
||||
|
||||
void Device::loadParamAddr(std::string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
njson json;
|
||||
if (!JSON::load(filename, json))
|
||||
{
|
||||
spdlog::error("[device] json load param addr error, filename={}", filename);
|
||||
}
|
||||
for (auto& jsonitem : json.items())
|
||||
{
|
||||
std::string key = jsonitem.key();
|
||||
auto& jsonnodeItem = jsonitem.value();
|
||||
|
||||
int type = jsonnodeItem["deviceType"];
|
||||
auto& vec = s_mapDeviceAddrParam[type];
|
||||
for (auto& v : jsonnodeItem["addrYC"])
|
||||
{
|
||||
std::string name = JSON::get<std::string>(v[0]);
|
||||
std::string addr = JSON::get<std::string>(v[1]);
|
||||
std::string defaultVal = JSON::get<std::string>(v[2]);
|
||||
std::string unit = JSON::get<std::string>(v[3]);
|
||||
float ratio = Utils::toFloat(JSON::get<string>(v[4]));
|
||||
vec.push_back(DeviceParamAddr(name, addr, defaultVal, unit, ratio));
|
||||
}
|
||||
if (jsonnodeItem.contains("addrCurve"))
|
||||
{
|
||||
auto& vec = s_mapDeviceAddrCurve[type];
|
||||
for (auto& v : jsonnodeItem["addrCurve"])
|
||||
{
|
||||
vec.push_back(v.get<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (nlohmann::json::parse_error& e)
|
||||
{
|
||||
spdlog::error("[device] parse [{}] error: ", filename, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const int BCU_UNIT_SIZE = 256;
|
||||
@@ -119,7 +68,7 @@ void Device::setFields(Fields& fields)
|
||||
}
|
||||
}
|
||||
|
||||
auto& vecAddrs = GetDeviceParamAddrs(this->type);
|
||||
auto& vecAddrs = REGAddr::GetDeviceParamAddrs(this->type);
|
||||
for (auto& item: vecAddrs)
|
||||
{
|
||||
this->mapMyParams[item.addr] = &item;
|
||||
@@ -224,8 +173,8 @@ bool Device::cache(int npos)
|
||||
std::string addrV;
|
||||
std::string addrI;
|
||||
std::string addrP;
|
||||
auto iter = s_mapDeviceAddrCurve.find(this->type);
|
||||
if (iter != s_mapDeviceAddrCurve.end())
|
||||
auto iter = REGAddr::s_mapDeviceAddrCurve.find(this->type);
|
||||
if (iter != REGAddr::s_mapDeviceAddrCurve.end())
|
||||
{
|
||||
auto& vecAddr = iter->second;
|
||||
auto size = vecAddr.size();
|
||||
@@ -340,79 +289,23 @@ std::string Device::getParam(std::string k, std::string defaultVal)
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
static map<int, map<string, string>> g_mapAddrValStr =
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void Device::getRuntimeParams(std::vector<std::pair<std::string, std::string>>& params)
|
||||
{
|
||||
// 3 电表
|
||||
// 101 EMS
|
||||
// 102 PCS
|
||||
// 103 PCU
|
||||
// 104 BMS
|
||||
// 105 BCU
|
||||
// 106 充电桩
|
||||
// 109 光伏板
|
||||
auto& vecAddr = s_mapDeviceAddrParam[this->type];
|
||||
auto& vecAddr = REGAddr::s_mapDeviceAddrParam[this->type];
|
||||
for (auto& item: vecAddr)
|
||||
{
|
||||
std::string v = getParam(item.addr, item.defaultVal);
|
||||
if (type == int(EDeviceType::BCU) )
|
||||
auto& mapValStr = REGAddr::g_mapRegAddrValStr[type][item.addr];
|
||||
auto iter = mapValStr.find(v);
|
||||
if (iter != mapValStr.end())
|
||||
{
|
||||
if (item.addr == "0xA003") //"0x11开路,0x22待机,0x33充电,0x44放电"
|
||||
{
|
||||
if (v == "17") v = "开路";
|
||||
else if (v == "34") v = "待机";
|
||||
else if (v == "51") v = "充电";
|
||||
else if (v == "68") v = "放电";
|
||||
}
|
||||
else if (item.addr == "0xA004") //"0x11跳机 ,0x22待机,0x33放空,0x44充满,0x55预警,0x66正常"
|
||||
{
|
||||
if (v == "17") v = "跳机";
|
||||
else if (v == "34") v = "待机";
|
||||
else if (v == "51") v = "放空";
|
||||
else if (v == "68") v = "充满";
|
||||
else if (v == "85") v = "预警";
|
||||
else if (v == "102") v = "正常";
|
||||
}
|
||||
v = iter->second;
|
||||
}
|
||||
else if (type == int(EDeviceType::BMS))
|
||||
{
|
||||
if (item.addr == "0x004A") // 0-待机 1-充电 2-放电
|
||||
{
|
||||
if (v == "0") v = "待机";
|
||||
else if (v == "1") v = "充电";
|
||||
else if (v == "2") v = "放电";
|
||||
}
|
||||
}
|
||||
else if (type == int(EDeviceType::PCU))
|
||||
{
|
||||
if (item.addr == "0x1007") // 电网状态 R uint16 1离网,0并网 0x1007
|
||||
{
|
||||
if (v == "0") v = "并网";
|
||||
else if (v == "1") v = "离网";
|
||||
}
|
||||
if (item.addr == "0x1006") // 启停状态 R uint16 1开机,0关机 0x1008
|
||||
{
|
||||
if (v == "1") v = "开机";
|
||||
else if (v == "0") v = "关机";
|
||||
}
|
||||
}
|
||||
else if (type == int(EDeviceType::PCS))
|
||||
{
|
||||
if (item.addr == "0x1009") //充放状态 R uint16 0:待机, 1:充电, 2:放电, 3:搁置 0x1009
|
||||
{
|
||||
if (v == "0") v = "待机";
|
||||
else if (v == "1") v = "充电";
|
||||
else if (v == "2") v = "放电";
|
||||
else if (v == "3") v = "搁置";
|
||||
}
|
||||
else if (item.addr == "0x100A") //电网状态 R uint16 1离网,0并网 0x100A
|
||||
{
|
||||
if (v == "0") v = "并网";
|
||||
else if (v == "1") v = "离网";
|
||||
}
|
||||
}
|
||||
|
||||
//if (this->online) { }
|
||||
//else { v = "--"; }
|
||||
params.push_back({item.name, v + item.unit});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user