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.

38 lines
920 B

using HybirdFrameworkDriver.Common;
using Service.Fire.Common;
namespace Service.Fire.Msg;
public abstract class APCI : IToBytes
{
/// <summary>
/// 目标地址
/// </summary>
public byte DestAddress { get; set; }
/// <summary>
/// 数据长度
/// </summary>
public byte Length { get; set; }
public byte CrcHight { get; set; }
public byte CrcLow { get; set; }
public byte[] ToBytes()
{
var bodyBytes = GetBytes();
var list = new List<byte>();
list.AddRange(FireConst.StartChar);
list.Add(DestAddress);
list.Add((byte)bodyBytes.Length);
list.AddRange(bodyBytes);
CRC16 CRC16 = new();
//进行CRC校验
list.AddRange(BitConverter.GetBytes(CRC16.ComputeChecksum(list.ToArray())));
return list.ToArray();
}
public abstract byte[] GetBytes();
}