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
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx"
- uses: actions/upload-artifact@v4 # upload test results
if: success() || failure() # run this step even if previous step failed
with:
name: test-results
path: /home/runner/work/RfmOta/RfmOta/RfmOta.UnitTests/TestResults/test-results.trx
32 changes: 32 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish

on:
release:
types: [published]

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Pack
run: dotnet pack --configuration Release --no-restore
- name: Publish
uses: softprops/action-gh-release@v2.0.8
with:
files: |
/home/runner/work/RfmOta/RfmOta/bin/Debug/RfmOta*.nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Test Report'
on:
workflow_run:
workflows: ['Build'] # runs after CI workflow
types:
- completed
permissions:
contents: read
actions: read
checks: write
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
with:
artifact: test-results # artifact name
name: xUnit Tests # Name of the check run which will be created
path: '*.trx' # Path to test results (inside artifact .zip)
reporter: dotnet-trx # Format of test results
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# RfmOta

[![Build Status](https://dev.azure.com/DerekGn/GitHub/_apis/build/status/DerekGn.RfmOta?branchName=main)](https://dev.azure.com/DerekGn/GitHub/_build/latest?definitionId=6&branchName=main)
![GitHub Actions](https://github.com/DerekGn/RfmOta/actions/workflows/build.yml/badge.svg)

[![NuGet Badge](https://buildstats.info/nuget/RfmOta)](https://www.nuget.org/packages/RfmOta/)
[![NuGet](https://img.shields.io/nuget/v/RfmOta.svg?style=flat-square)](https://www.nuget.org/packages/RfmOta/)

A library for the flashing hex files to Rfm69 nodes over the air.

Expand All @@ -18,7 +18,7 @@ Install-Package RfmOta

The RfmOta package is compatible with the following runtimes:

* .NET Standard 2.1
* .NET Core 8

## Using OtaService

Expand Down
9 changes: 9 additions & 0 deletions RfmOta.UnitTests/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "namespace", Target = "~N:RfmOta.UnitTests")]
[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "type", Target = "~T:RfmOta.UnitTests.OtaServiceTests")]
32 changes: 17 additions & 15 deletions RfmOta.UnitTests/OtaServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* SOFTWARE.
*/

using FluentAssertions;
using HexIO;
using Microsoft.Extensions.Logging;
using Moq;
Expand Down Expand Up @@ -51,7 +50,7 @@ public OtaServiceTests()
_mockIntelHexReaderFactory = new Mock<IIntelHexStreamReaderFactory>();

_otaService = new OtaService(
Mock.Of<ILogger<IOtaService>>(),
Mock.Of<ILogger<OtaService>>(),
_mockRfmUsb.Object,
_mockIntelHexReaderFactory.Object);
}
Expand All @@ -61,13 +60,13 @@ public void TestGetFlashSizeOk()
{
// Arrange
_mockRfmUsb.Setup(_ => _.TransmitReceive(It.IsAny<List<byte>>(), It.IsAny<int>()))
.Returns(new List<byte>() { 13, (byte)ResponseType.FlashSize + 0x80, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 });
.Returns([13, (byte)ResponseType.FlashSize + 0x80, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55]);

// Act
var result = _otaService.GetFlashSize();

// Assert
result.Should().BeTrue();
Assert.True(result);
}

[Fact]
Expand All @@ -91,8 +90,9 @@ public void TestOtaUpdate()
bool result = _otaService.OtaUpdate(1, memoryStream, out uint crc);

// Assert
result.Should().BeTrue();
functionCalled.Should().BeTrue();
Assert.True(result);
Assert.Equal<uint>(0, crc);
Assert.True(functionCalled);
}

[Theory]
Expand All @@ -106,10 +106,11 @@ public void TestOtaUpdateInvalidPowerLevel(sbyte outputPower)
_otaService._steps = new List<Func<bool>>();

// Act
Action action = () => _otaService.OtaUpdate(outputPower, memoryStream, out uint crc);
void action() => _otaService.OtaUpdate(outputPower, memoryStream, out uint _);

// Assert
action.Should().Throw<ArgumentOutOfRangeException>().WithMessage("Specified argument was out of the range of valid values. (Parameter 'outputPower')");
ArgumentOutOfRangeException exception = Assert.Throws<ArgumentOutOfRangeException>(action);
Assert.Equal("Specified argument was out of the range of valid values. (Parameter 'outputPower')", exception.Message);
}

[Fact]
Expand All @@ -123,7 +124,7 @@ public void TestPingBootLoaderOk()
var result = _otaService.PingBootLoader();

// Assert
result.Should().BeTrue();
Assert.True(result);
}

