Commit d6c46ac1 authored by Micha Mueller's avatar Micha Mueller
Browse files

Add factor-option for BACnet plugin

parent 3c0f1ddf
......@@ -410,6 +410,7 @@ global {
templates {
property def0 {
factor 100
id 85
interval 1000
minValues 3
......@@ -458,6 +459,7 @@ Explanation of the values specific for the BACnet plugin:
| apdu_timeout | Value of µ-seconds before sending a request times out.
| apdu_retries | How often should sending a request be retried.
| templates | One can define template properties in this section for convenience.
| factor | Described in the section for the [IPMI-plugin](#IPMI).
| devices | Starts the part in the config file where the actual BACnet devices are configured. A BACnet device consists of multiple nested parts: device > objects > properties.
| mqttPart | One can define a partial MQTT topic on each nesting level, which will be appended to the MQTT prefix. Together with the mqttsuffix of a property this will make up the whole MQTT topic of a property (aka sensor). MQTT topic = mqttPrefix + mqttPart (device) + mqttPart (object) + mqttsuffix.
| instance (device) | Instance of the BACnet-device.
......
......@@ -8,6 +8,7 @@ global {
templates {
property def0 {
factor 100
id 85
interval 1000
minValues 3
......@@ -24,6 +25,7 @@ devices {
instance 1234
mqttPart FF
property test1 {
factor 10
default def0
mqttsuffix 0000
}
......
......@@ -17,7 +17,7 @@
#include "rp.h"
#include "tsm.h"
uint64_t BACnetClient::_presentValue;
double BACnetClient::_presentValue;
uint8_t BACnetClient::_handlerTransmitBuffer[MAX_PDU];
BACnetClient::BACnetClient() {
......@@ -64,7 +64,7 @@ void BACnetClient::init(std::string interface, unsigned port, unsigned timeout,
apdu_set_reject_handler(rejectHandler);
}
uint64_t BACnetClient::readProperty(uint32_t deviceObjInstance, uint32_t objInstance, BACNET_OBJECT_TYPE objType, BACNET_PROPERTY_ID objProperty, int32_t objIndex) {
double BACnetClient::readProperty(uint32_t deviceObjInstance, uint32_t objInstance, BACNET_OBJECT_TYPE objType, BACNET_PROPERTY_ID objProperty, int32_t objIndex) {
//TODO better use readPropertyMultiple? But how to assign the properties to multiple different MQTT topics?
uint16_t pdu_lenRec = 0;
......
......@@ -54,7 +54,7 @@ public:
*
* @throws Runtime error
*/
uint64_t readProperty(uint32_t deviceObjInstance, uint32_t objInstance = 0, BACNET_OBJECT_TYPE objType = OBJECT_DEVICE, BACNET_PROPERTY_ID objProperty = PROP_PRESENT_VALUE, int32_t objIndex = BACNET_ARRAY_ALL);
double readProperty(uint32_t deviceObjInstance, uint32_t objInstance = 0, BACNET_OBJECT_TYPE objType = OBJECT_DEVICE, BACNET_PROPERTY_ID objProperty = PROP_PRESENT_VALUE, int32_t objIndex = BACNET_ARRAY_ALL);
private:
......@@ -79,7 +79,7 @@ private:
uint8_t _invokeId; //store as member variable to enable access in handler methods
unsigned _timeout;
// static because of handler functions
static uint64_t _presentValue;
static double _presentValue;
static uint8_t _handlerTransmitBuffer[MAX_PDU];
BACNET_ADDRESS _targetAddress; //store as member variable to enable access in handler methods
......
......@@ -149,6 +149,8 @@ bool BACnetConfigurator::readSensor(BACnetSensor& sensor, boost::property_tree::
sensor.setMqtt(sensor.getMqtt() + val.second.data());
} else if (boost::iequals(val.first, "minValues")) {
sensor.setMinValues(stoull(val.second.data()));
} else if (boost::iequals(val.first, ("factor"))) {
sensor.setFactor(std::stod(val.second.data()));
} else if (boost::iequals(val.first, ("id"))) {
sensor.setPropertyId(static_cast<BACNET_PROPERTY_ID>(stoul(val.second.data())));
} else if (boost::iequals(val.first, "default")) {
......@@ -161,6 +163,7 @@ bool BACnetConfigurator::readSensor(BACnetSensor& sensor, boost::property_tree::
LOG(debug) << " MQTTtopic:" << sensor.getMqtt();
LOG(debug) << " Interval : " << sensor.getInterval();
LOG(debug) << " minValues: " << sensor.getMinValues();
LOG(debug) << " factor : " << sensor.getFactor();
LOG(debug) << " instance : " << sensor.getDeviceInstance();
LOG(debug) << " objInst : " << sensor.getObjectInstance();
LOG(debug) << " objType : " << sensor.getObjectType();
......
......@@ -11,6 +11,7 @@
BACnetSensor::BACnetSensor(const std::string& name) :
Sensor(name) {
_factor = 1;
_deviceInstance = 0;
_objectInstance = 0;
_objectType = OBJECT_DEVICE;
......@@ -28,7 +29,7 @@ void BACnetSensor::read() {
reading.timestamp = getTimestamp();
try {
reading.value = _bacClient->readProperty(_deviceInstance, _objectInstance, _objectType, _propertyId);
reading.value = _bacClient->readProperty(_deviceInstance, _objectInstance, _objectType, _propertyId) * _factor;
_readingQueue->push(reading);
_latestValue.value = reading.value;
_latestValue.timestamp = reading.timestamp;
......
......@@ -20,6 +20,14 @@ public:
virtual ~BACnetSensor();
/**** GETTERS + SETTERS ****/
void setFactor(double factor) {
_factor = factor;
}
double getFactor() const {
return _factor;
}
uint32_t getDeviceInstance() const {
return _deviceInstance;
}
......@@ -80,6 +88,8 @@ public:
void stopPolling();
private:
double _factor;
uint32_t _deviceInstance;
uint32_t _objectInstance;
BACNET_OBJECT_TYPE _objectType;
......
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