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

118 lines
3.2 KiB
C++
Raw Permalink Normal View History

/** Node type: ethercat
*
* @file
* @author Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.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
* @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 ethercats WebSockets node type
* @ingroup node
* @{
*/
#pragma once
2020-01-25 17:38:22 +01:00
#include <thread>
#include <villas/node.h>
#include <villas/pool.h>
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>
#include <villas/io.h>
#include <villas/config.h>
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)
#define DEFAULT_ETHERCAT_SAMPLE_LENGTH DEFAULT_SAMPLE_LENGTH
/** 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 queue_signalled queue; /**< For samples which are received from WebSockets */
2020-01-20 14:03:49 +01:00
2020-01-25 17:38:22 +01:00
std::atomic<struct sample *> send; /**< Last sample to be sent via EtherCAT */
};
/* Internal datastructures */
/** @see node_type::type_start */
int ethercat_type_start(struct super_node *sn);
/** @see node_type::type_stop */
int ethercat_type_stop();
2020-01-25 17:38:22 +01:00
/** @see node_type::init */
2020-08-25 21:00:52 +02:00
int ethercat_init(struct vnode *n);
2020-01-25 17:38:22 +01:00
/** @see node_type::destroy */
2020-08-25 21:00:52 +02:00
int ethercat_destroy(struct vnode *n);
2020-01-25 17:38:22 +01:00
/** @see node_type::parse */
2020-08-25 21:00:52 +02:00
int ethercat_parse(struct vnode *n, json_t *cfg);
2020-01-25 17:38:22 +01:00
/** @see node_type::check */
2020-08-25 21:00:52 +02:00
int ethercat_check(struct vnode *n);
2020-01-25 17:38:22 +01:00
/** @see node_type::prepare */
2020-08-25 21:00:52 +02:00
int ethercat_prepare(struct vnode *n);
2020-01-25 17:38:22 +01:00
/** @see node_type::open */
2020-08-25 21:00:52 +02:00
int ethercat_start(struct vnode *n);
/** @see node_type::close */
2020-08-25 21:00:52 +02:00
int ethercat_stop(struct vnode *n);
/** @see node_type::read */
2020-08-25 21:00:52 +02:00
int ethercat_read(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
/** @see node_type::write */
2020-08-25 21:00:52 +02:00
int ethercat_write(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
/** @} */