From 1243ea39dc784fbfba8c76849b5cb05a03afb3ce Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Thu, 17 Mar 2022 17:25:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=86=B2=E7=AA=81=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0IOT=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Business/IotReport.cs | 125 +++++++++++++++++++ HBLConsole.GVL/InternetInfo.cs | 24 +++- HBLConsole.Interface/IControl.cs | 1 + HBLConsole.MORKD/Control_MORKD.cs | 5 + HBLConsole.MORKIC/Control_MORKIC.cs | 5 +- HBLConsole.MORKIC/HBLConsole.MORKIC.csproj | 6 +- HBLConsole.MORKS/Control_MORKS.cs | 5 + HBLConsole.MainConsole/Main.cs | 2 + HBLConsole/App.config | 36 +++--- HBLDevice.Coffee/HBLDevice.Coffee.csproj | 2 +- HBLDevice.IceCream/HBLDevice.IceCream.csproj | 2 +- 11 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 HBLConsole.Business/IotReport.cs diff --git a/HBLConsole.Business/IotReport.cs b/HBLConsole.Business/IotReport.cs new file mode 100644 index 0000000..4b02d53 --- /dev/null +++ b/HBLConsole.Business/IotReport.cs @@ -0,0 +1,125 @@ +using BPA.Message.IOT; +using HBLConsole.Communication; +using HBLConsole.GVL; +using HBLConsole.Interface; +using HBLConsole.Service; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace HBLConsole.Business +{ + public class IotReport + { + private volatile static IotReport _Instance; + public static IotReport GetInstance => _Instance ?? (_Instance = new IotReport()); + private IotReport() + { + iOTDevSXModel = new IOTDevSXModel(); + iOTDevSXModel.SBMC = InternetInfo.DeviceName; + iOTDevSXModel.SBMS = InternetInfo.DeviceMS; + iOTDevSXModel.SetKZSX(new DevSX { data = new List {new DevSXBase { SXMC="",SXLX=""} }}); + IOTDev.GetInstance().Set(InternetInfo.ProductKey,InternetInfo.DeviceName,InternetInfo.DeviceSecret); + iSLinks = IOTDev.GetInstance().CreateLinks(); + if (iSLinks) MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接成功."); + else MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接失败.不能上报业务信息"); + string NameSpace = $"HBLConsole.{GeneralConfig.DeviceType}";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类 + Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{GeneralConfig.DeviceType}"); + control = Activator.CreateInstance(type) as IControl; + } + /// + /// 是否连接成功 + /// + public bool iSLinks = false; + /// + /// 大屏上报Model + /// + public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel(); + /// + /// + /// + IControl control; + + public T GetTypeValue(string str) + { + return (T)control.GetT().GetType().GetProperty(str).GetValue(control.GetT(),null); + } + + 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 } + } + }); + bool IsAllowRun = GetTypeValue("AllowRun"); + bool TemperatureReached = GetTypeValue("TemperatureReached"); + bool MissingBowl = GetTypeValue("MissingBowl"); + bool TurntableLowerLimit = GetTypeValue("TurntableLowerLimit"); + + //设置扩展属性与状态,连接上机器人后才会处罚 + 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=TurntableLowerLimit , + SXYCMS=TurntableLowerLimit?"":DateTime.Now+" 异常,转台缺面...."} + } + }); + } + + //设置告警消息 + List bases = Tools.JsonToObjectTools(iOTDevSXModel.JBSX)?.data?.ToList().FindAll(par => par.SXStatus == false); + if (bases != null) bases.AddRange(Tools.JsonToObjectTools(iOTDevSXModel.KZSX)?.data?.ToList().FindAll(par => par.SXStatus == false)); + List alarms=new List(); + bases?.ForEach(par => alarms.Add(new AlarmModel { DeviceMC = iOTDevSXModel.SBMC,DeviceSJ = DateTime.Now.ToString(),AlarmCD = "一般",DeviceZT = "未处理",DeviceMS = par.SXYCMS })); + iOTDevSXModel.SetGJXX(new AlarmMessage { data = alarms }); + + bool InitComplete = GetTypeValue("InitComplete"); + bool RobotTakeNoodle = GetTypeValue("RobotTakeNoodle"); + bool RobotOutMeal = GetTypeValue("RobotOutMeal"); + iOTDevSXModel.SetLCSB(new ProcessMessage + { + data = new List + { + new ProcessModel { ProcessName="开机",IsMark=!IsAllowRun }, + new ProcessModel { ProcessName="初始化",IsMark=!InitComplete }, + new ProcessModel { ProcessName="取面",IsMark=RobotTakeNoodle,ProcessMS=RobotTakeNoodle?"机器人正在取面过程中....":""}, + new ProcessModel { ProcessName="出餐",IsMark=RobotOutMeal,ProcessMS=RobotOutMeal?"机器人正在出餐过程中....":"" } + } + }); + #endregion + + } + + public void Init() + { + ThreadOperate.GetInstance.StartLong(new Action(() => + { + if (iSLinks && GeneralConfig.DeviceType.ToString()== "MORKS") + { + SetData(); + IOTDev.GetInstance().IOT_Publish(IOTDev.PubTopic,iOTDevSXModel.Tojson()); + } + Thread.Sleep(5000); + }),"设备IOT上报云端"); + + } + } +} diff --git a/HBLConsole.GVL/InternetInfo.cs b/HBLConsole.GVL/InternetInfo.cs index c147a04..7643ee7 100644 --- a/HBLConsole.GVL/InternetInfo.cs +++ b/HBLConsole.GVL/InternetInfo.cs @@ -36,7 +36,10 @@ namespace HBLConsole.GVL ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"]; ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]); - + ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"]; + DeviceName = System.Configuration.ConfigurationManager.AppSettings["DeviceName"]; + DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"]; + DeviceMS= System.Configuration.ConfigurationManager.AppSettings["DeviceMS"]; while (StockServer == null) { try @@ -121,5 +124,24 @@ namespace HBLConsole.GVL public static string StockServer { get; set; } #endregion + #region IOT设备地址 + /// + /// IOT ProductKey + /// + public static string ProductKey { get; set; } + /// + /// IOT DeviceName + /// + public static string DeviceName { get; set; } + /// + /// IOT DeviceSecret + /// + public static string DeviceSecret { get; set; } + /// + /// IOT DeviceMS + /// + public static string DeviceMS { get; set; } + #endregion + } } diff --git a/HBLConsole.Interface/IControl.cs b/HBLConsole.Interface/IControl.cs index 7434810..d5533e9 100644 --- a/HBLConsole.Interface/IControl.cs +++ b/HBLConsole.Interface/IControl.cs @@ -9,6 +9,7 @@ namespace HBLConsole.Interface public interface IControl { void Main(); + object GetT(); void Init(); void ReadData(); void SimOrder(T simOrder); diff --git a/HBLConsole.MORKD/Control_MORKD.cs b/HBLConsole.MORKD/Control_MORKD.cs index af891d8..01d3b47 100644 --- a/HBLConsole.MORKD/Control_MORKD.cs +++ b/HBLConsole.MORKD/Control_MORKD.cs @@ -20,6 +20,11 @@ namespace HBLConsole.MORKD ReadData(); } + public object GetT() + { + return mORKD; + } + public void DataParse(T order) { if (order is MorkOrderPush morkOrderPush) diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index c929b5a..43ee157 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -45,7 +45,10 @@ namespace HBLConsole.MORKIC Main(); ReadData(); } - + public object GetT() + { + return mORKD; + } public void Init() { //构建所有商品物料信息 diff --git a/HBLConsole.MORKIC/HBLConsole.MORKIC.csproj b/HBLConsole.MORKIC/HBLConsole.MORKIC.csproj index 3f307e9..633a91a 100644 --- a/HBLConsole.MORKIC/HBLConsole.MORKIC.csproj +++ b/HBLConsole.MORKIC/HBLConsole.MORKIC.csproj @@ -18,13 +18,13 @@ - ..\..\..\BPACommon_output\net5.0\BPA.Message.dll + ..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll - ..\..\..\BPACommon_output\net5.0\BPA.Models.dll + ..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Models.dll - ..\..\..\BPACommon_output\net5.0\BPA.Utility.dll + ..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll diff --git a/HBLConsole.MORKS/Control_MORKS.cs b/HBLConsole.MORKS/Control_MORKS.cs index 20b54c4..f2c500b 100644 --- a/HBLConsole.MORKS/Control_MORKS.cs +++ b/HBLConsole.MORKS/Control_MORKS.cs @@ -26,6 +26,11 @@ namespace HBLConsole.MORKS ActionOperate.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand"); } + public object GetT() + { + return mORKS; + } + public void ConnectOk() { //WriteRecipeBoms(); diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index c9ae0b7..5b6bad2 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -62,6 +62,8 @@ namespace HBLConsole.MainConsole MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 + IotReport.GetInstance.Init();//IOT 上报 + HeartbeatReport.GetInstance.Init();//心跳上报 ServerData.GetInstance.Init();//数据处理初始化 diff --git a/HBLConsole/App.config b/HBLConsole/App.config index 713cf52..f348a93 100644 --- a/HBLConsole/App.config +++ b/HBLConsole/App.config @@ -1,23 +1,29 @@  - - + + - - + + - - + + - - - + + + + + + + + - - - - - + + + + + + - + \ No newline at end of file diff --git a/HBLDevice.Coffee/HBLDevice.Coffee.csproj b/HBLDevice.Coffee/HBLDevice.Coffee.csproj index d0fb844..af0da4a 100644 --- a/HBLDevice.Coffee/HBLDevice.Coffee.csproj +++ b/HBLDevice.Coffee/HBLDevice.Coffee.csproj @@ -10,7 +10,7 @@ - ..\..\..\BPACommon_output\net5.0\BPA.Utility.dll + ..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll diff --git a/HBLDevice.IceCream/HBLDevice.IceCream.csproj b/HBLDevice.IceCream/HBLDevice.IceCream.csproj index d0fb844..af0da4a 100644 --- a/HBLDevice.IceCream/HBLDevice.IceCream.csproj +++ b/HBLDevice.IceCream/HBLDevice.IceCream.csproj @@ -10,7 +10,7 @@ - ..\..\..\BPACommon_output\net5.0\BPA.Utility.dll + ..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll