1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/include/villas/nodes/ethercat.hpp
Philipp Jungkamp 802f86090b node-ethercat: Fix #include after opened namespace
The `ethercat_config.hpp` header was included from `ethercat.hpp`
after opening the `villas::node` namespace. This made all definitions
originating from that header including the transitive definitions
from ethercat's `ecrt.h` part of the `villas::node` namespace.

The especially problematic part was that `ecrt.h` itself has an
`#include <netinet/in.h>` introduced in [1]. This caused the libc
definitions for `sa_familt_t`, `sockaddr_in` and `sockaddr_in6` to be
moved into the `villas::node` namespace, causing build error on recent
`ethercat` versions.

[1]: c2f9baf96a

Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
2024-10-16 21:59:41 +02:00

89 lines
2.1 KiB
C++

/* Node type: ethercat.
*
* Author: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
* Author: Steffen Vogel <post@steffenvogel.de>
* Author: Divya Laxetti <divya.laxetti@rwth-aachen.de>
* SPDX-FileCopyrightText: 2018-2020 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <thread>
#include <villas/common.hpp>
#include <villas/config.hpp>
#include <villas/format.hpp>
#include <villas/pool.hpp>
#include <villas/queue_signalled.h>
#include <villas/task.hpp>
// Include hard-coded Ethercat Bus configuration
#include <villas/nodes/ethercat_config.hpp>
#define DEFAULT_ETHERCAT_QUEUE_LENGTH (DEFAULT_QUEUE_LENGTH * 64)
namespace villas::node {
// Forward declarations
class NodeCompat;
class SuperNode;
// Internal data per ethercat node
struct ethercat {
// Settings
double rate;
struct {
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
} in, out;
ec_domain_t *domain;
ec_pdo_entry_reg_t *domain_regs;
uint8_t *domain_pd; // Process data
std::thread thread; // Cyclic task thread
struct Task task; // Periodic timer
struct Pool pool;
struct CQueueSignalled
queue; // For samples which are received from WebSockets
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);
int ethercat_check(NodeCompat *n);
int ethercat_prepare(NodeCompat *n);
int ethercat_start(NodeCompat *n);
int ethercat_stop(NodeCompat *n);
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 villas::node