From ab819afb9777c0a9f4075b59c58746cb52c7c6c7 Mon Sep 17 00:00:00 2001 From: lxw Date: Tue, 28 May 2024 20:35:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0SOC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Charger/Handler/QueryBatterySnResHandler.cs | 6 +++--- .../Charger/Handler/VoltageCurrentSocHandler.cs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Service/Charger/Handler/QueryBatterySnResHandler.cs b/Service/Charger/Handler/QueryBatterySnResHandler.cs index 9e1b86e..788da46 100644 --- a/Service/Charger/Handler/QueryBatterySnResHandler.cs +++ b/Service/Charger/Handler/QueryBatterySnResHandler.cs @@ -31,10 +31,10 @@ namespace Service.Charger.Handler { if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { - StringBuilder sb = new StringBuilder(27); - foreach (var b in msg.BatterSnBytes) + StringBuilder sb = new StringBuilder(msg.BatterSnLength); + for (int i = 0; i < msg.BatterSnLength; i++) { - sb.Append(Convert.ToChar(b)); + sb.Append(Convert.ToChar(msg.BatterSnBytes[i])); } client.BatteryNo = sb.ToString(); diff --git a/Service/Charger/Handler/VoltageCurrentSocHandler.cs b/Service/Charger/Handler/VoltageCurrentSocHandler.cs index 4f22c6e..7acebdd 100644 --- a/Service/Charger/Handler/VoltageCurrentSocHandler.cs +++ b/Service/Charger/Handler/VoltageCurrentSocHandler.cs @@ -1,6 +1,7 @@ using DotNetty.Transport.Channels; using HybirdFrameworkCore.Autofac.Attribute; using log4net; +using Repository.Station; using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; using System; @@ -19,14 +20,26 @@ namespace Service.Charger.Handler public class VoltageCurrentSocHandler : SimpleChannelInboundHandler, IBaseHandler { private readonly ILog Log = LogManager.GetLogger(typeof(VoltageCurrentSocHandler)); + private BinInfoRepository _binInfoRepository; + public VoltageCurrentSocHandler(BinInfoRepository binInfoRepository) + { + _binInfoRepository = binInfoRepository; + } protected override void ChannelRead0(IChannelHandlerContext ctx, VoltageCurrentSoc msg) { if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); - + if (_binInfoRepository.Update(t => t.Soc == (decimal)msg.SOC, t => t.No == client.BinNo) > 0) + { + Log.Info($"succeed update battery soc {msg.SOC} for {client.BinNo}"); + } + else + { + Log.Info($"fail update battery soc {msg.SOC} for {client.BinNo}"); + } } } }