zw
lxw 6 months ago
parent 9792612377
commit ab819afb97

@ -31,10 +31,10 @@ namespace Service.Charger.Handler
{ {
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{ {
StringBuilder sb = new StringBuilder(27); StringBuilder sb = new StringBuilder(msg.BatterSnLength);
foreach (var b in msg.BatterSnBytes) for (int i = 0; i < msg.BatterSnLength; i++)
{ {
sb.Append(Convert.ToChar(b)); sb.Append(Convert.ToChar(msg.BatterSnBytes[i]));
} }
client.BatteryNo = sb.ToString(); client.BatteryNo = sb.ToString();

@ -1,6 +1,7 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using log4net; using log4net;
using Repository.Station;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Req;
using System; using System;
@ -19,14 +20,26 @@ namespace Service.Charger.Handler
public class VoltageCurrentSocHandler : SimpleChannelInboundHandler<VoltageCurrentSoc>, IBaseHandler public class VoltageCurrentSocHandler : SimpleChannelInboundHandler<VoltageCurrentSoc>, IBaseHandler
{ {
private readonly ILog Log = LogManager.GetLogger(typeof(VoltageCurrentSocHandler)); 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) protected override void ChannelRead0(IChannelHandlerContext ctx, VoltageCurrentSoc msg)
{ {
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{ {
Log.Info($"receive {msg} from {sn}"); 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}");
}
} }
} }
} }

Loading…
Cancel
Save