Exemple #1
0
 public void AllUnitsOff(X10HouseCodes housecode)
 {
     lock (this)
     {
         string hcunit    = String.Format("{0:X}{1:X}", (int)housecode, 0);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.All_Units_Off);
         SendMessage(new byte[] {
             (int)X10CommandType.Address,
             byte.Parse(
                 hcunit,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
         //
         // TODO: pick only lights module
         AllUnitsOff(housecode.ToString());
     }
 }
Exemple #2
0
        public void Bright(X10HouseCodes housecode, X10UnitCodes unitcode, int percentage)
        {
            string huc       = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
            string hcunit    = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
            string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Bright);
            string dimbright = String.Format("{0:x1}", (int)(((double)percentage / 100D) * 210));

            //
            _modstatus[huc].Level += ((double)percentage / 100.0);
            if (_modstatus[huc].Level > 1.0)
            {
                _modstatus[huc].Level = 1.0;
            }
            //
            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
            if (_x10interface.GetType().Equals(typeof(CM11)))
            {
                int dimvalue = (int)(((double)percentage / 100D) * 16) << 3;
                dimbright = String.Format("{0:x1}", dimvalue);
                _sendqueue.Enqueue(new byte[] { (byte)((int)X10CommandType.Function | dimvalue), byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
            }
            else
            {
                _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber), byte.Parse(dimbright, System.Globalization.NumberStyles.HexNumber) });
            }
        }
Exemple #3
0
        public static string HouseUnitCodeFromEnum(X10HouseCodes housecode, X10UnitCodes unitcodes)
        {
            string unit = unitcodes.ToString();

            unit = unit.Substring(unit.LastIndexOf("_") + 1);
            //
            return(housecode.ToString() + unit);
        }
Exemple #4
0
        public void StatusRequest(X10HouseCodes housecode, X10UnitCodes unitcode)
        {
            string hcunit    = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
            string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Status_Request);

            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
        }
Exemple #5
0
        public void AllLightsOn(X10HouseCodes housecode)
        {
            string hcunit    = String.Format("{0:X}{1:X}", (int)housecode, 0);
            string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.All_Lights_On);

            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
            //
            // TODO: pick only lights module
            _allLightsOn(housecode.ToString());
        }
Exemple #6
0
        public void LightOff(X10HouseCodes housecode, X10UnitCodes unitcode)
        {
            string hcunit    = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
            string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Off);

            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
            _sendqueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
            //
            string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);

            _modstatus[huc].Level = 0.0;
        }
Exemple #7
0
 public void StatusRequest(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Status_Request);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
     }
 }
Exemple #8
0
 public void Bright(X10HouseCodes housecode, X10UnitCodes unitcode, int percentage)
 {
     lock (this)
     {
         string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Bright);
         //
         SendModuleAddress(housecode, unitcode);
         if (x10interface.GetType().Equals(typeof(CM15)))
         {
             double normalized = ((double)percentage / 100D);
             SendMessage(new byte[] {
                 (int)X10CommandType.Function,
                 byte.Parse(
                     hcfuntion,
                     System.Globalization.NumberStyles.HexNumber
                     ),
                 (byte)(normalized * 210)
             });
             double newLevel = moduleStatus[huc].Level + normalized;
             if (newLevel > 1)
             {
                 newLevel = 1;
             }
             moduleStatus[huc].Level = newLevel;
         }
         else
         {
             byte dimvalue = Utility.GetDimValue(percentage);
             SendMessage(new byte[] {
                 (byte)((int)X10CommandType.Function | dimvalue | 0x04),
                 byte.Parse(
                     hcfuntion,
                     System.Globalization.NumberStyles.HexNumber
                     )
             });
             double newLevel = moduleStatus[huc].Level + Utility.GetPercentageValue(dimvalue);
             if (newLevel > 1)
             {
                 newLevel = 1;
             }
             moduleStatus[huc].Level = newLevel;
         }
     }
 }
Exemple #9
0
 public void LightOff(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Off);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
         //
         string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
         moduleStatus[huc].Level = 0.0;
     }
 }
Exemple #10
0
 private void SendModuleAddress(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     if (!addressedModules.ContainsKey(housecode.ToString()))
     {
         addressedModules.Add(housecode.ToString(), new List <X10Module>());
     }
     string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
     var    mod = moduleStatus[huc];
     // TODO: do more tests about this optimization
     //if (!addressedModules[housecode.ToString()].Contains(mod) || addressedModules[housecode.ToString()].Count > 1)
     {
         addressedModules[housecode.ToString()].Clear();
         addressedModules[housecode.ToString()].Add(mod);
         string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Address,
             byte.Parse(
                 hcunit,
                 System.Globalization.NumberStyles.HexNumber
                 )
         });
     }
 }
Exemple #11
0
 public void LightOff(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Off);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
         //
         string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
         moduleStatus[huc].Level = 0.0;
     }
 }
