From 404cdc88627f942df7944af04ee05b9d527752d6 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 30 九月 2019 13:22:40 +0800 Subject: [PATCH] 合并了徐梅的按键面板绑定 --- ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs | 275 ++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 214 insertions(+), 61 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs index 3ae2a58..d3feb0d 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs @@ -23,7 +23,7 @@ { //if (msg.Contains("DeviceStatusReport") == false) //{ - System.Console.WriteLine(msg); + System.Console.WriteLine(msg); //} } } @@ -76,7 +76,7 @@ gateWay.getGatewayBaseInfo.gwID = CurrentGateWayId; gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId; ZbGateway.GateWayList.Add(gateWay); - } + } return gateWay; } @@ -110,13 +110,13 @@ return null; } return CommonDeviceByByteString(v[1], System.Text.Encoding.UTF8.GetString(Shared.Common.Global.ReadFileByHomeId(deviceFilePath))); - } - - /// <summary> - /// 鐢辫澶囧瓧绗︿覆姣旂壒鎭㈠璁惧瀵硅薄 - /// </summary> - /// <param name="strDeviceType">璁惧DeviceType鐨勫瓧绗︿覆绫诲瀷</param> - /// <param name="strDeviceByte">璁惧Json鏂囦欢杞负姣旂壒鍚庡啀杞负鐨勫瓧绗︿覆</param> + } + + /// <summary> + /// 鐢辫澶囧瓧绗︿覆姣旂壒鎭㈠璁惧瀵硅薄 + /// </summary> + /// <param name="strDeviceType">璁惧DeviceType鐨勫瓧绗︿覆绫诲瀷</param> + /// <param name="strDeviceByte">璁惧Json鏂囦欢杞负姣旂壒鍚庡啀杞负鐨勫瓧绗︿覆</param> /// <returns></returns> public static CommonDevice CommonDeviceByByteString(string strDeviceType, string strDeviceByte) { @@ -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> @@ -312,7 +398,7 @@ /// <summary> /// 搴忓垪鍙� /// </summary> - public string SerialNumber = string.Empty; + public string SerialNumber = string.Empty; /// <summary> /// 鎵�鏈夋寚瀹歝luster鏄惁閮藉凡缁忔垚鍔熺粦瀹氬崗璋冨櫒 ///<para>0:鏈畬鍏ㄧ粦瀹�</para> @@ -559,6 +645,18 @@ /// 椹卞姩浠g爜銆備负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> @@ -798,7 +896,7 @@ /// 1:璺敱鍣ㄨ澶� /// <para>2:缁堢璁惧</para> /// </summary> - public int ZigbeeType; + public int ZigbeeType; } /// <summary> @@ -931,7 +1029,7 @@ /// <summary> /// 搴忓垪鍙� /// </summary> - public string SerialNumber = string.Empty; + public string SerialNumber = 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; } } }; @@ -1223,7 +1339,7 @@ var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 96 } }; var data = new JObject { { "DeviceName", deviceName } }; jObject.Add("Data", data); - Gateway?.Send(("DeviceRename"), jObject.ToString()); + Gateway?.Send(("DeviceRename"), jObject.ToString()); } catch { } @@ -1349,7 +1465,7 @@ if (infoToggleLight != null) { infoToggleLight.DeviceName = toggleLight.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.AirSwitch: @@ -1368,7 +1484,7 @@ if (infoAirSwitch != null) { infoAirSwitch.DeviceName = airSwitch.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.OnOffSwitch: @@ -1386,7 +1502,7 @@ if (infoPanel != null) { infoPanel.DeviceName = panelObj.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.WindowCoveringDevice: @@ -1404,7 +1520,7 @@ if (wc != null) { wc.DeviceName = windowCovering.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.IASZone: @@ -1423,7 +1539,7 @@ if (info != null) { info.DeviceName = ias.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.DimmableLight: @@ -1442,7 +1558,7 @@ if (info != null) { info.DeviceName = dimmableLight.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.Repeater: @@ -1461,7 +1577,7 @@ if (info != null) { info.DeviceName = repeater.renameDeviceMacNameData.MacName; - } + } } break; case DeviceType.Thermostat: @@ -1502,6 +1618,25 @@ } } 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; //case DeviceType.TemperatureSensor: // var temperatureSensor = new TemperatureSensor() { 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 }; // temperatureSensor.renameDeviceData = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor.DeviceRenameResponseData>(jobject["Data"].ToString()); @@ -1536,7 +1671,7 @@ var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 100 } }; var data = new JObject { { "MacName", macName } }; jObject.Add("Data", data); - Gateway?.Send(("MacRename"), jObject.ToString()); + Gateway?.Send(("MacRename"), jObject.ToString()); } catch { } @@ -1625,7 +1760,7 @@ try { var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 97 } }; - Gateway.Send("FactoryReset", jObject.ToString()); + Gateway.Send("FactoryReset", jObject.ToString()); } catch { } @@ -1862,6 +1997,25 @@ } } 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); + } + } + } + break; } } } @@ -1890,7 +2044,7 @@ { "DeviceAddrList", deviceAddrList } }; jObject.Add("Data", data); - Gateway.Send(("RemoveDevice"), jObject.ToString()); + Gateway.Send(("RemoveDevice"), jObject.ToString()); } } catch { } @@ -2086,7 +2240,7 @@ var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 81 } }; var data = new JObject { { "GwId", gwId } }; jObject.Add("Data", data); - Gateway.Send(("RemoveEqOfGw"), jObject.ToString()); + Gateway.Send(("RemoveEqOfGw"), jObject.ToString()); } catch { } @@ -2179,7 +2333,7 @@ var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 3 }, { "Command", 0 }, { "SendMode", 2 } }; var data = new JObject { { "Time", time } }; jObject.Add("Data", data); - Gateway.Send(("Identify"), jObject.ToString()); + Gateway.Send(("Identify"), jObject.ToString()); } catch { } @@ -2715,11 +2869,11 @@ { "AttriButeId", (int)attriButeId} } }; - var data = new JObject { { "AttriBute", attriBute } }; - JObject.Add("Data", data); + var data = new JObject { { "AttriBute", attriBute } }; + JObject.Add("Data", data); Gateway?.Send(("GetDeviceStatus"), JObject.ToString()); - } - catch { } + } + catch { } // Gateway.Actions -= action; System.Console.WriteLine("GetDeviceStatus_Actions 閫�鍑�" + System.DateTime.Now.ToString()); @@ -2831,7 +2985,7 @@ var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } }; var data = new JObject { { "Undivided", setWritableValue.Undivided }, { "AttributeId", setWritableValue.AttributeId }, { "AttributeDataType", setWritableValue.AttributeDataType }, { "AttributeData", setWritableValue.AttributeData } }; jObject.Add("Data", data); - gateway.Send("SetWritableValue", jObject.ToString()); + gateway.Send("SetWritableValue", jObject.ToString()); } catch { } @@ -2951,7 +3105,7 @@ try { var jobject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 6 }, { "Command", command }, { "SendMode", 2 } }; - Gateway?.Send(("DeviceControl"), jobject.ToString()); + Gateway?.Send(("DeviceControl"), jobject.ToString()); System.Console.WriteLine("SwitchControl_鍙戦�佹暟鎹�" + "_" + jobject.ToString() + "_" + System.DateTime.Now.ToString()); } @@ -3026,7 +3180,7 @@ try { var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 301 } }; - gateway.Send("Cluster/OwnAttributes", jObject.ToString()); + gateway.Send("Cluster/OwnAttributes", jObject.ToString()); } catch { } @@ -3283,7 +3437,7 @@ var jObject = new JObject { { "Cluster_ID", 25 }, { "Command", 30 } }; var data = new JObject { { "OTAImageName", oTAImageName }, { "OTAImagePath", "/tmp" } }; jObject.Add("Data", data); - gateway.Send(("OTA/SetImage"), jObject.ToString()); + gateway.Send(("OTA/SetImage"), jObject.ToString()); } catch { } @@ -3457,7 +3611,7 @@ } var data = new JObject { { "DeviceList", deviceList } }; jObject.Add("Data", data); - gateway.Send(("OTA/StartUpdate"), jObject.ToString()); + gateway.Send(("OTA/StartUpdate"), jObject.ToString()); } } catch @@ -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); @@ -3837,7 +3990,7 @@ { "FileName", imageName } }; jObject.Add("Data", data); - gateway.Send("DownloadFile", jObject.ToString()); + gateway.Send("DownloadFile", jObject.ToString()); } catch { @@ -4003,7 +4156,7 @@ try { var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 25 }, { "Command", 5 } }; - gateway.Send("OTA/KillUpdate", jObject.ToString()); + gateway.Send("OTA/KillUpdate", jObject.ToString()); } catch { } @@ -4098,12 +4251,12 @@ /// <summary> ///鍝嶅簲鎿嶄綔鐮侊紙0-ffff锛� /// </summary> - public int command=-1; + public int command = -1; /// <summary> /// 鐘舵�佸�� /// <para>0--鎴愬姛 1--澶辫触 ff--鏃犳晥</para> /// </summary> - public int status=-1; + public int status = -1; } #endregion } -- Gitblit v1.8.0