The value of a channel data item can represent the actual value of the measured quantity, or the channel data item can represent relative value which is scaled to between maximum and minimum values of the measured quantity.
The KSensrvPropIdChannelDataFormat
property defines if channel data items are in a scaled format.
For scaled data items, the KSensrvPropIdScaledRange
property defines range
for the data item value and the KSensrvPropIdMeasureRange
property defines range
for the measured quantity.
The following example reads the maximum value of measure range for data
items (KSensrvPropIdScaledRange)
and the maximum value of
the measured quantity (KSensrvPropIdMeasureRange)
. The example
takes into account that the KSensrvPropIdMeasureRange
property
can be defined as an array property.
TSensrvProperty property; TInt channelDataFormat( ESensrvFormatAbsolute ); TInt channelDataScaledRange( 1 ); TReal channelDataMeasureRangeMaxValue( 1 ); //Read channel data format iSensorChannel->GetPropertyL( KSensrvPropIdChannelDataFormat, KSensrvItemIndexNone, property ); property.GetValue( channelDataFormat ); if( ESensrvFormatScaled == channelDataFormat ) { //Read data item scaled range iSensorChannel->GetPropertyL( KSensrvPropIdScaledRange, KSensrvItemIndexNone, property ); property.GetMaxValue( channelDataScaledRange ); //Read data item measure range iSensorChannel->GetPropertyL( KSensrvPropIdMeasureRange, KSensrvItemIndexNone, property ); if( ESensrvArrayPropertyInfo == property.GetArrayIndex() ) { TInt arrayIndex( 0 ); property.GetValue( arrayIndex );//Value points to array index currently in use iSensorChannel->GetPropertyL( KSensrvPropIdMeasureRange, KSensrvItemIndexNone, arrayIndex, property ); } else { //Single property } property.GetMaxValue( channelDataMeasureRangeMaxValue ); } else { //No scaling needed. //Value of the data item represents actual value of the measured quantity. }
You can convert the scaled channel data item value to the absolute value by dividing the channel data item value with the maximum value of scaled range of the channel and multiplying it with the maximum value of the measured quantity.
For example, the accelerometer channel provides the following properties:
KSensrvPropIdChannelDataFormat
with value ESensrvFormatScaled
KSensrvPropIdScaledRange
with maximum value of 127
KSensrvPropIdMeasureRange
with maximum value of 2 gKSensrvPropIdChannelUnit
with value ESensrvUnitGravityConstant
In the above example, the accelerometer channel data item value 64 means an absolute value of 1.01g (64 / 127 * 2g = 1.01g).
You can also scale the value of the channel data item. The scaling factor
is published in the KSensrvPropIdChannelScale
property.