[Fact]
Expand All @@ -136,7 +137,7 @@ public void TestRebootOk()
var result = _otaService.Reboot();

// Assert
result.Should().BeTrue();
Assert.True(result);
}

[Fact]
Expand All @@ -159,10 +160,11 @@ public void TestSendHexDataMax()
_otaService._flashInfo = new FlashInfo(0x0000, 20, 0x100);

// Act
Action action = () => { var result = _otaService.SendHexData(); };
void action() { _otaService.SendHexData(); }

// Assert
action.Should().Throw<OtaException>().WithMessage("Invalid flash write size [0xCE] Max: [0x40]");
OtaException exception = Assert.Throws<OtaException>(action);
Assert.Equal("Invalid flash write size [0xCE] Max: [0x40]", exception.Message);
}

[Fact]
Expand All @@ -189,7 +191,7 @@ public void TestSendHexDataOk()
var result = _otaService.SendHexData();

// Assert
result.Should().BeTrue();
Assert.True(result);
}

[Fact]
Expand All @@ -203,7 +205,7 @@ public void TestSetCrcNOk()
var result = _otaService.SetCrc();

// Assert
result.Should().BeFalse();
Assert.False(result);
}

[Fact]
Expand All @@ -217,7 +219,7 @@ public void TestSetCrcOk()
var result = _otaService.SetCrc();

// Assert
result.Should().BeTrue();
Assert.True(result);
}
}
}
18 changes: 11 additions & 7 deletions RfmOta.UnitTests/RfmOta.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
Expand All @@ -12,15 +12,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="9.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="Moq" Version="4.*" />
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.*">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PackageReference Include="coverlet.collector" Version="6.*">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
5 changes: 2 additions & 3 deletions RfmOta.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
# Visual Studio Version 17
VisualStudioVersion = 17.12.35728.132 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RfmOta", "RfmOta\RfmOta.csproj", "{903CC2C7-A5AD-45C6-8EE6-28E2699ACDF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RfmOta.UnitTests", "RfmOta.UnitTests\RfmOta.UnitTests.csproj", "{D972A29B-FC61-4CAA-825E-CD3A43E97971}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{62523B01-834B-4DAF-84E7-B6202DDDFB27}"
ProjectSection(SolutionItems) = preProject
azure-pipelines.yml = azure-pipelines.yml
README.md = README.md
EndProjectSection
EndProject
Expand Down
12 changes: 0 additions & 12 deletions RfmOta/Exceptions/OtaException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
*/

using System;
using System.Runtime.Serialization;

namespace RfmOta.Exceptions
{
/// <summary>
/// An <see cref="Exception"/> that is thrown when an error occurs during Ota updates
/// </summary>
[Serializable]
public class OtaException : Exception
{
/// <summary>
Expand All @@ -49,15 +47,5 @@ public OtaException(string message) : base(message) { }
/// <param name="inner">The exception that is the cause of the current exception,
/// or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
public OtaException(string message, Exception inner) : base(message, inner) { }
/// <summary>
/// Initializes a new instance of the <see cref="OtaException"/> class with serialized data.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds
/// the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information
/// about the source or destination.</param>
protected OtaException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}
3 changes: 3 additions & 0 deletions RfmOta/Factory/IIntelHexStreamReaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* SOFTWARE.
*/


// Ignore Spelling: Rfm Ota

using HexIO;
using System.IO;

Expand Down
3 changes: 3 additions & 0 deletions RfmOta/Factory/IntelHexStreamReaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* SOFTWARE.
*/


// Ignore Spelling: Rfm Ota

using HexIO;
using System.Diagnostics.CodeAnalysis;
using System.IO;
Expand Down
12 changes: 12 additions & 0 deletions RfmOta/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "member", Target = "~M:RfmOta.OtaService.#ctor(Microsoft.Extensions.Logging.ILogger{RfmOta.OtaService},RfmUsb.Net.IRfm69,RfmOta.Factory.IIntelHexStreamReaderFactory)")]
[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "member", Target = "~M:RfmOta.OtaService.OtaUpdate(System.SByte,System.IO.Stream,System.UInt32@)~System.Boolean")]
[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "namespace", Target = "~N:RfmOta")]
[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "namespace", Target = "~N:RfmOta.Exceptions")]
[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "type", Target = "~T:RfmOta.Exceptions.OtaException")]
3 changes: 3 additions & 0 deletions RfmOta/IOtaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* SOFTWARE.
*/


// Ignore Spelling: Ota

using RfmUsb.Net;
using System;
using System.IO;
Expand Down
Loading