Add project files.
This commit is contained in:
27
NmeaParser.cs
Normal file
27
NmeaParser.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using GpsClient2.NmeaMessages;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GpsClient2 {
|
||||
public class NmeaParser {
|
||||
/// <summary>
|
||||
/// Parses a string to the NmeaMessage class.
|
||||
/// </summary>
|
||||
/// <param name="message">The nmea string that need to be parsed.</param>
|
||||
/// <returns>Returns an NmeaMessage class. If it cannot parse it will return null.</returns>
|
||||
public NmeaMessage Parse(string message) {
|
||||
if (!message.StartsWith("$")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var messageParts = message.RemoveAfter("*").Split(',');
|
||||
var classType = NmeaConstants.GetClassType(messageParts[0].TrimStart('$'));
|
||||
var newInstance = (NmeaMessage)Activator.CreateInstance(classType);
|
||||
newInstance.Parse(messageParts);
|
||||
return newInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user