예제 #1
0
        /// <summary>
        /// Constructor, reading the dataflash configuration file.
        /// </summary>
        /// <param name="bcfgxPath">Full path to dataflash configuration file.</param>
        public BcfgItems(string bcfgxPath)
        {
            string  s = string.Empty;
            bool    b = false;
            int     n = 0;
            double  d = 0;
            XmlNode singleNode;

            try
            {
                using (FileStream sbcfgx = new FileStream(bcfgxPath, FileMode.Open))
                {
                    XmlDocument bcfgx = new XmlDocument();
                    bcfgx.Load(sbcfgx);

                    #region bcfgInfo
                    XmlNodeList info = bcfgx.DocumentElement.SelectNodes("/bcfg/bcfgInfo");
                    foreach (XmlNode node in info)
                    {
                        singleNode = node.SelectSingleNode("bcfgxBaseAddr");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    bcfgBaseAddr = Convert.ToInt32(s, 16);
                                }
                                else
                                {
                                    int.TryParse(s, out bcfgBaseAddr);
                                }
                            }
                        }
                    }
                    #endregion

                    #region bcfgItem
                    XmlNodeList items = bcfgx.DocumentElement.SelectNodes("/bcfg/bcfgItem");
                    bcfgItems = new List <BcfgItem>(items.Count);
                    s         = null;

                    foreach (XmlNode node in items)
                    {
                        BcfgItem i = new BcfgItem();
                        singleNode = node.SelectSingleNode("class");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.Class = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("subclass");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.Subclass = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("caption");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.Caption = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("offset");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            n = 0;
                            if (s != null)
                            {
                                if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    n = Convert.ToInt32(s, 16);
                                }
                                else
                                {
                                    int.TryParse(s, out n);
                                }
                                i.OffsetWithinDataflash = n;
                            }
                        }

                        singleNode = node.SelectSingleNode("length");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            n = 0;
                            if (s != null)
                            {
                                if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    n = Convert.ToInt32(s, 16);
                                }
                                else
                                {
                                    int.TryParse(s, out n);
                                }
                                i.LengthWithinDataflash = n;
                            }
                        }

                        singleNode = node.SelectSingleNode("readformula");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.ReadFormula = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("writeformula");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.WriteFormula = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("unit");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.Unit = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("munit");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.MUnit = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("displaytype");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.DisplayFormat = s.Trim().ToLower();
                            }
                        }

                        singleNode = node.SelectSingleNode("default");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            d = 0.0;
                            if (s != null)
                            {
                                if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    d = Convert.ToInt32(s, 16);
                                }
                                else
                                {
                                    double.TryParse(s, out d);
                                }
                                i.DefaultValue = d;
                            }
                        }

                        singleNode = node.SelectSingleNode("min");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            d = 0.0;
                            if (s != null)
                            {
                                if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    d = Convert.ToInt32(s, 16);
                                }
                                else
                                {
                                    double.TryParse(s, out d);
                                }
                                i.MinValue = d;
                            }
                        }

                        singleNode = node.SelectSingleNode("max");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            d = 0.0;
                            if (s != null)
                            {
                                if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    d = Convert.ToInt32(s, 16);
                                }
                                else
                                {
                                    double.TryParse(s, out d);
                                }
                                i.MaxValue = d;
                            }
                        }

                        singleNode = node.SelectSingleNode("datatype");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                i.DataType = s.Trim();
                            }
                        }

                        singleNode = node.SelectSingleNode("isbitfield");
                        if (singleNode != null)
                        {
                            s = singleNode.InnerText;
                            if (s != null)
                            {
                                bool.TryParse(s, out b);
                                i.IsBitfield = b;
                            }
                        }

                        if (i.IsBitfield)
                        {
                            XmlNodeList bits = node.SelectSingleNode("fields").ChildNodes;
                            i.SbsBitItems = new List <SbsBitItem>(bits.Count);
                            foreach (XmlNode bit in bits)
                            {
                                SbsBitItem bi = new SbsBitItem();
                                n             = 0;
                                bi.SbsCaption = bi.SbsBitDescription = bit.InnerText;
                                s             = bit.Name.Substring(3);
                                if (s != null)
                                {
                                    int.TryParse(s, out n);
                                }
                                bi.SbsBitPosition = n;
                                bi.SbsBitValue    = 0;
                                i.SbsBitItems.Add(bi);
                            }
                        }
                        bcfgItems.Add(i);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Constructor, reading the device configuration file.
        /// </summary>
        /// <param name="bqzPath">Full path to configuration file.</param>
        public SbsItems(string bqzPath)
        {
            string  s = string.Empty;
            bool    b = false;
            int     n = 0;
            XmlNode singleNode;

            try
            {
                using (ZipArchive archive = ZipFile.OpenRead(bqzPath))
                {
                    #region default.sbsx
                    ZipArchiveEntry e = archive.GetEntry(@"sbs/default.sbsx");
                    using (Stream sbsx = e.Open())
                    {
                        XmlDocument sbs = new XmlDocument();
                        sbs.Load(sbsx);

                        #region sbsInfo
                        XmlNodeList info = sbs.DocumentElement.SelectNodes("/sbs/sbsInfo");
                        foreach (XmlNode node in info)
                        {
                            singleNode = node.SelectSingleNode("targetAddress");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        targetAdress = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out targetAdress);
                                    }
                                }
                            }

                            singleNode = node.SelectSingleNode("targetEndianess");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        targetEndianess = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out targetEndianess);
                                    }
                                }
                            }

                            singleNode = node.SelectSingleNode("mac");
                            if (singleNode != null)
                            {
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        mac = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out mac);
                                    }
                                }
                            }

                            singleNode = node.SelectSingleNode("SMB_NewMacCMD");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        targetMacAddress = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out targetMacAddress);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region sbsItem
                        XmlNodeList items = sbs.DocumentElement.SelectNodes("/sbs/sbsItem");
                        sbsRegister = new List <SbsRegisterItem>(items.Count);
                        s           = null;

                        foreach (XmlNode node in items)
                        {
                            SbsRegisterItem i = new SbsRegisterItem();
                            singleNode = node.SelectSingleNode("caption");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Caption = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("logcaption");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.LogCaption = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("isstatic");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsStatic = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("isvisible");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsVisible = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("ismac");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsMac = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("readstyle");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.ReadStyle = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("offsetwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.OffsetWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("lengthwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.LengthWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("length");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Length = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("command");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Command = (short)n;
                                }
                            }

                            singleNode = node.SelectSingleNode("readformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.ReadFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("writeformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.WriteFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("writable");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.Writable = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("unit");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Unit = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("displayformat");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.DisplayFormat = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("mreadformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.MReadFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("mwriteformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.MWriteFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("munit");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.MUnit = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("isbitfield");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsBitfield = b;
                                }
                            }

                            if (i.IsBitfield)
                            {
                                XmlNodeList bits = node.SelectSingleNode("fields").ChildNodes;
                                i.SbsBitItems = new List <SbsBitItem>(bits.Count);
                                foreach (XmlNode bit in bits)
                                {
                                    SbsBitItem bi = new SbsBitItem();
                                    n             = 0;
                                    bi.SbsCaption = bi.SbsBitDescription = bit.InnerText;
                                    s             = bit.Name.Substring(3);
                                    if (s != null)
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    bi.SbsBitPosition = n;
                                    bi.SbsBitValue    = 0;
                                    i.SbsBitItems.Add(bi);
                                }
                            }

                            sbsRegister.Add(i);
                        }
                        #endregion
                    }
                    #endregion

                    #region commands.xml
                    e = archive.GetEntry(@"toolcustomization/commands.xml");
                    using (Stream strm = e.Open())
                    {
                        XmlDocument xml = new XmlDocument();
                        xml.Load(strm);

                        #region Commands
                        XmlNodeList items = xml.DocumentElement.SelectNodes("/commands/commandItem");
                        sbsCommands = new List <SbsCommandItem>(items.Count);
                        s           = null;

                        foreach (XmlNode node in items)
                        {
                            SbsCommandItem i = new SbsCommandItem();
                            singleNode = node.SelectSingleNode("caption");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Caption = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("description");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Description = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("result");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.HasResult = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("sealedaccess");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.SealedAccess = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("private");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsPrivate = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("databigendian");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsBigEndian = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("writestyle");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.WriteStyle = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("offsetwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.OffsetWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("lengthwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.LengthWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("length");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Length = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("writevalue");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Command = (short)n;
                                }
                            }

                            singleNode = node.SelectSingleNode("delayms");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Delayms = n;
                                }
                            }

                            sbsCommands.Add(i);
                        }
                        #endregion
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }