Beispiel #1
0
        ///     Output a Wind Heading and velocity sentence with this format:
        ///     MWV,x.x,R,v.v,M,A
        ///     x.x = relative heading of the wind
        ///     R = relative
        ///     v.v = the wind velocity in MPH
        ///     M/N/K = mph, knots, kph
        private void ParseWindSpeedAndVelocity(string talkerId, string[] words, string sentence)
        {
            if (words.Length != 6)
            {
                DebugLog.WriteLine("invalid MWV sentence: " + sentence);
                return;
            }

            int    relativeHeading;
            double velocity;

            try
            {
                int period = words[1].IndexOf('.');
                if (period > 0)
                {
                    relativeHeading = Int32.Parse(words[1].Substring(0, period));
                }
                else
                {
                    relativeHeading = Int32.Parse(words[1]);
                }
                velocity = Double.Parse(words[3]);
            }
            catch (Exception e)
            {
                DebugLog.WriteLine("Could not parse: " + sentence + " e:" + e.ToString());
                return;
            }

            // convert velocity to knots
            switch (words[4])
            {
            case "M":
                velocity *= 0.868976242;
                break;

            case "K":
                velocity *= 0.539956803;
                break;

            case "N":
                // velocity is already in knots
                break;

            default:
                DebugLog.WriteLine("Invalid wind speed: " + sentence);
                return;
            }

            DebugLog.WriteLine("Wind velocity update: h=" + relativeHeading + " v=" + velocity);
            if (WindEvent != null)
            {
                var args = new NmeaWindEventArgs(relativeHeading, velocity);
                WindEvent(this, args);
            }
        }
Beispiel #2
0
 void m_nmeaInputPort_WindEvent(object sender, NmeaWindEventArgs args)
 {
     DisplayVariables.WindDirection.Value = args.RelativeHeading;
     DisplayVariables.WindSpeed.Value     = args.Velocity;
 }