Ejemplo n.º 1
0
        private void _receiveTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                string infoToAnalogDisplay = string.Empty;

                _receiveTimer.Stop();
                _socket.Receive(_receiveByteArray);
                //Konwersja bajtów na floaty
                for (int i = 0; i < _howManyAnalogs * sizeof(float); i += sizeof(float))
                {
                    _receiveAnalogs[i / sizeof(float)] = BitConverter.ToSingle(_receiveByteArray, i);
                }

                infoToAnalogDisplay += "roll: " + _receiveAnalogs[0] + "\n";
                infoToAnalogDisplay += "pitch: " + _receiveAnalogs[1] + "\n";
                infoToAnalogDisplay += "gaz: " + _receiveAnalogs[2] + "\n";
                infoToAnalogDisplay += "yaw: " + _receiveAnalogs[3] + "\n";

                //Wyodrębnianie komend
                for (int i = _howManyAnalogs * sizeof(float); i < _receiveByteArray.Length; ++i)
                {
                    _commandsArrayAsBytes[i - _howManyAnalogs * sizeof(float)] = _receiveByteArray[i];
                }
                #region TEST
                ////-----W CELACH TESTOWYCH-----
                //if (_commandsArrayAsBytes[0] != 0)
                //{
                //    int i = 10;
                //}
                ////----------------------------
                #endregion

                string intoToCommandDisplay = Drone.CommandsText(_commandsArrayAsBytes.BytesIntoBooleanArray());

                //Ten dispaczer jest po to, aby ten wątek miał dostęp do GUI
                this.Dispatcher.Invoke(() => { this.FromSimulatorTextBlock.Text = infoToAnalogDisplay; });
                if (intoToCommandDisplay != string.Empty)
                {
                    this.Dispatcher.Invoke(() => { this.FromSimulatorCommandsTextBlock.Text = intoToCommandDisplay; });
                }
                ////-----W CELACH TESTOWYCH-----
                //else
                //{
                //    this.Dispatcher.Invoke(() => { this.FromSimulatorCommandsTextBlock.Text = "*" +  this.FromSimulatorCommandsTextBlock.Text; });
                //}
                ////----------------------------

                _receiveTimer.Start();
            }
            catch (Exception exception)
            {
                //Gdyby się nie zastartował w traju
                _receiveTimer.Start();
                this.Dispatcher.Invoke(() => { this.FromSimulatorTextBlock.Text = exception.Message; });
                //Narazie zlewam tę sytuację, albowiem synchronizacja wątków i wgl nie działa
                //this.LogTextBlock.Text = exception.Message;
            }
        }