Permalink
Browse files

support ecuxml dynamic sensors

  • Loading branch information...
1 parent c0b34e2 commit 0e88d3203e9769cadacdc59b3f9419e8f641ef8a @cail committed Nov 9, 2011
Showing with 71 additions and 12 deletions.
  1. +59 −11 src/elm/ECUXMLSensorProvider.cs
  2. +12 −1 src/elm/SensorRegistry.cs
@@ -34,12 +34,12 @@ void init(SensorRegistry registry)
if (reader == null)
throw new Exception("Can't do double init");
- Namespace = Description = "Default";
+ reader.Read();
- reader.ReadStartElement("parameters");
+ this.Namespace = reader.GetAttribute("namespace") ?? "Default";
+ this.Description = reader.GetAttribute("description") ?? "";
- this.Namespace = reader.GetAttribute("namespace");
- this.Description = reader.GetAttribute("description");
+ reader.ReadStartElement("parameters");
while( reader.IsStartElement("parameter") ){
@@ -53,7 +53,11 @@ void init(SensorRegistry registry)
string basename = null;
string units = null;
string valuea = null;
+ string valueb = null;
+ string valuec = null;
+ string valued = null;
string valueab = null;
+ string valuebc = null;
string valuecd = null;
double offset = 0;
@@ -63,36 +67,60 @@ void init(SensorRegistry registry)
{
case "address":
reader.ReadStartElement();
- var hexval = reader.ReadElementString("byte");
+ var hexval = reader.ReadElementString("byte").Trim();
if (hexval.StartsWith("0x"))
hexval = hexval.Substring(2);
command = int.Parse(hexval, NumberStyles.HexNumber);
reader.ReadEndElement();
break;
case "raw":
- rawcommand = reader.ReadElementString();
+ rawcommand = reader.ReadElementString().Trim();
break;
case "base":
- basename = reader.ReadElementString();
+ basename = reader.ReadElementString().Trim();
break;
case "valuea":
valuea = reader.ReadElementString();
break;
+ case "valueb":
+ valueb = reader.ReadElementString();
+ break;
+ case "valuec":
+ valuec = reader.ReadElementString();
+ break;
+ case "valued":
+ valued = reader.ReadElementString();
+ break;
+
case "valueab":
valueab = reader.ReadElementString();
break;
+ case "valuebc":
+ valuebc = reader.ReadElementString();
+ break;
case "valuecd":
valuecd = reader.ReadElementString();
break;
+
case "offset":
offset = double.Parse(reader.ReadElementString(), UnitsConverter.DefaultNumberFormat);
break;
case "description":
- reader.ReadElementString();
- break;
- case "units":
- units = reader.ReadElementString();
+ reader.ReadStartElement();
+ while(reader.NodeType == XmlNodeType.Element)
+ {
+ switch(reader.Name)
+ {
+ case "unit":
+ units = reader.ReadElementString().Trim();
+ break;
+ default:
+ reader.ReadElementString();
+ break;
+ }
+ }
+ reader.ReadEndElement();
break;
default:
throw new Exception("unknown tag `"+reader.Name+"` while creating PID "+id);
@@ -114,11 +142,31 @@ void init(SensorRegistry registry)
var val = double.Parse(valuea, UnitsConverter.DefaultNumberFormat);
s.obdValue = (p) => p.get(0) * val + offset;
}
+ if (valueb != null)
+ {
+ var val = double.Parse(valueb, UnitsConverter.DefaultNumberFormat);
+ s.obdValue = (p) => p.get(1) * val + offset;
+ }
+ if (valuec != null)
+ {
+ var val = double.Parse(valuec, UnitsConverter.DefaultNumberFormat);
+ s.obdValue = (p) => p.get(2) * val + offset;
+ }
+ if (valued != null)
+ {
+ var val = double.Parse(valued, UnitsConverter.DefaultNumberFormat);
+ s.obdValue = (p) => p.get(3) * val + offset;
+ }
if (valueab != null)
{
var val = double.Parse(valueab, UnitsConverter.DefaultNumberFormat);
s.obdValue = (p) => p.getab() * val + offset;
}
+ if (valuebc != null)
+ {
+ var val = double.Parse(valuebc, UnitsConverter.DefaultNumberFormat);
+ s.obdValue = (p) => p.getbc() * val + offset;
+ }
if (valuecd != null)
{
var val = double.Parse(valuecd, UnitsConverter.DefaultNumberFormat);
View
@@ -56,9 +56,20 @@ public void Deactivate()
}
}
+ /**
+ Provider should be either a SensorProvider full class name, or special string
+ ecuxml://path/to/file.ecuxml
+ for dynamic sensor definitions
+ */
public void RegisterProvider(string provider)
{
- this.RegisterProvider( (SensorProvider)Assembly.GetExecutingAssembly().CreateInstance(provider));
+ if (provider.StartsWith("ecuxml://")){
+ provider = provider.Replace("ecuxml://", "");
+ var prov = new ECUXMLSensorProvider(provider);
+ this.RegisterProvider(prov);
+ }else{
+ this.RegisterProvider( (SensorProvider)Assembly.GetExecutingAssembly().CreateInstance(provider));
+ }
}
public void RegisterProvider(SensorProvider provider)

0 comments on commit 0e88d32

Please sign in to comment.