예제 #1
0
        private void UDPMessageHandler(NetInMessage message)
        {
            int commandInt = message.ReadInt32();

            MessageType.Command command = (MessageType.Command)commandInt;
            if (command == MessageType.Command.Control)
            {
                MessageType.ControlType controlType = (MessageType.ControlType)message.ReadInt32();
                if ((controlType == MessageType.ControlType.Start) || (controlType == MessageType.ControlType.Next))
                {
                    int activeFingerIndex = message.ReadInt32();
                    for (int i = 0; i < fingerIndicators.Count; i++)
                    {
                        fingerIndicators[i].SetIsOn(i == activeFingerIndex);
                        fingerIndicators[i].IsVisible = (i == activeFingerIndex);
                    }

                    for (int i = 0; i < fingerBarGraphs.Count; i++)
                    {
                        int    fingerIndex = message.ReadInt32();
                        double targetForce = message.ReadDouble();

                        fingerBarGraphs[fingerIndex].targetValue = targetForce;
                    }
                }
                else if (controlType == MessageType.ControlType.Stop)
                {
                    ResetIndicators();
                    ResetGraphValues();
                }
            }
            else if (command == MessageType.Command.Data)
            {
                for (int i = 0; i < fingerBarGraphs.Count; i++)
                {
                    int   fingerIndex = message.ReadInt32();
                    float plotValue   = message.ReadFloat();

                    fingerBarGraphs[fingerIndex].value = plotValue;
                }
            }
        }
        private void UDPMessageReceived(NetInMessage message)
        {
            MessageType.Command commandType = (MessageType.Command)message.ReadInt32();
            if (commandType == MessageType.Command.Data)
            {
                if (m_isRunning)
                {
                    float timeX       = message.ReadFloat();
                    float valueToPlot = message.ReadFloat();
                    lineGraph.Plot(timeX, valueToPlot, Constants.FORCE_PLOT_SERIES_NAME);
                }
            }
            else if (commandType == MessageType.Command.Control)
            {
                MessageType.ControlType controlType = (MessageType.ControlType)message.ReadInt32();
                if (controlType == MessageType.ControlType.Start)
                {
                    m_isRunning = true;
                    m_time      = 0.0f;

                    ClearIndicators();
                    HideIndicators();

                    int numFingersToPress = message.ReadInt32();
                    for (int i = 0; i < numFingersToPress; i++)
                    {
                        int       fingerIndex = message.ReadInt32();
                        Indicator indicator   = GetFingerIndicator((Finger)fingerIndex);
                        if (indicator != null)
                        {
                            indicator.IsVisible = true;
                            indicator.SetIsOn(true);
                        }
                    }

                    double maximumPlotValue        = message.ReadDouble();
                    float  staticPhaseDuration     = message.ReadFloat();
                    float  increasingPhaseDuration = message.ReadFloat();
                    float  plateauPhaseDuration    = message.ReadFloat();
                    float  decreasingPhaseDuration = message.ReadFloat();
                    float  staticEndPhaseDuration  = message.ReadFloat();

                    double plateauPhaseValue = message.ReadDouble();

                    float measurementDuration = staticPhaseDuration +
                                                increasingPhaseDuration +
                                                plateauPhaseDuration +
                                                decreasingPhaseDuration +
                                                staticEndPhaseDuration;

                    lineGraph.maxX = measurementDuration;
                    lineGraph.maxY = (float)maximumPlotValue;
                    lineGraph.Refresh();

                    lineGraph.ClearPlot(Constants.TARGET_FORCE_PLOT_SERIES_NAME);
                    lineGraph.ClearPlot(Constants.FORCE_PLOT_SERIES_NAME);

                    float timeStamp = 0.0f;
                    lineGraph.Plot(0.0f, 0.0f, Constants.TARGET_FORCE_PLOT_SERIES_NAME);

                    timeStamp += staticPhaseDuration;
                    lineGraph.Plot(timeStamp, 0.0f, Constants.TARGET_FORCE_PLOT_SERIES_NAME);

                    timeStamp += increasingPhaseDuration;
                    lineGraph.Plot(timeStamp, plateauPhaseValue, Constants.TARGET_FORCE_PLOT_SERIES_NAME);

                    timeStamp += plateauPhaseDuration;
                    lineGraph.Plot(timeStamp, plateauPhaseValue, Constants.TARGET_FORCE_PLOT_SERIES_NAME);

                    timeStamp += decreasingPhaseDuration;
                    lineGraph.Plot(timeStamp, 0.0f, Constants.TARGET_FORCE_PLOT_SERIES_NAME);

                    timeStamp += staticEndPhaseDuration;
                    lineGraph.Plot(timeStamp, 0.0f, Constants.TARGET_FORCE_PLOT_SERIES_NAME);

                    m_time = 0.0f;
                }
                else if (controlType == MessageType.ControlType.Stop)
                {
                    m_isRunning = false;

                    ClearIndicators();
                    HideIndicators();
                }
            }
        }