Skip to content

Commit f1a29eb

Browse files
torbaczEllerbach
andauthored
Generic GnssDevice (#1100)
Co-authored-by: Laurent Ellerbach <[email protected]>
1 parent d4c1035 commit f1a29eb

28 files changed

+1386
-0
lines changed

devices/GnssDevice/Fix.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
namespace Iot.Device.Common.GnssDevice
5+
{
6+
/// <summary>
7+
/// Defines the Gnss module fix status.
8+
/// </summary>
9+
public enum Fix : byte
10+
{
11+
/// <summary> Represents no fix mode of the Gnss module.
12+
/// </summary>
13+
NoFix = 1,
14+
15+
/// <summary>
16+
/// Represents a 2D fix status of the Gnss module.
17+
/// </summary>
18+
Fix2D = 2,
19+
20+
/// <summary>
21+
/// Represents a 3D fix status of the Gnss module.
22+
/// </summary>
23+
Fix3D = 3
24+
}
25+
}

devices/GnssDevice/GeoPosition.cs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
using UnitsNet;
6+
7+
namespace Iot.Device.Common.GnssDevice
8+
{
9+
/// <summary>
10+
/// Represents a geographic position with latitude and longitude coordinates.
11+
/// </summary>
12+
public class GeoPosition
13+
{
14+
/// <summary>
15+
/// Gets the latitude of a geographic position.
16+
/// </summary>
17+
public double Latitude { get; private set; }
18+
19+
/// <summary>
20+
/// Gets the longitude of a geographic position.
21+
/// </summary>
22+
public double Longitude { get; private set; }
23+
24+
/// <summary>
25+
/// Gets or sets the altitude of the GNSS position.
26+
/// </summary>
27+
public double Altitude { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the speed of the GNSS position.
31+
/// </summary>
32+
public double Speed { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets the course angle of the GNSS position.
36+
/// </summary>
37+
public Angle Course { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the horizontal accuracy(in meters) of the location.
41+
/// </summary>
42+
public double Accuracy { get; set; }
43+
44+
/// <summary>
45+
/// Gets or sets the vertical accuracy (in meters) of the location.
46+
/// </summary>
47+
public double VerticalAccuracy { get; set; }
48+
49+
/// <summary>
50+
/// Gets or sets the date and time of the GNSS position.
51+
/// </summary>
52+
public DateTime Timestamp { get; set; }
53+
54+
/// <summary>
55+
/// Converts latitude and longitude coordinates from decimal degrees format to a GeoPosition object.
56+
/// </summary>
57+
/// <param name="latitude">The latitude coordinate in decimal degrees.</param>
58+
/// <param name="longitude">The longitude coordinate in decimal degrees.</param>
59+
/// <returns>A GeoPosition object with the specified latitude and longitude coordinates.</returns>
60+
public static GeoPosition FromDecimalDegrees(double latitude, double longitude)
61+
{
62+
return new GeoPosition()
63+
{
64+
Latitude = latitude,
65+
Longitude = longitude
66+
};
67+
}
68+
}
69+
}

devices/GnssDevice/GngsaData.cs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
using System.Diagnostics;
6+
7+
namespace Iot.Device.Common.GnssDevice
8+
{
9+
/// <summary>
10+
/// Represents the GNGSA data parsed from NMEA0183 sentences.
11+
/// </summary>
12+
public class GngsaData : INmeaData
13+
{
14+
/// <summary>
15+
/// Gets the Gnss module mode.
16+
/// </summary>
17+
public GnssOperation Mode { get; }
18+
19+
/// <summary>
20+
/// Gets the Gnss module fix status.
21+
/// </summary>
22+
public Fix Fix { get; }
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="GngsaData" /> class.
26+
/// </summary>
27+
/// <param name="mode">Gnss mode.</param>
28+
/// <param name="fix">Gnss fix.</param>
29+
public GngsaData(GnssOperation mode, Fix fix)
30+
{
31+
Mode = mode;
32+
Fix = fix;
33+
}
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="GngsaData" /> class.
37+
/// </summary>
38+
public GngsaData()
39+
{
40+
}
41+
42+
/// <inheritdoc/>
43+
public INmeaData Parse(string inputData)
44+
{
45+
try
46+
{
47+
var data = inputData.Split(',');
48+
var mode = Nmea0183Parser.ConvertToMode(data[1]);
49+
var fix = Nmea0183Parser.ConvertToFix(data[2]);
50+
51+
return new GngsaData(mode, fix);
52+
}
53+
catch (Exception ex)
54+
{
55+
Debug.WriteLine(ex.Message);
56+
}
57+
58+
return null;
59+
}
60+
}
61+
}

devices/GnssDevice/GnssDevice.cs

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
namespace Iot.Device.Common.GnssDevice
5+
{
6+
/// <summary>
7+
/// Base class for all Gnss devices.
8+
/// </summary>
9+
public abstract class GnssDevice
10+
{
11+
private Fix _fix = Fix.NoFix;
12+
private GnssOperation _mode = GnssOperation.Unknown;
13+
private GeoPosition _location;
14+
15+
/// <summary>
16+
/// Delegate type to handle the event when the Gnss module fix status changes.
17+
/// </summary>
18+
/// <param name="fix">The new fix status.</param>
19+
public delegate void FixChangedHandler(Fix fix);
20+
21+
/// <summary>
22+
/// Delegate type to handle the event when the Gnss module mode changes.
23+
/// </summary>
24+
/// <param name="mode">The new Gnss module mode.</param>
25+
public delegate void ModeChangedHandler(GnssOperation mode);
26+
27+
/// <summary>
28+
/// Delegate type to handle the event when the Gnss module location changes.
29+
/// </summary>
30+
/// <param name="position">The new position.</param>
31+
public delegate void LocationChangeHandler(GeoPosition position);
32+
33+
/// <summary>
34+
/// Gets or sets the fix status of the Gnss module.
35+
/// </summary>
36+
public Fix Fix
37+
{
38+
get => _fix;
39+
protected set
40+
{
41+
if (_fix == value)
42+
{
43+
return;
44+
}
45+
46+
_fix = value;
47+
FixChanged?.Invoke(value);
48+
}
49+
}
50+
51+
/// <summary>
52+
/// Gets or sets the mode of the GNSS device.
53+
/// </summary>
54+
public virtual GnssMode GnssMode { get; set; }
55+
56+
/// <summary>
57+
/// Gets or sets the mode of the Gnss module.
58+
/// </summary>
59+
/// <value>
60+
/// The mode of the Gnss module.
61+
/// </value>
62+
public GnssOperation GnssOperation
63+
{
64+
get => _mode;
65+
protected set
66+
{
67+
if (value == _mode)
68+
{
69+
return;
70+
}
71+
72+
_mode = value;
73+
OperationModeChanged?.Invoke(_mode);
74+
}
75+
}
76+
77+
/// <summary>
78+
/// Gets or sets the last known location.
79+
/// </summary>
80+
public GeoPosition Location
81+
{
82+
get => _location;
83+
protected set
84+
{
85+
_location = value;
86+
LocationChanged?.Invoke(_location);
87+
}
88+
}
89+
90+
/// <summary>
91+
/// Represents the event handler for when the fix status of the Gnss module changes.
92+
/// </summary>
93+
public event FixChangedHandler FixChanged;
94+
95+
/// <summary>
96+
/// Event that occurs when the location changes.
97+
/// </summary>
98+
public event LocationChangeHandler LocationChanged;
99+
100+
/// <summary>
101+
/// Represents the event that is raised when the mode of the Gnss module is changed.
102+
/// </summary>
103+
public event ModeChangedHandler OperationModeChanged;
104+
}
105+
}

devices/GnssDevice/GnssDevice.nfproj

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.props" Condition="Exists('packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.props')" />
4+
<PropertyGroup Label="Globals">
5+
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
6+
</PropertyGroup>
7+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
8+
<PropertyGroup>
9+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
10+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
11+
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
12+
<ProjectGuid>d3085490-46b6-488a-96f1-ef820e67acc0</ProjectGuid>
13+
<OutputType>Library</OutputType>
14+
<AppDesignerFolder>Properties</AppDesignerFolder>
15+
<FileAlignment>512</FileAlignment>
16+
<RootNamespace>Iot.Device.Common.GnssDevice</RootNamespace>
17+
<AssemblyName>Iot.Device.Common.GnssDevice</AssemblyName>
18+
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
19+
<DocumentationFile>bin\$(Configuration)\Iot.Device.Common.GnssDevice.xml</DocumentationFile>
20+
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
21+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
22+
<RestoreLockedMode Condition="'$(TF_BUILD)' == 'True' or '$(ContinuousIntegrationBuild)' == 'True'">true</RestoreLockedMode>
23+
</PropertyGroup>
24+
<PropertyGroup>
25+
<SignAssembly>true</SignAssembly>
26+
</PropertyGroup>
27+
<PropertyGroup>
28+
<AssemblyOriginatorKeyFile>..\key.snk</AssemblyOriginatorKeyFile>
29+
</PropertyGroup>
30+
<PropertyGroup>
31+
<DelaySign>false</DelaySign>
32+
</PropertyGroup>
33+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
34+
<ItemGroup>
35+
<Compile Include="Fix.cs" />
36+
<Compile Include="GeoPosition.cs" />
37+
<Compile Include="GpggaData.cs" />
38+
<Compile Include="GpgllData.cs" />
39+
<Compile Include="GngsaData.cs" />
40+
<Compile Include="GnssDevice.cs" />
41+
<Compile Include="GnssMode.cs" />
42+
<Compile Include="GnssOperation.cs" />
43+
<Compile Include="GpgsaData.cs" />
44+
<Compile Include="Nmea0183Parser.cs" />
45+
<Compile Include="INmeaData.cs" />
46+
<Compile Include="PositioningIndicator.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
<Compile Include="Status.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Reference Include="mscorlib, Version=1.15.6.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
52+
<HintPath>packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll</HintPath>
53+
</Reference>
54+
<Reference Include="nanoFramework.System.Collections, Version=1.5.31.0, Culture=neutral, PublicKeyToken=c07d481e9758c731, processorArchitecture=MSIL">
55+
<HintPath>packages\nanoFramework.System.Collections.1.5.31\lib\nanoFramework.System.Collections.dll</HintPath>
56+
</Reference>
57+
<Reference Include="System.Math, Version=1.5.43.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
58+
<HintPath>packages\nanoFramework.System.Math.1.5.43\lib\System.Math.dll</HintPath>
59+
</Reference>
60+
<Reference Include="UnitsNet.Angle">
61+
<HintPath>packages\UnitsNet.nanoFramework.Angle.5.55.0\lib\UnitsNet.Angle.dll</HintPath>
62+
</Reference>
63+
</ItemGroup>
64+
<ItemGroup>
65+
<None Include="packages.config" />
66+
</ItemGroup>
67+
<ItemGroup>
68+
<Content Include="packages.lock.json" />
69+
</ItemGroup>
70+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
71+
<ProjectExtensions>
72+
<ProjectCapabilities>
73+
<ProjectConfigurationsDeclaredAsItems />
74+
</ProjectCapabilities>
75+
</ProjectExtensions>
76+
<Import Project="packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets" Condition="Exists('packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets')" />
77+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
78+
<PropertyGroup>
79+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
80+
</PropertyGroup>
81+
<Error Condition="!Exists('packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets'))" />
82+
<Error Condition="!Exists('packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.props'))" />
83+
<Error Condition="!Exists('packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.targets'))" />
84+
</Target>
85+
<Import Project="packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.targets" Condition="Exists('packages\Nerdbank.GitVersioning.3.6.139\build\Nerdbank.GitVersioning.targets')" />
86+
</Project>

devices/GnssDevice/GnssDevice.nuspec

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>nanoFramework.Iot.Device.Common.GnssDevice</id>
5+
<version>$version$</version>
6+
<title>nanoFramework.Iot.Device.Common.GnssDevice</title>
7+
<authors>nanoframework</authors>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<license type="file">LICENSE.md</license>
10+
<releaseNotes>
11+
</releaseNotes>
12+
<readme>docs/README.md</readme>
13+
<developmentDependency>false</developmentDependency>
14+
<projectUrl>https://github.com/nanoframework/nanoFramework.IoT.Device</projectUrl>
15+
<icon>images\nf-logo.png</icon>
16+
<repository type="git" url="https://github.com/nanoframework/nanoFramework.IoT.Device" commit="$commit$" />
17+
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
18+
<description>This package includes the .NET IoT Core binding Iot.Device.Common.GnssDevice for .NET nanoFramework C# projects.</description>
19+
<summary>Iot.Device.Common.GnssDevice assembly for .NET nanoFramework C# projects</summary>
20+
<tags>nanoFramework C# csharp netmf netnf Weather Helper</tags>
21+
<dependencies>
22+
<dependency id="nanoFramework.CoreLibrary" version="1.15.5" />
23+
<dependency id="nanoFramework.System.Math" version="1.5.43" />
24+
<dependency id="nanoFramework.System.Collections" version="1.5.31" />
25+
<dependency id="UnitsNet.nanoFramework.Angle" version="5.55.0" />
26+
</dependencies>
27+
</metadata>
28+
<files>
29+
<file src="bin\Release\Iot.Device.Common.GnssDevice.dll" target="lib\Iot.Device.Common.GnssDevice.dll" />
30+
<file src="bin\Release\Iot.Device.Common.GnssDevice.pdb" target="lib\Iot.Device.Common.GnssDevice.pdb" />
31+
<file src="bin\Release\Iot.Device.Common.GnssDevice.pdbx" target="lib\Iot.Device.Common.GnssDevice.pdbx" />
32+
<file src="bin\Release\Iot.Device.Common.GnssDevice.pe" target="lib\Iot.Device.Common.GnssDevice.pe" />
33+
<file src="bin\Release\Iot.Device.Common.GnssDevice.xml" target="lib\Iot.Device.Common.GnssDevice.xml" />
34+
<file src="README.md" target="docs\" />
35+
<file src="..\..\assets\nf-logo.png" target="images" />
36+
<file src="..\..\LICENSE.md" target="" />
37+
</files>
38+
</package>

0 commit comments

Comments
 (0)