终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

77 rader
2.4 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. }
  28. public void Start()
  29. {
  30. running = true;
  31. ThreadManage.GetInstance().Start(() =>
  32. {
  33. while (running)
  34. {
  35. wholeDeviceHealth = true;
  36. foreach (var device in deviceMgr.GetDevices())
  37. {
  38. wholeDeviceStatus[device.DeviceId] = device.Status.GetStatus();
  39. }
  40. Thread.Sleep(50);
  41. }
  42. }, "设备状态收集", true);
  43. deviceStatus.BatchingInfo = new List<BPA.Models.BatchingInfo>();
  44. ThreadManage.GetInstance().Start(() =>
  45. {
  46. while (running)
  47. {
  48. wholeDeviceHealth = true;
  49. foreach (var device in deviceMgr.GetDevices())
  50. {
  51. wholeDeviceStatus[device.DeviceId] = device.Status.GetStatus();
  52. deviceStatus.Healthy = device.IsHealth ? BPA.Message.Enum.DeviceHealthy.Health : BPA.Message.Enum.DeviceHealthy.UnHealth;
  53. deviceStatus.DeviceType = device.DeviceType;
  54. var msg = BPAPackage.Make(deviceStatus, device.DeviceId, device.DeviceType);
  55. mqttMgr.Publish(TopicDefine.GetInstance().PushHeartbeatTopics[device.DeviceType], msg.Serialize());
  56. }
  57. Thread.Sleep(1000);
  58. }
  59. }, "设备心跳上报", true);
  60. }
  61. public void Dispose()
  62. {
  63. running = false;
  64. }
  65. }
  66. }