Commit 4d3650d6 authored by Micha Mueller's avatar Micha Mueller
Browse files

Tiny improvements

parent 276cc675
......@@ -196,7 +196,7 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
for(const auto& g : p.configurator->getSensorGroups()) {
for(const auto& s : g->getSensors()) {
if (s->getName() == sensor) {
response = pathStrs[0] + "::" + sensor + _httpsServer.calcAvg(*s, s->getCacheSize(), time);
response = pathStrs[0] + "::" + sensor + _httpsServer.calcAvg(*s, time);
connection->set_status(server::connection::ok);
break;
}
......@@ -321,12 +321,12 @@ HttpsServer::~HttpsServer() {
delete _server;
}
std::string HttpsServer::calcAvg(SensorBase& s, unsigned cacheSize, uint64_t time) {
std::string HttpsServer::calcAvg(SensorBase& s, uint64_t time) {
uint64_t avg = 0;
const reading_t * const cache = s.getCache();
unsigned count = 0;
for(unsigned i = 0; i < cacheSize; i++) {
for(unsigned i = 0; i < s.getCacheSize(); i++) {
if (cache[i].timestamp > time) {
avg += cache[i].value;
count++;
......
......@@ -94,7 +94,7 @@ private:
*
* @return Response message of the form " Average of last *count* values is *avg*"
*/
std::string calcAvg(SensorBase& s, unsigned cacheSize, uint64_t time);
std::string calcAvg(SensorBase& s, uint64_t time);
/*
* Check if the authkey is valid and has the permission requiredPerm associated
......
......@@ -74,7 +74,7 @@ public:
const std::string& getMqtt() const { return _mqtt; }
unsigned getCacheSize() const { return _cacheSize; }
const reading_t * const getCache() const { return _cache.get(); }
const reading_t getLatestValue() const { return _latestValue; } /*TODO return reference*/
const reading_t& getLatestValue() const { return _latestValue; }
void setDelta(const bool delta) { _delta = delta; }
void setName(const std::string& name, int cpuID=-1) { _name = formatName(name, cpuID); }
......
Supports Markdown
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