GCC Code Coverage Report


Directory: ./
File: OutputMonitor.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 634 748 84.8%
Functions: 52 56 92.9%
Branches: 772 1548 49.9%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2022 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the LGPL v2.1 as described in the
10 * included LICENSE.LGPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #include "fpp-json.h"
16 #include "fpphttp.h" // drogon/HTTP helpers used here; no longer pulled transitively (see fpphttp_types.h)
17 #include "fpphttp_clientip.h" // getEffectiveClientIP() - FPP-internal, not in the plugin API
18
19 #include <cinttypes>
20 #include <cmath>
21 #include <fcntl.h>
22 #include <list>
23 #include <map>
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include <string>
27 #include <unistd.h>
28 #include <vector>
29
30 #include "Sequence.h"
31 #include "Timers.h"
32 #include "Warnings.h"
33 #include "common.h"
34 #include "gpio.h"
35 #include "log.h"
36 #include "settings.h"
37 #include "channeloutput/stringtesters/PixelCountStringTester.h"
38 #include "channeltester/ChannelTester.h"
39 #include "commands/Commands.h"
40 #include "sensors/Sensors.h"
41 #include "util/GPIOUtils.h"
42
43 #include "OutputMonitor.h"
44
45 OutputMonitor OutputMonitor::INSTANCE;
46
47 class CurrentMonitorBase {
48 public:
49 CurrentMonitorBase() {}
50 46 CurrentMonitorBase(const Json::Value& c) {
51 46 currentMonitorScale = c["scale"].asFloat();
52
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 30 times.
46 if (c.isMember("offset")) {
53 16 currentMonitorOffset = c["offset"].asFloat();
54 }
55 46 }
56 92 virtual ~CurrentMonitorBase() {
57 92 }
58
59 2025 float getValue() {
60 2025 float f = getRawValue();
61 2025 f -= currentMonitorOffset;
62
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 1689 times.
2025 if (f < 0) {
63 336 f = 0;
64 }
65 2025 f *= currentMonitorScale;
66 2025 return f;
67 }
68
69 virtual float getRawValue() = 0;
70
71 float currentMonitorScale = 1.0f;
72 float currentMonitorOffset = 0.0f;
73 };
74
75 class FileCurrentMonitor : public CurrentMonitorBase {
76 public:
77 30 FileCurrentMonitor(const Json::Value& c) :
78 30 CurrentMonitorBase(c) {
79
3/6
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 30 times.
✗ Branch 5 not taken.
30 currentMonitorFile = open(c["path"].asString().c_str(), O_NONBLOCK | O_RDONLY);
80 30 }
81 120 virtual ~FileCurrentMonitor() {
82
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
60 if (currentMonitorFile >= 0) {
83 60 close(currentMonitorFile);
84 }
85 120 }
86 1689 virtual float getRawValue() override {
87
1/2
✓ Branch 0 taken 1689 times.
✗ Branch 1 not taken.
1689 if (currentMonitorFile >= 0) {
88 1689 float f = 0;
89
2/2
✓ Branch 0 taken 5067 times.
✓ Branch 1 taken 1689 times.
6756 for (int x = 0; x < 3; x++) {
90 // pread: multiple status readers can sample the same monitor
91 // concurrently; a shared lseek+read would interleave offsets.
92 5067 char buf[12] = { 0 };
93
2/4
✓ Branch 0 taken 5067 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5067 times.
✗ Branch 3 not taken.
5067 if (pread(currentMonitorFile, buf, sizeof(buf) - 1, 0) > 0) {
94 5067 f += atoi(buf);
95 }
96 }
97 1689 f /= 3.0;
98 1689 return f;
99 }
100 ✗ return 0;
101 }
102 int currentMonitorFile = -1;
103 };
104 class SensorCurrentMonitor : public CurrentMonitorBase {
105 public:
106 16 SensorCurrentMonitor(const Json::Value& c) :
107 16 CurrentMonitorBase(c) {
108
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
16 sensor = Sensors::INSTANCE.getSensorSource(c["sensor"].asString());
109
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 channel = c["channel"].asInt();
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (sensor) {
111 ✗ sensor->enable(channel);
112 }
113 16 }
114 336 virtual float getRawValue() override {
115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 336 times.
336 if (sensor) {
116 ✗ return sensor->getValue(channel);
117 }
118 336 return 0;
119 }
120
121 SensorSource* sensor = nullptr;
122 int channel = 0;
123 };
124
125 class ReceiverInfo {
126 public:
127 bool isOn = false;
128 bool hasTriggered = false;
129 bool enabled = false;
130 int pixelCount = -1;
131 int configuredCount = -1;
132 float current = 0.0f;
133
134 std::string warning;
135 int retryCount = 0;
136 int okCount = 0;
137 long long firstTriggerTime = 0;
138 long long nextRetryTime = 0;
139 };
140
141 class PortPinInfo {
142 public:
143
3/4
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3894 times.
✓ Branch 3 taken 649 times.
4543 PortPinInfo() {
144 649 }
145
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
4543 ~PortPinInfo() {
146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 649 times.
649 if (currentMonitor) {
147 ✗ delete currentMonitor;
148 }
149
2/2
✓ Branch 0 taken 3894 times.
✓ Branch 1 taken 649 times.
5192 }
150
151 833 void setConfig(const std::string& n, const Json::Value& c) {
152 833 name = n;
153 833 config = c;
154
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 817 times.
833 if (config.isMember("row")) {
155 16 row = config["row"].asInt();
156 }
157
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 817 times.
833 if (config.isMember("col")) {
158 16 col = config["col"].asInt();
159 }
160
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 816 times.
833 if (config.isMember("bank")) {
161
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
17 bankLabel = config["bank"].asString();
162 }
163 833 }
164
165 std::string name;
166 std::string bankLabel;
167 Json::Value config;
168 uint32_t group = 0;
169
170 const PinCapabilities* enablePin = nullptr;
171 bool highToEnable = true;
172 const PinCapabilities* eFusePin = nullptr;
173 int eFuseOKValue = 0;
174
175 const PinCapabilities* eFuseInterruptPin = nullptr;
176 CurrentMonitorBase* currentMonitor = nullptr;
177
178 bool isSmartReceiver = false;
179 ReceiverInfo receivers[6];
180
181 int row = -1;
182 int col = -1;
183
184 210 void reset() {
185 210 name = "";
186 210 bankLabel = "";
187
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 config = Json::Value();
188 210 group = 0;
189
190 210 enablePin = nullptr;
191 210 highToEnable = true;
192 210 eFusePin = nullptr;
193 210 eFuseOKValue = 0;
194 210 eFuseInterruptPin = nullptr;
195
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 164 times.
210 if (currentMonitor) {
196
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 delete currentMonitor;
197 46 currentMonitor = nullptr;
198 }
199 210 isSmartReceiver = false;
200
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 210 times.
1470 for (auto& r : receivers) {
201 1260 r = ReceiverInfo();
202 }
203 210 row = -1;
204 210 col = -1;
205 210 }
206
207 1275 void appendTo(Json::Value& result) {
208
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1273 times.
1275 if (name.empty()) {
209 2 return;
210 }
211
1/2
✓ Branch 0 taken 1273 times.
✗ Branch 1 not taken.
1273 Json::Value v;
212
2/4
✓ Branch 0 taken 1273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1273 times.
✗ Branch 3 not taken.
1273 v["name"] = name;
213
214
2/2
✓ Branch 0 taken 724 times.
✓ Branch 1 taken 549 times.
1273 if (isSmartReceiver) {
215
2/4
✓ Branch 0 taken 724 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 724 times.
✗ Branch 3 not taken.
724 v["smartReceivers"] = true;
216
2/2
✓ Branch 0 taken 4344 times.
✓ Branch 1 taken 724 times.
5068 for (int x = 0; x < 6; x++) {
217
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 4180 times.
4344 if (receivers[x].enabled) {
218
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
328 std::string sri(1, (char)('A' + x));
219
3/6
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 164 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
164 v[sri]["ma"] = receivers[x].current;
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 164 times.
164 if (receivers[x].hasTriggered) {
221 ✗ v[sri]["status"] = false;
222 ✗ v[sri]["enabled"] = false;
223 } else {
224
3/6
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 164 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
164 v[sri]["enabled"] = receivers[x].isOn;
225
3/6
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 164 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
164 v[sri]["status"] = receivers[x].enabled;
226 }
227
2/4
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 164 times.
164 if (receivers[x].pixelCount >= 0 && receivers[x].pixelCount < 0xFFFF) {
228 ✗ v[sri]["pixelCount"] = receivers[x].pixelCount;
229 }
230 164 }
231 }
232 } else {
233
2/2
✓ Branch 0 taken 353 times.
✓ Branch 1 taken 196 times.
549 if (enablePin) {
234
1/2
✓ Branch 0 taken 353 times.
✗ Branch 1 not taken.
353 int pv = enablePin->getValue();
235
7/12
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 351 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 353 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 353 times.
✗ Branch 11 not taken.
353 v["enabled"] = (pv && highToEnable) || (!pv && !highToEnable);
236 }
237 // Only report a fuse status for ports that actually have a fuse pin
238 // to read. Ports with nothing but an enable (the local outputs on
239 // the K8-Pro/K16-Pro, where only the differential receivers report
240 // back) have nothing to detect, and a hard-coded "OK" there is a
241 // green light for a check that can never go red. Leaving the key
242 // out lets the UI say nothing instead of saying something false.
243
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 198 times.
549 if (eFusePin) {
244
2/2
✓ Branch 0 taken 350 times.
✓ Branch 1 taken 1 times.
351 if (receivers[0].isOn) {
245
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 349 times.
350 if (receivers[0].hasTriggered) {
246
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 v["status"] = false;
247 } else {
248
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 v["status"] = eFuseOKValue == eFusePin->getValue();
249 }
250 } else {
251
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 v["status"] = true;
252 }
253 }
254
255 // printf("Port %s isOn: %d hasTriggered: %d okVal: %d curVal: %d\n", name.c_str(), receivers[0].isOn, receivers[0].hasTriggered, eFuseOKValue, eFusePin->getValue());
256
1/2
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
549 if (currentMonitor) {
257
1/2
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
549 float f = currentMonitor->getValue();
258 549 int c = std::round(f);
259
2/4
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 549 times.
✗ Branch 3 not taken.
549 v["ma"] = c;
260 }
261
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 543 times.
549 if (receivers[0].pixelCount >= 0) {
262
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 v["pixelCount"] = receivers[0].pixelCount;
263 }
264 }
265
266
2/2
✓ Branch 0 taken 1060 times.
✓ Branch 1 taken 213 times.
1273 if (row != -1) {
267
2/4
✓ Branch 0 taken 1060 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1060 times.
✗ Branch 3 not taken.
1060 v["row"] = row;
268 }
269
2/2
✓ Branch 0 taken 1060 times.
✓ Branch 1 taken 213 times.
1273 if (col != -1) {
270
2/4
✓ Branch 0 taken 1060 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1060 times.
✗ Branch 3 not taken.
1060 v["col"] = col;
271 }
272
2/2
✓ Branch 0 taken 338 times.
✓ Branch 1 taken 935 times.
1273 if (!bankLabel.empty()) {
273
2/4
✓ Branch 0 taken 338 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 338 times.
✗ Branch 3 not taken.
338 v["bank"] = bankLabel;
274 }
275
1/2
✓ Branch 0 taken 1273 times.
✗ Branch 1 not taken.
1273 result.append(v);
276 1273 }
277 };
278
279 class FPPEnableOutputsCommand : public Command {
280 public:
281 static FPPEnableOutputsCommand INSTANCE;
282 3252 FPPEnableOutputsCommand() :
283
2/4
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
6504 Command("Outputs On") {
284 3252 }
285 18 virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) override {
286 18 OutputMonitor::INSTANCE.EnableOutputs();
287 18 return std::make_unique<Command::Result>("OK");
288 }
289 };
290
291 class FPPDisableOutputsCommand : public Command {
292 public:
293 static FPPDisableOutputsCommand INSTANCE;
294
295 3252 FPPDisableOutputsCommand() :
296
2/4
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
6504 Command("Outputs Off") {
297 3252 }
298 9 virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) override {
299 9 OutputMonitor::INSTANCE.DisableOutputs();
300 9 return std::make_unique<Command::Result>("OK");
301 }
302 };
303
304 class FPPEnablePortCommand : public Command {
305 public:
306 static FPPEnablePortCommand INSTANCE;
307 3252 FPPEnablePortCommand() :
308
2/4
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
6504 Command("Set Port Status") {
309
7/14
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3252 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3252 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3252 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3252 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3252 times.
✗ Branch 13 not taken.
26016 args.push_back(CommandArg("Port", "string", "Port").setContentListUrl("api/fppd/ports/list"));
310
5/10
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3252 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3252 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3252 times.
✗ Branch 9 not taken.
19512 args.push_back(CommandArg("on", "bool", "On"));
311 3252 }
312 603 virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) override {
313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 603 times.
603 if (args.size() < 2) {
314 ✗ return std::make_unique<Command::ErrorResult>("Required arguments not provided");
315 }
316
3/4
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 303 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 300 times.
603 bool enable = args[1] == "true" || args[1] == "1";
317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 603 times.
603 if (args[0] == "--ALL--") {
318 ✗ if (enable) {
319 ✗ OutputMonitor::INSTANCE.EnableOutputs();
320 } else {
321 ✗ OutputMonitor::INSTANCE.DisableOutputs();
322 }
323 } else {
324 603 OutputMonitor::INSTANCE.SetOutput(args[0], enable);
325 }
326 603 return std::make_unique<Command::Result>("OK");
327 }
328 };
329
330 class FPPCheckConfiguredPixelsCommand : public Command {
331 public:
332 static FPPCheckConfiguredPixelsCommand INSTANCE;
333
334 3252 FPPCheckConfiguredPixelsCommand() :
335
2/4
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
6504 Command("Check Pixel Count") {
336
8/16
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3252 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3252 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3252 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3252 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3252 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3252 times.
✗ Branch 15 not taken.
26016 args.push_back(CommandArg("Ports", "multistring", "Ports").setContentListUrl("api/fppd/ports/list", false).setDefaultValue("--ALL--"));
337
6/12
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3252 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3252 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3252 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3252 times.
✗ Branch 11 not taken.
19512 args.push_back(CommandArg("Sensitivity", "int", "Sensitivity").setRange(0, 20).setDefaultValue("2"));
338
7/14
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3252 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3252 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3252 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3252 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3252 times.
✗ Branch 13 not taken.
26016 args.push_back(CommandArg("Action", "string", "Action").setContentList({ "Warn", "Log" }).setDefaultValue("Warn"));
339 3252 }
340 1 virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) override {
341 1 std::vector<std::string> nargs;
342
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 nargs.push_back("50");
343
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 nargs.push_back("Output Specific");
344
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 nargs.push_back("--ALL--");
345
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 nargs.push_back("999");
346
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_COMMAND, "\"Check Pixel Count\" command starting Test Mode to measure current draw\n");
347
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 CommandManager::INSTANCE.run("Test Start", nargs);
348 // Resolved here, against the defaults declared above, rather than
349 // indexed inside the timer: all three arguments are optional in
350 // practice, and a caller that supplied fewer than three left the
351 // lambda reading past the end of its captured vector a second later.
352
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
1 std::string ports = args.size() > 0 ? args[0] : "--ALL--";
353
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 int sensitivity = args.size() > 1 ? std::atoi(args[1].c_str()) : 2;
354
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
1 std::string action = args.size() > 2 ? args[2] : "Warn";
355
5/12
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
3 Timers::INSTANCE.addPeriodicTimer("CheckPixelCount", 1000, [ports, sensitivity, action]() {
356
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 26 times.
27 if (CurrentBasedPixelCountPixelStringTester::INSTANCE.getCurrentStatus() == CurrentBasedPixelCountPixelStringTester::Status::Complete) {
357
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 OutputMonitor::INSTANCE.checkPixelCounts(ports, action, sensitivity);
358 1 std::vector<std::string> args;
359
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_COMMAND, "\"Check Pixel Count\" command stopping Test Mode, current-based detection complete\n");
360
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 CommandManager::INSTANCE.run("Test Stop", args);
361
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 Timers::INSTANCE.stopPeriodicTimer("CheckPixelCount");
362 1 }
363 27 });
364
365
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 return std::make_unique<Command::Result>("OK");
366 1 }
367 };
368 FPPEnableOutputsCommand FPPEnableOutputsCommand::INSTANCE;
369 FPPDisableOutputsCommand FPPDisableOutputsCommand::INSTANCE;
370 FPPCheckConfiguredPixelsCommand FPPCheckConfiguredPixelsCommand::INSTANCE;
371 FPPEnablePortCommand FPPEnablePortCommand::INSTANCE;
372
373 3252 OutputMonitor::OutputMonitor() {
374 3252 }
375 600 OutputMonitor::~OutputMonitor() {
376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 for (auto pi : portPins) {
377 ✗ if (pi) {
378 ✗ delete pi;
379 }
380 }
381 600 portPins.clear();
382 600 pullHighOutputPins.clear();
383 600 pullLowOutputPins.clear();
384 600 fusePins.clear();
385 600 }
386
387 2649 void OutputMonitor::Initialize(std::map<int, std::function<bool(int)>>& callbacks) {
388 2649 eFuseRetryCount = getSettingInt("eFuseRetryCount", 0);
389 2649 eFuseRetryInterval = getSettingInt("eFuseRetryInterval", 100);
390
3/6
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
12950 registerSettingsListener("OutputMonitor", "eFuseRetryCount", [this](const std::string& value) {
391 1 eFuseRetryCount = getSettingInt("eFuseRetryCount", 0);
392 1 });
393
3/6
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
12950 registerSettingsListener("OutputMonitor", "eFuseRetryInterval", [this](const std::string& value) {
394 ✗ eFuseRetryInterval = getSettingInt("eFuseRetryInterval", 100);
395 ✗ });
396
2/4
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
5298 CommandManager::INSTANCE.addCategorizedCommand(&FPPEnableOutputsCommand::INSTANCE, "Outputs", 1);
397
2/4
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
2649 CommandManager::INSTANCE.addCategorizedCommand(&FPPDisableOutputsCommand::INSTANCE, "Outputs", 1);
398
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 2523 times.
2649 if (!portPins.empty()) {
399
2/4
✓ Branch 0 taken 126 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 126 times.
✗ Branch 3 not taken.
252 CommandManager::INSTANCE.addCategorizedCommand(&FPPCheckConfiguredPixelsCommand::INSTANCE, "Outputs", 1);
400
2/4
✓ Branch 0 taken 126 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 126 times.
✗ Branch 3 not taken.
252 CommandManager::INSTANCE.addCategorizedCommand(&FPPEnablePortCommand::INSTANCE, "Outputs", 1);
401 }
402 2649 }
403 2620 void OutputMonitor::Cleanup() {
404
3/6
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2620 times.
✗ Branch 5 not taken.
10480 unregisterSettingsListener("OutputMonitor", "eFuseRetryCount");
405
3/6
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2620 times.
✗ Branch 5 not taken.
7860 unregisterSettingsListener("OutputMonitor", "eFuseRetryInterval");
406
1/2
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
2620 CommandManager::INSTANCE.removeCommand(&FPPEnableOutputsCommand::INSTANCE);
407
1/2
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
2620 CommandManager::INSTANCE.removeCommand(&FPPDisableOutputsCommand::INSTANCE);
408
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 2492 times.
2620 if (!portPins.empty()) {
409
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 CommandManager::INSTANCE.removeCommand(&FPPCheckConfiguredPixelsCommand::INSTANCE);
410
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 CommandManager::INSTANCE.removeCommand(&FPPEnablePortCommand::INSTANCE);
411 }
412
1/2
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
2620 std::unique_lock<std::shared_mutex> lock(gpioLock);
413 2620 eFuseRetries.clear();
414
2/2
✓ Branch 0 taken 669 times.
✓ Branch 1 taken 2620 times.
3289 for (auto pi : portPins) {
415
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 532 times.
669 if (pi) {
416
1/2
✓ Branch 0 taken 137 times.
✗ Branch 1 not taken.
137 clearReceiverWarnings(pi);
417
1/2
✓ Branch 0 taken 137 times.
✗ Branch 1 not taken.
137 delete pi;
418 }
419 }
420 2620 portPins.clear();
421 2620 pullHighOutputPins.clear();
422 2620 pullLowOutputPins.clear();
423 2620 fusePins.clear();
424 2620 }
425
426 1 void OutputMonitor::checkPixelCounts(const std::string& portList, const std::string& action, int sensitivty) {
427
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::unique_lock<std::shared_mutex> lock(gpioLock);
428 1 std::set<std::string> ports;
429
4/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 for (auto p : split(portList, ',')) {
430
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (p == "--ALL--") {
431
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (auto p : portPins) {
432
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (p) {
433
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ports.insert(p->name);
434 }
435 }
436 } else {
437 ✗ ports.insert(p);
438 }
439 2 }
440
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (auto p : portPins) {
441
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 if (p && ports.find(p->name) != ports.end()) {
442
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 for (int x = 0; x < 6; x++) {
443 6 int diff = std::abs(p->receivers[x].configuredCount - p->receivers[x].pixelCount);
444 6 std::string newWarn;
445
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (diff > sensitivty) {
446
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 newWarn = p->name;
447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (p->isSmartReceiver) {
448 ✗ newWarn += (char)('A' + x);
449 }
450
5/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 newWarn += " configured for " + std::to_string(p->receivers[x].configuredCount) + " pixels but " + std::to_string(p->receivers[x].pixelCount) + " pixels detected.";
451 }
452
6/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 5 times.
6 if (action == "Warn" && newWarn != p->receivers[x].warning) {
453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!p->receivers[x].warning.empty()) {
454 ✗ WarningHolder::RemoveWarning(16, p->receivers[x].warning);
455 }
456
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 p->receivers[x].warning = newWarn;
457
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!p->receivers[x].warning.empty()) {
458
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 WarningHolder::AddWarning(16, p->receivers[x].warning);
459 }
460
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 } else if (action == "Log") {
461 ✗ LogInfo(VB_CHANNELOUT, "%s\n", newWarn.c_str());
462 }
463 6 }
464 }
465 }
466 1 }
467
468 2762 void OutputMonitor::EnableOutputs() {
469
1/2
✓ Branch 0 taken 2762 times.
✗ Branch 1 not taken.
2762 std::unique_lock<std::shared_mutex> lock(gpioLock);
470
5/6
✓ Branch 0 taken 2729 times.
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2729 times.
✓ Branch 4 taken 33 times.
✓ Branch 5 taken 2729 times.
2762 if (!pullHighOutputPins.empty() || !pullLowOutputPins.empty()) {
471
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
33 LogDebug(VB_CHANNELOUT, "Enabling outputs\n");
472 }
473 2762 outputsEnabled = true;
474
1/2
✓ Branch 0 taken 2762 times.
✗ Branch 1 not taken.
2762 PinCapabilities::SetMultiPinValue(pullHighOutputPins, 1);
475
1/2
✓ Branch 0 taken 2762 times.
✗ Branch 1 not taken.
2762 PinCapabilities::SetMultiPinValue(pullLowOutputPins, 0);
476
2/2
✓ Branch 0 taken 697 times.
✓ Branch 1 taken 2762 times.
3459 for (auto p : portPins) {
477
2/2
✓ Branch 0 taken 161 times.
✓ Branch 1 taken 536 times.
697 if (p) {
478
2/2
✓ Branch 0 taken 966 times.
✓ Branch 1 taken 161 times.
1127 for (auto& r : p->receivers) {
479
2/2
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 907 times.
966 if (r.enabled) {
480 59 r.isOn = true;
481 59 r.hasTriggered = false;
482 }
483 }
484 }
485 }
486
2/2
✓ Branch 0 taken 697 times.
✓ Branch 1 taken 2762 times.
3459 for (auto p : portPins) {
487
8/10
✓ Branch 0 taken 161 times.
✓ Branch 1 taken 536 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 121 times.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 40 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 657 times.
697 if (p && p->eFusePin && p->eFusePin->getValue() == p->eFuseOKValue) {
488
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 clearEFuseWarning(p, 0);
489 }
490 }
491
1/2
✓ Branch 0 taken 2762 times.
✗ Branch 1 not taken.
2762 lock.unlock();
492
4/6
✓ Branch 0 taken 2762 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2762 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2760 times.
5524 if (CommandManager::INSTANCE.HasPreset("OUTPUTS_ENABLED")) {
493
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 CommandManager::INSTANCE.TriggerPreset("OUTPUTS_ENABLED");
494 }
495 2762 }
496 2728 void OutputMonitor::DisableOutputs() {
497
1/2
✓ Branch 0 taken 2728 times.
✗ Branch 1 not taken.
2728 std::unique_lock<std::shared_mutex> lock(gpioLock);
498
5/6
✓ Branch 0 taken 2706 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2706 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 2706 times.
2728 if (!pullHighOutputPins.empty() || !pullLowOutputPins.empty()) {
499
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 LogDebug(VB_CHANNELOUT, "Disabling outputs\n");
500 }
501 2728 outputsEnabled = false;
502
2/2
✓ Branch 0 taken 685 times.
✓ Branch 1 taken 2728 times.
3413 for (auto p : portPins) {
503
2/2
✓ Branch 0 taken 147 times.
✓ Branch 1 taken 538 times.
685 if (p) {
504
2/2
✓ Branch 0 taken 882 times.
✓ Branch 1 taken 147 times.
1029 for (auto& r : p->receivers) {
505 882 r.isOn = false;
506
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 354 times.
882 if (p->isSmartReceiver) {
507 528 r.current = 0;
508 }
509 }
510 }
511 }
512
1/2
✓ Branch 0 taken 2728 times.
✗ Branch 1 not taken.
2728 PinCapabilities::SetMultiPinValue(pullHighOutputPins, 0);
513
1/2
✓ Branch 0 taken 2728 times.
✗ Branch 1 not taken.
2728 PinCapabilities::SetMultiPinValue(pullLowOutputPins, 1);
514
1/2
✓ Branch 0 taken 2728 times.
✗ Branch 1 not taken.
2728 lock.unlock();
515
4/6
✓ Branch 0 taken 2728 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2728 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2726 times.
5456 if (CommandManager::INSTANCE.HasPreset("OUTPUTS_DISABLED")) {
516
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 CommandManager::INSTANCE.TriggerPreset("OUTPUTS_DISABLED");
517 }
518 2728 }
519
520 603 void OutputMonitor::SetOutput(const std::string& port, bool on) {
521 // Smart-receiver commands are collected under gpioLock and dispatched
522 // after it is released: srCallback lands in FalconV5Support, and calling
523 // out of the monitor with gpioLock held invites re-entry deadlocks.
524 struct SRAction {
525 int port;
526 int index;
527 const char* cmd;
528 };
529 603 std::vector<SRAction> srActions;
530 {
531
1/2
✓ Branch 0 taken 603 times.
✗ Branch 1 not taken.
603 std::unique_lock<std::shared_mutex> lock(gpioLock);
532 603 int pn = 0;
533
2/2
✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 599 times.
2999 for (auto p : portPins) {
534
6/8
✓ Branch 0 taken 2400 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2396 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 2396 times.
2400 if (p && p->name == port && p->enablePin) {
535 4 p->receivers[0].hasTriggered = false;
536 4 p->receivers[0].isOn = on;
537
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 int value = p->highToEnable ? on : !on;
538
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 clearEFuseWarning(p, 0);
539
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 p->enablePin->setValue(value);
540 4 return;
541
3/4
✓ Branch 0 taken 2396 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2356 times.
✓ Branch 3 taken 40 times.
2396 } else if (p && p->isSmartReceiver) {
542
2/2
✓ Branch 0 taken 14136 times.
✓ Branch 1 taken 2356 times.
16492 for (int x = 0; x < 6; x++) {
543
5/8
✓ Branch 0 taken 14136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14136 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14136 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 589 times.
✓ Branch 7 taken 13547 times.
42408 if (port == std::string(p->name) + std::string(1, 'A' + x)) {
544
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 589 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
589 bool isOn = p->receivers[x].isOn && !p->receivers[x].hasTriggered;
545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 589 times.
589 if (p->receivers[x].hasTriggered) {
546 ✗ srActions.push_back({ pn, x, "ResetOutput" });
547
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 293 times.
589 } else if (on != isOn) {
548
1/2
✓ Branch 0 taken 296 times.
✗ Branch 1 not taken.
296 srActions.push_back({ pn, x, "ToggleOutput" });
549 }
550 }
551 }
552 }
553 2396 pn++;
554 }
555
2/2
✓ Branch 0 taken 599 times.
✓ Branch 1 taken 4 times.
603 }
556
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 303 times.
599 if (!srActions.empty()) {
557 // Call through the member under srCallbackLock rather than copying it
558 // out first: a copy captures FalconV5Support's raw 'this' without
559 // owning it, so a config reload destroying that object between the
560 // copy and the call leaves us writing into freed memory.
561
1/2
✓ Branch 0 taken 296 times.
✗ Branch 1 not taken.
296 std::unique_lock<std::mutex> cbLock(srCallbackLock);
562
2/2
✓ Branch 0 taken 285 times.
✓ Branch 1 taken 11 times.
296 if (srCallback) {
563
2/2
✓ Branch 0 taken 285 times.
✓ Branch 1 taken 285 times.
570 for (auto& a : srActions) {
564
2/4
✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 285 times.
✗ Branch 3 not taken.
855 srCallback(a.port, a.index, a.cmd);
565 }
566 }
567 296 }
568
2/2
✓ Branch 0 taken 599 times.
✓ Branch 1 taken 4 times.
603 }
569 50 void OutputMonitor::setSmartReceiverEventCallback(std::function<void(int port, int index, const std::string& cmd)>&& f) {
570
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 std::unique_lock<std::mutex> lock(srCallbackLock);
571 50 srCallback = std::move(f);
572 50 }
573 720 void OutputMonitor::RemovePortConfiguration(int port, const Json::Value& config) {
574
1/2
✓ Branch 0 taken 720 times.
✗ Branch 1 not taken.
720 std::unique_lock<std::shared_mutex> lock(gpioLock);
575
1/2
✓ Branch 0 taken 720 times.
✗ Branch 1 not taken.
720 std::string name = "Port " + std::to_string(port + 1);
576
6/8
✓ Branch 0 taken 720 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
✓ Branch 3 taken 510 times.
✓ Branch 4 taken 210 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 210 times.
✓ Branch 7 taken 510 times.
720 if (port < portPins.size() && portPins[port] && portPins[port]->name == name) {
577 210 PortPinInfo* pi = portPins[port];
578
2/2
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 157 times.
210 if (pi->enablePin) {
579 // The pin stays on the enable list while another enabled port
580 // shares it, and stays claimed while any other port, enabled or
581 // not, still holds it. A port with no pixels is registered
582 // disabled, but its pin was claimed all the same, and Port Status
583 // and the eFuse handlers still drive it through that port.
584 53 bool sharedWithEnabledPort = false;
585 53 bool sharedWithAnyPort = false;
586
2/2
✓ Branch 0 taken 466 times.
✓ Branch 1 taken 44 times.
510 for (auto other : portPins) {
587
5/6
✓ Branch 0 taken 466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 398 times.
466 if (other && other != pi && other->enablePin == pi->enablePin) {
588 16 sharedWithAnyPort = true;
589
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 7 times.
16 if (other->receivers[0].enabled) {
590 9 sharedWithEnabledPort = true;
591 9 break;
592 }
593 }
594 }
595
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 9 times.
53 if (!sharedWithEnabledPort) {
596
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if (pi->highToEnable) {
597 44 pullHighOutputPins.remove(pi->enablePin);
598 } else {
599 ✗ pullLowOutputPins.remove(pi->enablePin);
600 }
601 }
602
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 14 times.
53 if (!sharedWithAnyPort) {
603 // The pin object is shared, and releasing it drops its gpiod
604 // request, so setValue() on it becomes a silent no-op for any
605 // port still using it (on a Pi the line also reverts to an
606 // input and floats).
607
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 pi->enablePin->releasePin();
608 }
609 }
610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
210 if (pi->eFuseInterruptPin) {
611 // One interrupt pin (and its GPIO callback) can serve several
612 // ports; only unregister it when the last port using it goes away.
613 // fusePins is keyed by the interrupt pin's name -- erasing it here
614 // is what lets a later AddPortConfiguration re-register the
615 // callback; leaving it behind means fuse trips are silently
616 // ignored after a config reload. getPinByName() matches on name
617 // exactly (there are no aliases), so the name here is the same
618 // string the add side keyed on.
619 ✗ bool sharedInterrupt = false;
620 ✗ for (auto other : portPins) {
621 ✗ if (other && other != pi && other->eFuseInterruptPin == pi->eFuseInterruptPin) {
622 ✗ sharedInterrupt = true;
623 ✗ break;
624 }
625 }
626 ✗ if (!sharedInterrupt) {
627 ✗ GPIOManager::INSTANCE.RemoveGPIOCallback(pi->eFuseInterruptPin);
628 ✗ fusePins.erase(pi->eFuseInterruptPin->name);
629 ✗ pi->eFuseInterruptPin->releasePin();
630 }
631 ✗ if (pi->eFusePin) {
632 ✗ pi->eFusePin->releasePin();
633 }
634
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 178 times.
210 } else if (pi->eFusePin) {
635
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 GPIOManager::INSTANCE.RemoveGPIOCallback(pi->eFusePin);
636
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 pi->eFusePin->releasePin();
637 }
638 // reset() drops the pin pointers, so a retry still queued against this
639 // port would take processRetries() through a null eFusePin/enablePin.
640 // The timer stops itself once the list empties.
641 210 eFuseRetries.remove(pi);
642 // reset() also drops each receiver's stored warning text, which is
643 // the only handle RemoveWarning() can match on -- take the eFuse and
644 // pixel-count banners down first or they outlive the port.
645
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 clearReceiverWarnings(pi);
646
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 pi->reset();
647 }
648 720 }
649
650 722 void OutputMonitor::AddPortConfiguration(int port, const Json::Value& pinConfig, bool enabled) {
651
1/2
✓ Branch 0 taken 722 times.
✗ Branch 1 not taken.
722 std::unique_lock<std::shared_mutex> lock(gpioLock);
652
1/2
✓ Branch 0 taken 722 times.
✗ Branch 1 not taken.
722 std::string name = "Port " + std::to_string(port + 1);
653
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 246 times.
722 if (port >= portPins.size()) {
654
1/2
✓ Branch 0 taken 476 times.
✗ Branch 1 not taken.
476 portPins.resize(port + 1);
655 }
656
6/6
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 583 times.
✓ Branch 2 taken 111 times.
✓ Branch 3 taken 28 times.
✓ Branch 4 taken 111 times.
✓ Branch 5 taken 611 times.
722 if (portPins[port] && portPins[port]->name == name) {
657
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 portPins[port]->setConfig(name, pinConfig);
658 111 return;
659 }
660 611 PortPinInfo* pi = portPins[port];
661
2/2
✓ Branch 0 taken 583 times.
✓ Branch 1 taken 28 times.
611 if (!pi) {
662
3/8
✓ Branch 0 taken 583 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 583 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 583 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
583 pi = new PortPinInfo();
663 }
664
1/2
✓ Branch 0 taken 611 times.
✗ Branch 1 not taken.
611 pi->setConfig(name, pinConfig);
665 611 bool hasInfo = false;
666 611 pi->receivers[0].enabled = true;
667
3/4
✓ Branch 0 taken 611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 557 times.
611 if (pinConfig.isMember("enablePin")) {
668
3/6
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
54 std::string ep = pinConfig.get("enablePin", "").asString();
669
2/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
54 if (ep != "") {
670 54 pi->highToEnable = (ep[0] != '!');
671
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 pi->enablePin = addOutputPinInternal(name, ep, enabled);
672
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 53 times.
54 if (!pi->enablePin) {
673 1 enabled = false;
674 }
675
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 44 times.
54 if (!enabled) {
676 10 pi->receivers[0].enabled = false;
677 }
678 54 hasInfo = true;
679 }
680 54 }
681
3/4
✓ Branch 0 taken 611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 595 times.
611 if (pinConfig.isMember("group")) {
682
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 int g = pinConfig["group"].asInt();
683 16 pi->group = g;
684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (g >= numGroups) {
685 ✗ numGroups = g + 1;
686 }
687 }
688
3/4
✓ Branch 0 taken 611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 579 times.
611 if (pinConfig.isMember("eFusePin")) {
689
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
32 if (pinConfig.isMember("eFuseInterruptPin")) {
690 ✗ std::string eFuseInterruptPin = pinConfig.get("eFuseInterruptPin", "").asString();
691 // A leading '!' is stripped but carries no meaning here, and there
692 // is deliberately no inverted-interrupt flag to go with it: the
693 // callback below ignores the edge value it is handed and re-reads
694 // every affected port's eFusePin, so which edge announced the trip
695 // cannot change the outcome. (The pin is registered for BOTH edges
696 // anyway -- some i2c expanders mislabel a single-edge request -- so
697 // a polarity flag would have nothing to act on.)
698 ✗ if (eFuseInterruptPin[0] == '!') {
699 ✗ eFuseInterruptPin = eFuseInterruptPin.substr(1);
700 }
701 ✗ std::string postFix = "";
702 ✗ if (eFuseInterruptPin[0] == '-') {
703 ✗ postFix = "_pd";
704 ✗ eFuseInterruptPin = eFuseInterruptPin.substr(1);
705 ✗ } else if (eFuseInterruptPin[0] == '+') {
706 ✗ postFix = "_pu";
707 ✗ eFuseInterruptPin = eFuseInterruptPin.substr(1);
708 }
709 ✗ pi->eFuseInterruptPin = PinCapabilities::getPinByName(eFuseInterruptPin).ptr();
710 ✗ if (!pi->eFuseInterruptPin) {
711 ✗ LogWarn(VB_CHANNELOUT, "Could not find pin " + eFuseInterruptPin + " to handle fuse interrupts for output " + name + "\n");
712 ✗ WarningHolder::AddWarning(51, "Could not find pin " + eFuseInterruptPin + " to handle fuse interrupts for output " + name);
713 } else {
714 ✗ hasInfo = true;
715 ✗ if (fusePins[eFuseInterruptPin] == nullptr) {
716 ✗ pi->eFuseInterruptPin->configPin("gpio" + postFix, false, "eFuseInterrupt");
717 ✗ fusePins[eFuseInterruptPin] = pi->eFuseInterruptPin;
718 // Capture the pin, not the registering port: several ports
719 // share one interrupt pin, and the port that happened to
720 // register it can be reset by a config reload while the
721 // callback (and the other ports) live on.
722 ✗ const PinCapabilities* intPin = pi->eFuseInterruptPin;
723 ✗ GPIOManager::INSTANCE.AddGPIOCallback(intPin, [this, intPin](int v) {
724 ✗ std::unique_lock<std::shared_mutex> lock(gpioLock);
725 ✗ for (auto a : portPins) {
726 ✗ if (a && a->eFuseInterruptPin == intPin && a->eFusePin) {
727 ✗ int v = a->eFusePin->getValue();
728 ✗ if (v != a->eFuseOKValue) {
729 ✗ if (a->enablePin) {
730 // make sure the port is turned off
731 ✗ a->enablePin->setValue(a->highToEnable ? 0 : 1);
732 }
733 ✗ if (a->receivers[0].isOn && !a->receivers[0].hasTriggered) {
734 // Output SHOULD be on, but the fuse triggered. That's a warning.
735 ✗ a->receivers[0].hasTriggered = true;
736 ✗ if (checkEFuseRetry(a)) {
737 ✗ addEFuseWarning(a, 0);
738 }
739 }
740 }
741 }
742 }
743 ✗ lock.unlock();
744 ✗ triggerEFusePresets();
745 ✗ return true;
746 ✗ });
747 }
748 }
749 ✗ }
750
3/6
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
32 std::string eFusePin = pinConfig.get("eFusePin", "").asString();
751 32 bool eFuseHigh = false;
752
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 if (eFusePin[0] == '!') {
753 16 eFuseHigh = true;
754
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 eFusePin = eFusePin.substr(1);
755 }
756
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 std::string postFix = "";
757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (eFusePin[0] == '-') {
758 ✗ postFix = "_pd";
759 ✗ eFusePin = eFusePin.substr(1);
760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 } else if (eFusePin[0] == '+') {
761 ✗ postFix = "_pu";
762 ✗ eFusePin = eFusePin.substr(1);
763 }
764
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 pi->eFusePin = PinCapabilities::getPinByName(eFusePin).ptr();
765
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 pi->eFuseOKValue = eFuseHigh ? 1 : 0;
766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (pi->eFusePin == nullptr) {
767 ✗ LogWarn(VB_CHANNELOUT, "Could not find pin " + eFusePin + " to handle fuse for output " + name + "\n");
768 ✗ WarningHolder::AddWarning(51, "Could not find pin " + eFusePin + " to handle fuse for output " + name);
769 } else {
770
3/6
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
32 pi->eFusePin->configPin("gpio" + postFix, false, "eFuse" + std::to_string(port + 1));
771
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (pi->eFuseInterruptPin == nullptr) {
772
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 GPIOManager::INSTANCE.AddGPIOCallback(pi->eFusePin, [this, pi](int v) {
773
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 std::unique_lock<std::shared_mutex> lock(gpioLock);
774 // The callback is unregistered before a reload resets pi,
775 // but a dispatch already in flight can still land here.
776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!pi->eFusePin) {
777 ✗ return true;
778 }
779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 v = pi->eFusePin->getValue();
780
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (v != pi->eFuseOKValue) {
781
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (pi->enablePin) {
782 // make sure the port is turned off
783
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 pi->enablePin->setValue(pi->highToEnable ? 0 : 1);
784 }
785
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (pi->receivers[0].isOn) {
786 7 pi->receivers[0].hasTriggered = true;
787
3/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
7 if (checkEFuseRetry(pi)) {
788
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 addEFuseWarning(pi, 0);
789 }
790 }
791 }
792
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 lock.unlock();
793
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 triggerEFusePresets();
794 9 return true;
795 9 });
796 }
797 32 hasInfo = true;
798 }
799 32 }
800
3/4
✓ Branch 0 taken 611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✓ Branch 3 taken 565 times.
611 if (pinConfig.isMember("currentSensor")) {
801
4/6
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 30 times.
✓ Branch 5 taken 16 times.
46 if (pinConfig["currentSensor"].isMember("path")) {
802 30 hasInfo = true;
803
4/10
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 30 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 30 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
30 pi->currentMonitor = new FileCurrentMonitor(pinConfig["currentSensor"]);
804
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
16 } else if (pinConfig["currentSensor"].isMember("sensor")) {
805 16 hasInfo = true;
806
4/10
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
16 pi->currentMonitor = new SensorCurrentMonitor(pinConfig["currentSensor"]);
807 }
808 }
809
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 549 times.
611 if (hasInfo) {
810 // AddOutputPin() above brought the enable pin up in whatever state the
811 // monitor is in, so the port bookkeeping has to agree with it. It is
812 // what decides whether an eFuse trip on this port is reported as a
813 // trip or silently swallowed, and what the status API reports.
814
4/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 3 times.
62 pi->receivers[0].isOn = outputsEnabled && pi->receivers[0].enabled;
815 62 portPins[port] = pi;
816
3/4
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✓ Branch 3 taken 512 times.
549 } else if (pinConfig.isMember("falconV5Listener")) {
817 // Rows are 1-based (the page addresses them with nth-child), so a cape
818 // with no monitored local ports still starts its first block on row 1.
819 37 int mr = 0;
820 37 bool hasSR = false;
821
2/2
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 37 times.
295 for (auto a : portPins) {
822
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 22 times.
258 if (a) {
823 236 mr = std::max(mr, a->row);
824 236 hasSR |= a->isSmartReceiver;
825 }
826 }
827
828 // A new block goes beside the previous block, so the column comes from
829 // the last receiver port before this one. Not portPins.back(): the
830 // resize above just made that this port's own, still unplaced, slot.
831 37 int col = 1;
832
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 23 times.
53 for (int p = port - 1; p >= 0; --p) {
833
5/6
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 16 times.
30 if (portPins[p] && portPins[p]->isSmartReceiver) {
834 14 col = portPins[p]->col;
835 14 break;
836 }
837 }
838
839 37 pi->isSmartReceiver = true;
840 37 pi->group = -1;
841 37 pi->receivers[0].enabled = false;
842 37 portPins[port] = pi;
843
844
4/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 9 times.
37 if (!hasSR || col == 8) {
845 28 col = 1;
846
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 23 times.
28 mr += hasSR ? 8 : 1;
847 } else {
848 9 col = 5;
849 }
850
851
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 if (pi->row == -1) {
852 37 pi->col = col;
853 37 pi->row = mr;
854 }
855 37 int mc = pi->col;
856 37 mr = pi->row;
857
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 15 times.
37 if ((port + 4) > portPins.size()) {
858
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 portPins.resize(port + 4);
859 }
860
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 37 times.
148 for (int x = 1; x < 4; x++) {
861
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 std::string name = "Port " + std::to_string(port + 1 + x);
862 // after a reload the slot still holds the entry the last
863 // configuration placed, reset by RemovePortConfiguration()
864 111 pi = portPins[port + x];
865
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 45 times.
111 if (!pi) {
866
3/8
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 66 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
66 pi = new PortPinInfo();
867 }
868
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 pi->setConfig(name, pinConfig);
869
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 if (pi->row == -1) {
870 111 pi->row = mr;
871 111 pi->col = mc + x;
872 }
873 111 pi->isSmartReceiver = true;
874 111 pi->group = -1;
875 111 portPins[port + x] = pi;
876 111 }
877 } else {
878
1/2
✓ Branch 0 taken 512 times.
✗ Branch 1 not taken.
512 clearReceiverWarnings(pi);
879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 512 times.
512 if (portPins[port] == pi) {
880 ✗ pi->reset();
881 } else {
882
1/2
✓ Branch 0 taken 512 times.
✗ Branch 1 not taken.
512 delete pi;
883 }
884 }
885
4/4
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 611 times.
✓ Branch 3 taken 111 times.
833 }
886
887 ✗ const PinCapabilities* OutputMonitor::AddOutputPin(const std::string& name, const std::string& pinName, bool addToList) {
888 ✗ std::unique_lock<std::shared_mutex> lock(gpioLock);
889 ✗ return addOutputPinInternal(name, pinName, addToList);
890 ✗ }
891 // gpioLock must be held exclusively.
892 54 const PinCapabilities* OutputMonitor::addOutputPinInternal(const std::string& name, const std::string& pinName, bool addToList) {
893
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 std::string pin = pinName;
894 54 bool highToEnable = true;
895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (pin[0] == '!') {
896 ✗ pin = pin.substr(1);
897 ✗ highToEnable = false;
898 }
899
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 auto& op = highToEnable ? pullHighOutputPins : pullLowOutputPins;
900
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 43 times.
111 for (auto& pc : op) {
901
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 57 times.
68 if (pc->name == pin) {
902 11 return pc;
903 }
904 }
905
906
2/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
43 const PinCapabilities* pc = PinCapabilities::getPinByName(pin).ptr();
907
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
43 if (!pc) {
908
5/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 LogWarn(VB_CHANNELOUT, "Could not find pin " + pin + " to enable output " + name + "\n");
909
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 WarningHolder::AddWarning(51, "Could not find pin " + pin + " to enable output " + name);
910 1 return nullptr;
911 }
912
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 4 times.
42 if (addToList) {
913
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 op.push_back(pc);
914 }
915
3/6
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
104 pc->configPin("gpio", true, "Enable-" + name);
916 // Only pins that go on the enable lists follow the monitor's state; a port
917 // with nothing configured on it is left off even while output is running.
918
4/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 32 times.
42 bool on = addToList && outputsEnabled;
919
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
44 pc->setValue(on ? highToEnable : !highToEnable);
920 42 return pc;
921 56 }
922
923 2744 void OutputMonitor::AutoEnableOutputs() {
924 2744 int i = getSettingInt("AutoEnableOutputs", 1);
925
1/2
✓ Branch 0 taken 2744 times.
✗ Branch 1 not taken.
2744 if (i) {
926 2744 EnableOutputs();
927 }
928 2744 }
929 2719 void OutputMonitor::AutoDisableOutputs() {
930 2719 int i = getSettingInt("AutoEnableOutputs", 1);
931
1/2
✓ Branch 0 taken 2719 times.
✗ Branch 1 not taken.
2719 if (i) {
932 2719 DisableOutputs();
933 }
934 2719 }
935
936 10 void OutputMonitor::lockToGroup(int i) {
937 10 curGroup = i;
938 10 Sensors::INSTANCE.lockToGroup(i);
939 10 }
940 5 bool OutputMonitor::isPortInGroup(int group, int port) {
941
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::shared_lock<std::shared_mutex> lock(gpioLock);
942
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
10 return ((port < portPins.size()) && portPins[port] && (group == portPins[port]->group));
943 5 }
944
945 1476 std::vector<float> OutputMonitor::GetPortCurrentValues() {
946
1/2
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
1476 Sensors::INSTANCE.updateSensorSources(true);
947
1/2
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
1476 std::shared_lock<std::shared_mutex> lock(gpioLock);
948 1476 std::vector<float> ret;
949
1/2
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
1476 ret.reserve(portPins.size());
950
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 1476 times.
2952 for (auto a : portPins) {
951
4/8
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1476 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1476 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1476 times.
✗ Branch 7 not taken.
1476 if (a && a->currentMonitor && ((curGroup == -1) || (curGroup == a->group))) {
952
2/4
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1476 times.
✗ Branch 3 not taken.
1476 ret.push_back(a->currentMonitor->getValue());
953 ✗ } else if (a) {
954 ✗ ret.push_back(a->receivers[0].current);
955 }
956 }
957 1476 return ret;
958 1476 }
959 6 void OutputMonitor::SetPixelCount(int port, int pc, int cc) {
960
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::unique_lock<std::shared_mutex> lock(gpioLock);
961
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
6 if (port < portPins.size() && portPins[port] && ((curGroup == -1) || (curGroup == portPins[port]->group))) {
962 6 portPins[port]->receivers[0].pixelCount = pc;
963 6 portPins[port]->receivers[0].configuredCount = cc;
964 }
965 6 }
966 ✗ int OutputMonitor::GetPixelCount(int port) {
967 ✗ std::shared_lock<std::shared_mutex> lock(gpioLock);
968 ✗ if (port < portPins.size() && portPins[port]) {
969 ✗ return portPins[port]->receivers[0].pixelCount;
970 }
971 ✗ return 0;
972 ✗ }
973
974 259 void OutputMonitor::GetCurrentPortStatusJson(Json::Value& result) {
975 // The sensor refresh does its own locking; keep it outside ours.
976
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 Sensors::INSTANCE.updateSensorSources();
977
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 std::shared_lock<std::shared_mutex> lock(gpioLock);
978
2/2
✓ Branch 0 taken 1281 times.
✓ Branch 1 taken 259 times.
1540 for (auto a : portPins) {
979
2/2
✓ Branch 0 taken 1275 times.
✓ Branch 1 taken 6 times.
1281 if (a) {
980
1/2
✓ Branch 0 taken 1275 times.
✗ Branch 1 not taken.
1275 a->appendTo(result);
981 }
982 }
983 259 }
984
985 5 void OutputMonitor::addEFuseWarning(PortPinInfo* pi, int rec) {
986
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (pi && rec < 6) {
987
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string name = pi->name;
988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (pi->isSmartReceiver) {
989 ✗ name += std::string(1, 'A' + rec);
990 }
991
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string warn = "eFUSE Triggered for " + name;
992
993
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (!pi->receivers[rec].warning.starts_with(warn)) {
994
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
5 if (sequence->IsSequenceRunning()) {
995
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string seq = sequence->GetSeqFilenameCopy();
996 1 int sTime = sequence->m_seqMSElapsed / 1000;
997
7/14
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
1 warn += " (" + seq + "/" + std::to_string(sTime / 60) + ":" + std::to_string(sTime % 60) + ")";
998 1 }
999
1000
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 LogWarn(VB_CHANNELOUT, warn + "\n");
1001 // Output SHOULD be on, but the fuse triggered. That's a warning.
1002
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 WarningHolder::AddWarning(16, warn);
1003
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 pi->receivers[rec].warning = warn;
1004
1005 // Presets run commands synchronously, and an EFUSE_TRIGGERED
1006 // preset that flips outputs ("Outputs Off", "Set Port Status")
1007 // re-enters this class -- firing it here, with gpioLock held,
1008 // self-deadlocks. Queue it; every caller drains the queue via
1009 // triggerEFusePresets() once it has released the lock.
1010
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 pendingEFusePresets.push_back(name);
1011 }
1012 5 }
1013 5 }
1014 3586 void OutputMonitor::triggerEFusePresets() {
1015 // Must be called WITHOUT gpioLock held.
1016 3586 std::vector<std::string> ports;
1017 {
1018
1/2
✓ Branch 0 taken 3586 times.
✗ Branch 1 not taken.
3586 std::unique_lock<std::shared_mutex> lock(gpioLock);
1019 3586 ports.swap(pendingEFusePresets);
1020 3586 }
1021
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3586 times.
3591 for (auto& name : ports) {
1022
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
10 if (CommandManager::INSTANCE.HasPreset("EFUSE_TRIGGERED")) {
1023 ✗ std::map<std::string, std::string> keywords;
1024 ✗ keywords["PORT"] = name;
1025 ✗ CommandManager::INSTANCE.TriggerPreset("EFUSE_TRIGGERED", keywords);
1026 ✗ }
1027 }
1028 3586 }
1029 8770 void OutputMonitor::clearEFuseWarning(PortPinInfo* port, int rec) {
1030
2/4
✓ Branch 0 taken 8770 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8770 times.
✗ Branch 3 not taken.
8770 if (port && rec < 6) {
1031
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8764 times.
8770 if (!port->receivers[rec].warning.empty()) {
1032
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 WarningHolder::RemoveWarning(16, port->receivers[rec].warning);
1033 6 port->receivers[rec].warning.clear();
1034 }
1035 8770 port->receivers[rec].retryCount = 0;
1036 }
1037 8770 }
1038 // Every receiver's warning (eFuse trip or pixel-count mismatch, both id 16)
1039 // is retracted by its stored text, so a PortPinInfo must not be reset or
1040 // deleted while one is still up. gpioLock must be held exclusively.
1041 859 void OutputMonitor::clearReceiverWarnings(PortPinInfo* port) {
1042
2/2
✓ Branch 0 taken 5154 times.
✓ Branch 1 taken 859 times.
6013 for (int r = 0; r < 6; r++) {
1043 5154 clearEFuseWarning(port, r);
1044 }
1045 859 }
1046 7 bool OutputMonitor::checkEFuseRetry(PortPinInfo* port) {
1047
3/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5 times.
7 if (port && port->receivers[0].retryCount < eFuseRetryCount) {
1048 2 LogDebug(VB_CHANNELOUT, "eFuse triggered for %s. Attempting reset retry #%d\n", port->name.c_str(), port->receivers[0].retryCount + 1);
1049
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (std::find(eFuseRetries.begin(), eFuseRetries.end(), port) == eFuseRetries.end()) {
1050 2 eFuseRetries.push_back(port);
1051 }
1052
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!retryTimerRunning) {
1053
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
6 Timers::INSTANCE.addPeriodicTimer("eFuse Retry", 100, [this]() {
1054 5 processRetries();
1055 5 });
1056 2 retryTimerRunning = true;
1057 }
1058 2 return false;
1059 }
1060 5 return true;
1061 }
1062 5 void OutputMonitor::processRetries() {
1063
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::unique_lock<std::shared_mutex> lock(gpioLock);
1064
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 long long ft = GetMonotonicTimeMS(); // retry timing: must not step with the wall clock
1065 5 std::list<PortPinInfo*> toRemove;
1066
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (auto p : eFuseRetries) {
1067
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (!p->eFusePin || !p->enablePin) {
1068 // A port with an eFuse but no enable pin has no way to retry, and
1069 // a port reset by a config reload has neither.
1070 ✗ toRemove.push_back(p);
1071
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 } else if (!p->receivers[0].isOn) {
1072 // Turned off (Outputs Off, or the port switched off) while it was
1073 // retrying. Pulsing the enable pin now would power it back up
1074 // behind the user's back, and leave it on with isOn false, where
1075 // a later trip is ignored.
1076
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 toRemove.push_back(p);
1077
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 } else if (p->eFusePin->getValue() == p->eFuseOKValue) {
1078 ✗ p->receivers[0].okCount++;
1079 // must be good for at least two seconds
1080 ✗ long long resetTime = p->receivers[0].nextRetryTime;
1081 ✗ resetTime += 2000;
1082 ✗ if (ft > resetTime) {
1083 ✗ p->receivers[0].retryCount = 0;
1084 ✗ toRemove.push_back(p);
1085 }
1086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 } else if (p->receivers[0].retryCount > eFuseRetryCount) {
1087 // still not good after all the retries, mark it bad and send the warning
1088 ✗ toRemove.push_back(p);
1089 ✗ addEFuseWarning(p);
1090
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
4 } else if (p->receivers[0].retryCount == 0 || ft > p->receivers[0].nextRetryTime) {
1091 2 p->receivers[0].enabled = true;
1092 2 p->receivers[0].hasTriggered = false;
1093
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (p->receivers[0].retryCount == 0) {
1094 2 p->receivers[0].firstTriggerTime = ft;
1095 2 p->receivers[0].nextRetryTime = ft;
1096 }
1097 2 p->receivers[0].nextRetryTime += eFuseRetryInterval;
1098 2 p->receivers[0].retryCount++;
1099
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 p->enablePin->setValue(p->highToEnable ? 0 : 1);
1100
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 p->enablePin->setValue(p->highToEnable ? 1 : 0);
1101 }
1102 }
1103
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 for (auto p : toRemove) {
1104 1 eFuseRetries.remove(p);
1105 }
1106
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 if (eFuseRetries.empty()) {
1107
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 Timers::INSTANCE.stopPeriodicTimer("eFuse Retry");
1108 1 retryTimerRunning = false;
1109 }
1110
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 lock.unlock();
1111
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 triggerEFusePresets();
1112 5 }
1113 3572 void OutputMonitor::setSmartReceiverInfo(int port, int index, bool enabled, bool tripped, int current, int pixelCount) {
1114 // printf(" %d %c: Current: %d PC: %d EN: %d TR: %d\n", port + 1, (char)('A' + index), current, pixelCount, enabled, tripped);
1115 // both come decoded off the wire from a receiver's reply; receivers[] has 6
1116
3/6
✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3572 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3572 times.
3572 if (port < 0 || index < 0 || index >= 6) {
1117 ✗ return;
1118 }
1119
1/2
✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
3572 std::unique_lock<std::shared_mutex> lock(gpioLock);
1120
3/6
✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3572 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3572 times.
✗ Branch 5 not taken.
3572 if (port < portPins.size() && portPins[port]) {
1121 3572 portPins[port]->receivers[index].enabled = true;
1122 3572 portPins[port]->receivers[index].isOn = enabled;
1123 3572 portPins[port]->receivers[index].hasTriggered = tripped;
1124 3572 portPins[port]->receivers[index].pixelCount = pixelCount;
1125 3572 portPins[port]->receivers[index].current = current;
1126
1127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3572 times.
3572 if (tripped) {
1128 ✗ addEFuseWarning(portPins[port], index);
1129 } else {
1130
1/2
✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
3572 clearEFuseWarning(portPins[port], index);
1131 }
1132 }
1133
1/2
✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
3572 lock.unlock();
1134
1/2
✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
3572 triggerEFusePresets();
1135 3572 }
1136
1137 // --------------------------------------------------------------------------
1138 // OpenAPI docs for the /fppd/ports/* endpoints handled below.
1139 // --------------------------------------------------------------------------
1140
1141 /**
1142 * Get the current status of every output port (current draw, smart-receiver
1143 * data, sensor readings, etc.). Each port only reports what its hardware can
1144 * measure: "ma" is present only for ports with a current sensor, "status" only
1145 * for ports with an eFuse, and "enabled" only for ports with an enable pin.
1146 *
1147 * @route GET /api/fppd/ports
1148 * @response 200 Array of port status objects.
1149 */
1150
1151 /**
1152 * List the names of all configured output ports.
1153 *
1154 * @route GET /api/fppd/ports/list
1155 * @response 200 Array of port names (first entry is "--ALL--").
1156 * ```json
1157 * ["--ALL--", "Port 1", "Port 2"]
1158 * ```
1159 */
1160
1161 /**
1162 * Start a pixel-count test on all ports, then return current port status.
1163 *
1164 * @route GET /api/fppd/ports/pixelCount
1165 * @response 200 Array of port status objects.
1166 */
1167
1168 /**
1169 * Stop a running pixel-count test, then return current port status.
1170 * Any other test is left running.
1171 *
1172 * @route GET /api/fppd/ports/stop
1173 * @response 200 Array of port status objects.
1174 */
1175 277 HttpResponsePtr OutputMonitor::render_GET(const HttpRequestPtr& req) {
1176
2/4
✓ Branch 0 taken 277 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 277 times.
✗ Branch 3 not taken.
277 auto parts = getPathPieces(req->path());
1177 277 int plen = parts.size();
1178
4/8
✓ Branch 0 taken 277 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 277 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 277 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 277 times.
✗ Branch 7 not taken.
277 if (plen > 1 && parts[1] == "ports") {
1179
7/8
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 255 times.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 272 times.
277 if (plen > 2 && parts[2] == "list") {
1180
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Json::Value result;
1181
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 result.append("--ALL--");
1182
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::shared_lock<std::shared_mutex> lock(gpioLock);
1183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 for (auto a : portPins) {
1184 ✗ if (a && a->isSmartReceiver) {
1185 ✗ for (int x = 0; x < 6; x++) {
1186 ✗ if (a->receivers[x].enabled) {
1187 ✗ result.append(a->name + std::string(1, 'A' + x));
1188 }
1189 }
1190 ✗ } else if (a) {
1191 ✗ result.append(a->name);
1192 }
1193 }
1194
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 lock.unlock();
1195
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
10 std::string resultStr = SaveJsonToString(result);
1196
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 return makeStringResponse(resultStr, 200, "application/json");
1197 5 }
1198 {
1199
1/2
✓ Branch 0 taken 272 times.
✗ Branch 1 not taken.
272 std::shared_lock<std::shared_mutex> lock(gpioLock);
1200
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 257 times.
272 if (portPins.empty()) {
1201
3/6
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
60 return makeStringResponse("[]", 200, "application/json");
1202 }
1203
2/2
✓ Branch 0 taken 257 times.
✓ Branch 1 taken 15 times.
272 }
1204
7/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 250 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 253 times.
257 if (plen > 2 && parts[2] == "pixelCount") {
1205 4 std::vector<std::string> args;
1206
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 args.push_back("50");
1207
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 args.push_back("Output Specific");
1208
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 args.push_back("--ALL--");
1209
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 args.push_back("999");
1210
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 LogDebug(VB_COMMAND, "GET /api/fppd/ports/pixelCount from %s starting Test Mode\n", getEffectiveClientIP(req).c_str());
1211
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 CommandManager::INSTANCE.run("Test Start", args);
1212 4 }
1213
7/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 250 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 254 times.
257 if (plen > 2 && parts[2] == "stop") {
1214 // Only the pixel count the "pixelCount" route starts. The Port
1215 // Status page calls this as it is left, and any other test running
1216 // then was started elsewhere (Channel Outputs, the Display Testing
1217 // page) and is not the page's to end.
1218
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Json::Value test = ChannelTester::INSTANCE.GetStatusJson();
1219
17/44
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 3 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 3 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 3 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
3 if (test.isObject() && test.get("mode", "").asString() == "Outputs" && test.get("type", 0).asInt() == 999) {
1220 3 std::vector<std::string> args;
1221
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 LogDebug(VB_COMMAND, "GET /api/fppd/ports/stop from %s stopping Test Mode\n", getEffectiveClientIP(req).c_str());
1222
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 CommandManager::INSTANCE.run("Test Stop", args);
1223 3 }
1224 3 }
1225
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 Sensors::INSTANCE.updateSensorSources();
1226
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 Json::Value result = Json::arrayValue;
1227
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 GetCurrentPortStatusJson(result);
1228
2/4
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 257 times.
✗ Branch 3 not taken.
514 std::string resultStr = SaveJsonToString(result);
1229
2/4
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 257 times.
✗ Branch 3 not taken.
257 return makeStringResponse(resultStr, 200, "application/json");
1230 257 }
1231 ✗ return makeStringResponse("Not Found", 404, "text/plain");
1232 277 }
1233