MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / guessClock

Function guessClock

src/fe-inspect.cc:73–128  ·  view source on GitHub ↗

* Tries to guess the clock by finding the smallest common interval. * Returns nanoseconds. */

Source from the content-addressed store, hash-verified

71 * Returns nanoseconds.
72 */
73static nanoseconds_t guessClock(const Fluxmap& fluxmap)
74{
75 if (manualClockRate != 0.0)
76 return manualClockRate * 1000.0;
77
78 auto data = FluxmapReader(fluxmap).guessClock(
79 noiseFloorFactor.get(), signalLevelFactor.get());
80
81 std::cout << "\nClock detection histogram:" << std::endl;
82
83 uint32_t max =
84 *std::max_element(std::begin(data.buckets), std::end(data.buckets));
85
86 bool skipping = true;
87 for (int i = 0; i < 256; i++)
88 {
89 nanoseconds_t value = data.buckets[i];
90 if (value < data.noiseFloor / 2)
91 {
92 if (!skipping)
93 std::cout << "..." << std::endl;
94 skipping = true;
95 }
96 else
97 {
98 skipping = false;
99
100 int bar = 320 * value / max;
101 int fullblocks = bar / 8;
102
103 std::string s;
104 for (int j = 0; j < fullblocks; j++)
105 s += BLOCK_ELEMENTS[8];
106 s += BLOCK_ELEMENTS[bar & 7];
107
108 std::cout << fmt::format(
109 "{: 3} {:.2f} {:7} {}", i, (double)i * US_PER_TICK, value, s);
110 std::cout << std::endl;
111 }
112 }
113
114 std::cout << fmt::format("Noise floor: {}\n", data.noiseFloor);
115 std::cout << fmt::format("Signal level: {}\n", data.signalLevel);
116 std::cout << fmt::format(
117 "Peak start: {:.2f} us\n", data.peakStart / 1000.0);
118 std::cout << fmt::format(
119 "Peak end: {:.2f} us\n", data.peakEnd / 1000.0);
120 std::cout << fmt::format("Median: {:.2f} us\n", data.median / 1000.0);
121
122 /*
123 * Okay, the median should now be a good candidate for the (or a) clock.
124 * How this maps onto the actual clock rate depends on the encoding.
125 */
126
127 return data.median;
128}
129
130int mainInspect(int argc, const char* argv[])

Callers 1

mainInspectFunction · 0.85

Calls 3

guessClockMethod · 0.80
FluxmapReaderClass · 0.50
getMethod · 0.45

Tested by

no test coverage detected