Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 0 additions & 31 deletions .github/workflows/build.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: .NET Test and Build

on:
push:
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:
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

- name: Build application
run: dotnet build
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/RS485 Monitor.csproj",
"${workspaceFolder}/SuperSoco485Monitor.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand All @@ -19,7 +19,7 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/RS485 Monitor.csproj",
"${workspaceFolder}/SuperSoco485Monitor.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
"-c",
Expand All @@ -43,4 +43,4 @@
"problemMatcher": "$msCompile"
}
]
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion RS485 Monitor.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"Xmanu"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>RS485_Monitor</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions SuperSoco485Monitor.sln
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions tests/BaseTelegramTest.cs
Original file line number Diff line number Diff line change
@@ -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));
}

}
48 changes: 48 additions & 0 deletions tests/BatteryStatusTest.cs
Original file line number Diff line number Diff line change
@@ -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<ArgumentException>(() => 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);
}
}
}
45 changes: 45 additions & 0 deletions tests/ECUStatusTest.cs
Original file line number Diff line number Diff line change
@@ -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<ArgumentException>(() => 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));
}

}
}
30 changes: 30 additions & 0 deletions tests/tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RS485 Monitor\RS485 Monitor.csproj" />
</ItemGroup>

</Project>