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

83 lines
2 KiB
C++
Raw Normal View History

2018-03-28 19:07:00 +02:00
/** Node type: comedi
*
* @file
* @author Steffen Vogel <post@steffenvogel.de>
2022-03-15 09:28:57 -04:00
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
2022-07-04 18:20:03 +02:00
* @license Apache 2.0
2018-03-28 19:07:00 +02:00
*********************************************************************************/
#pragma once
#include <comedilib.h>
#include <villas/list.hpp>
#include <villas/timing.hpp>
namespace villas {
namespace node {
2018-03-28 19:07:00 +02:00
2021-06-21 16:11:42 -04:00
/* Forward declarations */
class NodeCompat;
2021-06-21 16:11:42 -04:00
// 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
};
char * comedi_print(NodeCompat *n);
int comedi_parse(NodeCompat *n, json_t *json);
2018-03-28 19:07:00 +02:00
int comedi_start(NodeCompat *n);
2018-03-28 19:07:00 +02:00
int comedi_stop(NodeCompat *n);
2018-03-28 19:07:00 +02:00
int comedi_poll_fds(NodeCompat *n, int fds[]);
2018-03-28 19:07:00 +02:00
int comedi_read(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
2018-03-28 19:07:00 +02:00
int comedi_write(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
2018-03-28 19:07:00 +02:00
} // namespace node
} // namespace villas