|
|
@ -1,8 +1,12 @@
|
|
|
|
using DotNetty.Buffers;
|
|
|
|
using DotNetty.Buffers;
|
|
|
|
using DotNetty.Codecs;
|
|
|
|
using DotNetty.Codecs;
|
|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
|
|
|
|
using HybirdFrameworkCore.Utils;
|
|
|
|
using log4net;
|
|
|
|
using log4net;
|
|
|
|
using Service.Car.Common;
|
|
|
|
using Service.Car.Common;
|
|
|
|
|
|
|
|
using Service.Car.Msg;
|
|
|
|
|
|
|
|
using Service.Car.Msg.Car.Req;
|
|
|
|
|
|
|
|
using Service.Car.Msg.Car.Resp;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Service.Car.Codec;
|
|
|
|
namespace Service.Car.Codec;
|
|
|
|
|
|
|
|
|
|
|
@ -20,7 +24,7 @@ public class Decoder : ByteToMessageDecoder
|
|
|
|
//分隔符索引
|
|
|
|
//分隔符索引
|
|
|
|
int delimiterIndex = IndexOf(buffer, delimiter);
|
|
|
|
int delimiterIndex = IndexOf(buffer, delimiter);
|
|
|
|
//帧长索引
|
|
|
|
//帧长索引
|
|
|
|
int frameLengthIndex = delimiterIndex + delimiter.Capacity;
|
|
|
|
int frameLengthIndex = delimiterIndex + CarConst.StartChar.Length;
|
|
|
|
|
|
|
|
|
|
|
|
if (delimiterIndex > 0)
|
|
|
|
if (delimiterIndex > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -28,7 +32,7 @@ public class Decoder : ByteToMessageDecoder
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buffer.ReadableBytes < frameLengthIndex + 2)
|
|
|
|
if (buffer.ReadableBytes < frameLengthIndex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 数据不足,等待更多数据
|
|
|
|
// 数据不足,等待更多数据
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -43,10 +47,30 @@ public class Decoder : ByteToMessageDecoder
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var msg = Parse(buffer, frameLength);
|
|
|
|
|
|
|
|
output.Add(msg);
|
|
|
|
|
|
|
|
|
|
|
|
buffer.Clear();
|
|
|
|
buffer.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BaseMsg Parse(IByteBuffer buffer, int length)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
byte[] data = new byte[length];
|
|
|
|
|
|
|
|
buffer.ReadBytes(data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return data[5] switch
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
0x01 => ModelConvert.Decode<ElecMsg>(data),
|
|
|
|
|
|
|
|
0x03 => ModelConvert.Decode<HeartBeatMsg>(data),
|
|
|
|
|
|
|
|
0x06 => ModelConvert.Decode<LockMsgResp>(data),
|
|
|
|
|
|
|
|
0x08 => ModelConvert.Decode<UnLockMsgResp>(data),
|
|
|
|
|
|
|
|
0x10 => ModelConvert.Decode<SettleConfirmMsgResp>(data),
|
|
|
|
|
|
|
|
0x12 => ModelConvert.Decode<SetParamMsgResp>(data),
|
|
|
|
|
|
|
|
_ => new BaseMsg()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IByteBuffer? FindDelimiter(IByteBuffer buffer)
|
|
|
|
private IByteBuffer? FindDelimiter(IByteBuffer buffer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (IByteBuffer delimiter in _delimiters)
|
|
|
|
foreach (IByteBuffer delimiter in _delimiters)
|
|
|
|