using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using HBLConsole.Service; using HBLConsole.GVL; using BPA.Message; using HBLConsole.Communication; using BPA.Message.Enum; namespace HBLConsole.Business { public class HeartbeatReport { private volatile static HeartbeatReport _Instance; public static HeartbeatReport GetInstance => _Instance ?? (_Instance = new HeartbeatReport()); private HeartbeatReport() { } /// /// 消息包 /// public BPAPackage MessagePackage { get; set; } = new BPAPackage(); public Action GetMessage { get; set; } public DeviceStatus deviceStatus = new DeviceStatus(); string Topic = string.Empty; public void Init() { deviceStatus.DeviceType = GeneralConfig.GetInstance.DeviceType; deviceStatus.BatchingInfo = new List(); deviceStatus.Healthy = DeviceHealthy.UnHealth; Topic = TOPIC.GetInstance.GetHeatbeatTopic(GeneralConfig.GetInstance.DeviceType); ThreadManagerment.GetInstance.StartLong(new Action(() => { if (GetMessage != null) GetMessage(); MessagePackage.ClientId = InternetInfo.GetInstance.ClientId; MessagePackage.ClientType = GeneralConfig.GetInstance.DeviceType; MessagePackage.MessageId = MessageID.MORK_HEART_BEAT; MessagePackage.MessageVersion = 0x01; MessagePackage.Timestamp = DateTime.Now; MessagePackage.Message = deviceStatus;//GetMessage == null ? deviceStatus : GetMessage(); MqttHelper.GetInstance.MqttPublishAsync(Topic, MessagePackage.Serialize()); Thread.Sleep(1000); }), "设备心跳上报"); } } }