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:13:21 +0100
commit6ba361d96bc2581667b3400f87ff89fae6449e1f (patch)
treee72e959d7d4c3b0f0b6dc20ec4f07d957eae1a50 /parameter/FixedPointParameterType.cpp
parent68a912857707864bbaaff9808717813105072a6e (diff)
downloadexternal_parameter-framework-6ba361d96bc2581667b3400f87ff89fae6449e1f.zip
external_parameter-framework-6ba361d96bc2581667b3400f87ff89fae6449e1f.tar.gz
external_parameter-framework-6ba361d96bc2581667b3400f87ff89fae6449e1f.tar.bz2
parameter-framework: improvements and corrections
BZ: 6721 - Bug correction concerning selection criteria display (inclusive type) - Adapted XML format to allow for only on parameter to be associated to a domain - Removed unused files in parameter project Change-Id: I9f42d08ff8cb60354714fe3d6b0f0b321ad0a7bf Orig-Change-Id: I837e553070f5acf2d275082c986ba29433493e31 Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com> Reviewed-on: http://android.intel.com:8080/16878 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.cpp113
1 files changed, 83 insertions, 30 deletions
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp
index 86c9053..a3c9bc5 100644
--- a/parameter/FixedPointParameterType.cpp
+++ b/parameter/FixedPointParameterType.cpp
@@ -31,6 +31,8 @@
#include "FixedPointParameterType.h"
#include <stdlib.h>
#include <sstream>
+#include <iomanip>
+#include <assert.h>
#include "Parameter.h"
#include "ParameterAccessContext.h"
#include "ConfigurationAccessContext.h"
@@ -82,7 +84,7 @@ bool CFixedPointParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerial
// Size vs. Q notation integrity check
if (uiSizeInBits < getUtilSizeInBits()) {
- serializingContext.setError("Inconsistent Size vs. Q notation for " + getKind() + " " + xmlElement.getPath() + ": Summing (Integral + _uiFractional + 1) should be less than given Size (" + xmlElement.getAttributeString("Size") + ")");
+ serializingContext.setError("Inconsistent Size vs. Q notation for " + getKind() + " " + xmlElement.getPath() + ": Summing (Integral + _uiFractional + 1) should not exceed given Size (" + xmlElement.getAttributeString("Size") + ")");
return false;
}
@@ -95,40 +97,50 @@ bool CFixedPointParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerial
bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
- int32_t iData;
+ // Hexa
+ bool bValueProvidedAsHexa = !strValue.compare(0, 2, "0x");
- if (parameterAccessContext.valueSpaceIsRaw()) {
+ // Check data integrity
+ if (bValueProvidedAsHexa && !parameterAccessContext.valueSpaceIsRaw()) {
- iData = strtol(strValue.c_str(), NULL, 0);
+ parameterAccessContext.setError("Hexadecimal values are not supported for " + getKind() + " when selected value space is real:");
- } else {
- double dData = strtod(strValue.c_str(), NULL);
-
- // Do the conversion
- iData = (int32_t)(dData * (1UL << _uiFractional) + 0.5F - (double)(dData < 0));
+ return false;
}
- // Check for admitted range: [-2^m, 2^m - 2^n]
- uint32_t uiSizeInBits = getUtilSizeInBits();
+ int32_t iData;
- int32_t iMin = ((int32_t)1 << 31) >> (32 - uiSizeInBits);
- int32_t iMax = -iMin - 1;
+ if (parameterAccessContext.valueSpaceIsRaw()) {
- if (iData < iMin || iData > iMax) {
- ostringstream strStream;
+ // Get data in integer form
+ iData = strtol(strValue.c_str(), NULL, 0);
- strStream << "Value " << strValue << " standing out of admitted ";
+ if (bValueProvidedAsHexa) {
- if (!parameterAccessContext.valueSpaceIsRaw()) {
+ if (!isEncodable(iData)) {
- strStream << "real range [" << (double)iMin / (1UL << _uiFractional) << ", "<< (double)iMax / (1UL << _uiFractional) << "]";
- } else {
+ // Illegal value provided
+ parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), true));
+
+ return false;
+ } else {
- strStream << "raw range [" << iMin << ", " << iMax << "]";
+ // Sign extend
+ signExtend(iData);
+ }
}
- strStream << " for " << getKind();
- parameterAccessContext.setError(strStream.str());
+ } else {
+ double dData = strtod(strValue.c_str(), NULL);
+
+ // Do the conversion
+ iData = (int32_t)(dData * (1UL << _uiFractional) + 0.5F - (double)(dData < 0));
+ }
+ // Check integrity
+ if (!isConsistent(iData, true)) {
+
+ // Illegal value provided
+ parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), bValueProvidedAsHexa));
return false;
}
@@ -140,22 +152,28 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal
void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const
{
- int32_t iData = (int32_t)uiValue;
+ int32_t iData = uiValue;
- // Sign extend
- uint32_t uiShift = 32 - getUtilSizeInBits();
-
- if (uiShift) {
+ // Check consistency
+ assert(isEncodable(iData));
- iData = (iData << uiShift) >> uiShift;
- }
+ // Sign extend
+ signExtend(iData);
// Format
ostringstream strStream;
+ // Raw formatting?
if (parameterAccessContext.valueSpaceIsRaw()) {
- strStream << iData;
+ // Hexa formatting?
+ if (parameterAccessContext.outputRawFormatIsHex()) {
+
+ strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << uiValue;
+ } else {
+
+ strStream << iData;
+ }
} else {
double dData = (double)iData / (1UL << _uiFractional);
@@ -171,3 +189,38 @@ uint32_t CFixedPointParameterType::getUtilSizeInBits() const
{
return _uiIntegral + _uiFractional + 1;
}
+
+// Out of range error
+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;
+
+ ostringstream strStream;
+
+ strStream << "Value " << strValue << " standing out of admitted ";
+
+ if (!bRawValueSpace) {
+
+ strStream << "real range [" << (double)iMin / (1UL << _uiFractional) << ", "<< (double)iMax / (1UL << _uiFractional) << "]";
+ } else {
+
+ strStream << "raw range [";
+
+ if (bHexaValue) {
+
+ strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << makeEncodable(iMin);
+ strStream << ", 0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << makeEncodable(iMax);
+
+ } else {
+
+ strStream << iMin << ", " << iMax;
+ }
+
+ strStream << "]";
+ }
+ strStream << " for " << getKind();
+
+ return strStream.str();
+}