水冷发送

master
tq 3 months ago
parent c6ff3cf2c4
commit 63daffb1b4

@ -0,0 +1,49 @@
using System.Collections.Concurrent;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Job;
using log4net;
using Service.WaterCool.Client;
namespace Service.Job;
/// <summary>
/// 每秒发送水冷固定帧
/// </summary>
[Scope]
public class SendWaterCoolJob : AbstractCronJob
{
private static readonly ILog Log = LogManager.GetLogger(typeof(SendWaterCoolJob));
protected override Task Handle()
{
ConcurrentDictionary<string, WaterCoolClient> waterCool = WaterCoolClientMgr.Dictionary;
if (waterCool.Values.Count <= 0)
{
return Task.CompletedTask;
}
foreach (var waterCoolClient in waterCool)
{
WaterCoolClient client = waterCoolClient.Value;
if (client.IsConnect && client.IsWaterCoolSend)
{
client.Send();
Log.Info($"水冷固定帧发送成功");
}
}
return Task.CompletedTask;
}
protected override string Key()
{
return "SendWaterCoolJob";
}
protected override string Cron()
{
return "* * * * * ? *";
}
}

@ -4,6 +4,7 @@ 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;
@ -25,6 +26,11 @@ public class WaterCoolClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// </summary>
public bool IsConnect { get; set; } = false;
/// <summary>
/// 是否发送水冷固定帧
/// </summary>
public bool IsWaterCoolSend { get; set; } = true;
private ILog Log()
{
var name = "WaterCool" + this.Sn;
@ -38,6 +44,30 @@ public class WaterCoolClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// 水冷机编号
/// </summary>
public string Sn { get; set; }
/// <summary>
/// 无参固定发送
/// </summary>
public void Send()
{
ModeMsg modeMsg=new ModeMsg();
Channel.WriteAndFlushAsync(modeMsg);
}
/// <summary>
/// 发送
/// </summary>
/// <param name="mode">BMS 请求设定模式</param>
/// <param name="highTension">高压请求</param>
/// <param name="chargState">充电状态</param>
/// <param name="bmsState">BMS 高压继电器状态</param>
/// <param name="setTemperature">设定温度</param>
/// <param name="hp">生命帧</param>
/// <param name="crcCheckValue">CRC 效验值</param>
public void Send(byte mode,byte highTension,byte chargState,byte bmsState,sbyte setTemperature,byte hp,byte crcCheckValue)
{
ModeMsg modeMsg=new ModeMsg(mode,highTension,chargState,bmsState,setTemperature,hp,crcCheckValue);
Channel.WriteAndFlushAsync(modeMsg);
}
/// <summary>
///

@ -93,5 +93,18 @@ public class ModeMsg : BaseMsg
HP = hp;
CrcCheckValue = crcCheckValue;
}
public ModeMsg()
{
Id = 0x18FF45A7;
Mode = 0;
HighTension = 3;
ChargState= 0;
BMSState= 3;
SetTemperature = 0;
BMSHighByte = 0;
BMSLowByte = 0;
HP = 0;
CrcCheckValue = 0;
}
}

@ -33,7 +33,7 @@
"Days": 7
},
"Job": {
"Enabled": false
"Enabled": true
},
"AllowedHosts": "*"
}

Loading…
Cancel
Save