HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-09-30 404cdc88627f942df7944af04ee05b9d527752d6
ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -160,6 +160,10 @@
            {
                return Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte);
            }
            else if (strDeviceType == ZigBee.Device.DeviceType.DoorLock.ToString())
            {
                return Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte);
            }
            return null;
        }
@@ -180,8 +184,87 @@
        /// </summary>
        public void ReSave()
        {
            //Console.WriteLine(FilePath);
            if (IconPath == string.Empty)
            {
                //保存设备图标(这里会保存一次,下面就不用保存了)
                this.SaveDeviceIcon();
                return;
            }
            Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
        }
        /// <summary>
        /// 保存设备图标
        /// </summary>
        private void SaveDeviceIcon()
        {
            if (IconPath == string.Empty)
            {
                //干接点
                if (this.Type == DeviceType.OnOffSwitch)
                {
                    IconPath = "Device/DryContact.png";
                }
                else if (this.Type == DeviceType.ColorDimmableLight)
                {
                    //彩灯
                    IconPath = "Device/ColorDimmableLight.png";
                }
                else if (this.Type == DeviceType.DimmableLight)
                {
                    //调光器
                    IconPath = "Device/ColorDimmableLight.png";
                }
                else if (this.Type == DeviceType.OnOffOutput)
                {
                    //继电器
                    IconPath = "Device/RelayEpoint.png";
                }
                else if (this.Type == DeviceType.Thermostat)
                {
                    //空调
                    IconPath = "Device/AirConditionerEpoint.png";
                }
                else if (this.Type != DeviceType.UnKown)
                {
                    //其他的图标有点特殊
                    string unSelectPic = string.Empty;
                    string selectPic = string.Empty;
                    Shared.Common.LocalDevice.Current.GetDeviceBeloneIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic);
                    IconPath = unSelectPic;
                }
                Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
            }
        }
        /// <summary>
        /// 是否是自定义图片
        /// </summary>
        public bool IsCustomizeImage = false;
        /// <summary>
        /// 设备图片
        /// </summary>
        public string IconPath = string.Empty;
        /// <summary>
        /// 设备图片--在线或者选中状态
        /// </summary>
        /// <value>The online icon path.</value>
        [Newtonsoft.Json.JsonIgnore]
        public string OnlineIconPath
        {
            get
            {
                if (string.IsNullOrEmpty(IconPath))
                {
                    return string.Empty;
                }
                var pathArr = IconPath.Split('.');
                if (pathArr == null || string.IsNullOrEmpty(pathArr[0]))
                {
                    return string.Empty;
                }
                return $"{pathArr[0]}Selected.png";
            }
        }
        /// <summary>
@@ -192,7 +275,10 @@
        /// 当前设备类型
        /// </summary>
        public DeviceType Type = DeviceType.UnKown;
        /// <summary>
        /// 设备的功能类型(此类型目前只针对继电器回路有效,默认为灯光)
        /// </summary>
        public DeviceFunctionType DfunctionType = DeviceFunctionType.A灯光;
        /// <summary>
        /// MAC地址
        /// </summary>
@@ -559,6 +645,18 @@
            /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备
            /// </summary>
            public int DriveCode;
            /// <summary>
            /// 厂商名称
            /// </summary>
            public string ManufacturerName = string.Empty;
            /// <summary>
            /// 模块ID
            /// </summary>
            public string ModelIdentifier = string.Empty;
            /// <summary>
            /// 好像是序列号
            /// </summary>
            public string ProductCode = string.Empty;
            /// <summary>
            /// 输入簇列表
            /// </summary>
@@ -1208,6 +1306,24 @@
                                    }
                                }
                                break;
                            case DeviceType.DoorLock:
                                var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId };
                                doorLock.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.DeviceRenameResponseData>(jobject["Data"].ToString());
                                if (doorLock.renameDeviceData == null)
                                {
                                    d = new DeviceRenameAllData { errorMessageBase = "网关返回的数据为空" };
                                }
                                else
                                {
                                    d = new DeviceRenameAllData { deviceRenameData = doorLock.renameDeviceData };
                                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
                                    var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr && obj.DeviceEpoint == doorLock.DeviceEpoint);
                                    if (info != null)
                                    {
                                        info.DeviceEpointName = doorLock.renameDeviceData.DeviceName;
                                    }
                                }
                                break;
                        }
                    }
                };
