Files
energy_storage/src/app/Station.h
2025-09-26 16:51:09 +08:00

272 lines
11 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <memory>
#include <unordered_map>
#include "common/Fields.h"
#include "Policy.h"
class Device;
class MqttClient;
struct TempHumUnit
{
float temp {0};
float hum {0};
TempHumUnit(float temp, float hum) : temp(temp), hum(hum) {};
TempHumUnit() {}
};
struct Fire40Unit
{
//主控数量 R uint16 1 0x0002
//主控ID R uint16 1 0x0003
int statusMain {0}; //主控状态 R uint16 0正常 1预警 2火警 0x0004
//主控硬件版本 R uint16[2] 主控硬件版本 0x0005~0x0006
//主控软件版本 R uint16[2] 主控软件版本 0x0007~0x0008
//主电状态 R uint16 0使用市电 1使用备电 0x0009
//备电电流 R uint32 0.1A 0x000A
//备电电压 R uint32 0.1V 0x000C
//可用容量 R uint32 0.01Ah 0x000E
//可充放容量 R uint32 0.01Ah 0x0010
int usedAlarm {0}; //警铃是否使用 R uint16 0x0012
int statusAlarm {0}; //警铃状态 R uint16 0无效 1掉线 2正常 3启动 0x0013
int usedValve {0}; //瓶头阀是否使用 R uint16 0x0014
int statusValve {0}; //瓶头阀状态 R uint16 0无效 1掉线 2正常 3启动 0x0015
int usedMCP {0}; //手报是否使用 R uint16 0x0016
int statusMCP {0}; //手报状态 R uint16 0无效 1掉线 2正常 3启动 0x0017 // Manual Call Point (MCP)
//簇控制器数量 R uint16 0x0018
//复合探测器总数量 R uint16 0x0019
//烟雾探测器总数量 R uint16 0x001A
//压力探测器总数量 R uint16 0x001B
//吸气式探测器总数量 R uint16 0x001C
//PACK探测器总数量 R uint16 0x001D
//电池总数量 R uint16 0x001E
};
struct CoolingUnit
{
int powerOn {0}; //开关 R uint16 0关机1开机 0x1003
int mode {0}; //采样模式 R uint16 0-出水温度 1-电芯温度 0x1004
int cooling {0}; //制冷状态 R uint16 0关闭, 1启动 0x1005
int heating {0}; //制热状态 R uint16 0关闭, 1启动 0x1006
int highTemp {0}; //高温告警 R uint16 0正常1告警 0x1007
int lowTemp {0}; //低温告警 R uint16 0正常1告警 0x1008
int highPressure {0}; //高压告警 R uint16 0正常1告警 0x1009
int lowPressure {0}; //低压告警 R uint16 0正常1告警 0x100A
//进水温度传感器 R uint16 0正常1告警 0x100B
//出水温度传感器 R uint16 0正常1告警 0x100C
//进水压力传感器 R uint16 0正常1告警 0x100D
//出水压力传感器 R uint16 0正常1告警 0x100E
};
struct AircUnit
{
int powerOn {0}; //开关 R uint16 0关机1开机
int cooling {0}; //启动制冷指令 R uint16 0关闭, 1启动
int airSupply {0}; //启动送风指令 R uint16 0关闭, 1启动
int standby {0}; //启动待机指令 R uint16 0关闭, 1启动
int heating {0}; //启动加热指令 R uint16 0关闭, 1启动
int sensorAlarm {0}; //传感器故障 R uint16 0正常1告警
int voltageAlarm {0}; //高低电压告警 R uint16 0正常1告警
int tempAlarm {0}; //高低温告警 R uint16 0正常1告警
int pressureAlarm {0}; //高低压告警 R uint16 0正常1告警
int compressorAlarm {0};//压缩机告警 R uint16 0正常1告警
//制冷点 R int16 0.1℃ 0x0003
//制冷偏差 R int16 0.1℃ 0x0004
//高温告警值 R int16 0.1℃ 0x0005
//低温告警值 R int16 0.1℃ 0x0006
//制热点 R int16 0.1℃ 0x0007
//制热偏差 R int16 0.1℃ 0x0008
int temp {0}; //当前温度 R int16 0.1℃ 0x0009
int hum {0}; //当前湿度 R int16 0.1℃ 0x000A
//除湿开启温度 R int16 0.1℃ 0x000B
//除湿停止温度 R int16 0.1℃ 0x000C
//除湿开启湿度 R int16 0.1℃ 0x000D
//除湿停止湿度 R int16 0.1℃ 0x000E
};
class Station
{
public:
Station();
void setFields(Fields& fields);
void addDevice(int deviceId, std::shared_ptr<Device> device);
void addDevice(Fields& fields);
std::shared_ptr<Device> getDevice(int deviceId);
void groupDevice();
std::shared_ptr<Device> getDeviceByType(int deviceType, std::string code);
void getDeviceByType(int typeId, std::vector<std::shared_ptr<Device>>& res);
int getDeviceCount(int category);
void getDeviceByCategory(int category, std::vector<std::shared_ptr<Device>>& res);
void setWorkMode(int modeId);
void setPolicy(int policyId);
void initMqtt();
void polling();
int64_t getPollingTS();
void setGarewayWorkMode();
void checkDevice();
string getGatewayMode();
string getGatewayParam();
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);
void readCoolingData(int deviceNo, string addr, int val);
void readGatewayMode(int mode, string p1, string p2, string p3);
void readGatewayStatus(int cdzStatus, int emuStatus);
void setCache(int datatype, std::vector<float>& vd);
void cache();
int posCache {0};
void writeStatistic();
int posDayStat {0};
public:
int stationId {};
std::string name;
std::string code;
int status {0};
std::string operationDate;
SysPolicy policy;
std::string launchDate {};
bool isConnected {false};
int workMode {}; // 运行模式
int runPolicyId {}; // 运行策略
struct {
int mode {-1}; // 运行模式
std::string param1;
std::string param2;
std::string param3;
} gatewayParam;
///////////////////////////////////////////////////////////////////////////////////////////////
/// === 系统统计 ===
// 累计发电量单位kWh
double electGenTotal {};
// 累计入网电量单位kWh
double electGridTotal {};
// 累计收益,单位:元
double incomeTotal {};
// 累计储能充电电量
double electStorageIn {};
// 累计储能放电电量
double electStorageOut {};
// 储能容量
double capacity {};
///////////////////////////////////////////////////////////////////////////////////////////////
/// === 环境 ===
// 光照度
double illuminance {};
// 辐照度
double irradiance {};
// 风速
double windspeed {};
// 温度
double temperature {};
// 湿度
double humidity {};
int aircStatus {0};
int coolingStatus {0};
double voltage {0};
double current {0};
double power {0};
double powerFactor {0};
///////////////////////////////////////////////////////////////////////////////////////////////
/// === 设备信息 ===
std::unordered_map<int, std::shared_ptr<Device>> mapDevice;
std::map<int, std::map<std::string, std::shared_ptr<Device>>> mapDeviceGroup;
// 温湿度信息
std::map<int, TempHumUnit> mapTempHumUnit;
// 消防4.0信息
std::map<int, Fire40Unit> mapFire40Unit;
// 冷机信息
std::map<int, CoolingUnit> mapCoolingUnit;
// 空调信息
std::map<int, AircUnit> mapAircUnit;
///////////////////////////////////////////////////////////////////////////////////////////////
/// === MQTT client
std::shared_ptr<MqttClient> mqttCli {nullptr};
struct {
int64_t ts {0};
float dayElectIn {0.0}; // 日充电电量 R uint32 1kWh 0x002F
float dayElectOut {0.0}; // 日放电电量 R uint32 1kWh 0x0031
float dayFeeIn {0.0}; // 日充电费用 R uint32 1RMB 0x0033
float dayFeeOut {0.0}; // 日放电费用 R uint32 1RMB 0x0035
float dayIncome {0.0}; // 日收益 R int32 1RMB 0x0037
float dayElectIn_J {0.0}; //日正向尖有功电能 R uint32 1kWh 0x0039
float dayElectIn_F {0.0}; //日正向峰有功电能 R uint32 1kWh 0x003B
float dayElectIn_P {0.0}; //日正向平有功电能 R uint32 1kWh 0x003D
float dayElectIn_G {0.0}; //日正向谷有功电能 R uint32 1kWh 0x003F
float dayElectIn_Total {0.0};//日正向总有功电能 R uint32 1kWh 0x0041
float dayElectOut_J {0.0}; //日反向尖有功电能 R uint32 1kWh 0x0043
float dayElectOut_F {0.0}; //日反向峰有功电能 R uint32 1kWh 0x0045
float dayElectOut_P {0.0}; //日反向平有功电能 R uint32 1kWh 0x0047
float dayElectOut_G {0.0}; //日反向谷有功电能 R uint32 1kWh 0x0049
float dayElectOut_Total {0.0}; //日反向总有功电能 R uint32 1kWh 0x004B
float totalElectIn {0.0}; // 总充电电量 R uint32 1kWh 0x004D
float totalElectOut {0.0}; // 总放电电量 R uint32 1kWh 0x004F
float totalFeeIn {0.0}; // 总充电费用 R uint32 1RMB 0x0051
float totalFeeOut {0.0}; // 总放电费用 R uint32 1RMB 0x0053
float totalIncome {0.0}; // 总收益 R int32 1RMB 0x0055
float totalElectIn_J {0.0}; //总正向尖有功电能 R uint32 1kWh 0x0057
float totalElectIn_F {0.0}; //总正向峰有功电能 R uint32 1kWh 0x0059
float totalElectIn_P {0.0}; //总正向平有功电能 R uint32 1kWh 0x005B
float totalElectIn_G {0.0}; //总正向谷有功电能 R uint32 1kWh 0x005D
float totalElectIn_Total {0.0}; //总正向总有功电能 R uint32 1kWh 0x005F
float totalElectOut_J {0.0}; //总反向尖有功电能 R uint32 1kWh 0x0061
float totalElectOut_F {0.0}; //总反向峰有功电能 R uint32 1kWh 0x0063
float totalElectOut_P {0.0}; //总反向平有功电能 R uint32 1kWh 0x0065
float totalElectOut_G {0.0}; //总反向谷有功电能 R uint32 1kWh 0x0067
float totalElectOut_Total {0.0}; //总反向总有功电能 R uint32 1kWh 0x0069
} statData;
///////////////////////////////////////////////////////////////////////////////////////////////
struct {
} runtimeData;
int cdzStatus {-1}; // 充电桩 1在线0离线
int emuStatus {-1}; // 储能 1在线0离线
std::map<std::string, int64_t> mapAlertCache;
///////////////////////////////////////////////////////////////////////////////////////////////
/// 说明从电表中读取对应数据每间隔600秒10分钟缓存一个点位存储到数据库用于绘制一天的电曲线
// 储能充电量缓存key位置索引0->144val电量
std::map<int, float> mapCacheElectIn;
// 储能放电量缓存key位置索引0->144val电量
std::map<int, float> mapCacheElectOut;
// 充电桩充电量缓存key位置索引0->144val电量
std::map<int, float> mapCacheElectCharger;
};