Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#72 #69 #37 #14 #35 Redfine all Model classes to be readonly for public access. Use FinishUp method to calc useful properties and support for extended Multiplexing. #73

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DbcParserLib.Tests/DbcBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void NodeCommentIsSkippedIfNodeIsNotFound()

Assert.AreEqual(1, dbc.Nodes.Count());
Assert.AreEqual("nodeName", dbc.Nodes.First().Name);
Assert.IsNull(dbc.Nodes.First().Comment);
Assert.AreEqual(string.Empty, dbc.Nodes.First().Comment);
}

[Test]
Expand Down Expand Up @@ -150,7 +150,7 @@ public void CommentIsNotAddedToMissingMessage()
Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.IsNull(dbc.Messages.First().Value.Comment);
Assert.AreEqual(string.Empty, dbc.Messages.First().Value.Comment);
}

[Test]
Expand Down Expand Up @@ -234,7 +234,7 @@ public void CommentIsNotAddedToMissingSignalMessageId()
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsNull(dbc.Messages.First().Value.Signals.First().Value.Comment);
Assert.AreEqual(string.Empty, dbc.Messages.First().Value.Signals.First().Value.Comment);
}

[Test]
Expand All @@ -253,7 +253,7 @@ public void CommentIsNotAddedToMissingSignalName()
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsNull(dbc.Messages.First().Value.Signals.First().Value.Comment);
Assert.AreEqual(string.Empty, dbc.Messages.First().Value.Signals.First().Value.Comment);
}

[Test]
Expand Down
115 changes: 115 additions & 0 deletions DbcParserLib.Tests/ExtendedMultiplexorParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System.Linq;
using DbcParserLib.Model;
using NUnit.Framework;

namespace DbcParserLib.Tests;

internal class ExtendedMultiplexorParserTests
{
[Test]
public void ParseSignalExtendedMultiplexingCase1()
{
var dbcString = @"
BO_ 2024 OBD2: 8 Vector__XXX
SG_ S1_PID_0D_VehicleSpeed m13 : 31|8@0+ (1,0) [0|255] ""km/h"" Vector__XXX
SG_ S1_PID_11_ThrottlePosition m17 : 31|8@0+ (0.39216,0) [0|100] ""%"" Vector__XXX
SG_ S1 m1M : 23|8@0+ (1,0) [0|255] """" Vector__XXX
SG_ Service M : 11|4@0+ (1,0) [0|15] """" Vector__XXX

SG_MUL_VAL_ 2024 S1_PID_0D_VehicleSpeed S1 13-13;
SG_MUL_VAL_ 2024 S1_PID_11_ThrottlePosition S1 17-17;
SG_MUL_VAL_ 2024 S1 Service 1-1;";


var dbc = Parser.Parse(dbcString);

Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(4, dbc.Messages.SelectMany(m => m.Value.Signals).Count());

var signal1 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("S1_PID_0D_VehicleSpeed"));
var signal2 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("S1_PID_11_ThrottlePosition"));
var signal3 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("S1"));
var signal4 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("Service"));

Assert.AreEqual(MultiplexingMode.Extended, signal1.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.Multiplexed, signal1.Value.Multiplexing.Role);
Assert.IsNull(signal1.Value.Multiplexing.SimpleMultiplex);
Assert.AreEqual("S1", signal1.Value.Multiplexing.ExtendedMultiplex!.MultiplexorSignal);
Assert.AreEqual(1, signal1.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Count);
Assert.AreEqual(13, signal1.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Lower);

Assert.AreEqual(MultiplexingMode.Extended, signal2.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.Multiplexed, signal2.Value.Multiplexing.Role);
Assert.IsNull(signal2.Value.Multiplexing.SimpleMultiplex);
Assert.AreEqual("S1", signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorSignal);
Assert.AreEqual(1, signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Count);
Assert.AreEqual(17, signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Lower);

Assert.AreEqual(MultiplexingMode.Extended, signal3.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.MultiplexedMultiplexor, signal3.Value.Multiplexing.Role);
Assert.IsNull(signal3.Value.Multiplexing.SimpleMultiplex);
Assert.AreEqual("Service", signal3.Value.Multiplexing.ExtendedMultiplex!.MultiplexorSignal);
Assert.AreEqual(1, signal3.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Count);
Assert.AreEqual(1, signal3.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Lower);

