You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0 KiB

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