diff --git a/Makefile.config b/Makefile.config index 926d27d6e..fbb80c5c9 100644 --- a/Makefile.config +++ b/Makefile.config @@ -57,6 +57,7 @@ endif WITH_NODE_FPGA ?= $(IS_LINUX) WITH_NODE_CBUILDER ?= $(IS_LINUX) WITH_NODE_LOOPBACK ?= $(IS_LINUX) +WITH_NODE_COMEDI ?= $(IS_LINUX) WITH_NODE_TEST_RTT ?= 1 WITH_NODE_FILE ?= 1 WITH_NODE_SIGNAL ?= 1 diff --git a/include/villas/nodes/comedi.h b/include/villas/nodes/comedi.h new file mode 100644 index 000000000..f44b0e92e --- /dev/null +++ b/include/villas/nodes/comedi.h @@ -0,0 +1,57 @@ +/** Node type: comedi + * + * @file + * @author Steffen Vogel + * @copyright 2018, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + *********************************************************************************/ + +/** + * @addtogroup comedi Comedi node type + * @ingroup node + * @{ + */ + +#pragma once + +#include +#include + +struct comedi { + +}; + +/** @see node_type::print */ +char * comedi_print(struct node *n); + +/** @see node_type::parse */ +int comedi_parse(struct node *n, json_t *cfg); + +/** @see node_type::open */ +int comedi_start(struct node *n); + +/** @see node_type::close */ +int comedi_stop(struct node *n); + +/** @see node_type::read */ +int comedi_read(struct node *n, struct sample *smps[], unsigned cnt); + +/** @see node_type::write */ +int comedi_write(struct node *n, struct sample *smps[], unsigned cnt); + +/** @} */ diff --git a/lib/nodes/Makefile.inc b/lib/nodes/Makefile.inc index fa588d767..0c9a7f590 100644 --- a/lib/nodes/Makefile.inc +++ b/lib/nodes/Makefile.inc @@ -155,3 +155,12 @@ ifneq ($(wildcard /usr/include/mosquitto.h),) WITH_IO = 1 endif endif + +# Enable Comedi support +if ($(WITH_NODE_COMEDI),1) +ifeq ($(shell $(PKGCONFIG) comedilib; echo $$?),0) + LIB_PKGS += comedilib + LIB_SRCS += lib/nodes/comedi.c + LIB_NODES += comedi +endif +endif diff --git a/lib/nodes/comedi.c b/lib/nodes/comedi.c new file mode 100644 index 000000000..342944dac --- /dev/null +++ b/lib/nodes/comedi.c @@ -0,0 +1,118 @@ +/** Node type: comedi + * + * @author Steffen Vogel + * @copyright 2018, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + *********************************************************************************/ + +#include + +#include +#include +#include +#include + +int comedi_parse(struct node *n, json_t *cfg) +{ + int ret; + struct comedi *c = (struct comedi *) n->_vd; + + ret = json_unpack_ex(cfg, &err, 0, "{ s?: o, s?: o, s?: s }", + "publish", &json_pub, + "subscribe", &json_sub, + "format", &format + ); + if (ret) + jerror(&err, "Failed to parse configuration of node %s", node_name(n)); + + return 0; +} + +char * comedi_print(struct node *n) +{ + struct comedi *c = (struct comedi *) n->_vd; + + char *buf = NULL; + + return buf; +} + +int comedi_start(struct node *n) +{ + int ret; + struct comedi *c = (struct comedi *) n->_vd; + + return 0; +} + +int comedi_stop(struct node *n) +{ + int ret; + struct comedi *c = (struct comedi *) n->_vd; + + return 0; +} + +int comedi_deinit() +{ + return 0; +} + +int comedi_read(struct node *n, struct sample *smps[], unsigned cnt) +{ + struct comedi *c = (struct comedi *) n->_vd; + + return -1; +} + +int comedi_write(struct node *n, struct sample *smps[], unsigned cnt) +{ + int ret; + struct comedi *c = (struct comedi *) n->_vd; + + return cnt; +} + +int comedi_fd(struct node *n) +{ + int ret; + struct comedi *c = (struct comedi *) n->_vd; + + return fd; +} + +static struct plugin p = { + .name = "comedi", + .description = "Comedi-compatible DAQ/ADC cards", + .type = PLUGIN_TYPE_NODE, + .node = { + .vectorize = 0, + .size = sizeof(struct comedi), + .parse = comedi_parse, + .print = comedi_print, + .start = comedi_start, + .stop = comedi_stop, + .deinit = comedi_deinit, + .read = comedi_read, + .write = comedi_write, + .fd = comedi_fd + } +}; + +REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances)