mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
添加QT的webengineview开发者调试功能
This commit is contained in:
@@ -7,6 +7,19 @@
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
std::map<int, std::vector<DeviceParamAddr>> Device::s_mapDeviceParamAddr;
|
||||
|
||||
static std::vector<DeviceParamAddr>& GetDeviceParamAddrs(int deviceType)
|
||||
{
|
||||
static std::vector<DeviceParamAddr> vecAddrs = {};
|
||||
auto iter = Device::s_mapDeviceParamAddr.find(deviceType);
|
||||
if (iter != Device::s_mapDeviceParamAddr.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)
|
||||
{
|
||||
@@ -20,6 +33,41 @@ std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
spdlog::info(jsonnodeItem.dump());
|
||||
|
||||
int type = jsonnodeItem["deviceType"];
|
||||
auto& vec = s_mapDeviceParamAddr[type];
|
||||
for (auto& v : jsonnodeItem["addr_YC"])
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (nlohmann::json::parse_error& e)
|
||||
{
|
||||
spdlog::error("[device] parse [{}] error: ", filename, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setFields(Fields& fields)
|
||||
{
|
||||
fields.get("device_id", this->deviceId);
|
||||
@@ -53,6 +101,12 @@ void Device::setFields(Fields& fields)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto& vecAddrs = GetDeviceParamAddrs(this->type);
|
||||
for (auto& item: vecAddrs)
|
||||
{
|
||||
this->mapMyParams[item.addr] = &item;
|
||||
}
|
||||
}
|
||||
|
||||
int Device::startComm()
|
||||
@@ -174,42 +228,47 @@ void Device::storeDB(int npos)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Device::setParam(std::string k, std::string v)
|
||||
void Device::setParam(std::string k, int v)
|
||||
{
|
||||
mapParams[k] = v;
|
||||
float ratio = 1.0;
|
||||
auto iter = mapMyParams.find(k);
|
||||
if (iter != mapMyParams.end())
|
||||
{
|
||||
ratio = iter->second->ratio;
|
||||
spdlog::info("[device] set param: {} {}={}, ratio={}", iter->second->name, k, v, ratio);
|
||||
}
|
||||
|
||||
int precision = (ratio != 1.0f) ? 2 : 0;
|
||||
mapParams[k] = Utils::toStr(v*ratio, precision);
|
||||
|
||||
if (type == 3 ) // 电表
|
||||
{
|
||||
if (k == "") this->err = Utils::toInt(v);
|
||||
if (k == "") this->err = v;
|
||||
}
|
||||
else if (type == 101) // EMS
|
||||
{
|
||||
}
|
||||
else if (type == 102) // PCS
|
||||
{
|
||||
if (k == "0x1003") err = Utils::toInt(v); // 故障状态 R uint16 1故障,0正常 0 0x1003
|
||||
if (k == "0x1005") online = Utils::toInt(v); // 设备在线 R uint16 1在线,0无效 1 0x1005
|
||||
if (k == "0x1009") running = (v=="1" || v=="2"); //充放状态 R uint16 0:待机, 1:充电, 2:放电, 3:搁置 0 0x1009
|
||||
if (k == "0x1003") err = v; // 故障状态 R uint16 1故障,0正常 0 0x1003
|
||||
if (k == "0x1005") online = v; // 设备在线 R uint16 1在线,0无效 1 0x1005
|
||||
if (k == "0x1009") running = (v==1 || v==2); //充放状态 R uint16 0:待机, 1:充电, 2:放电, 3:搁置 0 0x1009
|
||||
}
|
||||
else if (type == 103) // PCU
|
||||
{
|
||||
if (k == "0x1002") err = Utils::toInt(v); //故障状态 R uint16 1故障,0正常 0 0x1002
|
||||
if (k == "0x1004") online = Utils::toInt(v); //设备在线 R uint16 1在线,0无效 1 0x1004
|
||||
if (k == "0x1006") running = Utils::toInt(v); //启停状态 R uint16 1开机,0关机 1 0x1006
|
||||
if (k == "0x1002") err = v; //故障状态 R uint16 1故障,0正常 0 0x1002
|
||||
if (k == "0x1004") online = v; //设备在线 R uint16 1在线,0无效 1 0x1004
|
||||
if (k == "0x1006") running = v; //启停状态 R uint16 1开机,0关机 1 0x1006
|
||||
}
|
||||
else if (type == 104) // BMS
|
||||
{
|
||||
if (k == "0x004A") { err = (v=="1"); online = 1; } //运行状态 R uint16 0 运行状态 0-正常 1-告警 2-保护 0x004A
|
||||
if (k == "0x004B") running = (v=="1" || v=="2"); //充放电状态 R uint16 0 0-待机 1-充电 2-放电 0x004B
|
||||
if (k == "0x004A") { err = (v==1); online = 1; } //运行状态 R uint16 0 运行状态 0-正常 1-告警 2-保护 0x004A
|
||||
if (k == "0x004B") running = (v==1 || v==2); //充放电状态 R uint16 0 0-待机 1-充电 2-放电 0x004B
|
||||
}
|
||||
else if (type == 105) // BCU
|
||||
{
|
||||
if (k == "0xA003") running = (v=="51" || v=="68"); //蓄电池充放电状态 R uint16 "0x11开路,0x22待机,0x33充电,0x44放电" 34 0xA003
|
||||
if (k == "0xA004") err = (v=="85"); online=1; //电池组运行状态 R uint16 "0x11跳机,0x22待机,0x33放空,0x44充满,0x55预警,0x66正常" 102 0xA004
|
||||
if (k == "0xA003") running = (v==0x33 || v==0x44); //蓄电池充放电状态 R uint16 "0x11开路,0x22待机,0x33充电,0x44放电" 34 0xA003
|
||||
if (k == "0xA004") err = (v==0x55); online=1; //电池组运行状态 R uint16 "0x11跳机,0x22待机,0x33放空,0x44充满,0x55预警,0x66正常" 102 0xA004
|
||||
}
|
||||
else if (type == 106) // 充电桩
|
||||
{
|
||||
@@ -229,7 +288,6 @@ std::string Device::getParam(std::string k, std::string defaultVal)
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
|
||||
void Device::getRuntimeParams(std::vector<std::pair<std::string, std::string>>& params)
|
||||
{
|
||||
// 3 电表
|
||||
@@ -240,71 +298,23 @@ void Device::getRuntimeParams(std::vector<std::pair<std::string, std::string>>&
|
||||
// 105 BCU
|
||||
// 106 充电桩
|
||||
// 109 光伏板
|
||||
|
||||
|
||||
if (this->type == 3)
|
||||
auto& vecAddr = s_mapDeviceParamAddr[this->type];
|
||||
for (auto& itemAddr: vecAddr)
|
||||
{
|
||||
params.push_back({"A相电压", getParam("0x000B", "0.0") + " V"});
|
||||
params.push_back({"A相电流", getParam("0x000D", "0.0") + " A"});
|
||||
params.push_back({"B相电压", getParam("0x000F", "0.0") + " V"});
|
||||
params.push_back({"B相电流", getParam("0x0011", "0.0") + " A"});
|
||||
params.push_back({"C相电压", getParam("0x0013", "0.0") + " V"});
|
||||
params.push_back({"C相电流", getParam("0x0015", "0.0") + " A"});
|
||||
}
|
||||
else if (this->type == 101) // EMS
|
||||
{
|
||||
params.push_back({"A相电压", getParam("0x107E", "0.0") + " V"});
|
||||
params.push_back({"A相电流", getParam("0x1084", "0.0") + " A"});
|
||||
params.push_back({"B相电压", getParam("0x1080", "0.0") + " V"});
|
||||
params.push_back({"B相电流", getParam("0x1086", "0.0") + " A"});
|
||||
params.push_back({"C相电压", getParam("0x1082", "0.0") + " V"});
|
||||
params.push_back({"C相电流", getParam("0x1088", "0.0") + " A"});
|
||||
}
|
||||
else if (this->type == 102) // PCS
|
||||
{
|
||||
params.push_back({"A相电压", getParam("0x0010", "0.0") + " V"});
|
||||
params.push_back({"A相电流", getParam("0x0019", "0.0") + " A"});
|
||||
params.push_back({"B相电压", getParam("0x0011", "0.0") + " V"});
|
||||
params.push_back({"B相电流", getParam("0x001A", "0.0") + " A"});
|
||||
params.push_back({"C相电压", getParam("0x0011", "0.0") + " V"});
|
||||
params.push_back({"C相电流", getParam("0x001B", "0.0") + " A"});
|
||||
}
|
||||
else if (this->type == 103) // PCU
|
||||
{
|
||||
params.push_back({"A相电压", getParam("0x0013", "0.0") + " V"});
|
||||
params.push_back({"A相电流", getParam("0x001C", "0.0") + " A"});
|
||||
params.push_back({"B相电压", getParam("0x0014", "0.0") + " V"});
|
||||
params.push_back({"B相电流", getParam("0x001D", "0.0") + " A"});
|
||||
params.push_back({"C相电压", getParam("0x0015", "0.0") + " V"});
|
||||
params.push_back({"C相电流", getParam("0x001E", "0.0") + " A"});
|
||||
}
|
||||
else if (this->type == 104) // BMS
|
||||
{
|
||||
params.push_back({"SOC", getParam("0x0001", "0") + " %"});
|
||||
params.push_back({"SOH", getParam("0x0002", "0") + " %"});
|
||||
params.push_back({"电压", getParam("0x0003", "0.0") + " V"});
|
||||
params.push_back({"电流", getParam("0x0005", "0.0") + " A"});
|
||||
params.push_back({"单体最大电压", getParam("0x0021", "0.0") + " V"});
|
||||
params.push_back({"单体最小电压", getParam("0x0024", "0.0") + " V"});
|
||||
params.push_back({"单体最大温度", getParam("0x0029", "0.0") + " ℃"});
|
||||
params.push_back({"单体最小温度", getParam("0x002C", "0.0") + " ℃"});
|
||||
}
|
||||
else if (this->type == 105) // BCU
|
||||
{
|
||||
params.push_back({"簇电压", getParam("0x0003", "0.0") + " V"});
|
||||
params.push_back({"簇电流", getParam("0x0005", "0") + " A"});
|
||||
params.push_back({"簇温度", getParam("0x0007", "0.0") + " ℃"});
|
||||
params.push_back({"簇电阻", getParam("0x0009", "0.0") + " Ω"});
|
||||
params.push_back({"簇SOC", getParam("0x000B", "0") + " %"});
|
||||
params.push_back({"簇SOH", getParam("0x000C", "0") + " %"});
|
||||
}
|
||||
else
|
||||
{
|
||||
params.push_back({"额定电压", getParam("0x0001", "0.0") + " V"});
|
||||
params.push_back({"实时电压", getParam("0x0001", "0.0") + " V"});
|
||||
params.push_back({"额定电流", getParam("0x0001", "0.0") + " A"});
|
||||
params.push_back({"实时电流", getParam("0x0001", "0.0") + " A"});
|
||||
params.push_back({"额定功率", getParam("0x0001", "0.0") + " W"});
|
||||
params.push_back({"实时功率", getParam("0x0001", "0.0") + " W"});
|
||||
params.push_back({itemAddr.name, getParam(itemAddr.addr, itemAddr.defaultVal) + itemAddr.unit});
|
||||
}
|
||||
}
|
||||
|
||||
void Device::getRuntimeParams1(std::vector<std::pair<std::string, std::string>>& params)
|
||||
{
|
||||
if (type == 106)
|
||||
{
|
||||
params.push_back({"需求电压", getParam("31072", "0.0") + " V"});
|
||||
params.push_back({"需求电流", getParam("31074", "0.0") + " A"});
|
||||
params.push_back({"需求功率", getParam("31076", "0.0") + " kW"});
|
||||
params.push_back({"功率限值", getParam("31078", "0.0") + " kW"});
|
||||
params.push_back({"输出电压", getParam("31080", "0.0") + " V"});
|
||||
params.push_back({"输出电流", getParam("31082", "0.0") + " A"});
|
||||
params.push_back({"输出功率", getParam("31084", "0.0") + " kW"});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user