예제 #1
0
        /// <summary>
        /// Application's entry point, runs this Redbook example.
        /// </summary>
        public static void Main()
        {
            // Entry Point

            //gw

            if (System.Environment.GetCommandLineArgs().Length != 3)
            {
                Console.WriteLine("ERROR: Usage:  ViconProxy.exe <broadcast ip> <vicon_ip:vicon_port>");
                System.Environment.Exit(1);
                return;
            }

            //  Initialize vicon related stuff...
            Console.WriteLine("INFO: vicon init start...");
            MyClient = new ViconDataStreamSDK.DotNET.Client();

            //  Check if already connected...
            ViconDataStreamSDK.DotNET.Output_IsConnected output2 = MyClient.IsConnected();
            //if (!output2.Connected)
            //{
            //    Console.WriteLine("WARNING: That's weird, already connected...");
            //    System.Threading.Thread.Sleep(3);
            //}
            //else
            {

                //MyClient.Connect(VICON_ADDR);
                MyClient.Connect(System.Environment.GetCommandLineArgs()[2]);
                ;
                //  Better be connected now...
                ViconDataStreamSDK.DotNET.Output_IsConnected output3 = MyClient.IsConnected();
                if (!output3.Connected)
                {
                    Console.WriteLine("ERROR: Cannot connect to vicon.  Check that the system is on and Vicon software sees it.... ");
                    System.Environment.Exit(1);
                }
            }

            MyClient.EnableDeviceData();
            MyClient.EnableSegmentData();
            //MyClient.EnableUnlabeledMarkerData();

            MyClient.GetFrame();
            ViconDataStreamSDK.DotNET.Output_GetFrameNumber frame_no = MyClient.GetFrameNumber();
            MyClient.EnableMarkerData();
            ViconDataStreamSDK.DotNET.Output_IsUnlabeledMarkerDataEnabled Output4 = MyClient.IsUnlabeledMarkerDataEnabled();
            ViconDataStreamSDK.DotNET.Output_GetDeviceCount dc = MyClient.GetDeviceCount();
            Console.WriteLine("INFO: vicon init done...");

            //  Initialize udp socket broadcast related stuff...
            local_address = IPAddress.Parse(System.Environment.GetCommandLineArgs()[1]);
            local_ep = new IPEndPoint(local_address, 0);
            local_socket = new UdpClient(local_ep);
            simple_broadcast_address = IPAddress.Parse("255.255.255.255");
            simple_broadcast_ep = new IPEndPoint(simple_broadcast_address, DEFAULT_SIMPLE_BROADCAST_SERVER_PORT);
            json_broadcast_address = IPAddress.Parse("255.255.255.255");
            json_broadcast_ep = new IPEndPoint(json_broadcast_address, DEFAULT_JSON_BROADCAST_SERVER_PORT);

            //  Initialize tcp socket server related stuff...
            local_listener_address = IPAddress.Parse(System.Environment.GetCommandLineArgs()[1]);
            local_listener_ep = new IPEndPoint(local_listener_address, DEFAULT_LISTENER_SERVER_PORT);
            local_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            local_listener.Bind(local_listener_ep);
            local_listener.Listen(100);
            local_listener.Blocking = false;

            // Initialize timer stuff...
            timer_handler = new System.Timers.ElapsedEventHandler( timer_elapsed );
            timer = new System.Timers.Timer(10);  // TODO: should be arg...
            timer.Elapsed += timer_handler;
            timer.Enabled = true;
            timer.Start();

            //  start the app...
            //App.Run(new RedbookTorus());												// Run Our Example As A Windows Forms Application
            Application.Run();
        }
