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

Add template files for upcoming BACnet plugin

parent 6f7a286b
global {
mqttPrefix /FF112233445566778899FFFFFFFF
}
SensorTemplate {
sensor def0 {
interval 1000
mqttsuffix 0000
minValues 3
}
}
sensors {
sensor bac0 {
default def1
interval 1000
minValue 1
mqttsuffix 0000
deviceInstance 1234
; objectType 8
; objectInstance 1234
; property 85
}
sensor bac1 {
deviceInstance 4321
interval 1000
mqttsuffix 0001
}
}
......@@ -29,4 +29,9 @@ plugins {
config
}
; plugin bacnet {
; path ./
; config
; }
}
/*
* BACnetConfigurator.cpp
*
* Created on: 14.04.2018
* Author: Micha Mueller
*/
#include "BACnetConfigurator.h"
BACnetConfigurator::BACnetConfigurator() {
// TODO Auto-generated constructor stub
}
BACnetConfigurator::~BACnetConfigurator() {
for(auto s : _sensors) {
delete s;
}
}
std::vector<Sensor*>& BACnetConfigurator::readConfig(std::string cfgPath) {
//TODO
return _sensors;
}
void BACnetConfigurator::readSensor(BACnetSensor& sensor, boost::property_tree::iptree& config) {
//TODO
}
/*
* BACnetConfigurator.h
*
* Created on: 14.04.2018
* Author: Micha Mueller
*/
#ifndef BACNETCONFIGURATOR_H_
#define BACNETCONFIGURATOR_H_
#include "BACnetSensor.h"
#include "../../Configurator.h"
#include <string>
#include <vector>
#include <map>
#include <boost/property_tree/ptree.hpp>
class BACnetConfigurator: public Configurator {
typedef std::map<std::string, BACnetSensor> sensorMap_t;
public:
BACnetConfigurator();
virtual ~BACnetConfigurator();
/**
* Read in the configuration for BACnet-sensors.
* @param cfgPath Path + name of the config-file
*/
std::vector<Sensor*>& readConfig(std::string cfgPath);
private:
/**
* Set the variables of sensor according to the values specified in config.
* @param sensor The sensor to be configured
* @param config A property(sub)tree containing the values
*/
void readSensor(BACnetSensor& sensor, boost::property_tree::iptree& config);
std::vector<Sensor*> _sensors;
sensorMap_t _templateSensors;
};
extern "C" Configurator* create() {
return new BACnetConfigurator;
}
extern "C" void destroy(Configurator* c) {
delete c;
}
#endif /* BACNETCONFIGURATOR_H_ */
/*
* BACnetSensor.cpp
*
* Created on: 14.04.2018
* Author: Micha Mueller
*/
#include "BACnetSensor.h"
#include "timestamp.h"
#include <functional>
extern volatile int keepRunning;
BACnetSensor::BACnetSensor(const std::string& name) :
Sensor(name) {
_deviceInstance = 0;
}
BACnetSensor::~BACnetSensor() {
// TODO Auto-generated destructor stub
}
void BACnetSensor::read() {
//TODO
}
void BACnetSensor::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer != NULL && keepRunning) {
uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next));
_timer->async_wait(std::bind(&BACnetSensor::readAsync, this));
}
}
void BACnetSensor::startPolling(boost::asio::io_service& io) {
if (!_readingQueue) {
_readingQueue = new boost::lockfree::spsc_queue<reading_t>(1024);
}
_timer = new boost::asio::deadline_timer(io, boost::posix_time::seconds(0));
_timer->async_wait(std::bind(&BACnetSensor::readAsync, this));
}
/*
* BACnetSensor.h
*
* Created on: 14.04.2018
* Author: Micha Mueller
*/
#ifndef BACNETSENSOR_H_
#define BACNETSENSOR_H_
#include "../../Sensor.h"
class BACnetSensor: public Sensor {
public:
BACnetSensor(const std::string& name);
virtual ~BACnetSensor();
uint32_t getDeviceInstance() const {
return _deviceInstance;
}
void setDeviceInstance(uint32_t deviceInstance) {
_deviceInstance = deviceInstance;
}
void read();
void readAsync();
void startPolling(boost::asio::io_service& io);
private:
uint32_t _deviceInstance;
};
#endif /* BACNETSENSOR_H_ */
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