Exemple #1
0
        public object InterfaceControl(MIGInterfaceCommand request)
        {
            string response = "[{ ResponseValue : 'OK' }]";

            string nodeId  = request.NodeId;
            var    command = (Command)request.Command;
            string option  = request.GetOption(0);

            // Parse house/unit
            var houseCode = XTenLib.Utility.HouseCodeFromString(nodeId);
            var unitCode  = XTenLib.Utility.UnitCodeFromString(nodeId);

            // Modules control
            if (command == Command.PARAMETER_STATUS)
            {
                x10lib.StatusRequest(houseCode, unitCode);
            }
            else if (command == Command.CONTROL_ON)
            {
                x10lib.UnitOn(houseCode, unitCode);
            }
            else if (command == Command.CONTROL_OFF)
            {
                x10lib.UnitOff(houseCode, unitCode);
            }
            else if (command == Command.CONTROL_BRIGHT)
            {
                x10lib.Bright(houseCode, unitCode, int.Parse(option));
            }
            else if (command == Command.CONTROL_DIM)
            {
                x10lib.Dim(houseCode, unitCode, int.Parse(option));
            }
            else if (command == Command.CONTROL_LEVEL_ADJUST)
            {
                int dimvalue = int.Parse(option);
                //x10lib.Modules[nodeId].Level = ((double)dimvalue/100D);
                InterfacePropertyChangedAction(new InterfacePropertyChangedAction()
                {
                    Domain     = this.Domain,
                    SourceId   = nodeId,
                    SourceType = "X10 Module",
                    Path       = "Status.Level",
                    Value      = x10lib.Modules[nodeId].Level
                });
                throw(new NotImplementedException("X10 CONTROL_LEVEL_ADJUST Not Implemented"));
            }
            else if (command == Command.CONTROL_LEVEL)
            {
                int dimvalue = int.Parse(option) - (int)(x10lib.Modules[nodeId].Level * 100.0);
                if (dimvalue > 0)
                {
                    x10lib.Bright(houseCode, unitCode, dimvalue);
                }
                else if (dimvalue < 0)
                {
                    x10lib.Dim(houseCode, unitCode, -dimvalue);
                }
            }
            else if (command == Command.CONTROL_TOGGLE)
            {
                string huc = XTenLib.Utility.HouseUnitCodeFromEnum(houseCode, unitCode);
                if (x10lib.Modules[huc].Level == 0)
                {
                    x10lib.UnitOn(houseCode, unitCode);
                }
                else
                {
                    x10lib.UnitOff(houseCode, unitCode);
                }
            }
            else if (command == Command.CONTROL_ALLLIGHTSON)
            {
                x10lib.AllLightsOn(houseCode);
            }
            else if (command == Command.CONTROL_ALLLIGHTSOFF)
            {
                x10lib.AllUnitsOff(houseCode);
            }
            //
            return(response);
        }
Exemple #2
0
        public object InterfaceControl(MigInterfaceCommand request)
        {
            ResponseText response = new ResponseText("OK");

            string nodeId = request.Address;
            string option = request.GetOption(0);

            Commands command;

            Enum.TryParse <Commands>(request.Command.Replace(".", "_"), out command);

            // Parse house/unit
            var houseCode = XTenLib.Utility.HouseCodeFromString(nodeId);
            var unitCode  = XTenLib.Utility.UnitCodeFromString(nodeId);

            switch (command)
            {
            case Commands.Parameter_Status:
                x10lib.StatusRequest(houseCode, unitCode);
                break;

            case Commands.Control_On:
                x10lib.UnitOn(houseCode, unitCode);
                break;

            case Commands.Control_Off:
                x10lib.UnitOff(houseCode, unitCode);
                break;

            case Commands.Control_Bright:
                x10lib.Bright(houseCode, unitCode, int.Parse(option));
                break;

            case Commands.Control_Dim:
                x10lib.Dim(houseCode, unitCode, int.Parse(option));
                break;

            case Commands.Control_Level_Adjust:
                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"));
                break;

            case Commands.Control_Level:
                int dimvalue = int.Parse(option) - (int)(x10lib.Modules[nodeId].Level * 100.0);
                if (dimvalue > 0)
                {
                    x10lib.Bright(houseCode, unitCode, dimvalue);
                }
                else if (dimvalue < 0)
                {
                    x10lib.Dim(houseCode, unitCode, -dimvalue);
                }
                break;

            case Commands.Control_Toggle:
                string huc = XTenLib.Utility.HouseUnitCodeFromEnum(houseCode, unitCode);
                if (x10lib.Modules[huc].Level == 0)
                {
                    x10lib.UnitOn(houseCode, unitCode);
                }
                else
                {
                    x10lib.UnitOff(houseCode, unitCode);
                }
                break;

            case Commands.Control_AllLightsOn:
                x10lib.AllLightsOn(houseCode);
                break;

            case Commands.Control_AllLightsOff:
                x10lib.AllUnitsOff(houseCode);
                break;
            }

            return(response);
        }
