HeartBeatIn.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Edge.Core.Parser.BinaryParser.Attributes;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace PetroChinaOnlineWatchPlugin.MessageEntity.Incoming
  5. {
  6. public class HeartBeatIn : HeartBeatBase
  7. {
  8. [EnumerableFormat(4, -9990)]
  9. public List<byte> IpAddressBytes { get; 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; set; }
  20. [Format(1, EncodingType.BIN, -9940)]
  21. public byte MessageState { get; set; }
  22. public string IpAddress
  23. {
  24. get
  25. {
  26. return $"{IpAddressBytes[0]}.{IpAddressBytes[1]}.{IpAddressBytes[2]}.{IpAddressBytes[3]}";
  27. }
  28. }
  29. public bool NeedConfig
  30. {
  31. get
  32. {
  33. //02 = 0000 0010
  34. return (MessageState & 0x02) > 0;
  35. }
  36. }
  37. public bool NeedUpdate
  38. {
  39. get
  40. {
  41. //80 = 1000 0000
  42. return (MessageState & 0x80) > 0;
  43. }
  44. }
  45. public override string ToString()
  46. {
  47. string ipAddress = string.Empty;
  48. foreach (byte ip in IpAddressBytes)
  49. { ipAddress += " " + ip.ToString(); }
  50. return $"{IpAddress} {Port} {Subnet} {Node} {NeedConfig} {NeedUpdate}";
  51. }
  52. }
  53. }