mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2026-04-05 14:35:50 +00:00
Move the docs folder to docfx
This commit is contained in:
parent
3571fdec12
commit
d8be33581d
23 changed files with 2 additions and 2 deletions
|
|
@ -1,53 +0,0 @@
|
|||
# Creating a location provider for ArcGIS Runtime SDK
|
||||
|
||||
Below is an implementation for use with the [ArcGIS Runtime SDK for .NET](http://developers.arcgis.com/net). Use this location provider on the MapView's LocationDisplay to send it location data from your NMEA device to display your current location on a map.
|
||||
|
||||
**Usage:**
|
||||
```csharp
|
||||
NmeaParser.NmeaDevice device = new NmeaParser.NmeaFileDevice("NmeaSampleData.txt");
|
||||
mapView.LocationDisplay.LocationProvider = new NmeaLocationProvider(device);
|
||||
mapView.LocationDisplay.IsEnabled = true;
|
||||
```
|
||||
|
||||
**NmeaLocationProvider.cs**
|
||||
```csharp
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Esri.ArcGISRuntime.Geometry;
|
||||
using Esri.ArcGISRuntime.Location;
|
||||
|
||||
namespace NmeaParser.ArcGIS
|
||||
{
|
||||
public class NmeaLocationProvider : ILocationProvider
|
||||
{
|
||||
public event EventHandler<LocationInfo> LocationChanged;
|
||||
private readonly NmeaParser.NmeaDevice device;
|
||||
|
||||
public NmeaLocationProvider(NmeaParser.NmeaDevice device)
|
||||
{
|
||||
this.device = device;
|
||||
device.MessageReceived += device_MessageReceived;
|
||||
}
|
||||
|
||||
void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
|
||||
{
|
||||
var message = e.Message;
|
||||
if (message is NmeaParser.Messages.Rmc rmc && rmc.Active)
|
||||
{
|
||||
LocationChanged?.Invoke(this, new LocationInfo()
|
||||
{
|
||||
Course = rmc.Course,
|
||||
Speed = rmc.Speed,
|
||||
Location = new MapPoint(rmc.Longitude, rmc.Latitude, SpatialReferences.Wgs84)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public Task StartAsync() => device.OpenAsync();
|
||||
|
||||
public Task StopAsync() => device.CloseAsync();
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Creating a Bluetooth device in an Android app
|
||||
|
||||
TODO...
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
# Creating a Bluetooth device in a Windows Universal App
|
||||
|
||||
To use the NMEA Parser against a bluetooth device in a Windows Store or Windows Phone WinRT/Universal App, ensure the bluetooth capability is enabled by opening package.appxmanifest in a text editor, and add the following to the `<Capabilities>` section:
|
||||
```xml
|
||||
<DeviceCapability Name="bluetooth.rfcomm">
|
||||
<Device Id="any">
|
||||
<Function Type="name:serialPort" />
|
||||
</Device>
|
||||
</DeviceCapability>
|
||||
```
|
||||
See more here on bluetooth device capabilities in WinStore: http://msdn.microsoft.com/en-us/library/windows/apps/dn263090.aspx
|
||||
|
||||
Make sure your Bluetooth device is paired with your Windows Device.
|
||||
|
||||
```csharp
|
||||
//Get list of devices
|
||||
string serialDeviceType = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort);
|
||||
var devices = await DeviceInformation.FindAllAsync(serialDeviceType);
|
||||
//Select device by name (in this case TruePulse 360B Laser Range Finder)
|
||||
var TruePulse360B = devices.Where(t => t.Name.StartsWith("TP360B-")).FirstOrDefault();
|
||||
//Get service
|
||||
RfcommDeviceService rfcommService = await RfcommDeviceService.FromIdAsync(TruePulse360B.Id);
|
||||
if (rfcommService != null)
|
||||
{
|
||||
var rangeFinder = new NmeaParser.BluetoothDevice(rfcommService);
|
||||
rangeFinder.MessageReceived += device_NmeaMessageReceived;
|
||||
await rangeFinder.OpenAsync();
|
||||
}
|
||||
...
|
||||
private void device_NmeaMessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
|
||||
{
|
||||
// called when a message is received
|
||||
}
|
||||
```
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Creating a Bluetooth device in an iOS app
|
||||
|
||||
TODO...
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
# Creating custom NMEA messages
|
||||
|
||||
Custom NMEA messages can be registered for parsing as well.
|
||||
To create a new message, add the NmeaMessageType attribute to the class, and declare the 5-character message type.
|
||||
|
||||
*Note: You can use `--` as the first two characters to make it independent of the Talker Type.*
|
||||
|
||||
Next ensure you have a constructor that takes the `TypeName` string parameter first, and a second `string[]` parameter that will contain all the message values:
|
||||
|
||||
|
||||
Example:
|
||||
```cs
|
||||
[NmeaMessageType("PTEST")]
|
||||
public class CustomMessage : NmeaMessage
|
||||
{
|
||||
public CustomMessage(string type, string[] parameters) : base(type, parameters)
|
||||
{
|
||||
Value = parameters[0];
|
||||
}
|
||||
public string Value { get; }
|
||||
}
|
||||
```
|
||||
|
||||
Next register this with the NMEA Parser using either:
|
||||
|
||||
```cs
|
||||
NmeaMessage.RegisterAssembly(typeof(CustomMessage).Assembly); //Registers all types in the provided assembly
|
||||
NmeaMessage.RegisterMessage(typeof(CustomMessage).GetTypeInfo()); //Registers a single NMEA message
|
||||
```
|
||||
|
||||
Note that these methods will throw if the NMEA type has already been registers (there's an overload where you can declare the `replace` parameter to `true` to overwrite already registered messages.
|
||||
|
||||
Next you should be able to test this method using the Parse method:
|
||||
```cs
|
||||
var input = "$PTEST,TEST*7C";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
```
|
||||
|
||||
# Creating a multi-sentence message
|
||||
|
||||
A NMEA message cannot exceed 82 characters, so often messages are split into multiple sentences. To create a custom multi message, either implement `IMultiSentenceMessage` or simply subclass `NmeaMultiSentenceMessage`.
|
||||
|
||||
|
||||
```cs
|
||||
[NmeaMessageType("PTST2")]
|
||||
private class CustomMultiMessage : NmeaMultiSentenceMessage, IMultiSentenceMessage
|
||||
{
|
||||
public CustomMultiMessage(string type, string[] parameters) : base(type, parameters)
|
||||
{
|
||||
}
|
||||
public string Id { get; private set; }
|
||||
public List<string> Values { get; } = new List<string>();
|
||||
// Set index in the message where the total count is:
|
||||
protected override int MessageCountIndex => 0;
|
||||
// Set index in the message where the message number is:
|
||||
protected override int MessageNumberIndex => 1;
|
||||
protected override bool ParseSentences(Talker talkerType, string[] message)
|
||||
{
|
||||
// Ensure this message matches the previous message.
|
||||
// Use any indicator to detect message difference, so you can to error out and avoid
|
||||
// appending the wrong message
|
||||
if (Id == null)
|
||||
Id = message[2]; //First time it's not set
|
||||
else if (Id != message[2])
|
||||
return false;
|
||||
Values.AddRange(message.Skip(3));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
```
|
||||
Note that the message is parsed in the `ParseSentences` method, and not the constructor. Also note that the talkerType is parsed to you, because multi-sentence messages allows a mix of talker types, if you use the `--` prefex in the NMEA type.
|
||||
|
||||
Next we can parse the two messages and have the second one be appended to the first one:
|
||||
|
||||
```cs
|
||||
NmeaMessage.RegisterNmeaMessage(typeof(CustomMultiMessage).GetTypeInfo());
|
||||
var input1 = "$PTST2,2,1,123,A,B,C,D*2A";
|
||||
var input2 = "$PTST2,2,2,123,E,F,G,H*21";
|
||||
var msg1 = NmeaMessage.Parse(input1);
|
||||
var msg2 = NmeaMessage.Parse(input2, msg1 as IMultiSentenceMessage);
|
||||
```
|
||||
|
||||
If msg1 and msg2 aren't the same instance, it means the message couldn't be added to the previous message, and a new message was generated.
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
# Creating a Serial Port device in a .NET Core app
|
||||
|
||||
```csharp
|
||||
var port = new System.IO.Ports.SerialPort("COM3", 9600); //change name and baud rage to match your serial port
|
||||
var device = new NmeaParser.SerialPortDevice(port);
|
||||
device.MessageReceived += device_NmeaMessageReceived;
|
||||
device.OpenAsync();
|
||||
...
|
||||
private void device_NmeaMessageReceived(NmeaParser.NmeaDevice sender, NmeaParser.NmeaMessageReceivedEventArgs args)
|
||||
{
|
||||
// called when a message is received
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
# Creating a Serial Port device in a .NET Framework
|
||||
|
||||
```csharp
|
||||
var port = new System.IO.Ports.SerialPort("COM3", 9600); //change name and baud rage to match your serial port
|
||||
var device = new NmeaParser.SerialPortDevice(port);
|
||||
device.MessageReceived += device_NmeaMessageReceived;
|
||||
device.OpenAsync();
|
||||
...
|
||||
private void device_NmeaMessageReceived(NmeaParser.NmeaDevice sender, NmeaParser.NmeaMessageReceivedEventArgs args)
|
||||
{
|
||||
// called when a message is received
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
# Creating a Serial Port device in a Windows Universal app
|
||||
|
||||
To use the NMEA Parser against a serial device in a Windows 10 Universal app, ensure the serial device capability is enabled by opening package.appxmanifest in a text editor, and add the following to the `<Capabilities>` section:
|
||||
```xml
|
||||
<DeviceCapability Name="serialcommunication" >
|
||||
<Device Id="any">
|
||||
<Function Type="name:serialPort"/>
|
||||
</Device>
|
||||
</DeviceCapability>
|
||||
```
|
||||
|
||||
```csharp
|
||||
var selector = SerialDevice.GetDeviceSelector("COM3"); //Get the serial port on port '3'
|
||||
var devices = await DeviceInformation.FindAllAsync(selector);
|
||||
if(devices.Any()) //if the device is found
|
||||
{
|
||||
var deviceInfo = devices.First();
|
||||
var serialDevice = await SerialDevice.FromIdAsync(deviceInfo.Id);
|
||||
//Set up serial device according to device specifications:
|
||||
//This might differ from device to device
|
||||
serialDevice.BaudRate = 4800;
|
||||
serialDevice.DataBits = 8;
|
||||
serialDevice.Parity = SerialParity.None;
|
||||
var device = new NmeaParser.SerialPortDevice(serialDevice);
|
||||
device.MessageReceived += device_NmeaMessageReceived;
|
||||
}
|
||||
...
|
||||
private void device_NmeaMessageReceived(NmeaParser.NmeaDevice sender, NmeaMessageReceivedEventArgs args)
|
||||
{
|
||||
// called when a message is received
|
||||
}
|
||||
```
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
# Getting started:
|
||||
|
||||
### 1. Install from NuGET:
|
||||
|
||||
You can get the library via [NuGet](http://www.nuget.org) if you have the extension installed for Visual Studio or via the PowerShell package manager. This control is published via NuGet at [SharpGIS.NmeaParser](https://nuget.org/packages/SharpGIS.NmeaParser).
|
||||
|
||||
<table border="4px">
|
||||
<tr><td>
|
||||
<code>PM> Install-Package SharpGIS.NmeaParser</code>
|
||||
</td></tr></table>
|
||||
|
||||
### 2. Create a new device:
|
||||
|
||||
```cs
|
||||
// Create one of the NMEA devices
|
||||
var device = new NmeaFileDevice("PathToNmeaLogFile.txt", 1000);
|
||||
// Listen to messages from the device:
|
||||
device.MessageReceived += device_NmeaMessageReceived;
|
||||
// Open the device and start receiving:
|
||||
device.OpenAsync();
|
||||
|
||||
// Create event handler for receiving messages:
|
||||
private void device_NmeaMessageReceived(NmeaDevice sender, NmeaMessageReceivedEventArgs args)
|
||||
{
|
||||
// called when a message is received
|
||||
}
|
||||
```
|
||||
See the Platform specific device creation section in the menu for more specifics on device creation.
|
||||
|
||||
### 3. [Browse the API Reference](api/index.html)
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
- name: Getting Started
|
||||
href: index.md
|
||||
- name: Platform specific device creation
|
||||
items:
|
||||
- name: .NET Framework
|
||||
items:
|
||||
- name: SerialPort
|
||||
href: SerialPortNetFX.md
|
||||
- name: .NET Framework
|
||||
items:
|
||||
- name: SerialPort
|
||||
href: SerialPortNetCore.md
|
||||
- name: UWP
|
||||
items:
|
||||
- name: SerialPort
|
||||
href: SerialPortUWP.md
|
||||
- name: Bluetooth
|
||||
href: BluetoothUWP.md
|
||||
- name: Android
|
||||
items:
|
||||
- name: Bluetooth
|
||||
href: BluetoothAndroid.md
|
||||
- name: iOS
|
||||
items:
|
||||
- name: Bluetooth
|
||||
href: BluetoothiOS.md
|
||||
- name: Custom message types
|
||||
href: CustomMessages.md
|
||||
- name: Creating a location provider for ArcGIS Runtime SDK
|
||||
href: ArcGISRuntime.md
|
||||
Loading…
Add table
Add a link
Reference in a new issue