/// <summary> /// 异步更新Mesh设备列表 /// </summary> /// <param name="ip">Mesh设备IP地址</param> /// <param name="args">参数</param> private void doUpdateAdvTreeMeshList(string ip, params object[] args) { try { if (this.advTreeMeshList.InvokeRequired) { updateAdvTreeMeshList uatml = new updateAdvTreeMeshList(doUpdateAdvTreeMeshList); advTreeMeshList.BeginInvoke(uatml, ip, args); } else { advTreeMeshList.BeginUpdate(); MeshAllInfo mai = mMeshAllInfo.Find(m => m.DeviceInfo.IPV4 == ip); if (mai != null) { mai.BuddyNode.Cells[1].Text = args[0].ToString(); mai.BuddyNode.Cells[1].StyleNormal.TextColor = args[0].ToString().Equals("在线") ? Color.Black : Color.Gray; mai.BuddyNode.Cells[1].StyleNormal.Font = args[0].ToString().Equals("在线") ? new Font("宋体", 9, FontStyle.Bold) : new Font("宋体", 9, FontStyle.Regular); mai.BuddyNode.Cells[2].Images.ImageIndex = args[0].ToString().Equals("在线") && args.Length == 2 ? 10 : 9; mai.BuddyNode.Cells[3].Images.ImageIndex = args[0].ToString().Equals("在线") ? 12 : 11; } advTreeMeshList.EndUpdate(); } } catch (Exception ex) { logger.Error("更新Mesh设备列表发生异常:", ex); } }
/// <summary> /// 更新Mesh设备信息 /// </summary> /// <param name="mdi">Mesh设备信息</param> public void UpdateMeshDeviceInfo(MeshDeviceInfo mdi) { MeshAllInfo mai = mMeshAllInfo.Find(m => m.DeviceInfo.IPV4.Equals(mdi.IPV4)); if (mai != null) { mai.DeviceInfo.Frequency = mdi.Frequency; mai.DeviceInfo.Power = mdi.Power; mai.DeviceInfo.BandWidth = mdi.BandWidth; mai.BuddyBMeshPoint.Frequency = mdi.Frequency; mai.BuddyBMeshPoint.Power = mdi.Power; mai.BuddyBMeshPoint.BandWidth = mdi.BandWidth; } }
/// <summary> /// 接收到GPS信号事件 /// </summary> /// <param name="gpsInfo">GPS信息</param> private void PGPSUDPListener_OnReceiveGPSInfo(GPSInfo gpsInfo) { MeshAllInfo mesh = mMeshAllInfo.Find(m => m.PlanInfo.Model265ID == gpsInfo.ID); //如果ID不存在,则退出 if (mesh == null) { return; } if (mesh.PlanInfo != null) { GPSInfo gi = mesh.MeshGPSInfo; gi.Time = gpsInfo.Time; gi.Lat = gpsInfo.Lat; gi.Lon = gpsInfo.Lon; mesh.MeshGPSInfo = gi; BMeshPoint bmp = mesh.BuddyBMeshPoint; bmp.IsOnline = true; bmp.ReceiveGPSDT = DateTime.Now; bmp.Location = new LatLngPoint(gpsInfo.Lon, gpsInfo.Lat); mesh.BuddyBMeshPoint = bmp; } if (mesh.BuddyNode != null) { doUpdateAdvTreeMeshList(mesh.DeviceInfo.IPV4, "在线", "GPS在线"); } //如果之前没有在地图上显示该设备则添加显示 BMeshPoint p = mBMeshPoints.Find(b => b.IPV4 == mesh.PlanInfo.MeshIP); if (p != null) { p.Location = new LatLngPoint(gpsInfo.Lon, gpsInfo.Lat); if (BuddyBMapControl != null) { BuddyBMapControl.AddMeshDevicePlaces(mBMeshPoints); } } }
/// <summary> /// 更新Mesh设备状态 /// </summary> /// <param name="meshIp">Mesh设备IP</param> /// <param name="status">状态</param> public void UpdateMeshStatus(string meshIp, string status) { MeshAllInfo mai = mMeshAllInfo.Find(m => m.DeviceInfo.IPV4 == meshIp); if (mai != null) { if (status.Equals("离线")) { //如果之前有在线过,3次以内如果没有ping到该设备,仍然认为该设备在线,否则不在线 if (mai.WasOnline) { if (mai.OfflineCount < 2) { status = "在线"; mai.OfflineCount++; mai.WasOnline = true; } else { status = "离线"; mai.OfflineCount++; mai.WasOnline = false; } } else { status = "离线"; mai.OfflineCount++; mai.WasOnline = false; } } else { mai.OfflineCount = 0; mai.WasOnline = true; } logger.Info(string.Format("{0}:{1}-离线{2}次-{3}", meshIp, status, mai.OfflineCount, mai.WasOnline ? "曾经在线" : "不在线")); doUpdateAdvTreeMeshList(meshIp, status); } }
/// <summary> /// 从数据库中读取并添加Mesh设备列表 /// </summary> private void loadMeshDeviceFromDB() { advTreeMeshList.BeginUpdate(); List <MeshDeviceInfo> mdiList = SQLiteHelper.GetInstance().MeshDeviceInfoAllQuery(); foreach (MeshDeviceInfo item in mdiList) { foreach (Node node in advTreeMeshList.Nodes) { if (node.Text.Equals(item.GroupName)) { Node subNode = new Node(); subNode.Text = item.Alias; subNode.ImageIndex = 8; Cell cellState = new Cell(); cellState.Text = "离线"; cellState.StyleNormal = new DevComponents.DotNetBar.ElementStyle(); cellState.StyleNormal.TextColor = cellState.Text.Equals("离线") ? Color.Gray : Color.DarkGreen; subNode.Cells.Add(cellState); Cell cellGPS = new Cell(); cellGPS.Images.ImageIndex = 9; cellGPS.ImageAlignment = eCellPartAlignment.NearCenter; subNode.Cells.Add(cellGPS); Cell cellVideo = new Cell(); cellVideo.Images.ImageIndex = 11; subNode.Cells.Add(cellVideo); Cell cellGPSTrack = new Cell(); cellGPSTrack.Images.ImageIndex = 13; cellGPSTrack.ImageAlignment = eCellPartAlignment.NearBottom; cellGPSTrack.Tag = false; //标识是否在界面上绘制了历史轨迹 subNode.Cells.Add(cellGPSTrack); MeshPlanManage mpm = SQLiteHelper.GetInstance().MeshPlanQueryByMeshIP(item.IPV4); MeshAllInfo nodeMAI = new MeshAllInfo() { DeviceInfo = item, PlanInfo = mpm, MeshGPSInfo = new GPSInfo(), BuddyNode = subNode, BuddyBMeshPoint = new BMeshPoint() { GroupName = item.GroupName, Alias = item.Alias, IPV4 = item.IPV4, Model265ID = mpm.Model265ID, Power = item.Power, Frequency = item.Frequency, BandWidth = item.BandWidth, Battery = item.Battery, IsOnline = false, Location = new LatLngPoint(0, 0), Expiration = int.Parse(mFormMain.AllApplicationSetting[ApplicationSettingKey.GPSExpirationTime]), ReceiveGPSDT = DateTime.Now }, OfflineCount = 0, WasOnline = false }; //添加进列表 mMeshAllInfo.Add(nodeMAI); mBMeshPoints.Add(nodeMAI.BuddyBMeshPoint); subNode.Tag = nodeMAI; node.Nodes.Add(subNode); break; } } } //添加Mesh设备点到百度地图上 if (BuddyBMapControl != null) { //BuddyBMapControl.AddMeshDevicePlaces(mBMeshPoints); } advTreeMeshList.EndUpdate(); }
/// <summary> /// 单击节点,跳转到设备所在的位置。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void advTreeMeshList_NodeClick(object sender, TreeNodeMouseEventArgs e) { DevComponents.AdvTree.Node selectNode = advTreeMeshList.SelectedNode; //设备不在线,不执行后续操作 if (selectNode == null || selectNode.Level != 1) { return; } Cell selectCell = selectNode.GetCellAt(e.X, e.Y); if (selectCell == null) { return; } if (selectNode.Level == 1 && selectCell.Images != null) { MeshAllInfo mai = (MeshAllInfo)selectNode.Tag; GPSInfo vp = mai.MeshGPSInfo; //GPS坐标为(0,0),不能执行定位操作 if (selectCell.Images.ImageIndex == 9 && BuddyBMapControl != null) {//点中了离线设备 BuddyBMapControl.SelectMeshDevice(null); } if (selectCell.Images.ImageIndex == 10 && vp.Lat != 0 && vp.Lon != 0 && BuddyBMapControl != null) { //地图上跳转到设备所在的位置 BuddyBMapControl.Center = new LatLngPoint(vp.Lon, vp.Lat); BuddyBMapControl.Locate(false); //选中目标Mesh设备 BuddyBMapControl.SelectMeshDevice(mai.BuddyBMeshPoint); } else if (selectCell.Images.ImageIndex == 11) { MessageBox.Show("设备不在线!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (selectCell.Images.ImageIndex == 12 && selectNode.Cells[1].Text.Equals("在线")) { if (BuddyBMapControl != null) { BuddyBMapControl_OnOpenVideo(mai.BuddyBMeshPoint); } else if (BuddyGrid != null) { VideoInject inject = new VideoInject(mFormMain.AllApplicationSetting[ApplicationSettingKey.VideoServerIPV4], mFormMain.AllApplicationSetting[ApplicationSettingKey.VideoServerUserName], mFormMain.AllApplicationSetting[ApplicationSettingKey.VideoServerPassword]); Panel panel = BuddyGrid.GetNextAvailablePanel(); Process process = inject.injectPanel(panel, mFormMain.GetVideoFullScreenLocation(), BuddyGrid.GetFullScreenPanel(), mai.PlanInfo.Model265ID, "0"); BuddyGrid.BindPanelProcess(panel, process); mFormMain.VideoProcesses.Add(process); logger.Info(string.Format("在第{0}个Panel中打开了视频。", panel.Tag.ToString())); } } else if (selectCell.Images.ImageIndex == 13 && BuddyBMapControl != null) { bool isDrawingRoute = (bool)selectCell.Tag; if (isDrawingRoute) {//已经绘制,再次点击的时候隐藏已绘制的轨迹 BuddyBMapControl.DeleteDeviceRoute(mai.PlanInfo.Model265ID); selectCell.Tag = false; } else { //在地图上绘制轨迹记录 FGPSTimeSelect fgpsts = new FGPSTimeSelect(); fgpsts.StartDateTime = DateTime.Today.Subtract(new TimeSpan(1, 0, 0, 0)); fgpsts.StopDateTime = DateTime.Today; if (DialogResult.OK == fgpsts.ShowDialog() && BuddyBMapControl != null) { BMeshRoute bmr = FileUtils.ReadMeshRouteFromGPSLogs( mai.PlanInfo.Model265ID, fgpsts.StartDateTime, fgpsts.StopDateTime); if (bmr.DeviceLocationList.Count > 0) { BuddyBMapControl.AddDeviceRoute(bmr); //地图上跳转到设备所在的位置 BuddyBMapControl.Center = bmr.DeviceLocationList[0]; BuddyBMapControl.Locate(false); BuddyBMapControl.Zoom = 16; selectCell.Tag = true; //标识已经绘制了路径 logger.Info(string.Format("查看{0}设备的GPS轨迹记录,供{1}条GPS记录。", mai.PlanInfo.Model265ID, bmr.DeviceLocationList.Count)); } else { MessageBox.Show("无历史轨迹记录。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } } } }