From dc6493db59dcb0893eac50b72122f94c24056b3f Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 12 十月 2020 14:35:39 +0800 Subject: [PATCH] 新版本 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 252 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs index 91c4949..e0c1f4e 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs @@ -1061,6 +1061,258 @@ #endregion + #region 鈻� 鍙戦�佹埧闂翠俊鎭粰缃戝叧_________________ + + /// <summary> + /// 鍙戦�佹埧闂翠俊鎭粰缃戝叧 + /// </summary> + public void SetRoomInfoToGateway() + { + if (UserCenterResourse.UserInfo.AuthorityNo != 1 && UserCenterResourse.UserInfo.AuthorityNo != 2) + { + //涓嶆槸涓讳汉鍜岀鐞嗗憳,鍒欎笉澶勭悊 + return; + } + var realMain = ZbGateway.MainGateWay; + if (realMain == null || Common.Config.Instance.Home.IsVirtually == true) + { + //娌℃湁涓荤綉鍏�,鍒欎笉鐞� + return; + } + //鑾峰彇鎴块棿鍏ㄩ儴鐨勮澶囧璞� + string strSendDeviceRoomInfo = string.Empty; + foreach (var room in this.dicRooms.Values) + { + if (room.IsSharedRoom || room.IsLove) + { + continue; + } + var listDevice = this.GetRoomListDevice(room); + //鍙戦�佺粰缃戝叧鐨勮澶囨埧闂磈son + foreach (var device in listDevice) + { + if (strSendDeviceRoomInfo != string.Empty) + { + strSendDeviceRoomInfo += "\r\n"; + } + strSendDeviceRoomInfo += " " + this.SetDoublMark(device.DeviceAddr) + " "; + strSendDeviceRoomInfo += this.SetDoublMark("0x" + Convert.ToString(device.DeviceEpoint, 16).PadLeft(2, '0')) + " "; + strSendDeviceRoomInfo += this.SetDoublMark(LocalDevice.Current.GetDeviceEpointName(device).Replace(UserCenterResourse.douMarks, string.Empty)) + " "; + strSendDeviceRoomInfo += this.SetDoublMark(room.Id); + } + } + + var listAreaSpaceInfo = new List<AreaSpaceInfo>(); + //棣栧厛娣诲姞浣忓畢 + var houseInfo = new AreaSpaceInfo(); + houseInfo.name = Common.Config.Instance.Home.Name; + houseInfo.uid = Common.Config.Instance.Home.Id; + houseInfo.parentId = "null"; + listAreaSpaceInfo.Add(houseInfo); + //鐒跺悗娣诲姞妤煎眰 + foreach (var floorId in Common.Config.Instance.Home.FloorDics.Keys) + { + var floorInfo = new AreaSpaceInfo(); + floorInfo.name = Common.Config.Instance.Home.FloorDics[floorId]; + floorInfo.uid = floorId; + floorInfo.parentId = Common.Config.Instance.Home.Id; + listAreaSpaceInfo.Add(floorInfo); + } + //鐒跺悗娣诲姞鎴块棿 + var listRoom = this.GetAllListRooms(); + foreach (var room in listRoom) + { + if (room.IsLove == true) { continue; } + + var roomInfo = new AreaSpaceInfo(); + roomInfo.name = room.Name; + roomInfo.uid = room.Id; + if (Common.Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true) + { + roomInfo.parentId = room.FloorId; + } + else + { + roomInfo.parentId = Common.Config.Instance.Home.Id; + } + listAreaSpaceInfo.Add(roomInfo); + } + //鐒跺悗娣诲姞缃戝叧鎴块棿淇℃伅 + var gatewayInfo = new GatewayAreaSpaceInfo(); + + var loaclGateway = HdlGatewayLogic.Current.GetLocalGateway(realMain.GwId); + if (loaclGateway == null || loaclGateway.GwMac == string.Empty) + { + //娌℃湁mac,鎴栬�呮壘涓嶅埌瀵硅薄,鍒欎笉涓婁紶 + return; + } + string gwMac = loaclGateway.GwMac.Replace(":", string.Empty); + gatewayInfo.uid = "000101" + gwMac.Substring(2) + "07"; + gatewayInfo.name = HdlGatewayLogic.Current.GetGatewayName(loaclGateway); + + var roomGateway = HdlGatewayLogic.Current.GetRoomByGateway(loaclGateway); + if (roomGateway != null) + { + gatewayInfo.parentId = roomGateway.Id; + } + gatewayInfo.hwInfo = new GatewayHwInfo(); + gatewayInfo.pkgInfo = new GatewayPkgInfo { version = loaclGateway.LinuxFirmwareVersion.ToString() }; + gatewayInfo.swInfo = new List<GatewaySwInfo> { new GatewaySwInfo { ver = loaclGateway.LinuxFirmwareVersion.ToString() } }; + gatewayInfo.ip = loaclGateway.GwIP; + gatewayInfo.mac = loaclGateway.GwMac; + + var data = new { spaces = listAreaSpaceInfo, gateway = gatewayInfo }; + string strSendRoomInfo = Newtonsoft.Json.JsonConvert.SerializeObject(data); + + HdlThreadLogic.Current.RunThread(async () => + { + //鍙戦�佽澶囧尯鍩熶俊鎭� + if (strSendDeviceRoomInfo != string.Empty) + { + //鍒涘缓鏂囦欢瀵硅薄 + var result0 = await realMain.CreateFileAsync("DeviceRoomInfo.json"); + if (result0 == null || result0.Result != 0) + { + return; + } + //鍙戦�佹暟鎹祦 + var byteData = ASCIIEncoding.UTF8.GetBytes(strSendDeviceRoomInfo); + var result1 = await realMain.SendFileAsync(byteData); + if (result1 == null || result1.Result != 0) + { + return; + } + + } + + //鍒涘缓鏂囦欢瀵硅薄 + var result3 = await realMain.CreateFileAsync("space.json"); + if (result3 == null || result3.Result != 0) + { + return; + } + + //鍙戦�佸尯鍩熶俊鎭� + var byteData2 = ASCIIEncoding.UTF8.GetBytes(strSendRoomInfo); + var result4 = await realMain.SendFileAsync(byteData2); + }); + } + + /// <summary> + /// 璁剧疆鍙屽紩鍙� + /// </summary> + /// <param name="i_text"></param> + /// <returns></returns> + private string SetDoublMark(string i_text) + { + return UserCenterResourse.douMarks + i_text + UserCenterResourse.douMarks; + } + + /// <summary> + /// 绌洪棿鍖哄煙淇℃伅 + /// </summary> + private class AreaSpaceInfo + { + /// <summary> + /// 浣忓畢ID 鎴栬�� 妤煎眰ID 鎴栬�� 鎴块棿ID + /// </summary> + public string uid = string.Empty; + /// <summary> + /// 浣忓畢鍚嶇О 鎴栬�� 妤煎眰鍚嶇О 鎴栬�� 鎴块棿鍚嶇О + /// </summary> + public string name = string.Empty; + /// <summary> + /// 褰撳墠ID鐨勭埗ID,濡傛灉娌℃湁,鍒欎负甯﹀弻寮曞彿鐨�"null" 姣斿 妤煎眰ID灏卞~浣忓畢ID 鎴块棿ID灏卞~妤煎眰ID + /// </summary> + public string parentId = string.Empty; + } + + /// <summary> + /// 缃戝叧绌洪棿鍖哄煙淇℃伅 + /// </summary> + private class GatewayAreaSpaceInfo + { + /// <summary> + /// 銆�000101銆�+缁戝畾缃戝叧鐨勬椂闂存埑杞�16杩涘埗+銆�07銆� + /// </summary> + public string uid = string.Empty; + /// <summary> + /// 杩欎釜鍥哄畾 + /// </summary> + public string name = "hdl_bus_gatway"; + /// <summary> + /// 缃戝叧鎵�鍦ㄧ殑鎴块棿ID + /// </summary> + public string parentId = string.Empty; + /// <summary> + /// 杩欎釜鍥哄畾 + /// </summary> + public int deviceType = 61184; + /// <summary> + /// 缃戝叧纭欢淇℃伅 + /// </summary> + public GatewayHwInfo hwInfo = null; + /// <summary> + /// 缃戝叧鏍囧噯淇℃伅 + /// </summary> + public GatewayPkgInfo pkgInfo = null; + /// <summary> + /// 缃戝叧鍥轰欢鐗堟湰 + /// </summary> + public List<GatewaySwInfo> swInfo = null; + /// <summary> + /// 缃戝叧IP + /// </summary> + public string ip = string.Empty; + /// <summary> + /// 缃戝叧鐨凪ac + /// </summary> + public string mac = string.Empty; + } + + /// <summary> + /// 缃戝叧纭欢淇℃伅 + /// </summary> + private class GatewayHwInfo + { + /// <summary> + /// 杩欎釜鍥哄畾 + /// </summary> + public string brand = "MIPS"; + /// <summary> + /// 杩欎釜鍥哄畾 + /// </summary> + public string model = "MT7688"; + } + + /// <summary> + /// 缃戝叧鏍囧噯淇℃伅 + /// </summary> + private class GatewayPkgInfo + { + /// <summary> + /// 杩欎釜鏄疞inux鐨勫浐浠剁増鏈� + /// </summary> + public string version = string.Empty; + } + + /// <summary> + /// 缃戝叧鍥轰欢鐗堟湰 + /// </summary> + private class GatewaySwInfo + { + /// <summary> + /// 杩欎釜鍥哄畾 + /// </summary> + public string name = "HDL"; + /// <summary> + /// 杩欎釜鏄疞inux鐨勫浐浠剁増鏈� + /// </summary> + public string ver = string.Empty; + } + + #endregion + #region 鈻� 鍏嬮殕鎴块棿瀵硅薄_______________________ /// <summary> -- Gitblit v1.8.0