internal void ProcessParameters(byte[] data, byte initialOffsetInData) { ParamValues.Clear(); _cmdClassRef = null; _cmdRef = null; int index = 0; if (CommandDefinition.Param == null) { return; } foreach (var item in CommandDefinition.Param) { ParamValue pv = ProcessParameter(data, ref index, item, null); if (item.Mode == ParamModes.VariantGroup && pv.InnerValues != null && pv.InnerValues.Count > 0) { for (int i = 0; i < pv.InnerValues.Count; i++) { pv.InnerValues[i].ParamDefinitionTextSuffix = " " + (i + 1); ParamValues.Add(pv.InnerValues[i]); } } else { ParamValues.Add(pv); } } }
public static ParamValue CreateParamValue(Param item) { ParamValue ret = new ParamValue { ByteValueList = new List <byte>(), TextValueList = new List <string>(), ParamDefinition = item }; return(ret); }
private byte GetSize(string sizeRef, IList <ParamValue> vgParams) { byte ret = 0; string[] tokens = sizeRef.Split('.'); bool inParent = false; if (sizeRef.StartsWith("Parent.")) { tokens = sizeRef.Substring(7).Split('.'); inParent = true; } ParamValue p; if (vgParams == null || inParent) { p = ParamValues.FirstOrDefault(x => x.ParamDefinition.Name == tokens[0]); } else { p = vgParams.FirstOrDefault(x => x.ParamDefinition.Name == tokens[0]); } if (p != null) { if (tokens.Length == 2) { ParamValue s = p.InnerValues.FirstOrDefault(x => x.ParamDefinition.Name == tokens[1]); if (s != null) { if (s.ByteValueList.Count > 0) { ret = s.ByteValueList[0]; } } } else { if (p.ByteValueList.Count > 0) { ret = p.ByteValueList[0]; } } } return(ret); }
private byte GetByteValue(string optRef) { byte ret = 0; string[] tokens = optRef.Split('.'); int refLevel = 0; if (tokens[0] == ParamDefinition.Name) { refLevel++; } ParamValue p = InnerValues.FirstOrDefault(x => x.ParamDefinition.Name == tokens[refLevel]); if (p != null) { if (tokens.Length > refLevel) { refLevel++; if (p.ParamDefinition.Mode == ParamModes.Property) { ParamValue s = p.InnerValues.FirstOrDefault(x => x.ParamDefinition.Name == tokens[refLevel]); if (s != null) { ret = s.ByteValueList[0]; } } else { ret = p.ByteValueList[0]; } } else { ret = p.ByteValueList[0]; } } return(ret); }
private IEnumerable <byte> GetBytesValue(string optRef) { IEnumerable <byte> ret = null; string[] tokens = optRef.Split('.'); ParamValue p = ParamValues.FirstOrDefault(x => x.ParamDefinition.Name == tokens[0]); if (p != null) { if (tokens.Length == 2) { ParamValue s = p.InnerValues.FirstOrDefault(x => x.ParamDefinition.Name == tokens[1]); if (s != null) { ret = s.ByteValueList; } } else { ret = p.ByteValueList; } } return(ret); }
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); }
private void ProcessParametersTextValue(IEnumerable <ParamValue> paramValues, CommandClass cmdClass) { ParamValue prevParamValue = null; foreach (var item in paramValues) { if (item.HasTextValue) { break; } if (item.InnerValues != null) { ProcessParametersTextValue(item.InnerValues, cmdClass); } if (item.ParamDefinition != null) { if (item.ParamDefinition.Defines != null && cmdClass.DefineSet != null) { Collection <Define> defines = null; DefineSet dSet = cmdClass.DefineSet.FirstOrDefault(x => x.Name == item.ParamDefinition.Defines); if (dSet != null) { defines = dSet.Define; bool isMultiarray = dSet.Define.Aggregate(true, (current, d) => current & d.Define1 != null); if (isMultiarray && prevParamValue != null) { if (prevParamValue.ByteValueList != null && prevParamValue.ByteValueList.Count > 0) { var d = dSet.Define.FirstOrDefault(x => x.KeyId == prevParamValue.ByteValueList[0]); if (d != null) { defines = d.Define1; } } } } IEnumerable <string> range = ParameterToString(item.ByteValueList, item.ParamDefinition.Type, defines); foreach (var str in range) { item.TextValueList.Add(str); item.HasTextValue = true; } } else { var paramType = item.ParamDefinition != null ? item.ParamDefinition.Type : zwParamType.HEX; IEnumerable <string> range = ParameterToString(item.ByteValueList, paramType, null); foreach (var str in range) { item.TextValueList.Add(str); item.HasTextValue = true; } } } else { var paramType = item.ParamDefinition != null ? item.ParamDefinition.Type : zwParamType.HEX; IEnumerable <string> range = ParameterToString(item.ByteValueList, paramType, null); foreach (var str in range) { item.TextValueList.Add(str); item.HasTextValue = true; } } prevParamValue = item; } }