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

Commit d8b0a672 authored by Michael Ott's avatar Michael Ott
Browse files

Remove factor parameter from BACnet and IPMI plugins and introduce a generic...

Remove factor parameter from BACnet and IPMI plugins and introduce a generic factor parameter in SensorBase
parent 5cfee0d8
...@@ -52,6 +52,7 @@ public: ...@@ -52,6 +52,7 @@ public:
_cacheInterval(900000), _cacheInterval(900000),
_subsamplingFactor(1), _subsamplingFactor(1),
_subsamplingIndex(0), _subsamplingIndex(0),
_factor(1),
_cache(nullptr), _cache(nullptr),
_delta(false), _delta(false),
_deltaMax(LLONG_MAX), _deltaMax(LLONG_MAX),
...@@ -79,6 +80,7 @@ public: ...@@ -79,6 +80,7 @@ public:
_cacheInterval(other._cacheInterval), _cacheInterval(other._cacheInterval),
_subsamplingFactor(other._subsamplingFactor), _subsamplingFactor(other._subsamplingFactor),
_subsamplingIndex(0), _subsamplingIndex(0),
_factor(other._factor),
_cache(nullptr), _cache(nullptr),
_delta(other._delta), _delta(other._delta),
_deltaMax(other._deltaMax), _deltaMax(other._deltaMax),
...@@ -103,6 +105,7 @@ public: ...@@ -103,6 +105,7 @@ public:
_cacheInterval = other._cacheInterval; _cacheInterval = other._cacheInterval;
_subsamplingFactor = other._subsamplingFactor; _subsamplingFactor = other._subsamplingFactor;
_subsamplingIndex = 0; _subsamplingIndex = 0;
_factor = other._factor;
_cache.reset(nullptr); _cache.reset(nullptr);
_delta = other._delta; _delta = other._delta;
_deltaMax = other._deltaMax; _deltaMax = other._deltaMax;
...@@ -132,6 +135,8 @@ public: ...@@ -132,6 +135,8 @@ public:
bool getDelta() const { return _delta; } bool getDelta() const { return _delta; }
unsigned getCacheInterval() const { return _cacheInterval; } unsigned getCacheInterval() const { return _cacheInterval; }
int getSubsampling() const { return _subsamplingFactor; } int getSubsampling() const { return _subsamplingFactor; }
double getFactor() const { return _factor; }
const CacheEntry* const getCache() const { return _cache.get(); } const CacheEntry* const getCache() const { return _cache.get(); }
const reading_t& getLatestValue() const { return _latestValue; } const reading_t& getLatestValue() const { return _latestValue; }
const bool isInit() const { return _cache && _readingQueue; } const bool isInit() const { return _cache && _readingQueue; }
...@@ -150,6 +155,7 @@ public: ...@@ -150,6 +155,7 @@ public:
void setMqtt(const std::string& mqtt) { _mqtt = mqtt; } void setMqtt(const std::string& mqtt) { _mqtt = mqtt; }
void setCacheInterval(unsigned cacheInterval) { _cacheInterval = cacheInterval; } void setCacheInterval(unsigned cacheInterval) { _cacheInterval = cacheInterval; }
void setSubsampling(int factor) { _subsamplingFactor = factor; } void setSubsampling(int factor) { _subsamplingFactor = factor; }
void setFactor(const double &factor) { _factor = factor; }
void setLastRaw(int64_t raw) { _lastRawValue.value = raw; } void setLastRaw(int64_t raw) { _lastRawValue.value = raw; }
void setLastURaw(uint64_t raw) { _lastRawUValue.value = raw; } void setLastURaw(uint64_t raw) { _lastRawUValue.value = raw; }
...@@ -186,9 +192,9 @@ public: ...@@ -186,9 +192,9 @@ public:
if( _delta ) { if( _delta ) {
if (!_firstReading) { if (!_firstReading) {
if (rawReading.value < _lastRawValue.value) if (rawReading.value < _lastRawValue.value)
reading.value = (rawReading.value + ((int64_t)_deltaMax - _lastRawValue.value)) * factor; reading.value = (rawReading.value + ((int64_t)_deltaMax - _lastRawValue.value)) * factor * _factor;
else else
reading.value = (rawReading.value - _lastRawValue.value) * factor; reading.value = (rawReading.value - _lastRawValue.value) * factor * _factor;
} else { } else {
_firstReading = false; _firstReading = false;
_lastRawValue = rawReading; _lastRawValue = rawReading;
...@@ -197,7 +203,7 @@ public: ...@@ -197,7 +203,7 @@ public:
_lastRawValue = rawReading; _lastRawValue = rawReading;
} }
else else
reading.value = rawReading.value * factor; reading.value = rawReading.value * factor * _factor;
storeReadingLocal(reading); storeReadingLocal(reading);
if (storeGlobal) { if (storeGlobal) {
...@@ -285,6 +291,7 @@ public: ...@@ -285,6 +291,7 @@ public:
if (getSubsampling() != 1) { if (getSubsampling() != 1) {
LOG_VAR(ll) << leading << " SubSampling: " << getSubsampling(); LOG_VAR(ll) << leading << " SubSampling: " << getSubsampling();
} }
LOG_VAR(ll) << leading << " Factor: " << _factor;
LOG_VAR(ll) << leading << " Skip const values: " << (_skipConstVal ? "true" : "false"); LOG_VAR(ll) << leading << " Skip const values: " << (_skipConstVal ? "true" : "false");
LOG_VAR(ll) << leading << " Store delta only: " << (_delta ? "true" : "false"); LOG_VAR(ll) << leading << " Store delta only: " << (_delta ? "true" : "false");
if(_delta) { if(_delta) {
...@@ -302,6 +309,7 @@ protected: ...@@ -302,6 +309,7 @@ protected:
unsigned int _cacheInterval; unsigned int _cacheInterval;
int _subsamplingFactor; int _subsamplingFactor;
unsigned int _subsamplingIndex; unsigned int _subsamplingIndex;
double _factor;
std::unique_ptr<CacheEntry> _cache; std::unique_ptr<CacheEntry> _cache;
bool _delta; bool _delta;
uint64_t _deltaMax; uint64_t _deltaMax;
......
...@@ -308,6 +308,8 @@ class ConfiguratorTemplate : public ConfiguratorInterface { ...@@ -308,6 +308,8 @@ class ConfiguratorTemplate : public ConfiguratorInterface {
sBase.setDeltaMaxValue(std::stoull(val.second.data())); sBase.setDeltaMaxValue(std::stoull(val.second.data()));
} else if (boost::iequals(val.first, "subSampling")) { } else if (boost::iequals(val.first, "subSampling")) {
sBase.setSubsampling(std::stoi(val.second.data())); sBase.setSubsampling(std::stoi(val.second.data()));
} else if (boost::iequals(val.first, "factor")) {
sBase.setFactor(std::stod(val.second.data()));
} else if (boost::iequals(val.first, "publish")) { } else if (boost::iequals(val.first, "publish")) {
sBase.setPublish(to_bool(val.second.data())); sBase.setPublish(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "metadata")) { } else if (boost::iequals(val.first, "metadata")) {
......
...@@ -44,7 +44,6 @@ void BACnetConfigurator::sensorBase(BACnetSensorBase &s, CFG_VAL config) { ...@@ -44,7 +44,6 @@ void BACnetConfigurator::sensorBase(BACnetSensorBase &s, CFG_VAL config) {
ATTRIBUTE("objectInstance", setObjectInstance); ATTRIBUTE("objectInstance", setObjectInstance);
ATTRIBUTE("objectType", setObjectType); ATTRIBUTE("objectType", setObjectType);
ATTRIBUTE("id", setPropertyId); ATTRIBUTE("id", setPropertyId);
ATTRIBUTE("factor", setFactor);
} }
} }
......
...@@ -50,7 +50,6 @@ class BACnetSensorBase : public SensorBase { ...@@ -50,7 +50,6 @@ class BACnetSensorBase : public SensorBase {
public: public:
BACnetSensorBase(const std::string &name) BACnetSensorBase(const std::string &name)
: SensorBase(name), : SensorBase(name),
_factor(1),
_objectInstance(0) { _objectInstance(0) {
_objectType = OBJECT_DEVICE; _objectType = OBJECT_DEVICE;
_propertyId = PROP_PRESENT_VALUE; _propertyId = PROP_PRESENT_VALUE;
...@@ -59,7 +58,6 @@ class BACnetSensorBase : public SensorBase { ...@@ -59,7 +58,6 @@ class BACnetSensorBase : public SensorBase {
BACnetSensorBase(const BACnetSensorBase &other) BACnetSensorBase(const BACnetSensorBase &other)
: SensorBase(other), : SensorBase(other),
_factor(other._factor),
_objectInstance(other._objectInstance), _objectInstance(other._objectInstance),
_objectType(other._objectType), _objectType(other._objectType),
_propertyId(other._propertyId), _propertyId(other._propertyId),
...@@ -69,7 +67,6 @@ class BACnetSensorBase : public SensorBase { ...@@ -69,7 +67,6 @@ class BACnetSensorBase : public SensorBase {
BACnetSensorBase &operator=(const BACnetSensorBase &other) { BACnetSensorBase &operator=(const BACnetSensorBase &other) {
SensorBase::operator=(other); SensorBase::operator=(other);
_factor = other._factor;
_objectInstance = other._objectInstance; _objectInstance = other._objectInstance;
_objectType = other._objectType; _objectType = other._objectType;
_propertyId = other._propertyId; _propertyId = other._propertyId;
...@@ -78,13 +75,11 @@ class BACnetSensorBase : public SensorBase { ...@@ -78,13 +75,11 @@ class BACnetSensorBase : public SensorBase {
return *this; return *this;
} }
double getFactor() const { return _factor; }
uint32_t getObjectInstance() const { return _objectInstance; } uint32_t getObjectInstance() const { return _objectInstance; }
BACNET_OBJECT_TYPE getObjectType() const { return _objectType; } BACNET_OBJECT_TYPE getObjectType() const { return _objectType; }
BACNET_PROPERTY_ID getPropertyId() const { return _propertyId; } BACNET_PROPERTY_ID getPropertyId() const { return _propertyId; }
int32_t getObjectIndex() const { return _objectIndex; } int32_t getObjectIndex() const { return _objectIndex; }
void setFactor(const std::string &factor) { _factor = std::stod(factor); }
void setObjectInstance(const std::string &objectInstance) { _objectInstance = stoul(objectInstance); } void setObjectInstance(const std::string &objectInstance) { _objectInstance = stoul(objectInstance); }
void setObjectType(const std::string &objectType) { _objectType = static_cast<BACNET_OBJECT_TYPE>(stoul(objectType)); } void setObjectType(const std::string &objectType) { _objectType = static_cast<BACNET_OBJECT_TYPE>(stoul(objectType)); }
void setPropertyId(const std::string &property) { _propertyId = static_cast<BACNET_PROPERTY_ID>(stoul(property)); } void setPropertyId(const std::string &property) { _propertyId = static_cast<BACNET_PROPERTY_ID>(stoul(property)); }
...@@ -92,7 +87,6 @@ class BACnetSensorBase : public SensorBase { ...@@ -92,7 +87,6 @@ class BACnetSensorBase : public SensorBase {
void printConfig(LOG_LEVEL ll, LOGGER &lg, unsigned leadingSpaces = 16) override { void printConfig(LOG_LEVEL ll, LOGGER &lg, unsigned leadingSpaces = 16) override {
std::string leading(leadingSpaces, ' '); std::string leading(leadingSpaces, ' ');
LOG_VAR(ll) << leading << " Factor: " << _factor;
LOG_VAR(ll) << leading << " objectInstance: " << _objectInstance; LOG_VAR(ll) << leading << " objectInstance: " << _objectInstance;
LOG_VAR(ll) << leading << " objectType: " << _objectType; LOG_VAR(ll) << leading << " objectType: " << _objectType;
LOG_VAR(ll) << leading << " propertyId: " << _propertyId; LOG_VAR(ll) << leading << " propertyId: " << _propertyId;
...@@ -100,7 +94,6 @@ class BACnetSensorBase : public SensorBase { ...@@ -100,7 +94,6 @@ class BACnetSensorBase : public SensorBase {
} }
protected: protected:
double _factor;
uint32_t _objectInstance; uint32_t _objectInstance;
BACNET_OBJECT_TYPE _objectType; BACNET_OBJECT_TYPE _objectType;
BACNET_PROPERTY_ID _propertyId; BACNET_PROPERTY_ID _propertyId;
......
...@@ -56,7 +56,7 @@ void BACnetSensorGroup::read() { ...@@ -56,7 +56,7 @@ void BACnetSensorGroup::read() {
#ifdef DEBUG #ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\""; LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\"";
#endif #endif
s->storeReading(reading, s->getFactor()); s->storeReading(reading);
} catch (const std::exception &e) { } catch (const std::exception &e) {
LOG(error) << _groupName << "::" << s->getName() << " could not read value: " << e.what(); LOG(error) << _groupName << "::" << s->getName() << " could not read value: " << e.what();
continue; continue;
......
...@@ -62,7 +62,6 @@ void IPMIConfigurator::sensorBase(IPMISensorBase &s, CFG_VAL config) { ...@@ -62,7 +62,6 @@ void IPMIConfigurator::sensorBase(IPMISensorBase &s, CFG_VAL config) {
ATTRIBUTE("lsb", setLsb); ATTRIBUTE("lsb", setLsb);
ATTRIBUTE("msb", setMsb); ATTRIBUTE("msb", setMsb);
ATTRIBUTE("recordId", setRecordId); ATTRIBUTE("recordId", setRecordId);
ATTRIBUTE("factor", setFactor);
ATTRIBUTE("type", setType); ATTRIBUTE("type", setType);
} }
......
...@@ -56,7 +56,6 @@ class IPMISensorBase : public SensorBase { ...@@ -56,7 +56,6 @@ class IPMISensorBase : public SensorBase {
: SensorBase(name), : SensorBase(name),
_type(undefined), _type(undefined),
_recordId(0), _recordId(0),
_factor(1),
_lsb(0), _lsb(0),
_msb(0) {} _msb(0) {}
...@@ -65,7 +64,6 @@ class IPMISensorBase : public SensorBase { ...@@ -65,7 +64,6 @@ class IPMISensorBase : public SensorBase {
_type(other._type), _type(other._type),
_recordId(other._recordId), _recordId(other._recordId),
_sdrRecord(other._sdrRecord), _sdrRecord(other._sdrRecord),
_factor(other._factor),
_rawCmd(other._rawCmd), _rawCmd(other._rawCmd),
_lsb(other._lsb), _lsb(other._lsb),
_msb(other._msb) {} _msb(other._msb) {}
...@@ -77,7 +75,6 @@ class IPMISensorBase : public SensorBase { ...@@ -77,7 +75,6 @@ class IPMISensorBase : public SensorBase {
_type = other._type; _type = other._type;
_recordId = other._recordId; _recordId = other._recordId;
_sdrRecord = other._sdrRecord; _sdrRecord = other._sdrRecord;
_factor = other._factor;
_rawCmd = other._rawCmd; _rawCmd = other._rawCmd;
_lsb = other._lsb; _lsb = other._lsb;
_msb = other._msb; _msb = other._msb;
...@@ -97,7 +94,6 @@ class IPMISensorBase : public SensorBase { ...@@ -97,7 +94,6 @@ class IPMISensorBase : public SensorBase {
uint16_t getRecordId() const { return _recordId; } uint16_t getRecordId() const { return _recordId; }
const std::vector<uint8_t> &getSdrRecord() const { return _sdrRecord; } const std::vector<uint8_t> &getSdrRecord() const { return _sdrRecord; }
double getFactor() const { return _factor; }
const std::vector<uint8_t> &getRawCmd() const { return _rawCmd; } const std::vector<uint8_t> &getRawCmd() const { return _rawCmd; }
std::string getRawCmdString() const { std::string getRawCmdString() const {
std::stringstream ss; std::stringstream ss;
...@@ -134,7 +130,6 @@ class IPMISensorBase : public SensorBase { ...@@ -134,7 +130,6 @@ class IPMISensorBase : public SensorBase {
_type = sdr; _type = sdr;
} }
void setSdrRecord(const std::vector<uint8_t> &sdrRecord) { _sdrRecord = sdrRecord; } void setSdrRecord(const std::vector<uint8_t> &sdrRecord) { _sdrRecord = sdrRecord; }
void setFactor(const std::string &factor) { _factor = stod(factor); }
void setRawCmd(std::string &rawCmd) { void setRawCmd(std::string &rawCmd) {
boost::regex expr("(?:0x)?([0-9a-fA-F]+)"); boost::regex expr("(?:0x)?([0-9a-fA-F]+)");
boost::regex_token_iterator<std::string::iterator> it{rawCmd.begin(), rawCmd.end(), expr, 1}; boost::regex_token_iterator<std::string::iterator> it{rawCmd.begin(), rawCmd.end(), expr, 1};
...@@ -181,14 +176,12 @@ class IPMISensorBase : public SensorBase { ...@@ -181,14 +176,12 @@ class IPMISensorBase : public SensorBase {
default: default:
break; break;
} }
LOG_VAR(ll) << leading << " Factor: " << _factor;
} }
protected: protected:
sensorType _type; sensorType _type;
uint16_t _recordId; uint16_t _recordId;
std::vector<uint8_t> _sdrRecord; std::vector<uint8_t> _sdrRecord;
double _factor;
std::vector<uint8_t> _rawCmd; std::vector<uint8_t> _rawCmd;
uint8_t _lsb; uint8_t _lsb;
......
...@@ -120,7 +120,7 @@ void IPMISensorGroup::read() { ...@@ -120,7 +120,7 @@ void IPMISensorGroup::read() {
LenovoXCC xcc(_entity); LenovoXCC xcc(_entity);
if (_entity->getXCC()->getDatastorePower(readings) == 0) { if (_entity->getXCC()->getDatastorePower(readings) == 0) {
for (unsigned int i=0; i<readings.size(); i++) { for (unsigned int i=0; i<readings.size(); i++) {
s->storeReading(readings[i], s->getFactor()); s->storeReading(readings[i]);
} }
reading = readings.back(); reading = readings.back();
} }
...@@ -128,7 +128,7 @@ void IPMISensorGroup::read() { ...@@ -128,7 +128,7 @@ void IPMISensorGroup::read() {
} }
case IPMISensorBase::sensorType::xccSingleEnergy: { case IPMISensorBase::sensorType::xccSingleEnergy: {
if (_entity->getXCC()->getSingleEnergy(reading) == 0) { if (_entity->getXCC()->getSingleEnergy(reading) == 0) {
s->storeReading(reading, s->getFactor()); s->storeReading(reading);
} }
break; break;
} }
...@@ -136,7 +136,7 @@ void IPMISensorGroup::read() { ...@@ -136,7 +136,7 @@ void IPMISensorGroup::read() {
std::vector<reading_t> readings; std::vector<reading_t> readings;
if (_entity->getXCC()->getBulkPower(readings) == 0) { if (_entity->getXCC()->getBulkPower(readings) == 0) {
for (unsigned int i=0; i<readings.size(); i++) { for (unsigned int i=0; i<readings.size(); i++) {
s->storeReading(readings[i], s->getFactor()); s->storeReading(readings[i]);
} }
reading = readings.back(); reading = readings.back();
} }
...@@ -146,7 +146,7 @@ void IPMISensorGroup::read() { ...@@ -146,7 +146,7 @@ void IPMISensorGroup::read() {
std::vector<reading_t> readings; std::vector<reading_t> readings;
if (_entity->getXCC()->getBulkEnergy(readings) == 0) { if (_entity->getXCC()->getBulkEnergy(readings) == 0) {
for (unsigned int i=0; i<readings.size(); i++) { for (unsigned int i=0; i<readings.size(); i++) {
s->storeReading(readings[i], s->getFactor()); s->storeReading(readings[i]);
} }
reading = readings.back(); reading = readings.back();
} }
...@@ -159,12 +159,12 @@ void IPMISensorGroup::read() { ...@@ -159,12 +159,12 @@ void IPMISensorGroup::read() {
s->setSdrRecord(sdrRecord); s->setSdrRecord(sdrRecord);
} }
reading.value = _entity->readSensorRecord(sdrRecord); reading.value = _entity->readSensorRecord(sdrRecord);
s->storeReading(reading, s->getFactor()); s->storeReading(reading);
break; break;
} }
case IPMISensorBase::sensorType::raw: { case IPMISensorBase::sensorType::raw: {
reading.value = readRaw(s->getRawCmd(), s->getLsb(), s->getMsb()); reading.value = readRaw(s->getRawCmd(), s->getLsb(), s->getMsb());
s->storeReading(reading, s->getFactor()); s->storeReading(reading);
break; break;
} }
default: default:
......
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