diff --git a/Service/Job/SendWaterCoolJob.cs b/Service/Job/SendWaterCoolJob.cs new file mode 100644 index 0000000..875c39d --- /dev/null +++ b/Service/Job/SendWaterCoolJob.cs @@ -0,0 +1,49 @@ +using System.Collections.Concurrent; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.Job; +using log4net; +using Service.WaterCool.Client; + +namespace Service.Job; + +/// +/// 每秒发送水冷固定帧 +/// +[Scope] +public class SendWaterCoolJob : AbstractCronJob +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(SendWaterCoolJob)); + + + protected override Task Handle() + { + ConcurrentDictionary 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 "* * * * * ? *"; + } +} \ No newline at end of file diff --git a/Service/WaterCool/Client/WaterCoolClient.cs b/Service/WaterCool/Client/WaterCoolClient.cs index 6fb6347..b992312 100644 --- a/Service/WaterCool/Client/WaterCoolClient.cs +++ b/Service/WaterCool/Client/WaterCoolClient.cs @@ -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 /// public bool IsConnect { get; set; } = false; + /// + /// 是否发送水冷固定帧 + /// + public bool IsWaterCoolSend { get; set; } = true; + private ILog Log() { var name = "WaterCool" + this.Sn; @@ -38,6 +44,30 @@ public class WaterCoolClient : TcpClient /// 水冷机编号 /// public string Sn { get; set; } + + /// + /// 无参固定发送 + /// + public void Send() + { + ModeMsg modeMsg=new ModeMsg(); + Channel.WriteAndFlushAsync(modeMsg); + } + /// + /// 发送 + /// + /// BMS 请求设定模式 + /// 高压请求 + /// 充电状态 + /// BMS 高压继电器状态 + /// 设定温度 + /// 生命帧 + /// CRC 效验值 + 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); + } /// /// diff --git a/Service/WaterCool/Msg/Host/ModeMsg.cs b/Service/WaterCool/Msg/Host/ModeMsg.cs index 3cfb1ff..2927b0f 100644 --- a/Service/WaterCool/Msg/Host/ModeMsg.cs +++ b/Service/WaterCool/Msg/Host/ModeMsg.cs @@ -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; + } } \ No newline at end of file diff --git a/WebStarter/appsettings.dev.json b/WebStarter/appsettings.dev.json index 5bcf292..a6fd422 100644 --- a/WebStarter/appsettings.dev.json +++ b/WebStarter/appsettings.dev.json @@ -33,7 +33,7 @@ "Days": 7 }, "Job": { - "Enabled": false + "Enabled": true }, "AllowedHosts": "*" }