aboutsummaryrefslogtreecommitdiffstats
path: root/parameter/FixedPointParameterType.cpp
diff options
context:
space:
mode:
authorPatrick Benavoli <patrickx.benavoli@intel.com>2011-08-31 11:23:24 +0200
committerDavid Wagner <david.wagner@intel.com>2014-02-10 17:14:54 +0100
commit1387bda01b089d8e8df06339d9c15d53b3de6725 (patch)
treec8dd258fdff344e629433f89976ca573ff828c31 /parameter/FixedPointParameterType.cpp
parent2ecf900ad8c30ce9f8e81f57977a1a80a6f6d8af (diff)
downloadexternal_parameter-framework-1387bda01b089d8e8df06339d9c15d53b3de6725.zip
external_parameter-framework-1387bda01b089d8e8df06339d9c15d53b3de6725.tar.gz
external_parameter-framework-1387bda01b089d8e8df06339d9c15d53b3de6725.tar.bz2
Min/max value computation; Tuning lock handling
BZ: 7466 - Min/max values are now correctly computed. They concern integer and fixed point parameters - tuning mode lock issue solved: created an AutoLock class for safe lock handling - added configuration files for a demo on Ubuntu environment - had AMIXER subsystem plugin compliant for derivation - LPE library: add carriage return on logs - removed obsolete files - some cosmetics Change-Id: Ife7a4799fd48dd4a1ca25dae666c4e453815881e Orig-Change-Id: I72fc5c1ff6abf638b43266a75bc00e21ad412349 Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com> Reviewed-on: http://android.intel.com:8080/16880 Reviewed-by: Mahe, Erwan <erwan.mahe@intel.com> Tested-by: Barthes, FabienX <fabienx.barthes@intel.com> Reviewed-by: buildbot <buildbot@intel.com> Tested-by: buildbot <buildbot@intel.com>
Diffstat (limited to 'parameter/FixedPointParameterType.cpp')
-rw-r--r--parameter/FixedPointParameterType.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp
index fb986c5..5b90f13 100644
--- a/parameter/FixedPointParameterType.cpp
+++ b/parameter/FixedPointParameterType.cpp
@@ -130,7 +130,7 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal
if (bValueProvidedAsHexa) {
- if (!isEncodable(iData)) {
+ if (!isEncodable(iData, getUtilSizeInBits())) {
// Illegal value provided
parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), true));
@@ -149,8 +149,9 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal
// Do the conversion
iData = (int32_t)(dData * (1UL << _uiFractional) + 0.5F - (double)(dData < 0));
}
+
// Check integrity
- if (!isConsistent(iData, true)) {
+ if (!isConsistent(iData)) {
// Illegal value provided
parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), bValueProvidedAsHexa));
@@ -168,7 +169,7 @@ void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValu
int32_t iData = uiValue;
// Check consistency
- assert(isEncodable(iData));
+ assert(isEncodable(iData, getUtilSizeInBits()));
// Sign extend
signExtend(iData);
@@ -207,8 +208,8 @@ uint32_t CFixedPointParameterType::getUtilSizeInBits() const
string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool bRawValueSpace, bool bHexaValue) const
{
// Min/Max computation
- int32_t iMin = ((int32_t)1 << 31) >> (32 - getUtilSizeInBits());
- int32_t iMax = -iMin - 1;
+ int32_t iMax = (1L << (getUtilSizeInBits() - 1)) - 1;
+ int32_t iMin = -iMax - 1;
ostringstream strStream;
@@ -223,7 +224,9 @@ string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool
if (bHexaValue) {
+ // Format Min
strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << makeEncodable(iMin);
+ // Format Max
strStream << ", 0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << makeEncodable(iMax);
} else {
@@ -237,3 +240,21 @@ string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool
return strStream.str();
}
+
+// Check data is consistent with available range, with respect to its sign
+bool CFixedPointParameterType::isConsistent(uint32_t uiData) const
+{
+ uint32_t uiShift = 32 - getUtilSizeInBits();
+
+ if (uiShift) {
+
+ // Negative value?
+ bool bIsValueExpectedNegative = (uiData & (1 << (uiShift - 1))) != 0;
+
+ // Check high bits are clean
+ return bIsValueExpectedNegative ? !(~uiData >> uiShift) : !(uiData >> uiShift);
+ }
+
+ return true;
+}
+