Commit 3b257c4d authored by Micha Mueller's avatar Micha Mueller
Browse files

Add empty template for new PDU-sensors (XML)

parent e4ebdb39
global {
mqttprefix /00112233445566778899AABBCCDD
}
SensorTemplate {
sensor def1 {
interval 1000
clustsafeID 2
minValues 3
}
}
pdus {
pdu rack1 {
networkAddress ?
cooldown 500 //Time interval at which the energy.xml is refreshed. If empty use smallest sensor-interval
mqttprefix ? //give every pdu own prefix (like IPMI-hosts)?
total {
interval 500
mqttsuffix 0000
minValues 1
}
sensors {
sensor pcs1 {
interval 2000
clustsafeID 1
outletID 1
mqttsuffix 0001
}
sensor pcs2 {
default def1
outletID 3
mqttsuffix 0002
}
sensor pcs3 {
default def1
outletID 4
mqttsuffix 0003
}
}
}
pdu rack2 {
....
}
}
/*
* PDUConfigurator.cpp
*
* Created on: 24.02.2018
* Author: Micha Mueller
*/
#include "PDUConfigurator.h"
#include <boost/foreach.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/algorithm/string.hpp>
PDUConfigurator::PDUConfigurator() {
// TODO Auto-generated constructor stub
}
PDUConfigurator::~PDUConfigurator() {
for (auto s : _sensors) {
delete s;
}
}
std::vector<Sensor*>& PDUConfigurator::readConfig(std::string cfgPath) {
return _sensors;
}
bool PDUConfigurator::readSensor(PDUSensor& sensor, boost::property_tree::iptree& config) {
return 0;
}
/*
* PDUConfigurator.h
*
* Created on: 24.02.2018
* Author: Micha Mueller
*/
#include "PDUSensor.h"
#include "../../Configurator.h"
#include <string>
#include <vector>
#include <map>
#include <boost/property_tree/ptree.hpp>
#ifndef SRC_SENSORS_PDU_PDUCONFIGURATOR_H_
#define SRC_SENSORS_PDU_PDUCONFIGURATOR_H_
class PDUConfigurator: public Configurator {
typedef std::map<std::string, PDUSensor> sensorMap_t;
public:
PDUConfigurator();
virtual ~PDUConfigurator();
/**
* Read in the configuration for PDU-sensors.
* @param cfgPath Path + name of the config-file
* @return Vector with pointers to every created sensors
*/
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
*/
bool readSensor(PDUSensor& sensor, boost::property_tree::iptree& config);
std::vector<Sensor*> _sensors;
sensorMap_t _templateSensors;
};
extern "C" Configurator* create() {
return new PDUConfigurator;
}
extern "C" void destroy(Configurator* c) {
delete c;
}
#endif /* SRC_SENSORS_PDU_PDUCONFIGURATOR_H_ */
/*
* PDUSensor.cpp
*
* Created on: 24.02.2018
* Author: Micha Mueller
*/
#include "PDUSensor.h"
#include "timestamp.h"
//#include <functional>
PDUSensor::PDUSensor(const std::string& name) :
Sensor(name) {
_clustsafeID = 0;
_outletID = 0;
}
PDUSensor::~PDUSensor() {
// TODO Auto-generated destructor stub
}
void PDUSensor::read() {
//TODO
}
void PDUSensor::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(&PDUSensor::readAsync, this));
}
}
void PDUSensor::startPolling(boost::asio::io_service& io) {
if(!_readingQueue) {
_readingQueue = new boost::lockfree::spsc_queue<reading_t>(1024);
}
//TODO
_timer = new boost::asio::deadline_timer(io, boost::posix_time::seconds(0));
_timer->async_wait(std::bind(&PDUSensor::readAsync, this));
}
/*
* PDUSensor.h
*
* Created on: 24.02.2018
* Author: Micha Mueller
*/
#ifndef SRC_SENSORS_PDU_PDUSENSOR_H_
#define SRC_SENSORS_PDU_PDUSENSOR_H_
#include "../../Sensor.h"
class PDUSensor: public Sensor {
public:
PDUSensor(const std::string& name);
virtual ~PDUSensor();
void setClustsafeID(unsigned clustsafeID) {
_clustsafeID = clustsafeID;
}
unsigned getClustsafeID() const {
return _clustsafeID;
}
void setOutletID(unsigned outletID) {
_outletID = outletID;
}
unsigned getOutletID() const {
return _outletID;
}
void read();
void readAsync();
void startPolling(boost::asio::io_service& io);
private:
unsigned int _clustsafeID;
unsigned int _outletID;
};
#endif /* SRC_SENSORS_PDU_PDUSENSOR_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