mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
添加Openssl,Gmssl加密库
This commit is contained in:
@@ -115,7 +115,7 @@ void Application::runThreadStat()
|
||||
while (!isQuit)
|
||||
{
|
||||
static TimeTick ttStat(1);
|
||||
if(ttStat.elapse(10))
|
||||
if(Config::option.stat.enabled && ttStat.elapse(Config::option.stat.interval))
|
||||
{
|
||||
// 设备历史数据(电压、电流、功率),存储到 history_day
|
||||
// 统计数据,存储到 stat_day
|
||||
|
||||
@@ -24,6 +24,7 @@ bool Config::init(std::string filename)
|
||||
JSON::read(jsonroot, "weburl", option.webSrvUrl);
|
||||
JSON::read(jsonroot, "launchdate", option.lunchDate);
|
||||
JSON::read(jsonroot, "exportpath", option.exportpath);
|
||||
JSON::read(jsonroot, "windowEnabled", option.windowEnabled);
|
||||
|
||||
if (jsonroot.contains("database"))
|
||||
{
|
||||
@@ -110,6 +111,14 @@ bool Config::init(std::string filename)
|
||||
JSON::read(jsonItem, "enabled", info.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonroot.contains("statistics"))
|
||||
{
|
||||
njson& json = jsonroot["statistics"];
|
||||
JSON::read(json, "enabled", option.stat.enabled);
|
||||
JSON::read(json, "interval", option.stat.interval);
|
||||
if (option.stat.interval <= 0) { option.stat.interval = 60; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,12 @@ struct AppOption
|
||||
|
||||
std::map<std::string, VideoInfo> mapVideo;
|
||||
|
||||
int windowEnabled {0};
|
||||
|
||||
struct {
|
||||
int enabled {0};
|
||||
int interval {60};
|
||||
} stat;
|
||||
};
|
||||
|
||||
class Config
|
||||
|
||||
@@ -2,18 +2,8 @@
|
||||
#include "common/JsonN.h"
|
||||
#include "common/Utils.h"
|
||||
|
||||
std::string REGAddrOffset(std::string addr, int offset)
|
||||
{
|
||||
unsigned int val;
|
||||
std::stringstream ss;
|
||||
ss << std::hex << addr;
|
||||
ss >> val;
|
||||
return Utils::toHexStr(val + offset);
|
||||
}
|
||||
|
||||
std::map<std::string, std::map<std::string, RegAddrUnit>> REGAddr::s_mapReg;
|
||||
|
||||
|
||||
void REGAddr::load(std::string filename)
|
||||
{
|
||||
njson json;
|
||||
|
||||
@@ -32,7 +32,7 @@ enum class EDeviceType
|
||||
PCU = 103, //103 PCU 1
|
||||
BMS = 104, //104 BMS 1
|
||||
BCU = 105, //105 BCU 1
|
||||
//106 充电桩 2
|
||||
CHARGER = 106, //106 充电桩 2
|
||||
//107 充电枪 2
|
||||
//108 集中器 2
|
||||
//109 光伏板 3
|
||||
|
||||
@@ -241,16 +241,16 @@ bool Device::cache(int npos)
|
||||
if (iter != s_mapDeviceAddrCurve.end())
|
||||
{
|
||||
auto& vecAddr = iter->second;
|
||||
auto size = addrV.size();
|
||||
auto size = vecAddr.size();
|
||||
if (size >= 1) { addrV = vecAddr[0]; }
|
||||
else if (size >= 2) { addrI = vecAddr[1]; }
|
||||
else if (size >= 3) { addrP = vecAddr[2]; }
|
||||
if (size >= 2) { addrI = vecAddr[1]; }
|
||||
if (size >= 3) { addrP = vecAddr[2]; }
|
||||
}
|
||||
|
||||
// 根据设备类型从参数(寄存器地址)中读取实时数据进行保存
|
||||
int U = Utils::toInt(this->getParam(addrV, "0"));
|
||||
int I = Utils::toInt(this->getParam(addrI, "0"));
|
||||
int P = addrP.empty() ? U*I : Utils::toInt(this->getParam(addrP, "0"));
|
||||
int P = addrP.empty() ? U*I*0.001 : Utils::toInt(this->getParam(addrP, "0"));
|
||||
mapCacheVoltage[npos] = U;
|
||||
mapCacheCurrent[npos] = I;
|
||||
mapCachePower[npos] = P;
|
||||
@@ -299,33 +299,33 @@ void Device::setParam(std::string k, int v)
|
||||
{
|
||||
running = 1;
|
||||
}
|
||||
else if (type == 101) // EMS
|
||||
else if (type == int(EDeviceType::EMS)) // 101 EMS
|
||||
{
|
||||
running = 1;
|
||||
}
|
||||
else if (type == 102) // PCS
|
||||
else if (type == int(EDeviceType::PCS)) // 102 PCS
|
||||
{
|
||||
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
|
||||
else if (type == int(EDeviceType::PCU)) // 103 PCU
|
||||
{
|
||||
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
|
||||
else if (type == int(EDeviceType::BMS)) // 104 BMS
|
||||
{
|
||||
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
|
||||
if (k == "0x0049") { err = (v==1); } //运行状态 R uint16 0 运行状态 0-正常 1-告警 2-保护 0x0049
|
||||
else if (k == "0x004A") { running = (v==1 || v==2); } //充放电状态 R uint16 0 0-待机 1-充电 2-放电 0x004A
|
||||
}
|
||||
else if (type == int(EDeviceType::BCU)) // BCU
|
||||
{
|
||||
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) // 充电桩
|
||||
else if (type == int(EDeviceType::CHARGER)) // 106 充电桩
|
||||
{
|
||||
if (k == "21") {
|
||||
running = (mapParams["11"] == "充电" || mapParams["21"] == "充电"); // 充电状态: 0:空闲,1:充电
|
||||
|
||||
@@ -205,16 +205,23 @@ void Station::checkDevice()
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readAlert(std::shared_ptr<Device> device, int v, std::string text)
|
||||
void Station::readAlert(std::shared_ptr<Device> device, std::string addr, int v, std::string text)
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("log_id", Snowflake::instance().getIdStr());
|
||||
if (device) { fields.set("device_id", device->deviceId); }
|
||||
fields.set("type", int(EAlertType::DEVICE));
|
||||
fields.set("context", text + ":故障(" + std::to_string(v) + ")");
|
||||
fields.set("status", 1);
|
||||
auto dao = DaoEntity::create("log_alert");
|
||||
dao->insertFields(fields);
|
||||
int64_t ts = Utils::time();
|
||||
std::string alertId = std::to_string(device->deviceId) + "_" + addr;
|
||||
int tsCache = mapAlertCache[alertId];
|
||||
if (ts - tsCache > 60*5)
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("log_id", Snowflake::instance().getIdStr());
|
||||
if (device) { fields.set("device_id", device->deviceId); }
|
||||
fields.set("type", int(EAlertType::DEVICE));
|
||||
fields.set("content", text + ":故障(" + std::to_string(v) + ")");
|
||||
fields.set("status", 1);
|
||||
auto dao = DaoEntity::create("log_alert");
|
||||
dao->insertFields(fields);
|
||||
mapAlertCache[alertId] = ts;
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readRuntimeData(int deviceNo, string addr, int val)
|
||||
@@ -360,12 +367,13 @@ void Station::writeStatistic()
|
||||
std::string dt = Utils::dateStr();
|
||||
int64_t tTime = Utils::time();
|
||||
int64_t tDate = Utils::date();
|
||||
int64_t tDelta = tTime - tDate;
|
||||
int npos = (tTime-tDate) / 600;
|
||||
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
auto device = iter->second;
|
||||
if (device->cache(npos))
|
||||
if (device->cache(npos) && device->type == int(EDeviceType::BMS))
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("dt", dt);
|
||||
@@ -391,7 +399,6 @@ void Station::writeStatistic()
|
||||
Fields fields;
|
||||
fields.set("dt", Utils::dateStr(statData.ts));
|
||||
fields.set("station_id", this->stationId);
|
||||
fields.set("category", 1);
|
||||
fields.set("device_id", 0);
|
||||
fields.set("elect_in", statData.dayElectIn);
|
||||
fields.set("elect_out", statData.dayElectOut);
|
||||
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
void setGarewayWorkMode();
|
||||
void checkDevice();
|
||||
|
||||
void readAlert(std::shared_ptr<Device> device, int v, std::string text);
|
||||
void readAlert(std::shared_ptr<Device> device, std::string addr, int v, std::string text);
|
||||
void readRuntimeData(int deviceNo, string addr, int val);
|
||||
void readTHData(int deviceNo, string addr, int val);
|
||||
void readFire40Data(int deviceNo, string addr, int val);
|
||||
@@ -123,6 +123,7 @@ public:
|
||||
void readGatewayStatus(int cdzStatus, int emuStatus);
|
||||
|
||||
void writeStatistic();
|
||||
int posDayStat {0};
|
||||
|
||||
public:
|
||||
int stationId {};
|
||||
@@ -244,4 +245,6 @@ public:
|
||||
|
||||
int cdzStatus {-1};
|
||||
int emuStatus {-1};
|
||||
|
||||
std::map<std::string, int64_t> mapAlertCache;
|
||||
};
|
||||
Reference in New Issue
Block a user