From cbc79d432e501f8d5fea4509b9ddc5e9c64247f4 Mon Sep 17 00:00:00 2001
From: fyf <11621@LAPTOP-04QQU0AO>
Date: Wed, 6 Apr 2022 15:06:15 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
HBLConsole.Business/HeartbeatReport.cs | 1 +
HBLConsole.Business/IotReport.cs | 124 +++++++++++++------------
HBLConsole.MainConsole/Main.cs | 2 +-
3 files changed, 68 insertions(+), 59 deletions(-)
diff --git a/HBLConsole.Business/HeartbeatReport.cs b/HBLConsole.Business/HeartbeatReport.cs
index 518e5c1..808bfa5 100644
--- a/HBLConsole.Business/HeartbeatReport.cs
+++ b/HBLConsole.Business/HeartbeatReport.cs
@@ -46,6 +46,7 @@ namespace HBLConsole.Business
MessagePackage.Timestamp = DateTime.Now;
MessagePackage.Message = deviceStatus;//GetMessage == null ? deviceStatus : GetMessage();
MqttHelper.GetInstance.MqttPublishAsync(Topic, MessagePackage.Serialize());
+ IotReport.GetInstance.SendTargetMessage();
Thread.Sleep(1000);
}), "设备心跳上报");
diff --git a/HBLConsole.Business/IotReport.cs b/HBLConsole.Business/IotReport.cs
index d41805c..e41423b 100644
--- a/HBLConsole.Business/IotReport.cs
+++ b/HBLConsole.Business/IotReport.cs
@@ -77,6 +77,58 @@ namespace HBLConsole.Business
IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr);
}
}
+
+ ///
+ /// 上报属性状态
+ /// 调用示例:SendTargetMessage();
+ ///
+ ///
+ public void SendTargetMessage()
+ {
+ if (IOTDevServer.client != null && IOTDevServer.client.IsConnected)
+ {
+ string kzsx = string.Empty;
+ string jbsx = Tools.JsonConvertTools(new DevSX
+ {
+ data = new List
+ {
+ new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected
+ ,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."},
+ new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true }
+ }
+ });
+ bool IsAllowRun = GetTypeValue("AllowRun");
+ bool TemperatureReached = GetTypeValue("TemperatureReached");
+ bool MissingBowl = GetTypeValue("MissingBowl");
+ bool MissingBowlSignal2 = GetTypeValue("MissingBowlSignal2");
+ bool IsNoodles = GetTypeValue("IsNoodles");//转台
+ bool AllowFallNoodle = GetTypeValue("AllowFallNoodle");//是否允许到面
+ bool[] CookNoodlesComplete = GetTypeValue("CookNoodlesComplete");//煮面完成上升信号
+ bool isCookNoodles = CookNoodlesComplete.ToList().Find(o => o);
+ //设置扩展属性与状态,连接上机器人后才会处罚
+ if (IsAllowRun)
+ {
+ kzsx = Tools.JsonConvertTools(new DevSX
+ {
+ data = new List
+ {
+ new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= !TemperatureReached ,
+ SXYCMS=!TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."},
+ new DevSXBase { SXMC="设备硬件",SXLX="装小碗结构",SXStatus=MissingBowl ,
+ SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺小碗...."},
+ new DevSXBase { SXMC="设备硬件",SXLX="装大碗结构",SXStatus=MissingBowlSignal2 ,
+ SXYCMS=MissingBowlSignal2?"":DateTime.Now+" 异常,缺大碗...."},
+ new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=IsNoodles ,
+ SXYCMS=IsNoodles?"":DateTime.Now+" 异常,转台位置缺少物料...."},
+ new DevSXBase { SXMC="设备硬件",SXLX="配料机",SXStatus=!(!AllowFallNoodle && isCookNoodles) ,
+ SXYCMS=!((!AllowFallNoodle && isCookNoodles))?"":DateTime.Now+" 异常,配料机未配完料,疑似碗未到配料机下方或者配料机未工作...."}
+ }
+ });
+ }
+ string jsonstr = Tools.JsonConvertTools>(new IotModel { @params = new TargetIOT { JBSX = jbsx,KZSX = kzsx } });
+ IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr);
+ }
+ }
#endregion
#region 外部关闭或初始化IOT调用
@@ -125,64 +177,6 @@ namespace HBLConsole.Business
}
#endregion
- #region 废弃代码
- ///
- /// 设置上报基本与扩展数据
- ///
- public void SetData()
- {
- #region 基本数据
- //设置基本属性与状态
- iOTDevSXModel.SetJBSX(new DevSX
- {
- data = new List
- {
- new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected
- ,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."},
- new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true }
- }
- });
- #endregion
-
- #region 扩展数据
- bool IsAllowRun = GetTypeValue("AllowRun");
- bool TemperatureReached = GetTypeValue("TemperatureReached");
- bool MissingBowl = GetTypeValue("MissingBowl");
- bool MissingBowlSignal2 = GetTypeValue("MissingBowlSignal2");
- bool IsNoodles = GetTypeValue("IsNoodles");//转台
- bool AllowFallNoodle = GetTypeValue("AllowFallNoodle");//是否允许到面
- bool[] CookNoodlesComplete = GetTypeValue("CookNoodlesComplete");//煮面完成上升信号
- bool isCookNoodles = CookNoodlesComplete.ToList().Find(o => o);
- //设置扩展属性与状态,连接上机器人后才会处罚
- if (IsAllowRun)
- {
- iOTDevSXModel.SetKZSX(new DevSX
- {
- data = new List
- {
- new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= !TemperatureReached ,
- SXYCMS=!TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."},
- new DevSXBase { SXMC="设备硬件",SXLX="装小碗结构",SXStatus=MissingBowl ,
- SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺小碗...."},
- new DevSXBase { SXMC="设备硬件",SXLX="装大碗结构",SXStatus=MissingBowlSignal2 ,
- SXYCMS=MissingBowlSignal2?"":DateTime.Now+" 异常,缺大碗...."},
- new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=IsNoodles ,
- SXYCMS=IsNoodles?"":DateTime.Now+" 异常,转台位置缺少物料...."},
- new DevSXBase { SXMC="设备硬件",SXLX="配料机",SXStatus=!(!AllowFallNoodle && isCookNoodles) ,
- SXYCMS=!((!AllowFallNoodle && isCookNoodles))?"":DateTime.Now+" 异常,配料机未配完料,疑似碗未到配料机下方或者配料机未工作...."}
- }
- });
- }
- else
- {
- iOTDevSXModel.SetKZSX(new DevSX { data = new List { new DevSXBase { SXMC = "",SXLX = "" } } });
- }
- #endregion
-
- IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,iOTDevSXModel.Tojson());
- }
- #endregion
-
#region 私有函数
///
/// 获取属性状态
@@ -215,4 +209,18 @@ namespace HBLConsole.Business
{
public string NodeStatus { get; set; }
}
+ ///
+ /// 基本属性与扩展属性
+ ///
+ public class TargetIOT
+ {
+ ///
+ /// 基本属性
+ ///
+ public string JBSX { get; set; }
+ ///
+ /// 扩展属性
+ ///
+ public string KZSX { get; set; }
+ }
}
diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs
index 5bc3549..210b944 100644
--- a/HBLConsole.MainConsole/Main.cs
+++ b/HBLConsole.MainConsole/Main.cs
@@ -54,7 +54,7 @@ namespace HBLConsole.MainConsole
ThreadManage.GetInstance.Start(new Action(() =>
{
InternetInfo.ConfigInit();//从 consul 获取配置数据
- //IotReport.GetInstance.Initialize();
+ IotReport.GetInstance.Initialize();
Topics.Clear();
Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));