private string[] getByteRepresentationOfFields(ChipProperty property) { string[] strArray = new string[8]; try { if (property.Fields.Count > 0) { foreach (ByteField field in property.Fields) { int lsbPosition = field.LsbPosition; for (int j = 0; lsbPosition < (field.LsbPosition + field.Size); j++) { strArray[lsbPosition] = field.Name + ((field.Size > 1) ? j.ToString() : ""); lsbPosition++; } } for (int i = 0; i < strArray.Length; i++) { if (strArray[i] == null) { strArray[i] = "-"; } } } else { for (int k = 0; k < strArray.Length; k++) { strArray[k] = "bit" + k.ToString(); } } return strArray; } catch { return strArray; } }
public void createDescriptorFromXML(string chipType, string chipRev) { try { string str = chipType; string str2 = chipRev; if (((((str == "Si4060") || (str == "Si4063")) || ((str == "Si4362") || (str == "Si4438"))) || (((str == "Si4460") || (str == "Si4461")) || ((str == "Si4463") || (str == "Si4464")))) && (str2 == "B1")) { str = "Si4460"; } Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NewWDS.Applications.App_SPI_Tool_Pro2.ChipAPIDescriptor.xml"); XmlDocument document = new XmlDocument(); document.Load(manifestResourceStream); foreach (XmlNode node in document.GetElementsByTagName("CHIP")) { if ((node.Attributes.GetNamedItem("type").Value == str) && (node.Attributes.GetNamedItem("revision").Value == str2)) { XmlNodeList list2 = node.SelectNodes("COMMAND"); int num = 0; foreach (XmlNode node2 in list2) { ChipCommand item = new ChipCommand(); if (node2.Attributes.GetNamedItem("internal") != null) { item.Internal = node2.Attributes.GetNamedItem("internal").Value == "1"; } item.Name = node2.Attributes.GetNamedItem("name").Value; if (node2.Attributes.GetNamedItem("feature") != null) { item.Feature = node2.Attributes.GetNamedItem("feature").Value; } else { item.Feature = "common"; } if (!this.USER_PART_FEATURE_MAP[chipType].Contains(item.Feature)) { continue; } item.CmdID = ushort.Parse(node2.Attributes.GetNamedItem("value").Value.Replace("0x", ""), NumberStyles.HexNumber); XmlNodeList list3 = node2.SelectNodes("INPUT_DETAILS/PARAMETER"); int num2 = 0; foreach (XmlNode node4 in list3) { switch (node4.Attributes.GetNamedItem("type").Value) { case "u8": num2++; break; case "u16": num2 += 2; break; case "u24": num2 += 3; break; case "u32": num2 += 4; break; case "u40": num2 += 5; break; case "u48": num2 += 6; break; case "u56": num2 += 7; break; case "u64": num2 += 8; break; default: num2++; break; } } item.NumberOfParameters = num2; if (item.Name.Contains("SET") && item.Name.Contains("PROPERTY")) { this._setPropertyCommandId = item.CmdID; } if (item.Name.Contains("GET") && item.Name.Contains("PROPERTY")) { this._getPropertyCommandId = item.CmdID; } if (item.Name.Contains("POKE")) { this._pokeCommandId = item.CmdID; } if (item.Name.Contains("PEEK")) { this._peekCommandId = item.CmdID; } item.DefaultValues = item.CurrentValues = item.DeviceValues = new byte[item.NumberOfParameters]; if (node2.SelectSingleNode("DESCRIPTION") != null) { item.Description = node2.SelectSingleNode("DESCRIPTION").InnerText; } else { item.Description = node2.SelectSingleNode("SUMMARY").InnerText; } item.Enabled = item.Feature == "common"; XmlNodeList list4 = node2.SelectNodes("OUTPUT_DETAILS/REPLY"); int num3 = 0; foreach (XmlNode node5 in list4) { switch (node5.Attributes.GetNamedItem("type").Value) { case "u8": num3++; break; case "u16": num3 += 2; break; case "u24": num3 += 3; break; case "u32": num3 += 4; break; case "u40": num3 += 5; break; case "u48": num3 += 6; break; case "u56": num3 += 7; break; case "u64": num3 += 8; break; default: num3++; break; } } item.NumberOfReplyData = num3; string name = item.Name; if (name == null) { goto Label_06AD; } if (!(name == "SET_PROPERTY")) { if (name == "PEEK") { goto Label_068F; } if (name == "POKE") { goto Label_0699; } if ((name == "READ_DATA_BUFFER") || (name == "WRITE_DATA_BUFFER")) { goto Label_06A3; } goto Label_06AD; } item.MinNumberOfInputData = 4; goto Label_06BB; Label_068F: item.MinNumberOfInputData = 2; goto Label_06BB; Label_0699: item.MinNumberOfInputData = 3; goto Label_06BB; Label_06A3: item.MinNumberOfInputData = 4; goto Label_06BB; Label_06AD: item.MinNumberOfInputData = item.NumberOfParameters; Label_06BB: item.Index = num; item.IsMarked = false; this._commands.Add(item); num++; } num = 0; foreach (XmlNode node6 in node.SelectNodes("PROPERTY")) { ChipProperty property = new ChipProperty(); if (node6.Attributes.GetNamedItem("internal") != null) { property.Internal = node6.Attributes.GetNamedItem("internal").Value == "1"; } property.Name = node6.Attributes.GetNamedItem("group").Value + "_" + node6.Attributes.GetNamedItem("name").Value; if (node6.Attributes.GetNamedItem("feature") != null) { property.Feature = node6.Attributes.GetNamedItem("feature").Value; } else { property.Feature = "common"; } if (this.USER_PART_FEATURE_MAP[chipType].Contains(property.Feature)) { property.PropID = ushort.Parse(node6.Attributes.GetNamedItem("value").Value, NumberStyles.Integer); property.NumberOfParameters = 1; property.DefaultValues = property.CurrentValues = property.DeviceValues = new byte[] { byte.Parse(node6.Attributes.GetNamedItem("default").Value.Replace("0x", ""), NumberStyles.HexNumber) }; foreach (XmlNode node8 in node6.SelectNodes("DESCRIPTION")) { property.Description = property.Description + node8.InnerText + "\n"; } XmlNodeList list6 = node6.SelectNodes("FIELD"); if (list6.Count == 0) { list6 = node6.SelectNodes("BYTE/FIELD"); } foreach (XmlNode node9 in list6) { ByteField field = new ByteField { Name = node9.Attributes.GetNamedItem("name").Value, LsbPosition = short.Parse(node9.Attributes.GetNamedItem("lsb").Value), Size = short.Parse(node9.Attributes.GetNamedItem("size").Value) }; if (node9.SelectNodes("ENUMERATION/DESCRIPTION").Count > 0) { field.Description = node9.SelectNodes("ENUMERATION/DESCRIPTION")[0].InnerText; } else if (node9.SelectNodes("DESCRIPTION").Count > 0) { field.Description = node9.SelectNodes("DESCRIPTION")[0].InnerText; } else { field.Description = string.Empty; } property.Fields.Add(field); } property.Enabled = true; property.Index = num; property.IsMarked = false; this._properties.Add(property); num++; } } } } } catch (Exception exception) { _log.Error("Error at API description load from XML! " + exception.Message); } }