HeartBeatOut.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Edge.Core.Parser.BinaryParser.Attributes;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace PetroChinaOnlineWatchPlugin.MessageEntity.Outgoing
  5. {
  6. public class HeartBeatOut : HeartBeatBase
  7. {
  8. [EnumerableFormat("%cascade", -9990)]
  9. public List<byte> IpAddressBytes { get; protected set; }
  10. [Format(2, EncodingType.BIN, -9980)]
  11. public int Port { get; set; }
  12. [Format(1, EncodingType.BIN, -9970)]
  13. [Range(0, 255, "Subnet must range in 1 to 255")]
  14. public byte Subnet { get; set; }
  15. [Format(1, EncodingType.BIN, -9960)]
  16. [Range(0, 127, "Node must range in 1 to 127, but now is {0}")]
  17. public byte Node { get; set; }
  18. [Format(1, EncodingType.BIN, -9950)]
  19. public MessageCode MessageCode { get { return MessageCode.IFSF_MESSAGE_CODE_HEARTBEAT; } }
  20. [Format(1, EncodingType.BIN, -9940)]
  21. public byte MessageState { get; protected set; }
  22. public string IpAddress
  23. {
  24. set
  25. {
  26. IpAddressBytes = new List<byte>();
  27. foreach (string item in value.Split('.'))
  28. {
  29. IpAddressBytes.Add(byte.Parse(item));
  30. }
  31. }
  32. }
  33. public bool NeedConfig
  34. {
  35. set
  36. {
  37. //02 = 0000 0010
  38. if (value)
  39. MessageState = (byte)(MessageState | 0x02);
  40. }
  41. }
  42. public bool NeedUpdate
  43. {
  44. set
  45. {
  46. //80 = 1000 0000
  47. if (value)
  48. MessageState = (byte)(MessageState | 0x80);
  49. }
  50. }
  51. public override string ToString()
  52. {
  53. string ipAddress = string.Empty;
  54. foreach (byte ip in IpAddressBytes)
  55. { ipAddress += " " + ip.ToString(); }
  56. return $"{ipAddress} {Port} {Subnet} {Node}";
  57. }
  58. }
  59. }