2018-03-28 19:07:00 +02:00
|
|
|
/** Node type: comedi
|
|
|
|
*
|
|
|
|
* @file
|
2022-12-14 17:41:58 +01:00
|
|
|
* @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
|
|
|
|
|
2018-03-28 21:44:42 +02:00
|
|
|
#include <comedilib.h>
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
#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 */
|
2021-08-10 10:12:48 -04:00
|
|
|
class NodeCompat;
|
2021-06-21 16:11:42 -04:00
|
|
|
|
2018-06-15 15:42:46 +02: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
|
|
|
|
2018-06-15 15:42:46 +02:00
|
|
|
struct comedi_chanspec {
|
|
|
|
unsigned int maxdata;
|
|
|
|
comedi_range *range;
|
|
|
|
};
|
2018-03-29 15:40:00 +02:00
|
|
|
|
2018-06-15 15:42:46 +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 {
|
2018-03-28 21:44:42 +02:00
|
|
|
char *device;
|
2018-03-29 15:40:00 +02:00
|
|
|
struct comedi_direction in, out;
|
2018-06-15 15:42:46 +02:00
|
|
|
comedi_t *dev;
|
|
|
|
|
|
|
|
#if COMEDI_USE_READ
|
2018-06-28 13:42:50 +02:00
|
|
|
char *buf;
|
|
|
|
char *bufptr;
|
2018-06-15 15:42:46 +02:00
|
|
|
#else
|
2018-06-29 08:37:14 +02:00
|
|
|
char *map;
|
|
|
|
size_t bufpos;
|
|
|
|
size_t front;
|
|
|
|
size_t back;
|
2018-06-15 15:42:46 +02:00
|
|
|
#endif
|
|
|
|
|
2018-03-28 19:07:00 +02:00
|
|
|
};
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
char * comedi_print(NodeCompat *n);
|
|
|
|
|
|
|
|
int comedi_parse(NodeCompat *n, json_t *json);
|
2018-03-28 19:07:00 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int comedi_start(NodeCompat *n);
|
2018-03-28 19:07:00 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int comedi_stop(NodeCompat *n);
|
2018-03-28 19:07:00 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int comedi_poll_fds(NodeCompat *n, int fds[]);
|
2018-03-28 19:07:00 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int comedi_read(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
|
2018-03-28 19:07:00 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int comedi_write(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
|
2018-03-28 19:07:00 +02:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|