/// <summary> /// Parse all elements inside a <PIDSensor>-element (level 3 or deeper) /// </summary> /// <param name="xmlNodes">XML element containing the tree of PIDSensor-data</param> /// <param name="Mode">ELM mode in which this element resides.</param> /// <returns></returns> public PIDSensor parsePossibleSensorList(XElement xmlTree, int Mode, PIDSensor parent = null) { var PID = int.Parse(xmlTree.Attribute("PID").Value.ToString(), NumberStyles.HexNumber); var bytes = int.Parse(xmlTree.Attribute("bytes").Value.ToString(), NumberStyles.HexNumber); var description = xmlTree.Attribute("Description").Value.ToString(); // Formula attribute can be empty, so we first need to check it before parsing. var s_formulaAttribute = xmlTree.Attribute("Formula"); PIDSensor currentSensor; if (s_formulaAttribute == null) { currentSensor = new PIDSensor(Mode, PID, bytes, parent, description); } else { currentSensor = new PIDSensor(Mode, PID, bytes, parent, description, s_formulaAttribute.Value.ToString()); } if (xmlTree.HasElements) { // The PID node has children, so it should have an indication what the id's of that children are. currentSensor.firstPID = int.Parse(xmlTree.Attribute("firstPID").Value.ToString(), NumberStyles.HexNumber); } foreach (var childNode in xmlTree.Elements()) { currentSensor.PIDSensors.Add(parsePossibleSensorList(childNode, Mode, currentSensor)); } // subscribe to the current sensor currentSensor.RaiseOBDSensorData += OnRaiseOBDSensorData; return(currentSensor); }
public PIDSensor(int mode, int PID, int bytes, PIDSensor parent, string description, string formula = "") { this.mode = mode; this.PID = PID; this.bytes = bytes; this.description = description; this.formula = formula.ToUpper(); this.parent = parent; // The 'formula' field in the XML file can be filled with characters and calculation symbols // To determine the number of arguments needed, the highest used character in the formula will be stored. this.highestFormulaCharacter = GetHighestFormulaCharacterFrom(formula); if (this.highestFormulaCharacter == null) this.highestFormulaCharacterNumber = -1; // because A = 0 else if (this.highestFormulaCharacter != null) { char character = (char)highestFormulaCharacter; this.highestFormulaCharacterNumber = Array.IndexOf(alphabet, character, 0, 26); } }
public PIDSensor(int mode, int PID, int bytes, PIDSensor parent, string description, string formula = "") { this.mode = mode; this.PID = PID; this.bytes = bytes; this.description = description; this.formula = formula.ToUpper(); this.parent = parent; // The 'formula' field in the XML file can be filled with characters and calculation symbols // To determine the number of arguments needed, the highest used character in the formula will be stored. this.highestFormulaCharacter = GetHighestFormulaCharacterFrom(formula); if (this.highestFormulaCharacter == null) { this.highestFormulaCharacterNumber = -1; // because A = 0 } else if (this.highestFormulaCharacter != null) { char character = (char)highestFormulaCharacter; this.highestFormulaCharacterNumber = Array.IndexOf(alphabet, character, 0, 26); } }
/// <summary> /// Parse all elements inside a <PIDSensor>-element (level 3 or deeper) /// </summary> /// <param name="xmlNodes">XML element containing the tree of PIDSensor-data</param> /// <param name="Mode">ELM mode in which this element resides.</param> /// <returns></returns> public PIDSensor parsePossibleSensorList(XElement xmlTree, int Mode, PIDSensor parent = null) { var PID = int.Parse(xmlTree.Attribute("PID").Value.ToString(), NumberStyles.HexNumber); var bytes = int.Parse(xmlTree.Attribute("bytes").Value.ToString(), NumberStyles.HexNumber); var description = xmlTree.Attribute("Description").Value.ToString(); // Formula attribute can be empty, so we first need to check it before parsing. var s_formulaAttribute = xmlTree.Attribute("Formula"); PIDSensor currentSensor; if (s_formulaAttribute == null) currentSensor = new PIDSensor(Mode, PID, bytes, parent, description); else currentSensor = new PIDSensor(Mode, PID, bytes, parent, description, s_formulaAttribute.Value.ToString()); if (xmlTree.HasElements) { // The PID node has children, so it should have an indication what the id's of that children are. currentSensor.firstPID = int.Parse(xmlTree.Attribute("firstPID").Value.ToString(), NumberStyles.HexNumber); } foreach (var childNode in xmlTree.Elements()) { currentSensor.PIDSensors.Add(parsePossibleSensorList(childNode, Mode, currentSensor)); } // subscribe to the current sensor currentSensor.RaiseOBDSensorData += OnRaiseOBDSensorData; return currentSensor; }
public void TestNoErrorReturnMessage() { int mode = 01; int pid = 00; string returnMessage = "7E8 06 41 00 BE 3F A8 11 \r\n\r\n>"; PIDSensor testPID = new PIDSensor(mode, pid, 2, null, "no desc"); testPID.parseResponse(returnMessage); }