Esempio n. 1
0
        static void StartLoop(OscReceiver oscReceiver)
        {
            // Variables
            OscPacket     packet   = null;
            HeightData    height_Z = new HeightData();
            StringBuilder sb       = new StringBuilder();
            Stopwatch     sw       = new Stopwatch();

            string[]     extractData;
            const string START_LINE             = "/position";
            bool         connectionNotification = true;
            int          count  = 0;
            const int    CYCLES = 200;

            // Attempt to establish an OSC connection
            try
            {
                sw.Start();
                do
                {
                    if (oscReceiver.State == OscSocketState.Connected)
                    {
                        if (connectionNotification)
                        {
                            Console.WriteLine("connection established");
                            connectionNotification = false;
                        }

                        // Attempt receive OSC packet
                        if (oscReceiver.TryReceive(out packet))
                        {
                            // Extract position data from OSC packet
                            if (packet.ToString().StartsWith(START_LINE))
                            {
                                extractData = packet.ToString().Split(',');
                                int zValue = int.Parse(extractData[4]);    // Extract 'z' position value (height)
                                Console.WriteLine("{4} - Position:\tx:{0}, y:{1}, z:{2}, \tZ_ERROR:{3} ]", extractData[2], extractData[3], extractData[4], height_Z.GetError(zValue), count);
                                sb.AppendLine(string.Format("{0},{1},{2}", extractData[2], extractData[3], extractData[4]));
                                count++;
                            }
                        }
                    }
                } while (count < CYCLES);
                sw.Stop();
                Console.WriteLine("TOTAL COUNT: " + count);
                Console.WriteLine("TOTAL TIME: " + sw.ElapsedMilliseconds / 1000);
                Console.WriteLine(count / (sw.ElapsedMilliseconds / 1000) + " Hz");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Error average: {0}", height_Z.GetErrorAverage());
            FILE_IO.WriteLog(sb.ToString());
        }
Esempio n. 2
0
        private OscPacket RetryRecieveOSC(int timeout)
        {
            int       startTime     = (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds;
            int       currentTimeMS = startTime;
            int       timeElapsed   = 0;
            OscPacket packet        = null;

            while (timeElapsed < timeout && !_reciever.TryReceive(out packet))
            {
                currentTimeMS = (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds;
                timeElapsed   = currentTimeMS - startTime;
            }
            return(packet);
        }
    // Update is called once per frame
    void Update()
    {
        int i = 0;

        // if we are in a state to recieve
        while (i++ < MaxMessagesToProcessPerFrame &&
               m_Receiver.State == OscSocketState.Connected)
        {
            OscPacket packet;

            // get the next message this will not block
            if (m_Receiver.TryReceive(out packet) == false)
            {
                return;
            }

            switch (m_Manager.ShouldInvoke(packet))
            {
            case OscPacketInvokeAction.Invoke:
                // Debug.Log ("Received packet");
                m_Manager.Invoke(packet);
                break;

            case OscPacketInvokeAction.DontInvoke:
                Debug.LogWarning("Cannot invoke");
                Debug.LogWarning(packet.ToString());
                break;

            case OscPacketInvokeAction.HasError:
                Debug.LogError("Error reading osc packet, " + packet.Error);
                Debug.LogError(packet.ErrorMessage);
                break;

            case OscPacketInvokeAction.Pospone:
                Debug.Log("Posponed bundle");
                Debug.Log(packet.ToString());
                break;

            default:
                break;
            }
        }
    }
Esempio n. 4
0
        private void Listen_Tick(object sender, EventArgs e)
        {
            // if we are in a state to recieve
            if (m_Receiver != null &&
                m_Receiver.State == OscSocketState.Connected)
            {
                OscPacket packet;

                // try and get the next message
                while (m_Receiver.TryReceive(out packet) == true)
                {
                    if (packet.Error == OscPacketError.None)
                    {
                        // write the message to the output
                        AppendLine(packet.ToString());
                    }
                    else
                    {
                        AppendLine("Error reading packet, " + packet.Error);
                        AppendLine(packet.ErrorMessage);
                    }
                }
            }
        }
Esempio n. 5
0
        static void StartLoop(OscReceiver oscReceiver)
        {
            // Create Moving Average objects for each data value (x, y, z, p, r, yw)
            //MovingAverage maX = new MovingAverage(5);
            //MovingAverage maY = new MovingAverage(5);
            //MovingAverage maZ = new MovingAverage(5);
            MovingAverage maP    = new MovingAverage(5);
            MovingAverage maR    = new MovingAverage(5);
            MovingAverage maYw   = new MovingAverage(5, true);
            OscPacket     packet = null;

            string[]     extractData;
            const string START_LINE             = "/position";
            const int    MAX_TIME_ELAPSED       = 10000; // 10 seconds
            bool         connectionNotification = true;
            Stopwatch    sw = new Stopwatch();

            // Attempt to establish an OSC connection
            try
            {
                // Start stopwatch
                sw.Start();

                do
                {
                    if (oscReceiver.State == OscSocketState.Connected)
                    {
                        if (connectionNotification)
                        {
                            Console.WriteLine("connection established");
                            connectionNotification = false;
                        }

                        // Attempt receive OSC packet
                        if (oscReceiver.TryReceive(out packet))
                        {
                            sw.Reset();
                            sw.Start();

                            // Extract position data from OSC packet
                            if (packet.ToString().StartsWith(START_LINE))
                            {
                                extractData = packet.ToString().Split(',');
                                //maX.SmoothOrientationData(extractData[2], Values.X);
                                //maY.SmoothOrientationData(extractData[3], Values.Y);
                                //maZ.SmoothOrientationData(extractData[4], Values.Z);
                                maP.SmoothOrientationData(extractData[5], Values.P);
                                maR.SmoothOrientationData(extractData[6], Values.R);
                                maYw.SmoothOrientationData(extractData[7], Values.Yw);
                            }
                        }
                    }
                } while (sw.ElapsedMilliseconds < MAX_TIME_ELAPSED);
                sw.Stop();
                Console.WriteLine("No OSC packets detected after {0} seconds", sw.ElapsedMilliseconds / 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }