2014-07-25 22:26:30 +02:00
|
|
|
|
//
|
|
|
|
|
|
// Copyright (c) 2014 Morten Nielsen
|
|
|
|
|
|
//
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL) (the "License");
|
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
//
|
|
|
|
|
|
// http://opensource.org/licenses/Ms-PL.html
|
|
|
|
|
|
//
|
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-02-11 07:19:56 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2014-07-25 19:41:25 +02:00
|
|
|
|
namespace NmeaParser.Nmea.Gps
|
2014-02-11 07:19:56 +01:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Recommended Minimum
|
|
|
|
|
|
/// </summary>
|
2014-11-15 02:36:46 +01:00
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gprmc")]
|
|
|
|
|
|
[NmeaMessageType("GPRMC")]
|
2014-02-11 07:19:56 +01:00
|
|
|
|
public class Gprmc : NmeaMessage
|
|
|
|
|
|
{
|
2014-11-15 00:52:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Called when the message is being loaded.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="message">The NMEA message values.</param>
|
|
|
|
|
|
protected override void OnLoadMessage(string[] message)
|
2014-02-11 07:19:56 +01:00
|
|
|
|
{
|
2014-11-15 02:36:46 +01:00
|
|
|
|
if (message == null || message.Length < 11)
|
|
|
|
|
|
throw new ArgumentException("Invalid GPRMC", "message");
|
|
|
|
|
|
|
2014-11-12 19:58:58 +01:00
|
|
|
|
if (message[8].Length == 6 && message[0].Length == 6)
|
|
|
|
|
|
{
|
2014-11-15 02:36:46 +01:00
|
|
|
|
FixTime = new DateTime(int.Parse(message[8].Substring(4, 2), CultureInfo.InvariantCulture) + 2000,
|
|
|
|
|
|
int.Parse(message[8].Substring(2, 2), CultureInfo.InvariantCulture),
|
|
|
|
|
|
int.Parse(message[8].Substring(0, 2), CultureInfo.InvariantCulture),
|
|
|
|
|
|
int.Parse(message[0].Substring(0, 2), CultureInfo.InvariantCulture),
|
|
|
|
|
|
int.Parse(message[0].Substring(2, 2), CultureInfo.InvariantCulture),
|
|
|
|
|
|
int.Parse(message[0].Substring(4, 2), CultureInfo.InvariantCulture), DateTimeKind.Utc);
|
2014-11-12 19:58:58 +01:00
|
|
|
|
}
|
2014-02-11 07:19:56 +01:00
|
|
|
|
Active = (message[1] == "A");
|
2014-07-25 23:21:26 +02:00
|
|
|
|
Latitude = NmeaMessage.StringToLatitude(message[2], message[3]);
|
|
|
|
|
|
Longitude = NmeaMessage.StringToLongitude(message[4], message[5]);
|
2014-11-12 19:58:58 +01:00
|
|
|
|
Speed = NmeaMessage.StringToDouble(message[6]);
|
|
|
|
|
|
Course = NmeaMessage.StringToDouble(message[7]);
|
|
|
|
|
|
MagneticVariation = NmeaMessage.StringToDouble(message[9]);
|
|
|
|
|
|
if (!double.IsNaN(MagneticVariation) && message[10] == "W")
|
2014-02-11 07:19:56 +01:00
|
|
|
|
MagneticVariation *= -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fix Time
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DateTime FixTime { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a value whether the device is active
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool Active { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Latitude
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public double Latitude { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Longitude
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public double Longitude { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Speed over the ground in knots
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public double Speed { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Track angle in degrees True
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public double Course { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Magnetic Variation
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public double MagneticVariation { get; private set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|