GCC Code Coverage Report


Directory: ./
File: ecapp/VariablePdo.h
Date: 2026-09-23 16:22:15
Exec Total Coverage
Lines: 3 3 100.0%
Branches: 1 2 50.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 ****************************************************************************/
22
23 #ifndef ECAPP_VARIABLEPDO_H
24 #define ECAPP_VARIABLEPDO_H
25
26 /****************************************************************************/
27
28 #include "ecapp/SubDevice.h" // ChannelValue
29 #include "ecapp_export.h"
30
31 #include <string>
32 #include <vector>
33
34 /****************************************************************************/
35
36 namespace EcApp {
37
38 /** One channel to declare via VariablePdo::configure(). type is a
39 * default-constructed value of the desired channel type, exactly like
40 * ChannelKind::type tags a kind's type elsewhere in this library --
41 * e.g. {"Temperature", float(0)}. Every ChannelValue alternative is
42 * supported; the channel gets that alternative's natural width on the
43 * wire (1 bit for bool, 8/16/32/64 bit otherwise) and the matching
44 * pdserv type.
45 *
46 * forcible only applies to output channels (ignored for inputs): it
47 * additionally registers an EnableForcing/ForcedValue parameter pair,
48 * exactly like Ex20xx/Ex4xxx outputs -- while EnableForcing is set,
49 * ForcedValue overrides whatever the application writes via
50 * setOutput()/writeOutput()/bindOutput(), transparently to the
51 * caller. The value actually driven onto the wire (post-forcing) is
52 * separately visible as the read-only pdserv signal "<name>/Output". */
53
1/2
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
15 struct PdoChannel
54 {
55 std::string name;
56 ChannelValue type;
57 bool forcible = true;
58 };
59
60 /** Capability for slaves whose process data is not fixed by the
61 * device type at all, but freely composed by the application -- e.g.
62 * the EL6692 EtherCAT-Bridge, whose RxPDO/TxPDO mapping objects start
63 * out empty and accept application-chosen entries (unlike
64 * IoLinkMaster, where each port's channel set is still fixed once a
65 * device name has been assigned to it).
66 *
67 * Unlike IoLinkMaster's per-port setPortDevice() + a final
68 * applyPortConfig(), there is only one call here: ports are fixed,
69 * addressable slots that can sensibly be populated one at a time,
70 * while VariablePdo channels are just an ordered, append-only list --
71 * in practice always declared together at one call site anyway, so
72 * configure() takes the whole list at once rather than risking a
73 * forgotten "apply" step or a channel declared too late. Call it once,
74 * before the master is activated; it (re)builds the channel list /
75 * pdserv signals & parameters to match, and still does so even if
76 * this instance has no real slave config (master was null at
77 * construction), so the device remains usable in tests without a bus.
78 *
79 * A channel name must be unique per direction -- it becomes both the
80 * ChannelKind name (see SubDevice::inputIndex()/outputIndex() etc.)
81 * and the pdserv path segment below this device's own prefix. For
82 * several channels of the same kind, give each its own name (e.g.
83 * "Ch0", "Ch1", ...); there is no homogeneous count>1 kind here the
84 * way a fixed terminal like EL2008 has for its 8 identical outputs.
85 *
86 * The order of channels in each vector is the order they are mapped
87 * into the PDO. ecapp cannot check that the peer side of a
88 * point-to-point link (e.g. the bridge's other half, configured by
89 * separate application code, possibly in a different project) agrees
90 * on that order and on each channel's type -- getting both sides to
91 * agree is an application-level contract. */
92 1 class ECAPP_EXPORT VariablePdo
93 {
94 public:
95 1 virtual ~VariablePdo() = default;
96
97 virtual void configure(
98 const std::vector<PdoChannel> &inputs,
99 const std::vector<PdoChannel> &outputs) = 0;
100 };
101
102 } // namespace EcApp
103
104 #endif // ECAPP_VARIABLEPDO_H
105
106 /****************************************************************************/
107