From c592bf200d214e12102964ff46663e7aa61e7ef4 Mon Sep 17 00:00:00 2001 From: rszn <645583145@qq.com> Date: Tue, 18 Jun 2024 10:40:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/TBox/Codec/Decoder.cs | 15 ++++----------- Service/TBox/Codec/Encoder.cs | 3 +++ Service/TBox/Server/TBoxServerMgr.cs | 3 ++- WinFormStarter/Form2.cs | 20 -------------------- 4 files changed, 9 insertions(+), 32 deletions(-) diff --git a/Service/TBox/Codec/Decoder.cs b/Service/TBox/Codec/Decoder.cs index abe7722..c1faa0b 100644 --- a/Service/TBox/Codec/Decoder.cs +++ b/Service/TBox/Codec/Decoder.cs @@ -3,6 +3,7 @@ using DotNetty.Codecs; using DotNetty.Transport.Channels; using HybirdFrameworkCore.Utils; using log4net; +using Newtonsoft.Json; using Service.TBox.Msg; using Service.TBox.Msg.TBox; @@ -10,10 +11,6 @@ namespace Service.TBox.Codec; public class Decoder : ByteToMessageDecoder { - //TODO 实际开发时去掉 - public static Queue Msgs { get; set; } = new(); - //TODO 实际开发时去掉 - public static Queue BytesQueue { get; set; } = new(); private static readonly ILog Log = LogManager.GetLogger(typeof(Decoder)); @@ -27,9 +24,6 @@ public class Decoder : ByteToMessageDecoder input.SkipBytes(1); input.ReadBytes(bytes); - //TODO 实际开发时去掉 - BytesQueue.Enqueue(bytes); - Log.Info($"receive {BitUtls.BytesToHexStr(bytes)}"); int id = BitConverter.ToInt32(new byte[] { bytes[3], bytes[2], bytes[1], bytes[0] }, 0); @@ -37,12 +31,12 @@ public class Decoder : ByteToMessageDecoder { 0x1882D0F3 => ModelConvert.Decode(bytes), 0x18FF48A8 => ModelConvert.Decode(bytes), - + 0x18E1D0F3=> ModelConvert.Decode(bytes), 0x18E2D0F3=> ModelConvert.Decode(bytes), 0x18E3D0F3=> ModelConvert.Decode(bytes), 0x18E4D0F3=> ModelConvert.Decode(bytes), - + 0x18E1F3D0=> ModelConvert.Decode(bytes), 0x1801D8A7=> ModelConvert.Decode(bytes), //0x1880D0F3=> ModelConvert.Decode(bytes), @@ -56,8 +50,7 @@ public class Decoder : ByteToMessageDecoder _ => ModelConvert.Decode(bytes), }; - //TODO 实际开发时去掉 - Msgs.Enqueue(baseMsg); + Log.Info($"receive={BitUtls.BytesToHexStr(bytes)}, msg={JsonConvert.SerializeObject(baseMsg)}"); output.Add(baseMsg); } } diff --git a/Service/TBox/Codec/Encoder.cs b/Service/TBox/Codec/Encoder.cs index 2f6aa30..81ab7f7 100644 --- a/Service/TBox/Codec/Encoder.cs +++ b/Service/TBox/Codec/Encoder.cs @@ -1,6 +1,7 @@ using DotNetty.Buffers; using DotNetty.Codecs; using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Utils; using log4net; using Service.TBox.Msg; @@ -21,6 +22,8 @@ public class Encoder : MessageToByteEncoder byte[] bytes = obj.ToBytes(); byte[] result = { 88, bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], 0, 0, 0, 0 }; + + Log.Info($"send={BitUtls.BytesToHexStr(result)}"); output.WriteBytes(result); } } diff --git a/Service/TBox/Server/TBoxServerMgr.cs b/Service/TBox/Server/TBoxServerMgr.cs index 0236c32..c5162b5 100644 --- a/Service/TBox/Server/TBoxServerMgr.cs +++ b/Service/TBox/Server/TBoxServerMgr.cs @@ -1,4 +1,5 @@ using Autofac; +using DotNetty.Handlers.Logging; using HybirdFrameworkCore.Autofac; namespace Service.TBox.Server; @@ -12,7 +13,7 @@ public class TBoxServerMgr if (Server == null) { Server = AppInfo.Container.Resolve(); - Server.LogLevel = 0; + Server.LogLevel = LogLevel.TRACE; Server.Start(port); } } diff --git a/WinFormStarter/Form2.cs b/WinFormStarter/Form2.cs index 817263a..4819008 100644 --- a/WinFormStarter/Form2.cs +++ b/WinFormStarter/Form2.cs @@ -2,11 +2,7 @@ using Autofac.Core; using DotNetty.Handlers.Logging; using HybirdFrameworkCore.Autofac; -using HybirdFrameworkCore.Utils; using log4net; -using Newtonsoft.Json; -using Service.TBox; -using Service.TBox.Codec; using Service.TBox.Server; namespace WinFormStarter; @@ -22,22 +18,6 @@ public partial class Form2 : Form { InitializeComponent(); this.txtPort.Text = "9999"; - Task.Run(() => - { - while (true) - { - if (Decoder.Msgs.TryDequeue(out var msg)) - { - - AppendText(rTxtParsed, JsonConvert.SerializeObject(msg) + "\r\n"); - } - if (Decoder.BytesQueue.TryDequeue(out var bytes)) - { - AppendText(rTxtOriginal, BitUtls.BytesToHexStr(bytes) + "\r\n"); - } - Thread.Sleep(50); - } - }); } private void AppendText(RichTextBox r, string msg)