From 1018f4485472f3af982ea3b42686fe4c402071c6 Mon Sep 17 00:00:00 2001 From: xjl <2595686544@qq.com> Date: Sat, 26 Oct 2024 10:05:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=93=E5=B1=95=E5=B8=A7=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Car/Codec/Decoder.cs | 1 + Service/Car/Handler/ElecBaseMsgHandler.cs | 1 + .../Car/Handler/HeartExpandBeatMsgHandler.cs | 46 +++++++++++++++++++ Service/Car/Msg/Car/Req/HeartExpandBeatMsg.cs | 27 +++++++++++ Service/Car/Server/CarServer.cs | 2 +- WebStarter/Controllers/CarController.cs | 11 +++++ WebStarter/Dto/Resp/CarInfoResp.cs | 5 ++ 7 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Service/Car/Handler/HeartExpandBeatMsgHandler.cs create mode 100644 Service/Car/Msg/Car/Req/HeartExpandBeatMsg.cs diff --git a/Service/Car/Codec/Decoder.cs b/Service/Car/Codec/Decoder.cs index a3e85d5..742df73 100644 --- a/Service/Car/Codec/Decoder.cs +++ b/Service/Car/Codec/Decoder.cs @@ -69,6 +69,7 @@ public class Decoder : ByteToMessageDecoder 0x08 => ModelConvert.Decode(data), 0x10 => ModelConvert.Decode(data), 0x12 => ModelConvert.Decode(data), + 0x13 => ModelConvert.Decode(data), 0x51 => ModelConvert.Decode(data), 0x52 => ModelConvert.Decode(data), _ => new BaseMsg() diff --git a/Service/Car/Handler/ElecBaseMsgHandler.cs b/Service/Car/Handler/ElecBaseMsgHandler.cs index c0615bf..78df599 100644 --- a/Service/Car/Handler/ElecBaseMsgHandler.cs +++ b/Service/Car/Handler/ElecBaseMsgHandler.cs @@ -30,6 +30,7 @@ namespace Service.Car.Handler Log.Info($"receive ElecBaseMsg = {JsonConvert.SerializeObject(msg)}"); IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(msg.CarNo); + msg.BatteryCode = msg.BatteryCode.Replace("\u0000", ""); ioSession?.BusinessMap.AddOrUpdate("ElecBaseMsg", msg, ((s, o) => msg)); ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true)); } diff --git a/Service/Car/Handler/HeartExpandBeatMsgHandler.cs b/Service/Car/Handler/HeartExpandBeatMsgHandler.cs new file mode 100644 index 0000000..4a73f2d --- /dev/null +++ b/Service/Car/Handler/HeartExpandBeatMsgHandler.cs @@ -0,0 +1,46 @@ +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkDriver.Session; +using log4net; +using Newtonsoft.Json; +using Service.Car.Msg.Car.Req; +using Service.Car.Msg.Host.Resp; +using Service.Car.Server; + +namespace Service.Car.Handler; + +/// +/// +/// +[Order(8)] +[Scope("InstancePerDependency")] +public class HeartExpandBeatMsgHandler : SimpleChannelInboundHandler, IBaseHandler +{ + + private static readonly ILog Log = LogManager.GetLogger(typeof(HeartExpandBeatMsgHandler)); + /// + /// + /// + /// + /// + /// + protected override void ChannelRead0(IChannelHandlerContext ctx, HeartExpandBeatMsg msg) + { + + Log.Info($"receive HeartBeatMsg = {JsonConvert.SerializeObject(msg)}"); + IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(ctx.Channel.Id.ToString()); + if (ioSession != null && ioSession.Key != msg.CarNo) + { + CarServerMgr.CarServer?.SessionMgr.ChangeSessionKey(ioSession, msg.CarNo); + } + + if (ioSession == null) + { + ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(msg.CarNo); + } + + ioSession.BusinessMap.AddOrUpdate("HeartExpandBeatMsg", msg, ((s, o) => msg)); + ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true)); + + } +} diff --git a/Service/Car/Msg/Car/Req/HeartExpandBeatMsg.cs b/Service/Car/Msg/Car/Req/HeartExpandBeatMsg.cs new file mode 100644 index 0000000..793cb51 --- /dev/null +++ b/Service/Car/Msg/Car/Req/HeartExpandBeatMsg.cs @@ -0,0 +1,27 @@ +using HybirdFrameworkCore.Autofac.Attribute; + +namespace Service.Car.Msg.Car.Req; + +public class HeartExpandBeatMsg : BaseMsg +{ + /// + /// 锁止IO状态1 + /// + [Property(248, 8)] + public byte LockIOStatus01 { get; set; } + /// + /// 锁止IO状态2 + /// + [Property(256, 8)] + public byte LockIOStatus02 { get; set; } + /// + /// 充电连接器状态1 0 断开,1 连接 + /// + [Property(264, 8)] + public byte ChargingConnectorStatus01 { get; set; } + /// + /// 充电连接器状态1 0 断开,1 连接 + /// + [Property(272, 8)] + public byte ChargingConnectorStatus02 { get; set; } +} \ No newline at end of file diff --git a/Service/Car/Server/CarServer.cs b/Service/Car/Server/CarServer.cs index 74c4eec..1234835 100644 --- a/Service/Car/Server/CarServer.cs +++ b/Service/Car/Server/CarServer.cs @@ -24,7 +24,7 @@ public class CarServer : TcpServer /// 1 待机 2 换电 /// public byte StationStatus { get; set; } = 1; - public string VIN { get; set; }; + public string VIN { get; set; } public CarServer() : base() diff --git a/WebStarter/Controllers/CarController.cs b/WebStarter/Controllers/CarController.cs index 20f88d5..dda675c 100644 --- a/WebStarter/Controllers/CarController.cs +++ b/WebStarter/Controllers/CarController.cs @@ -54,6 +54,12 @@ public class CarController : ControllerBase{ { carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg; } + + ioSession.BusinessMap.TryGetValue("HeartExpandBeatMsg", out var heartExpandBeatMsg); + if (heartExpandBeatMsg != null) + { + carInfoResp.HeartExpandBeatMsg = (HeartExpandBeatMsg)heartExpandBeatMsg; + } } @@ -95,6 +101,11 @@ public class CarController : ControllerBase{ { carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg; } + ioSession.BusinessMap.TryGetValue("HeartExpandBeatMsg", out var heartExpandBeatMsg); + if (heartExpandBeatMsg != null) + { + carInfoResp.HeartExpandBeatMsg = (HeartExpandBeatMsg)heartExpandBeatMsg; + } result.Add(carInfoResp); diff --git a/WebStarter/Dto/Resp/CarInfoResp.cs b/WebStarter/Dto/Resp/CarInfoResp.cs index b5574a2..9f5e714 100644 --- a/WebStarter/Dto/Resp/CarInfoResp.cs +++ b/WebStarter/Dto/Resp/CarInfoResp.cs @@ -31,4 +31,9 @@ public class CarInfoResp /// 状态数据 /// public HeartBeatMsg? HeartBeatMsg { get; set; } + + /// + /// 状态拓展数据 + /// + public HeartExpandBeatMsg? HeartExpandBeatMsg { get; set; } } \ No newline at end of file