From b17051bc6353240a49871b063bea2acd81e14033 Mon Sep 17 00:00:00 2001 From: DerekGn Date: Thu, 25 Mar 2021 11:17:38 +0000 Subject: [PATCH] Refactored project structure --- RfmOTA/RfmOta.UnitTests/BaseTest.cs | 42 - .../RfmOta.UnitTests/Ota/OtaServiceTests.cs | 197 ----- .../Ota/TestRequestResponses.cs | 30 - RfmOTA/RfmOta.UnitTests/Ota/TestResponses.cs | 42 - RfmOTA/RfmOta.UnitTests/Rfm/RfmUsbTests.cs | 84 -- .../RfmOta.UnitTests/RfmOta.UnitTests.csproj | 26 - RfmOTA/RfmOta.sln | 31 - RfmOTA/RfmOta/Ota/Exceptions/OtaException.cs | 16 - RfmOTA/RfmOta/Ota/FlashWrite.cs | 33 - RfmOTA/RfmOta/Ota/IOtaService.cs | 34 - RfmOTA/RfmOta/Ota/OtaService.cs | 394 --------- RfmOTA/RfmOta/Ota/OtaServiceExtensions.cs | 38 - RfmOTA/RfmOta/Ota/PayloadSizes.cs | 37 - RfmOTA/RfmOta/Ota/RequestType.cs | 35 - RfmOTA/RfmOta/Ota/ResponseType.cs | 37 - RfmOTA/RfmOta/Ports/ISerialPort.cs | 810 ------------------ RfmOTA/RfmOta/Ports/ISerialPortFactory.cs | 34 - RfmOTA/RfmOta/Ports/PortsServiceExtensions.cs | 38 - RfmOTA/RfmOta/Ports/SerialPort.cs | 182 ---- RfmOTA/RfmOta/Ports/SerialPortFactory.cs | 41 - RfmOTA/RfmOta/Rfm/Dio.cs | 34 - RfmOTA/RfmOta/Rfm/DioMapping.cs | 34 - .../RfmUsbCommandExecutionException.cs | 40 - .../Exceptions/RfmUsbSerialPortException.cs | 40 - .../Rfm/Exceptions/RfmUsbTransmitException.cs | 38 - RfmOTA/RfmOta/Rfm/IRfmUsb.cs | 62 -- RfmOTA/RfmOta/Rfm/RfmUsb.cs | 268 ------ RfmOTA/RfmOta/Rfm/RfmUsbServiceExtensions.cs | 38 - RfmOtaClient/RfmOtaClient.sln | 31 + .../RfmOtaClient}/HexUtils.cs | 0 .../RfmOtaClient}/Options.cs | 10 +- .../RfmOtaClient}/Program.cs | 10 +- .../Properties/launchSettings.json | 0 .../RfmOtaClient/RfmOtaClient.csproj | 4 + .../RfmOtaClient}/appsettings.json | 0 35 files changed, 41 insertions(+), 2749 deletions(-) delete mode 100644 RfmOTA/RfmOta.UnitTests/BaseTest.cs delete mode 100644 RfmOTA/RfmOta.UnitTests/Ota/OtaServiceTests.cs delete mode 100644 RfmOTA/RfmOta.UnitTests/Ota/TestRequestResponses.cs delete mode 100644 RfmOTA/RfmOta.UnitTests/Ota/TestResponses.cs delete mode 100644 RfmOTA/RfmOta.UnitTests/Rfm/RfmUsbTests.cs delete mode 100644 RfmOTA/RfmOta.UnitTests/RfmOta.UnitTests.csproj delete mode 100644 RfmOTA/RfmOta.sln delete mode 100644 RfmOTA/RfmOta/Ota/Exceptions/OtaException.cs delete mode 100644 RfmOTA/RfmOta/Ota/FlashWrite.cs delete mode 100644 RfmOTA/RfmOta/Ota/IOtaService.cs delete mode 100644 RfmOTA/RfmOta/Ota/OtaService.cs delete mode 100644 RfmOTA/RfmOta/Ota/OtaServiceExtensions.cs delete mode 100644 RfmOTA/RfmOta/Ota/PayloadSizes.cs delete mode 100644 RfmOTA/RfmOta/Ota/RequestType.cs delete mode 100644 RfmOTA/RfmOta/Ota/ResponseType.cs delete mode 100644 RfmOTA/RfmOta/Ports/ISerialPort.cs delete mode 100644 RfmOTA/RfmOta/Ports/ISerialPortFactory.cs delete mode 100644 RfmOTA/RfmOta/Ports/PortsServiceExtensions.cs delete mode 100644 RfmOTA/RfmOta/Ports/SerialPort.cs delete mode 100644 RfmOTA/RfmOta/Ports/SerialPortFactory.cs delete mode 100644 RfmOTA/RfmOta/Rfm/Dio.cs delete mode 100644 RfmOTA/RfmOta/Rfm/DioMapping.cs delete mode 100644 RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbCommandExecutionException.cs delete mode 100644 RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbSerialPortException.cs delete mode 100644 RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbTransmitException.cs delete mode 100644 RfmOTA/RfmOta/Rfm/IRfmUsb.cs delete mode 100644 RfmOTA/RfmOta/Rfm/RfmUsb.cs delete mode 100644 RfmOTA/RfmOta/Rfm/RfmUsbServiceExtensions.cs create mode 100644 RfmOtaClient/RfmOtaClient.sln rename {RfmOTA/RfmOta => RfmOtaClient/RfmOtaClient}/HexUtils.cs (100%) rename {RfmOTA/RfmOta => RfmOtaClient/RfmOtaClient}/Options.cs (83%) rename {RfmOTA/RfmOta => RfmOtaClient/RfmOtaClient}/Program.cs (94%) rename {RfmOTA/RfmOta => RfmOtaClient/RfmOtaClient}/Properties/launchSettings.json (100%) rename RfmOTA/RfmOta/RfmOta.csproj => RfmOtaClient/RfmOtaClient/RfmOtaClient.csproj (93%) rename {RfmOTA/RfmOta => RfmOtaClient/RfmOtaClient}/appsettings.json (100%) diff --git a/RfmOTA/RfmOta.UnitTests/BaseTest.cs b/RfmOTA/RfmOta.UnitTests/BaseTest.cs deleted file mode 100644 index 189ca32..0000000 --- a/RfmOTA/RfmOta.UnitTests/BaseTest.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using Serilog; -using Xunit.Abstractions; - -namespace RfmOta.UnitTests -{ - public abstract class BaseTests - { - protected ILogger Logger; - - public BaseTests(ITestOutputHelper output) - { - Logger = new LoggerConfiguration() - .MinimumLevel.Verbose() - .WriteTo.TestOutput(output, Serilog.Events.LogEventLevel.Verbose) - .CreateLogger(); - } - } -} diff --git a/RfmOTA/RfmOta.UnitTests/Ota/OtaServiceTests.cs b/RfmOTA/RfmOta.UnitTests/Ota/OtaServiceTests.cs deleted file mode 100644 index a83b109..0000000 --- a/RfmOTA/RfmOta.UnitTests/Ota/OtaServiceTests.cs +++ /dev/null @@ -1,197 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using FluentAssertions; -using Microsoft.Extensions.Logging; -using Moq; -using RfmOta.Ota; -using RfmOta.Rfm; -using System.Collections.Generic; -using System.IO; -using Xunit; -using Xunit.Abstractions; - -namespace RfmOta.UnitTests.Ota -{ - public class OtaServiceTests : BaseTests - { - private readonly IOtaService _otaService; - private readonly Mock _mockRfmusb; - - public OtaServiceTests(ITestOutputHelper output) : base(output) - { - _mockRfmusb = new Mock(); - - _otaService = new OtaService(Mock.Of>(), _mockRfmusb.Object); - } - - [Fact] - public void TestOtaUpdatePingBootloaderFailed() - { - // Arrange - var stream = SetupHexStream(); - - _mockRfmusb.Setup(_ => _.TransmitReceive(It.IsAny>(), It.IsAny())) - .Returns(TestResponses.Empty); - - // Act - var result = _otaService.OtaUpdate(new Options() { }, stream, out _); - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void TestOtaUpdateGetFlashSizeFailed() - { - // Arrange - var stream = SetupHexStream(); - - _mockRfmusb.SetupSequence(_ => _.TransmitReceive(It.IsAny>(), It.IsAny())) - .Returns(TestResponses.PingOk) - .Returns(TestResponses.Empty); - - // Act - var result = _otaService.OtaUpdate(new Options() { }, stream, out _); - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void TestOtaUpdateEraseFailed() - { - // Arrange - var stream = SetupHexStream(); - - _mockRfmusb.SetupSequence(_ => _.TransmitReceive(It.IsAny>(), It.IsAny())) - .Returns(TestResponses.PingOk) - .Returns(TestResponses.FlashSizeOk) - .Returns(TestResponses.Empty); - - // Act - var result = _otaService.OtaUpdate(new Options() { }, stream, out _); - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void TestOtaUpdateSendHexDataFailed() - { - // Arrange - var stream = SetupHexStream(); - - _mockRfmusb.SetupSequence(_ => _.TransmitReceive(It.IsAny>(), It.IsAny())) - .Returns(TestResponses.PingOk) - .Returns(TestResponses.FlashSizeOk) - .Returns(TestResponses.Empty); - - // Act - var result = _otaService.OtaUpdate(new Options() { }, stream, out _); - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void TestOtaUpdateGetCrcFailed() - { - // Arrange - var stream = SetupHexStream(); - - _mockRfmusb.SetupSequence(_ => _.TransmitReceive(It.IsAny>(), It.IsAny())) - .Returns(TestResponses.PingOk) - .Returns(TestResponses.FlashSizeOk) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Empty); - - // Act - var result = _otaService.OtaUpdate(new Options() { }, stream, out _); - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void TestOtaUpdateRebootFailed() - { - // Arrange - var stream = SetupHexStream(); - - _mockRfmusb.SetupSequence(_ => _.TransmitReceive(It.IsAny>(), It.IsAny())) - .Returns(TestResponses.PingOk) - .Returns(TestResponses.FlashSizeOk) - .Returns(TestResponses.Empty); - - // Act - var result = _otaService.OtaUpdate(new Options() { }, stream, out _); - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void TestOtaUpdateSuceeded() - { - // Arrange - var stream = SetupHexStream(); - - _mockRfmusb.SetupSequence(_ => _.TransmitReceive(It.IsAny>(), It.IsAny())) - .Returns(TestResponses.PingOk) - .Returns(TestResponses.FlashSizeOk) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Ok) - .Returns(TestResponses.Crc); - - // Act - var result = _otaService.OtaUpdate(new Options() { }, stream, out _); - - // Assert - result.Should().BeTrue(); - } - - private Stream SetupHexStream() - { - var ms = new MemoryStream(); - var sw = new StreamWriter(ms); - - sw.WriteLine(":10010000214601360121470136007EFE09D2190140"); - sw.WriteLine(":100110002146017E17C20001FF5F16002148011928"); - sw.WriteLine(":10012000194E79234623965778239EDA3F01B2CAA7"); - sw.WriteLine(":100130003F0156702B5E712B722B732146013421C7"); - sw.WriteLine(":00000001FF"); - - sw.Flush(); - ms.Position = 0; - - return ms; - } - } -} diff --git a/RfmOTA/RfmOta.UnitTests/Ota/TestRequestResponses.cs b/RfmOTA/RfmOta.UnitTests/Ota/TestRequestResponses.cs deleted file mode 100644 index 9af0502..0000000 --- a/RfmOTA/RfmOta.UnitTests/Ota/TestRequestResponses.cs +++ /dev/null @@ -1,30 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -namespace RfmOta.UnitTests.Ota -{ - internal class TestRequestResponses - { - } -} diff --git a/RfmOTA/RfmOta.UnitTests/Ota/TestResponses.cs b/RfmOTA/RfmOta.UnitTests/Ota/TestResponses.cs deleted file mode 100644 index 1d8ccd2..0000000 --- a/RfmOTA/RfmOta.UnitTests/Ota/TestResponses.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using RfmOta.Ota; -using System.Collections.Generic; - -namespace RfmOta.UnitTests.Ota -{ - public static class TestResponses - { - public static List Empty = new List(); - - public static List Ok = new List() { (byte)ResponseType.Ok }; - - public static List PingOk = new List() { (byte)ResponseType.Ping }; - - public static List Crc = new List() { (byte)ResponseType.Crc, 0xAA, 0x55, 0xAA, 0x55 }; - - public static List FlashSizeOk = new List() { (byte)ResponseType.FlashSize, 0xAA, 0x55, 0xAA, 0x55 }; - } -} diff --git a/RfmOTA/RfmOta.UnitTests/Rfm/RfmUsbTests.cs b/RfmOTA/RfmOta.UnitTests/Rfm/RfmUsbTests.cs deleted file mode 100644 index 1b18a9a..0000000 --- a/RfmOTA/RfmOta.UnitTests/Rfm/RfmUsbTests.cs +++ /dev/null @@ -1,84 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using Microsoft.Extensions.Logging; -using Moq; -using RfmOta.Ports; -using RfmOta.Rfm; -using Xunit; -using Xunit.Abstractions; - -namespace RfmOta.UnitTests.Rfm -{ - public class RfmUsbTests : BaseTests - { - private readonly Mock _mockSerialPortFactory; - private readonly Mock _mockSerialPort; - private readonly IRfmUsb _rfmUsb; - - public RfmUsbTests(ITestOutputHelper output) : base(output) - { - _mockSerialPortFactory = new Mock(); - _mockSerialPort = new Mock(); - - _rfmUsb = new RfmUsb(Mock.Of>(), _mockSerialPortFactory.Object); - } - - [Fact] - public void TestOpen() - { - // Arrange - _mockSerialPortFactory - .Setup(_ => _.CreateSerialPortInstance(It.IsAny())) - .Returns(_mockSerialPort.Object); - - // Act - _rfmUsb.Open("ComPort", 9600); - - // Assert - _mockSerialPortFactory - .Verify(_ => _.CreateSerialPortInstance(It.IsAny()), Times.Once); - - _mockSerialPort.Verify(_ => _.Open(), Times.Once); - } - - //[Fact] - //public void TestOpen() - //{ - // // Arrange - // _mockSerialPortFactory - // .Setup(_ => _.CreateSerialPortInstance(It.IsAny())) - // .Returns(_mockSerialPort.Object); - - // // Act - // _rfmUsb.Open("ComPort"); - - // // Assert - // _mockSerialPortFactory - // .Verify(_ => _.CreateSerialPortInstance(It.IsAny()), Times.Once); - - // _mockSerialPort.Verify(_ => _.Open(), Times.Once); - //} - } -} diff --git a/RfmOTA/RfmOta.UnitTests/RfmOta.UnitTests.csproj b/RfmOTA/RfmOta.UnitTests/RfmOta.UnitTests.csproj deleted file mode 100644 index 660ba22..0000000 --- a/RfmOTA/RfmOta.UnitTests/RfmOta.UnitTests.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - netcoreapp3.1 - false - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - diff --git a/RfmOTA/RfmOta.sln b/RfmOTA/RfmOta.sln deleted file mode 100644 index 0fb3690..0000000 --- a/RfmOTA/RfmOta.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30114.105 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RfmOta", "RfmOTA\RfmOta.csproj", "{049EA8A8-9989-4EF9-B0A9-06A0F8322FF9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RfmOta.UnitTests", "RfmOta.UnitTests\RfmOta.UnitTests.csproj", "{C18B3F77-3838-4397-961B-0C2939197ACF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {049EA8A8-9989-4EF9-B0A9-06A0F8322FF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {049EA8A8-9989-4EF9-B0A9-06A0F8322FF9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {049EA8A8-9989-4EF9-B0A9-06A0F8322FF9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {049EA8A8-9989-4EF9-B0A9-06A0F8322FF9}.Release|Any CPU.Build.0 = Release|Any CPU - {C18B3F77-3838-4397-961B-0C2939197ACF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C18B3F77-3838-4397-961B-0C2939197ACF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C18B3F77-3838-4397-961B-0C2939197ACF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C18B3F77-3838-4397-961B-0C2939197ACF}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {CC936B5E-2B90-4A13-A929-51374E966C8C} - EndGlobalSection -EndGlobal diff --git a/RfmOTA/RfmOta/Ota/Exceptions/OtaException.cs b/RfmOTA/RfmOta/Ota/Exceptions/OtaException.cs deleted file mode 100644 index 6f0e4b3..0000000 --- a/RfmOTA/RfmOta/Ota/Exceptions/OtaException.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace RfmOta.Ota.Exceptions -{ - - [Serializable] - public class OtaException : Exception - { - public OtaException() { } - public OtaException(string message) : base(message) { } - public OtaException(string message, Exception inner) : base(message, inner) { } - protected OtaException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } -} diff --git a/RfmOTA/RfmOta/Ota/FlashWrite.cs b/RfmOTA/RfmOta/Ota/FlashWrite.cs deleted file mode 100644 index 4620205..0000000 --- a/RfmOTA/RfmOta/Ota/FlashWrite.cs +++ /dev/null @@ -1,33 +0,0 @@ - -using System.Collections.Generic; - -namespace RfmOta.Ota -{ - internal class FlashWrites - { - private readonly List> _writes; - - public FlashWrites() - { - _writes = new List>(); - } - - public IReadOnlyList> Writes => _writes.AsReadOnly(); - - public void AddWrite(IReadOnlyList write) - { - _writes.Add(write); - } - - public IReadOnlyList GetWritesBytes() - { - List writes = new List(); - foreach (var write in _writes) - { - writes.AddRange(write); - } - - return writes; - } - } -} diff --git a/RfmOTA/RfmOta/Ota/IOtaService.cs b/RfmOTA/RfmOta/Ota/IOtaService.cs deleted file mode 100644 index 682d09a..0000000 --- a/RfmOTA/RfmOta/Ota/IOtaService.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System; -using System.IO; - -namespace RfmOta.Ota -{ - interface IOtaService : IDisposable - { - bool OtaUpdate(Options options, Stream stream, out uint crc); - } -} diff --git a/RfmOTA/RfmOta/Ota/OtaService.cs b/RfmOTA/RfmOta/Ota/OtaService.cs deleted file mode 100644 index e9c6151..0000000 --- a/RfmOTA/RfmOta/Ota/OtaService.cs +++ /dev/null @@ -1,394 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using HexIO; -using Microsoft.Extensions.Logging; -using RfmOta.Ota.Exceptions; -using RfmOta.Rfm; -using RfmOta.Rfm.Exceptions; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; - -namespace RfmOta.Ota -{ - internal class OtaService : IOtaService - { - private readonly ILogger _logger; - private readonly List> _steps; - private readonly IRfmUsb _rfmUsb; - - private const int MaxFlashWriteSize = 64; - private const int FlashWriteRows = 2; - - private uint _flashWriteSize; - private uint _numberOfPages; - private uint _startAddress; - private uint _pageSize; - private Stream _stream; - private uint _crc; - - public OtaService(ILogger logger, IRfmUsb rfmUsb) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _rfmUsb = rfmUsb ?? throw new ArgumentNullException(nameof(rfmUsb)); - - _steps = new List> - { - () => PingBootLoader(), - () => GetFlashSize(), - () => SendHexData(), - () => SetCrc(), - () => Reboot() - }; - } - - public bool OtaUpdate(Options options, Stream stream, out uint crc) - { - if (options == null) - throw new ArgumentNullException(nameof(options)); - - _stream = stream ?? throw new ArgumentNullException(nameof(stream)); - - bool result = true; - - try - { - crc = 0; - InitaliseRfmUsb(options); - - foreach (var step in _steps) - { - if (!step()) - { - result = false; - break; - } - } - - crc = _crc; - } - finally - { - _rfmUsb?.Close(); - } - - return result; - } - - private bool SetCrc() - { - return HandleRfmUsbOperation( - nameof(OtaService), - () => - { - var requestBytes = new List() { 0x05, (byte)RequestType.Crc }; - requestBytes.AddRange(BitConverter.GetBytes(_flashWriteSize)); - - if (!SendAndValidateResponse( - requestBytes, - PayloadSizes.CrcResponse, - ResponseType.Crc, out IList response)) - { - return false; - } - - _crc = BitConverter.ToUInt32(response.ToArray(), 2); - _logger.LogInformation($"Flash Crc: [0x{_crc:X}]"); - - return true; - }); - } - - private bool Reboot() - { - return HandleRfmUsbOperation( - nameof(OtaService), - () => - { - SendRequest(new List() { 0x01, (byte)RequestType.Reboot }); - - _logger.LogInformation("Reboot Pending"); - - return true; - }); - } - - private bool SendHexData() - { - return HandleRfmUsbOperation( - nameof(OtaService), - () => - { - using IntelHexReader hexReader = new IntelHexReader(_stream); - - do - { - var flashWrites = new FlashWrites(); - - for (int i = 0; i < FlashWriteRows; i++) - { - if (hexReader.Read(out uint address, out IList hexData)) - { - if (hexData.Count > 0) - { - if (hexData.Count > MaxFlashWriteSize) - { - throw new OtaException($"Invalid flash write size [{hexData.Count}] Max: [{MaxFlashWriteSize}]"); - } - - _logger.LogInformation($"Writing Address: [0x{address:X}] Count: [0x{hexData.Count:X2}]" + - $" Data: [{BitConverter.ToString(hexData.ToArray()).Replace("-", "")}]"); - var write = new List(); - write.AddRange(BitConverter.GetBytes(address)); - write.AddRange(BitConverter.GetBytes(hexData.Count)); - write.AddRange(hexData); - flashWrites.AddWrite(write); - - _flashWriteSize += (uint)hexData.Count; - } - } - else - { - break; - } - } - - if (flashWrites.Writes.Count > 0) - { - var payload = flashWrites.GetWritesBytes(); - - var request = new List - { - (byte)(payload.Count + 2), - (byte)RequestType.Write, - (byte)flashWrites.Writes.Count, - }; - request.AddRange(payload); - - if (!SendAndValidateResponse( - request, PayloadSizes.OkResponse, ResponseType.Ok, out IList response)) - { - return false; - } - } - else - { - break; - } - } while (true); - - _logger.LogInformation($"[{nameof(SendHexData)}] Flash Complete Image Size: [0x{_flashWriteSize:X}]"); - return true; - }); - } - - private bool GetFlashSize() - { - return HandleRfmUsbOperation( - nameof(OtaService), - () => - { - if (!SendAndValidateResponse( - new List() { 0x01, (byte)RequestType.FlashSize }, - PayloadSizes.FlashSizeResponse, ResponseType.FlashSize, out IList response)) - { - return false; - } - - _startAddress = BitConverter.ToUInt32(response.ToArray(), 2); - _numberOfPages = BitConverter.ToUInt32(response.ToArray(), 6); - _pageSize = BitConverter.ToUInt32(response.ToArray(), 10); - _logger.LogInformation($"App Start Address: [0x{_startAddress:X}] Number Of Pages: [0x{_numberOfPages:X}] " + - $"Page Size: [0x{_pageSize:X}] Flash Size: [0x{_numberOfPages * _pageSize:X}]"); - - return true; - }); - } - - private bool PingBootLoader() - { - return HandleRfmUsbOperation( - nameof(OtaService), - () => - { - if (!SendAndValidateResponse( - new List() { 0x01, (byte)RequestType.Ping }, - PayloadSizes.PingResponse, ResponseType.Ping, out IList response)) - { - _logger.LogInformation("BootLoader Ping NOk"); - return false; - } - - _logger.LogInformation("BootLoader Ping Ok"); - - return true; - }); - } - - private bool SendAndValidateResponse(IList request, - int expectedSize, ResponseType expectedResponse, - out IList response, [CallerMemberName] string memberName = "") - { - Stopwatch sw = new Stopwatch(); - - try - { - sw.Start(); - - response = _rfmUsb.TransmitReceive(request, 1000); - - if (response.Count == 0 || response.Count < expectedSize) - { - _logger.LogError($"Invalid response received [{BitConverter.ToString(response.ToArray())}]"); - - return false; - } - - if (response[0] != (byte)expectedSize) - { - _logger.LogInformation($"BootLoader Invalid {memberName} Response Length: [{response[0]}]"); - - return false; - } - - if (response[1] != (byte)expectedResponse + 0x80) - { - _logger.LogInformation($"BootLoader Invalid {memberName} Response: [{(ResponseType)(response[1] - 0x80)}]"); - - return false; - } - } - finally - { - sw.Stop(); - } - - _logger.LogInformation($"BootLoader {memberName} Ok. Tx Time: [{sw.ElapsedTicks * 1000 / Stopwatch.Frequency} ms]"); - - return true; - } - private void SendRequest(IList request, [CallerMemberName] string memberName = "") - { - Stopwatch sw = new Stopwatch(); - - try - { - sw.Start(); - - _rfmUsb.Transmit(request); - } - finally - { - sw.Stop(); - } - - _logger.LogInformation($"BootLoader {memberName} Ok. Tx Time: [{sw.ElapsedTicks * 1000 / Stopwatch.Frequency} ms]"); - } - private bool HandleRfmUsbOperation(string className, Func operation, [CallerMemberName] string memberName = "") - { - Stopwatch sw = new Stopwatch(); - bool result; - - try - { - sw.Start(); - result = operation(); - sw.Stop(); - - _logger.LogDebug($"Executed [{className}].[{memberName}] in [{sw.Elapsed.TotalMilliseconds}] ms"); - } - catch (RfmUsbTransmitException ex) - { - _logger.LogError($"A transmission exception occurred executing [{className}].[{memberName}] Reason: [{ex.Message}]"); - _logger.LogDebug(ex, $"A transmission exception occurred executing [{className}].[{memberName}]"); - - return false; - } - - return result; - } - - private void InitaliseRfmUsb(Options options) - { - _rfmUsb.Open(options.SerialPort, options.BaudRate); - - _rfmUsb.Reset(); - - _logger.LogInformation(_rfmUsb.Version); - - _rfmUsb.RadioConfig = 23; - - _rfmUsb.VariableLenght = true; - - _rfmUsb.TransmissionStartCondition = true; - - _rfmUsb.Sync = new List() { 0x55, 0x55 }; - - _rfmUsb.OutputPower = 1; - - _rfmUsb.RetryCount = options.RetryCount; - - _rfmUsb.Timeout = options.Timeout; - } - - #region - private bool _disposedValue; - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - if (disposing) - { - _rfmUsb?.Close(); - _rfmUsb?.Dispose(); - } - - // TODO: free unmanaged resources (unmanaged objects) and override finalizer - // TODO: set large fields to null - _disposedValue = true; - } - } - - // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources - // ~OtaService() - // { - // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - // Dispose(disposing: false); - // } - - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - - #endregion - } -} diff --git a/RfmOTA/RfmOta/Ota/OtaServiceExtensions.cs b/RfmOTA/RfmOta/Ota/OtaServiceExtensions.cs deleted file mode 100644 index f0bc5c6..0000000 --- a/RfmOTA/RfmOta/Ota/OtaServiceExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using Microsoft.Extensions.DependencyInjection; - -namespace RfmOta.Ota -{ - internal static class OtaServiceExtensions - { - public static IServiceCollection AddOta(this IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(); - - return serviceCollection; - } - } -} diff --git a/RfmOTA/RfmOta/Ota/PayloadSizes.cs b/RfmOTA/RfmOta/Ota/PayloadSizes.cs deleted file mode 100644 index 6d12f6e..0000000 --- a/RfmOTA/RfmOta/Ota/PayloadSizes.cs +++ /dev/null @@ -1,37 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -namespace RfmOta.Ota -{ - internal static class PayloadSizes - { - public const int FlashSizeResponse = 13; - - public const int PingResponse = 1; - - public const int CrcResponse = 5; - - public const int OkResponse = 1; - } -} diff --git a/RfmOTA/RfmOta/Ota/RequestType.cs b/RfmOTA/RfmOta/Ota/RequestType.cs deleted file mode 100644 index 3566d77..0000000 --- a/RfmOTA/RfmOta/Ota/RequestType.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -namespace RfmOta.Ota -{ - internal enum RequestType - { - Crc, - Ping, - Write, - Reboot, - FlashSize - }; -} diff --git a/RfmOTA/RfmOta/Ota/ResponseType.cs b/RfmOTA/RfmOta/Ota/ResponseType.cs deleted file mode 100644 index a304f7f..0000000 --- a/RfmOTA/RfmOta/Ota/ResponseType.cs +++ /dev/null @@ -1,37 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -namespace RfmOta.Ota -{ - internal enum ResponseType - { - Ok, - Crc, - Ping, - FlashSize, - ErrorNumberWrites, - ErrorInvalidLength, - ErrorInvalidWrite - }; -} diff --git a/RfmOTA/RfmOta/Ports/ISerialPort.cs b/RfmOTA/RfmOta/Ports/ISerialPort.cs deleted file mode 100644 index b84aeee..0000000 --- a/RfmOTA/RfmOta/Ports/ISerialPort.cs +++ /dev/null @@ -1,810 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System; -using System.IO; -using System.IO.Ports; -using System.Text; - -namespace RfmOta.Ports -{ - internal interface ISerialPort : IDisposable - { - // - // Summary: - // Gets or sets the handshaking protocol for serial port transmission of data using - // a value from System.IO.Ports.Handshake. - // - // Returns: - // One of the System.IO.Ports.Handshake values. The default is None. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.ArgumentOutOfRangeException: - // The value passed is not a valid value in the System.IO.Ports.Handshake enumeration. - public Handshake Handshake { get; set; } - // - // Summary: - // Gets or sets the byte encoding for pre- and post-transmission conversion of text. - // - // Returns: - // An System.Text.Encoding object. The default is System.Text.ASCIIEncoding. - // - // Exceptions: - // T:System.ArgumentNullException: - // The System.IO.Ports.SerialPort.Encoding property was set to null. - // - // T:System.ArgumentException: - // The System.IO.Ports.SerialPort.Encoding property was set to an encoding that - // is not System.Text.ASCIIEncoding, System.Text.UTF8Encoding, System.Text.UTF32Encoding, - // System.Text.UnicodeEncoding, one of the Windows single byte encodings, or one - // of the Windows double byte encodings. - public Encoding Encoding { get; set; } - // - // Summary: - // Gets or sets a value that enables the Data Terminal Ready (DTR) signal during - // serial communication. - // - // Returns: - // true to enable Data Terminal Ready (DTR); otherwise, false. The default is false. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - public bool DtrEnable { get; set; } - // - // Summary: - // Gets the state of the Clear-to-Send line. - // - // Returns: - // true if the Clear-to-Send line is detected; otherwise, false. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public bool CtsHolding { get; } - // - // Summary: - // Gets or sets a value indicating whether null bytes are ignored when transmitted - // between the port and the receive buffer. - // - // Returns: - // true if null bytes are ignored; otherwise false. The default is false. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public bool DiscardNull { get; set; } - // - // Summary: - // Gets or sets the standard length of data bits per byte. - // - // Returns: - // The data bits length. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.ArgumentOutOfRangeException: - // The data bits value is less than 5 or more than 8. - public int DataBits { get; set; } - // - // Summary: - // Gets a value indicating the open or closed status of the System.IO.Ports.SerialPort - // object. - // - // Returns: - // true if the serial port is open; otherwise, false. The default is false. - // - // Exceptions: - // T:System.ArgumentNullException: - // The System.IO.Ports.SerialPort.IsOpen value passed is null. - // - // T:System.ArgumentException: - // The System.IO.Ports.SerialPort.IsOpen value passed is an empty string (""). - public bool IsOpen { get; } - // - // Summary: - // Gets the state of the Data Set Ready (DSR) signal. - // - // Returns: - // true if a Data Set Ready signal has been sent to the port; otherwise, false. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public bool DsrHolding { get; } - // - // Summary: - // Gets or sets the value used to interpret the end of a call to the System.IO.Ports.SerialPort.ReadLine - // and System.IO.Ports.SerialPort.WriteLine(System.String) methods. - // - // Returns: - // A value that represents the end of a line. The default is a line feed ("\n" in - // C# or Microsoft.VisualBasic.Constants.vbLf in Visual Basic). - // - // Exceptions: - // T:System.ArgumentException: - // The property value is empty. - // - // T:System.ArgumentNullException: - // The property value is null. - public string NewLine { get; set; } - // - // Summary: - // Gets or sets the size of the System.IO.Ports.SerialPort input buffer. - // - // Returns: - // The buffer size, in bytes. The default value is 4096; the maximum value is that - // of a positive int, or 2147483647. - // - // Exceptions: - // T:System.ArgumentOutOfRangeException: - // The System.IO.Ports.SerialPort.ReadBufferSize value set is less than or equal - // to zero. - // - // T:System.InvalidOperationException: - // The System.IO.Ports.SerialPort.ReadBufferSize property was set while the stream - // was open. - // - // T:System.IO.IOException: - // The System.IO.Ports.SerialPort.ReadBufferSize property was set to an odd integer - // value. - public int ReadBufferSize { get; set; } - // - // Summary: - // Gets or sets the byte that replaces invalid bytes in a data stream when a parity - // error occurs. - // - // Returns: - // A byte that replaces invalid bytes. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - public byte ParityReplace { get; set; } - // - // Summary: - // Gets or sets the port for communications, including but not limited to all available - // COM ports. - // - // Returns: - // The communications port. The default is COM1. - // - // Exceptions: - // T:System.ArgumentException: - // The System.IO.Ports.SerialPort.PortName property was set to a value with a length - // of zero. -or- The System.IO.Ports.SerialPort.PortName property was set to a value - // that starts with "\\". -or- The port name was not valid. - // - // T:System.ArgumentNullException: - // The System.IO.Ports.SerialPort.PortName property was set to null. - // - // T:System.InvalidOperationException: - // The specified port is open. - public string PortName { get; set; } - // - // Summary: - // Gets the state of the Carrier Detect line for the port. - // - // Returns: - // true if the carrier is detected; otherwise, false. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public bool CDHolding { get; } - // - // Summary: - // Gets or sets the number of milliseconds before a time-out occurs when a read - // operation does not finish. - // - // Returns: - // The number of milliseconds before a time-out occurs when a read operation does - // not finish. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.ArgumentOutOfRangeException: - // The read time-out value is less than zero and not equal to System.IO.Ports.SerialPort.InfiniteTimeout. - public int ReadTimeout { get; set; } - // - // Summary: - // Gets or sets the number of bytes in the internal input buffer before a System.IO.Ports.SerialPort.DataReceived - // event occurs. - // - // Returns: - // The number of bytes in the internal input buffer before a System.IO.Ports.SerialPort.DataReceived - // event is fired. The default is 1. - // - // Exceptions: - // T:System.ArgumentOutOfRangeException: - // The System.IO.Ports.SerialPort.ReceivedBytesThreshold value is less than or equal - // to zero. - public int ReceivedBytesThreshold { get; set; } - // - // Summary: - // Gets or sets a value indicating whether the Request to Send (RTS) signal is enabled - // during serial communication. - // - // Returns: - // true to enable Request to Transmit (RTS); otherwise, false. The default is false. - // - // Exceptions: - // T:System.InvalidOperationException: - // The value of the System.IO.Ports.SerialPort.RtsEnable property was set or retrieved - // while the System.IO.Ports.SerialPort.Handshake property is set to the System.IO.Ports.Handshake.RequestToSend - // value or the System.IO.Ports.Handshake.RequestToSendXOnXOff value. - // - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - public bool RtsEnable { get; set; } - // - // Summary: - // Gets or sets the standard number of stopbits per byte. - // - // Returns: - // One of the System.IO.Ports.StopBits values. - // - // Exceptions: - // T:System.ArgumentOutOfRangeException: - // The System.IO.Ports.SerialPort.StopBits value is System.IO.Ports.StopBits.None. - // - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - public StopBits StopBits { get; set; } - // - // Summary: - // Gets or sets the size of the serial port output buffer. - // - // Returns: - // The size of the output buffer. The default is 2048. - // - // Exceptions: - // T:System.ArgumentOutOfRangeException: - // The System.IO.Ports.SerialPort.WriteBufferSize value is less than or equal to - // zero. - // - // T:System.InvalidOperationException: - // The System.IO.Ports.SerialPort.WriteBufferSize property was set while the stream - // was open. - // - // T:System.IO.IOException: - // The System.IO.Ports.SerialPort.WriteBufferSize property was set to an odd integer - // value. - public int WriteBufferSize { get; set; } - // - // Summary: - // Gets or sets the number of milliseconds before a time-out occurs when a write - // operation does not finish. - // - // Returns: - // The number of milliseconds before a time-out occurs. The default is System.IO.Ports.SerialPort.InfiniteTimeout. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.ArgumentOutOfRangeException: - // The System.IO.Ports.SerialPort.WriteTimeout value is less than zero and not equal - // to System.IO.Ports.SerialPort.InfiniteTimeout. - public int WriteTimeout { get; set; } - // - // Summary: - // Gets or sets the parity-checking protocol. - // - // Returns: - // One of the enumeration values that represents the parity-checking protocol. The - // default is System.IO.Ports.Parity.None. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.ArgumentOutOfRangeException: - // The System.IO.Ports.SerialPort.Parity value passed is not a valid value in the - // System.IO.Ports.Parity enumeration. - public Parity Parity { get; set; } - // - // Summary: - // Gets the number of bytes of data in the send buffer. - // - // Returns: - // The number of bytes of data in the send buffer. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public int BytesToWrite { get; } - // - // Summary: - // Gets or sets the serial baud rate. - // - // Returns: - // The baud rate. - // - // Exceptions: - // T:System.ArgumentOutOfRangeException: - // The baud rate specified is less than or equal to zero, or is greater than the - // maximum allowable baud rate for the device. - // - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - public int BaudRate { get; set; } - // - // Summary: - // Gets or sets the break signal state. - // - // Returns: - // true if the port is in a break state; otherwise, false. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public bool BreakState { get; set; } - // - // Summary: - // Gets the underlying System.IO.Stream object for a System.IO.Ports.SerialPort - // object. - // - // Returns: - // A System.IO.Stream object. - // - // Exceptions: - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - // - // T:System.NotSupportedException: - // The stream is in a .NET Compact Framework application and one of the following - // methods was called: System.IO.Stream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)System.IO.Stream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)System.IO.Stream.EndRead(System.IAsyncResult)System.IO.Stream.EndWrite(System.IAsyncResult) - // The .NET Compact Framework does not support the asynchronous model with base - // streams. - public Stream BaseStream { get; } - // - // Summary: - // Gets the number of bytes of data in the receive buffer. - // - // Returns: - // The number of bytes of data in the receive buffer. - // - // Exceptions: - // T:System.InvalidOperationException: - // The port is not open. - public int BytesToRead { get; } - - // - // Summary: - // Indicates that data has been received through a port represented by the System.IO.Ports.SerialPort - // object. - public event SerialDataReceivedEventHandler DataReceived; - // - // Summary: - // Indicates that a non-data signal event has occurred on the port represented by - // the System.IO.Ports.SerialPort object. - public event SerialPinChangedEventHandler PinChanged; - // - // Summary: - // Indicates that an error has occurred with a port represented by a System.IO.Ports.SerialPort - // object. - public event SerialErrorReceivedEventHandler ErrorReceived; - - // - // Summary: - // Closes the port connection, sets the System.IO.Ports.SerialPort.IsOpen property - // to false, and disposes of the internal System.IO.Stream object. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - public void Close(); - // - // Summary: - // Discards data from the serial driver's receive buffer. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public void DiscardInBuffer(); - // - // Summary: - // Discards data from the serial driver's transmit buffer. - // - // Exceptions: - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The stream is closed. This can occur because the System.IO.Ports.SerialPort.Open - // method has not been called or the System.IO.Ports.SerialPort.Close method has - // been called. - public void DiscardOutBuffer(); - // - // Summary: - // Opens a new serial port connection. - // - // Exceptions: - // T:System.UnauthorizedAccessException: - // Access is denied to the port. -or- The current process, or another process on - // the system, already has the specified COM port open either by a System.IO.Ports.SerialPort - // instance or in unmanaged code. - // - // T:System.ArgumentOutOfRangeException: - // One or more of the properties for this instance are invalid. For example, the - // System.IO.Ports.SerialPort.Parity, System.IO.Ports.SerialPort.DataBits, or System.IO.Ports.SerialPort.Handshake - // properties are not valid values; the System.IO.Ports.SerialPort.BaudRate is less - // than or equal to zero; the System.IO.Ports.SerialPort.ReadTimeout or System.IO.Ports.SerialPort.WriteTimeout - // property is less than zero and is not System.IO.Ports.SerialPort.InfiniteTimeout. - // - // T:System.ArgumentException: - // The port name does not begin with "COM". -or- The file type of the port is not - // supported. - // - // T:System.IO.IOException: - // The port is in an invalid state. -or- An attempt to set the state of the underlying - // port failed. For example, the parameters passed from this System.IO.Ports.SerialPort - // object were invalid. - // - // T:System.InvalidOperationException: - // The specified port on the current instance of the System.IO.Ports.SerialPort - // is already open. - public void Open(); - // - // Summary: - // Reads a number of bytes from the System.IO.Ports.SerialPort input buffer and - // writes those bytes into a byte array at the specified offset. - // - // Parameters: - // buffer: - // The byte array to write the input to. - // - // offset: - // The offset in buffer at which to write the bytes. - // - // count: - // The maximum number of bytes to read. Fewer bytes are read if count is greater - // than the number of bytes in the input buffer. - // - // Returns: - // The number of bytes read. - // - // Exceptions: - // T:System.ArgumentNullException: - // The buffer passed is null. - // - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.ArgumentOutOfRangeException: - // The offset or count parameters are outside a valid region of the buffer being - // passed. Either offset or count is less than zero. - // - // T:System.ArgumentException: - // offset plus count is greater than the length of the buffer. - // - // T:System.TimeoutException: - // No bytes were available to read. - public int Read(byte[] buffer, int offset, int count); - // - // Summary: - // Reads a number of characters from the System.IO.Ports.SerialPort input buffer - // and writes them into an array of characters at a given offset. - // - // Parameters: - // buffer: - // The character array to write the input to. - // - // offset: - // The offset in buffer at which to write the characters. - // - // count: - // The maximum number of characters to read. Fewer characters are read if count - // is greater than the number of characters in the input buffer. - // - // Returns: - // The number of characters read. - // - // Exceptions: - // T:System.ArgumentException: - // offset plus count is greater than the length of the buffer. -or- count is 1 and - // there is a surrogate character in the buffer. - // - // T:System.ArgumentNullException: - // The buffer passed is null. - // - // T:System.ArgumentOutOfRangeException: - // The offset or count parameters are outside a valid region of the buffer being - // passed. Either offset or count is less than zero. - // - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.TimeoutException: - // No characters were available to read. - public int Read(char[] buffer, int offset, int count); - // - // Summary: - // Synchronously reads one byte from the System.IO.Ports.SerialPort input buffer. - // - // Returns: - // The byte, cast to an System.Int32, or -1 if the end of the stream has been read. - // - // Exceptions: - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.ServiceProcess.TimeoutException: - // The operation did not complete before the time-out period ended. -or- No byte - // was read. - public int ReadByte(); - // - // Summary: - // Synchronously reads one character from the System.IO.Ports.SerialPort input buffer. - // - // Returns: - // The character that was read. - // - // Exceptions: - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.ServiceProcess.TimeoutException: - // The operation did not complete before the time-out period ended. -or- No character - // was available in the allotted time-out period. - public int ReadChar(); - // - // Summary: - // Reads all immediately available bytes, based on the encoding, in both the stream - // and the input buffer of the System.IO.Ports.SerialPort object. - // - // Returns: - // The contents of the stream and the input buffer of the System.IO.Ports.SerialPort - // object. - // - // Exceptions: - // T:System.InvalidOperationException: - // The specified port is not open. - public string ReadExisting(); - // - // Summary: - // Reads up to the System.IO.Ports.SerialPort.NewLine value in the input buffer. - // - // Returns: - // The contents of the input buffer up to the first occurrence of a System.IO.Ports.SerialPort.NewLine - // value. - // - // Exceptions: - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.TimeoutException: - // The operation did not complete before the time-out period ended. -or- No bytes - // were read. - public string ReadLine(); - // - // Summary: - // Reads a string up to the specified value in the input buffer. - // - // Parameters: - // value: - // A value that indicates where the read operation stops. - // - // Returns: - // The contents of the input buffer up to the specified value. - // - // Exceptions: - // T:System.ArgumentException: - // The length of the value parameter is 0. - // - // T:System.ArgumentNullException: - // The value parameter is null. - // - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.TimeoutException: - // The operation did not complete before the time-out period ended. - public string ReadTo(string value); - // - // Summary: - // Writes a specified number of bytes to the serial port using data from a buffer. - // - // Parameters: - // buffer: - // The byte array that contains the data to write to the port. - // - // offset: - // The zero-based byte offset in the buffer parameter at which to begin copying - // bytes to the port. - // - // count: - // The number of bytes to write. - // - // Exceptions: - // T:System.ArgumentNullException: - // The buffer passed is null. - // - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.ArgumentOutOfRangeException: - // The offset or count parameters are outside a valid region of the buffer being - // passed. Either offset or count is less than zero. - // - // T:System.ArgumentException: - // offset plus count is greater than the length of the buffer. - // - // T:System.ServiceProcess.TimeoutException: - // The operation did not complete before the time-out period ended. - public void Write(byte[] buffer, int offset, int count); - // - // Summary: - // Writes the specified string to the serial port. - // - // Parameters: - // text: - // The string for output. - // - // Exceptions: - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.ArgumentNullException: - // text is null. - // - // T:System.ServiceProcess.TimeoutException: - // The operation did not complete before the time-out period ended. - public void Write(string text); - // - // Summary: - // Writes a specified number of characters to the serial port using data from a - // buffer. - // - // Parameters: - // buffer: - // The character array that contains the data to write to the port. - // - // offset: - // The zero-based byte offset in the buffer parameter at which to begin copying - // bytes to the port. - // - // count: - // The number of characters to write. - // - // Exceptions: - // T:System.ArgumentNullException: - // The buffer passed is null. - // - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.ArgumentOutOfRangeException: - // The offset or count parameters are outside a valid region of the buffer being - // passed. Either offset or count is less than zero. - // - // T:System.ArgumentException: - // offset plus count is greater than the length of the buffer. - // - // T:System.ServiceProcess.TimeoutException: - // The operation did not complete before the time-out period ended. - public void Write(char[] buffer, int offset, int count); - // - // Summary: - // Writes the specified string and the System.IO.Ports.SerialPort.NewLine value - // to the output buffer. - // - // Parameters: - // text: - // The string to write to the output buffer. - // - // Exceptions: - // T:System.ArgumentNullException: - // The text parameter is null. - // - // T:System.InvalidOperationException: - // The specified port is not open. - // - // T:System.TimeoutException: - // The System.IO.Ports.SerialPort.WriteLine(System.String) method could not write - // to the stream. - public void WriteLine(string text); - } -} diff --git a/RfmOTA/RfmOta/Ports/ISerialPortFactory.cs b/RfmOTA/RfmOta/Ports/ISerialPortFactory.cs deleted file mode 100644 index d970e37..0000000 --- a/RfmOTA/RfmOta/Ports/ISerialPortFactory.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System.Collections.Generic; - -namespace RfmOta.Ports -{ - internal interface ISerialPortFactory - { - IList GetSerialPorts(); - ISerialPort CreateSerialPortInstance(string serialPort); - } -} diff --git a/RfmOTA/RfmOta/Ports/PortsServiceExtensions.cs b/RfmOTA/RfmOta/Ports/PortsServiceExtensions.cs deleted file mode 100644 index 6073afc..0000000 --- a/RfmOTA/RfmOta/Ports/PortsServiceExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using Microsoft.Extensions.DependencyInjection; - -namespace RfmOta.Ports -{ - internal static class PortsServiceExtensions - { - public static IServiceCollection AddPorts(this IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(); - - return serviceCollection; - } - } -} diff --git a/RfmOTA/RfmOta/Ports/SerialPort.cs b/RfmOTA/RfmOta/Ports/SerialPort.cs deleted file mode 100644 index a006fb2..0000000 --- a/RfmOTA/RfmOta/Ports/SerialPort.cs +++ /dev/null @@ -1,182 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System; -using System.IO; -using System.IO.Ports; -using System.Text; - -namespace RfmOta.Ports -{ - internal class SerialPort : ISerialPort - { - private readonly System.IO.Ports.SerialPort _serialPort; - - public SerialPort(string serialPort) - { - if (string.IsNullOrWhiteSpace(serialPort)) - { - throw new ArgumentOutOfRangeException(nameof(serialPort)); - } - - _serialPort = new System.IO.Ports.SerialPort - { - PortName = serialPort - }; - - _serialPort.ErrorReceived += ErrorReceivedHandler; - _serialPort.DataReceived += DataReceivedHandler; - _serialPort.PinChanged += PinChangedHandler; - } - public Handshake Handshake { get => _serialPort.Handshake; set => _serialPort.Handshake = value; } - public Encoding Encoding { get => _serialPort.Encoding; set => _serialPort.Encoding = value; } - public bool DtrEnable { get => _serialPort.DtrEnable; set => _serialPort.DtrEnable = value; } - public bool CtsHolding => _serialPort.CtsHolding; - public bool DiscardNull { get => _serialPort.DiscardNull; set => _serialPort.DiscardNull = value; } - public int DataBits { get => _serialPort.DataBits; set => _serialPort.DataBits = value; } - public bool IsOpen => _serialPort.IsOpen; - public bool DsrHolding => _serialPort.DsrHolding; - public string NewLine { get => _serialPort.NewLine; set => _serialPort.NewLine = value; } - public int ReadBufferSize { get => _serialPort.ReadBufferSize; set => _serialPort.ReadBufferSize = value; } - public byte ParityReplace { get => _serialPort.ParityReplace; set => _serialPort.ParityReplace = value; } - public string PortName { get => _serialPort.PortName; set => _serialPort.PortName = value; } - public bool CDHolding => _serialPort.CDHolding; - public int ReadTimeout { get => _serialPort.ReadTimeout; set => _serialPort.ReadTimeout = value; } - public int ReceivedBytesThreshold { get => _serialPort.ReceivedBytesThreshold; set => _serialPort.ReceivedBytesThreshold = value; } - public bool RtsEnable { get => _serialPort.RtsEnable; set => _serialPort.RtsEnable = value; } - public StopBits StopBits { get => _serialPort.StopBits; set => _serialPort.StopBits = value; } - public int WriteBufferSize { get => _serialPort.WriteBufferSize; set => _serialPort.WriteBufferSize = value; } - public int WriteTimeout { get => _serialPort.WriteTimeout; set => _serialPort.WriteTimeout = value; } - public Parity Parity { get => _serialPort.Parity; set => _serialPort.Parity = value; } - public int BytesToWrite => _serialPort.BytesToWrite; - public int BaudRate { get => _serialPort.BaudRate; set => _serialPort.BaudRate = value; } - public bool BreakState { get => _serialPort.BreakState; set => _serialPort.BreakState = value; } - public Stream BaseStream => _serialPort.BaseStream; - public int BytesToRead => _serialPort.BytesToRead; - public event SerialDataReceivedEventHandler DataReceived; - public event SerialPinChangedEventHandler PinChanged; - public event SerialErrorReceivedEventHandler ErrorReceived; - - public void Close() - { - _serialPort.Close(); - } - - public void DiscardInBuffer() - { - _serialPort.DiscardInBuffer(); - } - - public void DiscardOutBuffer() - { - _serialPort.DiscardOutBuffer(); - } - - public void Dispose() - { - _serialPort.Dispose(); - _serialPort.ErrorReceived -= ErrorReceivedHandler; - _serialPort.DataReceived -= DataReceivedHandler; - _serialPort.PinChanged -= PinChangedHandler; - } - - public void Open() - { - _serialPort.Open(); - } - - public int Read(byte[] buffer, int offset, int count) - { - return _serialPort.Read(buffer, offset, count); - } - - public int Read(char[] buffer, int offset, int count) - { - return _serialPort.Read(buffer, offset, count); - } - - public int ReadByte() - { - return _serialPort.ReadByte(); - } - - public int ReadChar() - { - return _serialPort.ReadChar(); - } - - public string ReadExisting() - { - return _serialPort.ReadExisting(); - } - - public string ReadLine() - { - return _serialPort.ReadLine(); - } - - public string ReadTo(string value) - { - return _serialPort.ReadTo(value); - } - - public void Write(byte[] buffer, int offset, int count) - { - _serialPort.Write(buffer, offset, count); - } - - public void Write(string text) - { - _serialPort.Write(text); - } - - public void Write(char[] buffer, int offset, int count) - { - _serialPort.Write(buffer, offset, count); - } - - public void WriteLine(string text) - { - _serialPort.WriteLine(text); - } - - private void PinChangedHandler(object sender, SerialPinChangedEventArgs e) - { - SerialPinChangedEventHandler handler = PinChanged; - handler?.Invoke(this, e); - } - - private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) - { - SerialDataReceivedEventHandler handler = DataReceived; - handler?.Invoke(this, e); - } - - private void ErrorReceivedHandler(object sender, SerialErrorReceivedEventArgs e) - { - SerialErrorReceivedEventHandler handler = ErrorReceived; - handler?.Invoke(this, e); - } - } -} diff --git a/RfmOTA/RfmOta/Ports/SerialPortFactory.cs b/RfmOTA/RfmOta/Ports/SerialPortFactory.cs deleted file mode 100644 index c7b3abf..0000000 --- a/RfmOTA/RfmOta/Ports/SerialPortFactory.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System.Collections.Generic; - -namespace RfmOta.Ports -{ - internal class SerialPortFactory : ISerialPortFactory - { - public ISerialPort CreateSerialPortInstance(string serialPort) - { - return new SerialPort(serialPort); - } - - public IList GetSerialPorts() - { - return System.IO.Ports.SerialPort.GetPortNames(); - } - } -} diff --git a/RfmOTA/RfmOta/Rfm/Dio.cs b/RfmOTA/RfmOta/Rfm/Dio.cs deleted file mode 100644 index ce5c446..0000000 --- a/RfmOTA/RfmOta/Rfm/Dio.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -namespace RfmOta.Rfm -{ - public enum Dio - { - Dio0, - Dio1, - Dio2, - Dio3 - } -} \ No newline at end of file diff --git a/RfmOTA/RfmOta/Rfm/DioMapping.cs b/RfmOTA/RfmOta/Rfm/DioMapping.cs deleted file mode 100644 index 4c16f51..0000000 --- a/RfmOTA/RfmOta/Rfm/DioMapping.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -namespace RfmOta.Rfm -{ - public enum DioMapping - { - DioMapping0, - DioMapping1, - DioMapping2, - DioMapping3 - } -} \ No newline at end of file diff --git a/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbCommandExecutionException.cs b/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbCommandExecutionException.cs deleted file mode 100644 index 355002e..0000000 --- a/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbCommandExecutionException.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System; - -namespace RfmOta.Rfm.Exceptions -{ - - [Serializable] - public class RfmUsbCommandExecutionException : Exception - { - public RfmUsbCommandExecutionException() { } - public RfmUsbCommandExecutionException(string message) : base(message) { } - public RfmUsbCommandExecutionException(string message, Exception inner) : base(message, inner) { } - protected RfmUsbCommandExecutionException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } -} diff --git a/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbSerialPortException.cs b/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbSerialPortException.cs deleted file mode 100644 index 9d5fc31..0000000 --- a/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbSerialPortException.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System; - -namespace RfmOta.Rfm.Exceptions -{ - - [Serializable] - public class RfmUsbSerialPortNotFoundException : Exception - { - public RfmUsbSerialPortNotFoundException() { } - public RfmUsbSerialPortNotFoundException(string message) : base(message) { } - public RfmUsbSerialPortNotFoundException(string message, Exception inner) : base(message, inner) { } - protected RfmUsbSerialPortNotFoundException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } -} diff --git a/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbTransmitException.cs b/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbTransmitException.cs deleted file mode 100644 index a4e5536..0000000 --- a/RfmOTA/RfmOta/Rfm/Exceptions/RfmUsbTransmitException.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -namespace RfmOta.Rfm.Exceptions -{ - - [System.Serializable] - public class RfmUsbTransmitException : System.Exception - { - public RfmUsbTransmitException() { } - public RfmUsbTransmitException(string message) : base(message) { } - public RfmUsbTransmitException(string message, System.Exception inner) : base(message, inner) { } - protected RfmUsbTransmitException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } -} diff --git a/RfmOTA/RfmOta/Rfm/IRfmUsb.cs b/RfmOTA/RfmOta/Rfm/IRfmUsb.cs deleted file mode 100644 index ee74f81..0000000 --- a/RfmOTA/RfmOta/Rfm/IRfmUsb.cs +++ /dev/null @@ -1,62 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using System; -using System.Collections.Generic; - -namespace RfmOta.Rfm -{ - internal interface IRfmUsb : IDisposable - { - string Version { get; } - int OutputPower { get; set; } - byte PayloadLenght { get; set; } - bool VariableLenght { get; set; } - byte FifoThreshold { get; set; } - byte DioInterruptMask { get; set; } - int RetryCount { get; set; } - int Timeout { get; set; } - bool TransmissionStartCondition { get; set; } - byte RadioConfig { get; set; } - IEnumerable Sync { get; set; } - public void Reset(); - public void Close(); - public void Open(string serialPort, int baudRate); - void Send(IList data); - /// - /// Transmit a packet of data bytes and wait for a response - /// - /// The data to transmit - /// The timeout in milliseconds to wait for a response - /// The received packet bytes - IList TransmitReceive(IList data, int timeout); - /// - /// Transmit a packet of data bytes - /// - /// The data to transmit - /// The timeout in milliseconds to wait for a response - void Transmit(IList data); - void SetDioMapping(Dio dio, DioMapping mapping); - } -} diff --git a/RfmOTA/RfmOta/Rfm/RfmUsb.cs b/RfmOTA/RfmOta/Rfm/RfmUsb.cs deleted file mode 100644 index bb75ebd..0000000 --- a/RfmOTA/RfmOta/Rfm/RfmUsb.cs +++ /dev/null @@ -1,268 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using Microsoft.Extensions.Logging; -using RfmOta.Ports; -using RfmOta.Rfm.Exceptions; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace RfmOta.Rfm -{ - internal class RfmUsb : IRfmUsb - { - private const string ResponseOk = "OK"; - - private readonly ISerialPortFactory _serialPortFactory; - private readonly ILogger _logger; - - private ISerialPort _serialPort; - - public RfmUsb(ILogger logger, ISerialPortFactory serialPortFactory) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _serialPortFactory = serialPortFactory ?? throw new ArgumentNullException(nameof(serialPortFactory)); - } - /// - public string Version => SendCommand("g-fv"); - /// - public byte PayloadLenght - { - get => SendCommand("g-pl").ToBytes().First(); - set => SendCommandWithCheck($"s-pl 0x{value:X}", ResponseOk); - } - /// - public bool VariableLenght - { - get => SendCommand("g-pf").ToBytes().First() == 1; - set => SendCommandWithCheck($"s-pf 0x0{(value ? 0x01 : 0x00):X}", ResponseOk); - } - /// - public byte FifoThreshold - { - get => SendCommand("g-ft").ToBytes().First(); - set => SendCommandWithCheck($"s-ft 0x{value:X}", ResponseOk); - } - /// - public byte DioInterruptMask - { - get => SendCommand("g-di").ToBytes().First(); - set => SendCommandWithCheck($"s-di 0x{value:X}", ResponseOk); - } - /// - public int RetryCount { get; set; } - /// - public int Timeout - { - get => _serialPort.ReadTimeout; - set - { - _serialPort.ReadTimeout = value; - _serialPort.WriteTimeout = value; - } - } - /// - public bool TransmissionStartCondition - { - get => SendCommand("g-tsc").ToBytes().First() == 1; - set => SendCommandWithCheck($"s-tsc 0x0{(value ? 0x01 : 0x00):X}", ResponseOk); - } - /// - public byte RadioConfig - { - get => SendCommand($"g-rc").ToBytes().First(); - set => SendCommandWithCheck($"s-rc {value}", ResponseOk); - } - /// - public IEnumerable Sync - { - get => SendCommand($"g-sync").ToBytes(); - set => SendCommandWithCheck($"s-sync {BitConverter.ToString(value.ToArray()).Replace("-", string.Empty)}", ResponseOk); - } - /// - public int OutputPower - { - get => int.Parse(SendCommand($"g-op")); - set => SendCommandWithCheck($"s-op {value}", ResponseOk); - } - /// - public void Open(string serialPort, int baudRate) - { - try - { - if (_serialPort == null) - { - _serialPort = _serialPortFactory.CreateSerialPortInstance(serialPort); - - _serialPort.BaudRate = baudRate; - _serialPort.NewLine = "\r\n"; - _serialPort.DtrEnable = true; - _serialPort.RtsEnable = true; - _serialPort.ReadTimeout = 500; - _serialPort.WriteTimeout = 500; - _serialPort.Open(); - } - } - catch (FileNotFoundException ex) - { - _logger.LogDebug(ex, "Exception occurred opening serial port"); - - throw new RfmUsbSerialPortNotFoundException( - $"Unable to open serial port [{serialPort}] Reason: [{ex.Message}]. " + - $"Available Serial Ports: [{string.Join(", ", _serialPortFactory.GetSerialPorts())}]"); - } - } - /// - public void Close() - { - if (_serialPort != null && _serialPort.IsOpen) - { - _serialPort.Close(); - } - } - /// - public void Reset() - { - SendCommandWithCheck($"e-r", ResponseOk); - } - /// - public void Send(IList data) - { - _serialPort.Write($"{BitConverter.ToString(data.ToArray()).Replace("-", string.Empty)}"); - } - /// - public IList TransmitReceive(IList data, int timeout) - { - int retries = RetryCount; - - do - { - var response = SendCommand($"e-txrx {BitConverter.ToString(data.ToArray()).Replace("-", string.Empty)} {timeout}"); - - if (response.Contains("TX") || response.Contains("RX")) - { - if (retries == 0) - { - throw new RfmUsbTransmitException($"Packet transmission failed: [{response}]"); - } - - retries--; - } - else - { - return response.ToBytes(); - } - - } while (true); - } - /// - public void Transmit(IList data) - { - int retries = RetryCount; - - do - { - var response = SendCommand($"e-tx {BitConverter.ToString(data.ToArray()).Replace("-", string.Empty)}"); - - if (response.Contains("TX") || response.Contains("RX")) - { - if (retries == 0) - { - throw new RfmUsbTransmitException($"Packet transmission failed: [{response}]"); - } - - retries--; - } - else - { - break; - } - - } while (true); - } - /// - public void SetDioMapping(Dio dio, DioMapping mapping) - { - SendCommandWithCheck($"s-dio {(int)dio} {(int)mapping}", "[0x0001]-Map 01"); - } - private string SendCommand(string command) - { - _serialPort.Write($"{command}\n"); - - var response = _serialPort.ReadLine(); - - _logger.LogDebug($"Command: [{command}] Result: [{response}]"); - - return response; - } - private void SendCommandWithCheck(string command, string response) - { - var result = SendCommand(command); - - if (!result.StartsWith(response)) - { - throw new RfmUsbCommandExecutionException($"Command: [{command}] Execution Failed Reason: [{result}]"); - } - } - - #region IDisposible - private bool disposedValue; - - protected virtual void Dispose(bool disposing) - { - if (!disposedValue) - { - if (disposing) - { - if (_serialPort != null) - { - _serialPort.Close(); - } - } - - // TODO: free unmanaged resources (unmanaged objects) and override finalizer - // TODO: set large fields to null - disposedValue = true; - } - } - - // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources - // ~RfmUsb() - // { - // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - // Dispose(disposing: false); - // } - - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - System.GC.SuppressFinalize(this); - } - - #endregion - } -} diff --git a/RfmOTA/RfmOta/Rfm/RfmUsbServiceExtensions.cs b/RfmOTA/RfmOta/Rfm/RfmUsbServiceExtensions.cs deleted file mode 100644 index cbe6b63..0000000 --- a/RfmOTA/RfmOta/Rfm/RfmUsbServiceExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2020 Derek Goslin http://corememorydump.blogspot.ie/ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -using Microsoft.Extensions.DependencyInjection; - -namespace RfmOta.Rfm -{ - internal static class RfmUsbServiceExtensions - { - public static IServiceCollection AddRfmUsb(this IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(); - - return serviceCollection; - } - } -} diff --git a/RfmOtaClient/RfmOtaClient.sln b/RfmOtaClient/RfmOtaClient.sln new file mode 100644 index 0000000..c56c691 --- /dev/null +++ b/RfmOtaClient/RfmOtaClient.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RfmOtaClient", "RfmOtaClient\RfmOtaClient.csproj", "{2A7E16D7-2421-425D-8F88-4DB74FA1A88F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RfmOta", "..\..\RfmOta\RfmOta\RfmOta\RfmOta.csproj", "{F46D8B2E-8C74-40B8-B5A2-1138AE83ECFE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2A7E16D7-2421-425D-8F88-4DB74FA1A88F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A7E16D7-2421-425D-8F88-4DB74FA1A88F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A7E16D7-2421-425D-8F88-4DB74FA1A88F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A7E16D7-2421-425D-8F88-4DB74FA1A88F}.Release|Any CPU.Build.0 = Release|Any CPU + {F46D8B2E-8C74-40B8-B5A2-1138AE83ECFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F46D8B2E-8C74-40B8-B5A2-1138AE83ECFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F46D8B2E-8C74-40B8-B5A2-1138AE83ECFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F46D8B2E-8C74-40B8-B5A2-1138AE83ECFE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CC936B5E-2B90-4A13-A929-51374E966C8C} + EndGlobalSection +EndGlobal diff --git a/RfmOTA/RfmOta/HexUtils.cs b/RfmOtaClient/RfmOtaClient/HexUtils.cs similarity index 100% rename from RfmOTA/RfmOta/HexUtils.cs rename to RfmOtaClient/RfmOtaClient/HexUtils.cs diff --git a/RfmOTA/RfmOta/Options.cs b/RfmOtaClient/RfmOtaClient/Options.cs similarity index 83% rename from RfmOTA/RfmOta/Options.cs rename to RfmOtaClient/RfmOtaClient/Options.cs index 33d3b59..5671873 100644 --- a/RfmOTA/RfmOta/Options.cs +++ b/RfmOtaClient/RfmOtaClient/Options.cs @@ -23,7 +23,6 @@ */ using CommandLine; -using System; namespace RfmOta { @@ -35,13 +34,10 @@ class Options [Option('s', "serial", Required = true, HelpText = "The serial port that an RfmUsb device is connected")] public string SerialPort { get; set; } - [Option('r', "retry", Required = false, Default = 2, HelpText = "The number of transmission retries")] - public int RetryCount { get; set; } - - [Option('t', "timeout", Required = false, Default = 5000, HelpText = "The response timeout in milli seconds")] - public int Timeout { get; set; } - [Option('b', "baudrate", Required = false, Default = 115200, HelpText = "The baud rate for the serial port")] public int BaudRate { get; set; } + + [Option('p', "outputpower", Required = false, Default = 2, HelpText = "The output power of the RfmUsb in db")] + public int OutputPower { get; set; } } } diff --git a/RfmOTA/RfmOta/Program.cs b/RfmOtaClient/RfmOtaClient/Program.cs similarity index 94% rename from RfmOTA/RfmOta/Program.cs rename to RfmOtaClient/RfmOtaClient/Program.cs index 3b9053d..ee46ad6 100644 --- a/RfmOTA/RfmOta/Program.cs +++ b/RfmOtaClient/RfmOtaClient/Program.cs @@ -26,10 +26,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using RfmOta.Ota; -using RfmOta.Ports; -using RfmOta.Rfm; -using RfmOta.Rfm.Exceptions; +using RfmUsb; +using RfmUsb.Exceptions; using Serilog; using System; using System.Collections.Generic; @@ -67,7 +65,7 @@ static void RunOptions(Options options) using var stream = File.OpenRead(options.HexFile); using var otaservice = _serviceProvider.GetService(); - if (otaservice.OtaUpdate(options, stream, out uint crc)) + if (otaservice.OtaUpdate(options.SerialPort, options.BaudRate, (byte) options.OutputPower, stream, out uint crc)) { logger.LogInformation($"OTA flash update completed. Crc: [0x{crc:X}]"); } @@ -104,8 +102,6 @@ private static ServiceProvider BuildServiceProvider() .AddLogging(builder => builder.AddSerilog()) .AddSingleton(_configuration) .AddLogging() - .AddRfmUsb() - .AddPorts() .AddOta(); return serviceCollection.BuildServiceProvider(); diff --git a/RfmOTA/RfmOta/Properties/launchSettings.json b/RfmOtaClient/RfmOtaClient/Properties/launchSettings.json similarity index 100% rename from RfmOTA/RfmOta/Properties/launchSettings.json rename to RfmOtaClient/RfmOtaClient/Properties/launchSettings.json diff --git a/RfmOTA/RfmOta/RfmOta.csproj b/RfmOtaClient/RfmOtaClient/RfmOtaClient.csproj similarity index 93% rename from RfmOTA/RfmOta/RfmOta.csproj rename to RfmOtaClient/RfmOtaClient/RfmOtaClient.csproj index 0277511..622ffc5 100644 --- a/RfmOTA/RfmOta/RfmOta.csproj +++ b/RfmOtaClient/RfmOtaClient/RfmOtaClient.csproj @@ -38,4 +38,8 @@ + + + + diff --git a/RfmOTA/RfmOta/appsettings.json b/RfmOtaClient/RfmOtaClient/appsettings.json similarity index 100% rename from RfmOTA/RfmOta/appsettings.json rename to RfmOtaClient/RfmOtaClient/appsettings.json