using Edge.Core.Parser.BinaryParser.Attributes; using System; using System.Collections.Generic; namespace PetroChinaOnlineWatchPlugin.MessageEntity.Outgoing { public class HeartBeatOut : HeartBeatBase { [EnumerableFormat("%cascade", -9990)] public List IpAddressBytes { get; protected 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 { return MessageCode.IFSF_MESSAGE_CODE_HEARTBEAT; } } [Format(1, EncodingType.BIN, -9940)] public byte MessageState { get; protected set; } public string IpAddress { set { IpAddressBytes = new List(); foreach (string item in value.Split('.')) { IpAddressBytes.Add(byte.Parse(item)); } } } public bool NeedConfig { set { //02 = 0000 0010 if (value) MessageState = (byte)(MessageState | 0x02); } } public bool NeedUpdate { set { //80 = 1000 0000 if (value) MessageState = (byte)(MessageState | 0x80); } } public override string ToString() { string ipAddress = string.Empty; foreach (byte ip in IpAddressBytes) { ipAddress += " " + ip.ToString(); } return $"{ipAddress} {Port} {Subnet} {Node}"; } } }