diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs index 58a577a..49b822b 100644 --- a/Service/Plc/Client/PlcClient.cs +++ b/Service/Plc/Client/PlcClient.cs @@ -343,6 +343,36 @@ public class PlcClient : TcpClient } + ///// + ///// 发送电池充电状态 + ///// + ///// Plc编号 + ///// 消息 + //public Result SendWhetherChargedResq() + //{ + // if (!Connected) + // { + // return Result.Fail($"Plc{Sn}未连接"); + // } + // List binInfos = _binInfoRepository.Query(); + // var configuration = new MapperConfiguration(cfg => cfg.CreateMap()); + // var mapper = configuration.CreateMapper(); + + // List binInfoList = mapper.Map>(binInfos); + // byte[] granaries = new byte[8]; + + // for (int i = 0; i < binInfoList.Count && i < granaries.Length; i++) + // { + // granaries[i] = (binInfoList[i].ChargeStatus == 0 || binInfoList[i].ChargeStatus.Value == 2 || binInfoList[i].ChargeStatus.Value == 4) ? (byte)0 : (byte)1; + // } + // WhetherChargedResq req = new WhetherChargedResq(granaries[0], granaries[1], granaries[2], granaries[3], granaries[4], granaries[5], granaries[6], granaries[7]); + // this.Channel.WriteAndFlushAsync(req); + // return Result.Success(); + //} + + + + ///// ///// 发送参数设置 ///// diff --git a/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs b/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs index 30d25e0..bcccd71 100644 --- a/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs +++ b/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs @@ -1,9 +1,11 @@ +using AutoMapper; using DotNetty.Transport.Channels; +using Entity.Api.Resp; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Repository.Station; -using Service.Charger.Msg.Charger.Req; + namespace Service.Charger.Handler; @@ -14,7 +16,7 @@ namespace Service.Charger.Handler; [Scope("InstancePerDependency")] public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler, IBaseHandler { - + private readonly BinInfoRepository _binInfoRepository; private static readonly ILog Log =LogManager.GetLogger(typeof(BatteryStatusReportedReqHandler)); public BinInfoRepository BinInfoRepository { get; set; } @@ -25,8 +27,20 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryStatusReportedReq msg) { - // ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Req.WhetherChargedReq()); - UpdateBinInfo(msg.granary01, "1"); + List binInfos = _binInfoRepository.Query(); + var configuration = new MapperConfiguration(cfg => cfg.CreateMap()); + var mapper = configuration.CreateMapper(); + + List binInfoList = mapper.Map>(binInfos); + byte[] granaries = new byte[8]; + + for (int i = 0; i < binInfoList.Count && i < granaries.Length; i++) + { + granaries[i] = (binInfoList[i].ChargeStatus == 0 || binInfoList[i].ChargeStatus.Value == 2 || binInfoList[i].ChargeStatus.Value == 4) ? (byte)0 : (byte)1; + } + ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.WhetherChargedResq(granaries[0], granaries[1], granaries[2], granaries[3], granaries[4], granaries[5], granaries[6], granaries[7])); + + UpdateBinInfo(msg.granary01, "1"); UpdateBinInfo(msg.granary02, "2"); UpdateBinInfo(msg.granary03, "3"); UpdateBinInfo(msg.granary04, "4"); diff --git a/Service/Plc/Handler/VehicleModelResqHandler.cs b/Service/Plc/Handler/VehicleModelResqHandler.cs index 2951536..816a78d 100644 --- a/Service/Plc/Handler/VehicleModelResqHandler.cs +++ b/Service/Plc/Handler/VehicleModelResqHandler.cs @@ -30,6 +30,7 @@ public class VehicleModelResqHandler : SimpleChannelInboundHandler +/// 电池包拆卸完成 处理器 +/// +[Order(8)] +[Scope("InstancePerDependency")] +public class WhetherChargedResqHandler : SimpleChannelInboundHandler, IBaseHandler +{ + + /// + /// + /// + private static readonly ILog Log = LogManager.GetLogger(typeof(WhetherChargedResqHandler)); + + /// + /// + /// + protected override void ChannelRead0(IChannelHandlerContext ctx, WhetherChargedResq msg) + { + Log.Info("Sends the battery charge status"); + + } +} diff --git a/Service/Plc/Msg/Host/Resp/WhetherChargedResq.cs b/Service/Plc/Msg/Host/Resp/WhetherChargedResq.cs new file mode 100644 index 0000000..f0b1aa3 --- /dev/null +++ b/Service/Plc/Msg/Host/Resp/WhetherChargedResq.cs @@ -0,0 +1,71 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using Service.Charger.Msg; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Service.Charger.Msg.Host.Resp; +{ + public class WhetherChargedResq : ASDU + { + /// + /// 仓01 + /// + [Property(0, 1)] + public byte granary01 { get; set; } + /// + /// 仓02 + /// + [Property(1, 1)] + public byte granary02 { get; set; } + /// + /// 仓03 + /// + [Property(2, 1)] + public byte granary03 { get; set; } + /// + /// 仓04 + /// + [Property(3, 1)] + public byte granary04 { get; set; } + /// + /// 仓05 + /// + [Property(4, 1)] + public byte granary05 { get; set; } + /// + /// 仓06 + /// + [Property(5, 1)] + public byte granary06 { get; set; } + /// + /// 仓07 + /// + [Property(6, 1)] + public byte granary07 { get; set; } + /// + /// 仓08 + /// + [Property(7, 1)] + public byte granary08 { get; set; } + + public WhetherChargedResq(byte granary01, byte granary02, byte granary03, byte granary04, byte granary05, byte granary06, byte granary07, byte granary08) + { + FrameTypeNo = 122; + MsgBodyCount = 1; + TransReason = 3; + PublicAddr = 0; + MsgBodyAddr = new byte[] { 0, 0, 0 }; + this.granary01 = granary01; + this.granary02 = granary02; + this.granary03 = granary03; + this.granary04 = granary04; + this.granary05 = granary05; + this.granary06 = granary06; + this.granary07 = granary07; + this.granary08 = granary08; + } + } +} diff --git a/Service/Plc/Server/PlcServer.cs b/Service/Plc/Server/PlcServer.cs index 8255724..7285e39 100644 --- a/Service/Plc/Server/PlcServer.cs +++ b/Service/Plc/Server/PlcServer.cs @@ -1,5 +1,7 @@ using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.Entity; using HybirdFrameworkDriver.TcpServer; +using Microsoft.AspNetCore.Mvc; using Service.Charger.Client; using Service.Charger.Codec; using Service.Charger.Handler; @@ -23,6 +25,7 @@ public class PlcServer : TcpServer SessionMgr.GetSession(sn)?.Send(msg); } + /// /// 发送出库命令 /// diff --git a/WebStarter/Controllers/PlcController.cs b/WebStarter/Controllers/PlcController.cs index f501dd6..033b026 100644 --- a/WebStarter/Controllers/PlcController.cs +++ b/WebStarter/Controllers/PlcController.cs @@ -53,6 +53,22 @@ public class PlcController : ControllerBase } return Result.Fail("充电机未连接"); } + ///// + ///// 发送电池充电状态 + ///// + ///// 充电机编号 + ///// 消息 + //[HttpGet] + //[Route("SendWhetherChargedReq")] + //public Result SendWhetherChargedResq() + //{ + // Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient; + // if (chargerClient != null) + // { + // return chargerClient.SendWhetherChargedResq(); + // } + // return Result.Fail("充电机未连接"); + //} /////