Add project files.

This commit is contained in:
2023-07-11 10:54:27 -05:00
parent bffa409ea4
commit 8b111f95d0
24 changed files with 1130 additions and 0 deletions

27
NmeaParser.cs Normal file
View 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;
}
}
}