Commit 15b6fed0 authored by Michael Ott's avatar Michael Ott
Browse files

Make IPMIHost::sendRawCmd() generic and move the actual parsing of the...

Make IPMIHost::sendRawCmd() generic and move the actual parsing of the response to IPMISensorGroup::readRaw()
parent c9a05aff
......@@ -201,8 +201,7 @@ bool IPMIHost::getSdrRecord(uint16_t recordId, std::vector<uint8_t>& record) {
return success;
}
int64_t IPMIHost::sendRawCmd(const std::vector<uint8_t>& rawCmd, uint8_t lsb, uint8_t msb) {
uint8_t buf[256];
int IPMIHost::sendRawCmd(const uint8_t* rawCmd, unsigned int rawCmdLen, void* buf, unsigned int bufLen) {
int len = -1;
int i;
......@@ -215,7 +214,7 @@ int64_t IPMIHost::sendRawCmd(const std::vector<uint8_t>& rawCmd, uint8_t lsb, ui
int retries = RETRIES;
while (retries-- && !success) {
if (connect() == 0) {
if ((len = ipmi_cmd_raw(_ipmiCtx, rawCmd[0], rawCmd[1], &rawCmd[2], rawCmd.size() - 2, buf, sizeof(buf))) < 0) {
if ((len = ipmi_cmd_raw(_ipmiCtx, rawCmd[0], rawCmd[1], &rawCmd[2], rawCmdLen - 2, buf, bufLen)) < 0) {
_errorMsg = "Error sending IPMI raw command: " + std::string(ipmi_ctx_errormsg(_ipmiCtx));
increaseErrorCount();
disconnect();
......@@ -238,34 +237,11 @@ int64_t IPMIHost::sendRawCmd(const std::vector<uint8_t>& rawCmd, uint8_t lsb, ui
if (!success) {
throw std::runtime_error(_errorMsg);
return 0;
}
std::stringstream ss;
if (msb > len) {
ss << "Error processing IPMI raw data: msb=" << msb << " > len=" << len;
} else if (lsb > len) {
ss << "Error processing IPMI raw data: lsb=" << lsb << " > len=" << len;
}
if (ss.gcount() > 0) {
throw std::runtime_error(ss.str());
return 0;
}
_errorCount = 0;
int64_t val = 0;
if (msb > lsb) {
for (i = lsb; i <= msb; i++) {
val |= ((int64_t) buf[i]) << (msb - i) * 8;
}
} else {
for (i = lsb; i >= msb; i--) {
val |= ((int64_t) buf[i]) << (i-msb) * 8;
}
return -1;
}
return val;
_errorCount = 0;
return len;
}
double IPMIHost::readSensorRecord(std::vector<uint8_t>& record) {
......
......@@ -49,7 +49,7 @@ public:
/* Translate recordId to SDR record */
bool getSdrRecord(uint16_t recordId, std::vector<uint8_t>& record);
/* Send raw command to BMC. Returns sensor reading as responded by BMC. */
int64_t sendRawCmd(const std::vector<uint8_t>& rawCmd, uint8_t lsb, uint8_t msb);
int sendRawCmd(const uint8_t* rawCmd, unsigned int rawCmdLen, void* buf, unsigned int bufLen);
/* Read the sensor specified by its record id. Returns sensor reading. */
double readSensorRecord(std::vector<uint8_t>& record);
......
......@@ -49,6 +49,43 @@ IPMISensorGroup& IPMISensorGroup::operator=(const IPMISensorGroup& other) {
return *this;
}
uint64_t IPMISensorGroup::readRaw(const std::vector<uint8_t>& rawCmd, uint8_t lsb, uint8_t msb) {
uint8_t buf[256];
int len = -1;
try {
len = _entity->sendRawCmd(&rawCmd[0], rawCmd.size(), (void *) buf, sizeof(buf));
} catch (const std::exception& e) {
throw e;
return 0;
}
std::stringstream ss;
if (msb > len) {
ss << "Error processing IPMI raw data: msb=" << msb << " > len=" << len;
} else if (lsb > len) {
ss << "Error processing IPMI raw data: lsb=" << lsb << " > len=" << len;
}
if (ss.gcount() > 0) {
throw std::runtime_error(ss.str());
return 0;
}
int64_t val = 0;
int i;
if (msb > lsb) {
for (i = lsb; i <= msb; i++) {
val |= ((int64_t) buf[i]) << (msb - i) * 8;
}
} else {
for (i = lsb; i >= msb; i--) {
val |= ((int64_t) buf[i]) << (i-msb) * 8;
}
}
return val;
}
void IPMISensorGroup::read() {
reading_t reading;
reading.timestamp = getTimestamp();
......@@ -71,7 +108,7 @@ void IPMISensorGroup::read() {
}
reading.value = _entity->readSensorRecord(sdrRecord);
} else { /* use raw command */
reading.value = _entity->sendRawCmd(s->getRawCmd(), s->getLsb(), s->getMsb());
reading.value = readRaw(s->getRawCmd(), s->getLsb(), s->getMsb());
}
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\"";
......
......@@ -46,6 +46,7 @@ public:
private:
void read() final override;
uint64_t readRaw(const std::vector<uint8_t>& rawCmd, uint8_t lsb, uint8_t msb);
};
#endif /* IPMISENSORGROUP_H_ */
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