Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
hfedcba committed Jun 22, 2018
2 parents b67712d + 5e5a967 commit fb12208
Show file tree
Hide file tree
Showing 27 changed files with 1,556 additions and 12 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ set(SOURCE_FILES
pulsecounter/Factory.h
pulsecounter/MyNode.cpp
pulsecounter/MyNode.h
serial/serial-port/Factory.cpp
serial/serial-port/Factory.h
serial/serial-port/MyNode.cpp
serial/serial-port/MyNode.h
serial/serial-in/Factory.cpp
serial/serial-in/Factory.h
serial/serial-in/MyNode.cpp
serial/serial-in/MyNode.h
serial/serial-out/Factory.cpp
serial/serial-out/Factory.h
serial/serial-out/MyNode.cpp
serial/serial-out/MyNode.h
storage/file/Factory.cpp
storage/file/Factory.h
storage/file/MyNode.cpp
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4 -I cfg
SUBDIRS = average basic-logic comment debug function gpio http influxdb light link modbus mqtt notification parsers passthrough ping pulsecounter press-pattern synchronous storage template timers tls-config tls-server-config variable
SUBDIRS = average basic-logic comment debug function gpio http influxdb light link modbus mqtt notification parsers passthrough ping pulsecounter press-pattern serial synchronous storage template timers tls-config tls-server-config variable
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ esac
#AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [enable debugging, default: no]), [case "${enableval}" in yes) debug=true ;; no) debug=false ;; *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; esac], [debug=false])
#AM_CONDITIONAL(DEBUG, test x"$debug" = x"true")

AC_OUTPUT(Makefile average/Makefile basic-logic/Makefile comment/Makefile debug/Makefile function/Makefile gpio/Makefile http/Makefile influxdb/Makefile light/Makefile link/Makefile modbus/Makefile mqtt/Makefile notification/Makefile parsers/Makefile passthrough/Makefile ping/Makefile press-pattern/Makefile pulsecounter/Makefile synchronous/Makefile storage/Makefile template/Makefile timers/Makefile tls-config/Makefile tls-server-config/Makefile variable/Makefile)
AC_OUTPUT(Makefile average/Makefile basic-logic/Makefile comment/Makefile debug/Makefile function/Makefile gpio/Makefile http/Makefile influxdb/Makefile light/Makefile link/Makefile modbus/Makefile mqtt/Makefile notification/Makefile parsers/Makefile passthrough/Makefile ping/Makefile press-pattern/Makefile pulsecounter/Makefile serial/Makefile synchronous/Makefile storage/Makefile template/Makefile timers/Makefile tls-config/Makefile tls-server-config/Makefile variable/Makefile)
2 changes: 1 addition & 1 deletion modbus/modbus-host/MyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Flows::PVariable MyNode::writeRegisters(Flows::PArray parameters)
{
try
{
if(parameters->size() != 4 && parameters->size() != 6) return Flows::Variable::createError(-1, "Method expects four or sic parameters. " + std::to_string(parameters->size()) + " given.");
if(parameters->size() != 4 && parameters->size() != 6) return Flows::Variable::createError(-1, "Method expects four or six parameters. " + std::to_string(parameters->size()) + " given.");
if (!_modbus) return Flows::Variable::createError(-32500, "Unknown application error.");

if((Modbus::ModbusType)parameters->at(0)->integerValue == Modbus::ModbusType::tHoldingRegister && parameters->size() == 6)
Expand Down
2 changes: 1 addition & 1 deletion mqtt/mqtt-broker/MyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Flows::PVariable MyNode::registerNode(Flows::PArray parameters)
try
{
if(parameters->size() != 1) return Flows::Variable::createError(-1, "Method expects exactly one parameter. " + std::to_string(parameters->size()) + " given.");
if(parameters->at(0)->type != Flows::VariableType::tString) return Flows::Variable::createError(-1, "Parameter is not of type string.");
if(parameters->at(0)->type != Flows::VariableType::tString || parameters->at(0)->stringValue.empty()) return Flows::Variable::createError(-1, "Parameter is not of type string.");

if(_mqtt) _mqtt->registerNode(parameters->at(0)->stringValue);

Expand Down
28 changes: 28 additions & 0 deletions serial/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
AUTOMAKE_OPTIONS = subdir-objects

AM_CPPFLAGS = -Wall -std=c++11 -DFORTIFY_SOURCE=2 -DGCRYPT_NO_DEPRECATED
AM_LDFLAGS = -Wl,-rpath=/lib/homegear -Wl,-rpath=/usr/lib/homegear -Wl,-rpath=/usr/local/lib/homegear
LIBS += -Wl,-Bdynamic -lhomegear-node -lhomegear-base

libdir = $(localstatedir)/lib/homegear/node-blue/nodes/serial

lib_LTLIBRARIES = serial-port.la serial-in.la serial-out.la

serial_port_la_SOURCES = serial-port/Factory.cpp serial-port/MyNode.cpp
serial_port_la_LDFLAGS =-module -avoid-version -shared

serial_in_la_SOURCES = serial-in/Factory.cpp serial-in/MyNode.cpp
serial_in_la_LDFLAGS =-module -avoid-version -shared

serial_out_la_SOURCES = serial-out/Factory.cpp serial-out/MyNode.cpp
serial_out_la_LDFLAGS =-module -avoid-version -shared

serial_ladir = $(libdir)
serial_la_DATA = serial-port/serial-port.hni serial-in/serial-in.hni serial-out/serial-out.hni
locale_en_usdir = $(libdir)/locales/en-US
locale_en_us_DATA = serial-port/locales/en-US/serial-port serial-in/locales/en-US/serial-in serial-out/locales/en-US/serial-out

install-exec-hook:
rm -f $(DESTDIR)$(libdir)/serial-port.la
rm -f $(DESTDIR)$(libdir)/serial-in.la
rm -f $(DESTDIR)$(libdir)/serial-out.la
42 changes: 42 additions & 0 deletions serial/serial-in/Factory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Copyright 2013-2017 Sathya Laufer
*
* Homegear is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Homegear is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Homegear. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/

#include "Factory.h"
#include "MyNode.h"
#include "../config.h"

Flows::INode* MyFactory::createNode(std::string path, std::string nodeNamespace, std::string type, const std::atomic_bool* frontendConnected)
{
return new MyNode::MyNode(path, nodeNamespace, type, frontendConnected);
}

Flows::NodeFactory* getFactory()
{
return (Flows::NodeFactory*) (new MyFactory);
}
44 changes: 44 additions & 0 deletions serial/serial-in/Factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright 2013-2017 Sathya Laufer
*
* Homegear is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Homegear is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Homegear. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/

#ifndef FACTORY_H
#define FACTORY_H

#include <homegear-node/NodeFactory.h>
#include "MyNode.h"

class MyFactory : Flows::NodeFactory
{
public:
virtual Flows::INode* createNode(std::string path, std::string nodeNamespace, std::string type, const std::atomic_bool* frontendConnected);
};

extern "C" Flows::NodeFactory* getFactory();

#endif
118 changes: 118 additions & 0 deletions serial/serial-in/MyNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* Copyright 2013-2017 Sathya Laufer
*
* Homegear is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Homegear is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Homegear. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/

#include <homegear-base/HelperFunctions/HelperFunctions.h>
#include "MyNode.h"

namespace MyNode
{

MyNode::MyNode(std::string path, std::string nodeNamespace, std::string type, const std::atomic_bool* frontendConnected) : Flows::INode(path, nodeNamespace, type, frontendConnected)
{
_localRpcMethods.emplace("packetReceived", std::bind(&MyNode::packetReceived, this, std::placeholders::_1));
}

MyNode::~MyNode()
{
}

bool MyNode::init(Flows::PNodeInfo info)
{
try
{
auto settingsIterator = info->info->structValue->find("serial");
if(settingsIterator != info->info->structValue->end()) _server = settingsIterator->second->stringValue;

return true;
}
catch(const std::exception& ex)
{
_out->printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
_out->printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
return false;
}

void MyNode::configNodesStarted()
{
try
{
if(_server.empty())
{
_out->printError("Error: This node has no Modbus server assigned.");
return;
}

Flows::PArray parameters = std::make_shared<Flows::Array>();
parameters->push_back(std::make_shared<Flows::Variable>(_id));

Flows::PVariable result = invokeNodeMethod(_server, "registerNode", parameters, true);
if (result->errorStruct) _out->printError("Error: Could not register node: " + result->structValue->at("faultString")->stringValue);
}
catch(const std::exception& ex)
{
_out->printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
_out->printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
}

//{{{ RPC methods
Flows::PVariable MyNode::packetReceived(Flows::PArray parameters)
{
try
{
if(parameters->size() != 1) return Flows::Variable::createError(-1, "Method expects exactly one parameter. " + std::to_string(parameters->size()) + " given.");
if(parameters->at(0)->type != Flows::VariableType::tBinary && parameters->at(0)->type != Flows::VariableType::tString) return Flows::Variable::createError(-1, "Parameter 1 is not of type String or Binary.");

Flows::PVariable message = std::make_shared<Flows::Variable>(Flows::VariableType::tStruct);
message->structValue->emplace("payload", parameters->at(0));

output(0, message);

return std::make_shared<Flows::Variable>();
}
catch(const std::exception& ex)
{
_out->printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
_out->printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
return Flows::Variable::createError(-32500, "Unknown application error.");
}
//}}}

}
58 changes: 58 additions & 0 deletions serial/serial-in/MyNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright 2013-2017 Sathya Laufer
*
* Homegear is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Homegear is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Homegear. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/

#ifndef MYNODE_H_
#define MYNODE_H_

#include <homegear-base/BaseLib.h>
#include <homegear-node/INode.h>
#include <unordered_map>

namespace MyNode
{

class MyNode: public Flows::INode
{
public:
MyNode(std::string path, std::string nodeNamespace, std::string type, const std::atomic_bool* frontendConnected);
virtual ~MyNode();

virtual bool init(Flows::PNodeInfo info);
virtual void configNodesStarted();
private:
std::string _server;

//{{{ RPC methods
Flows::PVariable packetReceived(Flows::PArray parameters);
//}}}
};

}

#endif
11 changes: 11 additions & 0 deletions serial/serial-in/locales/en-US/serial-in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"serial/serial-in.hni": {
"serial-in": {
"help": "<p>Reads data from a local serial port.</p><p>Can either <ul><li>wait for a \"split\" character (default \n). Also accepts hex notation (0x0d).</li><li>Wait for a timeout in milliseconds from the first character received</li><li>Wait to fill a fixed sized buffer</li></ul></p><p>It then outputs <code>$message['payload']</code> as either a UTF8 ascii string or a binary Buffer object.</p><p><code>msg.port</code> is set to the name of the port selected.</p><p>If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters is sent - again either as ascii chars or size 1 binary buffers.</p>",
"label": {
"serialport": "Serial Port",
"serial": "serial"
}
}
}
}
Loading

0 comments on commit fb12208

Please sign in to comment.