Assert.AreEqual(MultiplexingMode.Simple, signal4.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.Multiplexor, signal4.Value.Multiplexing.Role);
Assert.IsNull(signal4.Value.Multiplexing.SimpleMultiplex);
Assert.IsNull(signal4.Value.Multiplexing.ExtendedMultiplex);
}

[Test]
public void ParseSignalExtendedMultiplexingCase2()
{
var dbcString = @"
BO_ 100 MuxMsg: 1 Vector__XXX
SG_ Mux_4 m2 : 6|2@1+ (1,0) [0|0] """" Vector__XXX
SG_ Mux_3 m3M : 4|2@1+ (1,0) [0|0] """" Vector__XXX
SG_ Mux_2 m3M : 2|2@1+ (1,0) [0|0] """" Vector__XXX
SG_ Mux_1 M : 0|2@1+ (1,0) [0|0] """" Vector__XXX

SG_MUL_VAL_ 100 Mux_2 Mux_1 3-3, 5-10;
SG_MUL_VAL_ 100 Mux_3 Mux_2 3-3;
SG_MUL_VAL_ 100 Mux_4 Mux_3 2-2;";


var dbc = Parser.Parse(dbcString);

Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(4, dbc.Messages.SelectMany(m => m.Value.Signals).Count());

var signal1 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("Mux_1"));
var signal2 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("Mux_2"));
var signal3 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("Mux_3"));
var signal4 = dbc.Messages.First().Value.Signals.First(x => x.Key.Equals("Mux_4"));

Assert.AreEqual(MultiplexingMode.Simple, signal1.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.Multiplexor, signal1.Value.Multiplexing.Role);
Assert.IsNull(signal1.Value.Multiplexing.SimpleMultiplex);
Assert.IsNull(signal1.Value.Multiplexing.ExtendedMultiplex);

Assert.AreEqual(MultiplexingMode.Extended, signal2.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.MultiplexedMultiplexor, signal2.Value.Multiplexing.Role);
Assert.IsNull(signal2.Value.Multiplexing.SimpleMultiplex);
Assert.AreEqual("Mux_1", signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorSignal);
Assert.AreEqual(2, signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Count);
Assert.AreEqual(3, signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Lower);
Assert.AreEqual(3, signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Upper);
Assert.AreEqual(5, signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Last().Lower);
Assert.AreEqual(10, signal2.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Last().Upper);

Assert.AreEqual(MultiplexingMode.Extended, signal3.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.MultiplexedMultiplexor, signal3.Value.Multiplexing.Role);
Assert.IsNull(signal3.Value.Multiplexing.SimpleMultiplex);
Assert.AreEqual("Mux_2", signal3.Value.Multiplexing.ExtendedMultiplex!.MultiplexorSignal);
Assert.AreEqual(1, signal3.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Count);
Assert.AreEqual(3, signal3.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Lower);

Assert.AreEqual(MultiplexingMode.Extended, signal4.Value.Multiplexing.Mode);
Assert.AreEqual(MultiplexingRole.Multiplexed, signal4.Value.Multiplexing.Role);
Assert.IsNull(signal4.Value.Multiplexing.SimpleMultiplex);
Assert.AreEqual("Mux_3", signal4.Value.Multiplexing.ExtendedMultiplex!.MultiplexorSignal);
Assert.AreEqual(1, signal4.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.Count);
Assert.AreEqual(2, signal4.Value.Multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Lower);
}
}
72 changes: 58 additions & 14 deletions DbcParserLib.Tests/MultiplexingInfoTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using DbcParserLib.Model;
using System.Collections.Generic;
using System.Linq;
using DbcParserLib.Model;
using NUnit.Framework;

