/// <summary> /// Load the extended parameters /// </summary> internal void LoadExtendedParameters(XPathDocument document) { XPathNavigator navigator = document.CreateNavigator(); foreach (XPathNavigator node in navigator.Select( "/logger/protocols/protocol/ecuparams/ecuparam/ecu[@id='" + this.EcuIdentifier + "']")) { node.MoveToFirstChild(); int address = SsmParameterSource.GetMemoryAddress(node); int length = SsmParameterSource.GetMemoryLength(node); node.MoveToParent(); node.MoveToParent(); string name = node.GetAttribute("name", ""); string id = node.GetAttribute("id", ""); XPathNodeIterator iterator = node.Select("conversions/conversion"); List <Conversion> conversions = SsmParameterSource.GetConversions(iterator); SsmParameter parameter = new SsmParameter( this, id, name, address, length, conversions.AsReadOnly()); // TODO: remove this when the duplicates in logger.xml are cleaned up if (!this.Parameters.Contains(parameter)) { this.AddParameter(parameter); } } }
/// <summary> /// Load the standard parameters /// </summary> internal void LoadStandardParameters(XPathDocument document) { XPathNavigator navigator = document.CreateNavigator(); foreach (XPathNavigator node in navigator.Select( "/logger/protocols/protocol/parameters/parameter")) { string id = node.GetAttribute("id", string.Empty); string name = node.GetAttribute("name", string.Empty); int byteIndex = SsmParameterSource.GetIndexFromAttribute(node, "ecubyteindex"); int bitIndex = SsmParameterSource.GetIndexFromAttribute(node, "ecubit"); XPathNodeIterator children = node.Select("address"); children.MoveNext(); int address = SsmParameterSource.GetMemoryAddress(children.Current); int length = SsmParameterSource.GetMemoryLength(children.Current); children.MoveNext(); children = node.Select("conversions/conversion"); List <Conversion> conversions = SsmParameterSource.GetConversions(children); children = node.Select("depends/ref"); ReadOnlyCollection <Parameter> dependencies = this.GetDependencies(children); if (this.EcuSupports(byteIndex, bitIndex)) { SsmParameter parameter = new SsmParameter( this, id, name, address, length, conversions.AsReadOnly(), byteIndex, bitIndex, dependencies); this.AddParameter(parameter); } else { Trace.WriteLine("Skipping parameter " + id + " / " + name); } } }
/// <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(); } } }
/// <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(); } }