From 013aafc3293d66738e0cd5257ede620ad3b3534b Mon Sep 17 00:00:00 2001 From: Bjarne von Horn Date: Fri, 5 Jul 2024 11:06:05 +0200 Subject: [PATCH] Simulate domain state --- fake_lib/fakeethercat.cpp | 9 ++++++++- fake_lib/fakeethercat.h | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fake_lib/fakeethercat.cpp b/fake_lib/fakeethercat.cpp index 2d6ed317..3a885e6c 100644 --- a/fake_lib/fakeethercat.cpp +++ b/fake_lib/fakeethercat.cpp @@ -26,9 +26,9 @@ #include #include #include +#include #include - static std::vector getPermutationVector(size_t count); size_t pdo::sizeInBytes() const @@ -61,10 +61,13 @@ ec_domain::ec_domain(rtipc *rtipc, const char *prefix) : rt_group(rtipc_create_g int ec_domain::activate(int domain_id) { + std::unordered_set slaves; + connected.resize(mapped_pdos.size()); size_t idx = 0; for (const auto &pdo : mapped_pdos) { + slaves.insert(pdo.slave_address.getCombined()); void *rt_pdo = nullptr; char buf[512]; const auto fmt = snprintf(buf, sizeof(buf), "%s/%d/%08X/%04X", prefix, domain_id, pdo.slave_address.getCombined(), pdo.pdo_index); @@ -95,6 +98,7 @@ int ec_domain::activate(int domain_id) ++idx; } activated_ = true; + numSlaves = slaves.size(); return 0; } @@ -153,6 +157,9 @@ int ecrt_domain_state( information. */ ) { + state->working_counter = domain->getNumSlaves(); + state->redundancy_active = 0; + state->wc_state = EC_WC_COMPLETE; return 0; } diff --git a/fake_lib/fakeethercat.h b/fake_lib/fakeethercat.h index 2a26d5d8..a8fd813d 100644 --- a/fake_lib/fakeethercat.h +++ b/fake_lib/fakeethercat.h @@ -165,6 +165,7 @@ private: rtipc_group *rt_group; const char *prefix; bool activated_ = false; + size_t numSlaves = 0; public: explicit ec_domain(struct rtipc *rtipc, const char *prefix); @@ -180,6 +181,8 @@ public: int process(); int queue(); + size_t getNumSlaves() const { return numSlaves; } + ssize_t map(ec_slave_config const &config, unsigned int syncManager, uint16_t pdo_index); };