Exemple #12
0
 public void Bright(X10HouseCodes housecode, X10UnitCodes unitcode, int percentage)
 {
     lock (this)
     {
         string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Bright);
         //
         SendModuleAddress(housecode, unitcode);
         if (x10interface.GetType().Equals(typeof(CM15)))
         {
             double normalized = ((double)percentage / 100D);
             SendMessage(new byte[] {
                 (int)X10CommandType.Function,
                 byte.Parse(
                     hcfuntion,
                     System.Globalization.NumberStyles.HexNumber
                 ),
                 (byte)(normalized * 210)
             });
             double newLevel = moduleStatus[huc].Level + normalized;
             if (newLevel > 1) newLevel = 1;
             moduleStatus[huc].Level = newLevel;
         }
         else
         {
             byte dimvalue = Utility.GetDimValue(percentage);
             SendMessage(new byte[] {
                 (byte)((int)X10CommandType.Function | dimvalue | 0x04),
                 byte.Parse(
                     hcfuntion,
                     System.Globalization.NumberStyles.HexNumber
                 )
             });
             double newLevel = moduleStatus[huc].Level + Utility.GetPercentageValue(dimvalue);
             if (newLevel > 1) newLevel = 1;
             moduleStatus[huc].Level = newLevel;
         }
     }
 }
Exemple #13
0
 public void StatusRequest(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     lock (this)
     {
         //string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.Status_Request);
         SendModuleAddress(housecode, unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
     }
 }
Exemple #14
0
        public static X10HouseCodes HouseCodeFromString(string s)
        {
            X10HouseCodes hc = X10HouseCodes.A;

            s = s.Substring(0, 1).ToUpper();
            switch (s)
            {
            case "A":
                hc = X10HouseCodes.A;
                break;

            case "B":
                hc = X10HouseCodes.B;
                break;

            case "C":
                hc = X10HouseCodes.C;
                break;

            case "D":
                hc = X10HouseCodes.D;
                break;

            case "E":
                hc = X10HouseCodes.E;
                break;

            case "F":
                hc = X10HouseCodes.F;
                break;

            case "G":
                hc = X10HouseCodes.G;
                break;

            case "H":
                hc = X10HouseCodes.H;
                break;

            case "I":
                hc = X10HouseCodes.I;
                break;

            case "J":
                hc = X10HouseCodes.J;
                break;

            case "K":
                hc = X10HouseCodes.K;
                break;

            case "L":
                hc = X10HouseCodes.L;
                break;

            case "M":
                hc = X10HouseCodes.M;
                break;

            case "N":
                hc = X10HouseCodes.N;
                break;

            case "O":
                hc = X10HouseCodes.O;
                break;

            case "P":
                hc = X10HouseCodes.P;
                break;
            }
            return(hc);
        }
Exemple #15
0
 public static string HouseUnitCodeFromEnum(X10HouseCodes housecode, X10UnitCodes unitcodes)
 {
     string unit = unitcodes.ToString();
     unit = unit.Substring(unit.LastIndexOf("_") + 1);
     //
     return housecode.ToString() + unit;
 }
Exemple #16
0
 public void AllUnitsOff(X10HouseCodes housecode)
 {
     lock (this)
     {
         string hcunit = String.Format("{0:X}{1:X}", (int)housecode, 0);
         string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.All_Units_Off);
         SendMessage(new byte[] {
             (int)X10CommandType.Address,
             byte.Parse(
                 hcunit,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
         SendMessage(new byte[] {
             (int)X10CommandType.Function,
             byte.Parse(
                 hcfuntion,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
         //
         // TODO: pick only lights module
         AllUnitsOff(housecode.ToString());
     }
 }
Exemple #17
0
 public void AllLightsOn(X10HouseCodes housecode)
 {
     string hcunit = String.Format("{0:X}{1:X}", (int)housecode, 0);
     string hcfuntion = String.Format("{0:x1}{1:x1}", (int)housecode, (int)X10Command.All_Lights_On);
     sendQueue.Enqueue(new byte[] { (int)X10CommandType.Address, byte.Parse(hcunit, System.Globalization.NumberStyles.HexNumber) });
     sendQueue.Enqueue(new byte[] { (int)X10CommandType.Function, byte.Parse(hcfuntion, System.Globalization.NumberStyles.HexNumber) });
     //
     // TODO: pick only lights module
     AllLightsOn(housecode.ToString());
 }
Exemple #18
0
 private void SendModuleAddress(X10HouseCodes housecode, X10UnitCodes unitcode)
 {
     if (!addressedModules.ContainsKey(housecode.ToString()))
     {
         addressedModules.Add(housecode.ToString(), new List<X10Module>());
     }
     string huc = Utility.HouseUnitCodeFromEnum(housecode, unitcode);
     var mod = moduleStatus[huc];
     // TODO: do more tests about this optimization
     //if (!addressedModules[housecode.ToString()].Contains(mod) || addressedModules[housecode.ToString()].Count > 1)
     {
         addressedModules[housecode.ToString()].Clear();
         addressedModules[housecode.ToString()].Add(mod);
         string hcunit = String.Format("{0:X}{1:X}", (int)housecode, (int)unitcode);
         SendMessage(new byte[] {
             (int)X10CommandType.Address,
             byte.Parse(
                 hcunit,
                 System.Globalization.NumberStyles.HexNumber
             )
         });
     }
 }
Exemple #19
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("");
        }