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}"); + } } } }