终端一体化运控平台
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.
 
 
 

70 lines
2.3 KiB

  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. }