| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using Edge.Core.Parser.BinaryParser.Attributes;
- using Edge.Core.Parser.BinaryParser.MessageEntity;
- using Edge.Core.Parser.BinaryParser.Util;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HengShan_Pump_TQC_IFSF.MessageEntity
- {
- public enum HeartbeatDeviceStatus
- {
- EverythingIsFine,
- ConfigurationNeeded,
- ReservedForFutureUse,
- SoftwareRefreshRequired,
- }
- public class Heartbeat : IfsfMessageBase
- {
- public Heartbeat(byte originatorSubnet, byte originatorNode, byte ipPart0, byte ipPart1, byte ipPart2, byte ipPart3, int port)
- {
- base.OriginatorSubnet = originatorSubnet;
- base.OriginatorNode = originatorNode;
- this.MessageCode = MessageCode.IFSF_MESSAGE_CODE_HEARTBEAT;
- this.IpPart0 = ipPart0;
- this.IpPart1 = ipPart1;
- this.IpPart2 = ipPart2;
- this.IpPart3 = ipPart3;
- this.Port = port;
- }
- [Range(1, 254, "Ip address 1st part should between 1 to 254")]
- [Format(1, EncodingType.BIN, -999999)]
- public byte IpPart0 { get; set; }
- [Range(1, 254, "Ip address 2nd part should between 1 to 254")]
- [Format(1, EncodingType.BIN, -999998)]
- public byte IpPart1 { get; set; }
- [Range(1, 254, "Ip address 3rd part should between 1 to 254")]
- [Format(1, EncodingType.BIN, -999997)]
- public byte IpPart2 { get; set; }
- [Range(1, 254, "Ip address 4th part should between 1 to 254")]
- [Format(1, EncodingType.BIN, -999996)]
- public byte IpPart3 { get; set; }
- [Range(1, 65534, "Ip port part should between 1 to 65534")]
- [Format(2, EncodingType.BIN, -999995)]
- public int Port { get; set; }
- [Format(1, EncodingType.BIN, 3)]
- public byte RawDeviceState { get; set; }
- public IEnumerable<HeartbeatDeviceStatus> DeviceStates
- {
- get
- {
- var result = new List<HeartbeatDeviceStatus>();
- if (this.RawDeviceState == 0)
- result.Add(HeartbeatDeviceStatus.EverythingIsFine);
- if (this.RawDeviceState.GetBit(0) == 1)
- result.Add(HeartbeatDeviceStatus.ConfigurationNeeded);
- if (this.RawDeviceState.GetBit(7) == 1)
- result.Add(HeartbeatDeviceStatus.SoftwareRefreshRequired);
- return result;
- }
- set
- {
- foreach (var e in value)
- {
- if (e == HeartbeatDeviceStatus.ConfigurationNeeded)
- this.RawDeviceState = this.RawDeviceState.SetBit(0, 0, 1);
- if (e == HeartbeatDeviceStatus.SoftwareRefreshRequired)
- this.RawDeviceState = this.RawDeviceState.SetBit(7, 7, 1);
- }
- }
- }
- public override string ToLogString()
- {
- return base.ToLogString() + this.DeviceStates.Select(s => s.ToString()).Aggregate((acc, n) => acc + ", " + n);
- }
- }
- }
|