终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

StatusMgr.cs 2.3 KiB

2 yıl önce
2 yıl önce
2 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using BPA.Message;
  2. using BPASmartClient.Helper;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace BPASmartClient.Business
  9. {
  10. /// <summary>
  11. /// 状态管理器
  12. /// </summary>
  13. public class StatusMgr : IPlugin
  14. {
  15. //运行标识
  16. private bool running = false;
  17. //设备管理
  18. private DeviceMgr deviceMgr;
  19. private MQTTMgr mqttMgr;
  20. DeviceStatus deviceStatus = new DeviceStatus();
  21. private bool wholeDeviceHealth;
  22. private Dictionary<int, Dictionary<string, object>> wholeDeviceStatus = new Dictionary<int, Dictionary<string, object>>();
  23. public void Initialize()
  24. {
  25. deviceMgr = Plugin.GetInstance().GetPlugin<DeviceMgr>();
  26. mqttMgr = Plugin.GetInstance().GetPlugin<MQTTMgr>();
  27. running = true;
  28. ThreadManage.GetInstance().Start(() =>
  29. {
  30. while (running)
  31. {
  32. wholeDeviceHealth = true;
  33. foreach (var device in deviceMgr.GetDevices())
  34. {
  35. wholeDeviceStatus[device.DeviceId] = device.Status.GetStatus();
  36. }
  37. Thread.Sleep(50);
  38. }
  39. }, "设备状态收集");
  40. deviceStatus.BatchingInfo = new List<BPA.Models.BatchingInfo>();
  41. ThreadManage.GetInstance().Start(() =>
  42. {
  43. while (running)
  44. {
  45. wholeDeviceHealth = true;
  46. foreach (var device in deviceMgr.GetDevices())
  47. {
  48. wholeDeviceStatus[device.DeviceId] = device.Status.GetStatus();
  49. deviceStatus.Healthy = device.IsHealth ? BPA.Message.Enum.DeviceHealthy.Health : BPA.Message.Enum.DeviceHealthy.UnHealth;
  50. var msg=BPAPackage.Make(deviceStatus, device.DeviceId, device.DeviceType);
  51. mqttMgr.Publish(TopicDefine.GetInstance().PushHeartbeatTopics[device.DeviceType], msg.Serialize());
  52. }
  53. Thread.Sleep(1000);
  54. }
  55. }, "设备心跳上报");
  56. }
  57. public void Dispose()
  58. {
  59. running = false;
  60. }
  61. }
  62. }