using Edge.Core.Parser.BinaryParser.Attributes; using System; using System.Collections.Generic; namespace PetroChinaOnlineWatchPlugin.MessageEntity.Incoming { public class HeartBeatIn : HeartBeatBase { [EnumerableFormat(4, -9990)] public List IpAddressBytes { get; set; } [Format(2, EncodingType.BIN, -9980)] public int Port { get; set; } [Format(1, EncodingType.BIN, -9970)] [Range(0, 255, "Subnet must range in 1 to 255")] public byte Subnet { get; set; } [Format(1, EncodingType.BIN, -9960)] [Range(0, 127, "Node must range in 1 to 127, but now is {0}")] public byte Node { get; set; } [Format(1, EncodingType.BIN, -9950)] public MessageCode MessageCode { get; set; } [Format(1, EncodingType.BIN, -9940)] public byte MessageState { get; set; } public string IpAddress { get { return $"{IpAddressBytes[0]}.{IpAddressBytes[1]}.{IpAddressBytes[2]}.{IpAddressBytes[3]}"; } } public bool NeedConfig { get { //02 = 0000 0010 return (MessageState & 0x02) > 0; } } public bool NeedUpdate { get { //80 = 1000 0000 return (MessageState & 0x80) > 0; } } public override string ToString() { string ipAddress = string.Empty; foreach (byte ip in IpAddressBytes) { ipAddress += " " + ip.ToString(); } return $"{IpAddress} {Port} {Subnet} {Node} {NeedConfig} {NeedUpdate}"; } } }