mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2026-04-07 23:44:00 +00:00
GPGSA
This commit is contained in:
parent
b54939e6d1
commit
d941f2c0f7
4 changed files with 152 additions and 1 deletions
105
src/NmeaParser.Shared/Nmea/Gps/GPGSA.cs
Normal file
105
src/NmeaParser.Shared/Nmea/Gps/GPGSA.cs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NmeaParser.Nmea.Gps
|
||||
{
|
||||
/// <summary>
|
||||
/// Global Positioning System Fix Data
|
||||
/// </summary>
|
||||
[NmeaMessageType(Type = "GPGSA")]
|
||||
public class Gpgsa : NmeaMessage
|
||||
{
|
||||
public enum ModeSelection
|
||||
{
|
||||
Auto,
|
||||
Manual,
|
||||
}
|
||||
public enum Mode : int
|
||||
{
|
||||
NotAvailable = 1,
|
||||
_2D = 2,
|
||||
_3D = 3
|
||||
}
|
||||
|
||||
protected override void LoadMessage(string[] message)
|
||||
{
|
||||
GpsMode = message[0] == "A" ? ModeSelection.Auto : ModeSelection.Manual;
|
||||
FixMode = (Mode)int.Parse(message[1]);
|
||||
|
||||
List<int> svs = new List<int>();
|
||||
for (int i = 2; i < 14; i++)
|
||||
{
|
||||
int id = -1;
|
||||
if (message[i].Length > 0 && int.TryParse(message[i], out id))
|
||||
svs.Add(id);
|
||||
}
|
||||
SVs = svs.ToArray();
|
||||
|
||||
double tmp;
|
||||
if (double.TryParse(message[14], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
|
||||
PDop = tmp;
|
||||
else
|
||||
PDop = double.NaN;
|
||||
|
||||
if (double.TryParse(message[15], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
|
||||
HDop = tmp;
|
||||
else
|
||||
HDop = double.NaN;
|
||||
|
||||
if (double.TryParse(message[16], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
|
||||
VDop = tmp;
|
||||
else
|
||||
VDop = double.NaN;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mode
|
||||
/// </summary>
|
||||
public ModeSelection GpsMode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Mode
|
||||
/// </summary>
|
||||
public Mode FixMode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// IDs of SVs used in position fix
|
||||
/// </summary>
|
||||
public int[] SVs { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dilution of precision
|
||||
/// </summary>
|
||||
public double PDop { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal dilution of precision
|
||||
/// </summary>
|
||||
public double HDop { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Vertical dilution of precision
|
||||
/// </summary>
|
||||
public double VDop { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ namespace NmeaParser.Nmea
|
|||
checksumTest ^= Convert.ToByte(message[i]);
|
||||
}
|
||||
if (checksum != checksumTest)
|
||||
throw new ArgumentException("Invalid nmea message: Checksum failure");
|
||||
throw new ArgumentException(string.Format("Invalid nmea message: Checksum failure. Got {0:X2}, Expected {1:X2}", checksum, checksumTest));
|
||||
}
|
||||
|
||||
string[] parts = message.Split(new char[] { ',' });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue