From 0c0a54c515332b84fe8622224f15d83bc7d78b3a Mon Sep 17 00:00:00 2001 From: Andreas Kurzmann <81073076+stprograms@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:47:07 +0000 Subject: [PATCH 1/6] 17 - Moved project to separate folder --- .vscode/tasks.json | 6 ++-- RS485 Monitor.code-workspace | 2 +- .../RS485 Monitor.csproj | 2 +- .../appsettings.json | 0 {src => RS485 Monitor/src}/CmdOptions.cs | 0 {src => RS485 Monitor/src}/Configuration.cs | 0 {src => RS485 Monitor/src}/Program.cs | 0 {src => RS485 Monitor/src}/SerialMonitor.cs | 0 {src => RS485 Monitor/src}/TelegramParser.cs | 0 .../src}/Telegrams/BaseTelegram.cs | 0 .../src}/Telegrams/BatteryStatus.cs | 0 .../src}/Telegrams/ECUStatus.cs | 0 .../src}/Telegrams/GSMStatus.cs | 0 .../src}/Utils/ConsolePrinter.cs | 0 .../src}/Utils/IUserVisualizable.cs | 0 .../src}/Utils/LogPrinter.cs | 0 .../src}/Utils/SerialSimulator.cs | 0 .../src}/Utils/TelegramPlayer.cs | 0 SuperSoco485Monitor.sln | 28 +++++++++++++++++++ 19 files changed, 33 insertions(+), 5 deletions(-) rename RS485 Monitor.csproj => RS485 Monitor/RS485 Monitor.csproj (96%) rename appsettings.json => RS485 Monitor/appsettings.json (100%) rename {src => RS485 Monitor/src}/CmdOptions.cs (100%) rename {src => RS485 Monitor/src}/Configuration.cs (100%) rename {src => RS485 Monitor/src}/Program.cs (100%) rename {src => RS485 Monitor/src}/SerialMonitor.cs (100%) rename {src => RS485 Monitor/src}/TelegramParser.cs (100%) rename {src => RS485 Monitor/src}/Telegrams/BaseTelegram.cs (100%) rename {src => RS485 Monitor/src}/Telegrams/BatteryStatus.cs (100%) rename {src => RS485 Monitor/src}/Telegrams/ECUStatus.cs (100%) rename {src => RS485 Monitor/src}/Telegrams/GSMStatus.cs (100%) rename {src => RS485 Monitor/src}/Utils/ConsolePrinter.cs (100%) rename {src => RS485 Monitor/src}/Utils/IUserVisualizable.cs (100%) rename {src => RS485 Monitor/src}/Utils/LogPrinter.cs (100%) rename {src => RS485 Monitor/src}/Utils/SerialSimulator.cs (100%) rename {src => RS485 Monitor/src}/Utils/TelegramPlayer.cs (100%) create mode 100644 SuperSoco485Monitor.sln diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5b31cc3..e939e22 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/RS485 Monitor.csproj", + "${workspaceFolder}/SuperSoco485Monitor.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -19,7 +19,7 @@ "type": "process", "args": [ "publish", - "${workspaceFolder}/RS485 Monitor.csproj", + "${workspaceFolder}/SuperSoco485Monitor.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", "-c", @@ -43,4 +43,4 @@ "problemMatcher": "$msCompile" } ] -} \ No newline at end of file +} diff --git a/RS485 Monitor.code-workspace b/RS485 Monitor.code-workspace index a087624..7e29a07 100644 --- a/RS485 Monitor.code-workspace +++ b/RS485 Monitor.code-workspace @@ -17,4 +17,4 @@ "Xmanu" ] } -} \ No newline at end of file +} diff --git a/RS485 Monitor.csproj b/RS485 Monitor/RS485 Monitor.csproj similarity index 96% rename from RS485 Monitor.csproj rename to RS485 Monitor/RS485 Monitor.csproj index ea182ca..3e93316 100644 --- a/RS485 Monitor.csproj +++ b/RS485 Monitor/RS485 Monitor.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 RS485_Monitor enable enable diff --git a/appsettings.json b/RS485 Monitor/appsettings.json similarity index 100% rename from appsettings.json rename to RS485 Monitor/appsettings.json diff --git a/src/CmdOptions.cs b/RS485 Monitor/src/CmdOptions.cs similarity index 100% rename from src/CmdOptions.cs rename to RS485 Monitor/src/CmdOptions.cs diff --git a/src/Configuration.cs b/RS485 Monitor/src/Configuration.cs similarity index 100% rename from src/Configuration.cs rename to RS485 Monitor/src/Configuration.cs diff --git a/src/Program.cs b/RS485 Monitor/src/Program.cs similarity index 100% rename from src/Program.cs rename to RS485 Monitor/src/Program.cs diff --git a/src/SerialMonitor.cs b/RS485 Monitor/src/SerialMonitor.cs similarity index 100% rename from src/SerialMonitor.cs rename to RS485 Monitor/src/SerialMonitor.cs diff --git a/src/TelegramParser.cs b/RS485 Monitor/src/TelegramParser.cs similarity index 100% rename from src/TelegramParser.cs rename to RS485 Monitor/src/TelegramParser.cs diff --git a/src/Telegrams/BaseTelegram.cs b/RS485 Monitor/src/Telegrams/BaseTelegram.cs similarity index 100% rename from src/Telegrams/BaseTelegram.cs rename to RS485 Monitor/src/Telegrams/BaseTelegram.cs diff --git a/src/Telegrams/BatteryStatus.cs b/RS485 Monitor/src/Telegrams/BatteryStatus.cs similarity index 100% rename from src/Telegrams/BatteryStatus.cs rename to RS485 Monitor/src/Telegrams/BatteryStatus.cs diff --git a/src/Telegrams/ECUStatus.cs b/RS485 Monitor/src/Telegrams/ECUStatus.cs similarity index 100% rename from src/Telegrams/ECUStatus.cs rename to RS485 Monitor/src/Telegrams/ECUStatus.cs diff --git a/src/Telegrams/GSMStatus.cs b/RS485 Monitor/src/Telegrams/GSMStatus.cs similarity index 100% rename from src/Telegrams/GSMStatus.cs rename to RS485 Monitor/src/Telegrams/GSMStatus.cs diff --git a/src/Utils/ConsolePrinter.cs b/RS485 Monitor/src/Utils/ConsolePrinter.cs similarity index 100% rename from src/Utils/ConsolePrinter.cs rename to RS485 Monitor/src/Utils/ConsolePrinter.cs diff --git a/src/Utils/IUserVisualizable.cs b/RS485 Monitor/src/Utils/IUserVisualizable.cs similarity index 100% rename from src/Utils/IUserVisualizable.cs rename to RS485 Monitor/src/Utils/IUserVisualizable.cs diff --git a/src/Utils/LogPrinter.cs b/RS485 Monitor/src/Utils/LogPrinter.cs similarity index 100% rename from src/Utils/LogPrinter.cs rename to RS485 Monitor/src/Utils/LogPrinter.cs diff --git a/src/Utils/SerialSimulator.cs b/RS485 Monitor/src/Utils/SerialSimulator.cs similarity index 100% rename from src/Utils/SerialSimulator.cs rename to RS485 Monitor/src/Utils/SerialSimulator.cs diff --git a/src/Utils/TelegramPlayer.cs b/RS485 Monitor/src/Utils/TelegramPlayer.cs similarity index 100% rename from src/Utils/TelegramPlayer.cs rename to RS485 Monitor/src/Utils/TelegramPlayer.cs diff --git a/SuperSoco485Monitor.sln b/SuperSoco485Monitor.sln new file mode 100644 index 0000000..38fe37b --- /dev/null +++ b/SuperSoco485Monitor.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RS485 Monitor", "RS485 Monitor\RS485 Monitor.csproj", "{48CB4F5C-8ED9-411C-BB59-9977016601EA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{6A504182-F91E-4FC5-9148-C8ACFF2420BB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {48CB4F5C-8ED9-411C-BB59-9977016601EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48CB4F5C-8ED9-411C-BB59-9977016601EA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48CB4F5C-8ED9-411C-BB59-9977016601EA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48CB4F5C-8ED9-411C-BB59-9977016601EA}.Release|Any CPU.Build.0 = Release|Any CPU + {6A504182-F91E-4FC5-9148-C8ACFF2420BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A504182-F91E-4FC5-9148-C8ACFF2420BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A504182-F91E-4FC5-9148-C8ACFF2420BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A504182-F91E-4FC5-9148-C8ACFF2420BB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal From f697b3f5370c00a78abc021561db1aabeea7cc34 Mon Sep 17 00:00:00 2001 From: Andreas Kurzmann <81073076+stprograms@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:49:28 +0000 Subject: [PATCH 2/6] 17 - Introduced test project Added a testproject to the solution and created first dummy test --- tests/UnitTest1.cs | 18 ++++++++++++++++++ tests/tests.csproj | 30 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/UnitTest1.cs create mode 100644 tests/tests.csproj diff --git a/tests/UnitTest1.cs b/tests/UnitTest1.cs new file mode 100644 index 0000000..bc1c68a --- /dev/null +++ b/tests/UnitTest1.cs @@ -0,0 +1,18 @@ +namespace RS485_Monitor.tests; +using System; +using CommandLine; +using NUnit.Framework; + +public class Tests +{ + [SetUp] + public void Setup() + { + } + + [Test] + public void Test1() + { + Assert.Pass(); + } +} diff --git a/tests/tests.csproj b/tests/tests.csproj new file mode 100644 index 0000000..96e71e7 --- /dev/null +++ b/tests/tests.csproj @@ -0,0 +1,30 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + + + From e87d9eea758ae0fa2b0bd593a5e667c232159a49 Mon Sep 17 00:00:00 2001 From: Andreas Kurzmann <81073076+stprograms@users.noreply.github.com> Date: Wed, 19 Feb 2025 20:43:22 +0000 Subject: [PATCH 3/6] 17 - Telegram tests Added basic tests for the telegram classes. --- tests/BaseTelegramTest.cs | 45 +++++++++++++++++++++++++++++++++++ tests/BatteryStatusTest.cs | 48 ++++++++++++++++++++++++++++++++++++++ tests/ECUStatusTest.cs | 45 +++++++++++++++++++++++++++++++++++ tests/UnitTest1.cs | 18 -------------- 4 files changed, 138 insertions(+), 18 deletions(-) create mode 100644 tests/BaseTelegramTest.cs create mode 100644 tests/BatteryStatusTest.cs create mode 100644 tests/ECUStatusTest.cs delete mode 100644 tests/UnitTest1.cs diff --git a/tests/BaseTelegramTest.cs b/tests/BaseTelegramTest.cs new file mode 100644 index 0000000..86f8791 --- /dev/null +++ b/tests/BaseTelegramTest.cs @@ -0,0 +1,45 @@ +namespace RS485_Monitor.tests; +using NUnit.Framework; + +public class BaseTelegramTest +{ + [Test] + public void ParseTelegramSuccessful() + { + byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D }; + + BaseTelegram telegram = new(raw); + + Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_RESPONSE)); + Assert.That(telegram.Destination, Is.EqualTo(0xDA)); + Assert.That(telegram.Source, Is.EqualTo(0xAA)); + Assert.That(telegram.Valid, Is.EqualTo(true)); + } + + [Test] + public void ParseTelegramRequestSuccessful() + { + byte[] raw = new byte[] { 0xC5, 0x5C, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D }; + + BaseTelegram telegram = new(raw); + + Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_REQUEST)); + Assert.That(telegram.Destination, Is.EqualTo(0xDA)); + Assert.That(telegram.Source, Is.EqualTo(0xAA)); + Assert.That(telegram.Valid, Is.EqualTo(true)); + } + + [Test] + public void ParseTelegramWrongChecksum() + { + byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x10, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D }; + + BaseTelegram telegram = new(raw); + + Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_RESPONSE)); + Assert.That(telegram.Destination, Is.EqualTo(0xDA)); + Assert.That(telegram.Source, Is.EqualTo(0xAA)); + Assert.That(telegram.Valid, Is.EqualTo(false)); + } + +} diff --git a/tests/BatteryStatusTest.cs b/tests/BatteryStatusTest.cs new file mode 100644 index 0000000..de8da92 --- /dev/null +++ b/tests/BatteryStatusTest.cs @@ -0,0 +1,48 @@ +namespace RS485_Monitor.tests; +using NUnit.Framework; + +public class BatteryStatusTest +{ + private BaseTelegram? batteryBase = null; + + [SetUp] + public void Setup() + { + byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0x5A, 0x0A, 0x4D, 0x48, 0x17, 0x00, 0x00, 0x23, 0x00, 0x0B, 0x00, 0x00, 0x30, 0x0D }; + batteryBase = new BaseTelegram(raw); + } + + [Test] + public void ConvertToBatteryStatusSuccess() + { + BatteryStatus status = new(batteryBase!); + Assert.That(status, Is.Not.Null); + } + + [Test] + public void ConvertToBatteryStatusFail() + { + byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0x5A, 0x09, 0x4D, 0x48, 0x17, 0x00, 0x00, 0x23, 0x00, 0x0B, 0x00, 0x30, 0x0D }; + BaseTelegram invalidTelegram = new(raw); + + Assert.Throws(() => new BatteryStatus(invalidTelegram)); + } + + [Test] + public void CheckContent() + { + BatteryStatus status = new(batteryBase!); + using (Assert.EnterMultipleScope()) + { + Assert.That(status.Voltage, Is.EqualTo(77)); + Assert.That(status.SoC, Is.EqualTo(72)); + Assert.That(status.Temperature, Is.EqualTo(23)); + Assert.That(status.Charge, Is.EqualTo(0x0)); + Assert.That(status.Cycles, Is.EqualTo(35)); + Assert.That(status.DischargeCycles, Is.EqualTo(11)); + Assert.That(status.VBreaker, Is.EqualTo(BatteryStatus.VBreakerStatus.OK)); + Assert.That(status.Activity, Is.EqualTo(BatteryStatus.BatteryActivity.NO_ACTIVITY)); + Assert.That(status.Charging, Is.False); + } + } +} diff --git a/tests/ECUStatusTest.cs b/tests/ECUStatusTest.cs new file mode 100644 index 0000000..978fbc1 --- /dev/null +++ b/tests/ECUStatusTest.cs @@ -0,0 +1,45 @@ +namespace RS485_Monitor.tests; +using NUnit.Framework; + +public class ECUStatusTest +{ + private BaseTelegram? ecuBase; + + [SetUp] + public void Setup() + { + byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D }; + ecuBase = new BaseTelegram(raw); + } + + [Test] + public void ConvertToEcuStatusSuccess() + { + ECUStatus status = new(ecuBase!); + Assert.That(status, Is.Not.Null); + } + + [Test] + public void ConvertToEcuStatusFail() + { + byte[] raw = new byte[] { 0xC5, 0x5C, 0xBA, 0xAA, 0x0E, 0x48, 0x00, 0x00, 0x00, 0x16, 0x19, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x40, 0x0A, 0x0D }; + BaseTelegram gsmTelegram = new(raw); + + Assert.Throws(() => new ECUStatus(gsmTelegram)); + } + + [Test] + public void CheckContent() + { + ECUStatus status = new(ecuBase!); + using (Assert.EnterMultipleScope()) + { + Assert.That(status.Mode, Is.EqualTo(2)); + Assert.That(status.Current, Is.EqualTo(0.4).Within(0.1)); + Assert.That(status.Speed, Is.EqualTo(0)); + Assert.That(status.Temperature, Is.EqualTo(0x13)); + Assert.That(status.IsParking, Is.EqualTo(true)); + } + + } +} diff --git a/tests/UnitTest1.cs b/tests/UnitTest1.cs deleted file mode 100644 index bc1c68a..0000000 --- a/tests/UnitTest1.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace RS485_Monitor.tests; -using System; -using CommandLine; -using NUnit.Framework; - -public class Tests -{ - [SetUp] - public void Setup() - { - } - - [Test] - public void Test1() - { - Assert.Pass(); - } -} From 23ee67d87a144d561731e41d3f06a15bd88594f2 Mon Sep 17 00:00:00 2001 From: Andreas Kurzmann Date: Tue, 25 Feb 2025 09:36:03 +0100 Subject: [PATCH 4/6] 17 - introduced dotnet test job - Renamed file - added containerized test job - making buld job depended on test --- .github/workflows/{build.yml => dotnet.yml} | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) rename .github/workflows/{build.yml => dotnet.yml} (61%) diff --git a/.github/workflows/build.yml b/.github/workflows/dotnet.yml similarity index 61% rename from .github/workflows/build.yml rename to .github/workflows/dotnet.yml index 4a91d95..5281a50 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/dotnet.yml @@ -2,15 +2,26 @@ name: .NET Application Build on: push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - workflow_dispatch: + workflow_dispatch: jobs: + test: + runs-on: ubuntu-latest + container: mcr.microsoft.com/dotnet/sdk:8.0 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run tests + run: dotnet test + build: runs-on: windows-latest # For a list of available runner types, refer to - # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on + # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on + + needs: test steps: - name: Checkout uses: actions/checkout@v4 From 99e197e427da911a433bd3c9ec8fe953c11e9be1 Mon Sep 17 00:00:00 2001 From: Andreas Kurzmann Date: Tue, 25 Feb 2025 09:46:56 +0100 Subject: [PATCH 5/6] 17 - Using container for build Using docker container for the build task --- .github/workflows/dotnet.yml | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 5281a50..1d049f7 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,4 +1,4 @@ -name: .NET Application Build +name: .NET Test and Build on: push: @@ -18,25 +18,14 @@ jobs: run: dotnet test build: - runs-on: windows-latest # For a list of available runner types, refer to - # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on - needs: test + runs-on: ubuntu-latest + container: mcr.microsoft.com/dotnet/sdk:8.0 steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - # Install the .NET Core workload - - name: Install .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 6.0.x - - # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild - - name: Setup MSBuild.exe - uses: microsoft/setup-msbuild@v2 - - name: Build application run: dotnet build From 06089b6aea78288831e60c35d9e490a474c6c34c Mon Sep 17 00:00:00 2001 From: Andreas Kurzmann Date: Tue, 25 Feb 2025 09:57:09 +0100 Subject: [PATCH 6/6] 17 - Updated badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 092bfff..988702d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![.NET Workflow for test building](https://github.com/stprograms/SuperSoco485Monitor/actions/workflows/build.yml/badge.svg)](https://github.com/stprograms/SuperSoco485Monitor/actions/workflows/build.yml) +[![.NET Unit Test](https://github.com/stprograms/SuperSoco485Monitor/actions/workflows/dotnet.yml/badge.svg)](https://github.com/stprograms/SuperSoco485Monitor/actions/workflows/dotnet.yml) # SuperSoco485Monitor C# Application to monitor the communication on the internal RS485 Bus on SuperSoco Motorcycles