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.

80 lines
2.1 KiB

using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using HybirdFrameworkDriver.TcpClient;
using log4net;
using Service.Charger.Common;
using Service.Charger.Handler;
using Service.WaterCool.Msg.Host;
using Service.WaterCool.Msg.WaterCool;
using Decoder = Service.Charger.Codec.Decoder;
using Encoder = Service.Charger.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 ModeMsg msg{ get; set; }= new ModeMsg();
private ILog Log()
{
var name = "WaterCool" + this.Sn;
ILog logger = LogManager.GetLogger(name);
Console.WriteLine(name + "-" + logger.GetHashCode());
return logger;
}
/// <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);
}
public bool Connect()
{
base.BaseConnect();
Log().Info($"charger {Sn} connect succeed");
return Connected;
}
}