You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
237 lines
5.4 KiB
237 lines
5.4 KiB
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using HybirdFrameworkDriver.Session;
|
|
using HybirdFrameworkDriver.TcpClient;
|
|
using log4net;
|
|
using Service.Charger.Client;
|
|
using Service.Charger.Common;
|
|
using Service.Charger.Handler;
|
|
using Service.Init;
|
|
using Service.MyTask;
|
|
using Service.WaterCool.Msg.Host;
|
|
using Service.WaterCool.Msg.WaterCool;
|
|
using Decoder = Service.WaterCool.Codec.Decoder;
|
|
using Encoder = Service.WaterCool.Codec.Encoder;
|
|
|
|
namespace Service.WaterCool.Client;
|
|
|
|
/// <summary>
|
|
/// 水冷客户端
|
|
/// </summary>
|
|
[Scope("InstancePerDependency")]
|
|
public class WaterCoolClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
{
|
|
/// <summary>
|
|
/// 水冷数据主动上报
|
|
/// </summary>
|
|
public WaterCoolStatus? WaterCoolStatus { get; set; }
|
|
|
|
/// <summary>
|
|
/// 水冷是否连接成功
|
|
/// </summary>
|
|
public bool IsConnect { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 是否发送水冷固定帧
|
|
/// </summary>
|
|
public bool IsWaterCoolSend { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// 上下电的时间
|
|
/// </summary>
|
|
public DateTime? PowerChangeTime { get; set; }
|
|
|
|
//上下电的时间间隔(单位/s)
|
|
public int Interval = 15;
|
|
|
|
/// <summary>
|
|
/// 停止标识
|
|
/// </summary>
|
|
public bool StopFlag = true;
|
|
|
|
/// <summary>
|
|
///制冷策略
|
|
/// </summary>
|
|
public bool ColdStrategyFlag = false;
|
|
|
|
/// <summary>
|
|
/// 制热策略
|
|
/// </summary>
|
|
public bool HortStrategyFlag = false;
|
|
|
|
/// <summary>
|
|
/// 自循环
|
|
/// </summary>
|
|
public bool LoopStrategyFlag = false;
|
|
|
|
/// <summary>
|
|
/// 消息
|
|
/// </summary>
|
|
public ModeMsg msg { get; set; } = new ModeMsg();
|
|
|
|
/// <summary>
|
|
/// 水冷机sn
|
|
/// </summary>
|
|
public string ChargeSn { get; set; }
|
|
|
|
private ILog Log()
|
|
{
|
|
var name = "WaterCool" + this.Sn;
|
|
ILog logger = LogManager.GetLogger(name);
|
|
|
|
Console.WriteLine(name + "-" + logger.GetHashCode());
|
|
return logger;
|
|
}
|
|
|
|
//闭合
|
|
public bool IsOpen()
|
|
{
|
|
return WaterCoolStatus?.TmsHighStatus == 1;
|
|
}
|
|
|
|
public bool WaitIsClose()
|
|
{
|
|
int count = 0;
|
|
bool IsClose = this.IsClose();
|
|
while (!IsClose)
|
|
{
|
|
if (count > 5)
|
|
{
|
|
break;
|
|
}
|
|
|
|
IsClose = this.IsClose();
|
|
Thread.Sleep(1000);
|
|
count++;
|
|
}
|
|
|
|
return IsClose;
|
|
}
|
|
|
|
public bool IsClose()
|
|
{
|
|
return WaterCoolStatus?.TmsHighStatus == 0;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 水冷机编号
|
|
/// </summary>
|
|
public string Sn { get; set; }
|
|
|
|
/// <summary>
|
|
/// 水冷发送
|
|
/// </summary>
|
|
public void Send()
|
|
{
|
|
Channel.WriteAndFlushAsync(msg);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sn"></param>
|
|
/// <param name="destAddr"></param>
|
|
public void SessionAttr(string sn, string destAddr)
|
|
{
|
|
ChannelUtils.AddAttr(Channel, WaterCoolerConst.WaterCoolSn, sn);
|
|
ChannelUtils.AddAttr(Channel, ChargerConst.EqmTypeNo, sn);
|
|
ChannelUtils.AddAttr(Channel, ChargerConst.EqmCode, sn);
|
|
ChannelUtils.AddAttr(Channel, ChargerConst.DestAddr, destAddr);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 热管理策略(开始充电调用)
|
|
/// 闭合继电器状态-延时300->上高压->按照策略开始液冷模式
|
|
/// </summary>
|
|
public void HeartManageStart()
|
|
{
|
|
Thread.Sleep(100);
|
|
int count = 0;
|
|
while (!IsOpen())
|
|
{
|
|
if (count > 5)
|
|
{
|
|
Log().Info("water Client Open err");
|
|
return;
|
|
}
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
Log().Info("wait waterClient Open");
|
|
msg.BMSState = 1;
|
|
msg.ChargState = 1;
|
|
count++;
|
|
}
|
|
|
|
Thread.Sleep(300);
|
|
//上高压
|
|
PowerOperate(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 热管理策略(停止充电调用)
|
|
/// 下高压->监测继电器状态(5s)->断开继电器 (停止失败做报警,手动处理报警)
|
|
/// </summary>
|
|
public bool HeartManageStop()
|
|
{
|
|
Thread.Sleep(100);
|
|
//下高压
|
|
PowerOperate(1);
|
|
|
|
int count = 0;
|
|
bool IsClose = this.IsClose();
|
|
while (!IsClose)
|
|
{
|
|
if (count > 5)
|
|
{
|
|
Log().Info("water Client Open err");
|
|
return IsClose;
|
|
}
|
|
|
|
IsClose = this.IsClose();
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
Log().Info("wait waterClient Open");
|
|
msg.BMSState = 0;
|
|
msg.ChargState = 0;
|
|
count++;
|
|
}
|
|
|
|
Thread.Sleep(300);
|
|
return IsClose;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 高压请求
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
public void PowerOperate(byte value)
|
|
{
|
|
if (msg.HighTension == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var dateTime = DateTime.Now;
|
|
if (PowerChangeTime != null)
|
|
{
|
|
while ((dateTime - PowerChangeTime).Value.Seconds < Interval)
|
|
{
|
|
Thread.Sleep(1000);
|
|
dateTime = DateTime.Now;
|
|
}
|
|
}
|
|
|
|
PowerChangeTime = dateTime;
|
|
msg.HighTension = value;
|
|
}
|
|
|
|
public bool Connect()
|
|
{
|
|
base.BaseConnect();
|
|
Log().Info($"WaterCool {Sn} connect succeed");
|
|
return Connected;
|
|
}
|
|
} |