Exemple #3
0
        public object InterfaceControl(MigInterfaceCommand request)
        {
            var response = new ResponseText("OK");

            string nodeId = lastAddressedModule = request.Address;
            string option = request.GetOption(0);

            Commands command;

            Enum.TryParse <Commands>(request.Command.Replace(".", "_"), out command);

            if (portName == Cm19LibDriverPort)
            {
                // Parse house/unit
                var houseCode = CM19Lib.Utility.HouseCodeFromString(nodeId);
                var unitCode  = CM19Lib.Utility.UnitCodeFromString(nodeId);
                var module    = GetSecurityModuleByAddress(nodeId, ModuleTypes.Switch);
                // module.CustomData is used to store the current level
                switch (command)
                {
                case Commands.Control_On:
                    cm19Lib.UnitOn(houseCode, unitCode);
                    module.CustomData = 1D;
                    UpdateModuleLevel(module);
                    break;

                case Commands.Control_Off:
                    cm19Lib.UnitOff(houseCode, unitCode);
                    module.CustomData = 0D;
                    UpdateModuleLevel(module);
                    break;

                case Commands.Control_Bright:
                    cm19Lib.Bright(houseCode);
                    module.CustomData = module.CustomData + (5 / 100D);
                    if (module.CustomData > 1)
                    {
                        module.CustomData = 1D;
                    }
                    UpdateModuleLevel(module);
                    break;

                case Commands.Control_Dim:
                    cm19Lib.Dim(houseCode);
                    module.CustomData = module.CustomData - (5 / 100D);
                    if (module.CustomData < 0)
                    {
                        module.CustomData = 0D;
                    }
                    UpdateModuleLevel(module);
                    break;

                case Commands.Control_Level:
                    int dimValue = (int.Parse(option) - (int)(module.CustomData * 100.0)) / 5;
                    if (dimValue > 0)
                    {
                        cm19Lib.Bright(houseCode);
                        for (int i = 0; i < (dimValue / Cm19Manager.SendRepeatCount); i++)
                        {
                            cm19Lib.Bright(houseCode);
                        }
                    }
                    else if (dimValue < 0)
                    {
                        cm19Lib.Dim(houseCode);
                        for (int i = 0; i < -(dimValue / Cm19Manager.SendRepeatCount); i++)
                        {
                            cm19Lib.Dim(houseCode);
                        }
                    }
                    module.CustomData = module.CustomData + (dimValue * 5 / 100D);
                    UpdateModuleLevel(module);
                    break;

                case Commands.Control_Toggle:
                    if (module.CustomData == 0D)
                    {
                        cm19Lib.UnitOn(houseCode, unitCode);
                        UpdateModuleLevel(module);
                    }
                    else
                    {
                        cm19Lib.UnitOff(houseCode, unitCode);
                        UpdateModuleLevel(module);
                    }
                    break;

                case Commands.Control_AllLightsOn:
                    cm19Lib.AllLightsOn(houseCode);
                    // TODO: update modules status
                    break;

                case Commands.Control_AllUnitsOff:
                    cm19Lib.AllUnitsOff(houseCode);
                    // TODO: update modules status
                    break;

                case Commands.Control_RfSend:
                    byte[] data = CM19Lib.Utility.StringToByteArray(option.Replace(" ", ""));
                    cm19Lib.SendMessage(data);
                    break;
                }
            }
            else
            {
                // Parse house/unit
                var houseCode = XTenLib.Utility.HouseCodeFromString(nodeId);
                var unitCode  = XTenLib.Utility.UnitCodeFromString(nodeId);
                switch (command)
                {
                case Commands.Parameter_Status:
                    x10Lib.StatusRequest(houseCode, unitCode);
                    break;

                case Commands.Control_On:
                    x10Lib.UnitOn(houseCode, unitCode);
                    break;

                case Commands.Control_Off:
                    x10Lib.UnitOff(houseCode, unitCode);
                    break;

                case Commands.Control_Bright:
                    x10Lib.Bright(houseCode, unitCode, int.Parse(option));
                    break;

                case Commands.Control_Dim:
                    x10Lib.Dim(houseCode, unitCode, int.Parse(option));
                    break;

                case Commands.Control_Level_Adjust:
                    //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"));
                    break;

                case Commands.Control_Level:
                    int dimvalue = int.Parse(option) - (int)(x10Lib.Modules[nodeId].Level * 100.0);
                    if (dimvalue > 0)
                    {
                        x10Lib.Bright(houseCode, unitCode, dimvalue);
                    }
                    else if (dimvalue < 0)
                    {
                        x10Lib.Dim(houseCode, unitCode, -dimvalue);
                    }
                    break;

                case Commands.Control_Toggle:
                    string huc = XTenLib.Utility.HouseUnitCodeFromEnum(houseCode, unitCode);
                    if (x10Lib.Modules[huc].Level == 0)
                    {
                        x10Lib.UnitOn(houseCode, unitCode);
                    }
                    else
                    {
                        x10Lib.UnitOff(houseCode, unitCode);
                    }
                    break;

                case Commands.Control_AllLightsOn:
                    x10Lib.AllLightsOn(houseCode);
                    break;

                case Commands.Control_AllUnitsOff:
                    x10Lib.AllUnitsOff(houseCode);
                    break;

                case Commands.Control_RfSend:
                    byte[] data = CM19Lib.Utility.StringToByteArray("EB" + option.Replace(" ", ""));
                    // SendRepeatCount is not implemented in XTenLib, so a for loop in required here
                    for (int i = 0; i < Cm19Manager.SendRepeatCount; i++)
                    {
                        x10Lib.SendMessage(data);
                        Thread.Sleep(Cm19Manager.SendPauseMs);
                    }
                    break;
                }
            }

            return(response);
        }
