Commit 089a88c0 authored by Micha Mueller's avatar Micha Mueller
Browse files

Update pluginGenerator

parent 8d3ba8a1
#!/bin/sh
cat << EOF > ${PLUGIN_NAME}Attributes.h
/*
* ${PLUGIN_NAME}Attributes.h
*
* Created on: ${DATE}
* Author: ${AUTHOR}
*/
#ifndef ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}ATTRIBUTES_H_
#define ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}ATTRIBUTES_H_
class ${PLUGIN_NAME}Attributes {
public:
${PLUGIN_NAME}Attributes() :
/*
* TODO
* Initializer list for attributes
*/ {}
virtual ~${PLUGIN_NAME}Attributes() {
/*
* TODO
* Deconstruct attributes if necessary
*/
}
/*
* TODO
* Getters + Setters if required for the attributes
*/
protected:
/*
* TODO
* Add plugin specific attributes, which are only required per SingleSensor
* or SensorGroup. Attributes which are required per SensorBase go to the
* SensorBase class.
*/
};
#endif /* ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}ATTRIBUTES_H_ */
EOF
......@@ -10,133 +10,34 @@ cat << EOF > ${PLUGIN_NAME}Configurator.cpp
#include "${PLUGIN_NAME}Configurator.h"
${PLUGIN_NAME}Configurator::${PLUGIN_NAME}Configurator() {}
${PLUGIN_NAME}Configurator::~${PLUGIN_NAME}Configurator() {}
bool ${PLUGIN_NAME}Configurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
${PLUGIN_NAME}Configurator::${PLUGIN_NAME}Configurator() {
/*
* TODO
* If neccessary, read in other plugin specific stuff
* If you want sensor, group or entity to be named differently in the config file, you can change it here
*/
_groupName = "group";
_baseName = "sensor";
}
//read one sensor at a time
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("sensors")) {
if (STRCMP(sensor, "sensor")) {
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
${PLUGIN_NAME}SingleSensor* ${PLUGIN_NAME_LWC}Sensor = new ${PLUGIN_NAME}SingleSensor(sensor.second.data());
//first check if default sensor is given
boost::optional<boost::property_tree::iptree&> defaultS = sensor.second.get_child_optional("default");
if(defaultS) {
LOG(debug) << " Using \"" << defaultS.get().data() << "\" as default.";
sensorMap_t::iterator it = _templateSensors.find(defaultS.get().data());
if(it != _templateSensors.end()) {
*${PLUGIN_NAME_LWC}Sensor = it->second;
${PLUGIN_NAME_LWC}Sensor->setName(sensor.second.data());
} else {
LOG(warning) << "Template sensor \"" << defaultS.get().data() << "\" not found! Using standard values.";
}
}
//read remaining values
if(readSingleSensor(*${PLUGIN_NAME_LWC}Sensor, sensor.second)) {
_sensors.push_back(${PLUGIN_NAME_LWC}Sensor);
} else {
LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has bad values! Ignoring...";
}
}
}
}
EOF
if [ "${enableGroups}" = true ]
then
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
//read groups
BOOST_FOREACH(boost::property_tree::iptree::value_type &group, cfg.get_child("groups")) {
if (STRCMP(group, "group")) {
LOG(debug) << "Group \"" << group.second.data() << "\"";
if (!group.second.empty()) {
${PLUGIN_NAME}SensorGroup* ${PLUGIN_NAME_LWC}Group = new ${PLUGIN_NAME}SensorGroup(group.second.data());
/*
* TODO
* Read in other plugin specific group attributes
*/
//read mqttPart if present
std::string mqttPart = "";
boost::optional<boost::property_tree::iptree&> mqtt = group.second.get_child_optional("mqttprefix");
if (mqtt) {
mqttPart = mqtt.get().data();
}
//read remaining values
if (!readSensorInterface(*${PLUGIN_NAME_LWC}Group, group.second)) {
LOG(warning) << " SensorGroup \"" << group.second.data() << "\" has bad values!";
}
${PLUGIN_NAME}Configurator::~${PLUGIN_NAME}Configurator() {}
//read sensors for this group
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, group.second) {
if (STRCMP(val, "sensor")) {
LOG(debug) << "Sensor \"" << val.second.data() << "\"";
${PLUGIN_NAME}SensorBase* ${PLUGIN_NAME_LWC}SB = new ${PLUGIN_NAME}SensorBase(val.second.data());
if(readSensorBase(*${PLUGIN_NAME_LWC}SB, val.second)) {
${PLUGIN_NAME_LWC}SB->setMqtt(_mqttPrefix + mqttPart + ${PLUGIN_NAME_LWC}SB->getMqtt());
LOG(debug) << " Sensor " << ${PLUGIN_NAME_LWC}SB->getName() << " using MQTT-Topic " << ${PLUGIN_NAME_LWC}SB->getMqtt();
${PLUGIN_NAME_LWC}Group->pushBackSensor(${PLUGIN_NAME_LWC}SB);
} else {
LOG(warning) << " Sensor \"" << val.second.data() << "\" has bad values! Ignoring...";
}
}
}
_sensorGroups.push_back(${PLUGIN_NAME_LWC}Group);
}
}
void ${PLUGIN_NAME}Configurator::sensorBase(${PLUGIN_NAME}SensorBase& s, CFG_VAL config) {
ADD {
/*
* TODO
* Add ATTRIBUTE macros for sensorBase attributes
*/
//ATTRIBUTE("attributeName", attributeSetter);
}
EOF
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
return true;
}
bool ${PLUGIN_NAME}Configurator::derivedReadSensorBase(${PLUGIN_NAME}SensorBase& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
void ${PLUGIN_NAME}Configurator::sensorGroup(${PLUGIN_NAME}SensorGroup& s, CFG_VAL config) {
ADD {
/*
* TODO
* Read in plugin specific sensor attributes
* Add ATTRIBUTE macros for sensorGroup attributes
*/
if (STRCMP(val, "mqttsuffix")) {
EOF
if [ "${enableGroups}" = true ]
then
echo "\t\t\tsensor.setMqtt(val.second.data());" >> ${PLUGIN_NAME}Configurator.cpp
else
echo "\t\t\tsensor.setMqtt(_mqttPrefix + val.second.data());" >> ${PLUGIN_NAME}Configurator.cpp
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
/* Example code:
} else if (STRCMP(val, ("stringAttribute"))) {
sensor.setStringAttribute(val.second.data());
} else if (STRCMP(val, "intAttribute")) {
sensor.setIntAttribute(stoi(val.second.data())); */
}
}
/*
* TODO
* Print the read in values for debugging
*/
/*
LOG(debug) << " stringAtt: " << sensor.getStringAttribute();
LOG(debug) << " intAtt : " << sensor.getIntAttribute();
*/
return true;
}
EOF
......@@ -12,28 +12,18 @@ cat << EOF > ${PLUGIN_NAME}Configurator.h
#define ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}CONFIGURATOR_H_
#include "../../includes/ConfiguratorTemplate.h"
#include "${PLUGIN_NAME}SensorGroup.h"
EOF
if [ "${enableGroups}" = true ]
then
echo "#include \"${PLUGIN_NAME}SensorGroup.h\"" >> ${PLUGIN_NAME}Configurator.h
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.h
#include "${PLUGIN_NAME}SingleSensor.h"
class ${PLUGIN_NAME}Configurator : public ConfiguratorTemplate<${PLUGIN_NAME}SensorBase, ${PLUGIN_NAME}SingleSensor> {
class ${PLUGIN_NAME}Configurator : public ConfiguratorTemplate<${PLUGIN_NAME}SensorBase, ${PLUGIN_NAME}SensorGroup> {
public:
${PLUGIN_NAME}Configurator();
virtual ~${PLUGIN_NAME}Configurator();
protected:
bool derivedReadConfig(boost::property_tree::iptree& cfg) override;
void derivedReReadConfig() override { /* nothing to overwrite */ }
void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override { /* nothing to overwrite */ }
bool derivedReadSensorBase(${PLUGIN_NAME}SensorBase& sensor, boost::property_tree::iptree& config) override;
/* Overwritten from ConfiguratorTemplate */
void sensorBase(${PLUGIN_NAME}SensorBase& s, CFG_VAL config) override;
void sensorGroup(${PLUGIN_NAME}SensorGroup& s, CFG_VAL config) override;
};
extern "C" ConfiguratorInterface* create() {
......
......@@ -18,7 +18,7 @@ cat << EOF > ${PLUGIN_NAME}SensorBase.h
* Add plugin specific includes
*/
class ${PLUGIN_NAME}SensorBase : virtual public SensorBase {
class ${PLUGIN_NAME}SensorBase : public SensorBase {
public:
${PLUGIN_NAME}SensorBase(const std::string& name) :
SensorBase(name) {
......
......@@ -12,7 +12,7 @@ cat << EOF > ${PLUGIN_NAME}SensorGroup.cpp
#include "timestamp.h"
${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const std::string name) :
${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
/*
......@@ -28,20 +28,6 @@ ${PLUGIN_NAME}SensorGroup::~${PLUGIN_NAME}SensorGroup() {
*/
}
void ${PLUGIN_NAME}SensorGroup::init(boost::asio::io_service& io) {
_cacheSize = _cacheInterval / _interval + 1;
_timer.reset(new boost::asio::deadline_timer(io, boost::posix_time::seconds(0)));
/*
* TODO
* Init plugin specific stuff
*/
for (auto s : _sensors) {
s->initSensor(_cacheSize);
}
}
void ${PLUGIN_NAME}SensorGroup::start() {
if (_keepRunning) {
//we have been started already
......
......@@ -13,17 +13,21 @@ cat << EOF > ${PLUGIN_NAME}SensorGroup.h
#include "../../includes/SensorGroupTemplate.h"
#include "${PLUGIN_NAME}Attributes.h"
#include "${PLUGIN_NAME}SensorBase.h"
class ${PLUGIN_NAME}SensorGroup : public SensorGroupTemplate<${PLUGIN_NAME}SensorBase>, public ${PLUGIN_NAME}Attributes {
class ${PLUGIN_NAME}SensorGroup : public SensorGroupTemplate<${PLUGIN_NAME}SensorBase> {
public:
${PLUGIN_NAME}SensorGroup(const std::string name);
${PLUGIN_NAME}SensorGroup(const std::string& name);
virtual ~${PLUGIN_NAME}SensorGroup();
void init(boost::asio::io_service& io) override;
void start() override;
void stop() override;
/*
* TODO
* Add getter and setters for group attributes if required
*/
private:
void read() override;
......
#!/bin/sh
cat << EOF > ${PLUGIN_NAME}SingleSensor.cpp
/*
* ${PLUGIN_NAME}SingleSensor.cpp
*
* Created on: ${DATE}
* Author: ${AUTHOR}
*/
#include "${PLUGIN_NAME}SingleSensor.h"
#include "timestamp.h"
/*
* TODO
* Add additional required includes
*/
${PLUGIN_NAME}SingleSensor::${PLUGIN_NAME}SingleSensor(const std::string& name) :
SensorBase(name), ${PLUGIN_NAME}SensorBase(name), SingleSensor(name) {}
${PLUGIN_NAME}SingleSensor::~${PLUGIN_NAME}SingleSensor() {}
void ${PLUGIN_NAME}SingleSensor::start() {
if (_keepRunning) {
//we have been started already
LOG(info) << "Sensor " << _name << " already running.";
return;
}
/*
* TODO
* Start plugin specific stuff
*/
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(std::bind(&${PLUGIN_NAME}SingleSensor::readAsync, this));
LOG(info) << "Sensor " << _name << " started.";
}
void ${PLUGIN_NAME}SingleSensor::stop() {
_keepRunning = 0;
/*
* TODO
* Stop plugin specific stuff
*/
LOG(info) << "Sensor " << _name << " stopped.";
}
void ${PLUGIN_NAME}SingleSensor::read() {
reading_t reading;
reading.timestamp = getTimestamp();
try {
reading.value = /*
* TODO
* Plugin sensor read logic goes here
*/ 0;
storeReading(reading, _cacheIndex);
_cacheIndex = (_cacheIndex + 1) % _cacheSize;
#ifdef DEBUG
LOG(debug) << _name << ": \"" << reading.value << "\"";
#endif
} catch (const std::exception& e) {
LOG(error) << _name << " could not read value: " << e.what();
}
}
void ${PLUGIN_NAME}SingleSensor::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer && _keepRunning) {
uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next));
_pendingTasks++;
_timer->async_wait(std::bind(&${PLUGIN_NAME}SingleSensor::readAsync, this));
}
_pendingTasks--;
}
EOF
#!/bin/sh
cat << EOF > ${PLUGIN_NAME}SingleSensor.h
/*
* ${PLUGIN_NAME}SingleSensor.h
*
* Created on: ${DATE}
* Author: ${AUTHOR}
*/
#ifndef ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}SINGLESENSOR_H_
#define ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}SINGLESENSOR_H_
#include "${PLUGIN_NAME}SensorBase.h"
#include "../../includes/SingleSensor.h"
EOF
if [ "${enableGroups}" = true ]
then
echo "#include \"${PLUGIN_NAME}Attributes.h\"" >> ${PLUGIN_NAME}SingleSensor.h
echo "" >> ${PLUGIN_NAME}SingleSensor.h
echo "class ${PLUGIN_NAME}SingleSensor : public ${PLUGIN_NAME}SensorBase, public ${PLUGIN_NAME}Attributes, public SingleSensor {" >> ${PLUGIN_NAME}SingleSensor.h
else
echo "" >> ${PLUGIN_NAME}SingleSensor.h
echo "class ${PLUGIN_NAME}SingleSensor : public ${PLUGIN_NAME}SensorBase, public SingleSensor {" >> ${PLUGIN_NAME}SingleSensor.h
fi
cat << EOF >> ${PLUGIN_NAME}SingleSensor.h
public:
${PLUGIN_NAME}SingleSensor(const std::string& name);
virtual ~${PLUGIN_NAME}SingleSensor();
void start() override;
void stop() override;
private:
void read() override;
void readAsync() override;
};
#endif /* ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}SINGLESENSOR_H_ */
EOF
......@@ -9,44 +9,36 @@ global {
;add here other global attributes for your plugin
}
sensorTemplates {
;define here template sensors
template_group def1 {
;define template groups by appending "template_"
interval 1000
minValues 3
groupAtt 1234
;add other attributes your plugin requires for a sensor group
;define sensors belonging to the group below
sensor temp1 {
interval 1000
minValues 3
pluginAtt 1234
}
}
sensors {
;define here the actual singleSensors for your plugin
sensor sens1 {
default temp1
mqttsuffix 0001
sensorAtt 5678
;add other attributes your plugin requires for a sensor
}
}
EOF
if [ "${enableGroups}" = true ]
then
cat << EOF >> ${PLUGIN_NAME_LWC}.conf
groups {
;define here the sensor groups for your plugin
single_sensor sens1 {
;if you want a group with only one sensor you can use a single_sensor
default temp1
mqttsuffix 0001
;add other attributes your plugin requires for a sensor
}
group g1 {
;specify group attributes here
interval 1000
mqttprefix 01
;define sensors belonging to the group below
sensor gSens {
mqttsuffix 00
}
group g1 {
interval 1000
mqttprefix 01
default def1
;sensor temp1 is took over from def1 and does not need to be redefined
sensor gSens {
mqttsuffix 00
}
}
EOF
fi
......@@ -2,6 +2,11 @@
# Reminder in shell 0 = true, 1 = false
#TODO: make sensor, group and entity name configurable
echo "NOTE: Entities currently not supported!"
#TODO: add option to create entity class
# Init variables
DATE=`date '+%d.%m.%Y'`
AUTHOR="Your name goes here!"
......@@ -16,7 +21,7 @@ while getopts "hp:ga:" opt; do
echo "./generatePlugin.sh -p pluginName"
echo "Options:"
echo "-h\tPrint this help section"
echo "-g\tGenerate files for SensorGroups"
# echo "-e xx\tGenerate files for entity"
echo "-a xx\tSpecify name of the author which is to be mentioned in the"
echo "\tsource files"
exit 0
......@@ -24,9 +29,9 @@ while getopts "hp:ga:" opt; do
p) PLUGIN_NAME=$OPTARG
echo "Plugin named ${PLUGIN_NAME}"
;;
g) enableGroups=true
echo "Groups enabled"
;;
# e) ENTITY_NAME=$OPTARG
# echo "Generating entity ${ENTITY_NAME}"
# ;;
a) AUTHOR=$OPTARG
echo "Author: ${AUTHOR}"
;;
......@@ -57,28 +62,13 @@ cd ${PLUGIN_NAME_LWC}
echo "Generating ${PLUGIN_NAME}SensorBase.h ..."
. ../SensorBase_h.sh
if [ "${enableGroups}" = true ]
then
# Generate ...Attributes.h
echo "Generating ${PLUGIN_NAME}Attributes.h ..."
. ../Attributes_h.sh
# Generate ...SensorGroup.h
echo "Generating ${PLUGIN_NAME}SensorGroup.h ..."
. ../SensorGroup_h.sh
# Generate ...SensorGroup.cpp
echo "Generating ${PLUGIN_NAME}SensorGroup.cpp ..."
. ../SensorGroup_cpp.sh
fi
# Generate ...SingleSensor.h
echo "Generating ${PLUGIN_NAME}SingleSensor.h ..."
. ../SingleSensor_h.sh
# Generate ...SensorGroup.h
echo "Generating ${PLUGIN_NAME}SensorGroup.h ..."
. ../SensorGroup_h.sh
# Generate ...SingleSensor.cpp
echo "Generating ${PLUGIN_NAME}SingleSensor.cpp ..."
. ../SingleSensor_cpp.sh
# Generate ...SensorGroup.cpp
echo "Generating ${PLUGIN_NAME}SensorGroup.cpp ..."
. ../SensorGroup_cpp.sh
# Generate ...Configurator.h
echo "Generating ${PLUGIN_NAME}Configurator.h ..."
......
#!/bin/sh
cat << EOF > appendToMakefile.txt
Append to PLUGINS_BASE variable: libdcdbplugin_${PLUGIN_NAME_LWC}
Append to PLUGINS variable: ${PLUGIN_NAME_LWC}
Append at end of Makefile:
EOF
if [ "${enableGroups}" = true ]
then
echo "libdcdbplugin_${PLUGIN_NAME_LWC}.\$(LIBEXT): src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}SingleSensor.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}Configurator.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}SensorGroup.o" >> appendToMakefile.txt
else
echo "libdcdbplugin_${PLUGIN_NAME_LWC}.\$(LIBEXT): src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}SingleSensor.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}Configurator.o" >> appendToMakefile.txt
fi
cat << EOF >> appendToMakefile.txt
libdcdbplugin_${PLUGIN_NAME_LWC}.\$(LIBEXT): src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}SensorGroup.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}Configurator.o
\$(CXX) \$(LIBFLAGS)\$@ -o \$@ $^ -L\$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
NOTE: Probably you will have to append further libraries to the linker for your plugin to compile
......
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