namespace DbcParserLib.Tests;
Expand All @@ -10,13 +12,16 @@ public void NoMultiplexingTest()
{
var sig = new Signal
{
multiplexing = null,
Name = "Test"
multiplexing = string.Empty,
Name = "Test",
extendedMultiplex = null
};

var multiplexing = new MultiplexingInfo(sig);
Assert.AreEqual(MultiplexingRole.None, multiplexing.Role);
Assert.AreEqual(0, multiplexing.Group);
Assert.AreEqual(MultiplexingMode.None, multiplexing.Mode);
Assert.IsNull(multiplexing.ExtendedMultiplex);
Assert.IsNull(multiplexing.SimpleMultiplex);
}

[Test]
Expand All @@ -25,12 +30,15 @@ public void MultiplexorTest()
var sig = new Signal
{
multiplexing = "M",
Name = "Test"
Name = "Test",
extendedMultiplex = null
};

var multiplexing = new MultiplexingInfo(sig);
Assert.AreEqual(MultiplexingRole.Multiplexor, multiplexing.Role);
Assert.AreEqual(0, multiplexing.Group);
Assert.AreEqual(MultiplexingMode.Simple, multiplexing.Mode);
Assert.IsNull(multiplexing.ExtendedMultiplex);
Assert.IsNull(multiplexing.SimpleMultiplex);
}

[Test]
Expand All @@ -39,26 +47,33 @@ public void MultiplexedSingleDigitTest()
var sig = new Signal
{
multiplexing = "m3",
Name = "Test"
Name = "Test",
extendedMultiplex = null
};

var multiplexing = new MultiplexingInfo(sig);
Assert.AreEqual(MultiplexingRole.Multiplexed, multiplexing.Role);
Assert.AreEqual(3, multiplexing.Group);
Assert.AreEqual(MultiplexingMode.Simple, multiplexing.Mode);
Assert.IsNull(multiplexing.ExtendedMultiplex);
Assert.AreEqual(3, multiplexing.SimpleMultiplex!.MultiplexorValue);
}

[Test]
public void ExtendedMultiplexingIsPartiallySupportedTest()
public void ExtendedMultiplexingUsedInvalid()
{
var sig = new Signal
{
multiplexing = "m3M",
Name = "Test"
Name = "Test",
extendedMultiplex = null
};

var multiplexing = new MultiplexingInfo(sig);
Assert.AreEqual(MultiplexingRole.Multiplexed, multiplexing.Role);
Assert.AreEqual(3, multiplexing.Group);

Assert.AreEqual(MultiplexingRole.Unknown, multiplexing.Role);
Assert.AreEqual(MultiplexingMode.Simple, multiplexing.Mode);
Assert.IsNull(multiplexing.ExtendedMultiplex);
Assert.IsNull(multiplexing.SimpleMultiplex);
}

[Test]
Expand All @@ -67,11 +82,40 @@ public void MultiplexedDoubleDigitTest()
var sig = new Signal
{
multiplexing = "m12",
Name = "Test"
Name = "Test",
extendedMultiplex = null
};

var multiplexing = new MultiplexingInfo(sig);

Assert.AreEqual(MultiplexingRole.Multiplexed, multiplexing.Role);
Assert.AreEqual(12, multiplexing.Group);
Assert.AreEqual(MultiplexingMode.Simple, multiplexing.Mode);
Assert.IsNull(multiplexing.ExtendedMultiplex);
Assert.AreEqual(12, multiplexing.SimpleMultiplex!.MultiplexorValue);
}

[Test]
public void ExtendedMultiplexing()
{
var sig = new Signal
{
multiplexing = "m3M",
Name = "Test",
extendedMultiplex = new ExtendedMultiplex
{
MultiplexorSignal = "Multiplexor",
MultiplexorRanges = new List<MultiplexorRange> { new MultiplexorRange{ Lower = 3, Upper = 3} }
}
};

var multiplexing = new MultiplexingInfo(sig);

Assert.AreEqual(MultiplexingRole.MultiplexedMultiplexor, multiplexing.Role);
Assert.AreEqual(MultiplexingMode.Extended, multiplexing.Mode);
Assert.IsNull(multiplexing.SimpleMultiplex);
Assert.AreEqual("Multiplexor", multiplexing.ExtendedMultiplex!.MultiplexorSignal);
Assert.AreEqual(1, multiplexing.ExtendedMultiplex!.MultiplexorRanges.Count);
Assert.AreEqual(3, multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Lower);
Assert.AreEqual(3, multiplexing.ExtendedMultiplex!.MultiplexorRanges.First().Upper);
}
}
17 changes: 11 additions & 6 deletions DbcParserLib.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,23 @@ public void UserDefinedAttributesTest()

