432 lines
15 KiB
C#
432 lines
15 KiB
C#
using HslCommunication.MQTT;
|
|
using OrpaonEMS.App.Com;
|
|
using OrpaonEMS.App.Models;
|
|
using OrpaonEMS.App.PrismEvent;
|
|
using OrpaonEMS.Core;
|
|
using OrpaonEMS.Core.Enums;
|
|
using OrpaonEMS.Model;
|
|
using OrpaonEMS.Model.Enums;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Documents;
|
|
|
|
namespace OrpaonEMS.App.Services
|
|
{
|
|
/// <summary>
|
|
/// 系统配置服务中心
|
|
/// </summary>
|
|
public class ConfigDataService : BindableBase
|
|
{
|
|
public ConfigDataService(IFreeSql freeSql, ILogService logService, IEventAggregator eventAggregator)
|
|
{
|
|
FreeSql = freeSql;
|
|
LogService = logService;
|
|
_eventAggregator = eventAggregator;
|
|
|
|
//储能运行配置值的实例化-初始值
|
|
energyStorageRunConfig = new EnergyStorageRunConfig();
|
|
|
|
energyStorageRunConfig.PcsChargOffset = double.Parse(ConfigHelper.GetValue("PcsChargOffset"));
|
|
energyStorageRunConfig.PcsDisChargOffset = double.Parse(ConfigHelper.GetValue("PcsDisChargOffset"));
|
|
energyStorageRunConfig.MaxBatChargRatio = double.Parse(ConfigHelper.GetValue("MaxBatChargRatio"));
|
|
energyStorageRunConfig.MaxBatDisChargRatio = double.Parse(ConfigHelper.GetValue("MaxBatDisChargRatio"));
|
|
energyStorageRunConfig.BMSSocUpSignLimitValue = double.Parse(ConfigHelper.GetValue("BMSSocUpSignLimitValue"));
|
|
energyStorageRunConfig.BMSSocDownSignLimitValue = double.Parse(ConfigHelper.GetValue("BMSSocDownSignLimitValue"));
|
|
|
|
|
|
|
|
IsMaster = ConfigHelper.GetValue("IsMaster") == "1" ? true : false;
|
|
ServerUrl = ConfigHelper.GetValue("ServerUrl");
|
|
Station = ushort.Parse(ConfigHelper.GetValue("Station"));
|
|
BMSIP = ConfigHelper.GetValue("BMSIP");
|
|
PCSIP = ConfigHelper.GetValue("PCSIP");
|
|
IsDebug = ConfigHelper.GetValue("IsDebug") == "True" ? true : false;
|
|
IsDemo = ConfigHelper.GetValue("IsDemo") == "True" ? true : false;
|
|
|
|
EMSActionLimitValue.TargetValue = double.Parse(ConfigHelper.GetValue("ControlTargetValue"));
|
|
PcsChangeValue = double.Parse(ConfigHelper.GetValue("PcsChangeValue"));
|
|
|
|
MqttServerUrl = ConfigHelper.GetValue("MqttServerUrl");
|
|
MqttTopic = ConfigHelper.GetValue("MqttTopic");//v1/devices/me/telemetry
|
|
MqttServerPort = int.Parse(ConfigHelper.GetValue("MqttServerPort"));
|
|
MqttClientId = ConfigHelper.GetValue("MqttClientId");
|
|
MqttUser = ConfigHelper.GetValue("MqttUser");
|
|
MqttPwd = ConfigHelper.GetValue("MqttPwd");
|
|
|
|
//数据保存的配置信息
|
|
DataLogFile = ConfigHelper.GetValue("DataLogFile");
|
|
|
|
YuPuSpecialPeakValley = new SpecialPeakValley();
|
|
|
|
//获取配置信息
|
|
ListEnergyStoragePeakValleyTimeConfig = FreeSql.Select<PeakValleyConfig>().ToList();
|
|
//削峰填谷模式的时间监视线程
|
|
var ListenPeakValleyTimeTaskInfo = Task.Run(() => ListenPeakValleyTimeCycle());
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 储能运行配置值
|
|
/// </summary>
|
|
public EnergyStorageRunConfig energyStorageRunConfig { get; set; }
|
|
|
|
/// <summary>
|
|
/// FreeSQL实例
|
|
/// </summary>
|
|
public IFreeSql FreeSql { get; }
|
|
public ILogService LogService { get; }
|
|
|
|
/// <summary>
|
|
/// 事件聚合器
|
|
/// </summary>
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
#region 系统参数配置
|
|
|
|
/// <summary>
|
|
/// 是否保存数据信息
|
|
/// </summary>
|
|
public bool IsSaveDataLog { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// BMS IP
|
|
/// </summary>
|
|
public string BMSIP { get; set; }
|
|
|
|
/// <summary>
|
|
/// BMS IP
|
|
/// </summary>
|
|
public string PCSIP { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否调试
|
|
/// 默认False
|
|
/// </summary>
|
|
public bool IsDebug { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是不是Demo
|
|
/// 默认False
|
|
/// </summary>
|
|
public bool IsDemo { get; set; }
|
|
|
|
private bool _IsStartAuto = true;
|
|
/// <summary>
|
|
/// 在程序运行的初始状态时是否进行开始模式
|
|
/// 默认值为True
|
|
/// </summary>
|
|
public bool IsStartAuto
|
|
{
|
|
get { return _IsStartAuto; }
|
|
set { _IsStartAuto = value; RaisePropertyChanged(); }
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Mqtt Server配置参数
|
|
|
|
/// <summary>
|
|
/// MqttServerUrl
|
|
/// </summary>
|
|
public string MqttServerUrl { get; set; }
|
|
|
|
/// <summary>
|
|
/// MqttUser
|
|
/// </summary>
|
|
public string MqttUser { get; set; }
|
|
|
|
/// <summary>
|
|
/// MqttPwd
|
|
/// </summary>
|
|
public string MqttPwd { get; set; }
|
|
|
|
/// <summary>
|
|
/// MqttTopic
|
|
/// </summary>
|
|
public string MqttTopic { get; set; }
|
|
|
|
/// <summary>
|
|
/// MqttServerPort
|
|
/// </summary>
|
|
public int MqttServerPort { get; set; }
|
|
|
|
/// <summary>
|
|
/// MqttClientId
|
|
/// </summary>
|
|
public string MqttClientId { get; set; }
|
|
|
|
// MqttServerPort MqttClientId
|
|
#endregion
|
|
|
|
#region PCS配置参数
|
|
|
|
private double _PcsChangeValue;
|
|
/// <summary>
|
|
/// PCS的变化时的阈值设置
|
|
/// </summary>
|
|
public double PcsChangeValue
|
|
{
|
|
get { return _PcsChangeValue; }
|
|
set { _PcsChangeValue = value; }
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
private double _TransformerCapacity;
|
|
/// <summary>
|
|
/// 变压器容量设置
|
|
/// </summary>
|
|
public double TransformerCapacity
|
|
{
|
|
get { return _TransformerCapacity; }
|
|
set { _TransformerCapacity = value; }
|
|
}
|
|
|
|
|
|
#region 削峰填谷配置
|
|
|
|
|
|
/// <summary>
|
|
/// 月浦特殊的削峰填谷的模型
|
|
/// </summary>
|
|
public SpecialPeakValley YuPuSpecialPeakValley { get; set; }
|
|
|
|
/// <summary>
|
|
/// 线程使能
|
|
/// </summary>
|
|
public bool ThreadEnable { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// 当前的削峰填谷的配置
|
|
/// 在配置服务中,供统计服务使用
|
|
/// </summary>
|
|
public PeakValleyConfig CurPeakValleyConfig { get; set; } = new PeakValleyConfig();
|
|
|
|
/// <summary>
|
|
/// 监听削峰填谷时间信息
|
|
/// 这个不管是否处于削峰填谷的时期都可以实时轮训获取
|
|
/// 那么当软件处于启动时就可以实时轮训
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task ListenPeakValleyTimeCycle()
|
|
{
|
|
while (ThreadEnable)
|
|
{
|
|
//退出 由Master发送充放电的数据
|
|
if (!IsMaster) break;
|
|
try
|
|
{
|
|
|
|
//CurPeakValleyConfig = YuPuSpecialPeakValley.GetSpecialPeakValley();
|
|
_eventAggregator.GetEvent<PeakValleyTimeEvent>().Publish(YuPuSpecialPeakValley.GetSpecialPeakValley());
|
|
|
|
var TimeInfo = DateTime.Now.ToString("HH:mm");
|
|
foreach (var item in ListEnergyStoragePeakValleyTimeConfig)
|
|
{
|
|
if (item.Enable)
|
|
{
|
|
if (GetIsTimeSpan(TimeInfo, item.StartTime, item.EndTime))
|
|
{
|
|
CurPeakValleyConfig = item;
|
|
//_eventAggregator.GetEvent<PeakValleyTimeEvent>().Publish(item.ElePV);
|
|
|
|
//PeakValleySglModel = item.ElePV;
|
|
//switch (item.ElePV)
|
|
//{
|
|
// case ElePVEnum.Peak:
|
|
// EsSysPeakVellayStateMsg = "峰价";
|
|
// break;
|
|
// case ElePVEnum.Valley:
|
|
// EsSysPeakVellayStateMsg = "谷价";
|
|
// break;
|
|
// case ElePVEnum.Flat:
|
|
// EsSysPeakVellayStateMsg = "平价";
|
|
// break;
|
|
// default:
|
|
// break;
|
|
//}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await Task.Delay(10000);
|
|
|
|
//使用这个线程
|
|
|
|
//mqttClientDrive.mqttEntity.PcsPower = InPowerPCSDataService.Power;
|
|
//mqttClientDrive.mqttEntity.PcsTotalReactivePw = InPowerPCSDataService.TotalReactivePw;
|
|
//mqttClientDrive.mqttEntity.PcsTotalApparentPw = InPowerPCSDataService.TotalApparentPw;
|
|
//mqttClientDrive.mqttEntity.PcsInputVol = InPowerPCSDataService.InputVol;
|
|
//mqttClientDrive.mqttEntity.PcsInputCur = InPowerPCSDataService.InputCur;
|
|
//mqttClientDrive.mqttEntity.PcsInputPw = InPowerPCSDataService.InputPw;
|
|
//mqttClientDrive.mqttEntity.PcsCurAlarmStateStr = InPowerPCSDataService.CurPCSAlarmStateStr;
|
|
//mqttClientDrive.mqttEntity.PcsAVol = InPowerPCSDataService.AVol;
|
|
//mqttClientDrive.mqttEntity.PcsBVol = InPowerPCSDataService.BVol;
|
|
//mqttClientDrive.mqttEntity.PcsCVol = InPowerPCSDataService.CVol;
|
|
//mqttClientDrive.mqttEntity.PcsACur = InPowerPCSDataService.ACur;
|
|
//mqttClientDrive.mqttEntity.PcsBCur = InPowerPCSDataService.BCur;
|
|
//mqttClientDrive.mqttEntity.PcsCCur = InPowerPCSDataService.CCur;
|
|
//mqttClientDrive.mqttEntity.PCSFaultStateStr = InPowerPCSDataService.CurPCSFaultStateStr;
|
|
|
|
|
|
//mqttClientDrive.mqttEntity.BmsCur = BmsDataService.BmsCur.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsVol = BmsDataService.BmsVol.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsSOC = BmsDataService.BmsSOC.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsSOH = BmsDataService.BmsSOH.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsSOE = BmsDataService.BmsSOE.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsResP = BmsDataService.BmsResP.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsResN = BmsDataService.BmsResN.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsAccCharg = BmsDataService.BmsAccCharg.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsAccDisCharg = BmsDataService.BmsAccDisCharg.RtValue;
|
|
//mqttClientDrive.mqttEntity.BmsPw = 0;
|
|
//mqttClientDrive.mqttEntity.BmsBatState = BmsDataService.BmsBatState;
|
|
//mqttClientDrive.mqttEntity.MaxChargePowerCell = BmsDataService.MaxChargePowerCell.RtValue;
|
|
//mqttClientDrive.mqttEntity.MaxDisChargePowerCell = BmsDataService.MaxDisChargePowerCell.RtValue;
|
|
|
|
|
|
|
|
//mqttClientDrive.mqttEntity.InPress = BmsDataService.InPress.RtValue;
|
|
//mqttClientDrive.mqttEntity.OutPress = BmsDataService.OutPress.RtValue;
|
|
//mqttClientDrive.mqttEntity.OutTemp = BmsDataService.OutTemp.RtValue;
|
|
//mqttClientDrive.mqttEntity.InTemp = BmsDataService.InTemp.RtValue;
|
|
//mqttClientDrive.mqttEntity.CoolFaultCode = BmsDataService.CoolFaultCode;
|
|
//mqttClientDrive.mqttEntity.CoolStates = BmsDataService.CoolStates;
|
|
//mqttClientDrive.mqttEntity.FireSmokeTrig = BmsDataService.FireSmokeTrig;
|
|
//mqttClientDrive.mqttEntity.FireTempTrig = BmsDataService.FireTempTrig;
|
|
//mqttClientDrive.mqttEntity.FireMainPowerState = BmsDataService.FireMainPowerState;
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogService.Info($"时间:{DateTime.Now.ToString()}-【ListenPeakValleyTimeCycle】-{ex.Message}");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断时间是否在 某一时间段内
|
|
/// </summary>
|
|
/// <param name="timeStr"></param>
|
|
/// <returns></returns>
|
|
public bool GetIsTimeSpan(string timeStr, string startTime, string endTime)
|
|
{
|
|
//判断当前时间是否在工作时间段内
|
|
//string _strWorkingDayAM = "08:30";//工作时间上午08:30
|
|
//string _strWorkingDayPM = "17:30";
|
|
TimeSpan dspStart = DateTime.Parse(startTime).TimeOfDay;
|
|
TimeSpan dspEnd = DateTime.Parse(endTime).TimeOfDay;
|
|
|
|
//string time1 = "2017-2-17 8:10:00";
|
|
DateTime t1 = Convert.ToDateTime(timeStr);
|
|
|
|
TimeSpan dspNow = t1.TimeOfDay;
|
|
if (dspNow > dspStart && dspNow < dspEnd)
|
|
{
|
|
return true;
|
|
}
|
|
else if (dspStart > dspEnd)//时间区间处于跨天的状态
|
|
{
|
|
if (dspNow >= dspStart || dspNow <= dspEnd)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 储能柜的削峰填谷的配置数据集
|
|
/// </summary>
|
|
public List<PeakValleyConfig> ListEnergyStoragePeakValleyTimeConfig { get; set; }
|
|
|
|
/// <summary>
|
|
/// 电表动作的上限和下限值
|
|
///维持电表在一个区间而不是一个具体的值
|
|
///相当于回差值的意思,防止维持在一个点反复的波动导致问题
|
|
/// </summary>
|
|
public EleMeterActionValue EMSActionLimitValue { get; set; } = new EleMeterActionValue()
|
|
{
|
|
UpValue = 15,
|
|
//MidValue = 7,
|
|
DownValue = 8,
|
|
TargetValue = 12
|
|
};
|
|
|
|
#endregion
|
|
|
|
|
|
#region MasterSlave分布通信参数
|
|
|
|
/// <summary>
|
|
/// 是否是主站
|
|
/// </summary>
|
|
public bool IsMaster { get; set; }
|
|
|
|
/// <summary>
|
|
/// Client连接Server的Url
|
|
/// </summary>
|
|
public string ServerUrl { get; set; }
|
|
|
|
/// <summary>
|
|
/// 站信息数据
|
|
/// </summary>
|
|
public ushort Station { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region 液冷设置参数
|
|
|
|
/// <summary>
|
|
/// 制热设定温度
|
|
/// </summary>
|
|
public int SetHeadTargetTemp { get; set; } = 25;
|
|
|
|
/// <summary>
|
|
/// 制冷设定温度
|
|
/// </summary>
|
|
public int SetCoolTargetTemp { get; set; } = 25;
|
|
|
|
/// <summary>
|
|
/// 控制模式
|
|
/// 0 停止
|
|
/// 1 制冷
|
|
/// 2 制热
|
|
/// 3 自循环
|
|
/// 4 自动
|
|
/// </summary>
|
|
public int SetCtrModel { get; set; } = 4;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 数据保存的配置
|
|
|
|
/// <summary>
|
|
/// 数据保存的地址信息
|
|
/// </summary>
|
|
public string DataLogFile { get; set; } = string.Empty;
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|