From 1282f2b59e631c7802aa28686b894e58b4afdd67 Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Tue, 19 Feb 2019 01:27:45 +0300 Subject: [PATCH 1/8] bind start/stop commands added to the console app --- ThinkingHome.NooLite.Console/Program.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ThinkingHome.NooLite.Console/Program.cs b/ThinkingHome.NooLite.Console/Program.cs index a349e07..5ac86f2 100644 --- a/ThinkingHome.NooLite.Console/Program.cs +++ b/ThinkingHome.NooLite.Console/Program.cs @@ -61,6 +61,8 @@ static void Main(string[] args) app.Command("ports", PortsCommand); app.Command("bind", BindCommand); + app.Command("bindstart", BindStartCommand); + app.Command("bindstop", BindStopCommand); app.Command("unbind", UnbindCommand); app.Command("on", OnCommand); app.Command("off", OffCommand); @@ -109,6 +111,22 @@ private static void BindCommand(CommandLineApplication cmd) cmd.OnExecute(() => Invoke(args, (a, c) => a.Bind(c), (a, c) => a.BindF(c))); } + private static void BindStartCommand(CommandLineApplication cmd) + { + var args = AddCommonArgs(cmd); + + cmd.Description = "Enter bind mode to pair nooLite sensor."; + cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStart(c), null)); + } + + private static void BindStopCommand(CommandLineApplication cmd) + { + var args = AddCommonArgs(cmd); + + cmd.Description = "Disable bind mode to pair nooLite sensor."; + cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStop(), null)); + } + private static void UnbindCommand(CommandLineApplication cmd) { var args = AddCommonArgs(cmd); From 8d080c68c473c6df5400866657b5df6927a5a9e8 Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Tue, 19 Feb 2019 10:07:30 +0300 Subject: [PATCH 2/8] bindstart/bindstop command added to the console application --- ThinkingHome.NooLite.Console/Program.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ThinkingHome.NooLite.Console/Program.cs b/ThinkingHome.NooLite.Console/Program.cs index a349e07..da8285e 100644 --- a/ThinkingHome.NooLite.Console/Program.cs +++ b/ThinkingHome.NooLite.Console/Program.cs @@ -62,6 +62,8 @@ static void Main(string[] args) app.Command("bind", BindCommand); app.Command("unbind", UnbindCommand); + app.Command("bindstart", BindStartCommand); + app.Command("bindstop", BindStopCommand); app.Command("on", OnCommand); app.Command("off", OffCommand); app.Command("switch", SwitchCommand); @@ -117,6 +119,22 @@ private static void UnbindCommand(CommandLineApplication cmd) cmd.OnExecute(() => Invoke(args, (a, c) => a.Unbind(c), (a, c) => a.UnbindF(c))); } + private static void BindStartCommand(CommandLineApplication cmd) + { + var args = AddCommonArgs(cmd); + + cmd.Description = "Start binding the specified adapter channel to the nooLite sensor."; + cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStart(c), (a, c) => a.BindStart(c))); + } + + private static void BindStopCommand(CommandLineApplication cmd) + { + var args = AddCommonArgs(cmd); + + cmd.Description = "Stop binding the specified adapter channel from the nooLite sensor."; + cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStop(), (a, c) => a.BindStop())); + } + private static void OnCommand(CommandLineApplication cmd) { var args = AddCommonArgs(cmd); From a016f0d6878e773285a5d453f9c9da56df83576d Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Tue, 23 Jun 2020 08:48:39 +0300 Subject: [PATCH 3/8] Library and .net updates --- .../ThinkingHome.NooLite.Console.csproj | 8 ++++---- .../ThinkingHome.NooLite.DebugConsole.csproj | 2 +- .../ThinkingHome.NooLite.Tests.csproj | 13 ++++++++----- ThinkingHome.NooLite/ThinkingHome.NooLite.csproj | 8 ++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ThinkingHome.NooLite.Console/ThinkingHome.NooLite.Console.csproj b/ThinkingHome.NooLite.Console/ThinkingHome.NooLite.Console.csproj index 4094e5b..c4448a9 100644 --- a/ThinkingHome.NooLite.Console/ThinkingHome.NooLite.Console.csproj +++ b/ThinkingHome.NooLite.Console/ThinkingHome.NooLite.Console.csproj @@ -1,5 +1,5 @@  - + Command line interface for the wireless control of appliances using the nooLite system (including nooLite-F mode). Adapter MTRF-64-USB is supported. @@ -11,12 +11,12 @@ http://www.noo.com.by Exe true noolite - netcoreapp2.1 + netcoreapp3.1 - + - + \ No newline at end of file diff --git a/ThinkingHome.NooLite.DebugConsole/ThinkingHome.NooLite.DebugConsole.csproj b/ThinkingHome.NooLite.DebugConsole/ThinkingHome.NooLite.DebugConsole.csproj index 642abd4..5bb9972 100644 --- a/ThinkingHome.NooLite.DebugConsole/ThinkingHome.NooLite.DebugConsole.csproj +++ b/ThinkingHome.NooLite.DebugConsole/ThinkingHome.NooLite.DebugConsole.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp2.0 + netcoreapp3.1 diff --git a/ThinkingHome.NooLite.Tests/ThinkingHome.NooLite.Tests.csproj b/ThinkingHome.NooLite.Tests/ThinkingHome.NooLite.Tests.csproj index 1d69a69..3fe1397 100644 --- a/ThinkingHome.NooLite.Tests/ThinkingHome.NooLite.Tests.csproj +++ b/ThinkingHome.NooLite.Tests/ThinkingHome.NooLite.Tests.csproj @@ -1,13 +1,16 @@  - netcoreapp2.0 + netcoreapp3.1 false - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj b/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj index 2d1e7ef..ca7fac2 100644 --- a/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj +++ b/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj @@ -1,5 +1,5 @@  - + .NET Core API for the wireless control of appliances using the nooLite system (including nooLite-F mode). Adapter MTRF-64-USB is supported. @@ -7,11 +7,11 @@ http://www.noo.com.by - netstandard2.0 + netstandard2.1 true - - + + \ No newline at end of file From b904823b7b2c6d5de7b754445d6dbe53f1824cbe Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Tue, 23 Jun 2020 09:08:24 +0300 Subject: [PATCH 4/8] merge fix --- ThinkingHome.NooLite.Console/Program.cs | 26 ++++--------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/ThinkingHome.NooLite.Console/Program.cs b/ThinkingHome.NooLite.Console/Program.cs index 9e2f859..f04fe19 100644 --- a/ThinkingHome.NooLite.Console/Program.cs +++ b/ThinkingHome.NooLite.Console/Program.cs @@ -64,8 +64,6 @@ static void Main(string[] args) app.Command("bindstart", BindStartCommand); app.Command("bindstop", BindStopCommand); app.Command("unbind", UnbindCommand); - app.Command("bindstart", BindStartCommand); - app.Command("bindstop", BindStopCommand); app.Command("on", OnCommand); app.Command("off", OffCommand); app.Command("switch", SwitchCommand); @@ -117,16 +115,16 @@ private static void BindStartCommand(CommandLineApplication cmd) { var args = AddCommonArgs(cmd); - cmd.Description = "Enter bind mode to pair nooLite sensor."; - cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStart(c), null)); + cmd.Description = "Start binding the specified adapter channel to the nooLite sensor."; + cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStart(c), (a, c) => a.BindStart(c))); } private static void BindStopCommand(CommandLineApplication cmd) { var args = AddCommonArgs(cmd); - cmd.Description = "Disable bind mode to pair nooLite sensor."; - cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStop(), null)); + cmd.Description = "Stop binding the specified adapter channel from the nooLite sensor."; + cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStop(), (a, c) => a.BindStop())); } private static void UnbindCommand(CommandLineApplication cmd) @@ -137,22 +135,6 @@ private static void UnbindCommand(CommandLineApplication cmd) cmd.OnExecute(() => Invoke(args, (a, c) => a.Unbind(c), (a, c) => a.UnbindF(c))); } - private static void BindStartCommand(CommandLineApplication cmd) - { - var args = AddCommonArgs(cmd); - - cmd.Description = "Start binding the specified adapter channel to the nooLite sensor."; - cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStart(c), (a, c) => a.BindStart(c))); - } - - private static void BindStopCommand(CommandLineApplication cmd) - { - var args = AddCommonArgs(cmd); - - cmd.Description = "Stop binding the specified adapter channel from the nooLite sensor."; - cmd.OnExecute(() => Invoke(args, (a, c) => a.BindStop(), (a, c) => a.BindStop())); - } - private static void OnCommand(CommandLineApplication cmd) { var args = AddCommonArgs(cmd); From a1dc3acb4d0c9443ce1f8d53406efb720a0b1f22 Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Wed, 5 Aug 2020 16:44:15 +0300 Subject: [PATCH 5/8] readstate command --- ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs b/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs index ff7cf3a..eb47bc8 100644 --- a/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs +++ b/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs @@ -288,6 +288,12 @@ public static void ExitServiceMode(this MTRFXXAdapter adapter) adapter.SendCommand(MTRFXXMode.Service, MTRFXXAction.SendCommand, 0, MTRFXXCommand.None); } + + public static void ReadState(this MTRFXXAdapter adapter, byte channel) + { + adapter.SendCommand(MTRFXXMode.TXF, MTRFXXAction.SendCommand, channel, MTRFXXCommand.ReadState); + } + #endregion } } \ No newline at end of file From 9a1f8a146657aabb2d0b8b252e02d53b20b32137 Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Wed, 5 Aug 2020 18:59:30 +0300 Subject: [PATCH 6/8] update --- ThinkingHome.NooLite.Tests/F/CommandTest.cs | 12 +++++++++ .../MTRFXXAdapterExtensions.cs | 25 +++++++++++++++---- .../ThinkingHome.NooLite.csproj | 12 ++++++++- 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 ThinkingHome.NooLite.Tests/F/CommandTest.cs diff --git a/ThinkingHome.NooLite.Tests/F/CommandTest.cs b/ThinkingHome.NooLite.Tests/F/CommandTest.cs new file mode 100644 index 0000000..fdb2299 --- /dev/null +++ b/ThinkingHome.NooLite.Tests/F/CommandTest.cs @@ -0,0 +1,12 @@ +using Xunit; + +namespace ThinkingHome.NooLite.Tests.MicroclimateData +{ + using H = TestHelpers; + + public class CommandTest + { + + + } +} \ No newline at end of file diff --git a/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs b/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs index eb47bc8..4ebfea3 100644 --- a/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs +++ b/ThinkingHome.NooLite/MTRFXXAdapterExtensions.cs @@ -34,6 +34,21 @@ private static void SendData(MTRFXXAdapter adapter, MTRFXXCommand command, bool } + + #endregion + + #region read state + + public static void ReadState(this MTRFXXAdapter adapter, byte channel) + { + throw new NotSupportedException("Not supported in basic mode."); + } + + public static void ReadStateF(this MTRFXXAdapter adapter, byte channel, UInt32? deviceId = null) + { + SendReadState(adapter, channel); + } + #endregion #region brightness @@ -262,6 +277,11 @@ public static void UnbindF(this MTRFXXAdapter adapter, byte channel) #region RX mode + private static void SendReadState(this MTRFXXAdapter adapter, byte channel) + { + adapter.SendCommand(MTRFXXMode.TXF, MTRFXXAction.SendCommand, channel, MTRFXXCommand.ReadState); + } + public static void BindStart(this MTRFXXAdapter adapter, byte channel) { adapter.SendCommand(MTRFXXMode.RX, MTRFXXAction.StartBinding, channel, MTRFXXCommand.None); @@ -289,11 +309,6 @@ public static void ExitServiceMode(this MTRFXXAdapter adapter) } - public static void ReadState(this MTRFXXAdapter adapter, byte channel) - { - adapter.SendCommand(MTRFXXMode.TXF, MTRFXXAction.SendCommand, channel, MTRFXXCommand.ReadState); - } - #endregion } } \ No newline at end of file diff --git a/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj b/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj index ca7fac2..e0e1dff 100644 --- a/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj +++ b/ThinkingHome.NooLite/ThinkingHome.NooLite.csproj @@ -4,11 +4,21 @@ .NET Core API for the wireless control of appliances using the nooLite system (including nooLite-F mode). Adapter MTRF-64-USB is supported. http://www.noo.com.by - + netstandard2.1 true + true + 4.0.0-rc-5-1530995509343 + noolite + Dmitry Andriyanov <dima117a@gmail.com>, Vadim Kosin <vkosin@outlook.com> + Dmitry Andriyanov <dima117a@gmail.com>, Vadim Kosin <vkosin@outlook.com> + Vadim Kosin 2020 + https://github.com/wadimk/noolite + https://github.com/wadimk/noolite.git + noolite + core;noolite From d40c5709e1893fff25e9e959dee567c674d1b95a Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Thu, 6 Aug 2020 09:22:24 +0300 Subject: [PATCH 7/8] update --- ThinkingHome.NooLite/ReceivedData.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ThinkingHome.NooLite/ReceivedData.cs b/ThinkingHome.NooLite/ReceivedData.cs index 3c5f46b..bf2294b 100644 --- a/ThinkingHome.NooLite/ReceivedData.cs +++ b/ThinkingHome.NooLite/ReceivedData.cs @@ -6,6 +6,8 @@ namespace ThinkingHome.NooLite { public class ReceivedData { + //https://www.noo.by/wiki/index.php?title=API_%D1%88%D0%BB%D1%8E%D0%B7%D0%B0/%D0%B0%D0%B4%D0%B0%D0%BF%D1%82%D0%B5%D1%80%D0%B0_%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D1%8B_nooLite(-F)&mobileaction=toggle_view_mobile + #region static public const byte START_MARKER = 173; From 7471b73a233220625dc7bc6409b520bf7799165f Mon Sep 17 00:00:00 2001 From: Vadim Kosin Date: Sat, 29 Aug 2020 08:03:07 +0300 Subject: [PATCH 8/8] update --- .../SendData/ParseTests.cs | 96 +++++++++++++++++++ .../SendData/ValidationTests.cs | 54 +++++++++++ ThinkingHome.NooLite/Internal/MTRFXXAction.cs | 15 +++ 3 files changed, 165 insertions(+) create mode 100644 ThinkingHome.NooLite.Tests/SendData/ParseTests.cs create mode 100644 ThinkingHome.NooLite.Tests/SendData/ValidationTests.cs diff --git a/ThinkingHome.NooLite.Tests/SendData/ParseTests.cs b/ThinkingHome.NooLite.Tests/SendData/ParseTests.cs new file mode 100644 index 0000000..ac73e53 --- /dev/null +++ b/ThinkingHome.NooLite.Tests/SendData/ParseTests.cs @@ -0,0 +1,96 @@ +using System; +using ThinkingHome.NooLite.Internal; +using Xunit; + +namespace ThinkingHome.NooLite.Tests.SendData +{ + using H = TestHelpers; + + public class ParseTests + { + [Fact] + public void Parse_Mode_IsCorrect() + { + const byte RXF_CODE = 3; + byte[] bytes = H.GetBytes().Set(1, RXF_CODE); + + var data = new NooLite.ReceivedData(bytes); + + Assert.Equal(MTRFXXMode.RXF, data.Mode); + } + + [Fact] + public void Parse_ResultCode_IsCorrect() + { + const byte NO_RESPONSE_CODE = 1; + byte[] bytes = H.GetBytes().Set(2, NO_RESPONSE_CODE); + + var data = new NooLite.ReceivedData(bytes); + + Assert.Equal(ResultCode.NoResponse, data.Result); + } + + [Fact] + public void Parse_Remains_IsCorrect() + { + const byte REMAINS_TEST_VALUE = 133; + byte[] bytes = H.GetBytes().Set(3, REMAINS_TEST_VALUE); + + var data = new NooLite.ReceivedData(bytes); + + Assert.Equal(REMAINS_TEST_VALUE, data.Remains); + } + + [Fact] + public void Parse_Channel_IsCorrect() + { + const byte CHANNEL_TEST_VALUE = 8; + byte[] bytes = H.GetBytes().Set(4, CHANNEL_TEST_VALUE); + + var data = new NooLite.ReceivedData(bytes); + + Assert.Equal(CHANNEL_TEST_VALUE, data.Channel); + } + + [Fact] + public void Parse_Command_IsCorrect() + { + const byte COMMAND_SEND_STATE_CODE = 130; + byte[] bytes = H.GetBytes().Set(5, COMMAND_SEND_STATE_CODE); + + var data = new NooLite.ReceivedData(bytes); + + Assert.Equal(MTRFXXCommand.SendState, data.Command); + } + + [Fact] + public void Parse_Data_IsCorrect() + { + const byte FMT_TEST_VALUE = 2; + byte[] TEST_DATA = {22, 33, 44, 55}; + + byte[] bytes = H.GetBytes() + .Set(6, FMT_TEST_VALUE) + .Set(7, TEST_DATA); + + var data = new NooLite.ReceivedData(bytes); + + Assert.Equal(FMT_TEST_VALUE, data.DataFormat); + Assert.Equal(22, data.Data1); + Assert.Equal(33, data.Data2); + Assert.Equal(44, data.Data3); + Assert.Equal(55, data.Data4); + } + + [Fact] + public void Parse_DeviceId_IsCorrect() + { + byte[] bytesOfId = {0, 21, 5, 13}; + byte[] bytes = H.GetBytes().Set(11, bytesOfId); + + var data = new NooLite.ReceivedData(bytes); + + Assert.Equal((UInt32) 1377549, data.DeviceId); + } + } +} \ No newline at end of file diff --git a/ThinkingHome.NooLite.Tests/SendData/ValidationTests.cs b/ThinkingHome.NooLite.Tests/SendData/ValidationTests.cs new file mode 100644 index 0000000..33127f6 --- /dev/null +++ b/ThinkingHome.NooLite.Tests/SendData/ValidationTests.cs @@ -0,0 +1,54 @@ +using System; +using Xunit; + +namespace ThinkingHome.NooLite.Tests.ReceivedData +{ + public class ValidationTests + { + public const int VALID_DATA_SIZE = 17; + + [Fact] + public void Constructor_ForNull_ThrowsException() + { + byte[] nullReceivedData = null; + + Exception ex = Assert.ThrowsAny(() => new NooLite.ReceivedData(nullReceivedData)); + + Assert.Contains("null", ex.Message); + } + + [Fact] + public void Constructor_ForInvalidDataSize_ThrowsException() + { + byte[] invalidSizeData = new byte[3]; + + Exception ex = Assert.ThrowsAny(() => new NooLite.ReceivedData(invalidSizeData)); + + Assert.Contains("length", ex.Message); + } + + + [Fact] + public void Constructor_ForInvalidFirstByte_ThrowsException() + { + byte[] testData = new byte[VALID_DATA_SIZE]; + testData[0] = 124; + + Exception ex = Assert.ThrowsAny(() => new NooLite.ReceivedData(testData)); + + Assert.Contains("start", ex.Message); + } + + [Fact] + public void Constructor_ForInvalidLastByte_ThrowsException() + { + byte[] testData = new byte[VALID_DATA_SIZE]; + testData[0] = 173; // valid start marker + testData[VALID_DATA_SIZE - 1] = 124; + + Exception ex = Assert.ThrowsAny(() => new NooLite.ReceivedData(testData)); + + Assert.Contains("stop", ex.Message); + } + } +} \ No newline at end of file diff --git a/ThinkingHome.NooLite/Internal/MTRFXXAction.cs b/ThinkingHome.NooLite/Internal/MTRFXXAction.cs index 3246157..6101ce8 100644 --- a/ThinkingHome.NooLite/Internal/MTRFXXAction.cs +++ b/ThinkingHome.NooLite/Internal/MTRFXXAction.cs @@ -1,5 +1,20 @@ namespace ThinkingHome.NooLite.Internal { + /* + Бит 5…0 – Команда адаптеру(0…63) + Значение=0 – Передать команду + Значение=1 – Передать широковещательную команду + (одновременно всем устройствам на канале CH) + Значение=2 – Считать ответ(состояние приѐмного буфера) + Значение=3 – Включить привязку + Значение=4 – Выключить привязку + Значение=5 – Очистить ячейку(канал) + Значение=6 – Очистить память(все каналы) + Значение=7 – Отвязать адрес от канала + Значение=8 – Передать команду по указанному адресу + nooLite-F + Бит 6…7 – Nrep, количество дополнительных повторовкоманды(0...3). Количество передач команд = 2+Nrep + */ public enum MTRFXXAction : byte { SendCommand = 0,