Run It
Every instrument is mocked, so the example runs without hardware.
bash
git clone https://github.com/tofupilot/panelscd panelstofupilot run spectrum-analyzerThe procedure
procedure.yaml
name: Spectrum Analyzerversion: 1.0.0plugs: - key: analyzer name: Spectrum analyzer python: plugs.spectrum_analyzer:SpectrumAnalyzermain: - key: downlink name: Acquire downlink python: phases.spectrum_analyzer:acquire measurements: - key: carrier_level name: Carrier peak level unit: "dBm" validators: - operator: ">=" expected_value: -55 - operator: "<=" expected_value: -40 ui: panel: panels/analyzer.htmlThe panel
panels/analyzer.html
<div class="inst"><svg viewBox="0 0 320 210" role="img"><defs><linearGradient id="fp" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#e6e8eb"/><stop offset="1" stop-color="#c9cdd2"/></linearGradient><linearGradient id="win" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#000" stop-opacity=".55"/><stop offset=".14" stop-color="#000" stop-opacity="0"/></linearGradient></defs><rect x="1" y="1" width="318" height="208" rx="10" fill="url(#fp)" stroke="#9aa1a8" stroke-width="2"/><circle cx="12" cy="12" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><circle cx="308" cy="12" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><circle cx="12" cy="198" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><circle cx="308" cy="198" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><text x="18" y="24" text-anchor="start" style="font: 700 7.5px system-ui, sans-serif; letter-spacing: .14em; fill: #3a4048">SPECTRUM ANALYZER</text><text x="302" y="24" text-anchor="end" style="font: 600 7px ui-monospace, Menlo, monospace; letter-spacing: .04em; fill: #5a6068">9 kHz – 6 GHz</text><rect x="12" y="30" width="296" height="168" rx="5" fill="#020403" stroke="#2f3533" stroke-width="2"/><rect x="20" y="40" width="280" height="136" fill="none" stroke="#1f4a2c" stroke-width=".8"/><path d="M48.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M76.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M104.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M132.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M160.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M188.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M216.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M244.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M272.0 40V176" stroke="#16321f" stroke-width=".6"/><path d="M20 55.1H300" stroke="#16321f" stroke-width=".6"/><path d="M20 70.2H300" stroke="#16321f" stroke-width=".6"/><path d="M20 85.3H300" stroke="#16321f" stroke-width=".6"/><path d="M20 100.4H300" stroke="#16321f" stroke-width=".6"/><path d="M20 115.6H300" stroke="#16321f" stroke-width=".6"/><path d="M20 130.7H300" stroke="#16321f" stroke-width=".6"/><path d="M20 145.8H300" stroke="#16321f" stroke-width=".6"/><path d="M20 160.9H300" stroke="#16321f" stroke-width=".6"/><text x="20" y="37" text-anchor="start" style="font: 600 6px ui-monospace, Menlo, monospace; letter-spacing: 0; fill: #8fe3a8">REF −20.0 dBm 10 dB/</text><text x="300" y="37" text-anchor="end" data-bind="ui.mkr" style="font: 600 6px ui-monospace, Menlo, monospace; letter-spacing: 0; fill: #ffd166">MKR1 —</text><g class="sp" data-bind="ui.s0" style="--x: 20.0px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s1" style="--x: 26.0px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s2" style="--x: 31.9px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s3" style="--x: 37.9px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s4" style="--x: 43.8px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s5" style="--x: 49.8px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s6" style="--x: 55.7px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s7" style="--x: 61.7px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s8" style="--x: 67.7px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s9" style="--x: 73.6px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s10" style="--x: 79.6px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s11" style="--x: 85.5px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s12" style="--x: 91.5px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s13" style="--x: 97.4px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s14" style="--x: 103.4px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s15" style="--x: 109.4px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s16" style="--x: 115.3px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s17" style="--x: 121.3px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s18" style="--x: 127.2px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s19" style="--x: 133.2px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s20" style="--x: 139.1px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s21" style="--x: 145.1px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s22" style="--x: 151.1px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s23" style="--x: 157.0px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s24" style="--x: 163.0px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s25" style="--x: 168.9px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s26" style="--x: 174.9px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s27" style="--x: 180.9px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s28" style="--x: 186.8px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s29" style="--x: 192.8px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s30" style="--x: 198.7px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s31" style="--x: 204.7px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s32" style="--x: 210.6px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s33" style="--x: 216.6px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s34" style="--x: 222.6px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s35" style="--x: 228.5px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s36" style="--x: 234.5px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s37" style="--x: 240.4px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s38" style="--x: 246.4px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s39" style="--x: 252.3px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s40" style="--x: 258.3px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s41" style="--x: 264.3px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s42" style="--x: 270.2px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s43" style="--x: 276.2px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s44" style="--x: 282.1px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s45" style="--x: 288.1px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s46" style="--x: 294.0px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="sp" data-bind="ui.s47" style="--x: 300.0px"><rect x="-2.1" y="-.8" width="4.2" height="1.6" rx=".8"/></g><g class="mk-x" data-bind="ui.pk"><g class="mk-y" data-bind="ui.pl"><path d="M0 -2l-3.5 -5h7z"/></g></g><text x="20" y="189" text-anchor="start" style="font: 600 6.5px ui-monospace, Menlo, monospace; letter-spacing: 0; fill: #8fe3a8">CF 2.2450 GHz</text><text x="160" y="189" text-anchor="middle" style="font: 600 6.5px ui-monospace, Menlo, monospace; letter-spacing: 0; fill: #8fe3a8">RBW 10 kHz VBW 10 kHz</text><text x="300" y="189" text-anchor="end" style="font: 600 6.5px ui-monospace, Menlo, monospace; letter-spacing: 0; fill: #8fe3a8">SPAN 2.000 MHz</text></svg></div><style> .inst { width: min(560px, 100%); margin: 0 auto; } .inst svg { display: block; width: 100%; height: auto; } .inst text { font-family: system-ui, sans-serif; } .dp rect { fill: var(--off); } .dp.on rect, .dp[data-value=true] rect { fill: var(--on); } .led circle { fill: #2a2f35; transition: fill .15s; } .led[data-value=true] circle { fill: var(--led, #38e07a); } .ann text { fill: var(--off); transition: fill .15s; } .ann[data-value=true] text { fill: var(--on); } .d7 rect { fill: var(--off); transition: fill .08s; } .d7[data-value="0"] :is(.sa, .sb, .sc, .sd, .se, .sf) { fill: var(--on); } .d7[data-value="1"] :is(.sb, .sc) { fill: var(--on); } .d7[data-value="2"] :is(.sa, .sb, .sd, .se, .sg) { fill: var(--on); } .d7[data-value="3"] :is(.sa, .sb, .sc, .sd, .sg) { fill: var(--on); } .d7[data-value="4"] :is(.sb, .sc, .sf, .sg) { fill: var(--on); } .d7[data-value="5"] :is(.sa, .sc, .sd, .sf, .sg) { fill: var(--on); } .d7[data-value="6"] :is(.sa, .sc, .sd, .se, .sf, .sg) { fill: var(--on); } .d7[data-value="7"] :is(.sa, .sb, .sc) { fill: var(--on); } .d7[data-value="8"] :is(.sa, .sb, .sc, .sd, .se, .sf, .sg) { fill: var(--on); } .d7[data-value="9"] :is(.sa, .sb, .sc, .sd, .sf, .sg) { fill: var(--on); } .d7[data-value="-"] :is(.sg) { fill: var(--on); } .d7[data-value="E"] :is(.sa, .sd, .se, .sf, .sg) { fill: var(--on); } .d7[data-value="U"] :is(.sb, .sc, .sd, .se, .sf) { fill: var(--on); } .d7[data-value="r"] :is(.se, .sg) { fill: var(--on); } .sp rect { fill: #ffd34d; } .sp { opacity: 0; transform: translate(var(--x), calc(40px + (-20 - clamp(-110, var(--value, -110), -20)) / 90 * 136px)); transition: transform .36s linear; } .sp[data-value] { opacity: 1; } .mk-x { opacity: 0; transform: translateX(calc(20px + var(--value, 0) / 47 * 280px)); transition: transform .36s linear; } .mk-x[data-value] { opacity: 1; } .mk-y { transform: translateY(calc(40px + (-20 - clamp(-110, var(--value, -110), -20)) / 90 * 136px)); transition: transform .36s linear; } .mk-y path { fill: #ffd166; }</style>The phase
phases/spectrum_analyzer.py
"""Watches the S-band downlink on the spectrum analyzer while thetransmitter comes up. `ui.s0` to `ui.s47` are the trace in dBm, `ui.pk` and`ui.pl` place the marker on the peak, `ui.mkr` is its readout. The run recordsthe carrier's peak level."""import timeCENTER_MHZ, SPAN_MHZ = 2245.0, 2.0def acquire(ui, measurements, analyzer): peak = -200.0 for n in range(analyzer.length()): trace = analyzer.sweep() if n % 3 == 0: for k, dbm in enumerate(trace): setattr(ui, f"s{k}", round(dbm, 1)) bin_ = max(range(len(trace)), key=trace.__getitem__) peak = trace[bin_] mhz = CENTER_MHZ + (bin_ / (len(trace) - 1) - 0.5) * SPAN_MHZ ui.pk = bin_ ui.pl = round(peak, 1) ui.mkr = f"MKR1 {mhz / 1000:.6f} GHz {peak:.1f} dBm" time.sleep(0.1) measurements.carrier_level = round(peak, 1) time.sleep(1.5)The mocked instrument
plugs/spectrum_analyzer.py
"""Mock spectrum analyzer on the S-band downlink: the noise floor, then theQPSK carrier rising as the transmitter warms and the coupler is set. Replace itwith your analyzer's driver."""import mathimport randomPOINTS, SPAN_MHZ, CENTER_MHZ = 48, 2.0, 2245.0class SpectrumAnalyzer: def __init__(self): self.k = 0 self.rng = random.Random(7) self.trace = [-95.0] * POINTS def length(self): return 200 def sweep(self): """[trace in dBm, one point per bin across the span]""" x = self.k / 199 self.k += 1 level = -120.0 if x < 0.12 else -78 + 32 * (0.5 - 0.5 * math.cos(math.pi * min(1, (x - 0.12) / 0.5))) for b in range(POINTS): u = ((b / (POINTS - 1)) - 0.5) * SPAN_MHZ / 0.45 sinc = 1.0 if abs(u) < 1e-6 else (math.sin(math.pi * u) / (math.pi * u)) ** 2 p = 10 * math.log10(10 ** (-9.6) + 10 ** ((level + 10 * math.log10(sinc + 1e-6)) / 10)) + self.rng.gauss(0, 1.3) self.trace[b] = self.trace[b] * 0.6 + p * 0.4 return list(self.trace)