Exemple #4
0
        public object InterfaceControl(MIGInterfaceCommand request)
        {
            string response = "[{ ResponseValue : 'OK' }]";

            string nodeId  = request.NodeId;
            var    command = (Command)request.Command;
            string option  = request.GetOption(0);

            // Parse house/unit
            var houseCode = XTenLib.Utility.HouseCodeFromString(nodeId);
            var unitCode  = XTenLib.Utility.UnitCodeFromString(nodeId);

            // Modules control
            if (command == Command.PARAMETER_STATUS)
            {
                x10lib.StatusRequest(houseCode, unitCode);
            }
            else if (command == Command.CONTROL_ON)
            {
                x10lib.LightOn(houseCode, unitCode);
            }
            else if (command == Command.CONTROL_OFF)
            {
                x10lib.LightOff(houseCode, unitCode);
            }
            else if (command == Command.CONTROL_BRIGHT)
            {
                x10lib.Bright(houseCode, unitCode, int.Parse(option));
            }
            else if (command == Command.CONTROL_DIM)
            {
                x10lib.Dim(houseCode, unitCode, int.Parse(option));
            }
            else if (command == Command.CONTROL_LEVEL)
            {
                int dimvalue = int.Parse(option) - (int)(x10lib.ModulesStatus[nodeId].Level * 100.0);
                if (dimvalue > 0)
                {
                    x10lib.Bright(houseCode, unitCode, dimvalue);
                }
                else if (dimvalue < 0)
                {
                    x10lib.Dim(houseCode, unitCode, -dimvalue);
                }
            }
            else if (command == Command.CONTROL_TOGGLE)
            {
                string huc = XTenLib.Utility.HouseUnitCodeFromEnum(houseCode, unitCode);
                if (x10lib.ModulesStatus[huc].Level == 0)
                {
                    x10lib.LightOn(houseCode, unitCode);
                }
                else
                {
                    x10lib.LightOff(houseCode, unitCode);
                }
            }
            else if (command == Command.CONTROL_ALLLIGHTSON)
            {
                x10lib.AllLightsOn(houseCode);
            }
            else if (command == Command.CONTROL_ALLLIGHTSOFF)
            {
                x10lib.AllUnitsOff(houseCode);
            }//
            return(response);
        }
