添加日志

master
rszn 4 months ago
parent 34ba107429
commit c592bf200d

@ -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<BaseMsg> Msgs { get; set; } = new();
//TODO 实际开发时去掉
public static Queue<byte[]> 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<SocMsg>(bytes),
0x18FF48A8 => ModelConvert.Decode<StatusMsg>(bytes),
0x18E1D0F3=> ModelConvert.Decode<BatteryOneSn>(bytes),
0x18E2D0F3=> ModelConvert.Decode<BatteryTwoSn>(bytes),
0x18E3D0F3=> ModelConvert.Decode<BatteryThreeSn>(bytes),
0x18E4D0F3=> ModelConvert.Decode<BatteryFourSn>(bytes),
0x18E1F3D0=> ModelConvert.Decode<VinMsg>(bytes),
0x1801D8A7=> ModelConvert.Decode<VersionMsg>(bytes),
//0x1880D0F3=> ModelConvert.Decode<StatusMsg>(bytes),
@ -56,8 +50,7 @@ public class Decoder : ByteToMessageDecoder
_ => ModelConvert.Decode<OtherMsg>(bytes),
};
//TODO 实际开发时去掉
Msgs.Enqueue(baseMsg);
Log.Info($"receive={BitUtls.BytesToHexStr(bytes)}, msg={JsonConvert.SerializeObject(baseMsg)}");
output.Add(baseMsg);
}
}

@ -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<BaseMsg>
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);
}
}

@ -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<TBoxServer>();
Server.LogLevel = 0;
Server.LogLevel = LogLevel.TRACE;
Server.Start(port);
}
}

@ -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)

Loading…
Cancel
Save