diff --git a/Service/TBox/Handler/VinMsgHandler.cs b/Service/TBox/Handler/VinMsgHandler.cs new file mode 100644 index 0000000..47dc0dd --- /dev/null +++ b/Service/TBox/Handler/VinMsgHandler.cs @@ -0,0 +1,22 @@ +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Newtonsoft.Json; +using Service.TBox.Msg.TBox; +using Service.TBox.Server; + +namespace Service.TBox.Handler; + +[Order(8)] +[Scope("InstancePerDependency")] +public class VinMsgHandler : SimpleChannelInboundHandler, IBaseHandler +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(VinMsgHandler)); + + protected override void ChannelRead0(IChannelHandlerContext ctx, VinMsg msg) + { + Log.Info($"receive VinMsg={JsonConvert.SerializeObject(msg)}"); + var server = TBoxServerMgr.Server; + if (server != null) server.VinMsgs[msg.Seq] = msg; + } +} diff --git a/Service/TBox/Server/TBoxServer.cs b/Service/TBox/Server/TBoxServer.cs index fd657ff..5b12ab5 100644 --- a/Service/TBox/Server/TBoxServer.cs +++ b/Service/TBox/Server/TBoxServer.cs @@ -1,12 +1,14 @@ -using HybirdFrameworkCore.Autofac.Attribute; +using System.Text; +using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.AutoTask; using HybirdFrameworkDriver.TcpServer; using log4net; -using Service.TBox.Codec; using Service.TBox.Handler; using Service.TBox.Msg.Host; using Service.TBox.Msg.TBox; using Service.TBox.MyTask; +using Decoder = Service.TBox.Codec.Decoder; +using Encoder = Service.TBox.Codec.Encoder; using VinMsg = Service.TBox.Msg.Host.VinMsg; namespace Service.TBox.Server; @@ -38,12 +40,15 @@ public class TBoxServer : TcpServer public SubMileMsg SubMileMsg { get; set; } public TotalMileMsg TotalMileMsg { get; set; } public VersionMsg VersionMsg { get; set; } - public Msg.TBox.VinMsg VinMsg { get; set; } + public Msg.TBox.VinMsg[] VinMsgs { get; set; } = new Msg.TBox.VinMsg[3]; #endregion #region func + #region Send + + /// /// /// @@ -147,4 +152,41 @@ public class TBoxServer : TcpServer TBoxServerMgr.Server?.SessionMgr.Broadcast(new RestartMsg(restart)); } #endregion + + #region Read + + /// + /// 读取vin + /// + /// + public string? ReadVin() + { + if (VinMsgs[0] != null && VinMsgs[1] != null && VinMsgs[2] != null) + { + byte[] bytes = new byte[17]; + bytes[0] = VinMsgs[0].B2; + bytes[1] = VinMsgs[0].B3; + bytes[2] = VinMsgs[0].B4; + bytes[3] = VinMsgs[0].B5; + bytes[4] = VinMsgs[0].B6; + bytes[5] = VinMsgs[0].B7; + bytes[6] = VinMsgs[0].B8; + bytes[7] = VinMsgs[1].B2; + bytes[8] = VinMsgs[1].B3; + bytes[9] = VinMsgs[1].B4; + bytes[10] = VinMsgs[1].B5; + bytes[11] = VinMsgs[1].B6; + bytes[12] = VinMsgs[1].B7; + bytes[13] = VinMsgs[1].B8; + bytes[14] = VinMsgs[2].B2; + bytes[15] = VinMsgs[2].B3; + bytes[16] = VinMsgs[2].B4; + return Encoding.ASCII.GetString(bytes); + } + + return null; + } + + #endregion + #endregion }