mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
修改设备显示信息的寄存器地址配置文件,修改服务端界面
This commit is contained in:
@@ -149,10 +149,7 @@ bool AppData::initFromDB()
|
||||
for (auto& fields: result)
|
||||
{
|
||||
auto policy = std::make_shared<SysPolicy>();
|
||||
policy->policyId = fields.get<int>(DMPolicy::POLICY_ID);
|
||||
policy->type = fields.get<int>(DMPolicy::TYPE);
|
||||
policy->name = fields.value(DMPolicy::NAME);
|
||||
policy->value = fields.value(DMPolicy::VALUE);
|
||||
policy->setFields(fields);
|
||||
this->mapPolicy[policy->policyId] = policy;
|
||||
}
|
||||
}
|
||||
@@ -452,13 +449,23 @@ std::vector<std::string> AppData::getPolicyNames()
|
||||
return vec;
|
||||
}
|
||||
|
||||
int AppData::getPolicyTypeId(std::string name)
|
||||
std::shared_ptr<SysPolicy> AppData::getPolicyByType(int typeId)
|
||||
{
|
||||
for (auto iter = mapPolicyType.begin(); iter != mapPolicyType.end(); ++iter)
|
||||
for (auto iter = mapPolicy.begin(); iter != mapPolicy.end(); ++iter)
|
||||
{
|
||||
if (iter->second == name) { return iter->first; }
|
||||
if (iter->second->type == typeId) { return iter->second; }
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<SysPolicy> AppData::getPolicyById(int policyId)
|
||||
{
|
||||
auto iter = mapPolicy.find(policyId);
|
||||
if (iter != mapPolicy.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -95,9 +95,11 @@ public:
|
||||
std::vector<std::string> getPolicyTypeNames();
|
||||
// 获取策略名称
|
||||
std::vector<std::string> getPolicyNames();
|
||||
// 根据策略类型ID获取策略类型名称
|
||||
// 根据策略类型名称获取策略类型ID
|
||||
int getPolicyTypeId(std::string name);
|
||||
// 根据策略类型ID获取策略信息
|
||||
std::shared_ptr<SysPolicy> getPolicyByType(int typeId);
|
||||
|
||||
std::shared_ptr<SysPolicy> getPolicyById(int policyId);
|
||||
|
||||
|
||||
//std::vector<std::string> getElectPreiodVals(int month);
|
||||
//std::string getElectPreiodVal(int month, int hour);
|
||||
@@ -158,8 +160,6 @@ public:
|
||||
// 策略信息
|
||||
std::unordered_map<int, std::shared_ptr<SysPolicy>> mapPolicy;
|
||||
|
||||
|
||||
|
||||
std::map<int64_t, double> mapDataDay;
|
||||
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ void Application::init()
|
||||
// MQTT 数据结构
|
||||
REGAddr::load("assets/config/regaddrs.json");
|
||||
// 设备读取寄存器的地址定义
|
||||
Device::loadParamAddr("assets/config/regaddrsShow.json");
|
||||
REGAddr::loadParamAddr("assets/config/regaddrsShow.json");
|
||||
|
||||
// 设置数据库配置
|
||||
DaoEntity::setOption(Config::option.database.host,
|
||||
|
||||
@@ -2,8 +2,33 @@
|
||||
#include "common/JsonN.h"
|
||||
#include "common/Utils.h"
|
||||
|
||||
static map<string, int> g_mapTopicDeviceType =
|
||||
{
|
||||
{"EMS_YT", 101}, {"EMS_YX", 101}, {"EMS_YC", 101},
|
||||
{"PCU_YC", 103}, {"PCU_YX", 103},
|
||||
{"PCS_YC", 102}, {"PCS_YX", 102},
|
||||
{"BMS_YC", 104},
|
||||
{"BCU_YC", 105}, {"BCU_YX", 105},
|
||||
{"MEM_YC", 3},
|
||||
{"TH_YC", 10},
|
||||
{"Fire40_YX", 7},
|
||||
{"Cooling_YC", 14},
|
||||
{"Cooling_YX", 14},
|
||||
{"Gateway_YC", 15},
|
||||
{"Gateway_YX", 15},
|
||||
{"Charger_YC", 106}
|
||||
};
|
||||
|
||||
// key: tpoic, 子key: addr
|
||||
std::map<std::string, std::map<std::string, RegAddrUnit>> REGAddr::s_mapReg;
|
||||
|
||||
std::map<int, std::vector<DeviceParamAddr>> REGAddr::s_mapDeviceAddrParam;
|
||||
std::map<int, std::vector<std::string>> REGAddr::s_mapDeviceAddrCurve;
|
||||
std::map<int, std::map<std::string, std::map<std::string, std::string>>> REGAddr::g_mapRegAddrValStr;
|
||||
|
||||
// key: 设备类型, 子key: addr
|
||||
std::map<int, std::map<std::string, RegAddrUnit>> REGAddr::g_mapRegDeviceType;
|
||||
|
||||
void REGAddr::load(std::string filename)
|
||||
{
|
||||
njson json;
|
||||
@@ -12,7 +37,9 @@ void REGAddr::load(std::string filename)
|
||||
// 遍历 JSON 对象
|
||||
for (auto& jsonitem : json.items())
|
||||
{
|
||||
std::string name = jsonitem.key();
|
||||
std::string name = jsonitem.key(); // topic名称
|
||||
int deviceType = g_mapTopicDeviceType[name];
|
||||
|
||||
auto& jsonnodeItem = jsonitem.value();
|
||||
//int count = jsonnodeItem["count"];
|
||||
auto jsonaddrs = jsonnodeItem["addr"];
|
||||
@@ -28,12 +55,68 @@ void REGAddr::load(std::string filename)
|
||||
std::string remark = JSON::read<std::string>(item, "remark");
|
||||
std::string name = JSON::read<std::string>(item, "name");
|
||||
int alert = JSON::read<int>(item, "alert");
|
||||
mapItem[addr] = RegAddrUnit(addr, datatype, alert, name, remark);
|
||||
g_mapRegDeviceType[deviceType][addr] = mapItem[addr] = RegAddrUnit(addr, datatype, alert, name, remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void REGAddr::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 deviceType = jsonnodeItem["deviceType"];
|
||||
auto& vec = s_mapDeviceAddrParam[deviceType];
|
||||
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[deviceType];
|
||||
for (auto& v : jsonnodeItem["addrCurve"])
|
||||
{
|
||||
vec.push_back(v.get<std::string>());
|
||||
}
|
||||
}
|
||||
if (jsonnodeItem.contains("valstr"))
|
||||
{
|
||||
auto& mapDT = g_mapRegAddrValStr[deviceType];
|
||||
for (auto& itemaddr : jsonnodeItem["valstr"].items())
|
||||
{
|
||||
string addr = itemaddr.key();
|
||||
auto& mapAddr = mapDT[addr];
|
||||
for (auto& itemval: itemaddr.value().items())
|
||||
{
|
||||
string key = itemval.key();
|
||||
mapAddr[key] = itemval.value().get<std::string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (nlohmann::json::parse_error& e)
|
||||
{
|
||||
spdlog::error("[device] parse [{}] error: ", filename, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, RegAddrUnit>* REGAddr::getRegMap(std::string name)
|
||||
{
|
||||
auto iter = s_mapReg.find(name);
|
||||
@@ -42,4 +125,25 @@ std::map<std::string, RegAddrUnit>* REGAddr::getRegMap(std::string name)
|
||||
return &(iter->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::map<std::string, RegAddrUnit>* REGAddr::getRegMapByDeviceType(int deviceType)
|
||||
{
|
||||
auto iter = g_mapRegDeviceType.find(deviceType);
|
||||
if (iter != g_mapRegDeviceType.end())
|
||||
{
|
||||
return &(iter->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<DeviceParamAddr>& REGAddr::GetDeviceParamAddrs(int deviceType)
|
||||
{
|
||||
static std::vector<DeviceParamAddr> vecAddrs = {};
|
||||
auto iter = s_mapDeviceAddrParam.find(deviceType);
|
||||
if (iter != s_mapDeviceAddrParam.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return vecAddrs;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum class EAlertType
|
||||
{
|
||||
@@ -56,12 +57,43 @@ struct RegAddrUnit
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 需要在前端展示的设备参数
|
||||
struct DeviceParamAddr
|
||||
{
|
||||
std::string name;
|
||||
std::string addr;
|
||||
std::string defaultVal;
|
||||
std::string unit;
|
||||
float ratio {1.0};
|
||||
DeviceParamAddr() {};
|
||||
DeviceParamAddr(std::string name, std::string addr, std::string defaultVal, std::string unit, float ratio = 1.0f)
|
||||
: name(name), addr(addr), defaultVal(defaultVal), unit(unit), ratio(ratio)
|
||||
{
|
||||
if (this->ratio == 0.0)
|
||||
{
|
||||
this->ratio = 1.0f;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class REGAddr
|
||||
{
|
||||
public:
|
||||
// key: 寄存器地址
|
||||
static std::map<std::string, std::map<std::string, RegAddrUnit>> s_mapReg;
|
||||
|
||||
static std::map<int, std::vector<DeviceParamAddr>> s_mapDeviceAddrParam;
|
||||
static std::map<int, std::vector<std::string>> s_mapDeviceAddrCurve;
|
||||
static std::map<int, std::map<std::string, std::map<std::string, std::string>>> g_mapRegAddrValStr;
|
||||
static std::map<int, std::map<std::string, RegAddrUnit>> g_mapRegDeviceType;
|
||||
|
||||
static void load(std::string filename);
|
||||
static void loadParamAddr(std::string filename);
|
||||
|
||||
static std::map<std::string, RegAddrUnit>* getRegMap(std::string name);
|
||||
|
||||
static std::map<std::string, RegAddrUnit>* getRegMapByDeviceType(int deviceType);
|
||||
|
||||
static std::vector<DeviceParamAddr>& GetDeviceParamAddrs(int deviceType);
|
||||
};
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,33 +8,14 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/Fields.h"
|
||||
#include "app/DataStruct.h"
|
||||
|
||||
class CommEntity;
|
||||
|
||||
// 需要在前端展示的设备参数
|
||||
struct DeviceParamAddr
|
||||
{
|
||||
std::string name;
|
||||
std::string addr;
|
||||
std::string defaultVal;
|
||||
std::string unit;
|
||||
float ratio {1.0};
|
||||
DeviceParamAddr() {};
|
||||
DeviceParamAddr(std::string name, std::string addr, std::string defaultVal, std::string unit, float ratio=1.0f)
|
||||
: name(name), addr(addr), defaultVal(defaultVal), unit(unit), ratio(ratio)
|
||||
{
|
||||
if (this->ratio == 0.0)
|
||||
{
|
||||
this->ratio = 1.0f;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<Device> create(Fields& fields);
|
||||
static void loadParamAddr(std::string filename);
|
||||
|
||||
Device();
|
||||
|
||||
@@ -61,8 +42,7 @@ public:
|
||||
void setBCUUnit(std::string k, int pos, int v, int count);
|
||||
|
||||
public:
|
||||
static std::map<int, std::vector<DeviceParamAddr>> s_mapDeviceAddrParam;
|
||||
static std::map<int, std::vector<std::string>> s_mapDeviceAddrCurve;
|
||||
|
||||
|
||||
int stationId = {0};
|
||||
int deviceId = {0};
|
||||
@@ -90,8 +70,11 @@ public:
|
||||
std::map<int, float> mapCacheVoltage;
|
||||
std::map<int, float> mapCacheCurrent;
|
||||
std::map<int, float> mapCachePower;
|
||||
|
||||
// 参数值(保存从设备读取的参数值)
|
||||
std::map<std::string, std::string> mapParams;
|
||||
|
||||
// 参数定义(定义参数的基础信息,包括寄存器地址,名称,单位,倍率)
|
||||
std::map<std::string, DeviceParamAddr*> mapMyParams;
|
||||
|
||||
std::vector<std::vector<float>> vecBCUUnit;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
void SysPolicy::setFields(Fields& fields)
|
||||
{
|
||||
this->policyId = fields.get<int>("policy_id");
|
||||
this->type = fields.get<int>("policy_type");
|
||||
this->name = fields.value("policy_name");
|
||||
this->type = fields.get<int>("type"); // policy_type
|
||||
this->name = fields.value("name"); // policy_name
|
||||
this->value = fields.value("value");
|
||||
|
||||
this->parseValue(value);
|
||||
@@ -146,6 +146,7 @@ void SysPolicy::getGatewayJsonPeriods(njson& json)
|
||||
{
|
||||
if (vecPeriods1.size()>0)
|
||||
{
|
||||
njson jsonArray = njson::array();
|
||||
for (auto& item: vecPeriods1[0])
|
||||
{
|
||||
int h = 0; int m = 0;
|
||||
@@ -156,8 +157,9 @@ void SysPolicy::getGatewayJsonPeriods(njson& json)
|
||||
else if (item.second == "峰") p = 3;
|
||||
else if (item.second == "尖") p = 4;
|
||||
else p = 0;
|
||||
json.push_back({h, m, p});
|
||||
jsonArray.push_back({h, m, p});
|
||||
}
|
||||
json.push_back(jsonArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "app/Config.h"
|
||||
#include "common/Snowflake.h"
|
||||
#include "app/DataStruct.h"
|
||||
#include "app/Application.h"
|
||||
|
||||
Station::Station() : stationId(0)
|
||||
{
|
||||
@@ -27,7 +28,7 @@ void Station::setFields(Fields& fields)
|
||||
|
||||
this->operationDate = fields.value(DMStation::OPERATION_DATE);
|
||||
this->launchDate = fields.value("operation_date");
|
||||
this->policy.setFields(fields);
|
||||
//this->policy.setFields(fields);
|
||||
}
|
||||
|
||||
void Station::addDevice(int deviceId, std::shared_ptr<Device> device)
|
||||
@@ -133,17 +134,7 @@ void Station::setWorkMode(int modeId)
|
||||
}
|
||||
}
|
||||
|
||||
void Station::setPolicy(int policyId)
|
||||
{
|
||||
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
|
||||
.update(DMStation::POLICY_ID, std::to_string(policyId))
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(stationId)).str();
|
||||
Errcode err = DAO::exec(NULL, sql);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
spdlog::error("set station policy failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Station::initMqtt()
|
||||
{
|
||||
@@ -181,23 +172,30 @@ void Station::setGarewayWorkMode()
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto policy = Application::data().getPolicyByType(this->workMode);
|
||||
|
||||
njson json;
|
||||
json["ts"] = Utils::time();
|
||||
json["no"] = 1; // 设备编号
|
||||
json["40001"] = this->workMode;
|
||||
|
||||
if (policy.type == 1)
|
||||
if (policy)
|
||||
{
|
||||
json["40002"] = njson::array(); // 峰谷套利
|
||||
policy.getGatewayJsonPeriods(json["40002"]);
|
||||
}
|
||||
else if (policy.type == 5)
|
||||
{
|
||||
json["40021"] = njson::array(); // 自定时段
|
||||
policy.getGatewayJsonPeriods(json["40021"]);
|
||||
if (policy->type == 1)
|
||||
{
|
||||
json["40002"] = njson::array(); // 峰谷套利
|
||||
policy->getGatewayJsonPeriods(json["40002"]);
|
||||
}
|
||||
else if (policy->type == 5)
|
||||
{
|
||||
json["40021"] = njson::array(); // 自定时段
|
||||
policy->getGatewayJsonPeriods(json["40021"]);
|
||||
}
|
||||
}
|
||||
|
||||
json["40038"] = {gatewayParam.socMin, gatewayParam.socMax, gatewayParam.capacity, gatewayParam.powerSafe, gatewayParam.powerDischarge, gatewayParam.powerCharge};
|
||||
json["40058"] = {gatewayParam.backflow, gatewayParam.overload};
|
||||
|
||||
std::string text = json.dump();
|
||||
spdlog::info(text);
|
||||
mqttCli->publish("Gateway_YT", text);
|
||||
@@ -229,7 +227,6 @@ string Station::getGatewayParam()
|
||||
{
|
||||
stringstream ss;
|
||||
std::string str1 = "峰谷套利时段:<br>";
|
||||
std::string str2 = "自定时段:<br>";
|
||||
{
|
||||
njson json;
|
||||
if (JSON::parse(gatewayParam.param1, json))
|
||||
@@ -249,6 +246,7 @@ string Station::getGatewayParam()
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string str2 = "自定时段:<br>";
|
||||
{
|
||||
njson json;
|
||||
if (JSON::parse(gatewayParam.param2, json))
|
||||
@@ -267,7 +265,35 @@ string Station::getGatewayParam()
|
||||
}
|
||||
}
|
||||
}
|
||||
return str1 + "<br/>" + str2;
|
||||
std::string str3 = "其它参数:<br>";
|
||||
{
|
||||
njson json;
|
||||
if (JSON::parse(gatewayParam.param3, json))
|
||||
{
|
||||
for (int i = 0; i<json.size(); ++i)
|
||||
{
|
||||
int val = json[i].get<int>();
|
||||
if (i==0) { str3 += "    储能放电下限值SOC: " + std::to_string(val) + "<br>"; } //储能放电下限值 SOC : 40038 (%:0-99 且小于充电上限值)
|
||||
else if (i==1) { str3 += "    储能充电上限值SOC: " + std::to_string(val) + "<br>"; }//储能充电上限值 SOC : 40039 (%:1-100 且大于放电下限值)
|
||||
else if (i==2) { str3 += "    台区变压器容量: " + std::to_string(val) + "<br>"; }//台区变压器容量 : 40040 (KVVA 160-1600)
|
||||
else if (i==3) { str3 += "    安全输入功率: " + std::to_string(val) + "<br>"; }//安全输入功率 : 40041 (KW 0-400)
|
||||
else if (i==4) { str3 += "    储能最大放电功率: " + std::to_string(val) + "<br>"; }//储能最大放电功率 : 40042 (1KW0-150)
|
||||
else if (i==5) { str3 += "    储能最大充电功率: " + std::to_string(val) + "<br>"; }//储能最大充电功率::40043 (1KW0-150)
|
||||
else if (i==6) { str3 += "    运行状态: " + std::to_string(val) + "<br>"; }//运行状态 : 40044 (只读不写,0:无 1:高峰放电 2:低谷充电)
|
||||
else if (i==7) { str3 += "    台区电表变比: " + std::to_string(val) + "<br>"; }//台区电表变比:40045
|
||||
//else if (i==8) { str3 += "    对时(年): " + std::to_string(val) + "<br>"; }//对时(年) : 40051
|
||||
//else if (i==9) { str3 += "    对时(月): " + std::to_string(val) + "<br>"; }//对时(月) : 40052
|
||||
//else if (i==10) { str3 += "    对时(日): " + std::to_string(val) + "<br>"; }//对时(日) : 40053
|
||||
//else if (i==11) { str3 += "    对时(时): " + std::to_string(val) + "<br>"; }//对时(时) : 40054
|
||||
//else if (i==12) { str3 += "    对时(分): " + std::to_string(val) + "<br>"; }//对时(分) : 40055
|
||||
//else if (i==13) { str3 += "    对时(秒): " + std::to_string(val) + "<br>"; }//对时(秒) : 40056
|
||||
//else if (i==19) { str3 += "    时间段月份: " + std::to_string(val) + "<br>"; }//时间段月份 : 40057(1-12 对应1月-12月)
|
||||
else if (i==20) { str3 += "    防逆流回差: " + std::to_string(val) + "<br>"; }//防逆流回差 : 40058(1KW 10-300)
|
||||
else if (i==21) { str3 += "    防过载回差: " + std::to_string(val) + "<br>"; }//防过载回差 : 40059(1KW 10-300)
|
||||
}
|
||||
}
|
||||
}
|
||||
return str1 + "<br/>" + str2 + "<br/>" + str3;
|
||||
}
|
||||
|
||||
void Station::checkDevice()
|
||||
@@ -290,7 +316,7 @@ void Station::readAlert(std::shared_ptr<Device> device, std::string addr, int v,
|
||||
int64_t ts = Utils::time();
|
||||
std::string alertId = std::to_string(device->deviceId) + "_" + addr;
|
||||
int tsCache = mapAlertCache[alertId];
|
||||
if (ts - tsCache > 60*5)
|
||||
if (ts - tsCache > 60*30)
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("log_id", Snowflake::instance().getIdStr());
|
||||
@@ -419,6 +445,14 @@ void Station::readCoolingData(int deviceNo, string addr, int val)
|
||||
else if (addr == "0x100E") { ; }// 出水压力传感器 R uint16 0:正常,1:告警 0x100E
|
||||
}
|
||||
|
||||
static void JSONReadArrayItem(njson& json, int i, int& v)
|
||||
{
|
||||
if (json.is_array() && i < json.size())
|
||||
{
|
||||
v = json[i].get<int>();
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readGatewayMode(int mode, string p1, string p2, string p3)
|
||||
{
|
||||
this->gatewayParam.mode = mode;
|
||||
@@ -429,6 +463,22 @@ void Station::readGatewayMode(int mode, string p1, string p2, string p3)
|
||||
{
|
||||
//this->setGarewayWorkMode();
|
||||
}
|
||||
|
||||
|
||||
njson json;
|
||||
if (JSON::parse(gatewayParam.param3, json))
|
||||
{
|
||||
JSONReadArrayItem(json, 0, gatewayParam.socMin); //储能放电下限值 SOC : 40038 (%:0-99 且小于充电上限值)
|
||||
JSONReadArrayItem(json, 1, gatewayParam.socMax); //储能充电上限值 SOC : 40039 (%:1-100 且大于放电下限值)
|
||||
JSONReadArrayItem(json, 2, gatewayParam.capacity); //台区变压器容量 : 40040 (KVVA 160-1600)
|
||||
JSONReadArrayItem(json, 3, gatewayParam.powerSafe); //安全输入功率 : 40041 (KW 0-400)
|
||||
JSONReadArrayItem(json, 4, gatewayParam.powerDischarge); //储能最大放电功率 : 40042 (1KW0-150)
|
||||
JSONReadArrayItem(json, 5, gatewayParam.powerCharge); //储能最大充电功率::40043 (1KW0-150)
|
||||
JSONReadArrayItem(json, 6, gatewayParam.status); //运行状态 : 40044 (只读不写,0:无 1:高峰放电 2:低谷充电)
|
||||
JSONReadArrayItem(json, 7, gatewayParam.vtRatio); //台区电表变比:40045
|
||||
JSONReadArrayItem(json, 20, gatewayParam.backflow); //防逆流回差 : 40058(1KW 10-300)
|
||||
JSONReadArrayItem(json, 21, gatewayParam.overload); //防过载回差 : 40059(1KW 10-300)
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readGatewayStatus(int cdzStatus, int emuStatus)
|
||||
|
||||
@@ -107,7 +107,6 @@ public:
|
||||
void getDeviceByCategory(int category, std::vector<std::shared_ptr<Device>>& res);
|
||||
|
||||
void setWorkMode(int modeId);
|
||||
void setPolicy(int policyId);
|
||||
|
||||
void initMqtt();
|
||||
void polling();
|
||||
@@ -139,7 +138,7 @@ public:
|
||||
std::string code;
|
||||
int status {0};
|
||||
std::string operationDate;
|
||||
SysPolicy policy;
|
||||
//SysPolicy policy;
|
||||
std::string launchDate {};
|
||||
|
||||
bool isConnected {false};
|
||||
@@ -153,6 +152,17 @@ public:
|
||||
std::string param1;
|
||||
std::string param2;
|
||||
std::string param3;
|
||||
|
||||
int socMin {}; // 储能放电下限值 SOC 40038 (%, 0-99)
|
||||
int socMax {}; // 储能充电上限值 SOC 40039 (%:1-100)
|
||||
int capacity {}; // 台区变压器容量 40040 (KVA 160-1600)
|
||||
int powerSafe {}; // 安全输入功率 40041 (KW 0-400)
|
||||
int powerDischarge {}; // 储能最大放电功率 40042 (1KW 0-150)
|
||||
int powerCharge {}; // 储能最大充电功率 40043 (1KW 0-150)
|
||||
int status {}; // 运行状态:40044 (只读不写,0:无 1:高峰放电 2:低谷充电)
|
||||
int vtRatio ;// 台区电表变比 40045
|
||||
int backflow {}; // 防逆流回差 40058(1KW 10-300)
|
||||
int overload {}; // 防过载回差 40059(1KW 10-300)
|
||||
} gatewayParam;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user