From d91f797991d7bb4e5788a2269710cf2d7d874a59 Mon Sep 17 00:00:00 2001 From: lxw Date: Wed, 17 Jul 2024 10:24:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=83=AD=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Station/ChargeWaterCoolerRelation.cs | 27 +++ Repository/BaseRepository.cs | 2 + .../ChargeWaterCoolerRelationRepository.cs | 14 ++ Service/Charger/ChargerService.cs | 119 ++++++++++--- Service/Charger/Client/ChargerClient.cs | 42 +++-- .../Handler/FinishStartChargingHandler.cs | 25 ++- Service/Charger/MyTask/AutoChargeTask.cs | 24 ++- Service/Init/StaticStationInfo.cs | 37 ++-- Service/MyTask/HeartManagementTask.cs | 163 ++++++++++++++++++ Service/WaterCool/Client/WaterCoolClient.cs | 162 ++++++++++++++++- WebStarter/Program.cs | 3 + 11 files changed, 555 insertions(+), 63 deletions(-) create mode 100644 Entity/DbModel/Station/ChargeWaterCoolerRelation.cs create mode 100644 Repository/Station/ChargeWaterCoolerRelationRepository.cs create mode 100644 Service/MyTask/HeartManagementTask.cs diff --git a/Entity/DbModel/Station/ChargeWaterCoolerRelation.cs b/Entity/DbModel/Station/ChargeWaterCoolerRelation.cs new file mode 100644 index 0000000..9f1de27 --- /dev/null +++ b/Entity/DbModel/Station/ChargeWaterCoolerRelation.cs @@ -0,0 +1,27 @@ +using SqlSugar; + +namespace Entity.DbModel.Station; + +[SugarTable("charge_water_cooler_relation")] +public class ChargeWaterCoolerRelation +{ + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// 充电机编码 + /// + [SugarColumn(ColumnName = "charge_code")] + public string ChargeCode { get; set; } + + /// + /// 水冷机编码 + /// + [SugarColumn(ColumnName = "water_cooler_code")] + public string WaterCoolerCode { get; set; } +} \ No newline at end of file diff --git a/Repository/BaseRepository.cs b/Repository/BaseRepository.cs index 97f2c93..7aba34a 100644 --- a/Repository/BaseRepository.cs +++ b/Repository/BaseRepository.cs @@ -295,6 +295,7 @@ public abstract class BaseRepository where T : class, new() .ToListAsync(); } + public async Task> QueryListByOrderClauseAsync(Expression> expression) { return await DbBaseClient @@ -614,6 +615,7 @@ public abstract class BaseRepository where T : class, new() .Select(expression2) .ToListAsync(); } + public async Task> QueryByClauseAsync(Expression> predicate, Expression> selectExpression, bool blUseNoLock = false) { return await DbBaseClient diff --git a/Repository/Station/ChargeWaterCoolerRelationRepository.cs b/Repository/Station/ChargeWaterCoolerRelationRepository.cs new file mode 100644 index 0000000..b90525c --- /dev/null +++ b/Repository/Station/ChargeWaterCoolerRelationRepository.cs @@ -0,0 +1,14 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar; + +namespace Repository.Station; + + +[Scope("SingleInstance")] +public class ChargeWaterCoolerRelationRepository: BaseRepository +{ + public ChargeWaterCoolerRelationRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) + { + } +} \ No newline at end of file diff --git a/Service/Charger/ChargerService.cs b/Service/Charger/ChargerService.cs index 256f4f6..364b50f 100644 --- a/Service/Charger/ChargerService.cs +++ b/Service/Charger/ChargerService.cs @@ -7,6 +7,7 @@ using Repository.Station; using Service.Charger.Client; using Service.Charger.Msg.Host.Req; using Service.Init; +using Service.WaterCool.Client; using SqlSugar; namespace Service.Charger; @@ -50,7 +51,7 @@ public class ChargerService float? chargePower = EquipInfoRepository.QueryPowerByCode(binInfo.ChargerNo); float? power = chargePower == null ? StaticStationInfo.ChargePower : chargePower; - return chargerClient.StartCharge(chargeSoc,(float)power, 1); + return chargerClient.StartCharge(chargeSoc, (float)power, 1); } /// @@ -77,6 +78,21 @@ public class ChargerService return Result.Fail(@"充电机未连接"); } + // + WaterCoolClientMgr.Dictionary.TryGetValue(StaticStationInfo.RelationMap[chargerClient.Sn].WaterCoolerCode, + out WaterCoolClient client); + if (client == null) + { + return Result.Fail("未初始化液冷"); + } + + if (!client.HeartManageStop()) + { + return Result.Fail("液冷系统断开失败"); + } + + client.StopFlag = true; + chargerClient.SendRemoteStopCharging(); return Result.Success(true, "发送停止命令成功"); @@ -114,30 +130,78 @@ public class ChargerService SetPeakValleyTime setPeakValleyTime = new SetPeakValleyTime() { NumberTime = Convert.ToByte(elecPriceModelVersionDetails.Count), - StartHH1 = (byte)(elecPriceModelVersionDetails.Count > 0?Convert.ToByte(elecPriceModelVersionDetails[0].StartHour) :0), - StartHH2 = (byte)(elecPriceModelVersionDetails.Count > 1?Convert.ToByte(elecPriceModelVersionDetails[1].StartHour) : 0), - StartHH3 = (byte)(elecPriceModelVersionDetails.Count > 2?Convert.ToByte(elecPriceModelVersionDetails[2].StartHour):0), - StartHH4 = (byte)(elecPriceModelVersionDetails.Count > 3?Convert.ToByte(elecPriceModelVersionDetails[3].StartHour):0), - StartHH5 = (byte)(elecPriceModelVersionDetails.Count > 4?Convert.ToByte(elecPriceModelVersionDetails[4].StartHour):0), - StartHH6 = (byte)(elecPriceModelVersionDetails.Count > 5?Convert.ToByte(elecPriceModelVersionDetails[5].StartHour):0), - StartHH7 = (byte)(elecPriceModelVersionDetails.Count > 6?Convert.ToByte(elecPriceModelVersionDetails[6].StartHour):0), - StartHH8 = (byte)(elecPriceModelVersionDetails.Count > 7?Convert.ToByte(elecPriceModelVersionDetails[7].StartHour) : 0), - StartMM1 = (byte)(elecPriceModelVersionDetails.Count > 0?Convert.ToByte(elecPriceModelVersionDetails[0].StartMinute):0), - StartMM2 = (byte)(elecPriceModelVersionDetails.Count > 1?Convert.ToByte(elecPriceModelVersionDetails[1].StartMinute):0), - StartMM3 = (byte)(elecPriceModelVersionDetails.Count > 2?Convert.ToByte(elecPriceModelVersionDetails[2].StartMinute):0), - StartMM4 = (byte)(elecPriceModelVersionDetails.Count > 3?Convert.ToByte(elecPriceModelVersionDetails[3].StartMinute):0), - StartMM5 = (byte)(elecPriceModelVersionDetails.Count > 4?Convert.ToByte(elecPriceModelVersionDetails[4].StartMinute):0), - StartMM6 = (byte)(elecPriceModelVersionDetails.Count > 5?Convert.ToByte(elecPriceModelVersionDetails[5].StartMinute):0), - StartMM7 = (byte)(elecPriceModelVersionDetails.Count > 6?Convert.ToByte(elecPriceModelVersionDetails[6].StartMinute) : 0), - StartMM8 = (byte)(elecPriceModelVersionDetails.Count > 7 ? Convert.ToByte(elecPriceModelVersionDetails[7].StartMinute) : 0), - TimePeak1 = (byte)(elecPriceModelVersionDetails.Count > 0 ? Convert.ToByte(elecPriceModelVersionDetails[0].Type):0), - TimePeak2 = (byte)(elecPriceModelVersionDetails.Count > 1?Convert.ToByte(elecPriceModelVersionDetails[1].Type):0), - TimePeak3 = (byte)(elecPriceModelVersionDetails.Count > 2?Convert.ToByte(elecPriceModelVersionDetails[2].Type):0), - TimePeak4 = (byte)(elecPriceModelVersionDetails.Count > 3?Convert.ToByte(elecPriceModelVersionDetails[3].Type):0), - TimePeak5 = (byte)(elecPriceModelVersionDetails.Count > 4?Convert.ToByte(elecPriceModelVersionDetails[4].Type):0), - TimePeak6 = (byte)(elecPriceModelVersionDetails.Count > 5?Convert.ToByte(elecPriceModelVersionDetails[5].Type):0), - TimePeak7 = (byte)(elecPriceModelVersionDetails.Count > 6?Convert.ToByte(elecPriceModelVersionDetails[6].Type):0), - TimePeak8 = (byte)(elecPriceModelVersionDetails.Count > 7?Convert.ToByte(elecPriceModelVersionDetails[7].Type):0) + StartHH1 = (byte)(elecPriceModelVersionDetails.Count > 0 + ? Convert.ToByte(elecPriceModelVersionDetails[0].StartHour) + : 0), + StartHH2 = (byte)(elecPriceModelVersionDetails.Count > 1 + ? Convert.ToByte(elecPriceModelVersionDetails[1].StartHour) + : 0), + StartHH3 = (byte)(elecPriceModelVersionDetails.Count > 2 + ? Convert.ToByte(elecPriceModelVersionDetails[2].StartHour) + : 0), + StartHH4 = (byte)(elecPriceModelVersionDetails.Count > 3 + ? Convert.ToByte(elecPriceModelVersionDetails[3].StartHour) + : 0), + StartHH5 = (byte)(elecPriceModelVersionDetails.Count > 4 + ? Convert.ToByte(elecPriceModelVersionDetails[4].StartHour) + : 0), + StartHH6 = (byte)(elecPriceModelVersionDetails.Count > 5 + ? Convert.ToByte(elecPriceModelVersionDetails[5].StartHour) + : 0), + StartHH7 = (byte)(elecPriceModelVersionDetails.Count > 6 + ? Convert.ToByte(elecPriceModelVersionDetails[6].StartHour) + : 0), + StartHH8 = (byte)(elecPriceModelVersionDetails.Count > 7 + ? Convert.ToByte(elecPriceModelVersionDetails[7].StartHour) + : 0), + StartMM1 = (byte)(elecPriceModelVersionDetails.Count > 0 + ? Convert.ToByte(elecPriceModelVersionDetails[0].StartMinute) + : 0), + StartMM2 = (byte)(elecPriceModelVersionDetails.Count > 1 + ? Convert.ToByte(elecPriceModelVersionDetails[1].StartMinute) + : 0), + StartMM3 = (byte)(elecPriceModelVersionDetails.Count > 2 + ? Convert.ToByte(elecPriceModelVersionDetails[2].StartMinute) + : 0), + StartMM4 = (byte)(elecPriceModelVersionDetails.Count > 3 + ? Convert.ToByte(elecPriceModelVersionDetails[3].StartMinute) + : 0), + StartMM5 = (byte)(elecPriceModelVersionDetails.Count > 4 + ? Convert.ToByte(elecPriceModelVersionDetails[4].StartMinute) + : 0), + StartMM6 = (byte)(elecPriceModelVersionDetails.Count > 5 + ? Convert.ToByte(elecPriceModelVersionDetails[5].StartMinute) + : 0), + StartMM7 = (byte)(elecPriceModelVersionDetails.Count > 6 + ? Convert.ToByte(elecPriceModelVersionDetails[6].StartMinute) + : 0), + StartMM8 = (byte)(elecPriceModelVersionDetails.Count > 7 + ? Convert.ToByte(elecPriceModelVersionDetails[7].StartMinute) + : 0), + TimePeak1 = (byte)(elecPriceModelVersionDetails.Count > 0 + ? Convert.ToByte(elecPriceModelVersionDetails[0].Type) + : 0), + TimePeak2 = (byte)(elecPriceModelVersionDetails.Count > 1 + ? Convert.ToByte(elecPriceModelVersionDetails[1].Type) + : 0), + TimePeak3 = (byte)(elecPriceModelVersionDetails.Count > 2 + ? Convert.ToByte(elecPriceModelVersionDetails[2].Type) + : 0), + TimePeak4 = (byte)(elecPriceModelVersionDetails.Count > 3 + ? Convert.ToByte(elecPriceModelVersionDetails[3].Type) + : 0), + TimePeak5 = (byte)(elecPriceModelVersionDetails.Count > 4 + ? Convert.ToByte(elecPriceModelVersionDetails[4].Type) + : 0), + TimePeak6 = (byte)(elecPriceModelVersionDetails.Count > 5 + ? Convert.ToByte(elecPriceModelVersionDetails[5].Type) + : 0), + TimePeak7 = (byte)(elecPriceModelVersionDetails.Count > 6 + ? Convert.ToByte(elecPriceModelVersionDetails[6].Type) + : 0), + TimePeak8 = (byte)(elecPriceModelVersionDetails.Count > 7 + ? Convert.ToByte(elecPriceModelVersionDetails[7].Type) + : 0) }; return setPeakValleyTime; } @@ -153,7 +217,8 @@ public class ChargerService if (binInfos.Count > 0) batteryStatusInfoResp.btyTotalCount = binInfos.Count(); List canSwapCounts = BinInfoRepository.QueryListByClause(i => - i.Exists == 1 && i.Status == 1 && i.Soc >= Convert.ToDecimal(StaticStationInfo.SwapSoc) && i.ChargeStatus!=1); + i.Exists == 1 && i.Status == 1 && i.Soc >= Convert.ToDecimal(StaticStationInfo.SwapSoc) && + i.ChargeStatus != 1); if (canSwapCounts.Count > 0) batteryStatusInfoResp.canSwapCount = canSwapCounts.Count(); List chargingCounts = @@ -162,4 +227,4 @@ public class ChargerService batteryStatusInfoResp.chargingCount = chargingCounts.Count(); return Result.Success(batteryStatusInfoResp); } -} +} \ No newline at end of file diff --git a/Service/Charger/Client/ChargerClient.cs b/Service/Charger/Client/ChargerClient.cs index b8cc721..55b001f 100644 --- a/Service/Charger/Client/ChargerClient.cs +++ b/Service/Charger/Client/ChargerClient.cs @@ -22,6 +22,8 @@ using Service.Charger.Msg.Charger.Resp; using Service.Charger.Msg.Host.Req; using Service.Charger.Msg.Host.Req.Bms; using Service.Charger.Msg.Host.Req.OutCharger.Req; +using Service.Init; +using Service.WaterCool.Client; namespace Service.Charger.Client; @@ -463,10 +465,7 @@ public class ChargerClient : TcpClient } - - - setPeakValleyTime= GetMsgContents(setPeakValleyTime); - + setPeakValleyTime = GetMsgContents(setPeakValleyTime); CurrentCmd = JsonConvert.SerializeObject(setPeakValleyTime, Formatting.Indented) + "\r\n" + @@ -645,6 +644,23 @@ public class ChargerClient : TcpClient return Result.Fail($"仓-{BinNo} 被禁用"); } + //判断水冷继电器状态为断开 + + var relation = StaticStationInfo.RelationMap[Sn]; + var waterCoolClient = WaterCoolClientMgr.GetBySn(relation.WaterCoolerCode) + ; + if (waterCoolClient == null) + { + return Result.Fail($"液冷机组未初始化"); + } + + + if (!waterCoolClient.WaitIsClose()) + { + return Result.Fail($"继电器未断开"); + } + + RedisHelper redisHelper = AppInfo.Container.Resolve(); string? lockKey = redisHelper.GetStrValue($"chargeNo{BinNo}Start"); @@ -716,22 +732,22 @@ public class ChargerClient : TcpClient { for (int i = 0; i < timeRng.NumberTime; i++) { - PropertyInfo propertyStartTimePeriod1 = timeRng.GetType().GetProperty("StartHH" + (i + 1)); - propertyStartTimePeriod1.SetValue(timeRng, BitUtls.ByteToBCD(Convert.ToByte(timeRng.GetType().GetProperty("StartHH" + (i + 1)).GetValue(timeRng)))); + propertyStartTimePeriod1.SetValue(timeRng, + BitUtls.ByteToBCD(Convert.ToByte(timeRng.GetType().GetProperty("StartHH" + (i + 1)) + .GetValue(timeRng)))); PropertyInfo propertyStartTimePeriod2 = timeRng.GetType().GetProperty("StartMM" + (i + 1)); - propertyStartTimePeriod2.SetValue(timeRng, BitUtls.ByteToBCD(Convert.ToByte(timeRng.GetType().GetProperty("StartMM" + (i + 1)).GetValue(timeRng)))); + propertyStartTimePeriod2.SetValue(timeRng, + BitUtls.ByteToBCD(Convert.ToByte(timeRng.GetType().GetProperty("StartMM" + (i + 1)) + .GetValue(timeRng)))); PropertyInfo propertyTimePeriodPeakIden = timeRng.GetType().GetProperty("TimePeak" + (i + 1)); - propertyTimePeriodPeakIden.SetValue(timeRng, timeRng.GetType().GetProperty("TimePeak" + (i + 1)).GetValue(timeRng)); - - - + propertyTimePeriodPeakIden.SetValue(timeRng, + timeRng.GetType().GetProperty("TimePeak" + (i + 1)).GetValue(timeRng)); } return timeRng; } - -} +} \ No newline at end of file diff --git a/Service/Charger/Handler/FinishStartChargingHandler.cs b/Service/Charger/Handler/FinishStartChargingHandler.cs index 9b149fa..1ab4a8c 100644 --- a/Service/Charger/Handler/FinishStartChargingHandler.cs +++ b/Service/Charger/Handler/FinishStartChargingHandler.cs @@ -10,6 +10,8 @@ using Service.Charger.Common; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Init; +using Service.WaterCool.Client; namespace HybirdFrameworkServices.Charger.Handler { @@ -31,6 +33,7 @@ namespace HybirdFrameworkServices.Charger.Handler public SwapOrderBatteryRepository SwapOrderBatteryRepository { get; set; } private static readonly ILog Log = LogManager.GetLogger(typeof(FinishStartChargingHandler)); + protected override void ChannelRead0(IChannelHandlerContext ctx, FinishStartCharging msg) { if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) @@ -43,13 +46,15 @@ namespace HybirdFrameworkServices.Charger.Handler client.IsCharged = true; client.IsStopped = false; chargeStatus = 1; - SwapOrderBattery? swapOrderBattery = SwapOrderBatteryRepository.QueryLatestOrderNoByBatterySn(client.BatteryNo); + SwapOrderBattery? swapOrderBattery = + SwapOrderBatteryRepository.QueryLatestOrderNoByBatterySn(client.BatteryNo); if (swapOrderBattery != null) { ChargeOrderRepository.Update(it => it.SwapOrderSn == swapOrderBattery.SwapOrderSn, it => it.Sn == client.ChargeOrderNo); - List orders = ChargeOrderRepository.QueryBySwapOrderAndBatterySn(swapOrderBattery.SwapOrderSn, + List orders = ChargeOrderRepository.QueryBySwapOrderAndBatterySn( + swapOrderBattery.SwapOrderSn, client.BatteryNo); if (orders.Count > 0) { @@ -60,7 +65,6 @@ namespace HybirdFrameworkServices.Charger.Handler { cloudChargeOrder = order.CloudChargeOrder; } - } if (string.IsNullOrWhiteSpace(cloudChargeOrder)) @@ -72,21 +76,28 @@ namespace HybirdFrameworkServices.Charger.Handler ChargeOrderRepository.Update(it => it.CloudChargeOrder == cloudChargeOrder, it => hashSet.Contains(it.Id)); } - - } else { Log.Error($"can not find swapOrderBattery by {client.BatteryNo}"); } + //闭合继电器状态 + + var waterCoolClient = + WaterCoolClientMgr.GetBySn(StaticStationInfo.RelationMap[client.Sn].WaterCoolerCode); + if (waterCoolClient != null) + { + //闭合继电器状态-延时300->上高压->按照策略开始液冷模式 + waterCoolClient.HeartManageStart(); + } } else if (msg.Result == 1) { client.IsCharged = false; } - if (ObjUtils.IsNotNullOrWhiteSpace( client.ChargeOrderNo)) + if (ObjUtils.IsNotNullOrWhiteSpace(client.ChargeOrderNo)) { ChargeOrderRepository.Update(it => it.CmdStatus == (msg.Result == 0 ? 1 : 2), it => it.Sn == client.ChargeOrderNo); @@ -101,4 +112,4 @@ namespace HybirdFrameworkServices.Charger.Handler } } } -} +} \ No newline at end of file diff --git a/Service/Charger/MyTask/AutoChargeTask.cs b/Service/Charger/MyTask/AutoChargeTask.cs index 1afc403..01c9f36 100644 --- a/Service/Charger/MyTask/AutoChargeTask.cs +++ b/Service/Charger/MyTask/AutoChargeTask.cs @@ -9,6 +9,7 @@ using Newtonsoft.Json; using Repository.Station; using Service.Charger.Client; using Service.Init; +using Service.WaterCool.Client; namespace Service.Charger.MyTask; @@ -200,7 +201,26 @@ public class AutoChargeTask : ITask foreach (var binInfo in stopList) { Log.Info($"auto stop charge {binInfo.No} soc:{binInfo.Soc}"); - ClientMgr.GetBySn(binInfo.ChargerNo)?.SendRemoteStopCharging(); + + var chargerClient = ClientMgr.GetBySn(binInfo.ChargerNo); + + WaterCoolClientMgr.Dictionary.TryGetValue( + StaticStationInfo.RelationMap[chargerClient?.Sn].WaterCoolerCode, + out WaterCoolClient client); + if (client == null) + { + Log.Info("stop charge fail -- not init watercooler"); + continue; + } + + if (!client.HeartManageStop()) + { + Log.Info("stop charge fail -- watercooler execute stop fail"); + continue; + } + + client.StopFlag = true; + chargerClient?.SendRemoteStopCharging(); } #endregion @@ -227,4 +247,4 @@ public class AutoChargeTask : ITask { _stop = false; } -} +} \ No newline at end of file diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs index 2f235dc..a79eee9 100644 --- a/Service/Init/StaticStationInfo.cs +++ b/Service/Init/StaticStationInfo.cs @@ -1,6 +1,8 @@ using Autofac; using Entity.Constant; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; +using Repository.Station; using Service.System; namespace Service.Init; @@ -8,61 +10,77 @@ namespace Service.Init; /// /// 换电站基本信息静态数据 /// -public class StaticStationInfo +public abstract class StaticStationInfo { + /// + /// 水冷/充电机关联关系 + /// + public static Dictionary RelationMap { get; set; } + + public static void Init() + { + List coolerRelations = + AppInfo.Container.Resolve().Query(); + RelationMap = coolerRelations.ToDictionary(i => i.ChargeCode, i => i); + } + public static int StationStatus { get => int.Parse(Resolve(StationParamConst.StationStatus)); set => Set(StationParamConst.StationStatus, value); } + public static string OperationStartTime { get => Resolve(StationParamConst.OperationStartTime); set => Set(StationParamConst.OperationStartTime, value); } + public static string OperationEndTime { get => Resolve(StationParamConst.OperationEndTime); set => Set(StationParamConst.OperationEndTime, value); } + public static string StationWay { get => Resolve(StationParamConst.StationWay); set => Set(StationParamConst.StationWay, value); } + public static string StationModel { get => Resolve(StationParamConst.StationModel); set => Set(StationParamConst.StationModel, value); } - + public static string StationName { get => Resolve(StationParamConst.StationName); set => Set(StationParamConst.StationName, value); } - public static string StationNo { get => Resolve(StationParamConst.StationNo); set => Set(StationParamConst.StationNo, value); } + public static string StationSn { get => Resolve(StationParamConst.StationSn); set => Set(StationParamConst.StationSn, value); } - + public static string SwapFinishChargeTime { get => Resolve(StationParamConst.SwapFinishChargeTime); set => Set(StationParamConst.SwapFinishChargeTime, value); } - + public static float SwapSoc { get => float.Parse(Resolve(StationParamConst.SwapSoc)); @@ -71,7 +89,7 @@ public class StaticStationInfo #region 充电相关 - public static int Eid + public static int Eid { get => int.Parse(Resolve(StationParamConst.Eid)); set => Set(StationParamConst.Eid, value); @@ -94,7 +112,7 @@ public class StaticStationInfo get => byte.Parse(Resolve(StationParamConst.ChargeSoc)); set => Set(StationParamConst.ChargeSoc, value); } - + public static float ChargePower { get => float.Parse(Resolve(StationParamConst.ChargePower)); @@ -109,10 +127,8 @@ public class StaticStationInfo get => byte.Parse(Resolve(StationParamConst.AutoChargeEnabled)); set => Set(StationParamConst.AutoChargeEnabled, value); } - #endregion - #region cloud @@ -124,7 +140,7 @@ public class StaticStationInfo } public static int CloudServerPort - { + { get { string port = Resolve(StationParamConst.CloudServerPort); @@ -132,6 +148,7 @@ public class StaticStationInfo { return 33000; } + return int.Parse(port); } set => Set(StationParamConst.CloudServerPort, value); diff --git a/Service/MyTask/HeartManagementTask.cs b/Service/MyTask/HeartManagementTask.cs new file mode 100644 index 0000000..7da7b9d --- /dev/null +++ b/Service/MyTask/HeartManagementTask.cs @@ -0,0 +1,163 @@ +using Autofac; +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.AutoTask; +using HybirdFrameworkCore.Redis; +using log4net; +using Newtonsoft.Json; +using Repository.Station; +using Service.Charger.Client; +using Service.Init; +using Service.Swap.Dto; +using Service.WaterCool.Client; + +namespace Service.MyTask; + +[Scope] +public class HeartManagementTask : ITask +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(HeartManagementTask)); + + private static bool _stop; + + public string Name() + { + return nameof(HeartManagementTask); + } + + public int Interval() + { + return 1000 * 3; + } + + public void Handle() + { + var waterCoolClients = WaterCoolClientMgr.Dictionary; + if (waterCoolClients.Count <= 0) + { + return; + } + + foreach (var waterCoolClient in waterCoolClients.Values) + { + if (waterCoolClient.Connected) + { + while (true) + { + if (string.IsNullOrWhiteSpace(waterCoolClient.ChargeSn)) + { + var dictionary = + StaticStationInfo.RelationMap.Values.ToDictionary(i => i.WaterCoolerCode, + i => i.ChargeCode); + waterCoolClient.ChargeSn = dictionary[waterCoolClient.Sn]; + } + var chargerClient = ClientMgr.GetBySn(waterCoolClient.ChargeSn); + if (chargerClient == null) + { + return; + } + + if (!waterCoolClient.StopFlag) + { + //Tmin<=12℃且Tmean<=15℃ + if (!waterCoolClient.HortStrategyFlag && chargerClient.BatteryPackDataVoltage + ?.CellTemperatureMax <= + 15 + && chargerClient.BatteryPackDataVoltage + ?.CellTemperatureMin <= + 12) + { + waterCoolClient.HortStrategyFlag = true; + } + if (waterCoolClient.HortStrategyFlag && (chargerClient.BatteryPackDataVoltage?.CellTemperatureMax >= 20 + || chargerClient.BatteryPackDataVoltage?.CellTemperatureMin >= 17)) + { + waterCoolClient.HortStrategyFlag = false; + waterCoolClient.msg.SetTemperature = 0; + waterCoolClient.msg.Mode = 0; + } + + //开启制冷策略 + if (!waterCoolClient.ColdStrategyFlag && chargerClient.BatteryPackDataVoltage?.CellTemperatureMax >= + 28 + && chargerClient.BatteryPackDataVoltage?.CellTemperatureMin >= + 24) + { + waterCoolClient.ColdStrategyFlag = true; + } + + if (waterCoolClient.ColdStrategyFlag && + (chargerClient.BatteryPackDataVoltage?.CellTemperatureMax <= 28 + || chargerClient.BatteryPackDataVoltage?.CellTemperatureMin <= 22)) + { + waterCoolClient.msg.SetTemperature = 0; + waterCoolClient.msg.Mode = 0; + waterCoolClient.ColdStrategyFlag = false; + } + + //加热模式 + if (waterCoolClient.HortStrategyFlag) + { + waterCoolClient.msg.Mode = 2; + waterCoolClient.msg.SetTemperature = 45; + } + + if (waterCoolClient.ColdStrategyFlag) + { + //若前一个模式为关机模式或制热模式或自循环模式,则请求TMS进行自循环模式;若前一个模式为制冷模式,则请求TMS进行制冷模式 + if (waterCoolClient.WaterCoolStatus?.ComeBackTemperature > 7 && + waterCoolClient.WaterCoolStatus?.ComeBackTemperature < 10) + { + Log.Info("7< <10"); + if (waterCoolClient.WaterCoolStatus?.TmsStatus != 1) + { + waterCoolClient.msg.Mode = 3; + } + else + { + waterCoolClient.msg.Mode = 1; + waterCoolClient.msg.SetTemperature = 10; + } + } + else if (waterCoolClient.WaterCoolStatus?.ComeBackTemperature >= 10) + { + Log.Info(">= 10"); + + // 进水口温度>=10℃,则请求 TMS进行冷却 + waterCoolClient.msg.Mode = 1; + waterCoolClient.msg.SetTemperature = 10; + } + else if (waterCoolClient.WaterCoolStatus?.ComeBackTemperature <= 7) + { + Log.Info("<=7"); + waterCoolClient.msg.Mode = 3; + } + } + } + else + { + //TODO:: 停止需要干什么事情 + + + } + } + } + } + } + + public bool Stoped() + { + return _stop; + } + + public void Stop() + { + _stop = true; + } + + public void ResetStop() + { + _stop = false; + } +} \ No newline at end of file diff --git a/Service/WaterCool/Client/WaterCoolClient.cs b/Service/WaterCool/Client/WaterCoolClient.cs index b6beafe..157962e 100644 --- a/Service/WaterCool/Client/WaterCoolClient.cs +++ b/Service/WaterCool/Client/WaterCoolClient.cs @@ -2,14 +2,18 @@ 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.Charger.Codec.Decoder; using Encoder = Service.Charger.Codec.Encoder; namespace Service.WaterCool.Client; + /// /// 水冷客户端 /// @@ -30,12 +34,33 @@ public class WaterCoolClient : TcpClient /// 是否发送水冷固定帧 /// public bool IsWaterCoolSend { get; set; } = true; - + + //上下电的时间 + /// + /// + /// + public DateTime? PowerChangeTime { get; set; } + + //上下电的时间间隔(单位/s) + public int Interval = 15; + + //停止标识 + public bool StopFlag = true; + + //制冷策略 + public bool ColdStrategyFlag = false; + + //制热策略 + public bool HortStrategyFlag = false; + /// /// 消息 /// - public ModeMsg msg{ get; set; }= new ModeMsg(); - + public ModeMsg msg { get; set; } = new ModeMsg(); + + //充电机sn + public string ChargeSn { get; set; } + private ILog Log() { var name = "WaterCool" + this.Sn; @@ -45,11 +70,42 @@ public class WaterCoolClient : TcpClient 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; + } + + /// /// 水冷机编号 /// public string Sn { get; set; } - + /// /// 水冷发送 /// @@ -71,6 +127,104 @@ public class WaterCoolClient : TcpClient ChannelUtils.AddAttr(Channel, ChargerConst.DestAddr, destAddr); } + + /// + /// 热管理策略 + /// 闭合继电器状态-延时300->上高压->按照策略开始液冷模式 + /// + 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); + } + + + /// + /// 热管理策略 + /// 下高压->监测继电器状态(5s)->断开继电器 (停止失败做报警,手动处理报警) + /// + 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; + } + + //上高压 + 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; + } + + /// + /// Tmax>=28℃且Tmean>=24℃ + /// 进水口温度>=10℃,则请求 TMS进行冷却。 + /// 7℃<进水口温度<10℃,若前一个模式为关机模式或制热模式或自循环模式,则请求TMS进行自循环模式;若前一个模式为制冷模式,则请求TMS进行制冷模式 + ///进水口温度<=7℃,则请求TMS进行自循环 + /// Tmax<=24℃或Tmean<=22℃ + /// + public void Strategy() + { + } + public bool Connect() { base.BaseConnect(); diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index 8eeb5fe..eb5d766 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -8,6 +8,7 @@ using HybirdFrameworkCore.Job; using HybirdFrameworkCore.Redis; using log4net; using Service.Charger.Client; +using Service.Init; using Service.RealTime; using Service.WaterCool.Client; using SqlSugar; @@ -114,6 +115,8 @@ if (signalrEnabled) RealtimeClient.Init(); } +StaticStationInfo.Init(); + // 水冷连接 WaterCoolClientMgr.InitClient();