Esempio n. 1
0
        /// <summary>
        /// Show or fix the setting
        /// </summary>
        /// <param name="message">Warning message</param>
        /// <param name="fixAction"></param>
        /// <param name="silentFix">false: show warning and fix button, true: fix without showing</param>
        private void FixSetting(string message, FixMethod fixAction, bool silentFix = false)

        {
            if (silentFix)
            {
                // Fix
                fixAction.Invoke();
            }
            else
            {
                // Show the message and a fix button
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox(message, MessageType.Warning, true);
                GUILayout.FlexibleSpace();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.Space();
                if (GUILayout.Button("Fix", GUILayout.Width(60f)))
                {
                    fixAction.Invoke();
                }
                //GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="language"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        public string Fix(LanguageOption language, string line)
        {
            FixMethod method = null;

            if (language == LanguageOption.GenerateCSharpCode)
            {
                method = _CSFixMethods[(int)Type];
            }
            else if (language == LanguageOption.GenerateVBCode)
            {
                method = _VBFixMethods[(int)Type];
            }

            if (method != null)
            {
                line = method(line);
            }

            return(line);
        }
Esempio n. 3
0
        protected Emulator(string name)
        {
            _Name = name;

            // Create new buffers for reading and writing
            _ReadBuffer  = new List <byte>(_DefaultReadBufferSize);
            _WriteBuffer = new List <byte>(_DefaultWriteBufferSize);

            // Initialize simulated values
            _ReadDataAvailableWaitHandle  = new ManualResetEvent(false);
            _WriteDataAvailableWaitHandle = new ManualResetEvent(false);
            _EmulationIntervalWaitHandle  = new ManualResetEvent(false);

            // Default timeouts for reading and writing
            _ReadTimeout  = _DefaultReadTimeout;
            _WriteTimeout = _DefaultWriteTimeout;

            // Simulated values
            _seed            = new Random();
            _UtcDateTime     = DateTime.UtcNow;
            _CurrentPosition = Positioning.Position.Empty;
            _Altitude        = Distance.FromFeet(1000);
            _Route           = new List <Position>();
            _Satellites      = new List <Satellite>();
            _FixQuality      = FixQuality.GpsFix;
            _FixMode         = FixMode.Automatic;
            _FixMethod       = FixMethod.Fix3D;
            _FixStatus       = FixStatus.Fix;
            _HorizontalDop   = DilutionOfPrecision.Good;
            _VerticalDop     = DilutionOfPrecision.Good;
            _MeanDop         = DilutionOfPrecision.Good;

            _Speed     = Speed.FromStatuteMilesPerHour(20);
            _speedLow  = Speed.FromKilometersPerSecond(10).Value;
            _speedHigh = Speed.FromKilometersPerSecond(25).Value;

            _Bearing      = Azimuth.Southwest;
            _bearingStart = _seed.NextDouble() * 360;
            _bearingArc   = 10;
        }
Esempio n. 4
0
        protected Emulator(string name)
        {
            _Name = name;

            // Create new buffers for reading and writing
            _ReadBuffer = new List<byte>(_DefaultReadBufferSize);
            _WriteBuffer = new List<byte>(_DefaultWriteBufferSize);

            // Initialize simulated values
            _ReadDataAvailableWaitHandle = new ManualResetEvent(false);
            _WriteDataAvailableWaitHandle = new ManualResetEvent(false);
            _EmulationIntervalWaitHandle = new ManualResetEvent(false);

            // Default timeouts for reading and writing
            _ReadTimeout = _DefaultReadTimeout;
            _WriteTimeout = _DefaultWriteTimeout;
            
            // Simulated values
            _seed = new Random();
            _UtcDateTime = DateTime.UtcNow;
            _CurrentPosition = GeoFramework.Position.Empty;            
            _Altitude = Distance.FromFeet(1000);
            _Route = new List<Position>();
            _Satellites = new List<Satellite>();
            _FixQuality = FixQuality.GpsFix;
            _FixMode = FixMode.Automatic;
            _FixMethod = FixMethod.Fix3D;
            _FixStatus = FixStatus.Fix;
            _HorizontalDop = DilutionOfPrecision.Good;
            _VerticalDop = DilutionOfPrecision.Good;
            _MeanDop = DilutionOfPrecision.Good;

            _Speed = Speed.FromStatuteMilesPerHour(20);
            _speedLow = Speed.FromKilometersPerSecond(10).Value;
            _speedHigh = Speed.FromKilometersPerSecond(25).Value;

            _Bearing = Azimuth.Southwest;
            _bearingStart = _seed.NextDouble() * 360;
            _bearingArc = 10;

        }
Esempio n. 5
0
 /// <summary>
 /// Creates a new instance with the specified fix method.
 /// </summary>
 /// <param name="fixMethod">A value from the <strong>FixMethod</strong> enumeration.</param>
 /// <remarks></remarks>
 public FixMethodEventArgs(FixMethod fixMethod)
 {
     _FixMethod = fixMethod;
 }
		/// <summary>
		/// Creates a new instance with the specified fix method.
		/// </summary>
		/// <param name="fixMethod">A value from the <strong>FixMethod</strong> enumeration.</param>
		/// <remarks></remarks>
		public FixMethodEventArgs(FixMethod fixMethod)
		{
			_FixMethod = fixMethod;
		}
Esempio n. 7
0
        /// <summary>
        /// Creates a new GpgsaSentence
        /// </summary>
        /// <param name="fixMode">The fix mode.</param>
        /// <param name="fixMethod">The fix method.</param>
        /// <param name="satellites">The satellites.</param>
        /// <param name="positionDilutionOfPrecision">The position dilution of precision.</param>
        /// <param name="horizontalDilutionOfPrecision">The horizontal dilution of precision.</param>
        /// <param name="verticalDilutionOfPrecision">The vertical dilution of precision.</param>
        public GpgsaSentence(FixMode fixMode, FixMethod fixMethod, IEnumerable <Satellite> satellites, DilutionOfPrecision positionDilutionOfPrecision,
                             DilutionOfPrecision horizontalDilutionOfPrecision, DilutionOfPrecision verticalDilutionOfPrecision)
        {
            // Use a string builder to create the sentence text
            StringBuilder builder = new StringBuilder(128);

            // Append the command word
            builder.Append("$GPGSA");
            builder.Append(',');

            switch (fixMode)
            {
            case FixMode.Automatic:
                builder.Append("A");
                break;

            default:
                builder.Append("M");
                break;
            }
            builder.Append(',');

            switch (fixMethod)
            {
            case FixMethod.Fix2D:
                builder.Append("2");
                break;

            case FixMethod.Fix3D:
                builder.Append("3");
                break;

            default:
                builder.Append("1");
                break;
            }
            builder.Append(',');

            #region Fixed satellites

            /* A comma-delimited list of satellites involved in a fix. Up to 12 satellites can be serialized.
             * This one concerns me, because while the limit is 12, ever more satellites are being launched.
             * Should we just serialize everything??
             */

            // Get a count of satellites to write, up to 123. We'll scrub the list to ensure only fixed satellites are written
            int fixedSatellitesWritten = 0;
            foreach (Satellite item in satellites)
            {
                // Is it fixed?
                if (item.IsFixed)
                {
                    // Yes.  It cannot have babies
                    builder.Append(item.PseudorandomNumber.ToString(NmeaCultureInfo));

                    // Append a comma
                    builder.Append(",");

                    // Update the count
                    fixedSatellitesWritten++;

                    // If we're at 12, that's the limit. Stop here
                    if (fixedSatellitesWritten == 12)
                    {
                        break;
                    }
                }
            }

            // If we wrote less than 12 satellites, write commas for the remainder
            for (int index = 0; index < 12 - fixedSatellitesWritten; index++)
            {
                builder.Append(",");
            }

            #endregion Fixed satellites

            // NOTE: Commas have been written at this point

            // Position Dilution of Precision
            builder.Append(positionDilutionOfPrecision.Value.ToString(NmeaCultureInfo));
            builder.Append(",");

            // Horizontal Dilution of Precision
            builder.Append(horizontalDilutionOfPrecision.Value.ToString(NmeaCultureInfo));
            builder.Append(",");

            // Vertical Dilution of Precision
            builder.Append(verticalDilutionOfPrecision.Value.ToString(NmeaCultureInfo));

            // Set this object's sentence
            Sentence = builder.ToString();
            SetPropertiesFromSentence();

            // Finally, append the checksum
            AppendChecksum();
        }
Esempio n. 8
0
        public GpgsaSentence(FixMode fixMode, FixMethod fixMethod, IList<Satellite> satellites,
            DilutionOfPrecision positionDilutionOfPrecision,
            DilutionOfPrecision horizontalDilutionOfPrecision,
            DilutionOfPrecision verticalDilutionOfPrecision)
        {
            // Use a string builder to create the sentence text
            StringBuilder builder = new StringBuilder(128);

            // Append the command word
            builder.Append("$GPGSA");

            // Append a comma
            builder.Append(',');

            #region Append the fix method

            switch (_FixMode)
            {
                case FixMode.Automatic:
                    builder.Append("A");
                    break;
                default:
                    builder.Append("M");
                    break;
            }

            #endregion

            // Append a comma
            builder.Append(',');
        
            #region Append the fix method

            switch (_FixMethod)
            {
                case FixMethod.Fix2D:
                    builder.Append("2");
                    break;
                case FixMethod.Fix3D:
                    builder.Append("3");
                    break;
                default:
                    builder.Append("1");
                    break;
            }

            #endregion

            // Append a comma
            builder.Append(',');

            #region Fixed satellites

            /* A comma-delimited list of satellites involved in a fix.  Up to 12 satellites can be serialized.
             * This one concerns me, because while the limit is 12, ever more satellites are being launched.
             * Should we just serialize everything??
             */

            // Get a count of satellites to write, up to 123.  We'll scrub the list to ensure only fixed satellites are written
            int fixedSatellitesWritten = 0;
            for(int index = 0; index < satellites.Count; index++)
            {
                // Get the satellite
                Satellite item = satellites[index];

                // Is it fixed?
                if(item.IsFixed)
                {
                    // Yes.  It cannot have babies
                    builder.Append(item.PseudorandomNumber.ToString(NmeaCultureInfo));

                    // Append a comma
                    builder.Append(",");

                    // Update the count
                    fixedSatellitesWritten++;

                    // If we're at 12, that's the limit.  Stop here
                    if(fixedSatellitesWritten == 12)
                        break;
                }
            }

            // If we wrote less than 12 satellites, write commas for the remainder
            for(int index = 0; index < 12 - fixedSatellitesWritten; index++)
                builder.Append(",");

            #endregion

            // NOTE: Commas have been written at this point

            // Position Dilution of Precision
            builder.Append(positionDilutionOfPrecision.Value.ToString(NmeaCultureInfo));

            // Append a comma
            builder.Append(",");

            // Horizontal Dilution of Precision
            builder.Append(horizontalDilutionOfPrecision.Value.ToString(NmeaCultureInfo));

            // Append a comma
            builder.Append(",");

            // Vertical Dilution of Precision
            builder.Append(verticalDilutionOfPrecision.Value.ToString(NmeaCultureInfo));

            // Set this object's sentence
            SetSentence(builder.ToString());

            // Finally, append the checksum
            AppendChecksum();
        }
Esempio n. 9
0
        protected override void OnSentenceChanged()
        {
            // First, process the basic info for the sentence
            base.OnSentenceChanged();

            // Cache the sentence words
            string[] words = base.Words;
            int wordCount = words.Length;

            #region Fix mode

            if (wordCount >= 1 && words[0].Length != 0)
            {
                switch (words[0])
                {
                    case "A":
                        _FixMode = FixMode.Automatic;
                        break;
                    case "M":
                        _FixMode = FixMode.Manual;
                        break;
                    default:
                        _FixMode = FixMode.Unknown;
                        break;
                }
            }
            else
            {
                _FixMode = FixMode.Unknown;
            }

            #endregion

            #region Fix method

            // Get the fix quality information
            if (wordCount >= 2 && words[1].Length != 0)
            {
                switch (words[1])
                {
                    case "1":
                        _FixMethod = FixMethod.NoFix;
                        break;
                    case "2":
                        _FixMethod = FixMethod.Fix2D;
                        break;
                    case "3":
                        _FixMethod = FixMethod.Fix3D;
                        break;
                    default:
                        _FixMethod = FixMethod.Unknown;
                        break;
                }
            }
            else
            {
                _FixMethod = FixMethod.Unknown;
            }

            #endregion

            #region Fixed satellites

            if (wordCount >= 3)
            {
                // The sentence supports up to 12 satellites
                _FixedSatellites = new List<Satellite>(12);

                // Get each satellite PRN number
                int count = wordCount < 14 ? wordCount : 14;
                for (int index = 2; index < count; index++)
                    // Is the word empty?
                    if (words[index].Length != 0)
                        // No.  Add a satellite
                        _FixedSatellites.Add(
                            // We'll only have an empty object for now
                            new Satellite(int.Parse(words[index], NmeaCultureInfo)));
            }

            #endregion

            #region Dilution of Precision

            // Set overall dilution of precision
            if (wordCount >= 15 && words[14].Length != 0)
                _PositionDop = new DilutionOfPrecision(float.Parse(words[14], NmeaCultureInfo));
            else
                _PositionDop = DilutionOfPrecision.Invalid;

            // Set horizontal dilution of precision
            if (wordCount >= 16 && words[15].Length != 0)
                _HorizontalDop = new DilutionOfPrecision(float.Parse(words[15], NmeaCultureInfo));
            else
                _HorizontalDop = DilutionOfPrecision.Invalid;

            // Set vertical dilution of precision
            if (wordCount >= 17 && words[16].Length != 0)
                _VerticalDop = new DilutionOfPrecision(float.Parse(words[16], NmeaCultureInfo));
            else
                _VerticalDop = DilutionOfPrecision.Invalid;

            #endregion
        }
Esempio n. 10
0
        /// <summary>
        /// Called when [sentence changed].
        /// </summary>
        protected override void OnSentenceChanged()
        {
            // First, process the basic info for the sentence
            base.OnSentenceChanged();

            // Cache the sentence words
            string[] words     = Words;
            int      wordCount = words.Length;

            #region Fix mode

            if (wordCount >= 1 && words[0].Length != 0)
            {
                switch (words[0])
                {
                case "A":
                    _fixMode = FixMode.Automatic;
                    break;

                case "M":
                    _fixMode = FixMode.Manual;
                    break;

                default:
                    _fixMode = FixMode.Unknown;
                    break;
                }
            }
            else
            {
                _fixMode = FixMode.Unknown;
            }

            #endregion Fix mode

            #region Fix method

            // Get the fix quality information
            if (wordCount >= 2 && words[1].Length != 0)
            {
                switch (words[1])
                {
                case "1":
                    _fixMethod = FixMethod.NoFix;
                    break;

                case "2":
                    _fixMethod = FixMethod.Fix2D;
                    break;

                case "3":
                    _fixMethod = FixMethod.Fix3D;
                    break;

                default:
                    _fixMethod = FixMethod.Unknown;
                    break;
                }
            }
            else
            {
                _fixMethod = FixMethod.Unknown;
            }

            #endregion Fix method

            #region Fixed satellites

            if (wordCount >= 3)
            {
                // The sentence supports up to 12 satellites
                _fixedSatellites = new List <Satellite>(12);

                // Get each satellite PRN number
                int count = wordCount < 14 ? wordCount : 14;
                for (int index = 2; index < count; index++)
                {
                    // Is the word empty?
                    if (words[index].Length != 0)
                    {
                        // No.  Add a satellite
                        _fixedSatellites.Add(
                            // We'll only have an empty object for now
                            new Satellite(int.Parse(words[index], NmeaCultureInfo)));
                    }
                }
            }

            #endregion Fixed satellites

            #region Dilution of Precision

            // Set overall dilution of precision
            if (wordCount >= 15 && words[14].Length != 0)
            {
                _positionDop = new DilutionOfPrecision(float.Parse(words[14], NmeaCultureInfo));
            }
            else
            {
                _positionDop = DilutionOfPrecision.Invalid;
            }

            // Set horizontal dilution of precision
            if (wordCount >= 16 && words[15].Length != 0)
            {
                _horizontalDop = new DilutionOfPrecision(float.Parse(words[15], NmeaCultureInfo));
            }
            else
            {
                _horizontalDop = DilutionOfPrecision.Invalid;
            }

            // Set vertical dilution of precision
            if (wordCount >= 17 && words[16].Length != 0)
            {
                _verticalDop = new DilutionOfPrecision(float.Parse(words[16], NmeaCultureInfo));
            }
            else
            {
                _verticalDop = DilutionOfPrecision.Invalid;
            }

            #endregion Dilution of Precision
        }
Esempio n. 11
0
        /// <summary>
        /// Updates the fix method to the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        protected virtual void SetFixMethod(FixMethod value)
        {
            // If the new value is the same or it's invalid, ignore it
            if (value == _fixMethod || value == FixMethod.Unknown)
                return;

            // Set the new value
            _fixMethod = value;

            // And notify
            if (FixMethodChanged != null)
                FixMethodChanged(this, new FixMethodEventArgs(_fixMethod));
        }