mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
修改MQTT通讯数据解析问题
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "common/Utils.h"
|
||||
#include "protocol/CommEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
|
||||
#include "app/DataStruct.h"
|
||||
#include <unordered_set>
|
||||
|
||||
std::map<int, std::vector<DeviceParamAddr>> Device::s_mapDeviceAddrParam;
|
||||
@@ -76,6 +76,13 @@ void Device::loadParamAddr(std::string filename)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const int BCU_UNIT_SIZE = 256;
|
||||
Device::Device()
|
||||
{
|
||||
vecBCUUnit = std::vector<std::vector<float>>(BCU_UNIT_SIZE, std::vector<float>(5, 0.0f));
|
||||
}
|
||||
|
||||
void Device::setFields(Fields& fields)
|
||||
{
|
||||
fields.get("station_id", this->stationId);
|
||||
@@ -256,6 +263,9 @@ void Device::storeDB(int npos)
|
||||
|
||||
void Device::setParam(std::string k, int v)
|
||||
{
|
||||
this->ts = Utils::time();
|
||||
online = 1;
|
||||
|
||||
float ratio = 1.0;
|
||||
auto iter = mapMyParams.find(k);
|
||||
if (iter != mapMyParams.end())
|
||||
@@ -264,40 +274,62 @@ void Device::setParam(std::string k, int v)
|
||||
//spdlog::info("[device] set param: {} {}={}, ratio={}", iter->second->name, k, v, ratio);
|
||||
}
|
||||
|
||||
if (type == 106) // 充电桩2号枪,特殊数据格式
|
||||
{
|
||||
if (k=="22") { ratio = 0.1; }
|
||||
else if (k=="23") { ratio = 0.01; }
|
||||
else if (k== "24") { ratio = 0.1; }
|
||||
else if (k== "25") { ratio = 0.1; }
|
||||
else if (k== "26") { ratio = 0.01; }
|
||||
else if (k== "27") { ratio = 0.1; }
|
||||
else if (k== "28") { ratio = 0.1; }
|
||||
}
|
||||
|
||||
int precision = (ratio != 1.0f) ? 1 : 0;
|
||||
mapParams[k] = Utils::toStr(v*ratio, precision);
|
||||
std::string valStr = Utils::toStr(v*ratio, precision);
|
||||
if (type == 106) // 充电桩状态,特殊数据格式
|
||||
{
|
||||
if (k=="11" || k == "21") {
|
||||
valStr = (valStr == "1" ? "充电" : "空闲");
|
||||
}
|
||||
}
|
||||
mapParams[k] = valStr;
|
||||
|
||||
if (type == 3 ) // 电表
|
||||
{
|
||||
if (k == "") this->err = v;
|
||||
{
|
||||
running = 1;
|
||||
}
|
||||
else if (type == 101) // EMS
|
||||
{
|
||||
running = 1;
|
||||
}
|
||||
else if (type == 102) // PCS
|
||||
{
|
||||
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
|
||||
if (k == "0x1003") err = v; // 故障状态 R uint16 1故障,0正常 0 0x1003
|
||||
else if (k == "0x1005") online = v; // 设备在线 R uint16 1在线,0无效 1 0x1005
|
||||
else 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 = 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
|
||||
if (k == "0x1002") err = v; //故障状态 R uint16 1故障,0正常 0 0x1002
|
||||
else if (k == "0x1004") online = v; //设备在线 R uint16 1在线,0无效 1 0x1004
|
||||
else 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); } //运行状态 R uint16 0 运行状态 0-正常 1-告警 2-保护 0x004A
|
||||
else if (k == "0x004B") running = (v==1 || v==2); //充放电状态 R uint16 0 0-待机 1-充电 2-放电 0x004B
|
||||
}
|
||||
else if (type == 105) // BCU
|
||||
else if (type == int(EDeviceType::BCU)) // BCU
|
||||
{
|
||||
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
|
||||
if (k == "0xA003") { running = (v==0x33 || v==0x44); } //蓄电池充放电状态 R uint16 "0x11开路,0x22待机,0x33充电,0x44放电" 34 0xA003
|
||||
else if (k == "0xA004") { err = (v==0x55); } //电池组运行状态 R uint16 "0x11跳机,0x22待机,0x33放空,0x44充满,0x55预警,0x66正常" 102 0xA004
|
||||
}
|
||||
else if (type == 106) // 充电桩
|
||||
{
|
||||
if (k == "21") {
|
||||
running = (mapParams["11"] == "充电" || mapParams["21"] == "充电"); // 充电状态: 0:空闲,1:充电
|
||||
}
|
||||
}
|
||||
else if (type == 109) // 光伏板
|
||||
{
|
||||
@@ -329,13 +361,69 @@ void Device::getRuntimeParams(std::vector<std::pair<std::string, std::string>>&
|
||||
// 106 充电桩
|
||||
// 109 光伏板
|
||||
auto& vecAddr = s_mapDeviceAddrParam[this->type];
|
||||
for (auto& itemAddr: vecAddr)
|
||||
for (auto& item: vecAddr)
|
||||
{
|
||||
std::string v;
|
||||
v = getParam(itemAddr.addr, itemAddr.defaultVal) + itemAddr.unit;
|
||||
std::string v = getParam(item.addr, item.defaultVal);
|
||||
if (type == int(EDeviceType::BCU) )
|
||||
{
|
||||
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 = "正常";
|
||||
}
|
||||
}
|
||||
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 == "0x1008") // 模块状态 R uint16 1开机,0待机 0x1008
|
||||
{
|
||||
if (v == "0") v = "开机";
|
||||
else if (v == "1") 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({itemAddr.name, v});
|
||||
params.push_back({item.name, v + item.unit});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,12 +431,39 @@ void Device::getRuntimeParams1(std::vector<std::pair<std::string, std::string>>&
|
||||
{
|
||||
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"});
|
||||
params.push_back({"工作状态", getParam("21", "空闲")});
|
||||
params.push_back({"需求电压", getParam("22", "0.0") + " V"});
|
||||
params.push_back({"需求电流", getParam("23", "0.0") + " A"});
|
||||
params.push_back({"需求功率", getParam("24", "0.0") + " kW"});
|
||||
params.push_back({"输出电压", getParam("25", "0.0") + " V"});
|
||||
params.push_back({"输出电流", getParam("26", "0.0") + " A"});
|
||||
params.push_back({"输出功率", getParam("27", "0.0") + " kW"});
|
||||
params.push_back({"功率限值", getParam("28", "0.0") + " kW"});
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setBCUUnit(std::string k, int pos, int v, int count)
|
||||
{
|
||||
//单体SOC R uint16[1000] 0.1 0x0056~0x043D
|
||||
//单体SOH R uint16[1000] 0.1 0x043E~0x0825
|
||||
//单体电压 R uint16[1000] mV 0x0826~0x0C0D
|
||||
//单体温度 R int16[1000] 0.01℃ 0x0C0E~0x0FF5
|
||||
//单体内阻 R uint16[1000] mΩ 0x0FF6~0x13DD
|
||||
if (pos < BCU_UNIT_SIZE)
|
||||
{
|
||||
auto& bcuUnit = vecBCUUnit[pos];
|
||||
if (pos == 0)
|
||||
{
|
||||
bcuCount = count;
|
||||
for (int i = count; i<BCU_UNIT_SIZE; ++i)
|
||||
{
|
||||
std::fill(vecBCUUnit[i].begin(), vecBCUUnit[i].end(), 0.0f);
|
||||
}
|
||||
}
|
||||
if (k == "0x0056") { bcuUnit[0] = float(v) * 0.1f; }
|
||||
else if (k == "0x043E") { bcuUnit[1] = float(v) * 0.1f; }
|
||||
else if (k == "0x0826") { bcuUnit[2] = float(v) * 0.001f; }
|
||||
else if (k == "0x0C0E") { bcuUnit[3] = float(v); } // * 0.01f
|
||||
else if (k == "0x0FF6") { bcuUnit[4] = float(v); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user