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.

HeartbeatReport.cs 2.0 KiB

2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.deviceId;
  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. IotReport.GetInstance.SendTargetMessage();
  44. Thread.Sleep(1000);
  45. }), "设备心跳上报", true);
  46. }
  47. }
  48. }