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. using BPA.Models;
  13. namespace HBLConsole.Business
  14. {
  15. public class HeartbeatReport
  16. {
  17. private volatile static HeartbeatReport _Instance;
  18. public static HeartbeatReport GetInstance => _Instance ?? (_Instance = new HeartbeatReport());
  19. private HeartbeatReport() { }
  20. /// <summary>
  21. /// 消息包
  22. /// </summary>
  23. public BPAPackage MessagePackage { get; set; } = new BPAPackage();
  24. public Action GetMessage { get; set; }
  25. DeviceStatus deviceStatus = new DeviceStatus();
  26. string Topic = string.Empty;
  27. public void Init()
  28. {
  29. deviceStatus.DeviceType = GeneralConfig.DeviceType;
  30. Topic = TOPIC.GetInstance.GetHeatbeatTopic(GeneralConfig.DeviceType);
  31. ThreadManage.GetInstance.StartLong(new Action(() =>
  32. {
  33. deviceStatus.BatchingInfo = GeneralConfig.BatchingInfos;
  34. deviceStatus.Healthy = GeneralConfig.Healthy ? DeviceHealthy.Health : DeviceHealthy.UnHealth;
  35. if (GetMessage != null) GetMessage();
  36. MessagePackage.ClientId = InternetInfo.ClientId;
  37. MessagePackage.ClientType = GeneralConfig.DeviceType;
  38. MessagePackage.MessageId = MessageID.MORK_HEART_BEAT;
  39. MessagePackage.MessageVersion = 0x01;
  40. MessagePackage.Timestamp = DateTime.Now;
  41. MessagePackage.Message = deviceStatus;//GetMessage == null ? deviceStatus : GetMessage();
  42. MqttHelper.GetInstance.MqttPublishAsync(Topic, MessagePackage.Serialize());
  43. Thread.Sleep(1000);
  44. }), "设备心跳上报");
  45. }
  46. }
  47. }