Commit 214281cf authored by Michael Ott's avatar Michael Ott

Rename xcc sensor to xccBulkPower, move code for reading it from...

Rename xcc sensor to xccBulkPower, move code for reading it from IPMISensorGroup::read() to LenovoXCC::getBulkPower()
parent 509f1b0f
......@@ -89,7 +89,7 @@ class IPMISensorBase : public SensorBase {
undefined = 0,
raw,
sdr,
xcc
xccBulkPower
};
uint16_t getRecordId() const { return _recordId; }
......@@ -113,8 +113,8 @@ class IPMISensorBase : public SensorBase {
return std::string("raw");
case sdr:
return std::string("sdr");
case xcc:
return std::string("xcc");
case xccBulkPower:
return std::string("xccBulkPower");
default:
return std::string("undefined");
}
......@@ -144,8 +144,8 @@ class IPMISensorBase : public SensorBase {
_type = raw;
} else if (boost::iequals(type, "sdr")) {
_type = sdr;
} else if (boost::iequals(type, "xcc")) {
_type = xcc;
} else if (boost::iequals(type, "xccBulkPower")) {
_type = xccBulkPower;
} else {
_type = undefined;
}
......
......@@ -100,29 +100,12 @@ void IPMISensorGroup::read() {
for (const auto &s : _sensors) {
try {
if (s->getType() == IPMISensorBase::sensorType::xcc) {
if (s->getType() == IPMISensorBase::sensorType::xccBulkPower) {
std::vector<reading_t> readings(3000);
LenovoXCC xcc(_entity);
if (xcc.openDatastore() == 0) {
uint64_t ts1, ts2;
std::vector<uint16_t> readings;
if ((ts1 = xcc.readDatastoreTimestamp()) > 0) {
if (xcc.readDatastorePower(readings) == 0) {
// Check whether the timestamp changed during readDatastorePower() and re-read if it did
ts2 = xcc.readDatastoreTimestamp();
if (ts2 > ts1) {
xcc.readDatastorePower(readings);
ts1 = ts2;
}
}
xcc.closeDatastore();
}
ts1 += xcc.getDrift();
for (unsigned int i = 0; i < readings.size(); i++) {
reading.timestamp = ts1 + MS_TO_NS(i * 10);
reading.value = readings[i];
s->storeReading(reading, s->getFactor());
// LOG(debug) << _groupName << "::" << s->getName() << " xcc: " << i << " " << reading.timestamp << " " << reading.value;
}
int count = xcc.getBulkPower(readings);
for (int i=0; i<count; i++) {
s->storeReading(readings[i], s->getFactor());
}
} else {
if (s->getType() == IPMISensorBase::sensorType::sdr) {
......@@ -148,7 +131,7 @@ void IPMISensorGroup::read() {
}
uint64_t IPMISensorGroup::nextReadingTime() {
if ((_sensors.size() == 1) && (_sensors.front()->getType() == IPMISensorBase::sensorType::xcc)) {
if ((_sensors.size() == 1) && (_sensors.front()->getType() == IPMISensorBase::sensorType::xccBulkPower)) {
reading_t r = _sensors.front()->getLatestValue();
uint64_t now = getTimestamp();
......@@ -167,7 +150,7 @@ uint64_t IPMISensorGroup::nextReadingTime() {
bool IPMISensorGroup::checkConfig() {
if (_sensors.size() > 1) {
for (const auto &s : _sensors) {
if (s->getType() == IPMISensorBase::sensorType::xcc) {
if (s->getType() == IPMISensorBase::sensorType::xccBulkPower) {
LOG(error) << _groupName << " contains an XCC sensor among others, this is not possible";
return false;
}
......
......@@ -175,7 +175,7 @@ uint64_t LenovoXCC::readDatastoreTimestamp() {
}
}
int LenovoXCC::readDatastorePower(std::vector<uint16_t> &readings) {
int LenovoXCC::readDatastorePower(std::vector<uint16_t> &rawReadings) {
uint8_t buf[256];
try {
for (uint16_t offset = 16; offset < 6016; offset += 200) {
......@@ -183,7 +183,7 @@ int LenovoXCC::readDatastorePower(std::vector<uint16_t> &readings) {
if (len >= 0) {
uint16_t n = (buf[5] | buf[6] << 8) / 2;
uint16_t *buf16 = (uint16_t *)&buf[7];
readings.insert(readings.end(), buf16, buf16 + n);
rawReadings.insert(rawReadings.end(), buf16, buf16 + n);
}
}
} catch (const std::exception &e) {
......@@ -191,9 +191,36 @@ int LenovoXCC::readDatastorePower(std::vector<uint16_t> &readings) {
return 1;
}
if (readings.size()) {
if (rawReadings.size()) {
return 0;
} else {
return -1;
}
}
int LenovoXCC::getBulkPower(std::vector<reading_t> &readings) {
if (openDatastore() == 0) {
uint64_t ts1, ts2;
std::vector<uint16_t> rawReadings;
if ((ts1 = readDatastoreTimestamp()) > 0) {
if (readDatastorePower(rawReadings) == 0) {
// Check whether the timestamp changed during readDatastorePower() and re-read if it did
ts2 = readDatastoreTimestamp();
if (ts2 > ts1) {
readDatastorePower(rawReadings);
ts1 = ts2;
}
}
closeDatastore();
}
ts1 += getDrift();
for (unsigned int i = 0; i < readings.size(); i++) {
readings[i].timestamp = ts1 + MS_TO_NS(i * 10);
readings[i].value = rawReadings[i];
// LOG(debug) << _groupName << "::" << s->getName() << " xcc: " << i << " " << reading.timestamp << " " << reading.value;
}
return (int) readings.size();
} else {
return 0;
}
}
......@@ -10,6 +10,7 @@
#define LenovoXCC_hpp
#include "IPMIHost.h"
#include "cacheentry.h"
#include <cstdint>
class LenovoXCC {
......@@ -19,6 +20,7 @@ class LenovoXCC {
virtual ~LenovoXCC();
int getSingleEnergy(uint64_t &timeStamp, uint64_t &energy);
int getBulkPower(std::vector<reading_t> &readings);
int64_t getDrift();
int openDatastore();
......
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