Exemple #1
0
 /// <summary>
 /// Creates a new GPSData object.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="time"></param>
 /// <param name="trueVelocity"></param>
 /// <param name="knotVelocity"></param>
 public GPSDataRaw(GPSPosition position, DateTime time, float trueVelocity, float knotVelocity)
 {
     this.position     = position;
     this.time         = time;
     this.trueVelocity = trueVelocity;
     this.knotVelocity = knotVelocity;
 }
Exemple #2
0
        /// <summary>
        /// Returns a new GPSData-Object with the values of the input.
        /// </summary>
        /// <param name="message">The input data string starting with $GPRMC</param>
        /// <returns>New GPSData-Object.</returns>
        public static GPSDataRaw GetGPRMCObject(string message)
        {
            string[]    data     = message.Split(',');
            GPSPosition position = new GPSPosition(
                new Coordinate(float.Parse(data[3]), Coordinate.ParseDirection(data[4])),
                new Coordinate(float.Parse(data[5]), Coordinate.ParseDirection(data[6])));

            // Format DateTime
            StringBuilder timeBuilder = new StringBuilder();

            for (int i = 0; i < data[1].Length; i++)
            {
                if (i % 2 == 0)
                {
                    timeBuilder.Append(':');
                }
                timeBuilder.Append(data[1][i]);
            }
            string timeFormatted = timeBuilder.ToString();

            StringBuilder dateBuilder = new StringBuilder();

            for (int i = 0; i < data[9].Length; i++)
            {
                if (i % 2 == 0)
                {
                    dateBuilder.Append('.');
                }
                dateBuilder.Append(data[9][i]);
            }
            string dateFormatted = dateBuilder.ToString();

            dateFormatted = dateFormatted.Remove(0, 1);
            timeFormatted = timeFormatted.Remove(0, 1);

            DateTime time = DateTime.ParseExact(timeFormatted + " " + dateFormatted, "HH:mm:ss dd.MM.yy", CultureInfo.InvariantCulture);

            float trueVelocity = float.Parse(data[8]);
            float knotVelocity = float.Parse(data[9]);

            return(new GPSDataRaw(position, time, trueVelocity, knotVelocity));
        }