Exemple #5
0
        public object InterfaceControl(MIGInterfaceCommand request)
        {
            string  nodeid  = request.nodeid;
            Command command = (Command)request.command;
            string  option  = request.GetOption(0);

            //process command
            #region X10HAL-commands compatibility !!! <-- DEPRECATE THIS
            if (nodeid.ToUpper() == "STATUS")
            {
                List <X10Module> tempdataitems = new List <X10Module>(x10lib.ModulesStatus.Count);
                foreach (string key in x10lib.ModulesStatus.Keys)
                {
                    tempdataitems.Add(x10lib.ModulesStatus[key]);
                }

                XmlSerializer           serializer = new XmlSerializer(typeof(List <X10Module>));
                StringWriter            sw         = new StringWriter();
                XmlSerializerNamespaces ns         = new XmlSerializerNamespaces();
                ns.Add("", "");
                serializer.Serialize(sw, tempdataitems, ns);

                StringBuilder sb = new StringBuilder();
                sb.Append(sw.ToString());
                //byte[] b = Encoding.UTF8.GetBytes(sb.ToString());
                //response.ContentLength64 = b.Length;
                //response.OutputStream.Write(b, 0, b.Length);
                return(sb.ToString());
            }
            else if (nodeid.ToUpper() == "CONFIG")
            {
                string configpath = @"C:\Program Files\ActiveHome Pro\HAL.ahx";
                string config     = "";
                //
                try
                {
                    config = System.IO.File.ReadAllText(configpath);
                    //
                    if (config.IndexOf("&amp;") <= 0)
                    {
                        config = config.Replace("&", "&amp;");
                    }
                    //
                    StringBuilder sb = new StringBuilder();
                    sb.Append(config);
                    return(sb.ToString());
                }
                catch (Exception e)
                {
                }
            }
            #endregion
            X10HouseCodes housecode = XTenLib.Utility.HouseCodeFromString(nodeid);
            X10UnitCodes  unitcode  = XTenLib.Utility.UnitCodeFromString(nodeid);
            if (command == Command.PARAMETER_STATUS)
            {
                x10lib.StatusRequest(housecode, unitcode);
            }
            else if (command == Command.CONTROL_ON)
            {
                x10lib.LightOn(housecode, unitcode);
            }
            else if (command == Command.CONTROL_OFF)
            {
                x10lib.LightOff(housecode, unitcode);
            }
            else if (command == Command.CONTROL_BRIGHT)
            {
                x10lib.Bright(housecode, unitcode, int.Parse(option));
            }
            else if (command == Command.CONTROL_DIM)
            {
                x10lib.Dim(housecode, unitcode, int.Parse(option));
            }
            else if (command == Command.CONTROL_LEVEL)
            {
                int dimvalue = int.Parse(option) - (int)(x10lib.ModulesStatus[nodeid].Level * 100.0);
                if (dimvalue > 0)
                {
                    x10lib.Bright(housecode, unitcode, dimvalue);
                }
                else if (dimvalue < 0)
                {
                    x10lib.Dim(housecode, unitcode, -dimvalue);
                }
            }
            else if (command == Command.CONTROL_TOGGLE)
            {
                string huc = XTenLib.Utility.HouseUnitCodeFromEnum(housecode, unitcode);
                if (x10lib.ModulesStatus[huc].Level == 0)
                {
                    x10lib.LightOn(housecode, unitcode);
                }
                else
                {
                    x10lib.LightOff(housecode, unitcode);
                }
            }
            else if (command == Command.CONTROL_ALLLIGHTSON)
            {
                x10lib.AllLightsOn(housecode);
            }
            else if (command == Command.CONTROL_ALLLIGHTSOFF)
            {
                x10lib.AllUnitsOff(housecode);
            }//
            return("");
        }