From fe5430ac1f296169ffddd057bf6b977bad008b6d Mon Sep 17 00:00:00 2001 From: Generoso Martello Date: Tue, 18 Dec 2018 16:44:48 +0100 Subject: [PATCH] added 'Control.RfSend' command for sending X10 RF command with CM15 and CM19 --- MIG.HomeAutomation.Tests/Tests.cs | 2 +- MIG.HomeAutomation/MIG.HomeAutomation.csproj | 4 +-- MIG.HomeAutomation/X10.cs | 26 ++++++++++++++++++-- MIG.HomeAutomation/packages.config | 4 +-- Test.WebService/Program.cs | 3 ++- Test.WebService/systemconfig.xml | 1 + 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/MIG.HomeAutomation.Tests/Tests.cs b/MIG.HomeAutomation.Tests/Tests.cs index e94737b..8f6969a 100644 --- a/MIG.HomeAutomation.Tests/Tests.cs +++ b/MIG.HomeAutomation.Tests/Tests.cs @@ -12,4 +12,4 @@ public void Test1() Assert.True(true); } } -} \ No newline at end of file +} diff --git a/MIG.HomeAutomation/MIG.HomeAutomation.csproj b/MIG.HomeAutomation/MIG.HomeAutomation.csproj index 7be138e..9719309 100644 --- a/MIG.HomeAutomation/MIG.HomeAutomation.csproj +++ b/MIG.HomeAutomation/MIG.HomeAutomation.csproj @@ -52,7 +52,7 @@ True - ..\packages\MIG.1.0.5\lib\MIG.dll + ..\packages\MIG.1.0.6\lib\MIG.dll True @@ -89,7 +89,7 @@ True - ..\packages\XTenLib.1.0.11\lib\XTenLib.dll + ..\packages\XTenLib.1.0.12\lib\XTenLib.dll True diff --git a/MIG.HomeAutomation/X10.cs b/MIG.HomeAutomation/X10.cs index 2fbebd7..c17e47c 100644 --- a/MIG.HomeAutomation/X10.cs +++ b/MIG.HomeAutomation/X10.cs @@ -57,7 +57,8 @@ public enum Commands Control_Level_Adjust, Control_Toggle, Control_AllLightsOn, - Control_AllUnitsOff + Control_AllUnitsOff, + Control_RfSend } #endregion @@ -305,6 +306,10 @@ public object InterfaceControl(MigInterfaceCommand request) cm19Lib.AllUnitsOff(houseCode); // TODO: update modules status break; + case Commands.Control_RfSend: + byte[] data = StringToByteArray(option.Replace("-", "")); + x10Lib.SendMessage(data); + break; } } else @@ -330,7 +335,7 @@ public object InterfaceControl(MigInterfaceCommand request) x10Lib.Dim(houseCode, unitCode, int.Parse(option)); break; case Commands.Control_Level_Adjust: - int adjvalue = int.Parse(option); + //int adjvalue = int.Parse(option); //x10Lib.Modules[nodeId].Level = ((double)adjvalue/100D); OnInterfacePropertyChanged(this.GetDomain(), nodeId, "X10 Module", ModuleEvents.Status_Level, x10Lib.Modules[nodeId].Level); throw(new NotImplementedException("X10 CONTROL_LEVEL_ADJUST Not Implemented")); @@ -363,6 +368,10 @@ public object InterfaceControl(MigInterfaceCommand request) case Commands.Control_AllUnitsOff: x10Lib.AllUnitsOff(houseCode); break; + case Commands.Control_RfSend: + byte[] data = StringToByteArray("EB"+option.Replace("-", "")); + x10Lib.SendMessage(data); + break; } } @@ -463,6 +472,17 @@ private void ParseModuleAddress(String eventAddress, String eventName, out Modul moduleType = ModuleTypes.Sensor; } } + + private byte[] StringToByteArray(String hexString) + { + int size = hexString.Length; + byte[] bytes = new byte[size / 2]; + for (int i = 0; i < size; i += 2) + { + bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16); + } + return bytes; + } private InterfaceModule GetModuleByAddress(string address, ModuleTypes? defaultType = null) { @@ -557,6 +577,7 @@ private void Cm19LibOnRfDataReceived(object sender, CM19Lib.Events.RfDataReceive // TODO: Cm19LibOnRfCameraReceived not implemented (perhaps not needed) private void Cm19LibOnRfCameraReceived(object sender, RfCommandReceivedEventArgs args) { + /* var address = lastAddressedModule = "CAMERA-" + args.HouseCode; switch (args.Command) { @@ -569,6 +590,7 @@ private void Cm19LibOnRfCameraReceived(object sender, RfCommandReceivedEventArgs case RfFunction.CameraDown: break; } + */ // TODO: not implemented (perhaps not needed) } diff --git a/MIG.HomeAutomation/packages.config b/MIG.HomeAutomation/packages.config index 8c03086..58529bc 100644 --- a/MIG.HomeAutomation/packages.config +++ b/MIG.HomeAutomation/packages.config @@ -4,13 +4,13 @@ - + - + \ No newline at end of file diff --git a/Test.WebService/Program.cs b/Test.WebService/Program.cs index cf999d3..f448758 100644 --- a/Test.WebService/Program.cs +++ b/Test.WebService/Program.cs @@ -56,9 +56,10 @@ public static void Main(string[] args) /* var x10 = migService.AddInterface("HomeAutomation.X10", "MIG.HomeAutomation.dll"); + zwave.SetOption("Port", "CM19"); // "USB" for CM15 or the serial port path for CM11 migService.EnableInterface("HomeAutomation.X10"); */ - + while (true) { Thread.Sleep(10000); diff --git a/Test.WebService/systemconfig.xml b/Test.WebService/systemconfig.xml index 999b3cb..8d2cde7 100644 --- a/Test.WebService/systemconfig.xml +++ b/Test.WebService/systemconfig.xml @@ -20,6 +20,7 @@ +