decoder优化

zw
rszn 5 months ago
parent dc9296ddf1
commit 156b49ab9d

@ -124,8 +124,8 @@ public class Decoder : ByteToMessageDecoder
int removeIndex = delimiter.Capacity; int removeIndex = delimiter.Capacity;
ushort cmd = byteBuffer.GetByte(14 + removeIndex); ushort cmd =data[14 + removeIndex];
ushort recordType = byteBuffer.GetByte(23 + removeIndex); ushort recordType = data[23 + removeIndex];
byte[] bytes = new byte[data.Length - (23 + removeIndex)]; byte[] bytes = new byte[data.Length - (23 + removeIndex)];
Array.Copy(data, 23 + removeIndex, bytes, 0, bytes.Length); Array.Copy(data, 23 + removeIndex, bytes, 0, bytes.Length);
ASDU asdu = cmd switch ASDU asdu = cmd switch
@ -248,7 +248,7 @@ public class Decoder : ByteToMessageDecoder
_ => new ASDU() _ => new ASDU()
}; };
ASDU.ParseHeader(byteBuffer, asdu); ASDU.ParseHeader(data, asdu);
return asdu; return asdu;
} }

@ -46,29 +46,41 @@ public class ASDU : APCI
} }
public static void ParseHeader(IByteBuffer byteBuffer, ASDU asdu) public static void ParseHeader(byte[] data, ASDU asdu)
{ {
var start = ChargerConst.StartChar.Length - 1; IByteBuffer byteBuffer = Unpooled.WrappedBuffer(data);
try
{
var start = ChargerConst.StartChar.Length - 1;
asdu.PackLen = byteBuffer.GetUnsignedShortLE(start + 1); asdu.PackLen = byteBuffer.GetUnsignedShortLE(start + 1);
asdu.CtlArea = byteBuffer.GetUnsignedInt(start + 3); asdu.CtlArea = byteBuffer.GetUnsignedInt(start + 3);
asdu.DestAddr = new[] asdu.DestAddr = new[]
{
byteBuffer.GetByte(start + 7),
byteBuffer.GetByte(start + 8),
byteBuffer.GetByte(start + 9),
byteBuffer.GetByte(start + 10)
};
asdu.SrcAddr = byteBuffer.GetUnsignedInt(start + 11);
asdu.FrameTypeNo = byteBuffer.GetByte(start + 15);
asdu.MsgBodyCount = byteBuffer.GetByte(start + 16);
asdu.TransReason = byteBuffer.GetUnsignedShortLE(start + 17);
asdu.PublicAddr = byteBuffer.GetUnsignedShortLE(start + 19);
asdu.MsgBodyAddr = new[]
{
byteBuffer.GetByte(start + 21),
byteBuffer.GetByte(start + 22),
byteBuffer.GetByte(start + 23)
};
}
catch (Exception e)
{ {
byteBuffer.GetByte(start + 7), throw e;
byteBuffer.GetByte(start + 8), }
byteBuffer.GetByte(start + 9), finally
byteBuffer.GetByte(start + 10)
};
asdu.SrcAddr = byteBuffer.GetUnsignedInt(start + 11);
asdu.FrameTypeNo = byteBuffer.GetByte(start + 15);
asdu.MsgBodyCount = byteBuffer.GetByte(start + 16);
asdu.TransReason = byteBuffer.GetUnsignedShortLE(start + 17);
asdu.PublicAddr = byteBuffer.GetUnsignedShortLE(start + 19);
asdu.MsgBodyAddr = new[]
{ {
byteBuffer.GetByte(start + 21), byteBuffer.Release();
byteBuffer.GetByte(start + 22), }
byteBuffer.GetByte(start + 23)
};
} }
} }
Loading…
Cancel
Save