1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/nodes/comedi.hpp

104 lines
2.8 KiB
C++
Raw Normal View History

2018-03-28 19:07:00 +02:00
/** Node type: comedi
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2018-03-28 19:07:00 +02:00
* @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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
/**
* @addtogroup comedi Comedi node type
* @ingroup node
* @{
*/
#pragma once
#include <comedilib.h>
2018-03-28 19:07:00 +02:00
#include <villas/list.h>
#include <villas/timing.h>
2018-03-28 19:07:00 +02:00
2021-06-21 16:11:42 -04:00
/* Forward declarations */
struct vnode;
// whether to use read() or mmap() kernel interface
#define COMEDI_USE_READ (1)
//#define COMEDI_USE_READ (0)
2018-03-29 15:40:00 +02:00
struct comedi_chanspec {
unsigned int maxdata;
comedi_range *range;
};
2018-03-29 15:40:00 +02:00
struct comedi_direction {
2018-06-29 08:37:14 +02:00
int subdevice; ///< Comedi subdevice
int buffer_size; ///< Comedi's kernel buffer size in kB
int sample_size; ///< Size of a single measurement sample
int sample_rate_hz; ///< Sample rate in Hz
bool present; ///< Config present
bool enabled; ///< Card is started successfully
bool running; ///< Card is actively transfering samples
struct timespec started; ///< Timestamp when sampling started
struct timespec last_debug; ///< Timestamp of last debug output
size_t counter; ///< Number of villas samples transfered
struct comedi_chanspec *chanspecs; ///< Range and maxdata config of channels
unsigned *chanlist; ///< Channel list in comedi's packed format
2019-01-14 19:07:57 +01:00
size_t chanlist_len; ///< Number of channels for this direction
2018-06-29 08:37:14 +02:00
char* buffer;
char* bufptr;
2018-03-29 15:40:00 +02:00
};
2018-03-28 19:07:00 +02:00
struct comedi {
char *device;
2018-03-29 15:40:00 +02:00
struct comedi_direction in, out;
comedi_t *dev;
#if COMEDI_USE_READ
char *buf;
char *bufptr;
#else
2018-06-29 08:37:14 +02:00
char *map;
size_t bufpos;
size_t front;
size_t back;
#endif
2018-03-28 19:07:00 +02:00
};
/** @see node_type::print */
2020-08-25 21:00:52 +02:00
char * comedi_print(struct vnode *n);
2018-03-28 19:07:00 +02:00
/** @see node_type::parse */
2021-02-16 14:15:14 +01:00
int comedi_parse(struct vnode *n, json_t *json);
2018-03-28 19:07:00 +02:00
2020-01-21 14:27:28 +01:00
/** @see node_type::start */
2020-08-25 21:00:52 +02:00
int comedi_start(struct vnode *n);
2018-03-28 19:07:00 +02:00
2020-01-21 14:27:28 +01:00
/** @see node_type::stop */
2020-08-25 21:00:52 +02:00
int comedi_stop(struct vnode *n);
2018-03-28 19:07:00 +02:00
/** @see node_type::read */
2021-05-10 00:12:30 +02:00
int comedi_read(struct vnode *n, struct sample * const smps[], unsigned cnt);
2018-03-28 19:07:00 +02:00
/** @see node_type::write */
2021-05-10 00:12:30 +02:00
int comedi_write(struct vnode *n, struct sample * const smps[], unsigned cnt);
2018-03-28 19:07:00 +02:00
2018-06-29 08:37:14 +02:00
/** @} */