@@ -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<DevSXBase> {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; | |||
} | |||
/// <summary> | |||
/// 是否连接成功 | |||
/// </summary> | |||
public bool iSLinks = false; | |||
/// <summary> | |||
/// 大屏上报Model | |||
/// </summary> | |||
public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel(); | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
IControl control; | |||
public T GetTypeValue<T>(string str) | |||
{ | |||
return (T)control.GetT().GetType().GetProperty(str).GetValue(control.GetT(),null); | |||
} | |||
public void SetData() | |||
{ | |||
#region 上报 | |||
//设置基本属性与状态 | |||
iOTDevSXModel.SetJBSX(new DevSX | |||
{ | |||
data = new List<DevSXBase> | |||
{ | |||
new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected | |||
,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."}, | |||
new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true } | |||
} | |||
}); | |||
bool IsAllowRun = GetTypeValue<bool>("AllowRun"); | |||
bool TemperatureReached = GetTypeValue<bool>("TemperatureReached"); | |||
bool MissingBowl = GetTypeValue<bool>("MissingBowl"); | |||
bool TurntableLowerLimit = GetTypeValue<bool>("TurntableLowerLimit"); | |||
//设置扩展属性与状态,连接上机器人后才会处罚 | |||
if (IsAllowRun) | |||
{ | |||
iOTDevSXModel.SetKZSX(new DevSX | |||
{ | |||
data = new List<DevSXBase> | |||
{ | |||
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<DevSXBase> bases = Tools.JsonToObjectTools<DevSX>(iOTDevSXModel.JBSX)?.data?.ToList().FindAll(par => par.SXStatus == false); | |||
if (bases != null) bases.AddRange(Tools.JsonToObjectTools<DevSX>(iOTDevSXModel.KZSX)?.data?.ToList().FindAll(par => par.SXStatus == false)); | |||
List<AlarmModel> alarms=new List<AlarmModel>(); | |||
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<bool>("InitComplete"); | |||
bool RobotTakeNoodle = GetTypeValue<bool>("RobotTakeNoodle"); | |||
bool RobotOutMeal = GetTypeValue<bool>("RobotOutMeal"); | |||
iOTDevSXModel.SetLCSB(new ProcessMessage | |||
{ | |||
data = new List<ProcessModel> | |||
{ | |||
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上报云端"); | |||
} | |||
} | |||
} |
@@ -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设备地址 | |||
/// <summary> | |||
/// IOT ProductKey | |||
/// </summary> | |||
public static string ProductKey { get; set; } | |||
/// <summary> | |||
/// IOT DeviceName | |||
/// </summary> | |||
public static string DeviceName { get; set; } | |||
/// <summary> | |||
/// IOT DeviceSecret | |||
/// </summary> | |||
public static string DeviceSecret { get; set; } | |||
/// <summary> | |||
/// IOT DeviceMS | |||
/// </summary> | |||
public static string DeviceMS { get; set; } | |||
#endregion | |||
} | |||
} |
@@ -9,6 +9,7 @@ namespace HBLConsole.Interface | |||
public interface IControl | |||
{ | |||
void Main(); | |||
object GetT(); | |||
void Init(); | |||
void ReadData(); | |||
void SimOrder<T>(T simOrder); | |||
@@ -20,6 +20,11 @@ namespace HBLConsole.MORKD | |||
ReadData(); | |||
} | |||
public object GetT() | |||
{ | |||
return mORKD; | |||
} | |||
public void DataParse<T>(T order) | |||
{ | |||
if (order is MorkOrderPush morkOrderPush) | |||
@@ -45,7 +45,10 @@ namespace HBLConsole.MORKIC | |||
Main(); | |||
ReadData(); | |||
} | |||
public object GetT() | |||
{ | |||
return mORKD; | |||
} | |||
public void Init() | |||
{ | |||
//构建所有商品物料信息 | |||
@@ -18,13 +18,13 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Message"> | |||
<HintPath>..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
<HintPath>..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
</Reference> | |||
<Reference Include="BPA.Models"> | |||
<HintPath>..\..\..\BPACommon_output\net5.0\BPA.Models.dll</HintPath> | |||
<HintPath>..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Models.dll</HintPath> | |||
</Reference> | |||
<Reference Include="BPA.Utility"> | |||
<HintPath>..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
<HintPath>..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -26,6 +26,11 @@ namespace HBLConsole.MORKS | |||
ActionOperate.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand"); | |||
} | |||
public object GetT() | |||
{ | |||
return mORKS; | |||
} | |||
public void ConnectOk() | |||
{ | |||
//WriteRecipeBoms(); | |||
@@ -62,6 +62,8 @@ namespace HBLConsole.MainConsole | |||
MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 | |||
IotReport.GetInstance.Init();//IOT 上报 | |||
HeartbeatReport.GetInstance.Init();//心跳上报 | |||
ServerData.GetInstance.Init();//数据处理初始化 | |||
@@ -1,23 +1,29 @@ | |||
<?xml version="1.0" encoding="utf-8" ?> | |||
<configuration> | |||
<appSettings> | |||
<!--通用配置--> | |||
<appSettings> | |||
<!--通用配置--> | |||
<!--测试服务 Consul 地址--> | |||
<add key="ConsulAddress" value="http://114.117.161.250:9011" /> | |||
<!--测试服务 Consul 地址--> | |||
<add key="ConsulAddress" value="http://114.117.161.250:9011" /> | |||
<!--正式服务 Consul 地址--> | |||
<!--<add key="ConsulAddress" value="http://162.14.105.138:9005" />--> | |||
<!--正式服务 Consul 地址--> | |||
<!--<add key="ConsulAddress" value="http://162.14.105.138:9005" />--> | |||
<!--客户端ID--> | |||
<!--MorkD = 2,MorkS 且时且多 = 8,MorkS 珠海 = 9,冰淇淋 = 4,咖啡机 = 13--> | |||
<add key="ClientId" value="2"/> | |||
<!--客户端ID--> | |||
<!--MorkD = 2,MorkS 且时且多 = 8,MorkS 珠海 = 9,冰淇淋 = 4,咖啡机 = 13--> | |||
<add key="ClientId" value="2"/> | |||
<!--IOT大屏上报--> | |||
<add key="ProductKey" value="grgpECHSL7q"/> | |||
<add key="DeviceName" value="qsqd_zmj"/> | |||
<add key="DeviceSecret" value="4f603aa0645571eaa1558ade85f8a90e"/> | |||
<add key="DeviceMS" value="成都银泰且时且多"/> | |||
<add key="COM_Coffee" value=""/> | |||
<add key="BAUD_Coffee" value="115200"/> | |||
<add key="COM_IceCream" value=""/> | |||
<add key="BAUD_IceCream" value="9600"/> | |||
<add key="IceCream_CXB_Threshold" value="90"/> | |||
<add key="COM_Coffee" value=""/> | |||
<add key="BAUD_Coffee" value="115200"/> | |||
<add key="COM_IceCream" value=""/> | |||
<add key="BAUD_IceCream" value="9600"/> | |||
<add key="IceCream_CXB_Threshold" value="90"/> | |||
</appSettings> | |||
</appSettings> | |||
</configuration> |
@@ -10,7 +10,7 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Utility"> | |||
<HintPath>..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
<HintPath>..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -10,7 +10,7 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Utility"> | |||
<HintPath>..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
<HintPath>..\..\..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||