From 0a1301c141809fc8441abee5415c791ce894f068 Mon Sep 17 00:00:00 2001 From: Tom Joseph Date: Fri, 16 Feb 2018 08:27:00 +0530 Subject: sensor: Add result exponent to the sensor yaml Result exponent sets the decimal point location for the result before the linearization function is applied. This is different from the scale implemented by the sensors dbus objects. The scale is the scaling factor to get the value for the units specified for the sensor. Linearization is done after applying the scale on the raw sensor value. Change-Id: I76624c593bf6cdf40ec884c0ff0aceb58746732c Signed-off-by: Tom Joseph --- scripts/sensor-example.yaml | 5 +++++ scripts/writesensor.mako.cpp | 5 +++-- types.hpp | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/sensor-example.yaml b/scripts/sensor-example.yaml index db0e694..06c8836 100755 --- a/scripts/sensor-example.yaml +++ b/scripts/sensor-example.yaml @@ -100,6 +100,11 @@ multiplierM: 511 offsetB: 0 bExp: 0 + # Result exponent field in Type 1 SDR(2's complement, signed) + rExp: 0 + # Applies for analog sensors, the actual reading value for the sensor is + # Value * 10^N + scale: -3 mutability: Mutability::Write|Mutability::Read serviceInterface: org.freedesktop.DBus.Properties readingType: readingData diff --git a/scripts/writesensor.mako.cpp b/scripts/writesensor.mako.cpp index 4644ff7..a59e149 100644 --- a/scripts/writesensor.mako.cpp +++ b/scripts/writesensor.mako.cpp @@ -45,6 +45,7 @@ extern const IdInfoMap sensors = { multiplier = sensor.get("multiplierM", 1) offsetB = sensor.get("offsetB", 0) exp = sensor.get("bExp", 0) + rExp = sensor.get("rExp", 0) unit = sensor.get("unit", "") scale = sensor.get("scale", 0) hasScale = "true" if "scale" in sensor.keys() else "false" @@ -68,8 +69,8 @@ extern const IdInfoMap sensors = { mutability = sensor.get("mutability", "Mutability::Read") %> ${entityID},${instance},${sensorType},"${path}","${sensorInterface}", - ${readingType},${multiplier}, ${offsetB},${exp}, - ${offsetB * pow(10,exp)}, ${hasScale},${scale},"${unit}", + ${readingType},${multiplier},${offsetB},${exp}, + ${offsetB * pow(10,exp)}, ${rExp}, ${hasScale},${scale},"${unit}", ${updateFunc},${getFunc},Mutability(${mutability}),${sensorNameFunc},{ % for interface,properties in interfaces.items(): {"${interface}",{ diff --git a/types.hpp b/types.hpp index 61f3d68..e77dc8e 100644 --- a/types.hpp +++ b/types.hpp @@ -115,8 +115,8 @@ using InstancePath = std::string; using Type = uint8_t; using ReadingType = uint8_t; using Multiplier = uint16_t; -using OffsetB = uint16_t; -using Exponent = uint8_t; +using OffsetB = int16_t; +using Exponent = int8_t; using ScaledOffset = int64_t; using Scale = int16_t; using Unit = std::string; @@ -154,6 +154,7 @@ struct Info OffsetB coefficientB; Exponent exponentB; ScaledOffset scaledOffset; + Exponent exponentR; bool hasScale; Scale scale; Unit unit; -- cgit v1.2.1