master
rszn 4 months ago
parent b2f365f9f2
commit 49077d2e17

@ -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<VinMsg>, 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;
}
}

@ -1,12 +1,14 @@
using HybirdFrameworkCore.Autofac.Attribute; using System.Text;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask; using HybirdFrameworkCore.AutoTask;
using HybirdFrameworkDriver.TcpServer; using HybirdFrameworkDriver.TcpServer;
using log4net; using log4net;
using Service.TBox.Codec;
using Service.TBox.Handler; using Service.TBox.Handler;
using Service.TBox.Msg.Host; using Service.TBox.Msg.Host;
using Service.TBox.Msg.TBox; using Service.TBox.Msg.TBox;
using Service.TBox.MyTask; using Service.TBox.MyTask;
using Decoder = Service.TBox.Codec.Decoder;
using Encoder = Service.TBox.Codec.Encoder;
using VinMsg = Service.TBox.Msg.Host.VinMsg; using VinMsg = Service.TBox.Msg.Host.VinMsg;
namespace Service.TBox.Server; namespace Service.TBox.Server;
@ -38,12 +40,15 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
public SubMileMsg SubMileMsg { get; set; } public SubMileMsg SubMileMsg { get; set; }
public TotalMileMsg TotalMileMsg { get; set; } public TotalMileMsg TotalMileMsg { get; set; }
public VersionMsg VersionMsg { 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 #endregion
#region func #region func
#region Send
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -147,4 +152,41 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
TBoxServerMgr.Server?.SessionMgr.Broadcast(new RestartMsg(restart)); TBoxServerMgr.Server?.SessionMgr.Broadcast(new RestartMsg(restart));
} }
#endregion #endregion
#region Read
/// <summary>
/// 读取vin
/// </summary>
/// <returns></returns>
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
} }

Loading…
Cancel
Save