Implemement NmeaMessage : IEquatable<NmeaMessage>

Also avoid processing identical messages in GnssMonitor
This commit is contained in:
Morten Nielsen 2020-08-25 15:39:40 -07:00
parent 02579ab3e8
commit cb5249db73
2 changed files with 20 additions and 1 deletions

View file

@ -75,7 +75,11 @@ namespace NmeaParser.Gnss
double lon = 0;
List<string> properties = new List<string>();
lock (m_lock)
{
if(m_allMessages.ContainsKey(message.MessageType) && m_allMessages[message.MessageType].Equals(message))
return; // Nothing to update/notify
m_allMessages[message.MessageType] = message;
}
properties.Add(nameof(AllMessages));
if (message.TalkerId == NmeaParser.Talker.GlobalNavigationSatelliteSystem)
m_supportGNMessages = true; // Support for GN* messages detected

View file

@ -52,7 +52,7 @@ namespace NmeaParser.Messages
/// <summary>
/// NMEA Message base class.
/// </summary>
public abstract class NmeaMessage
public abstract class NmeaMessage : IEquatable<NmeaMessage>
{
private readonly static Dictionary<string, ConstructorInfo> messageTypes;
@ -301,6 +301,21 @@ namespace NmeaParser.Messages
return TimeSpan.Zero;
}
/// <inheritdoc />
public bool Equals(NmeaMessage other)
{
if (other.MessageType != MessageType)
return false;
if (other.MessageParts.Count != MessageParts.Count)
return false;
for (int i = 0; i < MessageParts.Count; i++)
{
if (other.MessageParts[i] != MessageParts[i])
return false;
}
return true;
}
/// <summary>
/// Gets a relative timestamp in milliseconds indicating the time the message was created.
/// </summary>