11.08., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 23c0e3df authored by Michael Ott's avatar Michael Ott

Add LenovoXCC::getBulkEnergy() function and xccBulkEnergy sensor type for...

Add LenovoXCC::getBulkEnergy() function and xccBulkEnergy sensor type for XCC's bulk energy readings
parent 758948e1
......@@ -91,7 +91,8 @@ class IPMISensorBase : public SensorBase {
sdr,
xccDatastorePower,
xccSingleEnergy,
xccBulkPower
xccBulkPower,
xccBulkEnergy
};
uint16_t getRecordId() const { return _recordId; }
......@@ -121,6 +122,8 @@ class IPMISensorBase : public SensorBase {
return std::string("xccSingleEnergy");
case xccBulkPower:
return std::string("xccBulkPower");
case xccBulkEnergy:
return std::string("xccBulkEnergy");
default:
return std::string("undefined");
}
......@@ -156,6 +159,8 @@ class IPMISensorBase : public SensorBase {
_type = xccSingleEnergy;
} else if (boost::iequals(type, "xccBulkPower")) {
_type = xccBulkPower;
} else if (boost::iequals(type, "xccBulkEnergy")) {
_type = xccBulkEnergy;
} else {
_type = undefined;
}
......
......@@ -130,6 +130,17 @@ void IPMISensorGroup::read() {
}
break;
}
case IPMISensorBase::sensorType::xccBulkEnergy: {
std::vector<reading_t> readings;
LenovoXCC xcc(_entity);
if (xcc.getBulkEnergy(readings) == 0) {
for (unsigned int i=0; i<readings.size(); i++) {
s->storeReading(readings[i], s->getFactor());
}
reading = readings[99];
}
break;
}
case IPMISensorBase::sensorType::sdr: {
std::vector<uint8_t> sdrRecord = s->getSdrRecord();
if (sdrRecord.size() == 0) {
......
......@@ -114,6 +114,53 @@ int LenovoXCC::getBulkPower(std::vector<reading_t> &readings) {
return 1;
}
int LenovoXCC::getBulkEnergy(std::vector<reading_t> &readings) {
if (_drift || getDrift() == 0) {
uint8_t buf[256];
uint8_t getBulkCmd[] = {0x00, 0x3a, 0x32, 0x04, 0x01, 0x00, 0x00, 0x00};
int len = -1;
try {
len = _host->sendRawCmd(getBulkCmd, sizeof(getBulkCmd), buf, sizeof(buf));
} catch (const std::exception &e) {
throw e;
return 1;
}
if ((len == 212) && (buf[0] == 0x32) && (buf[1] == 0x00)) {
uint32_t ts1;
uint16_t ts2;
memcpy(&ts1, &buf[2], sizeof(ts1));
memcpy(&ts2, &buf[6], sizeof(ts2));
uint64_t timeStamp = S_TO_NS(ts1);
if (ts2 < 1000) {
timeStamp += MS_TO_NS(ts2);
}
timeStamp += _drift;
uint32_t baseEnergy;
memcpy(&baseEnergy, &buf[8], sizeof(baseEnergy));
reading_t r;
r.timestamp = timeStamp;
r.value = baseEnergy;
readings.push_back(r);
uint16_t *buf16 = (uint16_t *)&buf[12];
for (int i=1; i<=100; i++) {
reading_t r;
r.timestamp = timeStamp + MS_TO_NS(i * 10);
r.value = baseEnergy + buf16[i-1];
readings.push_back(r);
}
return 0;
}
}
return 1;
}
int LenovoXCC::readSingleEnergyRaw(uint64_t &timeStamp, uint64_t &energy) {
uint8_t buf[256];
uint8_t getSingleEnergyCmd[] = {0x00, 0x3a, 0x32, 0x04, 0x02, 0x00, 0x00, 0x00};
......
......@@ -22,6 +22,7 @@ class LenovoXCC {
int getDatastorePower(std::vector<reading_t> &readings);
int getSingleEnergy(reading_t &reading);
int getBulkPower(std::vector<reading_t> &readings);
int getBulkEnergy(std::vector<reading_t> &readings);
private:
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