Example #1
0
        static void Main(string[] args)
        {
            bool      bRet = SetConsoleCtrlHandler(newDelegate, true);
            UdpClient x    = new UdpClient(0);

            x.Connect("localhost", 3333);                       //将雷达的数据通过udp的方式传给应用,默认端口为3333

            int          oneRadarMaxnumber = 3000;              //设置单个雷达单次采样的最大点数
            List <Radar> radars            = radarSet(oneRadarMaxnumber);

            Cursor2DManagement management = new Cursor2DManagement();  //管理通过雷达生成的触摸点
            int mergeDistance = 50, maxX = 3560, maxY = 2000;          //maxX和maxY分别为屏幕坐标的最大距离(最终传输数据限制在0到1之间)
                                                                       //mergeDistance为两个点融合为一个点的最小距离
                                                                       //(因为物体有体积,一个物体往往在雷达里会生成多个靠近的点)
            grid pointGrid = new grid(mergeDistance, Math.Max(maxX, maxY), oneRadarMaxnumber * radars.Count);

            Cursor2D.set(maxX, maxY);                                  //设置融合操作

            int frame = 0;

            way.dtime = 1000.0f / 60.0f;                               //雷达数据的更新频率,为60帧每秒
            for (int i = 0; i < radars.Count; i++)
            {
                radars[i].start();                                     //雷达开启扫描
            }
            while (true)                                               //雷达获取数据和数据的操作
            {
                way.operation(ref radars, pointGrid, management, ref x, ref frame, oneRadarMaxnumber);
            }

            for (int i = 0; i < radars.Count; i++)
            {
                radars[i].close();
            }
        }
Example #2
0
        public static float dtime;                                    //更新间隔时间
        //Operation先判断时间流逝是否大于更新间隔时间,只有大于时间间隔才执行下面操作
        //将每个雷达获取的xy坐标点数据添加到pointGrid中,启用combine方法合并点数据后,传入到management进行鼠标信息的更新
        //然后对cursor2Dset里的每一个鼠标用single生成set信息,添加到multi里
        //对所有鼠标用single生成alive信息并添加到multi里
        //用frame和single生成fseq信息,添加到multi里
        //最后用udpclient传递数据到客户端,并把frame加1。
        public static void operation(ref List <Radar> radar, grid pointGrid, Cursor2DManagement management, ref UdpClient x, ref int frame, int maxnumber)
        {
            if ((DateTime.Now - time).TotalMilliseconds >= dtime)
            {
                frame++;
                time = DateTime.Now;
                pointGrid.clear();
                for (int i = 0; i < radar.Count; i++)
                {
                    radar[i].xyUpdate(maxnumber);
                    radar[i].cutPointXY();
                    pointGrid.add(radar[i].getXYdata());
                }
                pointGrid.combine();
                management.update(ref pointGrid.pointList);
                multi.clear();

                for (int i = 0; i < management.cursor2Dset.Count; i++)
                {
                    single.setCur2DMessage(management.cursor2Dset[i]);
                    multi.add(single);
                }
                int[] alive = new int[management.cursor2Dset.Count];
                for (int i = 0; i < management.cursor2Dset.Count; i++)
                {
                    alive[i] = management.cursor2Dset[i].ID();
                }
                single.aliveCur2DMessage(ref alive);
                multi.add(single);
                single.fseqCur2DMessage(frame);
                multi.add(single);
                byte[] message = multi.getMessage();
                x.Send(message, message.Length);
            }
        }