| | |
| | |
|
| | | #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);
|
| | | //发送给网关的设备房间json
|
| | | 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>
|
| | | /// 网关的Mac
|
| | | /// </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>
|
| | | /// 这个是Linux的固件版本
|
| | | /// </summary>
|
| | | public string version = string.Empty;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 网关固件版本
|
| | | /// </summary>
|
| | | private class GatewaySwInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 这个固定
|
| | | /// </summary>
|
| | | public string name = "HDL";
|
| | | /// <summary>
|
| | | /// 这个是Linux的固件版本
|
| | | /// </summary>
|
| | | public string ver = string.Empty;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 克隆房间对象_______________________
|
| | |
|
| | | /// <summary>
|