summaryrefslogtreecommitdiffstats
path: root/parameter/FixedPointParameterType.cpp
diff options
context:
space:
mode:
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;
+}
+