Skip to content

Commit 21abbb5

Browse files
[GnssDevice] Add ZDA and a constructor for Location with latitude and longitude (#1115)
Co-authored-by: José Simões <[email protected]>
1 parent 7d50b26 commit 21abbb5

File tree

6 files changed

+110
-7
lines changed

6 files changed

+110
-7
lines changed

Diff for: devices/GnssDevice/GnssDevice.nfproj

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Compile Include="Messages\GsaData.cs" />
4444
<Compile Include="Messages\RmcData.cs" />
4545
<Compile Include="Messages\VtgData.cs" />
46+
<Compile Include="Messages\ZdaData.cs" />
4647
<Compile Include="Nmea0183Parser.cs" />
4748
<Compile Include="Messages\NmeaData.cs" />
4849
<Compile Include="PositioningIndicator.cs" />

Diff for: devices/GnssDevice/Location.cs

+23-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,32 @@ namespace Iot.Device.Common.GnssDevice
1212
public class Location
1313
{
1414
/// <summary>
15-
/// Gets the latitude of a geographic position.
15+
/// Initializes a new instance of the <see cref="Location"/> class.
1616
/// </summary>
17-
public double Latitude { get; internal set; }
17+
public Location()
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="Location"/> class.
23+
/// </summary>
24+
/// <param name="latitude">The latitude.</param>
25+
/// <param name="longitude">The longitude.</param>
26+
public Location(double latitude, double longitude)
27+
{
28+
Latitude = latitude;
29+
Longitude = longitude;
30+
}
31+
32+
/// <summary>
33+
/// Gets or sets the latitude of a geographic position.
34+
/// </summary>
35+
public double Latitude { get; set; }
1836

1937
/// <summary>
20-
/// Gets the longitude of a geographic position.
38+
/// Gets or sets the longitude of a geographic position.
2139
/// </summary>
22-
public double Longitude { get; internal set; }
40+
public double Longitude { get; set; }
2341

2442
/// <summary>
2543
/// Gets or sets the altitude of the GNSS position.
@@ -66,4 +84,4 @@ public static Location FromDecimalDegrees(double latitude, double longitude)
6684
};
6785
}
6886
}
69-
}
87+
}

Diff for: devices/GnssDevice/Messages/ZdaData.cs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
6+
namespace Iot.Device.Common.GnssDevice
7+
{
8+
/// <summary>
9+
/// Represents the ZDA (Timing MEssage) NMEA0183 data from a Gnss device.
10+
/// </summary>
11+
public class ZdaData : NmeaData
12+
{
13+
/// <inheritdoc/>
14+
public override string MessageId => "ZDA";
15+
16+
/// <summary>
17+
/// Gets the time of the GNSS position.
18+
/// </summary>
19+
public DateTime DateTime { get; internal set; }
20+
21+
/// <summary>
22+
/// Gets the local hour of the GNSS position.
23+
/// </summary>
24+
public int LocalHour { get; internal set; }
25+
26+
/// <summary>
27+
/// Gets the local minute of the GNSS position.
28+
/// </summary>
29+
public int LocalMinute { get; internal set; }
30+
31+
/// <inheritdoc/>
32+
public override NmeaData Parse(string inputData)
33+
{
34+
if (!IsMatch(inputData))
35+
{
36+
throw new ArgumentException();
37+
}
38+
39+
if (!ValidateChecksum(inputData))
40+
{
41+
return null;
42+
}
43+
44+
try
45+
{
46+
var subfields = GetSubFields(inputData);
47+
var time = Nmea0183Parser.ConvertToTimeSpan(subfields[1]);
48+
var day = Nmea0183Parser.ConvertToInt(subfields[2]);
49+
var month = Nmea0183Parser.ConvertToInt(subfields[3]);
50+
var year = Nmea0183Parser.ConvertToInt(subfields[4]);
51+
var localHour = Nmea0183Parser.ConvertToInt(subfields[5]);
52+
var localMinute = Nmea0183Parser.ConvertToInt(subfields[6]);
53+
54+
return new ZdaData()
55+
{
56+
DateTime = new DateTime(year, month, day).Add(time),
57+
LocalHour = localHour,
58+
LocalMinute = localMinute,
59+
};
60+
}
61+
catch
62+
{
63+
return null;
64+
}
65+
}
66+
}
67+
}

Diff for: devices/GnssDevice/Nmea0183Parser.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static class Nmea0183Parser
2323
new GgaData(),
2424
new RmcData(),
2525
new VtgData(),
26+
new ZdaData(),
2627
};
2728

2829
/// <summary>

Diff for: devices/GnssDevice/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Global Navigation Satellite System Device NMEA 0183 - Including Generic Serial Module with GPS, GNSS, BeiDou
1+
# Global Navigation Satellite System Device NMEA 0183 - Including Generic Serial Module with GPS, GNSS, BeiDou - NEO6-M, NEO-M8P-2, NEO-M9N from u-blox, ATGM336H, Minewsemi, ZED-F9P, ZOE-M8Q, SAM-M8Q, SARA-R5 and many many more
22

3-
This binding implements a base Global Navigation Satellite System (GNSS) device and a generic serial implementation. The device includes a generic serial module that supports multiple satellite navigation systems such as GPS, GNSS, and BeiDou. The Generic Serial GNSS Device is also extensible. Any serial modules like the NEO6-M from u-blox, ATGM336H,Minewsemi and many many more are directly supported for the main NMEA0183 features.
3+
This binding implements a base Global Navigation Satellite System (GNSS) device and a generic serial implementation. The device includes a generic serial module that supports multiple satellite navigation systems such as GPS, GNSS, and BeiDou. The Generic Serial GNSS Device is also extensible. Any serial modules like the NEO6-M, NEO-M8P-2, NEO-M9N from u-blox, ATGM336H, Minewsemi, ZED-F9P, ZOE-M8Q, SAM-M8Q, SARA-R5 and many many more are directly supported for the main NMEA0183 features.
44

55
## Documentation
66

Diff for: devices/GnssDevice/Tests/GnssDeviceTests/NMEA0183ParserTests.cs

+16
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,21 @@ public void TestGnssMode(string command, int gnssMode)
131131
// Assert
132132
Assert.AreEqual(gnssMode, (int)gnss);
133133
}
134+
135+
[TestMethod]
136+
[DataRow("$GNZDA,105708.000,11,08,2024,00,00*4F", 2024, 8, 11, 10, 57, 08)]
137+
public void TestZdaData(string command, int year, int month, int day, int hour, int minute, int second)
138+
{
139+
// Act
140+
ZdaData result = (ZdaData)Nmea0183Parser.Parse(command);
141+
142+
// Assert
143+
Assert.AreEqual(year, result.DateTime.Year);
144+
Assert.AreEqual(month, result.DateTime.Month);
145+
Assert.AreEqual(day, result.DateTime.Day);
146+
Assert.AreEqual(hour, result.DateTime.Hour);
147+
Assert.AreEqual(minute, result.DateTime.Minute);
148+
Assert.AreEqual(second, result.DateTime.Second);
149+
}
134150
}
135151
}

0 commit comments

Comments
 (0)