Ejemplo n.º 1
0
 public static DeviceRegisterSet FromXml2DeviceRecordSet(string chipType, string chipRev, string descriptorResourceName, string descriptorResourcePath)
 {
     XmlNode node = null;
     XmlNode node2 = null;
     try
     {
         XmlDocument document = new XmlDocument();
         string path = Path.Combine(Path.Combine(Application.CommonAppDataPath, "WDS_Resources"), descriptorResourceName);
         if (File.Exists(path))
         {
             document.Load(path);
         }
         else
         {
             Assembly executingAssembly = Assembly.GetExecutingAssembly();
             executingAssembly.GetManifestResourceNames();
             Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(descriptorResourcePath + "." + descriptorResourceName);
             document.Load(manifestResourceStream);
         }
         document.PreserveWhitespace = false;
         DeviceRegisterSet set = new DeviceRegisterSet();
         foreach (XmlNode node3 in document.DocumentElement.SelectNodes("SPIDevice"))
         {
             if ((node3.Attributes.GetNamedItem("type").Value == chipType) && (node3.Attributes.GetNamedItem("revision").Value == chipRev))
             {
                 node = node3;
                 set = new DeviceRegisterSet {
                     ChipID = Convert.ToInt32(node3.Attributes.GetNamedItem("chipID").Value),
                     Name = node3.Attributes.GetNamedItem("name").Value,
                     Type = node3.Attributes.GetNamedItem("type").Value,
                     Revision = node3.Attributes.GetNamedItem("revision").Value,
                     ProjectID = node3.Attributes.GetNamedItem("projectID").Value,
                     TxPufferSize = Convert.ToInt32(node3.SelectSingleNode("TxPufferSize").InnerText),
                     RxPufferSize = Convert.ToInt32(node3.SelectSingleNode("RxPufferSize").InnerText),
                     TxPufferAddress = (node3.SelectSingleNode("TxPufferAddress").InnerText != "") ? Convert.ToInt32(node3.SelectSingleNode("TxPufferAddress").InnerText, 0x10) : 0,
                     RxPufferAddress = (node3.SelectSingleNode("RxPufferAddress").InnerText != "") ? Convert.ToInt32(node3.SelectSingleNode("RxPufferAddress").InnerText, 0x10) : 0,
                     NffsControl = (node3.SelectSingleNode("nFFS_control").InnerText == "0") ? false : true
                 };
                 foreach (XmlNode node4 in node3.SelectNodes("Register"))
                 {
                     node2 = node4;
                     DeviceRegister item = new DeviceRegister {
                         Address = Convert.ToInt32(node4.Attributes.GetNamedItem("address").Value, 0x10),
                         Name = node4.Attributes.GetNamedItem("name").Value,
                         Size = Convert.ToInt32(node4.Attributes.GetNamedItem("size").Value)
                     };
                     string str = node4.Attributes.GetNamedItem("defaultVal").Value.Replace(" ", "");
                     item.DefaultValue = (str != "-") ? Convert.ToInt32(str, 0x10) : 0;
                     item.CurrentValue = item.DeviceValue = item.DefaultValue;
                     item.IsRead = Convert.ToBoolean(Convert.ToInt32(node4.Attributes.GetNamedItem("isRead").Value));
                     item.IsWrite = Convert.ToBoolean(Convert.ToInt32(node4.Attributes.GetNamedItem("isWrite").Value));
                     if (node4.Attributes.GetNamedItem("isMarked") != null)
                     {
                         item.IsMarked = Convert.ToBoolean(Convert.ToInt32(node4.Attributes.GetNamedItem("isMarked").Value));
                     }
                     else
                     {
                         item.IsMarked = false;
                     }
                     DeviceRegisterClassification classification = new DeviceRegisterClassification {
                         IsTest = Convert.ToBoolean(Convert.ToInt32(node4.SelectSingleNode("Classification").Attributes.GetNamedItem("isTestReg").Value)),
                         IsRF = Convert.ToBoolean(Convert.ToInt32(node4.SelectSingleNode("Classification").Attributes.GetNamedItem("isRFReg").Value)),
                         IsDigital = Convert.ToBoolean(Convert.ToInt32(node4.SelectSingleNode("Classification").Attributes.GetNamedItem("isDigitalReg").Value)),
                         IsMisc = Convert.ToBoolean(Convert.ToInt32(node4.SelectSingleNode("Classification").Attributes.GetNamedItem("isMiscReg").Value)),
                         IsStatus = Convert.ToBoolean(Convert.ToInt32(node4.SelectSingleNode("Classification").Attributes.GetNamedItem("isStatusReg").Value))
                     };
                     XmlNode namedItem = node4.SelectSingleNode("Classification").Attributes.GetNamedItem("isAconfig");
                     if (namedItem != null)
                     {
                         classification.IsAConfig = Convert.ToBoolean(Convert.ToInt32(namedItem.Value));
                     }
                     item.RegClass = classification;
                     foreach (XmlNode node6 in node4.SelectNodes("Bit"))
                     {
                         DeviceRegisterBit bit = new DeviceRegisterBit {
                             BitIdx = Convert.ToInt32(node6.Attributes.GetNamedItem("index").Value),
                             Name = node6.Attributes.GetNamedItem("name").Value
                         };
                         item.Bits.Add(bit);
                     }
                     item.Description = node4.LastChild.InnerText;
                     set.Registers.Add(item);
                 }
                 return set;
             }
         }
         return null;
     }
     catch (Exception exception)
     {
         MessageBox.Show("XML Reading error! \n The " + descriptorResourceName + " XML File is not supported!\n" + exception.Message + "\n\rDevice: " + ((node == null) ? "" : node.Attributes.GetNamedItem("type").Value) + " ChipID: " + ((node == null) ? "" : node.Attributes.GetNamedItem("chipID").Value) + " Register: " + ((node2 == null) ? "" : node2.Attributes.GetNamedItem("address").Value));
         return null;
     }
 }
