Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
d070d6b0
Commit
d070d6b0
authored
Apr 16, 2016
by
Axel Auweter
Browse files
Do not return garbage when a virtual sensor cannot be evaluated at a given time.
parent
4e4f834d
Changes
2
Hide whitespace changes
Inline
Side-by-side
DCDBLib/include_internal/virtualsensor_internal.h
View file @
d070d6b0
...
...
@@ -30,6 +30,19 @@
namespace
DCDB
{
namespace
VirtualSensor
{
/**
* @brief Exception class for errors during Physical Sensor Evaluation
*
* Exceptions of this type are thrown whenever the the evaluation of
* a physical sensor is impossible due to data being out of range.
* What() returns a human readable error string.
*/
class
PhysicalSensorEvaluatorException
:
public
std
::
runtime_error
{
public:
PhysicalSensorEvaluatorException
(
const
std
::
string
&
msg
)
:
runtime_error
(
msg
)
{}
};
namespace
qi
=
boost
::
spirit
::
qi
;
namespace
ascii
=
boost
::
spirit
::
ascii
;
...
...
DCDBLib/src/virtualsensor.cpp
View file @
d070d6b0
...
...
@@ -11,6 +11,7 @@
#include "dcdbglobals.h"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstdlib>
...
...
@@ -219,7 +220,14 @@ int64_t VSensorExpressionImpl::physicalSensorInterpolator(Connection* connection
readingBefore
.
value
=
(
int64_t
)
value
;
}
else
{
std
::
cerr
<<
"Cannot find reading for sensor "
<<
sensor
.
name
<<
" prior to time "
<<
t
.
getString
()
<<
"("
<<
t
.
getRaw
()
<<
")"
<<
std
::
endl
;
std
::
stringstream
msg
;
msg
<<
"Cannot find reading for sensor "
<<
sensor
.
name
<<
" prior to time "
<<
t
.
getString
()
<<
"("
<<
t
.
getRaw
()
<<
")"
<<
std
::
endl
;
cass_iterator_free
(
rows
);
cass_result_free
(
cresult
);
cass_statement_free
(
statement
);
cass_future_free
(
future
);
cass_prepared_free
(
prepared
);
throw
(
PhysicalSensorEvaluatorException
(
msg
.
str
()));
}
cass_iterator_free
(
rows
);
cass_result_free
(
cresult
);
...
...
@@ -265,7 +273,14 @@ int64_t VSensorExpressionImpl::physicalSensorInterpolator(Connection* connection
readingAfter
.
value
=
(
int64_t
)
value
;
}
else
{
std
::
cerr
<<
"Cannot find reading for sensor "
<<
sensor
.
name
<<
" following time "
<<
t
.
getString
()
<<
"("
<<
t
.
getRaw
()
<<
")"
<<
std
::
endl
;
std
::
stringstream
msg
;
msg
<<
"Cannot find reading for sensor "
<<
sensor
.
name
<<
" following time "
<<
t
.
getString
()
<<
"("
<<
t
.
getRaw
()
<<
")"
<<
std
::
endl
;
cass_iterator_free
(
rows
);
cass_result_free
(
cresult
);
cass_statement_free
(
statement
);
cass_future_free
(
future
);
cass_prepared_free
(
prepared
);
throw
(
PhysicalSensorEvaluatorException
(
msg
.
str
()));
}
cass_iterator_free
(
rows
);
cass_result_free
(
cresult
);
...
...
@@ -455,12 +470,17 @@ VSError VSensorImpl::query(std::list<SensorDataStoreReading>& result, TimeStamp&
i
<=
(
tzero
.
getRaw
()
+
(
n_end
*
frequency
));
i
+=
frequency
)
{
int64_t
eval
=
expression
->
evaluateAt
(
i
);
TimeStamp
t
(
i
);
SensorDataStoreReading
r
;
r
.
timeStamp
=
t
;
r
.
value
=
eval
;
result
.
push_back
(
r
);
try
{
int64_t
eval
=
expression
->
evaluateAt
(
i
);
TimeStamp
t
(
i
);
SensorDataStoreReading
r
;
r
.
timeStamp
=
t
;
r
.
value
=
eval
;
result
.
push_back
(
r
);
}
catch
(
PhysicalSensorEvaluatorException
&
e
)
{
std
::
cerr
<<
e
.
what
();
}
}
return
VS_OK
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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