LonWorksHeartbeat.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Edge.Core.Parser.BinaryParser.Attributes;
  2. using Edge.Core.Parser.BinaryParser.MessageEntity;
  3. using Edge.Core.Parser.BinaryParser.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace HengShan_Pump_TQC_IFSF.MessageEntity
  10. {
  11. /// <summary>
  12. /// LNAO (Originator Subnet + Node) + IFSF_MsgCode = 1 + DEVICE_STATUS
  13. ///
  14. /// </summary>
  15. public class LonWorksHeartbeat : IfsfMessageBase
  16. {
  17. public LonWorksHeartbeat(byte ifsfDomain, byte originatorSubnet, byte originatorNode)
  18. {
  19. this.IfsfDomain = ifsfDomain;
  20. base.OriginatorSubnet = originatorSubnet;
  21. base.OriginatorNode = originatorNode;
  22. this.MessageCode = MessageCode.IFSF_MESSAGE_CODE_HEARTBEAT;
  23. }
  24. [Format(1, EncodingType.BIN, -19990)]
  25. [Range(0, 255, "IfsfDomaint must range in 0 to 255, but actual is: {0}")]
  26. public byte IfsfDomain { get; set; }
  27. [Format(1, EncodingType.BIN, 3)]
  28. public byte RawDeviceState { get; set; }
  29. public IEnumerable<HeartbeatDeviceStatus> DeviceStates
  30. {
  31. get
  32. {
  33. var result = new List<HeartbeatDeviceStatus>();
  34. if (this.RawDeviceState == 0)
  35. result.Add(HeartbeatDeviceStatus.EverythingIsFine);
  36. if (this.RawDeviceState.GetBit(0) == 1)
  37. result.Add(HeartbeatDeviceStatus.ConfigurationNeeded);
  38. if (this.RawDeviceState.GetBit(7) == 1)
  39. result.Add(HeartbeatDeviceStatus.SoftwareRefreshRequired);
  40. return result;
  41. }
  42. set
  43. {
  44. foreach (var e in value)
  45. {
  46. if (e == HeartbeatDeviceStatus.ConfigurationNeeded)
  47. this.RawDeviceState = this.RawDeviceState.SetBit(0, 0, 1);
  48. if (e == HeartbeatDeviceStatus.SoftwareRefreshRequired)
  49. this.RawDeviceState = this.RawDeviceState.SetBit(7, 7, 1);
  50. }
  51. }
  52. }
  53. public override string ToLogString()
  54. {
  55. return base.ToLogString() + this.DeviceStates.Select(s => s.ToString()).Aggregate((acc, n) => acc + ", " + n);
  56. }
  57. }
  58. }