陈嘉乐
2020-05-28 f759dc1e6f49c53733eafda82207c85af18f9931
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
@@ -274,7 +274,7 @@
                }
                #endregion
                #region ■ 空调数据
                #region ■ 空调和新风数据
                //空调数据
                else if (report.DeviceStatusReport.CluterID == 513)
                {
@@ -343,29 +343,59 @@
                    locadevice.DeviceStatusReport = report.DeviceStatusReport;
                    foreach (var attData in report.DeviceStatusReport.AttriBute)
                    {
                        if (attData.AttributeId == 0)
                        //区分是空调还是新风
                        var device = Shared.Common.LocalDevice.Current.GetDevice(report.DeviceAddr, report.DeviceEpoint);
                        if (device.Type == DeviceType.FreshAir)
                        {
                            //风扇模式
                            ((AC)locadevice).currentFanMode = attData.AttriButeData;
                            //已经接收到状态
                            locadevice.HadReadDeviceStatu = true;
                            if (attData.AttributeId == 0)
                            {
                                switch (attData.AttriButeData)
                                {
                                    case 0:
                                    case 4:
                                        ((FreshAir)locadevice).currentFanStatus = attData.AttriButeData;
                                        break;
                                    case 1:
                                    case 2:
                                    case 3:
                                        ((FreshAir)locadevice).currentFanSpeed = attData.AttriButeData;
                                        break;
                                    case 5:
                                    case 15:
                                        ((FreshAir)locadevice).currentFanMode = attData.AttriButeData;
                                        break;
                                }
                                //已经接收到状态
                                locadevice.HadReadDeviceStatu = true;
                            }
                        }
                        else if (attData.AttributeId == 4096)
                        else
                        {
                            //风扇扫风
                            ((AC)locadevice).currentFanSwingMode = attData.AttriButeData;
                            //已经接收到状态
                            locadevice.HadReadDeviceStatu = true;
                        }
                        else if (attData.AttributeId == 4097)
                        {
                            //转换为二进制
                            var value = Convert.ToString(attData.AttriButeData, 2).PadLeft(16, '0');
                            //这个设置是放在后面的
                            value = value.Substring(value.Length - 1, 1);
                            //启用摆风功能
                            ((AC)locadevice).UseSwingFunction = value == "1";
                            locadevice.ReSave();
                            if (attData.AttributeId == 0)
                            {
                                //风扇模式
                                ((AC)locadevice).currentFanMode = attData.AttriButeData;
                                //已经接收到状态
                                locadevice.HadReadDeviceStatu = true;
                            }
                            else if (attData.AttributeId == 4096)
                            {
                                //风扇扫风
                                ((AC)locadevice).currentFanSwingMode = attData.AttriButeData;
                                //已经接收到状态
                                locadevice.HadReadDeviceStatu = true;
                            }
                            else if (attData.AttributeId == 4097)
                            {
                                //转换为二进制
                                var value = Convert.ToString(attData.AttriButeData, 2).PadLeft(16, '0');
                                //这个设置是放在后面的
                                value = value.Substring(value.Length - 1, 1);
                                //启用摆风功能
                                ((AC)locadevice).UseSwingFunction = value == "1";
                                locadevice.ReSave();
                            }
                        }
                    }
                }
