Commit aac1f011 authored by Axel Auweter's avatar Axel Auweter
Browse files

Support for immediate scaling in DCDBQuery.

parent 05693069
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <cinttypes> #include <cinttypes>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include "dcdbendian.h" #include "dcdbendian.h"
#include "query.h" #include "query.h"
...@@ -54,21 +55,32 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC ...@@ -54,21 +55,32 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC
/* Iterate over list of sensors requested by the user */ /* Iterate over list of sensors requested by the user */
for (std::list<std::string>::iterator it = sensors.begin(); it != sensors.end(); it++) { for (std::list<std::string>::iterator it = sensors.begin(); it != sensors.end(); it++) {
bool unitConvert = false; bool unitConvert = false;
std::string targetUnitStr; bool scale = false;
double scalingFactor = 1;
std::string modifierStr, targetUnitStr;
DCDBUnit baseUnit = DCDBUnit_None, targetUnit = DCDBUnit_None; DCDBUnit baseUnit = DCDBUnit_None, targetUnit = DCDBUnit_None;
/* Check if the sensor was requested in a different unit */ /* Check if the sensor was requested in a different unit or with scaling factor */
if (it->find('/') != std::string::npos) { if (it->find('/') != std::string::npos) {
targetUnitStr = it->substr(it->find('/')+1, it->length()); modifierStr = it->substr(it->find('/')+1, it->length());
*it = it->substr(0, it->find('/'));
targetUnit = UnitConv::fromString(targetUnitStr); /* Remove the modifier from the string */
*it = it->substr(0, it->find('/'));
DCDBPublicSensor sen; /* Check what type of modificatino is requested */
sensorConfig.getPublicSensorByName(sen, it->c_str()); boost::regex e("\\.?[0-9]*", boost::regex::extended);
baseUnit = UnitConv::fromString(sen.unit); if (boost::regex_match(modifierStr, e)) {
scale = true;
sscanf(modifierStr.c_str(), "%lf", &scalingFactor);
}
else {
unitConvert = true;
targetUnit = UnitConv::fromString(targetUnitStr);
unitConvert = true; DCDBPublicSensor sen;
sensorConfig.getPublicSensorByName(sen, it->c_str());
baseUnit = UnitConv::fromString(sen.unit);
}
} }
/* Lookup the sensor in the published sensors table */ /* Lookup the sensor in the published sensors table */
...@@ -119,6 +131,11 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC ...@@ -119,6 +131,11 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC
} }
} }
/* Scale the value if requested */
if (scale) {
reading.value *= scalingFactor;
}
/* Print the sensor's public name */ /* Print the sensor's public name */
std::cout << *it << ","; std::cout << *it << ",";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment