<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to UnitsOfMeasurement</title><link>https://sourceforge.net/p/obdchat/wiki/UnitsOfMeasurement/</link><description>Recent changes to UnitsOfMeasurement</description><atom:link href="https://sourceforge.net/p/obdchat/wiki/UnitsOfMeasurement/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 22 Jan 2014 16:44:00 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/obdchat/wiki/UnitsOfMeasurement/feed" rel="self" type="application/rss+xml"/><item><title>UnitsOfMeasurement modified by Dave Brondsema</title><link>https://sourceforge.net/p/obdchat/wiki/UnitsOfMeasurement/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="units-of-measurement"&gt;Units of Measurement&lt;/h1&gt;
&lt;p&gt;The &lt;span&gt;[VehicleDatabases]&lt;/span&gt; can declare the exact unit of measurement (for example, degrees Celsius, kilometers per hour) for all values read from vehicle computers where the measurement unit is known. The units are labeled using the "case sensitive" syntax of the &lt;a class="" href="http://aurora.regenstrief.org/~ucum/ucum.html#section-introduction" rel="nofollow"&gt;Unified Code for Units of Measure&lt;/a&gt;, which allows any UCUM-aware app to convert values into any unit the user chooses for display (degrees Fahrenheit or miles per hour, for example) while offering only units that make sense for the value to be displayed. &lt;/p&gt;
&lt;p&gt;Tiny platforms, those that do not use the &lt;span&gt;[VehicleDatabaseFormat]&lt;/span&gt; directly but are programmed in some other form generated from the database by an exporter, will generally not be UCUM aware, but the unit information can be used by the exporter to allow the user to select preferred units when generating the data to load on the tiny platform. &lt;/p&gt;
&lt;h2 id="notes-for-database-writers"&gt;Notes for database writers&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Be sure &lt;code&gt;ucum&lt;/code&gt; attributes are written exactly. They are not just labels for humans to read, but exactly specify a physical unit. The syntax is strict. Look in the &lt;a class="" href="http://aurora.regenstrief.org/~ucum/ucum.html#section-Tables-of-Terminal-Symbols" rel="nofollow"&gt;Tables of Terminal Symbols&lt;/a&gt; (using the &lt;em&gt;case-sensitive&lt;/em&gt; column); know the &lt;a class="" href="http://aurora.regenstrief.org/~ucum/ucum.html#section-Character-Set-and-Lexical-Rules" rel="nofollow"&gt;lexical&lt;/a&gt; and &lt;a class="" href="http://aurora.regenstrief.org/~ucum/ucum.html#section-Syntax-Rules" rel="nofollow"&gt;syntax&lt;/a&gt; rules for combining them. &lt;/li&gt;
&lt;li&gt;Some UCUM spellings are surprises, like &lt;code&gt;Cel&lt;/code&gt; for degrees Celsius but &lt;code&gt;[degF]&lt;/code&gt; for degrees Fahrenheit. The UCUM spelling of RPM is &lt;code&gt;circ/min&lt;/code&gt;. Get used to it. :) It doesn't have to appear that way when displayed by an app; these are the unit tags in the database. &lt;/li&gt;
&lt;li&gt;The UCUM &lt;a class="" href="http://aurora.regenstrief.org/~schadow/units" rel="nofollow"&gt;web applet&lt;/a&gt; can be a good instant test of whether you have written a UCUM unit correctly and it converts to another unit the way you expect. &lt;/li&gt;
&lt;li&gt;&lt;code&gt;ucum&lt;/code&gt; attributes do not go directly on a &lt;code&gt;field&lt;/code&gt; element, but on one or more of its contained &lt;code&gt;calc&lt;/code&gt; elements. That's because it may be awkward or impossible to express in UCUM what the units are of the raw value in a field. It would be possible to say that the units of PID 0C engine speed in raw form are &lt;code&gt;circ/4/min&lt;/code&gt; but that's a little puzzling to work out (checking it in the &lt;a class="" href="http://aurora.regenstrief.org/~schadow/units" rel="nofollow"&gt;applet&lt;/a&gt; and re-reading the &lt;a class="" href="http://aurora.regenstrief.org/~ucum/ucum.html#section-Syntax-Rules" rel="nofollow"&gt;strict left-to-right rule&lt;/a&gt; should help). And the fact that PID 0F intake air is degrees Celsius plus 40 isn't expressible in UCUM at all. Instead, respectively, just use a &lt;code&gt;calc&lt;/code&gt; that divides engine speed by 4 and declares the result to be &lt;code&gt;circ/min&lt;/code&gt;, and one that subtracts 40 from intake air and calls the result &lt;code&gt;Cel&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;If multiple &lt;code&gt;calc&lt;/code&gt;s appear for a field, and more than one has a &lt;code&gt;ucum&lt;/code&gt; attribute, the &lt;code&gt;ucum&lt;/code&gt; attributes have to be consistent. That is, if _calc_1 says it gives _unit_1 and _calc_2 says it gives _unit_2 then _calc_1 composed with (_calc_2)-1 composed with the conversion from _unit_1 to _unit_2 should be the identity function. Eventually we can have sanity code that checks that. Until then, please make sure it's so. &lt;/li&gt;
&lt;li&gt;Misleading &lt;code&gt;ucum&lt;/code&gt; attributes are worse than none; if it's doubtful what the units are for a value, better to omit any &lt;code&gt;ucum&lt;/code&gt; attribute. (Or, another attribute could be added to indicate level of confidence in the unit.) &lt;/li&gt;
&lt;li&gt;&lt;code&gt;ucum&lt;/code&gt; attributes that aren't quite accurate are also bad. For some device with limited arithmetic it might be necessary to use a &lt;code&gt;calc&lt;/code&gt; that only approximates a unit conversion (say, 5/8 instead of 15625/25146 for &lt;code&gt;km&lt;/code&gt; to &lt;code&gt;[mi_i]&lt;/code&gt;, for example). That may be the best that device can do but in the database it should be flagged as an approximation. The options are to leave the &lt;code&gt;ucum&lt;/code&gt; attribute off, or keep it and include a &lt;code&gt;rel-err&lt;/code&gt; attribute saying how far the approximation is from exact: &lt;code&gt;rel-err='6e-3'&lt;/code&gt; in this case. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="notes-for-application-writers"&gt;Notes for application writers&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Obtain a &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/service/UnitFormatService.html#" rel="nofollow"&gt;UnitFormatService&lt;/a&gt; implementation using &lt;a class="" href="http://developer.android.com/reference/java/util/ServiceLoader.html#load" rel="nofollow"&gt;ServiceLoader.load&lt;/a&gt;&lt;code&gt;(org.unitsofmeasurement.service.UnitFormatService)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Call &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/service/UnitFormatService.html#getUnitFormat()" rel="nofollow"&gt;getUnitFormat&lt;/a&gt;&lt;code&gt;()&lt;/code&gt; on the &lt;code&gt;UnitFormatService&lt;/code&gt; to get the UCUM &lt;code&gt;UnitFormat&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Call &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/UnitFormat.html#parse(java.lang.CharSequence,java.text.ParsePosition)" rel="nofollow"&gt;parse&lt;/a&gt; on the &lt;code&gt;UnitFormat&lt;/code&gt; to parse any ucum attribute from the database and get the corresponding &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/Unit.html#" rel="nofollow"&gt;Unit&lt;/a&gt; &lt;em&gt;u&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;If the user wants the data displayed in a different unit &lt;em&gt;v&lt;/em&gt;, use &lt;em&gt;u&lt;/em&gt;.&lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/Unit.html#getConverterToAny(org.unitsofmeasurement.unit.Unit)" rel="nofollow"&gt;getConverterToAny&lt;/a&gt;(&lt;em&gt;v&lt;/em&gt;) to get the appropriate converter and use its &lt;code&gt;convert&lt;/code&gt; methods to do the calculation. If &lt;em&gt;v&lt;/em&gt; isn't a compatible unit (the user wanted degrees Fahrenheit for an engine torque?) an exception will be thrown by &lt;code&gt;getConverterToAny&lt;/code&gt;. Or check first with &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/Unit.isCompatible(org.unitsofmeasurement.unit.Unit).html#" rel="nofollow"&gt;isCompatible&lt;/a&gt;. &lt;/li&gt;
&lt;li&gt;Or, just have the user choose from a menu of only compatible units. Pick a &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/SystemOfUnits.html#" rel="nofollow"&gt;SystemOfUnits&lt;/a&gt; (after loading the &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/service/SystemOfUnitsService.html#" rel="nofollow"&gt;SystemOfUnitsService&lt;/a&gt;), get the &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/Unit.html#getDimension()" rel="nofollow"&gt;dimension&lt;/a&gt; of &lt;em&gt;u&lt;/em&gt;, and use &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/SystemOfUnits.html#getUnits(org.unitsofmeasurement.unit.Dimension)" rel="nofollow"&gt;getUnits&lt;/a&gt;&lt;code&gt;(Dimension)&lt;/code&gt; to get the set of compatible units in that system. If the user chooses unit &lt;em&gt;v&lt;/em&gt; from that set, it's known to be compatible; use &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/Unit.html#getConverterTo(org.unitsofmeasurement.unit.Unit)" rel="nofollow"&gt;getConverterTo&lt;/a&gt;, which can't throw the exception. &lt;/li&gt;
&lt;li&gt;Suppose you allow a user to choose a parameter giving rpm and a parameter giving torque, and create a gauge showing their product. When you multiply the numbers, what will be the unit of the result? Find out by &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/Unit.html#multiply(org.unitsofmeasurement.unit.Unit)" rel="nofollow"&gt;multiply&lt;/a&gt;ing the &lt;code&gt;Unit&lt;/code&gt;s too. You can even use &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/SystemOfUnits.html#getUnits(org.unitsofmeasurement.unit.Dimension)" rel="nofollow"&gt;getUnits&lt;/a&gt; to show a menu of appropriate unit choices for the result (horsepower, watts, etc.), and &lt;a class="" href="http://www.unitsofmeasurement.org/apidocs/org/unitsofmeasurement/unit/Unit.html#getConverterTo(org.unitsofmeasurement.unit.Unit)" rel="nofollow"&gt;getConverterTo&lt;/a&gt; for the correct conversion to the desired display. &lt;/li&gt;
&lt;li&gt;All this depends on having a suitable service implementation as part of the app. &lt;a class="" href="http://www.eclipse.org/uomo/" rel="nofollow"&gt;UOMo&lt;/a&gt; appeared heavy in its dependencies to me, but Werner Keil assures me that a lot of them are in Android already and he's used it on Android already. Maybe one day he'll write up an example showing the steps needed to get it working. &lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Dave Brondsema</dc:creator><pubDate>Wed, 22 Jan 2014 16:44:00 -0000</pubDate><guid>https://sourceforge.net1d2f562b94717fbacaa82e984e3516b35deb4561</guid></item></channel></rss>