var node = dbc.Nodes.First();
Assert.AreEqual(1, node.CustomProperties.Count());
Assert.AreEqual(70, node.CustomProperties["HexAttribute"].HexCustomProperty.Value);
Assert.That(node.CustomProperties["HexAttribute"].PropertyValue is HexPropertyValue);
Assert.AreEqual(70, ((HexPropertyValue)node.CustomProperties["HexAttribute"].PropertyValue).Value);

var message = dbc.Messages.First();
Assert.AreEqual(2, message.Value.CustomProperties.Count());
Assert.AreEqual(7, message.Value.CustomProperties["IntegerAttribute"].IntegerCustomProperty.Value);
Assert.AreEqual(0.5, message.Value.CustomProperties["FloatAttribute"].FloatCustomProperty.Value);
Assert.AreEqual(2, message.Value.CustomProperties.Count);
Assert.That(message.Value.CustomProperties["IntegerAttribute"].PropertyValue is IntegerPropertyValue);
Assert.AreEqual(7, ((IntegerPropertyValue)message.Value.CustomProperties["IntegerAttribute"].PropertyValue).Value);
Assert.That(message.Value.CustomProperties["FloatAttribute"].PropertyValue is FloatPropertyValue);
Assert.AreEqual(0.5, ((FloatPropertyValue)message.Value.CustomProperties["FloatAttribute"].PropertyValue).Value);

var signal = dbc.Messages.Single().Value.Signals.FirstOrDefault(x => x.Value.Name.Equals("COUNTER_ALT")).Value;
Assert.IsNotNull(signal);
Assert.AreEqual(2, signal.CustomProperties.Count());
Assert.AreEqual("ThirdVal", signal.CustomProperties["EnumAttributeName"].EnumCustomProperty.Value);
Assert.AreEqual("DefaultString", signal.CustomProperties["StringAttribute"].StringCustomProperty.Value);
Assert.That(signal.CustomProperties["EnumAttributeName"].PropertyValue is EnumPropertyValue);
Assert.AreEqual("ThirdVal", ((EnumPropertyValue)signal.CustomProperties["EnumAttributeName"].PropertyValue).Value);
Assert.That(signal.CustomProperties["StringAttribute"].PropertyValue is StringPropertyValue);
Assert.AreEqual("DefaultString", ((StringPropertyValue)signal.CustomProperties["StringAttribute"].PropertyValue).Value);
}

[Test]
Expand Down
7 changes: 5 additions & 2 deletions DbcParserLib.Tests/PropertiesDefaultParsingFailuresTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DbcParserLib.Parsers;
using Moq;
using System.Linq;
using DbcParserLib.Model;
using DbcParserLib.Observers;

namespace DbcParserLib.Tests
Expand Down Expand Up @@ -232,7 +233,8 @@ public void DefaultCustomPropertyEnumWithIntegerValuesIsParsed()
var dbc = Parser.Parse(dbcString);

Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual("3", dbc.Messages.First().Value.CustomProperties.Values.First().EnumCustomProperty.Value);
Assert.That(dbc.Messages.First().Value.CustomProperties.Values.First().PropertyValue is EnumPropertyValue);
Assert.AreEqual("3", ((EnumPropertyValue)dbc.Messages.First().Value.CustomProperties.Values.First().PropertyValue).Value);
}

[Test]
Expand All @@ -246,7 +248,8 @@ public void DefaultCustomPropertyEnumWithIntegerValuesByIndexIsParsed()
var dbc = Parser.Parse(dbcString);

Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual("3", dbc.Messages.First().Value.CustomProperties.Values.First().EnumCustomProperty.Value);
Assert.That(dbc.Messages.First().Value.CustomProperties.Values.First().PropertyValue is EnumPropertyValue);
Assert.AreEqual("3", ((EnumPropertyValue)dbc.Messages.First().Value.CustomProperties.Values.First().PropertyValue).Value);
}
}
}
Loading