黄学彪
2020-11-19 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
@@ -33,6 +33,14 @@
        }
        /// <summary>
        /// 网关接收事件(参数1:主题 参数2:推送消息)
        /// </summary>
        private Action<string, string> GatewayReceiveEvent = null;
        /// <summary>
        /// 接收网关的id
        /// </summary>
        private string GatewayReceiveId = null;
        /// <summary>
        /// 设备推送事件集合
        /// </summary>
        private Dictionary<string, Action<CommonDevice>> dicDeviceEvent = new Dictionary<string, Action<CommonDevice>>();
@@ -54,6 +62,11 @@
        /// <param name="msgData">接收的数据</param>
        public void GatewayOverallMsgReceive(string gatewayId, string topic, string reportTopic, string msgData)
        {
            //如果它在登陆界面,则不做任何处理
            if (Common.Config.Instance.HomeId == string.Empty)
            {
                return;
            }
            if (topic == "AppNoLogin")
            {
                HdlThreadLogic.Current.RunMain(() =>
@@ -141,7 +154,11 @@
            {
                if (HdlGatewayLogic.Current.IsGatewayExist(gatewayId) == false)
                {
                    //不是自己绑定的网关,则不处理
                    //不是自己绑定的网关,则不处理,但是下面这个东西有点特殊
                    if (gatewayId == this.GatewayReceiveId)
                    {
                        this.GatewayReceiveEvent?.Invoke(topic, msgData);
                    }
                    return;
                }
                //设备属性上报
@@ -194,6 +211,11 @@
                else if (topic == gatewayId + "/Scene/Exec_Respon")
                {
                    this.SceneExecPush(null);
                }
                //网关接收事件
                else if (gatewayId == this.GatewayReceiveId)
                {
                    this.GatewayReceiveEvent?.Invoke(topic, msgData);
                }
            }
            catch (Exception ex)
@@ -288,7 +310,8 @@
                        {
                            if (attData.AttributeId == 0)
                            {
                                ((ColorTemperatureLight)locadevice).IsBuzzerRing = attData.AttriButeData == 1 ? true : false;
                                //这个是报警持续时间(大于2秒时,标记为还在响着)
                                ((ColorTemperatureLight)locadevice).IsBuzzerRing = attData.AttriButeData > 2 ? true : false;
                            }
                        }
                    }
@@ -464,6 +487,12 @@
                        }
                        //已经接收到状态
                        locadevice.HadReadDeviceStatu = true;
                        //if (locadevice is LightBase)
                        //{
                        //    //当接收到亮度值时,默认打开
                        //    ((LightBase)locadevice).OnOffStatus = 1;
                        //}
                    }
                }
                #endregion
@@ -535,7 +564,7 @@
                            //温度传感器
                            if (locadevice is TemperatureSensor)
                            {
                                ((TemperatureSensor)locadevice).Temperatrue = temperatrue;
                                ((TemperatureSensor)locadevice).currentTemperature = temperatrue;
                            }
                            //PM2.5传感器
                            else if (locadevice is PMSensor)
@@ -544,6 +573,8 @@
                            }
                            //已经接收到状态
                            locadevice.HadReadDeviceStatu = true;
                            //温度值需要保存
                            locadevice.ReSave();
                        }
                    }
                }
@@ -584,21 +615,23 @@
                            //湿度传感器
                            if (locadevice is TemperatureSensor)
                            {
                                ((TemperatureSensor)locadevice).Humidity = humidity;
                                ((TemperatureSensor)locadevice).currentHumidity = humidity;
                            }
                            //新风的湿度传感器
                            else if (locadevice is HumiditySensor)
                            {
                                ((HumiditySensor)locadevice).Humidity = humidity;
                                ((HumiditySensor)locadevice).currentHumidity = humidity;
                            }
                            //PM2.5传感器
                            else if (locadevice is PMSensor)
                            {
                                ((PMSensor)locadevice).currentHumidity = (int)humidity;
                            }
                            //已经接收到状态
                            locadevice.HadReadDeviceStatu = true;
                            //湿度值需要保存
                            locadevice.ReSave();
                        }
                        //已经接收到状态
                        locadevice.HadReadDeviceStatu = true;
                    }
                }
                #endregion
