Пример #1
0
        public static Command FindCommand(this ZWaveDefinition zWaveDefinition, CommandClass commandClass, byte key)
        {
            Command ret = null;

            if (commandClass.Command != null)
            {
                foreach (Command var in commandClass.Command)
                {
                    if (var.Bits > 0 && var.Bits < 8)
                    {
                        if (var.KeyId == (key & Tools.GetMaskFromBits(var.Bits, (byte)(8 - var.Bits))))
                        {
                            ret = var;
                            break;
                        }
                    }
                    else if (var.KeyId == key)
                    {
                        ret = var;
                        break;
                    }
                }
            }
            return(ret);
        }
Пример #2
0
        public static void Save(ZWaveDefinition zWaveDefinition, string path)
        {
            DefinitionConverter conv = new DefinitionConverter(null, null)
            {
                ZWaveDefinition = zWaveDefinition
            };

            conv.DowngradeConvert();
            conv.SaveZXmlDefinition(path);
        }
Пример #3
0
        private ParamValue ProcessParameter(byte[] data, ref int index, Param item, IList <ParamValue> vgParams)
        {
            ParamValue ret = ParamValue.CreateParamValue(item);

            if (string.IsNullOrEmpty(item.OptionalReference) || IsIncluded(item.OptionalReference))
            {
                switch (item.Mode)
                {
                case ParamModes.VariantGroup:
                    ret.InnerValues = new List <ParamValue>();
                    if (item.Size > 1)
                    {
                        for (int i = 0; i < item.Size; i++)
                        {
                            ParamValue vg = ParamValue.CreateParamValue(item);
                            vg.InnerValues = new List <ParamValue>();
                            foreach (var prm1 in item.Param1)
                            {
                                ParamValue innerParam = ProcessParameter(data, ref index, prm1, vg.InnerValues);
                                vg.InnerValues.Add(innerParam);
                                vg.ByteValueList.AddRange(innerParam.ByteValueList);
                            }
                            ret.InnerValues.Add(vg);
                        }
                    }
                    else if (item.SizeReference != null && item.SizeReference == MsgLength)
                    {
                        while (data.Length - GetTailSize(CommandDefinition) > index)
                        {
                            ParamValue vg = ParamValue.CreateParamValue(item);
                            vg.InnerValues = new List <ParamValue>();
                            foreach (var prm1 in item.Param1)
                            {
                                ParamValue innerParam = ProcessParameter(data, ref index, prm1, vg.InnerValues);
                                vg.InnerValues.Add(innerParam);
                                vg.ByteValueList.AddRange(innerParam.ByteValueList);
                            }
                            ret.InnerValues.Add(vg);
                            if (!string.IsNullOrEmpty(item.MoreToFollowReference) && !vg.IsIncluded(item.MoreToFollowReference))
                            {
                                break;
                            }
                        }
                    }
                    else if (item.SizeReference != null && item.SizeReference == MsgMarker)
                    {
                        byte[] marker = GetMarkerValue(item);
                        while (data.Length - GetTailSize(CommandDefinition) > index && !IsMarker(data, index, marker))
                        {
                            ParamValue vg = ParamValue.CreateParamValue(item);
                            vg.InnerValues = new List <ParamValue>();
                            foreach (var prm1 in item.Param1)
                            {
                                ParamValue innerParam = ProcessParameter(data, ref index, prm1, vg.InnerValues);
                                vg.InnerValues.Add(innerParam);
                                vg.ByteValueList.AddRange(innerParam.ByteValueList);
                            }
                            ret.InnerValues.Add(vg);
                        }
                    }
                    else if (item.SizeReference != null)
                    {
                        for (int i = 0; i < GetSize(item.SizeReference, vgParams); i++)
                        {
                            ParamValue vg = ParamValue.CreateParamValue(item);
                            vg.InnerValues = new List <ParamValue>();
                            foreach (var prm1 in item.Param1)
                            {
                                ParamValue innerParam = ProcessParameter(data, ref index, prm1, vg.InnerValues);
                                vg.InnerValues.Add(innerParam);
                                vg.ByteValueList.AddRange(innerParam.ByteValueList);
                            }
                            ret.InnerValues.Add(vg);
                        }
                    }
                    break;

                case ParamModes.Property:
                    ret.InnerValues = new List <ParamValue>();
                    byte bvalue = data.Length > index ? data[index++] : (byte)0;
                    ret.ByteValueList.Add(bvalue);
                    byte totalbits = 0;
                    foreach (var prm1 in item.Param1)
                    {
                        ParamValue sp = ParamValue.CreateParamValue(prm1);
                        sp.ByteValueList.Add((byte)(bvalue >> totalbits & Tools.GetMaskFromBits(prm1.Bits, 0)));
                        ret.InnerValues.Add(sp);
                        totalbits += prm1.Bits;
                    }
                    break;

                default:
                    byte bytesCount = GetParamValueBytes(item);
                    if (item.Size > 1)
                    {
                        for (int i = 0; i < item.Size; i++)
                        {
                            for (int j = 0; j < bytesCount; j++)
                            {
                                if (data.Length > index)
                                {
                                    ret.ByteValueList.Add(data[index++]);
                                }
                            }
                        }
                    }
                    else if (item.SizeReference != null && item.SizeReference == MsgLength)
                    {
                        if (data.Length > 1000)
                        {
                        }
                        while (data.Length - GetTailSize(CommandDefinition) > index)
                        {
                            for (int j = 0; j < bytesCount; j++)
                            {
                                if (data.Length > index)
                                {
                                    ret.ByteValueList.Add(data[index++]);
                                }
                            }
                        }
                    }
                    else if (item.SizeReference != null && item.SizeReference == MsgMarker)
                    {
                        byte[] marker = GetMarkerValue(item);
                        while (data.Length - GetTailSize(CommandDefinition) > index && !IsMarker(data, index, marker))
                        {
                            for (int j = 0; j < bytesCount; j++)
                            {
                                if (data.Length > index)
                                {
                                    ret.ByteValueList.Add(data[index++]);
                                }
                            }
                        }
                    }
                    else if (item.SizeReference != null)
                    {
                        for (int i = 0; i < GetSize(item.SizeReference, vgParams) + item.SizeChange; i++)
                        {
                            for (int j = 0; j < bytesCount; j++)
                            {
                                if (data.Length > index)
                                {
                                    ret.ByteValueList.Add(data[index++]);
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < bytesCount; j++)
                        {
                            if (data.Length > index)
                            {
                                ret.ByteValueList.Add(data[index++]);
                            }
                        }
                    }

                    if (item.Type == zwParamType.CMD_CLASS_REF && ret.ByteValueList != null && ret.ByteValueList.Count > 0)
                    {
                        _cmdClassRef = ZWaveDefinition.CommandClasses.FirstOrDefault(x => x.KeyId == ret.ByteValueList[0]);
                    }
                    else if (item.Type == zwParamType.CMD_REF && _cmdClassRef != null)
                    {
                        if (_cmdClassRef.Command != null && ret.ByteValueList != null && ret.ByteValueList.Count > 0)
                        {
                            _cmdRef = _cmdClassRef.Command.FirstOrDefault(x => x.KeyId == ret.ByteValueList[0]);
                        }
                    }
                    if (item.Type == zwParamType.CMD_DATA && _cmdClassRef != null && _cmdRef != null && ret.ByteValueList != null && ret.ByteValueList.Count > 0)
                    {
                        byte[] cmddata = new byte[ret.ByteValueList.Count + 2];
                        cmddata[0] = _cmdClassRef.KeyId;
                        cmddata[1] = _cmdRef.KeyId;
                        Array.Copy(ret.ByteValueList.ToArray(), 0, cmddata, 2, cmddata.Length - 2);
                        CommandClassValue[] encapCmds;

                        ZWaveDefinition.ParseApplicationObject(cmddata, out encapCmds);
                        ret.InnerValues = new List <ParamValue>();
                        if (encapCmds != null)
                        {
                            foreach (var ec in encapCmds)
                            {
                                if (encapCmds.Length > 1)
                                {
                                    ParamValue pv = new ParamValue
                                    {
                                        ParamDefinition           = item,
                                        ParamDefinitionTextSuffix = ", ver." + ec.CommandClassDefinition.Version,
                                        InnerValues = ec.CommandValue.ParamValues
                                    };
                                    ret.InnerValues.Add(pv);
                                }
                                else
                                {
                                    ret.InnerValues = ec.CommandValue.ParamValues;
                                }
                            }
                        }
                    }
                    if (item.Type == zwParamType.CMD_ENCAP && ret.ByteValueList != null && ret.ByteValueList.Count > 0)
                    {
                        byte[] cmddata = new byte[ret.ByteValueList.Count];
                        Array.Copy(ret.ByteValueList.ToArray(), 0, cmddata, 0, cmddata.Length);
                        CommandClassValue[] encapCmds;

                        ZWaveDefinition.ParseApplicationObject(cmddata, out encapCmds);
                        ret.InnerValues = new List <ParamValue>();
                        if (encapCmds != null)
                        {
                            foreach (var ec in encapCmds)
                            {
                                if (encapCmds.Length > 1)
                                {
                                    ParamValue pv = new ParamValue
                                    {
                                        ParamDefinitionTextPrefix = ec.CommandValue.CommandDefinition.Name,
                                        ParamDefinitionTextSuffix = ", ver." + ec.CommandClassDefinition.Version,
                                        InnerValues = ec.CommandValue.ParamValues
                                    };
                                    ret.InnerValues.Add(pv);
                                }
                                else
                                {
                                    ret.InnerValues = ec.CommandValue.ParamValues;
                                }
                            }
                        }
                    }
                    break;
                }
            }
            return(ret);
        }
Пример #4
0
 /// <summary>
 /// Returns ParamValues as dictionary
 /// </summary>
 /// <param name="isIncludeParentKey">dictionary key contains parent param key if 'true'. Example: "properties1.level"</param>
 /// <param name="useQualifiedParamNameAsKey">dictionary key contains parameter's 'Name' instead of parameter's 'Text' attribute if 'true'</param>
 /// <returns>dictionary</returns>
 public Dictionary <string, List <ParamValue> > ToParamValuesDictionary(bool isIncludeParentKey, bool useQualifiedParamNameAsKey)
 {
     return(ZWaveDefinition.ToParamValuesDictionary(ParamValues, isIncludeParentKey, useQualifiedParamNameAsKey));
 }
Пример #5
0
 public CommandValue(ZWaveDefinition zWaveDefinition)
 {
     ZWaveDefinition = zWaveDefinition;
     ParamValues     = new List <ParamValue>();
 }
Пример #6
0
 public static CommandClass FindCommandClass(this ZWaveDefinition zWaveDefinition, string name, byte version)
 {
     return(zWaveDefinition.CommandClasses.FirstOrDefault(var => var.Name == name && var.Version == version));
 }
Пример #7
0
        public static Command FindCommand(this ZWaveDefinition zWaveDefinition, string commandClassName, byte commandClassVersion, string name)
        {
            CommandClass cmdClass = FindCommandClass(zWaveDefinition, commandClassName, commandClassVersion);

            return(cmdClass.Command.FirstOrDefault(var => var.Name == name));
        }
Пример #8
0
 public static Command FindCommand(this ZWaveDefinition zWaveDefinition, CommandClass commandClass, string name)
 {
     return(commandClass.Command.FirstOrDefault(var => var.Name == name));
 }
Пример #9
0
 public static List <CommandClass> FindCommandClasses(this ZWaveDefinition zWaveDefinition, byte key)
 {
     return(zWaveDefinition.CommandClasses.Where(var => var.KeyId == key).ToList());
 }
Пример #10
0
 public static CommandClass FindCommandClass(this ZWaveDefinition zWaveDefinition, byte key, byte version)
 {
     return(zWaveDefinition.CommandClasses.FirstOrDefault(var => var.KeyId == key && var.Version == version));
 }