@@ -1499,6 +1615,25 @@
                                    if (info != null)
                                    {
                                        info.DeviceName = transverter.renameDeviceMacNameData.MacName;
                                    }
                                }
                                break;
                            case DeviceType.DoorLock:
                                var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.CurrentGateWayId };
                                doorLock.renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.RenameDeviceMacNameData>(jobject["Data"].ToString());
                                if (doorLock.renameDeviceMacNameData == null)
                                {
                                    d = new RenameDeviceMacNameAllData { errorMessageBase = "网关返回的数据为空" };
                                }
                                else
                                {
                                    d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = doorLock.renameDeviceMacNameData };
                                    System.Console.WriteLine($"UI收到通知后的主题_{ topic}_收到通知后的数据_{ d.renameDeviceMacNameData.ToString()}");
                                    var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr && obj.DeviceEpoint == doorLock.DeviceEpoint);
                                    if (info != null)
                                    {
                                        info.DeviceName = doorLock.renameDeviceMacNameData.MacName;
                                    }
                                }
                                break;
@@ -1855,6 +1990,25 @@
                                                    if (transverter.removeDeviceResponseData.Result == 0)
                                                    {
                                                        var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr && obj.DeviceEpoint == transverter.DeviceEpoint);
                                                        if (info != null)
                                                        {
                                                            Gateway.DeviceList.Remove(info);
                                                        }
                                                    }
                                                }
                                                break;
                                            case DeviceType.DoorLock:
                                                var doorLock = new DoorLock() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                                                doorLock.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.RemoveDeviceResponseData>(jobject["Data"].ToString());
                                                if (doorLock.removeDeviceResponseData == null)
                                                {
                                                    return;
                                                }
                                                else
                                                {
                                                    if (doorLock.removeDeviceResponseData.Result == 0)
                                                    {
                                                        var info = Gateway.DeviceList.Find((CommonDevice obj) => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr && obj.DeviceEpoint == doorLock.DeviceEpoint);
                                                        if (info != null)
                                                        {
                                                            Gateway.DeviceList.Remove(info);
@@ -3594,28 +3748,28 @@
        /// <para>isOn 0:关闭透传数据上传</para>
        /// <para>isOn 1:开启透传数据上传</para>
        /// </summary>
        public void OpenPassthroughControl(ZigBee.Device.ZbGateway gateway, int isOn = 1)
        {
            if (Gateway == null)
            {
                return;
            }
            Action<string, string> action = (topic, message) => { };
            Gateway.Actions += action;
            System.Console.WriteLine("OnZbDataPassthrough_Actions 启动" + "_" + System.DateTime.Now.ToString());
        //public void OpenPassthroughControl(ZigBee.Device.ZbGateway gateway, int isOn = 1)
        //{
        //    if (Gateway == null)
        //    {
        //        return;
        //    }
        //    Action<string, string> action = (topic, message) => { };
        //    Gateway.Actions += action;
        //    System.Console.WriteLine("OnZbDataPassthrough_Actions 启动" + "_" + System.DateTime.Now.ToString());
            try
            {
                var jObject = new JObject { { "Cluster_ID", 64513 }, { "Command", 1 } };
                var data = new JObject { { "IsOn", isOn } };
                jObject.Add("Data", data);
                gateway.Send(("OnZbDataPassthrough"), jObject.ToString());
            }
            catch { }
        //    try
        //    {
        //        var jObject = new JObject { { "Cluster_ID", 64513 }, { "Command", 1 } };
        //        var data = new JObject { { "IsOn", isOn } };
        //        jObject.Add("Data", data);
        //        gateway.Send(("OnZbDataPassthrough"), jObject.ToString());
        //    }
        //    catch { }
            Gateway.Actions -= action;
            System.Console.WriteLine("OnZbDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
        }
        //    Gateway.Actions -= action;
        //    System.Console.WriteLine("OnZbDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
        //}
        #endregion
        #region 客户端向节点设备透传数据.
@@ -3671,7 +3825,6 @@
                try
                {
                    OpenPassthroughControl(gateway);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);