GCC Code Coverage Report


Directory: ./
File: src/Domain.cpp
Date: 2026-09-03 16:05:57
Exec Total Coverage
Lines: 11 46 23.9%
Branches: 2 42 4.8%

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 #include "ecapp/Domain.h"
24
25 #include "ecapp/Master.h"
26
27 #include <stdexcept>
28
29 /****************************************************************************/
30
31 namespace EcApp {
32
33 struct Domain::Impl
34 {
35 ec_domain_t *domain;
36 ec_domain_state_t state;
37 bool valid;
38 uint8_t *data;
39 uint32_t badCycles;
40 };
41
42 /****************************************************************************/
43
44 12 Domain::Domain(
45 pdserv *pdserv,
46 pdtask *task,
47 const std::string &prefix,
48 12 Master *master) :
49 12 impl(new Impl {NULL, {}, false, NULL, 0U})
50 {
51 12 impl->state.working_counter = 0;
52 12 impl->state.wc_state = EC_WC_ZERO;
53 12 impl->state.redundancy_active = 0;
54
55
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if (pdserv && task) {
56 pdserv_signal(
57 task, 1, (prefix + "/WorkingCounter").c_str(), pd_uint32_T,
58 &impl->state.working_counter, 1, NULL);
59 pdserv_signal(
60 task, 1, (prefix + "/WorkingCounterState").c_str(),
61 pd_uint32_T, &impl->state.wc_state, 1, NULL);
62 pdserv_signal(
63 task, 1, (prefix + "/RedundancyActive").c_str(), pd_uint32_T,
64 &impl->state.redundancy_active, 1, NULL);
65 pdserv_signal(
66 task, 1, (prefix + "/Valid").c_str(), pd_boolean_T,
67 &impl->valid, 1, NULL);
68 pdserv_signal(
69 task, 1, (prefix + "/BadCycles").c_str(), pd_uint32_T,
70 &impl->badCycles, 1, NULL);
71 }
72
73
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!master) {
74 12 return;
75 }
76
77 if (!(impl->domain = ecrt_master_create_domain(master->getMaster()))) {
78 throw std::runtime_error("Domain creation failed!");
79 }
80 }
81
82 /****************************************************************************/
83
84 Domain::~Domain() = default;
85
86 /****************************************************************************/
87
88 ec_domain_t *Domain::getDomain()
89 {
90 return impl->domain;
91 }
92
93 /****************************************************************************/
94
95 59 uint8_t *Domain::getData() const
96 {
97 59 return impl->data;
98 }
99
100 /****************************************************************************/
101
102 bool Domain::isValid() const
103 {
104 return impl->valid;
105 }
106
107 /****************************************************************************/
108
109 void Domain::updateDataPointer()
110 {
111 if (impl->domain) {
112 impl->data = ecrt_domain_data(impl->domain);
113 }
114 }
115
116 /****************************************************************************/
117
118 void Domain::process(bool resetStats)
119 {
120 if (resetStats) {
121 impl->badCycles = 0U;
122 }
123
124 if (impl->domain) {
125 ecrt_domain_process(impl->domain);
126 ecrt_domain_state(impl->domain, &impl->state);
127 impl->valid = impl->state.wc_state == EC_WC_COMPLETE;
128 impl->badCycles += !impl->valid;
129 }
130 }
131
132 /****************************************************************************/
133
134 void Domain::queue()
135 {
136 if (impl->domain) {
137 ecrt_domain_queue(impl->domain);
138 }
139 }
140
141 } // namespace EcApp
142
143 /****************************************************************************/
144