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.
 
 

126 lines
5.8 KiB

  1. using BPA.Message.IOT;
  2. using HBLConsole.Communication;
  3. using HBLConsole.GVL;
  4. using HBLConsole.Interface;
  5. using HBLConsole.Service;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. namespace HBLConsole.Business
  14. {
  15. public class IotReport
  16. {
  17. private volatile static IotReport _Instance;
  18. public static IotReport GetInstance => _Instance ?? (_Instance = new IotReport());
  19. private IotReport()
  20. {
  21. iOTDevSXModel = new IOTDevSXModel();
  22. iOTDevSXModel.SBMC = InternetInfo.DeviceName;
  23. iOTDevSXModel.SBMS = InternetInfo.DeviceMS;
  24. iOTDevSXModel.SetKZSX(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "", SXLX = "" } } });
  25. IOTDev.GetInstance().Set(InternetInfo.ProductKey, InternetInfo.DeviceName, InternetInfo.DeviceSecret);
  26. iSLinks = IOTDev.GetInstance().CreateLinks();
  27. if (iSLinks) MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接成功.");
  28. else MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接失败.不能上报业务信息");
  29. string NameSpace = $"HBLConsole.{GeneralConfig.DeviceType}";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类
  30. Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{GeneralConfig.DeviceType}");
  31. control = Activator.CreateInstance(type) as IControl;
  32. }
  33. /// <summary>
  34. /// 是否连接成功
  35. /// </summary>
  36. public bool iSLinks = false;
  37. /// <summary>
  38. /// 大屏上报Model
  39. /// </summary>
  40. public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel();
  41. /// <summary>
  42. ///
  43. /// </summary>
  44. IControl control;
  45. public T GetTypeValue<T>(string str)
  46. {
  47. return (T)control.GetT().GetType().GetProperty(str).GetValue(control.GetT(), null);
  48. }
  49. public void SetData()
  50. {
  51. #region 上报
  52. //设置基本属性与状态
  53. iOTDevSXModel.SetJBSX(new DevSX
  54. {
  55. data = new List<DevSXBase>
  56. {
  57. new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected
  58. ,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."},
  59. new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true }
  60. }
  61. });
  62. bool IsAllowRun = GetTypeValue<bool>("AllowRun");
  63. bool TemperatureReached = GetTypeValue<bool>("TemperatureReached");
  64. bool MissingBowl = GetTypeValue<bool>("MissingBowl");
  65. bool TurntableLowerLimit = GetTypeValue<bool>("TurntableLowerLimit");
  66. //设置扩展属性与状态,连接上机器人后才会处罚
  67. if (IsAllowRun)
  68. {
  69. iOTDevSXModel.SetKZSX(new DevSX
  70. {
  71. data = new List<DevSXBase>
  72. {
  73. new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= TemperatureReached ,
  74. SXYCMS=TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."},
  75. new DevSXBase { SXMC="设备硬件",SXLX="取碗结构",SXStatus=MissingBowl ,
  76. SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺碗...."},
  77. new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=TurntableLowerLimit ,
  78. SXYCMS=TurntableLowerLimit?"":DateTime.Now+" 异常,转台缺面...."}
  79. }
  80. });
  81. }
  82. //设置告警消息
  83. List<DevSXBase> bases = Tools.JsonToObjectTools<DevSX>(iOTDevSXModel.JBSX)?.data?.ToList().FindAll(par => par.SXStatus == false);
  84. if (bases != null) bases.AddRange(Tools.JsonToObjectTools<DevSX>(iOTDevSXModel.KZSX)?.data?.ToList().FindAll(par => par.SXStatus == false));
  85. List<AlarmModel> alarms = new List<AlarmModel>();
  86. bases?.ForEach(par => alarms.Add(new AlarmModel { DeviceMC = iOTDevSXModel.SBMC, DeviceSJ = DateTime.Now.ToString(), AlarmCD = "一般", DeviceZT = "未处理", DeviceMS = par.SXYCMS }));
  87. iOTDevSXModel.SetGJXX(new AlarmMessage { data = alarms });
  88. bool InitComplete = GetTypeValue<bool>("InitComplete");
  89. bool RobotTakeNoodle = GetTypeValue<bool>("RobotTakeNoodle");
  90. bool RobotOutMeal = GetTypeValue<bool>("RobotOutMeal");
  91. iOTDevSXModel.SetLCSB(new ProcessMessage
  92. {
  93. data = new List<ProcessModel>
  94. {
  95. new ProcessModel { ProcessName="开机",IsMark=!IsAllowRun },
  96. new ProcessModel { ProcessName="初始化",IsMark=!InitComplete },
  97. new ProcessModel { ProcessName="取面",IsMark=RobotTakeNoodle,ProcessMS=RobotTakeNoodle?"机器人正在取面过程中....":""},
  98. new ProcessModel { ProcessName="出餐",IsMark=RobotOutMeal,ProcessMS=RobotOutMeal?"机器人正在出餐过程中....":"" }
  99. }
  100. });
  101. #endregion
  102. }
  103. public void Init()
  104. {
  105. ThreadOperate.GetInstance.StartLong(new Action(() =>
  106. {
  107. if (iSLinks && GeneralConfig.DeviceType.ToString() == "MORKS")
  108. {
  109. SetData();
  110. IOTDev.GetInstance().IOT_Publish(IOTDev.PubTopic, iOTDevSXModel.Tojson());
  111. }
  112. Thread.Sleep(5000);
  113. }), "设备IOT上报云端");
  114. }
  115. }
  116. }