@@ -624,8 +657,135 @@
                }
                #endregion
            }
                #region ■ 设备基础信息
                else if (report.DeviceStatusReport.CluterID == 0)
                {
                    var listLocalDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr, false);
                    //属性都是一样的
                    foreach (var myDevice in listLocalDevice)
                    {
                        //属性是否改变
                        bool attriButeChanged = false;
                        foreach (var data in report.DeviceStatusReport.AttriBute)
                        {
                            //生产商名字
                            if (data.AttributeId == 4 && data.AttriButeDataHex.Length > 2)
                            {
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    if (myDevice.ManufacturerName != value)
                                    {
                                        //属性变更了
                                        attriButeChanged = true;
                                    }
                                    myDevice.ManufacturerName = value;
                                }
                            }
                            //型号码(也叫模块ID)
                            if (data.AttributeId == 5)
                            {
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    if (myDevice.ModelIdentifier != value)
                                    {
                                        //属性变更了
                                        attriButeChanged = true;
                                    }
                                    myDevice.ModelIdentifier = value;
                                }
                            }
                            //生产日期
                            if (data.AttributeId == 6)
                            {
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    if (myDevice.ProductionDate != value)
                                    {
                                        //属性变更了
                                        attriButeChanged = true;
                                    }
                                    myDevice.ProductionDate = value;
                                }
                            }
                            //电源
                            if (data.AttributeId == 7)
                            {
                                myDevice.PowerSource = data.AttriButeData;
                            }
                            //序列号
                            if (data.AttributeId == 13)
                            {
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    string value;
                                    if (Common.LocalDevice.Current.IsHdlDevice(myDevice) == false)
                                    {
                                        //第三方设备
                                        value = data.AttriButeDataHex.Substring(2);
                                    }
                                    else
                                    {
                                        //河东设备
                                        value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    }
                                    if (myDevice.SerialNumber != value)
                                    {
                                        //属性变更了
                                        attriButeChanged = true;
                                    }
                                    myDevice.SerialNumber = value;
                                }
                            }
                        }
                        //如果属性变更了
                        if (attriButeChanged == true && myDevice.IsCustomizeImage == false)
                        {
                            //UI重新生成
                            myDevice.IconPath = string.Empty;
                            myDevice.ReSave();
                        }
                    }
                }
                #endregion
            }
            else if (deviceEpoint == 200)
            {
                var localOta = Common.LocalDevice.Current.GetOTADevice(deviceAddr);
                if (localOta != null)
                {
                    #region ■ 固件版本
                    //固件版本
                    if (report.DeviceStatusReport.CluterID == (int)Cluster_ID.Ota)
                    {
                        foreach (var data in report.DeviceStatusReport.AttriBute)
                        {
                            //镜像版本
                            if (data.AttributeId == (int)AttriButeId.ImgVersion)
                            {
                                localOta.ImgVersion = data.AttriButeData;
                            }
                            //硬件版本
                            if (data.AttributeId == (int)AttriButeId.mgHWversion)
                            {
                                localOta.HwVersion = data.AttriButeData;
                            }
                            //镜像ID
                            if (data.AttributeId == (int)AttriButeId.ImgTypeId)
                            {
                                localOta.ImgTypeId = data.AttriButeData;
                            }
                        }
                        localOta.ReSave();
                    }
                    #endregion
                }
            }
            this.DeviceReportPush(report, ReceiveComandDiv.A设备属性上报);
        }
@@ -977,6 +1137,18 @@
            }
        }
        /// <summary>
        /// 添加网关接收事件(action只能存在一个,与AddAttributeEvent不共存,AddAttributeEvent优先)
        /// </summary>
        /// <param name="i_gatewayId">网关id</param>
        /// <param name="action">只能存在一个action (参数1:主题 参数2:推送消息)</param>
        public void AddGatewayReceiveEvent(string i_gatewayId, Action<string, string> action)
        {
            //添加事件
            this.GatewayReceiveEvent = action;
            this.GatewayReceiveId = i_gatewayId;
        }
        #endregion
        #region ■ 移除设备监听_______________________
@@ -1020,6 +1192,15 @@
            }
        }
        /// <summary>
        /// 移除网关接收事件(只能存在一个事件)
        /// </summary>
        public void RemoveGatewayReceiveEvent()
        {
            this.GatewayReceiveEvent = null;
            this.GatewayReceiveId = null;
        }
        #endregion
        #region ■ 一般方法___________________________