Esempio n. 1
0
        /// <summary>
        /// Get the address & length from an address element
        /// </summary>
        /// <exception cref="IOException">Unable to read from source stream</exception>
        /// <exception cref="InvalidDataException">Source document is corrupt</exception>
        private static void GetAddress(XmlReader reader, ref int address, ref int length)
        {
            reader.Read();
            string addressString = reader.Value;

            address = SsmParameterSource.GetAddress(addressString);
            string lengthString = reader.GetAttribute("length");

            length = GetInteger(lengthString, 1);

            int depth = reader.Depth;

            SsmParameterSource.ReadUntil(
                reader,
                delegate
            {
                return(reader.Depth >= depth);
            },
                "Did not expect EOF after address element");
        }
Esempio n. 2
0
        /// <summary>
        /// Use XmlReader to load extended parameters
        /// </summary>
        /// <exception cref="IOException">Unable to read from source stream</exception>
        /// <exception cref="InvalidDataException">Source document is corrupt</exception>
        internal void LoadExtendedParameters(XmlReader reader)
        {
            while (!reader.EOF)
            {
                if (!reader.ReadToFollowing("ecuparam"))
                {
                    return;
                }

                string id   = reader.GetAttribute("id");
                string name = reader.GetAttribute("name");

                int depth = reader.Depth;
                reader.Read();
                for (; ;)
                {
                    if (reader.EOF)
                    {
                        return;
                    }
                    if (reader.Depth < depth)
                    {
                        break;
                    }
                    if (reader.IsStartElement("ecu"))
                    {
                        depth = reader.Depth;
                        string ecuId   = reader.GetAttribute("id");
                        int    address = 0;
                        int    length  = 0;

                        if (ecuId == this.EcuIdentifier)
                        {
                            reader.Read();
                            SsmParameterSource.ReadUntil(
                                reader,
                                delegate
                            {
                                return(reader.IsStartElement());
                            },
                                "Expected address element after ecu element");

                            SsmParameterSource.GetAddress(reader, ref address, ref length);

                            if (!reader.ReadToFollowing("conversion"))
                            {
                                throw new InvalidDataException("Invalid XML: expected conversion element after ecuparam element");
                            }

                            List <Conversion> conversions = new List <Conversion>();
                            SsmParameterSource.GetConversions(reader, conversions);

                            SsmParameter parameter = new SsmParameter(
                                this,
                                id,
                                name,
                                address,
                                length,
                                conversions.AsReadOnly());
                            this.AddParameter(parameter);
                            break;
                        }
                    }
                    reader.Read();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Load standard parameters with the XmlReader method
        /// </summary>
        /// <remarks>
        /// TODO: stop at the end of the parameters element, so the stream rewind won't be necessary
        /// </remarks>
        /// <exception cref="IOException">Unable to read from source stream</exception>
        /// <exception cref="InvalidDataException">Source document is corrupt</exception>
        internal void LoadStandardParameters(XmlReader reader)
        {
            while (!reader.EOF)
            {
                if (!reader.ReadToFollowing("parameter"))
                {
                    return;
                }

                //string elementName = reader.LocalName;
                string id         = reader.GetAttribute("id");
                string name       = reader.GetAttribute("name");
                string byteString = reader.GetAttribute("ecubyteindex");
                string bitString  = reader.GetAttribute("ecubit");
                int    byteIndex  = GetInteger(byteString, 0);
                int    bitIndex   = GetInteger(bitString, 0);
                int    address    = 0;
                int    length     = 0;

                ReadOnlyCollection <Parameter> dependencies = null;

                reader.Read();
                SsmParameterSource.ReadUntil(
                    reader,
                    delegate
                {
                    return(reader.IsStartElement());
                },
                    "Expected address element after parameter element");

                if (reader.IsStartElement("address"))
                {
                    SsmParameterSource.GetAddress(reader, ref address, ref length);
                }
                else if (reader.IsStartElement("depends"))
                {
                    List <Parameter> dependencyList = new List <Parameter>();
                    if (reader.ReadToDescendant("ref"))
                    {
                        while (reader.IsStartElement("ref"))
                        {
                            string dependencyId = reader.GetAttribute("parameter");
                            foreach (Parameter candidate in this.Parameters)
                            {
                                if (candidate.Id == dependencyId)
                                {
                                    dependencyList.Add(candidate);
                                    break;
                                }
                            }

                            if (!reader.ReadToNextSibling("ref"))
                            {
                                break;
                            }
                        }
                        if (dependencyList.Count > 0)
                        {
                            dependencies = dependencyList.AsReadOnly();
                        }
                        else
                        {
                            dependencies = null;
                        }
                    }
                    else
                    {
                        throw new InvalidDataException("XML schema doesn't match expectations. Parameter \"" + name + "\" has depends but not ref");
                    }
                }
                else
                {
                    throw new InvalidDataException("XML schema doesn't match expectations. Parameter \"" + name + "\" not followed by address or depends");
                }

                if (!reader.ReadToFollowing("conversion"))
                {
                    throw new InvalidDataException("XML schema doesn't match expectations (expected conversions node after address node, found " + reader.Name + ")");
                }

                List <Conversion> conversions = new List <Conversion>();
                SsmParameterSource.GetConversions(reader, conversions);

                SsmParameter parameter = new SsmParameter(
                    this,
                    id,
                    name,
                    address,
                    length,
                    conversions.AsReadOnly(),
                    byteIndex,
                    bitIndex,
                    dependencies.Count == 0 ? null : dependencies);
                this.AddParameter(parameter);
                reader.Read();
            }
        }