diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 3b33803..bfe6fb0 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -19,20 +19,22 @@ jobs: 3.1.x 6.0.x 8.0.x + 10.0.x - name: Build library (.net core) run: dotnet build src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj --configuration release test: runs-on: windows-latest steps: - uses: actions/checkout@master - - name: Build and run .net core tests + - name: Setup .NET Core uses: actions/setup-dotnet@master with: dotnet-version: | 3.1.x 6.0.x 8.0.x - - name: Test Mids + 10.0.x + - name: Build and run .net core tests run: | dotnet build src/MIDTesters.Core/MIDTesters.Core.csproj dotnet test src/MIDTesters.Core/MIDTesters.Core.csproj \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2bea271..972ca5f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,20 +17,22 @@ jobs: 3.1.x 6.0.x 8.0.x + 10.0.x - name: Build library (.net core) run: dotnet build src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj --configuration release test: runs-on: windows-latest steps: - uses: actions/checkout@master - - name: Build and run .net core tests + - name: Setup .NET Core uses: actions/setup-dotnet@master with: dotnet-version: | 3.1.x 6.0.x 8.0.x - - name: Test Mids + 10.0.x + - name: Build and run .net core tests run: | dotnet build src/MIDTesters.Core/MIDTesters.Core.csproj dotnet test src/MIDTesters.Core/MIDTesters.Core.csproj @@ -46,4 +48,4 @@ jobs: - name: Publish NuGet run: | dotnet build src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj --configuration release - nuget push src/OpenProtocolInterpreter/bin/release/OpenProtocolInterpreter.6.1.0.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate \ No newline at end of file + nuget push src/OpenProtocolInterpreter/bin/release/OpenProtocolInterpreter.6.1.1.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f871fb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "dotnet.defaultSolution": "OpenProtocolInterpreter.sln", + "omnisharp.useModernNet": true, + "omnisharp.enableRoslynAnalyzers": true, + "omnisharp.enableEditorConfigSupport": true, + "omnisharp.enableDecompilationSupport": true, + "dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true +} diff --git a/omnisharp.json b/omnisharp.json new file mode 100644 index 0000000..a3c3b67 --- /dev/null +++ b/omnisharp.json @@ -0,0 +1,15 @@ +{ + "msbuild": { + "enabled": true, + "useBundledOnly": false, + "loadProjectsOnDemand": false + }, + "RoslynExtensionsOptions": { + "enableAnalyzersSupport": true, + "enableImportCompletion": true, + "enableDecompilationSupport": true + }, + "FormattingOptions": { + "enableEditorConfigSupport": true + } +} diff --git a/src/MIDTesters.Core/Converters/DecimalConverterTest.cs b/src/MIDTesters.Core/Converters/DecimalConverterTest.cs index 7ddaf4b..f8d0ca4 100644 --- a/src/MIDTesters.Core/Converters/DecimalConverterTest.cs +++ b/src/MIDTesters.Core/Converters/DecimalConverterTest.cs @@ -59,6 +59,33 @@ public void ZeroPaddedStringToDecimal() Assert.AreEqual(3.3123m, result); } + [TestMethod] + [TestCategory("Decimal")] + public void DecimalWithExponentToDecimal() + { + var value = "1.23E+02"; + var result = OpenProtocolConvert.ToDecimal(value); + Assert.AreEqual(123m, result); + } + + [TestMethod] + [TestCategory("Decimal")] + public void DecimalWithNegativeExponentToDecimal() + { + var value = "1.5E-03"; + var result = OpenProtocolConvert.ToDecimal(value); + Assert.AreEqual(0.0015m, result); + } + + [TestMethod] + [TestCategory("Decimal")] + public void DecimalWithLowercaseExponentToDecimal() + { + var value = "2.5e+01"; + var result = OpenProtocolConvert.ToDecimal(value); + Assert.AreEqual(25m, result); + } + [TestMethod] [TestCategory("Decimal")] public void ConcurrencyTest() diff --git a/src/MIDTesters.Core/MIDTesters.Core.csproj b/src/MIDTesters.Core/MIDTesters.Core.csproj index 9bb6c4b..f985dc5 100644 --- a/src/MIDTesters.Core/MIDTesters.Core.csproj +++ b/src/MIDTesters.Core/MIDTesters.Core.csproj @@ -1,7 +1,7 @@ - net8.0 + net10.0 false diff --git a/src/OpenProtocolInterpreter/OpenProtocolConvert.cs b/src/OpenProtocolInterpreter/OpenProtocolConvert.cs index a733609..dfaa908 100644 --- a/src/OpenProtocolInterpreter/OpenProtocolConvert.cs +++ b/src/OpenProtocolInterpreter/OpenProtocolConvert.cs @@ -59,7 +59,7 @@ public static decimal ToDecimal(string value) { decimal decimalValue = 0; if (!string.IsNullOrWhiteSpace(value)) - decimal.TryParse(value.Replace(',', '.'), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, _formatProvider, out decimalValue); + decimal.TryParse(value.Replace(',', '.'), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, _formatProvider, out decimalValue); return decimalValue; } diff --git a/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj b/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj index fa2b1c3..22e57ae 100644 --- a/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj +++ b/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj @@ -1,11 +1,11 @@  - netstandard2.0;net6;net8 + netstandard2.0;net6.0;net8.0;net10.0 latest - 6.1.0 + 6.1.1 Converts the ugly package that came from Open Protocol to an object - Copyright © 2023 + Copyright © 2026 Henrique Dal Bello Batista Henrique Dal Bello Batista https://github.com/Rickedb/OpenProtocolInterpreter diff --git a/src/OpenProtocolInterpreter/vin/IVIN.cs b/src/OpenProtocolInterpreter/Vin/IVin.cs similarity index 100% rename from src/OpenProtocolInterpreter/vin/IVIN.cs rename to src/OpenProtocolInterpreter/Vin/IVin.cs diff --git a/src/OpenProtocolInterpreter/vin/Mid0050.cs b/src/OpenProtocolInterpreter/Vin/Mid0050.cs similarity index 100% rename from src/OpenProtocolInterpreter/vin/Mid0050.cs rename to src/OpenProtocolInterpreter/Vin/Mid0050.cs diff --git a/src/OpenProtocolInterpreter/vin/Mid0051.cs b/src/OpenProtocolInterpreter/Vin/Mid0051.cs similarity index 100% rename from src/OpenProtocolInterpreter/vin/Mid0051.cs rename to src/OpenProtocolInterpreter/Vin/Mid0051.cs diff --git a/src/OpenProtocolInterpreter/vin/Mid0053.cs b/src/OpenProtocolInterpreter/Vin/Mid0053.cs similarity index 100% rename from src/OpenProtocolInterpreter/vin/Mid0053.cs rename to src/OpenProtocolInterpreter/Vin/Mid0053.cs diff --git a/src/OpenProtocolInterpreter/vin/Mid0054.cs b/src/OpenProtocolInterpreter/Vin/Mid0054.cs similarity index 100% rename from src/OpenProtocolInterpreter/vin/Mid0054.cs rename to src/OpenProtocolInterpreter/Vin/Mid0054.cs diff --git a/src/OpenProtocolInterpreter/vin/VINMessages.cs b/src/OpenProtocolInterpreter/Vin/VINMessages.cs similarity index 100% rename from src/OpenProtocolInterpreter/vin/VINMessages.cs rename to src/OpenProtocolInterpreter/Vin/VINMessages.cs diff --git a/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs b/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs index e03d607..47b10d5 100644 --- a/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs +++ b/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs @@ -97,7 +97,7 @@ protected void FilterSelectedMids(IEnumerable mids) /// Ignored mid instances private void FilterSelectedMids(IEnumerable mids) { - var ignoredMids = _templates.Where(x => !mids.Contains(x.Value)); + var ignoredMids = _templates.Where(x => !mids.Contains(x.Value)).ToList(); foreach (var ignore in ignoredMids) _templates.Remove(ignore); } diff --git a/src/OpenProtocolInterpreter/vin/Mid0052.cs b/src/OpenProtocolInterpreter/vin/Mid0052.cs deleted file mode 100644 index e10244c..0000000 --- a/src/OpenProtocolInterpreter/vin/Mid0052.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System.Collections.Generic; - -namespace OpenProtocolInterpreter.Vin -{ - /// - /// Vehicle ID Number - /// Transmission of the current identifiers of the tightening by the controller to the subscriber. - /// The tightening result can be stamped with up to four identifiers: - /// - /// VIN number (identifier result part 1) - /// Identifier result part 2 - /// Identifier result part 3 - /// Identifier result part 4 - /// - /// - /// The identifiers are received by the controller from several input sources, - /// for example serial, Ethernet, or field bus. - /// - /// Message sent by: Controller - /// Answer: Vehicle ID Number acknowledge - /// - public class Mid0052 : Mid, IVin, IController, IAcknowledgeable - { - public const int MID = 52; - - public string VinNumber - { - get => GetField(1, DataFields.VinNumber).Value; - set => GetField(1, DataFields.VinNumber).SetValue(value); - } - public string IdentifierResultPart2 - { - get => GetField(2, DataFields.IdentifierResultPart2).Value; - set => GetField(2, DataFields.IdentifierResultPart2).SetValue(value); - } - public string IdentifierResultPart3 - { - get => GetField(2, DataFields.IdentifierResultPart3).Value; - set => GetField(2, DataFields.IdentifierResultPart3).SetValue(value); - } - public string IdentifierResultPart4 - { - get => GetField(2, DataFields.IdentifierResultPart4).Value; - set => GetField(2, DataFields.IdentifierResultPart4).SetValue(value); - } - - public Mid0052() : this(DEFAULT_REVISION) - { - - } - - public Mid0052(Header header) : base(header) - { - } - - public Mid0052(int revision) : base(MID, revision) { } - - public override string Pack() - { - var vinNumberField = GetField(1, DataFields.VinNumber); - if (Header.Revision > 1) - vinNumberField.HasPrefix = true; - - //Can be up to 40 bytes long - vinNumberField.Size = (VinNumber.Length > 25) ? VinNumber.Length : 25; - return base.Pack(); - } - - public override Mid Parse(string package) - { - Header = ProcessHeader(package); - if (Header.Revision > 1) - { - var vinNumberField = GetField(1, DataFields.VinNumber); - vinNumberField.HasPrefix = true; - vinNumberField.Size = Header.Length - 103; - if (vinNumberField.Size > 25) - { - int addedSize = vinNumberField.Size - 25; - GetField(2, DataFields.IdentifierResultPart2).Index += addedSize; - GetField(2, DataFields.IdentifierResultPart3).Index += addedSize; - GetField(2, DataFields.IdentifierResultPart4).Index += addedSize; - } - } - else - GetField(1, DataFields.VinNumber).Size = Header.Length - 20; - ProcessDataFields(package); - return this; - } - - protected override Dictionary> RegisterDatafields() - { - return new Dictionary>() - { - { - 1, new List() - { - DataField.String(DataFields.VinNumber, 20, 25, false) - } - }, - { - 2, new List() - { - DataField.String(DataFields.IdentifierResultPart2, 47, 25), - DataField.String(DataFields.IdentifierResultPart3, 74, 25), - DataField.String(DataFields.IdentifierResultPart4, 101, 25) - } - } - }; - } - - protected enum DataFields - { - VinNumber, - IdentifierResultPart2, - IdentifierResultPart3, - IdentifierResultPart4, - } - } -}