mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
修改MQTT通讯数据解析问题
This commit is contained in:
@@ -16,6 +16,11 @@ void Application::init()
|
||||
{
|
||||
// 初始化系统配置,读取配置文件
|
||||
Config::init("assets/config/app.json");
|
||||
if (Config::option.debug)
|
||||
{
|
||||
spdlog::set_level(spdlog::level::debug); // 设置全局日志等级为 debug
|
||||
spdlog::debug("[app] spdlog debug enable.");
|
||||
}
|
||||
|
||||
// MQTT 数据结构
|
||||
REGAddr::load("assets/config/regaddrs.json");
|
||||
@@ -77,8 +82,8 @@ void Application::runThreadMain()
|
||||
if (!this->isInit) { continue; }
|
||||
}
|
||||
|
||||
static TimeTick ttMqtt(1); // 检查 场站的 MQTT 连接
|
||||
if (ttMqtt.elapse(20))
|
||||
static TimeTick ttMqtt; // 检查 场站的 MQTT 连接
|
||||
if (ttMqtt.elapse(30))
|
||||
{
|
||||
auto& optionMqtt = Config::option.mqtt;
|
||||
if (!optionMqtt.host.empty())
|
||||
@@ -86,22 +91,21 @@ void Application::runThreadMain()
|
||||
for (auto& item : appdata.mapStation)
|
||||
{
|
||||
auto& station = item.second;
|
||||
if (station && station->isOpen)
|
||||
if (station)
|
||||
{
|
||||
// 该函数检查连接状态,若已经连接,则无操作;若未连接,则进行连接操作
|
||||
item.second->initMqtt();
|
||||
// 召测
|
||||
item.second->polling();
|
||||
if (station->isOpen)
|
||||
{
|
||||
// 该函数检查连接状态,若已经连接,则无操作;若未连接,则进行连接操作
|
||||
item.second->initMqtt();
|
||||
// 召测
|
||||
item.second->polling();
|
||||
}
|
||||
// 检查设备的在线状态
|
||||
station->checkDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static TimeTick ttData(1); // 检查数据
|
||||
if (ttData.elapse(20))
|
||||
{
|
||||
//appdata.initFromDB();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,20 +114,14 @@ void Application::runThreadStat()
|
||||
int nCachePos = 0;
|
||||
while (!isQuit)
|
||||
{
|
||||
int64_t tTime = Utils::time();
|
||||
int64_t tDate = Utils::date();
|
||||
int64_t delta = tTime-tDate;
|
||||
int n = delta / 600;
|
||||
int offset = delta % 600;
|
||||
bool flagStore = (delta >=0 && delta < 86400 && offset <= 10 && n != nCachePos);
|
||||
if (flagStore)
|
||||
static TimeTick ttStat(1);
|
||||
if(ttStat.elapse(10))
|
||||
{
|
||||
nCachePos = n;
|
||||
std::string dt = Utils::dateStr(tDate);
|
||||
// // 设备历史数据(电压、电流、功率),存储到 history_day
|
||||
// 设备历史数据(电压、电流、功率),存储到 history_day
|
||||
// 统计数据,存储到 stat_day
|
||||
for (auto item: appdata.mapStation)
|
||||
{
|
||||
item.second->writeRuntimeData(dt, nCachePos);
|
||||
item.second->writeStatistic();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -131,12 +129,6 @@ void Application::runThreadStat()
|
||||
//spdlog::info("保存历史数据倒计时: {}", 600 - offset);
|
||||
}
|
||||
|
||||
// 统计计算,存储到 stat_station
|
||||
for (auto& station : appdata.mapStation)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "common/JsonN.h"
|
||||
#include "common/Spdlogger.h"
|
||||
#include "AppData.h"
|
||||
#include "protocol/MqttEntity.h"
|
||||
|
||||
AppOption Config::option;
|
||||
|
||||
@@ -19,49 +20,106 @@ bool Config::init(std::string filename)
|
||||
}
|
||||
spdlog::info("[config] load config file success, filename={}", filename);
|
||||
|
||||
JSON::read(jsonroot, "debug", option.debug);
|
||||
JSON::read(jsonroot, "weburl", option.webSrvUrl);
|
||||
JSON::read(jsonroot, "launchdate", option.lunchDate);
|
||||
|
||||
|
||||
if (jsonroot.contains("database"))
|
||||
{
|
||||
njson json = jsonroot.at("database");
|
||||
njson& json = jsonroot.at("database");
|
||||
JSON::read(json, "host", option.database.host);
|
||||
JSON::read(json, "port", option.database.port);
|
||||
JSON::read(json, "user", option.database.user);
|
||||
JSON::read(json, "passwd", option.database.passwd);
|
||||
JSON::read(json, "dbname", option.database.dbname);
|
||||
|
||||
spdlog::info("[config] parse database success. host={}", option.database.host);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("[config] parse database failed: not found.");
|
||||
spdlog::error("[config] parse database failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("http"))
|
||||
{
|
||||
njson json = jsonroot.at("http");
|
||||
std:string token;
|
||||
JSON::read(json, "token", token);
|
||||
option.http.useToken = !token.empty();
|
||||
njson& json = jsonroot.at("http");
|
||||
JSON::read(json, "token", option.http.useToken);
|
||||
JSON::read(json, "port", option.http.port);
|
||||
JSON::read(json, "encryption", option.http.encryption);
|
||||
JSON::read(json, "encryptKey", option.http.encryptKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("[config] parse http failed: not found.");
|
||||
spdlog::error("[config] parse http failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("mqtt"))
|
||||
{
|
||||
njson json = jsonroot.at("mqtt");
|
||||
njson& json = jsonroot.at("mqtt");
|
||||
JSON::read(json, "host", option.mqtt.host);
|
||||
JSON::read(json, "username", option.mqtt.username);
|
||||
JSON::read(json, "password", option.mqtt.password);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("[config] parse mqtt failed: not found.");
|
||||
spdlog::error("[config] parse mqtt failed: not found.");
|
||||
}
|
||||
|
||||
JSON::read(jsonroot, "weburl", option.webSrvUrl);
|
||||
JSON::read(jsonroot, "launchdate", option.lunchDate);
|
||||
if (jsonroot.contains("view"))
|
||||
{
|
||||
njson& json = jsonroot["view"];
|
||||
JSON::read(json, "latitude", option.view.latitude);
|
||||
JSON::read(json, "longitude", option.view.longitude);
|
||||
JSON::read(json, "altitude", option.view.altitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[config] parse view failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("video"))
|
||||
{
|
||||
njson& json = jsonroot["video"];
|
||||
for (auto& item: json.items())
|
||||
{
|
||||
auto& key = item.key();
|
||||
auto& jsonItem = item.value();
|
||||
auto& itemVideo = option.mapVideo[key];
|
||||
JSON::read(jsonItem, "host", itemVideo.host);
|
||||
JSON::read(jsonItem, "port", itemVideo.port);
|
||||
JSON::read(jsonItem, "user", itemVideo.user);
|
||||
JSON::read(jsonItem, "passwd", itemVideo.passwd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[config] parse video failed: not found.");
|
||||
}
|
||||
|
||||
if (jsonroot.contains("topic"))
|
||||
{
|
||||
njson& json = jsonroot["topic"];
|
||||
for (auto& item: json.items())
|
||||
{
|
||||
auto& key = item.key();
|
||||
auto& jsonItem = item.value();
|
||||
auto& info = MqttClient::s_mapTopicInfo[key];
|
||||
info.name = key;
|
||||
JSON::read(jsonItem, "deviceType", info.deviceType);
|
||||
JSON::read(jsonItem, "polling", info.polling);
|
||||
JSON::read(jsonItem, "enabled", info.enabled);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
AppOption::VideoInfo* Config::getVideoInfo(std::string name)
|
||||
{
|
||||
auto iter = option.mapVideo.find(name);
|
||||
if (iter!=option.mapVideo.end())
|
||||
{
|
||||
return &(iter->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1,23 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct DatabaseOption
|
||||
{
|
||||
std::string host;
|
||||
int port;
|
||||
std::string user;
|
||||
std::string passwd;
|
||||
std::string dbname;
|
||||
};
|
||||
|
||||
struct AppOption
|
||||
{
|
||||
DatabaseOption database;
|
||||
int debug {0};
|
||||
std::string webSrvUrl;
|
||||
std::string lunchDate;
|
||||
|
||||
struct {
|
||||
bool useToken {true};
|
||||
std::string host;
|
||||
int port;
|
||||
std::string user;
|
||||
std::string passwd;
|
||||
std::string dbname;
|
||||
} database;
|
||||
|
||||
struct {
|
||||
int useToken {1};
|
||||
int port {0};
|
||||
int encryption {1};
|
||||
std::string encryptKey;
|
||||
} http;
|
||||
|
||||
struct {
|
||||
@@ -26,8 +30,20 @@ struct AppOption
|
||||
std::string password;
|
||||
} mqtt;
|
||||
|
||||
std::string webSrvUrl;
|
||||
std::string lunchDate;
|
||||
struct {
|
||||
float latitude {0};
|
||||
float longitude {0};
|
||||
float altitude {0};
|
||||
} view;
|
||||
|
||||
struct VideoInfo {
|
||||
std::string host;
|
||||
int port;
|
||||
std::string user;
|
||||
std::string passwd;
|
||||
};
|
||||
|
||||
std::map<std::string, VideoInfo> mapVideo;
|
||||
|
||||
};
|
||||
|
||||
@@ -36,6 +52,7 @@ class Config
|
||||
public:
|
||||
static bool init(std::string filename);
|
||||
|
||||
static AppOption::VideoInfo* getVideoInfo(std::string name);
|
||||
|
||||
static AppOption option;
|
||||
};
|
||||
@@ -34,16 +34,14 @@ void REGAddr::load(std::string filename)
|
||||
for (auto& item : jsonaddrs)
|
||||
{
|
||||
std::string addr = item["key"];
|
||||
mapItem[addr] = RegAddrUnit(addr, item["datatype"], item["remark"]);
|
||||
std::string datatype = JSON::read<std::string>(item, "datatype");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for (auto& item: s_mapReg["EMS_YC"])
|
||||
//{
|
||||
// auto& unit = item.second;
|
||||
// spdlog::info("[{}]={}, {}", unit.key, unit.datatype, unit.remark);
|
||||
//}
|
||||
}
|
||||
|
||||
std::map<std::string, RegAddrUnit>* REGAddr::getRegMap(std::string name)
|
||||
|
||||
@@ -2,21 +2,57 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
enum class EAlertType
|
||||
{
|
||||
SYS = 1, // 系统告警
|
||||
USER = 2, // 用户告警
|
||||
DEVICE = 3, // 设备告警
|
||||
};
|
||||
|
||||
enum class EDeviceType
|
||||
{
|
||||
//1 变压器 0
|
||||
//2 配电柜 0
|
||||
//3 电表 1
|
||||
//4 门禁 0
|
||||
//5 空调 0
|
||||
//6 照明 0
|
||||
//7 消防 0
|
||||
//8 光照监测设备 0
|
||||
//9 风速监测设备 0
|
||||
//10 温湿度监测设备 0
|
||||
//11 烟感监测设备 0
|
||||
//12 水浸传感器 0
|
||||
//13 视频监控 4
|
||||
//14 冷机 0
|
||||
//15 网关 0
|
||||
//100 储能预制舱 1
|
||||
EMS = 101,//101 EMS 1
|
||||
PCS = 102, //102 PCS 1
|
||||
PCU = 103, //103 PCU 1
|
||||
BMS = 104, //104 BMS 1
|
||||
BCU = 105, //105 BCU 1
|
||||
//106 充电桩 2
|
||||
//107 充电枪 2
|
||||
//108 集中器 2
|
||||
//109 光伏板 3
|
||||
//110 风力发电机 3
|
||||
};
|
||||
|
||||
|
||||
struct RegAddrUnit
|
||||
{
|
||||
std::string key;
|
||||
std::string datatype;
|
||||
int bytes {0};
|
||||
std::string name;
|
||||
std::string remark;
|
||||
int ratio {1};
|
||||
int alert {0};
|
||||
|
||||
RegAddrUnit() {}
|
||||
RegAddrUnit(std::string key, std::string datatype, std::string remark)
|
||||
: key(key), datatype(datatype), remark(remark)
|
||||
RegAddrUnit(std::string key, std::string datatype, int alert, std::string name, std::string remark)
|
||||
: key(key), datatype(datatype), alert(alert), name(name), remark(remark)
|
||||
{
|
||||
if (datatype == "uint16" || datatype == "int16") { bytes = 1; }
|
||||
else if (datatype == "uint32" || datatype == "int32") { bytes = 2; }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
class CommEntity;
|
||||
|
||||
// 需要在前端展示的设备参数
|
||||
struct DeviceParamAddr
|
||||
{
|
||||
std::string name;
|
||||
@@ -35,6 +36,8 @@ public:
|
||||
static std::shared_ptr<Device> create(Fields& fields);
|
||||
static void loadParamAddr(std::string filename);
|
||||
|
||||
Device();
|
||||
|
||||
void setFields(Fields& fields);
|
||||
|
||||
int startComm();
|
||||
@@ -55,6 +58,8 @@ public:
|
||||
void getRuntimeParams(std::vector<std::pair<std::string, std::string>>& params);
|
||||
void getRuntimeParams1(std::vector<std::pair<std::string, std::string>>& params);
|
||||
|
||||
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;
|
||||
@@ -73,6 +78,8 @@ public:
|
||||
int online = 0;
|
||||
int running = 0;
|
||||
|
||||
int64_t ts {0};
|
||||
|
||||
//std::map<std::string, std::string> mapAttrs;
|
||||
Fields attrs;
|
||||
|
||||
@@ -87,5 +94,7 @@ public:
|
||||
|
||||
std::map<std::string, DeviceParamAddr*> mapMyParams;
|
||||
|
||||
std::vector<std::vector<float>> vecBCUUnit;
|
||||
int bcuCount {0};
|
||||
|
||||
};
|
||||
|
||||
@@ -99,13 +99,13 @@ void SysPolicy::parseJsonPeriods(njson& jsonroot)
|
||||
{
|
||||
auto& jsonP = item["charge_time"];
|
||||
vecPeriods1[i].push_back({jsonP[0], "谷"}); // 第一/二次充电开始
|
||||
vecPeriods1[i].push_back({jsonP[1], "平"}); // 第一/二次充电结束
|
||||
vecPeriods1[i].push_back({jsonP[1], ""}); // 第一/二次充电结束
|
||||
}
|
||||
if (item.contains("discharge_time") && item["discharge_time"].size() >= 2)
|
||||
{
|
||||
auto& jsonP = item["discharge_time"];
|
||||
vecPeriods1[i].push_back({jsonP[0], "尖"}); // 第一/二次放电开始
|
||||
vecPeriods1[i].push_back({jsonP[1], "峰"}); // 第一/二次放电结束
|
||||
vecPeriods1[i].push_back({jsonP[1], ""}); // 第一/二次放电结束
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,9 +123,8 @@ static void PeriodsTimeStrToInt(std::string str, int& h, int& m)
|
||||
|
||||
void SysPolicy::getGatewayJsonPeriods(njson& json)
|
||||
{
|
||||
if (type == 1 || type == 5)
|
||||
if (type == 1)
|
||||
{
|
||||
// std::vector<std::vector<std::pair<std::string, std::string>>>
|
||||
for (auto& itemMonth: vecPeriods1)
|
||||
{
|
||||
njson jsonArrayMonth = njson::array();
|
||||
@@ -143,4 +142,22 @@ void SysPolicy::getGatewayJsonPeriods(njson& json)
|
||||
json.push_back(jsonArrayMonth);
|
||||
}
|
||||
}
|
||||
else if (type == 5)
|
||||
{
|
||||
if (vecPeriods1.size()>0)
|
||||
{
|
||||
for (auto& item: vecPeriods1[0])
|
||||
{
|
||||
int h = 0; int m = 0;
|
||||
PeriodsTimeStrToInt(item.first, h, m);
|
||||
int p = 1;
|
||||
if (item.second == "谷") p = 1;
|
||||
else if (item.second == "平") p = 2;
|
||||
else if (item.second == "峰") p = 3;
|
||||
else if (item.second == "尖") p = 4;
|
||||
else p = 0;
|
||||
json.push_back({h, m, p});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,24 +8,12 @@
|
||||
#include "protocol/MqttEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
#include "app/Config.h"
|
||||
#include "common/Snowflake.h"
|
||||
#include "app/DataStruct.h"
|
||||
|
||||
Station::Station() : stationId(0)
|
||||
{
|
||||
mqttCli = std::make_shared<MqttClient>();
|
||||
|
||||
// 测试,设置默认值
|
||||
for (int i = 1; i<=5; i++) {
|
||||
auto& unit = mapCoolingUnit[i];
|
||||
unit.powerOn = 1;
|
||||
unit.mode = i%2;
|
||||
}
|
||||
|
||||
for (int i = 1; i<=5; i++) {
|
||||
auto& unit = mapAircUnit[i];
|
||||
unit.powerOn = 1;
|
||||
unit.temp = Utils::random(20, 40);
|
||||
unit.hum = Utils::random(20, 80);
|
||||
}
|
||||
}
|
||||
|
||||
void Station::setFields(Fields& fields)
|
||||
@@ -33,12 +21,12 @@ void Station::setFields(Fields& fields)
|
||||
this->stationId = fields.get<int>(DMStation::STATION_ID);
|
||||
this->name = fields.value(DMStation::NAME);
|
||||
this->capacity = fields.get<double>(DMStation::CAPACITY);
|
||||
this->workModeId = fields.get<int>(DMStation::WORK_MODE);
|
||||
this->workMode = fields.get<int>(DMStation::WORK_MODE);
|
||||
this->code = fields.value(DMStation::CODE);
|
||||
this->status = fields.get<int>(DMStation::STATUS);
|
||||
this->operationDate = fields.value(DMStation::OPERATION_DATE);
|
||||
this->isOpen = fields.get<int>(DMStation::STATUS);
|
||||
|
||||
this->launchDate = fields.value("operation_date");
|
||||
this->policy.setFields(fields);
|
||||
}
|
||||
|
||||
@@ -134,7 +122,7 @@ void Station::getDeviceByCategory(int category, std::vector<std::shared_ptr<Devi
|
||||
|
||||
void Station::setWorkMode(int modeId)
|
||||
{
|
||||
this->workModeId = modeId;
|
||||
this->workMode = modeId;
|
||||
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
|
||||
.update(DMStation::WORK_MODE, std::to_string(modeId))
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(stationId)).str();
|
||||
@@ -157,71 +145,6 @@ void Station::setPolicy(int policyId)
|
||||
}
|
||||
}
|
||||
|
||||
static std::string MapValueToJson(int npos, std::map<int, double>& mapV)
|
||||
{
|
||||
njson jsonarray = njson::array();
|
||||
for (int i = 0; i<=npos; i++)
|
||||
{
|
||||
jsonarray.push_back(mapV[i]);
|
||||
}
|
||||
return jsonarray.dump();
|
||||
}
|
||||
|
||||
void Station::writeRuntimeData(std::string dt, int npos)
|
||||
{
|
||||
auto dao = DaoEntity::create("history_day");
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
auto device = iter->second;
|
||||
if (device->cache(npos))
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("dt", dt);
|
||||
fields.set("station_id", this->stationId);
|
||||
fields.set("device_id", device->deviceId);
|
||||
fields.set("datatype", 1);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheVoltage));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 2);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheCurrent));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 3);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCachePower));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
spdlog::info("[device] write runtime date to database, deviceId={}", device->deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Station::writeStatistic(std::string dt)
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("storage_elect_in", statData.totalElectIn);
|
||||
fields.set("storage_elect_out", statData.totalElectOut);
|
||||
//fields.set("storage_num_in", statData.totalElectIn);
|
||||
//fields.set("storage_num_out", 0);
|
||||
//fields.set("storage_num_err", 0);
|
||||
//fields.set("storage_t_in", 0);
|
||||
//fields.set("storage_t_out", 0);
|
||||
//fields.set("storage_usage", 0);
|
||||
//fields.set("solar_elect_gen", 0);
|
||||
//fields.set("solar_elect_grid", 0);
|
||||
//fields.set("solar_num_err", 0);
|
||||
//fields.set("solar_t", 0);
|
||||
//fields.set("solar_usage", 0);
|
||||
//fields.set("charge_elect", 0);
|
||||
//fields.set("charge_num", 0);
|
||||
//fields.set("charge_num_err", 0);
|
||||
//fields.set("charge_t", 0);
|
||||
//fields.set("charge_usage", 0);
|
||||
fields.set("income_elect", statData.totalIncome);
|
||||
//fields.set("income_charge", 0);
|
||||
//fields.set("usage_rate", 0);
|
||||
}
|
||||
|
||||
void Station::initMqtt()
|
||||
{
|
||||
if (status!=0 && mqttCli)
|
||||
@@ -249,7 +172,7 @@ void Station::setGarewayWorkMode()
|
||||
njson json;
|
||||
json["ts"] = Utils::time();
|
||||
json["no"] = 1; // 设备编号
|
||||
json["40001"] = this->workModeId;
|
||||
json["40001"] = this->workMode;
|
||||
|
||||
if (policy.type == 1)
|
||||
{
|
||||
@@ -267,31 +190,75 @@ void Station::setGarewayWorkMode()
|
||||
mqttCli->publish("Gateway_YT", text);
|
||||
}
|
||||
|
||||
|
||||
void Station::setRuntimeData(string addr, int val)
|
||||
void Station::checkDevice()
|
||||
{
|
||||
if (addr == "0x110E") { statData.dayElectIn = val; } //日充电电量 R uint32 1kWh 0 0x110E
|
||||
else if (addr == "0x1110") { statData.dayElectOut = val; } //日放电电量 R uint32 1kWh 0 0x1110
|
||||
else if (addr == "0x1112") { statData.dayIncomeIn = val; } //日充电费用 R uint32 1RMB 0 0x1112
|
||||
else if (addr == "0x1114") { statData.dayIncomeOut = val; } //日放电费用 R uint32 1RMB 0 0x1114
|
||||
else if (addr == "0x1116") { statData.dayIncome = val; } //日收益 R int32 1RMB 0 0x1116
|
||||
else if (addr == "0x112C") { statData.totalElectIn = val; } //总充电电量 R uint32 1kWh 6659(0x112D) 0x112C
|
||||
else if (addr == "0x112E") { statData.totalElectOut = val; } //总放电电量 R uint32 1kWh 4925(0x112F) 0x112E
|
||||
else if (addr == "0x1130") { statData.totalIncomeIn = val; } //总充电费用 R uint32 1RMB 6605(0x1131) 0x1130
|
||||
else if (addr == "0x1132") { statData.totalIncomeOut = val; } //总放电费用 R uint32 1RMB 4949(0x1133) 0x1132
|
||||
else if (addr == "0x1134") { statData.totalIncome = val; } //总收益 R int32 1RMB -1 0x1134
|
||||
for (auto& item: mapDevice)
|
||||
{
|
||||
auto& device = item.second;
|
||||
if (device)
|
||||
{
|
||||
if (Utils::time() - device->ts > 60*6)
|
||||
{
|
||||
device->online = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Station::setTHData(int deviceNo, string addr, int val)
|
||||
void Station::readAlert(std::shared_ptr<Device> device, 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);
|
||||
}
|
||||
|
||||
void Station::readRuntimeData(int deviceNo, string addr, int val)
|
||||
{
|
||||
if (deviceNo == 1)
|
||||
{
|
||||
if (addr == "0x000B") { this->voltage = val; } // A相电压 R uint32 1V 0x000B
|
||||
if (addr == "0x0011") { this->current = val; } // A相电流 R int32 1A 0x0011
|
||||
if (addr == "0x0011") { this->power = val; } // 三相总有功 R int32 1kW 0x0023
|
||||
}
|
||||
else if (deviceNo == 2)
|
||||
{
|
||||
statData.ts = Utils::time();
|
||||
if (addr == "0x002F") { statData.dayElectIn = val; } //日充电电量 R uint32 1kWh 0x002F
|
||||
else if (addr == "0x0031") { statData.dayElectOut = val; } //日放电电量 R uint32 1kWh 0x0031
|
||||
else if (addr == "0x0033") { statData.dayFeeIn = val; } //日充电费用 R uint32 1RMB 0x0033
|
||||
else if (addr == "0x0035") { statData.dayFeeOut = val; } //日放电费用 R uint32 1RMB 0x0035
|
||||
else if (addr == "0x0037") { statData.dayIncome = val; } //日收益 R int32 1RMB 0x0037
|
||||
else if (addr == "0x004D") { statData.totalElectIn = val; } //总充电电量 R uint32 1kWh 0x004D
|
||||
else if (addr == "0x004F") { statData.totalElectOut = val; } //总放电电量 R uint32 1kWh 0x004F
|
||||
else if (addr == "0x0051") { statData.totalFeeIn = val; } //总充电费用 R uint32 1RMB 0x0051
|
||||
else if (addr == "0x0053") { statData.totalFeeOut = val; } //总放电费用 R uint32 1RMB 0x0053
|
||||
else if (addr == "0x0055") { statData.totalIncome = val; } //总收益 R int32 1RMB 0x0055
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readTHData(int deviceNo, string addr, int val)
|
||||
{
|
||||
auto& unit = mapTempHumUnit[deviceNo];
|
||||
if (addr == "0x0001") { ; } //所属通道号 R uint16 1 0x0001
|
||||
else if (addr == "0x0002") { ; } //所属温湿度号 R uint16 1~10 0x0002
|
||||
else if (addr == "0x0003") { unit.temp = float(val) * 0.1; } //温度 R int16 0.1℃ 0x0003
|
||||
else if (addr == "0x0004") { unit.hum = float(val) * 0.1; } //湿度 R int16 0.1℃ 0x0004
|
||||
else if (addr == "0x0003") //温度 R int16 0.1℃ 0x0003
|
||||
{
|
||||
unit.temp = float(val) * 0.1;
|
||||
if (deviceNo == 1) temperature = unit.temp;
|
||||
}
|
||||
else if (addr == "0x0004") //湿度 R int16 0.1℃ 0x0004
|
||||
{
|
||||
unit.hum = float(val) * 0.1;
|
||||
if (deviceNo == 1) humidity = unit.hum;
|
||||
}
|
||||
}
|
||||
|
||||
void Station::setFire40Data(int deviceNo, string addr, int val)
|
||||
void Station::readFire40Data(int deviceNo, string addr, int val)
|
||||
{
|
||||
auto& unit = mapFire40Unit[deviceNo];
|
||||
|
||||
@@ -322,14 +289,14 @@ void Station::setFire40Data(int deviceNo, string addr, int val)
|
||||
}
|
||||
|
||||
|
||||
void Station::setCoolingData(int deviceNo, string addr, int val)
|
||||
void Station::readCoolingData(int deviceNo, string addr, int val)
|
||||
{
|
||||
auto& unit = mapCoolingUnit[deviceNo];
|
||||
|
||||
if (addr == "0x1001") { ; } //所属通道号 R uint16 1 0x1001
|
||||
else if (addr == "0x1002") { ; }// 所属冷机号 R uint16 1~10 0x1002
|
||||
else if (addr == "0x1003") { unit.powerOn = val; }// 开关 R uint16 0:关机,1:开机 0x1003
|
||||
else if (addr == "0x1004") { ; }// 采样模式 R uint16 0-出水温度 1-电芯温度 0x1004
|
||||
else if (addr == "0x1003") { coolingStatus = unit.powerOn = val; }// 开关 R uint16 0:关机,1:开机 0x1003
|
||||
else if (addr == "0x1004") { unit.mode = val; }// 采样模式 R uint16 0-出水温度 1-电芯温度 0x1004
|
||||
else if (addr == "0x1005") { unit.cooling = val; }// 制冷状态 R uint16 0:关闭, 1:启动 0x1005
|
||||
else if (addr == "0x1006") { unit.heating = val; }// 制热状态 R uint16 0:关闭, 1:启动 0x1006
|
||||
else if (addr == "0x1007") { unit.highTemp = val; }// 高温告警 R uint16 0:正常,1:告警 0x1007
|
||||
@@ -340,4 +307,135 @@ void Station::setCoolingData(int deviceNo, string addr, int val)
|
||||
else if (addr == "0x100C") { ; }// 出水温度传感器 R uint16 0:正常,1:告警 0x100C
|
||||
else if (addr == "0x100D") { ; }// 进水压力传感器 R uint16 0:正常,1:告警 0x100D
|
||||
else if (addr == "0x100E") { ; }// 出水压力传感器 R uint16 0:正常,1:告警 0x100E
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readGatewayMode(int mode)
|
||||
{
|
||||
if (mode != this->workMode)
|
||||
{
|
||||
//this->setGarewayWorkMode();
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readGatewayStatus(int cdzStatus, int emuStatus)
|
||||
{
|
||||
//充电桩 1:在线,0:离线
|
||||
if (cdzStatus >= 0)
|
||||
{
|
||||
if (cdzStatus != this->cdzStatus)
|
||||
{
|
||||
std::string text = "场站[" + name + "(" + std::to_string(stationId) + ")]充电桩状态变化:" + (cdzStatus>0 ? "在线" : "离线");
|
||||
if (this->cdzStatus < 0) { text = "系统启动," + text; }
|
||||
DAO::insertSystemLogDevice(stationId, 0, text, cdzStatus);
|
||||
this->cdzStatus = cdzStatus;
|
||||
}
|
||||
}
|
||||
//储能 1:在线,0:离线
|
||||
if (emuStatus >= 0)
|
||||
{
|
||||
if (emuStatus != this->emuStatus)
|
||||
{
|
||||
std::string text = "场站[" + name + "(" + std::to_string(stationId) + ")]储能EMU状态变化:" + (emuStatus>0 ? "在线" : "离线");
|
||||
if (this->emuStatus < 0) { text = "系统启动," + text; }
|
||||
DAO::insertSystemLogDevice(stationId, 0, text, emuStatus);
|
||||
this->emuStatus = emuStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::string MapValueToJson(int npos, std::map<int, double>& mapV)
|
||||
{
|
||||
njson jsonarray = njson::array();
|
||||
for (int i = 0; i<=npos; i++)
|
||||
{
|
||||
jsonarray.push_back(mapV[i]);
|
||||
}
|
||||
return jsonarray.dump();
|
||||
}
|
||||
|
||||
void Station::writeStatistic()
|
||||
{
|
||||
auto dao = DaoEntity::create("history_day");
|
||||
|
||||
std::string dt = Utils::dateStr();
|
||||
int64_t tTime = Utils::time();
|
||||
int64_t tDate = Utils::date();
|
||||
int npos = (tTime-tDate) / 600;
|
||||
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
auto device = iter->second;
|
||||
if (device->cache(npos))
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("dt", dt);
|
||||
fields.set("station_id", this->stationId);
|
||||
fields.set("device_id", device->deviceId);
|
||||
fields.set("datatype", 1);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheVoltage));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 2);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheCurrent));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 3);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCachePower));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
//spdlog::info("[device] write runtime date to database, deviceId={}", device->deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
if (statData.ts != 0)
|
||||
{
|
||||
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);
|
||||
fields.set("fee_in", statData.dayFeeIn);
|
||||
fields.set("fee_out", statData.dayFeeOut);
|
||||
fields.set("income", statData.dayIncome);
|
||||
//fields.set("num_in", "");
|
||||
//fields.set("num_out", "");
|
||||
//fields.set("num_err", "");
|
||||
//fields.set("t_in", "");
|
||||
//fields.set("t_out", "");
|
||||
//fields.set("usage_rate", "");
|
||||
fields.set("elect_in_total", statData.totalElectIn);
|
||||
fields.set("elect_out_total", statData.totalElectOut);
|
||||
fields.set("fee_in_total", statData.totalFeeIn);
|
||||
fields.set("fee_out_total", statData.totalFeeOut);
|
||||
fields.set("income_total", statData.totalIncome);
|
||||
|
||||
dao->setTableName("stat_storage");
|
||||
std::vector<std::string> vecKeys = {
|
||||
"elect_in", "elect_out", "num_in", "num_out", "num_err", "t_in", "t_out", "usage_rate", "fee_in", "fee_out",
|
||||
"elect_in_total", "elect_out_total", "fee_in_total", "fee_out_total", "income_total"
|
||||
};
|
||||
dao->duplicateUpdate(fields, vecKeys);
|
||||
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("dt", Utils::dateStr(statData.ts));
|
||||
fields.set("station_id", this->stationId);
|
||||
fields.set("device_id", 0);
|
||||
fields.set("storage_elect_in", statData.dayElectIn);
|
||||
fields.set("storage_elect_out", statData.dayElectOut);
|
||||
fields.set("income_elect", statData.dayIncome);
|
||||
DAO::insertStatStation(dao, fields);
|
||||
}
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("station_id", this->stationId);
|
||||
fields.set("elect_in", statData.dayElectIn);
|
||||
fields.set("elect_out", statData.dayElectOut);
|
||||
fields.set("income", statData.dayIncome);
|
||||
dao->setTableName("stat_total");
|
||||
dao->duplicateUpdate(fields, {"elect_in", "elect_out", "income"});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,17 +109,20 @@ public:
|
||||
void setWorkMode(int modeId);
|
||||
void setPolicy(int policyId);
|
||||
|
||||
void writeRuntimeData(std::string dt, int npos);
|
||||
void writeStatistic(std::string dt);
|
||||
|
||||
void initMqtt();
|
||||
void polling();
|
||||
void setGarewayWorkMode();
|
||||
void checkDevice();
|
||||
|
||||
void setRuntimeData(string addr, int val);
|
||||
void setTHData(int deviceNo, string addr, int val);
|
||||
void setFire40Data(int deviceNo, string addr, int val);
|
||||
void setCoolingData(int deviceNo, string addr, int val);
|
||||
void readAlert(std::shared_ptr<Device> device, 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);
|
||||
void readCoolingData(int deviceNo, string addr, int val);
|
||||
void readGatewayMode(int mode);
|
||||
void readGatewayStatus(int cdzStatus, int emuStatus);
|
||||
|
||||
void writeStatistic();
|
||||
|
||||
public:
|
||||
int stationId {};
|
||||
@@ -129,14 +132,13 @@ public:
|
||||
int status {0};
|
||||
std::string operationDate;
|
||||
SysPolicy policy;
|
||||
std::string launchDate {};
|
||||
|
||||
bool isConnected {false};
|
||||
|
||||
int workModeId {}; // 运行模式
|
||||
int workMode {}; // 运行模式
|
||||
int runPolicyId {}; // 运行策略
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// === 系统统计 ===
|
||||
// 累计发电量,单位:kWh
|
||||
@@ -185,6 +187,12 @@ public:
|
||||
double temperature {};
|
||||
// 湿度
|
||||
double humidity {};
|
||||
int aircStatus {0};
|
||||
int coolingStatus {0};
|
||||
double voltage {0};
|
||||
double current {0};
|
||||
double power {0};
|
||||
double powerFactor {0};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// === 设备信息 ===
|
||||
@@ -207,25 +215,25 @@ public:
|
||||
|
||||
|
||||
struct {
|
||||
int64_t ts;
|
||||
int64_t ts {0};
|
||||
|
||||
double totalElectIn; //总充电电量 R uint32 1kWh 6659(0x112D) 0x112C
|
||||
double totalElectOut; //总放电电量 R uint32 1kWh 4925(0x112F) 0x112E
|
||||
double totalIncomeIn; //总充电费用 R uint32 1RMB 6605(0x1131) 0x1130
|
||||
double totalIncomeOut; //总放电费用 R uint32 1RMB 4949(0x1133) 0x1132
|
||||
double totalIncome; //总收益 R int32 1RMB -1 0x1134
|
||||
float totalElectIn {0.0}; //总充电电量 R uint32 1kWh 6659(0x112D) 0x112C
|
||||
float totalElectOut {0.0}; //总放电电量 R uint32 1kWh 4925(0x112F) 0x112E
|
||||
float totalFeeIn {0.0}; //总充电费用 R uint32 1RMB 6605(0x1131) 0x1130
|
||||
float totalFeeOut {0.0}; //总放电费用 R uint32 1RMB 4949(0x1133) 0x1132
|
||||
float totalIncome {0.0}; //总收益 R int32 1RMB -1 0x1134
|
||||
//储能充放电时段hh R uint16 时 336 0x01 0x121C
|
||||
//储能充放电时段mm R uint16 分 0 0x01 0x121D
|
||||
//储能充放电时段ss R uint16 秒 0 0x01 0x121E
|
||||
|
||||
double totalDurationIn;
|
||||
double totalDurationOut;
|
||||
float totalDurationIn {0.0};
|
||||
float totalDurationOut {0.0};
|
||||
|
||||
double dayElectIn; // 日充电电量 R uint32 1kWh 0 0x110E
|
||||
double dayElectOut; // 日放电电量 R uint32 1kWh 0 0x1110
|
||||
double dayIncomeIn; // 日充电费用 R uint32 1RMB 0 0x1112
|
||||
double dayIncomeOut; // 日放电费用 R uint32 1RMB 0 0x1114
|
||||
double dayIncome; // 日收益 R int32 1RMB 0 0x1116
|
||||
float dayElectIn {0.0}; // 日充电电量 R uint32 1kWh 0 0x110E
|
||||
float dayElectOut {0.0}; // 日放电电量 R uint32 1kWh 0 0x1110
|
||||
float dayFeeIn {0.0}; // 日充电费用 R uint32 1RMB 0 0x1112
|
||||
float dayFeeOut {0.0}; // 日放电费用 R uint32 1RMB 0 0x1114
|
||||
float dayIncome {0.0}; // 日收益 R int32 1RMB 0 0x1116
|
||||
|
||||
} statData;
|
||||
|
||||
@@ -233,4 +241,7 @@ public:
|
||||
struct {
|
||||
} runtimeData;
|
||||
|
||||
|
||||
int cdzStatus {-1};
|
||||
int emuStatus {-1};
|
||||
};
|
||||
Reference in New Issue
Block a user