using DotNetty.Buffers;
using HybirdFrameworkCore.Utils;
using Service.Charger.Common;
namespace Service.Charger.Msg;
public class ASDU : APCI
{
///
/// 帧类型号
///
public byte FrameTypeNo { get; set; }
///
/// 信息体个数
///
public byte MsgBodyCount { get; set; }
///
/// 传送原因-3.1.3.2
///
public ushort TransReason { get; set; }
///
/// 公共地址
///
public ushort PublicAddr { get; set; }
///
/// 信息体地址-3个字节
///
public byte[]? MsgBodyAddr { get; set; }
public override byte[] GetBytes()
{
var list = new List();
list.Add(FrameTypeNo);
list.Add(MsgBodyCount);
list.AddRange(BitConverter.GetBytes(TransReason));
list.AddRange(BitConverter.GetBytes(PublicAddr));
list.AddRange(MsgBodyAddr);
list.AddRange(ModelConvert.Encode(this));
return list.ToArray();
}
public static void ParseHeader(IByteBuffer byteBuffer, ASDU asdu)
{
var start = ChargerConst.ApciStartChar.Length - 1;
asdu.PackLen = byteBuffer.GetUnsignedShortLE(start + 1);
asdu.CtlArea = byteBuffer.GetUnsignedInt(start + 3);
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)
};
}
}