You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

55 lines
1.9 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7. using HBLConsole.Service;
  8. using HBLConsole.GVL;
  9. using BPA.Message;
  10. using HBLConsole.Communication;
  11. using BPA.Message.Enum;
  12. namespace HBLConsole.Business
  13. {
  14. public class HeartbeatReport
  15. {
  16. private volatile static HeartbeatReport _Instance;
  17. public static HeartbeatReport GetInstance => _Instance ?? (_Instance = new HeartbeatReport());
  18. private HeartbeatReport() { }
  19. /// <summary>
  20. /// 消息包
  21. /// </summary>
  22. public BPAPackage MessagePackage { get; set; } = new BPAPackage();
  23. public Action GetMessage { get; set; }
  24. public DeviceStatus deviceStatus = new DeviceStatus();
  25. string Topic = string.Empty;
  26. public void Init()
  27. {
  28. deviceStatus.DeviceType = GeneralConfig.GetInstance.DeviceType;
  29. deviceStatus.BatchingInfo = new List<BatchingInfo>();
  30. deviceStatus.Healthy = DeviceHealthy.UnHealth;
  31. Topic = TOPIC.GetInstance.GetHeatbeatTopic(GeneralConfig.GetInstance.DeviceType);
  32. ThreadManagerment.GetInstance.StartLong(new Action(() =>
  33. {
  34. if (GetMessage != null) GetMessage();
  35. MessagePackage.ClientId = InternetInfo.GetInstance.ClientId;
  36. MessagePackage.ClientType = GeneralConfig.GetInstance.DeviceType;
  37. MessagePackage.MessageId = MessageID.MORK_HEART_BEAT;
  38. MessagePackage.MessageVersion = 0x01;
  39. MessagePackage.Timestamp = DateTime.Now;
  40. MessagePackage.Message = deviceStatus;//GetMessage == null ? deviceStatus : GetMessage();
  41. MqttHelper.GetInstance.MqttPublishAsync(Topic, MessagePackage.Serialize());
  42. Thread.Sleep(1000);
  43. }), "设备心跳上报");
  44. }
  45. }
  46. }