예제 #2
0
파일: Main.cs 프로젝트: gosha1128/NYU
        /// <summary>
        /// Application's entry point, runs this Redbook example.
        /// </summary>
        public static void Main()
        {
            // Entry Point
            bool raw_mode = false;

            //  See if we are explicitly setting reg/raw mode...
            if (System.Environment.GetCommandLineArgs().Length == 5)
            {
                // get reg/raw mode...
                String raw = System.Environment.GetCommandLineArgs()[3];
                if (raw == "1")
                {
                    Console.WriteLine("INFO: Starting raw mode.");
                    raw_mode = true;
                }
                //  get timer time...
                String tt = System.Environment.GetCommandLineArgs()[4];
                timer_time = int.Parse(tt);

            }
            else if (System.Environment.GetCommandLineArgs().Length == 4)
            {
                String raw = System.Environment.GetCommandLineArgs()[3];
                if (raw == "1")
                {
                    Console.WriteLine("INFO: Starting raw mode.");
                    raw_mode = true;
                }
             }
            // else the minimum num args are specified...
            else if (System.Environment.GetCommandLineArgs().Length != 3)
            {
                Quit("ERROR: Usage:  ViconProxy.exe <broadcast ip:port> <vicon_ip:vicon_port> <raw_mode_flag>", 1);
                return;
            }

            //  Parse broadcast address...
            String broadcast_addr = System.Environment.GetCommandLineArgs()[1];
            int broadcast_port = DEFAULT_JSON_BROADCAST_SERVER_PORT;
            //  If has colon, sep into addr and port...
            String[] parts = broadcast_addr.Split( new char[] {':'});
            if (parts.Length > 1)
            {
                broadcast_addr = parts[0];
                broadcast_port = int.Parse(parts[1]);
                Console.WriteLine(String.Format("INFO: overriding default json broadcast port -> {0}...", broadcast_port));
                System.Threading.Thread.Sleep(3000);
            }

            //  Initialize vicon related stuff...
            Console.WriteLine(String.Format("INFO: vicon init start -> {0} ...", System.Environment.GetCommandLineArgs()[2]));
            MyClient = new ViconDataStreamSDK.DotNET.Client();

            //  Check if already connected...
            ViconDataStreamSDK.DotNET.Output_IsConnected output2 = MyClient.IsConnected();
            //if (!output2.Connected)
            //{
            //    Console.WriteLine("WARNING: That's weird, already connected...");
            //    System.Threading.Thread.Sleep(3);
            //}
            //else
            {

                //MyClient.Connect(VICON_ADDR);

                MyClient.Connect(System.Environment.GetCommandLineArgs()[2]);
                ;
                //  Better be connected now...
                ViconDataStreamSDK.DotNET.Output_IsConnected output3 = MyClient.IsConnected();
                if (!output3.Connected)
                {
                    Quit("ERROR: Cannot connect to vicon.  Check that the system is on and Vicon software sees it.... ", 1);
                    return;
                }
            }

            MyClient.EnableDeviceData();
            MyClient.EnableSegmentData();

            if (raw_mode)
            {
                MyClient.EnableUnlabeledMarkerData();
            }

            MyClient.GetFrame();
            ViconDataStreamSDK.DotNET.Output_GetFrameNumber frame_no = MyClient.GetFrameNumber();
            MyClient.EnableMarkerData();
            ViconDataStreamSDK.DotNET.Output_IsUnlabeledMarkerDataEnabled Output4 = MyClient.IsUnlabeledMarkerDataEnabled();
            ViconDataStreamSDK.DotNET.Output_GetDeviceCount dc = MyClient.GetDeviceCount();
            Console.WriteLine("INFO: vicon init done...");

            //  Initialize udp socket broadcast related stuff...
            try
            {
                local_address = IPAddress.Parse(broadcast_addr);
                local_ep = new IPEndPoint(local_address, 0);
                local_socket = new UdpClient(local_ep);
                simple_broadcast_address = IPAddress.Parse("255.255.255.255");
                simple_broadcast_ep = new IPEndPoint(simple_broadcast_address, DEFAULT_SIMPLE_BROADCAST_SERVER_PORT);
                json_broadcast_address = IPAddress.Parse("255.255.255.255");
                json_broadcast_ep = new IPEndPoint(json_broadcast_address, broadcast_port);

                //  Initialize tcp socket server related stuff...
                local_listener_address = IPAddress.Parse(broadcast_addr);
                local_listener_ep = new IPEndPoint(local_listener_address, DEFAULT_LISTENER_SERVER_PORT);
                local_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                local_listener.Bind(local_listener_ep);
                local_listener.Listen(100);
                local_listener.Blocking = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Quit("ERROR: Something went wrong with setting up sockets...", 1);
                return;
            }

            // Initialize timer stuff...
            if (raw_mode)
            {
                timer_handler = new System.Timers.ElapsedEventHandler(timer_elapsed_raw);
            }
            else
            {
                timer_handler = new System.Timers.ElapsedEventHandler(timer_elapsed);
            }
            timer = new System.Timers.Timer(timer_time);  // TODO: should be arg...
            timer.Elapsed += timer_handler;
            timer.Enabled = true;
            timer.Start();

            //  start the app...
            //App.Run(new RedbookTorus());												// Run Our Example As A Windows Forms Application
            Application.Run();
        }