Beispiel #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.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_ADJUST)
            {
                int dimvalue = int.Parse(option);
                x10lib.ModulesStatus[nodeId].Level = ((double)dimvalue / 100D);
                InterfacePropertyChangedAction(new InterfacePropertyChangedAction()
                {
                    Domain     = this.Domain,
                    SourceId   = nodeId,
                    SourceType = "X10 Module",
                    Path       = "Status.Level",
                    Value      = x10lib.ModulesStatus[nodeId].Level
                });
            }
            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);
        }
Beispiel #2
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("");
        }