GCC Code Coverage Report


Directory: ./
File: src/devices/Festo.h
Date: 2026-09-23 16:22:15
Exec Total Coverage
Lines: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * This file is part of the ecapp library (EtherCAT application devices).
4 *
5 * Copyright (C) 2026 Florian Pose <fp@igh.de>
6 *
7 * The ecapp library is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation, version 3 of the
10 * License.
11 *
12 * The ecapp library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with the ecapp library. If not, see
19 * <https://www.gnu.org/licenses/>.
20 *
21 * Festo bus node (fieldbus coupler for a modular valve terminal).
22 * Unlike every other ecapp terminal, its channel count isn't fixed by
23 * a catalog type -- how many of the 32 reserved output bits an
24 * installation actually uses depends on how many valve modules are
25 * physically attached, so it is set at runtime via the
26 * ConfigurableChannelCount capability rather than baked into a Type
27 * enum. The PDO layout itself is fixed regardless (always 32 bits
28 * reserved); only vector sizes and pdserv wiring depend on the count.
29 *
30 ****************************************************************************/
31
32 #ifndef ECAPP_FESTO_H
33 #define ECAPP_FESTO_H
34
35 /****************************************************************************/
36
37 #include "ecapp/Mode.h"
38
39 #include <ecrt.h> // EtherCAT realtime interface
40 #include <stdint.h>
41 #include <string>
42 #include <vector>
43
44 /****************************************************************************/
45
46 namespace EcApp {
47
48 class Master;
49 class Domain;
50
51 template <Mode mode>
52 class FestoAdapter; // Festo.cpp -- the SubDevice wrapping this class,
53 // friended below so it can reach output/
54 // enableForcing/forcedValue/toggle directly for
55 // pdserv publishing.
56
57 template <Mode mode>
58 2 class Festo
59 {
60 friend class FestoAdapter<mode>;
61
62 public:
63 // 4 PDO entries of 8 bits each are reserved regardless of how
64 // many are actually used as channels.
65 static constexpr unsigned int MaxChannels = 32;
66
67 Festo(Master *, uint16_t, uint16_t, Domain *);
68
69 /** Resizes internal storage and registers pdserv signals for
70 * exactly this many channels. Throws std::out_of_range if
71 * count exceeds MaxChannels, or std::logic_error if called
72 * more than once -- pdserv does not support registering the
73 * same signal twice, so this is not idempotent. Call exactly
74 * once, before the master is activated. */
75 void setChannelCount(unsigned int count);
76
77 void setOutput(unsigned int, bool);
78 bool getOutput(unsigned int) const;
79
80 void updateOutputs();
81
82 unsigned int numChannels() const;
83
84 private:
85 ec_slave_config_t *sc;
86 Domain *const domainOut;
87
88 bool channelCountSet;
89 int offOut;
90 std::vector<uint8_t> input; // value originating from setOutput()
91 std::vector<uint8_t> prevInput;
92 std::vector<unsigned int> toggle;
93 std::vector<unsigned int> prevToggle;
94 std::vector<uint8_t> autoValue; // toggled input value
95 std::vector<uint8_t> enableForcing;
96 std::vector<uint8_t> forcedValue;
97 std::vector<uint8_t> output; // value sent to hardware
98 };
99
100 } // namespace EcApp
101
102 #endif // ECAPP_FESTO_H
103
104 /****************************************************************************/
105