Ejemplo n.º 2
0
 public void RestoreRegister(XmlNode root, DeviceRegisterSet myDev)
 {
     XmlDocument ownerDocument = root.OwnerDocument;
     XmlNodeList list = root.SelectNodes("SPIDevice");
     for (int i = 0; i < list.Count; i++)
     {
         if (list[i].Attributes.GetNamedItem("type").Value.ToString() == myDev.Type)
         {
             XmlNode node = list[i];
             DeviceRegisterSet set = new DeviceRegisterSet {
                 ChipID = Convert.ToInt32(node.Attributes.GetNamedItem("chipID").Value),
                 Name = node.Attributes.GetNamedItem("name").Value,
                 Type = node.Attributes.GetNamedItem("type").Value,
                 Revision = node.Attributes.GetNamedItem("revision").Value,
                 ProjectID = node.Attributes.GetNamedItem("projectID").Value
             };
             if (node.Attributes.GetNamedItem("note") != null)
             {
                 set.Notes = node.Attributes.GetNamedItem("note").Value;
             }
             set.TxPufferSize = Convert.ToInt32(node.SelectSingleNode("TxPufferSize").InnerText);
             set.RxPufferSize = Convert.ToInt32(node.SelectSingleNode("RxPufferSize").InnerText);
             set.TxPufferAddress = (node.SelectSingleNode("TxPufferAddress").InnerText != "") ? Convert.ToInt32(node.SelectSingleNode("TxPufferAddress").InnerText, 0x10) : 0;
             set.RxPufferAddress = (node.SelectSingleNode("RxPufferAddress").InnerText != "") ? Convert.ToInt32(node.SelectSingleNode("RxPufferAddress").InnerText, 0x10) : 0;
             set.NffsControl = node.SelectSingleNode("nFFS_control").InnerText != "0";
             foreach (XmlNode node2 in node.SelectNodes("Register"))
             {
                 DeviceRegister item = new DeviceRegister {
                     Address = Convert.ToInt32(node2.Attributes.GetNamedItem("address").Value, 0x10),
                     Name = node2.Attributes.GetNamedItem("name").Value,
                     Size = Convert.ToInt32(node2.Attributes.GetNamedItem("size").Value),
                     DefaultValue = (node2.Attributes.GetNamedItem("defaultVal").Value != "-") ? Convert.ToInt32(node2.Attributes.GetNamedItem("defaultVal").Value, 0x10) : -1
                 };
                 if ((node2.Attributes.GetNamedItem("currentVal") != null) && (node2.Attributes.GetNamedItem("currentVal").Value != "-"))
                 {
                     item.CurrentValue = Convert.ToInt32(node2.Attributes.GetNamedItem("currentVal").Value, 0x10);
                 }
                 else
                 {
                     item.CurrentValue = item.DefaultValue;
                 }
                 item.DeviceValue = item.DefaultValue;
                 item.IsRead = Convert.ToBoolean(Convert.ToInt32(node2.Attributes.GetNamedItem("isRead").Value));
                 item.IsWrite = Convert.ToBoolean(Convert.ToInt32(node2.Attributes.GetNamedItem("isWrite").Value));
                 if (node2.Attributes.GetNamedItem("isMarked") != null)
                 {
                     item.IsMarked = Convert.ToBoolean(Convert.ToInt32(node2.Attributes.GetNamedItem("isMarked").Value));
                 }
                 else
                 {
                     item.IsMarked = false;
                 }
                 DeviceRegisterClassification classification = new DeviceRegisterClassification {
                     IsTest = Convert.ToBoolean(Convert.ToInt32(node2.SelectSingleNode("Classification").Attributes.GetNamedItem("isTestReg").Value)),
                     IsRF = Convert.ToBoolean(Convert.ToInt32(node2.SelectSingleNode("Classification").Attributes.GetNamedItem("isRFreg").Value)),
                     IsDigital = Convert.ToBoolean(Convert.ToInt32(node2.SelectSingleNode("Classification").Attributes.GetNamedItem("isDigitalReg").Value)),
                     IsMisc = Convert.ToBoolean(Convert.ToInt32(node2.SelectSingleNode("Classification").Attributes.GetNamedItem("isMiscReg").Value)),
                     IsStatus = Convert.ToBoolean(Convert.ToInt32(node2.SelectSingleNode("Classification").Attributes.GetNamedItem("isStatusReg").Value))
                 };
                 XmlNode namedItem = node2.SelectSingleNode("Classification").Attributes.GetNamedItem("isAconfig");
                 if (namedItem != null)
                 {
                     classification.IsAConfig = Convert.ToBoolean(Convert.ToInt32(namedItem.Value));
                 }
                 item.RegClass = classification;
                 foreach (XmlNode node4 in node2.SelectNodes("Bit"))
                 {
                     DeviceRegisterBit bit = new DeviceRegisterBit {
                         BitIdx = Convert.ToInt32(node4.Attributes.GetNamedItem("index").Value),
                         Name = node4.Attributes.GetNamedItem("name").Value
                     };
                     item.Bits.Add(bit);
                 }
                 item.Description = node2.LastChild.InnerText;
                 set.Registers.Add(item);
             }
             myDev = set;
             return;
         }
     }
 }