@@ -395,24 +425,51 @@
                        //温度
                        if (attData.AttributeId == (int)AttriButeId.MeasuredValue)
                        {
                            if (attData.AttriButeData == 0)
                            decimal temperatrue = 0;
                            string receiptData = string.Empty;
                            //两个两个位置替换
                            for (int i = attData.AttriButeDataHex.Length - 1; i >= 0; i = i - 2)
                            {
                                ((TemperatureSensor)locadevice).Temperatrue = 0;
                                receiptData += attData.AttriButeDataHex[i - 1].ToString() + attData.AttriButeDataHex[i].ToString();
                            }
                            else if (attData.AttriButeData > 32767)
                            {
                                //负数(特殊处理)
                                string strValue = (attData.AttriButeData - 65536).ToString();
                                //小数点需要一位
                                strValue = strValue.Substring(0, strValue.Length - 1);
                                ((TemperatureSensor)locadevice).Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                            }
                            else
                            //有符号(会出现负数)
                            if (attData.AttriButeDataType == 40 || attData.AttriButeDataType == 41)
                            {
                                //小数点需要一位
                                string strValue = attData.AttriButeData.ToString();
                                string strValue = Convert.ToInt16(receiptData, 16).ToString();
                                strValue = strValue.Substring(0, strValue.Length - 1);
                                ((TemperatureSensor)locadevice).Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                                temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                            }
                            //无符号(不会出现负数)
                            else if (attData.AttriButeDataType == 32 || attData.AttriButeDataType == 33)
                            {
                                ushort shortData = Convert.ToUInt16(receiptData, 16);
                                if (shortData > 32767)
                                {
                                    //负数(特殊处理)
                                    string strValue = (shortData - 65536).ToString();
                                    //小数点需要一位
                                    strValue = strValue.Substring(0, strValue.Length - 1);
                                    temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                                }
                                else
                                {
                                    //小数点需要一位
                                    string strValue = shortData.ToString();
                                    strValue = strValue.Substring(0, strValue.Length - 1);
                                    temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                                }
                            }
                            //温度传感器
                            if (locadevice is TemperatureSensor)
                            {
                                ((TemperatureSensor)locadevice).Temperatrue = temperatrue;
                            }
                            //PM2.5传感器
                            else if (locadevice is PMSensor)
                            {
                                ((PMSensor)locadevice).currentTemperature = (int)temperatrue;
                            }
                            //已经接收到状态
                            locadevice.HadReadDeviceStatu = true;
@@ -430,22 +487,66 @@
                        //湿度
                        if (attData.AttributeId == (int)AttriButeId.MeasuredValue)
                        {
                            if (attData.AttriButeData == 0)
                            decimal humidity = 0;
                            string receiptData = string.Empty;
                            //两个两个位置替换
                            for (int i = attData.AttriButeDataHex.Length - 1; i >= 0; i = i - 2)
                            {
                                ((TemperatureSensor)locadevice).Humidity = 0;
                                receiptData += attData.AttriButeDataHex[i - 1].ToString() + attData.AttriButeDataHex[i].ToString();
                            }
                            else
                            //有符号(会出现负数)
                            if (attData.AttriButeDataType == 40 || attData.AttriButeDataType == 41)
                            {
                                //小数点需要一位(湿度没有负数)
                                string strValue = attData.AttriButeData.ToString();
                                //小数点需要一位
                                string strValue = Convert.ToInt16(receiptData, 16).ToString();
                                strValue = strValue.Substring(0, strValue.Length - 1);
                                ((TemperatureSensor)locadevice).Humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                                humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                            }
                            //无符号(不会出现负数)
                            else if (attData.AttriButeDataType == 32 || attData.AttriButeDataType == 33)
                            {
                                //小数点需要一位 湿度不会出现负数
                                string strValue = Convert.ToUInt16(receiptData, 16).ToString();
                                strValue = strValue.Substring(0, strValue.Length - 1);
                                humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                            }
                            //温度传感器
                            if (locadevice is TemperatureSensor)
                            {
                                ((TemperatureSensor)locadevice).Humidity = humidity;
                            }
                            //PM2.5传感器
                            else if (locadevice is PMSensor)
                            {
                                ((PMSensor)locadevice).currentHumidity = (int)humidity;
                            }
                        }
                        //已经接收到状态
                        locadevice.HadReadDeviceStatu = true;
                    }
                }
                #endregion
                #region ■ PM2.5数据
                //PM2.5数据
                else if (report.DeviceStatusReport.CluterID == 1066)
                {
                    foreach (var attData in report.DeviceStatusReport.AttriBute)
                    {
                        //PM2.5
                        if (attData.AttributeId == (int)AttriButeId.MeasuredValue)
                        {
                            if (attData.AttriButeDataType == 57)
                            {
                                ((PMSensor)locadevice).currentPmData = attData.AttriButeData;
                            }
                        }
                        //已经接收到状态
                        locadevice.HadReadDeviceStatu = true;
                    }
                }
                #endregion
            }
@@ -477,6 +578,8 @@
            if (locadevice != null)
            {
                ((IASZone)locadevice).iASInfo = ias.iASInfo;
                //如果接收到上报,即说明这个传感器是在线的
                locadevice.IsOnline = 1;
                //记录回复时间
                locadevice.LastDateTime = DateTime.Now;
            }
@@ -512,10 +615,17 @@
                    //常开模式关闭
                    if (info.AlarmCode == 217 || info.AlarmCode == 219)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        HdlThreadLogic.Current.RunThread(async () =>
                        {
                            //弹出徐梅的那个窗口
                            DoorLock.DoorLockCommonInfo.NomallyOpenModeInvalidDialog((ZigBee.Device.DoorLock)device, DoorLock.DoorLockCommonInfo.DoorLockMessType.ServicePush, null);
                            //温居城的要网关中是否有逻辑存在
                            //参数:2-常开自动化;3-失效时间自动化
                            var result = await Shared.Phone.Device.Logic.SkipView.Exist(3, (ZigBee.Device.DoorLock)device);
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                //弹出徐梅的那个窗口
                                DoorLock.DoorLockCommonInfo.NomallyOpenModeInvalidDialog((ZigBee.Device.DoorLock)device, DoorLock.DoorLockCommonInfo.DoorLockMessType.ServicePush,
                                    result != 0 ? true : false, null);
                            });
                        });
                    }
                }
@@ -543,13 +653,18 @@
            tempDevice.IsOnline = Convert.ToInt32(receiveData["Data"]["IsOnline"].ToString());
            //处理网关上报的数据,然后变更本地缓存
            var locadevice = Common.LocalDevice.Current.GetDevice(tempDevice.DeviceAddr, tempDevice.DeviceEpoint);
            if (locadevice != null)
            var locadevice = Common.LocalDevice.Current.GetDevicesByMac(tempDevice.DeviceAddr);
            for (int i = 0; i < locadevice.Count; i++)
            {
                locadevice.IsOnline = tempDevice.IsOnline;
                bool onlineChanged = locadevice[i].IsOnline != tempDevice.IsOnline;
                locadevice[i].IsOnline = tempDevice.IsOnline;
                //记录回复时间
                locadevice.LastDateTime = DateTime.Now;
                locadevice.ReSave();
                locadevice[i].LastDateTime = DateTime.Now;
                if (onlineChanged == true)
                {
                    //在线状态变更了,才保存
                    locadevice[i].ReSave();
                }
            }
            this.DeviceReportPush(tempDevice, ReceiveComandDiv.A设备在线上报);