1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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
- {
- /// <summary>
- /// LNAO (Originator Subnet + Node) + IFSF_MsgCode = 1 + DEVICE_STATUS
- ///
- /// </summary>
- public class LonWorksHeartbeat : IfsfMessageBase
- {
- public LonWorksHeartbeat(byte ifsfDomain, byte originatorSubnet, byte originatorNode)
- {
- this.IfsfDomain = ifsfDomain;
- base.OriginatorSubnet = originatorSubnet;
- base.OriginatorNode = originatorNode;
- this.MessageCode = MessageCode.IFSF_MESSAGE_CODE_HEARTBEAT;
- }
- [Format(1, EncodingType.BIN, -19990)]
- [Range(0, 255, "IfsfDomaint must range in 0 to 255, but actual is: {0}")]
- public byte IfsfDomain { 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);
- }
- }
- }
|