Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
aac1f011
Commit
aac1f011
authored
Aug 13, 2015
by
Axel Auweter
Browse files
Support for immediate scaling in DCDBQuery.
parent
05693069
Changes
1
Hide whitespace changes
Inline
Side-by-side
DCDBTools/dcdbquery/query.cpp
View file @
aac1f011
...
...
@@ -14,6 +14,7 @@
#include
<cinttypes>
#include
<boost/algorithm/string.hpp>
#include
<boost/regex.hpp>
#include
"dcdbendian.h"
#include
"query.h"
...
...
@@ -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 */
for
(
std
::
list
<
std
::
string
>::
iterator
it
=
sensors
.
begin
();
it
!=
sensors
.
end
();
it
++
)
{
bool
unitConvert
=
false
;
std
::
string
targetUnitStr
;
bool
scale
=
false
;
double
scalingFactor
=
1
;
std
::
string
modifierStr
,
targetUnitStr
;
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
)
{
targetUnitStr
=
it
->
substr
(
it
->
find
(
'/'
)
+
1
,
it
->
length
());
*
it
=
it
->
substr
(
0
,
it
->
find
(
'/'
));
modifierStr
=
it
->
substr
(
it
->
find
(
'/'
)
+
1
,
it
->
length
());
targetUnit
=
UnitConv
::
fromString
(
targetUnitStr
);
/* Remove the modifier from the string */
*
it
=
it
->
substr
(
0
,
it
->
find
(
'/'
));
DCDBPublicSensor
sen
;
sensorConfig
.
getPublicSensorByName
(
sen
,
it
->
c_str
());
baseUnit
=
UnitConv
::
fromString
(
sen
.
unit
);
/* Check what type of modificatino is requested */
boost
::
regex
e
(
"
\\
.?[0-9]*"
,
boost
::
regex
::
extended
);
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 */
...
...
@@ -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 */
std
::
cout
<<
*
it
<<
","
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment