Exemple #1
0
        // called every time a event is broad casted from QTM server.
        public void Events(RTPacket packet)
        {
            QTMEvent currentEvent = packet.GetEvent();

            Debug.Log("Event occurred! : " + currentEvent);

            if (currentEvent == QTMEvent.EventRTFromFileStarted)
            {
                // reload settings when we start streaming to get proper settings
                Debug.Log("Reloading Settings");

                Get3DSettings();
                Get6DOFSettings();
            }
        }
Exemple #2
0
 /// <summary>Get latest event from QTM server</summary>
 /// <param name="respondedEvent">even from qtm</param>
 /// <returns>true if command was sent successfully</returns>
 public bool GetState(out QTMEvent respondedEvent)
 {
     if (SendString("GetState", PacketType.PacketCommand))
     {
         int        nReceived;
         PacketType packetType;
         do
         {
             nReceived = ReceiveRTPacket(out packetType, false, 2000000);
             if (nReceived > 0)
             {
                 respondedEvent = mPacket.GetEvent();
                 return(true);
             }
         }while (nReceived > 0);
     }
     respondedEvent = QTMEvent.EventNone;
     return(false);
 }
Exemple #3
0
        // called every time a event is broadcasted from QTM server.
        public void Events(RTPacket packet)
        {
            QTMEvent currentEvent = packet.GetEvent();

            Debug.Log("Event occurred! : " + currentEvent);

            if (currentEvent == QTMEvent.EventRTFromFileStarted ||
                currentEvent == QTMEvent.EventConnected ||
                currentEvent == QTMEvent.EventCaptureStarted ||
                currentEvent == QTMEvent.EventCalibrationStarted)
            {
                // reload settings when we start streaming to get proper settings
                Debug.Log("Reloading settings from QTM");

                Get3DSettings();
                Get6DOFSettings();
                GetGazeVectorSettings();
            }
        }
        void WriterThreadFunction()
        {
            try
            {
                using (var rtProtocol = new RTProtocol(RT_LOWEST_SUPPORTED_VERSION_MAJOR, RT_LOWEST_SUPPORTED_VERSION_MINOR))
                {
                    if (!rtProtocol.Connect(IpAddress, udpPort, RT_LOWEST_SUPPORTED_VERSION_MAJOR, RT_LOWEST_SUPPORTED_VERSION_MINOR))
                    {
                        throw new WriterThreadException("Error Creating Connection to server" + rtProtocol.GetErrorString());
                    }

                    RtProtocolVersion version = new RtProtocolVersion(RTProtocol.Constants.MAJOR_VERSION, RTProtocol.Constants.MINOR_VERSION);

                    //Upgrade protocol version
                    for (; version.minor >= RT_LOWEST_SUPPORTED_VERSION_MINOR; --version.minor)
                    {
                        lock (syncLock)
                        {
                            writerThreadState.rtProtocolVersion.CopyFrom(version);
                        }
                        string response;
                        if (rtProtocol.SetVersion(version.major, version.minor, out response))
                        {
                            break;
                        }
                    }

                    if (version.minor < RT_LOWEST_SUPPORTED_VERSION_MINOR)
                    {
                        throw new WriterThreadException("Failed to negotiate RT Protocol version with QTM");
                    }

                    lock (syncLock)
                    {
                        writerThreadState.connectionState = RTConnectionState.Connected;
                        if (!UpdateSettings(writerThreadState, rtProtocol, componentSelection))
                        {
                            throw new WriterThreadException("Failed to update settings: " + rtProtocol.GetErrorString());
                        }

                        if (!StartStreaming(writerThreadState, rtProtocol, streamRate, udpPort))
                        {
                            throw new WriterThreadException("Failed to start stream: " + rtProtocol.GetErrorString());
                        }
                    }


                    while (true)
                    {
                        if (!rtProtocol.IsConnected())
                        {
                            throw new WriterThreadException("Connection lost");
                        }

                        if (killThread)
                        {
                            throw new WriterThreadException("Thread was killed");
                        }

                        PacketType packetType;
                        if (rtProtocol.ReceiveRTPacket(out packetType, false) <= 0)
                        {
                            continue;
                        }

                        var packet = rtProtocol.GetRTPacket();
                        if (packet != null)
                        {
                            if (packetType == PacketType.PacketData)
                            {
                                lock (syncLock)
                                {
                                    Process(writerThreadState, packet);
                                }
                            }
                            else if (packetType == PacketType.PacketEvent)
                            {
                                QTMEvent currentEvent = packet.GetEvent();
                                switch (currentEvent)
                                {
                                case QTMEvent.QTMShuttingDown:
                                    throw new WriterThreadException("Qtm closed connection");

                                case QTMEvent.RTFromFileStarted:
                                case QTMEvent.Connected:
                                case QTMEvent.CaptureStarted:
                                case QTMEvent.CalibrationStarted:
                                case QTMEvent.CameraSettingsChanged:
                                    lock (syncLock)
                                    {
                                        // reload settings when we start streaming to get proper settings
                                        if (!UpdateSettings(writerThreadState, rtProtocol, componentSelection))
                                        {
                                            throw new WriterThreadException("Failed to update settings: " + rtProtocol.GetErrorString());
                                        }

                                        if (!StartStreaming(writerThreadState, rtProtocol, streamRate, udpPort))
                                        {
                                            throw new WriterThreadException("Failed to start stream: " + rtProtocol.GetErrorString());
                                        }
                                    }
                                    break;

                                case QTMEvent.ConnectionClosed:
                                default: break;
                                }
                            }
                        }
                    }
                }
            }
            catch (WriterThreadException writerThreadException)
            {
                lock (syncLock)
                {
                    writerThreadState.errorString     = writerThreadException.Message;
                    writerThreadState.connectionState = RTConnectionState.Disconnected;
                }
            }
            catch (System.Exception e)
            {
                lock (syncLock)
                {
                    writerThreadState.errorString = "Exception "
                                                    + e.GetType().Name + ": " + e.Message + "\n"
                                                    + e.StackTrace.Replace(" at ", "\n at ");

                    writerThreadState.connectionState = RTConnectionState.Disconnected;
                }
            }
        }
 /// <summary>
 /// Get latest event from QTM server
 ///</summary>
 /// <param name="respondedEvent">even from qtm</param>
 /// <returns>true if command was sent successfully</returns>
 public bool GetState(out QTMEvent respondedEvent)
 {
     if (SendCommand("GetState"))
     {
         respondedEvent = mPacket.GetEvent();
         return true;
     }
     respondedEvent = QTMEvent.EventNone;
     return false;
 }