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/ethercat.hpp

96 lines
2.3 KiB
C++
Raw Normal View History

/** Node type: ethercat
*
* @file
* @author Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
* @author Steffen Vogel <post@steffenvogel.de>
2020-01-25 17:38:22 +01:00
* @author Divya Laxetti <divya.laxetti@rwth-aachen.de>
* @copyright 2018-2020, Institute for Automation of Complex Power Systems, EONERC
2022-07-04 18:20:03 +02:00
* @license Apache 2.0
*********************************************************************************/
#pragma once
2020-01-25 17:38:22 +01:00
#include <thread>
#include <villas/pool.hpp>
2020-03-04 13:06:28 +01:00
#include <villas/task.hpp>
#include <villas/queue_signalled.h>
2020-03-04 12:41:55 +01:00
#include <villas/common.hpp>
2021-05-10 00:12:30 +02:00
#include <villas/format.hpp>
#include <villas/config.hpp>
namespace villas {
namespace node {
2021-06-21 16:11:42 -04:00
/* Forward declarations */
class NodeCompat;
class SuperNode;
2021-06-21 16:11:42 -04:00
2021-02-19 06:38:38 +01:00
/* Include hard-coded Ethercat Bus configuration */
2020-01-25 17:38:22 +01:00
#include <villas/nodes/ethercat_config.hpp>
2020-01-20 14:03:49 +01:00
extern "C" {
2021-02-19 06:38:38 +01:00
#include <ecrt.h>
}
2020-01-20 14:03:49 +01:00
#define DEFAULT_ETHERCAT_QUEUE_LENGTH (DEFAULT_QUEUE_LENGTH * 64)
/** Internal data per ethercat node */
struct ethercat {
2020-01-20 14:03:49 +01:00
/* Settings */
2020-01-25 17:38:22 +01:00
double rate;
2020-01-20 14:03:49 +01:00
struct {
2020-01-25 17:38:22 +01:00
unsigned num_channels;
double range;
unsigned position;
unsigned product_code; /**< Product ID of EtherCAT slave */
unsigned vendor_id; /**< Vendor ID of EtherCAT slave */
ec_slave_config_t *sc;
unsigned *offsets; /**< Offsets for PDO entries */
2020-01-20 14:03:49 +01:00
} in, out;
2020-01-25 17:38:22 +01:00
ec_domain_t *domain;
ec_pdo_entry_reg_t *domain_regs;
uint8_t *domain_pd; /**< Process data */
2020-01-20 14:03:49 +01:00
2020-01-25 17:38:22 +01:00
std::thread thread; /**< Cyclic task thread */
2020-03-04 13:06:28 +01:00
struct Task task; /**< Periodic timer */
struct Pool pool;
struct CQueueSignalled queue; /**< For samples which are received from WebSockets */
2020-01-20 14:03:49 +01:00
std::atomic<struct Sample *> send; /**< Last sample to be sent via EtherCAT */
};
/* Internal datastructures */
int ethercat_type_start(SuperNode *sn);
int ethercat_type_stop();
int ethercat_init(NodeCompat *n);
int ethercat_destroy(NodeCompat *n);
int ethercat_parse(NodeCompat *n, json_t *json);
2020-01-25 17:38:22 +01:00
int ethercat_check(NodeCompat *n);
2020-01-25 17:38:22 +01:00
int ethercat_prepare(NodeCompat *n);
2020-01-25 17:38:22 +01:00
int ethercat_start(NodeCompat *n);
2020-01-25 17:38:22 +01:00
int ethercat_stop(NodeCompat *n);
2020-01-25 17:38:22 +01:00
int ethercat_poll_fds(NodeCompat *n, int fds[]);
char * ethercat_print(NodeCompat *n);
int ethercat_read(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
int ethercat_write(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
} /* namespace node */
} /* namespace villas */