Exemplo n.º 1
0
 /// <summary>
 /// Checks to see if the current device or the useragent string contain each
 /// other at the start.
 /// </summary>
 /// <param name="userAgent">The useragent being searched for.</param>
 /// <param name="bestMatch">Reference to the best matching device so far.</param>
 /// <param name="maxInitialString">The maximum number of characters that have matched in the search so far.</param>
 /// <param name="current">The current device being checked for a match.</param>
 private static void Check(string userAgent, ref BaseDeviceInfo bestMatch, ref int maxInitialString,
                           BaseDeviceInfo current)
 {
     if ((userAgent.StartsWith(current.UserAgent) ||
          current.UserAgent.StartsWith(userAgent)) &&
         maxInitialString < current.UserAgent.Length)
     {
         maxInitialString = current.UserAgent.Length;
         bestMatch = current;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 接收控制灯光信息
        /// </summary>
        /// <param name="devGuid"></param>
        /// <param name="actionType"></param>
        /// <param name="brightness"></param>
        /// <returns></returns>
        public static string ControlLamp(string devGuid, ActionEnumLamp actionType, byte brightness)
        {
            string         DevGuid    = devGuid;
            string         dstAddress = "";
            string         actionLamp = "";
            string         Brightness = "";
            string         ActionLamp;
            BaseDeviceInfo knxDevbuff = new BaseDeviceInfo();

            //ActionEnumLamp actionLamp = actionType;
            //int a = Convert.ToInt32(actionLamp.GetType());
            for (int i = 0; i < baseDeviceInfos.Count; i++)
            {
                if (devGuid == baseDeviceInfos[i].DeviceGuid)
                {
                    knxDevbuff = baseDeviceInfos[i];
                }
            }

            //dstAddress = frmMyKNX.ExchangeDesaddr(knxDevbuff.KNX_GroupAddress[0], knxDevbuff.KNX_GroupAddress[1]);

            dstAddress = knxDevbuff.KNX_GroupAddress[0].ToString("X2") + " " + knxDevbuff.KNX_GroupAddress[1].ToString("X2");
            if (actionType == ActionEnumLamp.TurnOff)  //关灯
            {
                actionLamp = "01 00 80";
            }
            else if (actionType == ActionEnumLamp.TurnOn)   //开灯
            {
                actionLamp = "01 00 81";
            }
            else if (actionType == ActionEnumLamp.Dimmer)   //调光模式
            {
                actionLamp = "01 00 81";
                Brightness = brightness.ToString("X2");
            }
            ActionLamp = dstAddress + " " + actionLamp;
            return(ActionLamp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 接收控制窗帘信息
        /// </summary>
        /// <param name="devGuid"></param>
        /// <param name="actionType"></param>
        /// <param name="percent"></param>
        /// <returns></returns>
        public static string ControlCurtain(string devGuid, ActionEnumCurtain actionType, byte percent)
        {
            string         actionCurtain = " ";
            string         dstAddress    = "";
            BaseDeviceInfo knxDevbuff1   = new BaseDeviceInfo();
            string         Actioncurtain;
            string         Percent;

            for (int i = 0; i < baseDeviceInfos.Count; i++)
            {
                if (devGuid == baseDeviceInfos[i].DeviceGuid)
                {
                    knxDevbuff1 = baseDeviceInfos[i];
                }
            }
            dstAddress = knxDevbuff1.KNX_GroupAddress[0].ToString("X2") + " " + knxDevbuff1.KNX_GroupAddress[1].ToString("X2");

            if (actionType == ActionEnumCurtain.Close)   //关窗帘
            {
                actionCurtain = "01 00 80";
            }
            else if (actionType == ActionEnumCurtain.Open)  //开窗帘
            {
                actionCurtain = "01 00 81";
            }
            else if (actionType == ActionEnumCurtain.Stop)  //停止
            {
                actionCurtain = "01 00 80";
            }
            else if (actionType == ActionEnumCurtain.Percent) //开到百分比
            {
                Percent = percent.ToString("X2");             //有待改进
            }

            Actioncurtain = dstAddress + " " + actionCurtain;
            return(Actioncurtain);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructs a new instance of ClientCapability.
 /// See http://51degrees.mobi/Products/DeviceData/PropertyDictionary.aspx
 /// for a full list of available properties.
 /// All the properties used are non-lists and therefore the first
 /// item contained in the values list contains the only available value.
 /// </summary>
 public FiftyOneClientCapability(BaseDeviceInfo device)
 {
     Initialise(device.GetAllProperties());
     UserAgent = device.UserAgent;
 }
Exemplo n.º 5
0
 private void ProcessUaProf(BaseDeviceInfo device, int hashcode)
 {
     // Does the hashcode already exist?
     if (_uaprofs.ContainsKey(hashcode))
     {
         // Does the key already exist?
         int index;
         for (index = 0; index < _uaprofs[hashcode].Length; index++)
         {
             if (_uaprofs[hashcode][index].DeviceId != device.DeviceId) continue;
             // Yes. Update with the new device and then exit.
             _uaprofs[hashcode][index] = device;
             return;
         }
         // No. Expand the array adding the new device.
         List<BaseDeviceInfo> newList = new List<BaseDeviceInfo>(_uaprofs[hashcode]) { device };
         _uaprofs[hashcode] = newList.ToArray();
     }
     else
     {
         // Add the device to the collection.
         _uaprofs.Add(hashcode, new[] { device });
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the device to the collection of devices with UA prof information.
        /// If the device already exists the previous one is replaced.
        /// </summary>
        /// <param name="device">Device to be added.</param>
        private void SetUaProf(BaseDeviceInfo device)
        {
            foreach (int index in _provider.UserAgentProfileStringIndexes)
            {
                var list = device.GetPropertyValueStringIndexes(index);
                if (list != null)
                {
                    foreach (int userAgentProfileStringIndex in list)
                    {
                        string value = _provider.Strings.Get(userAgentProfileStringIndex);

                        // Don't process empty values.
                        if (String.IsNullOrEmpty(value)) continue;
                        
                        // If the url is not valid don't continue processing.
                        Uri url = null;
                        if (Uri.TryCreate(value, UriKind.Absolute, out url) == false) continue;

                        // Get the hashcode before locking the list and processing
                        // the device and hashcode.
                        int hashcode = value.GetHashCode();
                        lock (_uaprofs)
                        {
                            ProcessUaProf(device, hashcode);
                        }

                        // Add the domain to the list of domains for the handler.
                        lock (_uaProfDomains)
                        {
                            if (_uaProfDomains.Contains(url.Host) == false)
                                _uaProfDomains.Add(url.Host);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Adds the device and it's user agent string to the collection
 /// of user agent strings and devices. The useragent string
 /// hashcode is the key of the collection.
 /// </summary>
 /// <param name="device">A new device to add.</param>
 private void SetUserAgent(BaseDeviceInfo device)
 {
     int hashcode = device.UserAgent.GetHashCode();
     lock (_devices)
     {
         BaseDeviceInfo[] value;
         // Does the hashcode already exist?
         if (_devices.TryGetValue(hashcode, out value))
         {
             // Does the key already exist?
             for (int i = 0; i < value.Length; i++)
             {
                 if (value[i].UserAgent == device.UserAgent)
                 {
                     // Yes. Update with the new device and then exit.
                     value[i] = device;
                     return;
                 }
             }
             // No. Expand the array adding the new device.
             List<BaseDeviceInfo> newList = new List<BaseDeviceInfo>(value);
             newList.Add(device);
             _devices[hashcode] = newList.ToArray();
         }
         else
         {
             // Add the device to the collection.
             _devices.Add(hashcode, new[] { device });
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Checks to see if the handler can support this device.
 /// </summary>
 /// <param name="device">Device to be checked.</param>
 /// <returns>True if the device is supported, other false.</returns>
 protected internal virtual bool CanHandle(BaseDeviceInfo device)
 {
     return CanHandle(device.UserAgent);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Adds a new device to the handler.
 /// </summary>
 /// <param name="device">device being added to the handler.</param>
 internal virtual void Set(BaseDeviceInfo device)
 {
     SetUserAgent(device);
     SetUaProf(device);
 }
Exemplo n.º 10
0
        private static void LoadCapabilityData(
            XmlReader reader,
            BaseDeviceInfo device,
            StringCollection availableCapabilities)
        {
            string capabilityName = reader.GetAttribute(Constants.NameAttributeName, string.Empty);
            string capabilityValue = reader.GetAttribute(Constants.ValueAttributeName, string.Empty);

            // Store all the capabilities names, that's used to make sure
            // all devices havae all capabilities associated to it.
            if (availableCapabilities.Contains(capabilityName) == false)
                availableCapabilities.Add(capabilityName);

            // Ensure the capability is set to the current value.
            device.Properties.Set(capabilityName, capabilityValue.Split(
                new string[] { Detection.Constants.ValueSeperator }, 
                StringSplitOptions.RemoveEmptyEntries));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Processes the XML element containing the device attributes.
        /// </summary>
        /// <param name="provider">A list of loaded devices.</param>
        /// <param name="reader">The XML stream readers.</param>
        /// <returns>An empty device.</returns>
        private static BaseDeviceInfo LoadDevice(Provider provider, XmlReader reader)
        {
            // Create the next device using the fallback device if available.
            string deviceId = reader.GetAttribute(Constants.IdAttributeName, string.Empty);
            string userAgent = reader.GetAttribute(Constants.UserAgentAttributeName, string.Empty);
            string fallbackDeviceId = reader.GetAttribute(Constants.ParentAttributeName, string.Empty);

            // If the device already exists then use the previous one. This may happen
            // when an earlier device referenced a fallback device that had not yet
            // been created.
            var device = provider.GetDeviceInfoFromID(deviceId);
            if (device == null)
            {
                // Create the new device.
                device = new BaseDeviceInfo(provider, deviceId, userAgent ?? String.Empty);
            }
            else if (userAgent != null)
            {
                // Ensure the correct UserAgent string is assigned to this device.
                device.InternalUserAgent = userAgent;
                provider.Set(device);
            }

            // Check the fallback device is different to the device being loaded.
            if (fallbackDeviceId != null && device.DeviceId != fallbackDeviceId)
            {
                // Does the fallback device already exist?
                device.Parent = provider.GetDeviceInfoFromID(fallbackDeviceId);
                if (device.Parent == null)
                {
                    // No. So create new fallback device.
                    device.Parent = new BaseDeviceInfo(provider, fallbackDeviceId);
                    // Add it to the available devices.
                    provider.Set(device.Parent);
                }
            }
            return device;
        }
Exemplo n.º 12
0
        /// <summary>
        /// 接收控制空调信息
        /// </summary>
        /// <param name="devGuid"></param>
        /// <param name="actionType"></param>
        /// <param name="tempValue"></param>
        /// <returns></returns>
        public static string ControlAir(string devGuid, ActionEnumAir actionType, byte tempValue)
        {
            BaseDeviceInfo knxDevbuff2 = new BaseDeviceInfo();
            string         dstAddress  = "";
            string         strMessage  = null;
            string         Mess;

            for (int i = 0; i < baseDeviceInfos.Count; i++)
            {
                if (devGuid == baseDeviceInfos[i].DeviceGuid)
                {
                    knxDevbuff2 = baseDeviceInfos[i];
                }
            }

            dstAddress = knxDevbuff2.KNX_GroupAddress[0].ToString("X2") + " " + knxDevbuff2.KNX_GroupAddress[1].ToString("X2");

            if (actionType == ActionEnumAir.TurnOff)  //关空调
            {
                strMessage = " ";
            }
            else if (actionType == ActionEnumAir.TurnOn)  //开空调
            {
                strMessage = " ";
            }
            else if (actionType == ActionEnumAir.SetMode_Cold) //制冷
            {
                strMessage = "06 10 05 30 00 11 29 00 BC D0 11 09 1D 01 01 00 81";
            }
            else if (actionType == ActionEnumAir.SetMode_Hot)  //制热
            {
                strMessage = "06 10 05 30 00 11 29 00 BC D0 11 09 1D 02 01 00 81";
            }
            else if (actionType == ActionEnumAir.SetMode_Fan)  //通风
            {
                strMessage = "06 10 05 30 00 11 29 00 BC D0 11 09 1D 04 01 00 81";
            }
            else if (actionType == ActionEnumAir.SetMode_Auto)  //自动模式
            {
                strMessage = "06 10 05 30 00 11 29 00 BC D0 11 09 1D 05 01 00 81";
            }
            else if (actionType == ActionEnumAir.SetMode_Dry)   //除湿模式
            {
                strMessage = " ";
            }
            else if (actionType == ActionEnumAir.SetSpeed_Auto)  //自动送风
            {
                strMessage = "06 10 05 30 00 11 29 00 BC D0 11 09 1D 06 01 00 81";
            }
            else if (actionType == ActionEnumAir.SetSpeed_High)  //高风
            {
                strMessage = "06 10 05 30 00 12 29 00 BC D0 11 09 1C 01 02 00 80 FF";
            }
            else if (actionType == ActionEnumAir.SetSpeed_Middle)  //中风
            {
                strMessage = "06 10 05 30 00 12 29 00 BC D0 11 09 1C 01 02 00 80 AA";
            }
            else if (actionType == ActionEnumAir.SetSpeed_Low)   //低风
            {
                strMessage = "06 10 05 30 00 12 29 00 BC D0 11 09 1C 01 02 00 80 55";
            }
            else if (actionType == ActionEnumAir.CustomTemperature)   //自定义温度
            {
                strMessage = "";
            }
            else if (actionType == ActionEnumAir.WindClose)  //扫风关,摆风关
            {
            }
            else if (actionType == ActionEnumAir.WindOpen)  //扫风开,摆风开
            {
            }
            //Mess = strMessage;
            return(strMessage);
        }