GCC Code Coverage Report


Directory: ./
File: channeloutput/stringtesters/PixelCountStringTester.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 277 300 92.3%
Functions: 13 13 100.0%
Branches: 197 291 67.7%

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 GPL v2 as described in the
10 * included LICENSE.GPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #include "PixelCountStringTester.h"
16 #include "../../OutputMonitor.h"
17 #include "../../Timers.h"
18 #include "../../log.h"
19 #include "../../channeltester/ChannelTester.h"
20 #include "../PixelString.h"
21 #include "../channeloutputthread.h"
22
23 #include <algorithm>
24 #include <cmath>
25 #include <inttypes.h>
26
27 // #define PRINT_DEBUG_INFO
28
29 133 uint8_t* PixelCountPixelStringTester::createTestData(PixelString* ps, int cycleCount, float percentOfCycle, uint8_t* inChannelData, uint32_t& newLen) {
30 133 newLen = ps->m_outputBytes;
31 133 uint8_t* data = ps->m_outputBuffer;
32 133 uint8_t* out = ps->pixelDataStart();
33 133 uint32_t inCh = 0;
34 unsigned char clr[6];
35 133 clr[0] = clr[2] = 0;
36 133 clr[1] = 255;
37 133 clr[3] = clr[5] = 0;
38 133 clr[4] = 255;
39 133 int clrOffset = 0;
40 133 int curPixel = 1;
41
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 133 times.
266 for (auto& vs : ps->m_virtualStrings) {
42
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 69 times.
133 if (m_byString) {
43 64 clrOffset = 0;
44 64 curPixel = 1;
45 }
46
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 if (vs.receiverNum == -1) {
47
3/4
✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 133 times.
139 for (int x = 0; x < vs.startNulls * vs.channelsPerNode(); ++x) {
48 6 *out++ = 0;
49 }
50
2/2
✓ Branch 0 taken 13050 times.
✓ Branch 1 taken 133 times.
13183 for (int x = 0; x < vs.pixelCount; ++x) {
51
2/2
✓ Branch 0 taken 260 times.
✓ Branch 1 taken 12790 times.
13050 if (curPixel == 50) {
52 260 uint8_t brightness = vs.brightnessMap[255];
53
3/4
✓ Branch 0 taken 1040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 780 times.
✓ Branch 3 taken 260 times.
1040 for (int y = 0; y < vs.channelsPerNode(); ++y) {
54 780 *out = brightness;
55 780 ++out;
56 780 ++inCh;
57 }
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 260 times.
260 if (++clrOffset == 3) {
59 ✗ clrOffset = 0;
60 }
61 260 curPixel = 1;
62 } else {
63
2/4
✓ Branch 0 taken 12790 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12790 times.
12790 if (vs.colorOrder.whiteOffset() == 0) {
64 ✗ ++out;
65 }
66
3/4
✓ Branch 0 taken 51160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38370 times.
✓ Branch 3 taken 12790 times.
51160 for (int y = 0; y < std::min(vs.channelsPerNode(), 3); ++y) {
67 38370 *out = vs.brightnessMap[clr[y + clrOffset]];
68 38370 out++;
69 }
70
2/4
✓ Branch 0 taken 12790 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12790 times.
12790 if (vs.colorOrder.whiteOffset() == 3) {
71 ✗ ++out;
72 }
73
1/2
✓ Branch 0 taken 12790 times.
✗ Branch 1 not taken.
12790 inCh += vs.channelsPerNode();
74
2/2
✓ Branch 0 taken 1045 times.
✓ Branch 1 taken 11745 times.
12790 if (curPixel % 10 == 0) {
75
2/2
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 653 times.
1045 if (++clrOffset == 3) {
76 392 clrOffset = 0;
77 }
78 }
79 12790 ++curPixel;
80 }
81 }
82
3/4
✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 133 times.
136 for (int x = 0; x < vs.endNulls * vs.channelsPerNode(); ++x) {
83 3 *out++ = 0;
84 }
85 } else {
86 ✗ fillInSmartReceiver(ps, vs, inChannelData, inCh, out);
87 }
88 }
89 133 return data;
90 }
91
92 PixelCountPixelStringTester PixelCountPixelStringTester::INSTANCE_BYPORT(false);
93 PixelCountPixelStringTester PixelCountPixelStringTester::INSTANCE_BYSTRING(true);
94
95 // Pixels lit at once while searching. Sixteen seed pixels draw enough to
96 // read clearly above the sensor's noise; sixteen bullets at full white still
97 // draw well under the ~2A the sensors read up to.
98 constexpr int WINDOW = 16;
99 // The furthest pixel looked for on a port with nothing configured on it.
100 constexpr int MAX_PIXELS = 500;
101 constexpr int WARMUP_MS = 250;
102 // Frames a pattern is held before reading, then frames read. The settle is
103 // long because some sensors are slow to follow: a buffered IIO source (the
104 // BBB capes) delivers new values about once a second, so a shorter hold read
105 // the previous pattern. A measurement taken again reads for longer.
106 constexpr uint32_t SETTLE_FRAMES = 16;
107 constexpr uint32_t SAMPLE_FRAMES = 6;
108 constexpr uint32_t REPEAT_SAMPLE_FRAMES = 24;
109 // How many times an unclear measurement is taken before it is decided on what
110 // has been read. A seed pixel on a noisy sensor needs most of them.
111 constexpr int MAX_REPEATS = 10;
112 // The least a window holding any pixel draws: well under one seed pixel.
113 constexpr float ANY_PIXEL_MA = 3.0f;
114 // The least uncertainty a measurement is given. A sensor that reads in steps
115 // can return the same value every time, and a spread of zero is not
116 // certainty.
117 constexpr float MIN_ERROR_MA = 1.0f;
118
119 constexpr int STATE_WARMUP = 0;
120 constexpr int STATE_MEASURE = 1;
121 constexpr int STATE_DISPLAY_PIXEL = 999;
122
123 enum Phase {
124 PHASE_BASE,
125 PHASE_FIRST_WINDOW,
126 PHASE_DOUBLING,
127 PHASE_HALVING,
128 PHASE_END,
129 PHASE_DONE
130 };
131
132 223 static float median(std::vector<float> v) {
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 223 times.
223 if (v.empty()) {
134 ✗ return 0;
135 }
136 223 std::sort(v.begin(), v.end());
137 223 return v[v.size() / 2];
138 }
139
140 // The mean of the readings without the highest and lowest fifth: the sensors
141 // throw the odd reading a couple of hundred mA out. Also the spread of the
142 // readings, from their median absolute deviation, as a standard deviation.
143 156 static float trimmedMean(std::vector<float> v, float& spread) {
144 156 spread = 0;
145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 156 times.
156 if (v.empty()) {
146 ✗ return 0;
147 }
148
1/2
✓ Branch 0 taken 156 times.
✗ Branch 1 not taken.
156 std::sort(v.begin(), v.end());
149 156 float mid = v[v.size() / 2];
150 156 std::vector<float> dev;
151
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 156 times.
1632 for (float f : v) {
152
1/2
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
1476 dev.push_back(std::fabs(f - mid));
153 }
154
2/4
✓ Branch 0 taken 156 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 156 times.
✗ Branch 3 not taken.
156 spread = 1.4826f * median(dev);
155 156 size_t trim = v.size() / 5;
156 156 float sum = 0;
157
2/2
✓ Branch 0 taken 984 times.
✓ Branch 1 taken 156 times.
1140 for (size_t x = trim; x < v.size() - trim; x++) {
158 984 sum += v[x];
159 }
160 156 return sum / (v.size() - 2 * trim);
161 156 }
162
163 52 void CurrentBasedPixelCountPixelStringTester::measureWindow(PortSearch& p, int start, int len) {
164 52 p.litStart = start;
165 52 p.litLen = len;
166 52 }
167
168 5 void CurrentBasedPixelCountPixelStringTester::startGroup() {
169
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (int x = 0; x < (int)ports.size(); x++) {
170 5 PortSearch& p = ports[x];
171 5 p.testing = OutputMonitor::INSTANCE.isPortInGroup(curGroup, x);
172 5 p.phase = PHASE_BASE;
173 5 p.count = -1;
174 5 p.repeats = 0;
175 5 p.dSum = 0;
176 5 p.errSq = 0;
177 5 p.spreads.clear();
178 5 p.fullWindows.clear();
179 5 p.samples.clear();
180 5 p.darkSamples.clear();
181 5 p.darkAfterSamples.clear();
182 5 measureWindow(p, 0, 0);
183 }
184 5 state = STATE_MEASURE;
185 5 frameInMeasure = 0;
186 5 sampleFrames = SAMPLE_FRAMES;
187 5 part = 0;
188 5 }
189
190 // The pixel to read next while finding the last one: either side of the
191 // count the last window's current suggests, then halfway between the last
192 // pixel known lit and the first known not to be.
193 10 static int nextProbe(int lit, int unlit, int guess) {
194
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
10 if (guess - 1 > lit && guess - 1 < unlit) {
195 5 return guess - 1;
196 }
197
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (guess > lit && guess < unlit) {
198 5 return guess;
199 }
200 ✗ return (lit + unlit) / 2;
201 }
202
203 // Takes one measurement for a port, the lit current less the dark one and
204 // how uncertain that is, and picks what it shows next. Returns true once
205 // the port's count is known.
206 52 bool CurrentBasedPixelCountPixelStringTester::step(PortSearch& p, int port, float d, float err) {
207
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 47 times.
52 if (p.phase == PHASE_BASE) {
208 // three dark readings, for the spread of the port's sensor
209 5 p.phase = PHASE_FIRST_WINDOW;
210
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 measureWindow(p, 0, WINDOW);
211 5 return false;
212 }
213 // A window is lit if it draws more than half a pixel's current (or, for
214 // the first, any current at all). A measurement that does not clear
215 // that by twice its uncertainty is taken again, and the readings are
216 // decided together.
217
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 5 times.
47 float threshold = p.phase == PHASE_FIRST_WINDOW ? ANY_PIXEL_MA : 0.5f * p.perPixel;
218 47 p.dSum += d;
219 47 p.errSq += err * err;
220 47 ++p.repeats;
221 47 float mean = p.dSum / p.repeats;
222 47 float meanErr = std::sqrt(p.errSq) / p.repeats;
223
5/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 37 times.
47 if (std::fabs(mean - threshold) < 2 * meanErr && p.repeats < MAX_REPEATS) {
224
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 LogDebug(VB_CHANNELOUT, "Pixel count: port %d phase %d lit %d+%d: %+.1f mA (mean %+.1f +/- %.1f over %d, threshold %.1f) unclear, again\n",
225 port + 1, p.phase, p.litStart, p.litLen, d, mean, meanErr, p.repeats, threshold);
226 10 return false;
227 }
228 37 bool present = mean > threshold;
229
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 LogDebug(VB_CHANNELOUT, "Pixel count: port %d phase %d lit %d+%d: %+.1f mA (mean %+.1f +/- %.1f over %d, threshold %.1f, per pixel %.1f) %s\n",
230 port + 1, p.phase, p.litStart, p.litLen, d, mean, meanErr, p.repeats, threshold, p.perPixel,
231 present ? "lit" : "dark");
232 37 p.dSum = 0;
233 37 p.errSq = 0;
234 37 p.repeats = 0;
235 37 d = mean;
236
237 // The end is in the window starting at lo: find its last pixel, one at a
238 // time, starting either side of the count the window's current suggests.
239 15 auto probe = [&]() {
240
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 10 times.
15 if (p.unlitPixel - p.litPixel <= 1) {
241 5 p.count = p.unlitPixel;
242 5 return true;
243 }
244 10 measureWindow(p, nextProbe(p.litPixel, p.unlitPixel, p.guess), 1);
245 10 return false;
246 37 };
247 11 auto halve = [&]() {
248
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
11 if (p.hi - p.lo <= WINDOW) {
249 5 p.phase = PHASE_END;
250 5 p.litPixel = p.lo; // a lit window's first pixel is there
251 5 p.unlitPixel = p.hi;
252
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 p.guess = p.lo + std::clamp((int)std::lround(p.loCurrent / p.perPixel), 1, p.hi - p.lo);
253 5 return probe();
254 }
255 6 int mid = p.lo + ((p.hi - p.lo) / WINDOW / 2) * WINDOW;
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (mid <= p.lo) {
257 ✗ mid = p.lo + WINDOW;
258 }
259 6 p.phase = PHASE_HALVING;
260 6 measureWindow(p, mid, WINDOW);
261 6 return false;
262 37 };
263 // A window found lit proves every window before it full: the per-pixel
264 // current is taken from those, not from the first window alone, which is
265 // read while the port's dark current is still climbing after power-on.
266 15 auto foundLit = [&]() {
267
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (p.litStart > p.lo) {
268 15 p.fullWindows.push_back(p.loCurrent);
269
2/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
15 p.perPixel = median(p.fullWindows) / WINDOW;
270 }
271 15 p.lo = p.litStart;
272 15 p.loCurrent = d;
273 15 };
274
275 37 bool done = false;
276
4/5
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
37 switch (p.phase) {
277 5 case PHASE_FIRST_WINDOW:
278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!present) {
279 ✗ p.count = 0;
280 ✗ done = true;
281 ✗ break;
282 }
283 5 p.perPixel = d / WINDOW;
284 5 p.lo = 0;
285 5 p.loCurrent = d;
286 5 p.hi = p.maxPixels;
287 5 p.phase = PHASE_DOUBLING;
288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (2 * WINDOW > p.maxPixels) {
289 ✗ done = halve();
290 } else {
291
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 measureWindow(p, WINDOW, WINDOW);
292 }
293 5 break;
294 16 case PHASE_DOUBLING:
295
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 if (present) {
296
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 foundLit();
297 12 int next = p.lo * 2;
298
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
12 if (next + WINDOW > p.maxPixels) {
299
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 done = halve();
300 } else {
301
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 measureWindow(p, next, WINDOW);
302 }
303 } else {
304 4 p.hi = p.litStart;
305
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 done = halve();
306 }
307 16 break;
308 6 case PHASE_HALVING:
309
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (present) {
310
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 foundLit();
311 } else {
312 3 p.hi = p.litStart;
313 }
314
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 done = halve();
315 6 break;
316 10 case PHASE_END:
317
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (present) {
318 5 p.litPixel = p.litStart;
319 } else {
320 5 p.unlitPixel = p.litStart;
321 }
322
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 done = probe();
323 10 break;
324 ✗ default:
325 ✗ done = true;
326 ✗ break;
327 }
328
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 32 times.
37 if (done) {
329 5 p.phase = PHASE_DONE;
330
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 measureWindow(p, 0, 0);
331
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 LogInfo(VB_CHANNELOUT, "Pixel count: port %d has %d pixels on the wire (%d configured, %d nulls)\n", port + 1, p.count, std::max(p.configured, 0), p.nulls);
332 }
333 37 return done;
334 }
335
336 4028 void CurrentBasedPixelCountPixelStringTester::prepareTestData(int cycleCount, float percentOfCycle) {
337
1/2
✓ Branch 0 taken 4028 times.
✗ Branch 1 not taken.
4028 uint64_t now = GetMonotonicTimeMS();
338 // A new test: the first call, or the cycle count starting again (each
339 // test counts from 0). Not "cycleCount == 0": the cycles can already
340 // have advanced by the first frame a string asks for.
341
4/4
✓ Branch 0 taken 4024 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4023 times.
4028 bool newTest = (state == -1) || (cycleCount < lastCycleCount);
342 4028 lastCycleCount = cycleCount;
343
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4023 times.
4028 if (newTest) {
344 5 curGroup = 0;
345
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 OutputMonitor::INSTANCE.lockToGroup(curGroup);
346
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 SetChannelOutputRefreshRate(20);
347
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 for (int x = 0; x < (int)ports.size(); x++) {
348
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 OutputMonitor::INSTANCE.SetPixelCount(x, -1, -1);
349 // Start each port from its configuration as it is now: the
350 // configured count, nulls and search limit are worked out from
351 // the string on the port's next frame. Kept from the first run,
352 // a string fixed after a count was still searched (and reported)
353 // against the old configuration until fppd restarted.
354 1 ports[x] = PortSearch();
355 }
356 5 state = STATE_WARMUP;
357 5 stateStartMS = now;
358 }
359
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 3998 times.
4028 if (state == STATE_WARMUP) {
360
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 25 times.
30 if (now - stateStartMS >= WARMUP_MS) {
361
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 startGroup();
362 }
363 4023 return;
364 }
365
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 3972 times.
3998 if (state != STATE_MEASURE) {
366 26 return;
367 }
368
2/2
✓ Branch 0 taken 2496 times.
✓ Branch 1 taken 1476 times.
3972 if (++frameInMeasure <= SETTLE_FRAMES) {
369 2496 return;
370 }
371
1/2
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
1476 std::vector<float> values = OutputMonitor::INSTANCE.GetPortCurrentValues();
372
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 1476 times.
2952 for (int x = 0; x < (int)ports.size(); x++) {
373
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 (ports[x].testing && ports[x].phase != PHASE_DONE && x < (int)values.size()) {
374
5/6
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 984 times.
✓ Branch 2 taken 492 times.
✓ Branch 3 taken 492 times.
✓ Branch 4 taken 1476 times.
✗ Branch 5 not taken.
1476 (part == 0 ? ports[x].darkSamples : part == 1 ? ports[x].samples : ports[x].darkAfterSamples).push_back(values[x]);
375 }
376 }
377
2/2
✓ Branch 0 taken 1320 times.
✓ Branch 1 taken 156 times.
1476 if (frameInMeasure < SETTLE_FRAMES + sampleFrames) {
378 1320 return;
379 }
380 156 frameInMeasure = 0;
381
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 52 times.
156 if (part < 2) {
382 // dark, then the patterns lit, then dark again
383 104 ++part;
384 104 return;
385 }
386 52 part = 0;
387 52 bool allDone = true;
388 52 bool repeating = false;
389
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 52 times.
104 for (int x = 0; x < (int)ports.size(); x++) {
390 52 PortSearch& p = ports[x];
391
2/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 52 times.
52 if (!p.testing || p.phase == PHASE_DONE) {
392 ✗ continue;
393 }
394 // The lit reading less the mean of the dark ones either side of it:
395 // a port's dark current climbs for a while after it powers on, and a
396 // string powered at both ends does not return to the same dark
397 // current once it has been lit.
398 float s0, s1, s2;
399
2/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
52 float before = trimmedMean(p.darkSamples, s0);
400
2/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
52 float lit = trimmedMean(p.samples, s1);
401
2/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
52 float after = trimmedMean(p.darkAfterSamples, s2);
402
1/2
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
52 p.spreads.push_back(s0);
403
1/2
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
52 p.spreads.push_back(s1);
404
1/2
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
52 p.spreads.push_back(s2);
405
2/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
52 float spread = median(p.spreads);
406 52 float n0 = std::max<size_t>(p.darkSamples.size(), 1);
407 52 float n1 = std::max<size_t>(p.samples.size(), 1);
408 52 float n2 = std::max<size_t>(p.darkAfterSamples.size(), 1);
409 // the error of the difference from the sensor's spread, and from the
410 // dark current having moved while it was read
411 52 float moved = std::fabs(after - before) / 2;
412 52 float err = std::sqrt(spread * spread * (1 / n1 + 0.25f / n0 + 0.25f / n2) + moved * moved + MIN_ERROR_MA * MIN_ERROR_MA);
413 52 p.base = (before + after) / 2;
414 52 p.darkSamples.clear();
415 52 p.samples.clear();
416 52 p.darkAfterSamples.clear();
417
3/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 5 times.
52 if (!step(p, x, lit - p.base, err)) {
418 47 allDone = false;
419 47 repeating |= p.repeats > 0;
420 }
421 }
422
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 42 times.
52 sampleFrames = repeating ? REPEAT_SAMPLE_FRAMES : SAMPLE_FRAMES;
423
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 5 times.
52 if (!allDone) {
424 47 return;
425 }
426
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (int x = 0; x < (int)ports.size(); x++) {
427
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (ports[x].testing) {
428 // null nodes are pixels on the wire, but not configured ones
429
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 OutputMonitor::INSTANCE.SetPixelCount(x, std::max(ports[x].count - ports[x].nulls, 0), ports[x].configured);
430 }
431 }
432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (curGroup < (OutputMonitor::INSTANCE.getGroupCount() - 1)) {
433 ✗ ++curGroup;
434 ✗ OutputMonitor::INSTANCE.lockToGroup(curGroup);
435 ✗ state = STATE_WARMUP;
436 ✗ stateStartMS = now;
437 ✗ for (auto& p : ports) {
438 ✗ measureWindow(p, 0, 0);
439 }
440 } else {
441
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 OutputMonitor::INSTANCE.lockToGroup(-1);
442 5 state = STATE_DISPLAY_PIXEL;
443 // show each string's last pixel
444
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (auto& p : ports) {
445
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 measureWindow(p, p.count > 0 ? p.count - 1 : 0, p.count > 0 ? 1 : 0);
446 }
447 }
448
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1471 times.
1476 }
449
450 4028 uint8_t* CurrentBasedPixelCountPixelStringTester::createTestData(PixelString* ps, int cycleCount, float percentOfCycle, uint8_t* inChannelData, uint32_t& newLen) {
451 // PixelString allocates every string at least 2400 bytes for testers
452 // like this one, and drivers have always been handed 2000 of them; a
453 // string configured longer than that is searched over its own length.
454 4028 uint32_t pixelLen = std::max<int>(2000, ps->m_outputBytes - (int)ps->m_preamble.size());
455 // everything below indexes from pixel 0, so work past any protocol
456 // preamble and hand back the whole buffer at the end
457 4028 uint8_t* buffer = ps->pixelDataStart();
458 4028 newLen = pixelLen + ps->m_preamble.size();
459 4028 int currentPort = ps->m_portNumber;
460
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4028 times.
4032 while ((int)ports.size() <= currentPort) {
461
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 ports.emplace_back();
462 }
463 4028 PortSearch& p = ports[currentPort];
464
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4023 times.
4028 if (p.configured == -1) {
465 5 p.configured = 0;
466 5 p.nulls = 0;
467
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (auto& a : ps->m_virtualStrings) {
468 5 p.configured += a.pixelCount;
469 5 p.nulls += a.startNulls + a.endNulls;
470 }
471 // Null nodes are physical pixels, sent zeros: the search counts what
472 // is on the wire, and the nulls come off the count it reports. A
473 // configured port is searched a little past its configuration (enough
474 // to find pixels tucked away unconfigured), not to the end of the
475 // buffer: the test frame is cut there too.
476 5 int onWire = p.configured + p.nulls;
477
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 int cpn = ps->m_virtualStrings.empty() ? 3 : ps->m_virtualStrings[0].channelsPerNode();
478
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 p.maxPixels = std::min(onWire > 0 ? onWire + 64 : MAX_PIXELS, (int)(pixelLen / cpn));
479 }
480 4028 memset(buffer, 0, pixelLen);
481
1/2
✓ Branch 0 taken 4028 times.
✗ Branch 1 not taken.
4028 if (!ps->m_virtualStrings.empty()) {
482
1/2
✓ Branch 0 taken 4028 times.
✗ Branch 1 not taken.
4028 int cpn = ps->m_virtualStrings[0].channelsPerNode();
483 4028 newLen = std::min(pixelLen, (uint32_t)(p.maxPixels * cpn)) + ps->m_preamble.size();
484 }
485
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 4003 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
4028 if (state == STATE_WARMUP && curGroup == 0) {
486 // everything dimly on for a moment first, as the outputs come up
487 25 memset(buffer, 10, pixelLen);
488
9/10
✓ Branch 0 taken 3673 times.
✓ Branch 1 taken 330 times.
✓ Branch 2 taken 3642 times.
✓ Branch 3 taken 31 times.
✓ Branch 4 taken 1214 times.
✓ Branch 5 taken 2428 times.
✓ Branch 6 taken 1245 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1245 times.
✓ Branch 9 taken 2758 times.
4003 } else if (p.litLen > 0 && !(state == STATE_MEASURE && part != 1) && !ps->m_virtualStrings.empty()) {
489
1/2
✓ Branch 0 taken 1245 times.
✗ Branch 1 not taken.
1245 int cpn = ps->m_virtualStrings[0].channelsPerNode();
490 1245 int start = std::min(p.litStart, p.maxPixels);
491 1245 int len = std::min(p.litLen, p.maxPixels - start);
492
1/2
✓ Branch 0 taken 1245 times.
✗ Branch 1 not taken.
1245 if ((uint32_t)((start + len) * cpn) <= pixelLen) {
493 1245 memset(&buffer[start * cpn], 0xFF, len * cpn);
494 }
495 }
496 4028 return ps->m_outputBuffer;
497 }
498 27 CurrentBasedPixelCountPixelStringTester::Status CurrentBasedPixelCountPixelStringTester::getCurrentStatus() const {
499
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 26 times.
27 if (state == STATE_DISPLAY_PIXEL) {
500 1 return CurrentBasedPixelCountPixelStringTester::Status::Complete;
501 }
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (state == -1) {
503 ✗ return CurrentBasedPixelCountPixelStringTester::Status::NotRun;
504 }
505 26 return CurrentBasedPixelCountPixelStringTester::Status::Running;
506 }
507
508 CurrentBasedPixelCountPixelStringTester CurrentBasedPixelCountPixelStringTester::INSTANCE;
509