Compare commits

..

90 Commits

Author SHA1 Message Date
Smittix 367048e853 chore: bump version to 2.22.3 and update changelog
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 21:03:27 +00:00
Smittix 406ca28304 fix: suppress stale WebSocket close message after stopping waterfall
stop() sets _ws = null before the async onclose fires, so the handler
now early-returns when _ws is null instead of showing the misleading
"WebSocket closed before ready" retry message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 21:01:59 +00:00
Smittix f889c53d92 fix: waterfall monitor audio delay and unresponsive stop button
- _waitForPlayback now only succeeds on playing/timeupdate events, not
  loadeddata/canplay which fire from just the WAV header before real
  audio arrives
- stopMonitor() pauses audio and updates UI immediately instead of
  blocking on the backend stop request (1+ second delay)
- Reduced backend audio stop sleep from 1.0s to 0.15s; the start
  retry loop already handles USB contention

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 20:59:40 +00:00
Smittix b0af1d16d2 chore: bump pyproject.toml version to 2.22.2
Was missed during previous 2.22.x release bumps.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 20:27:35 +00:00
Smittix 4e67b77714 fix: first-load rendering for Waterfall CSS and WebSDR globe
- Waterfall: load waterfall.css eagerly in <head> instead of lazily on
  mode switch; the lazy inject raced with the panel becoming visible,
  leaving unstyled HTML for up to 20 s on cold cache
- WebSDR: await a requestAnimationFrame before calling Globe()(mapEl) so
  the browser has committed the display:flex layout and clientWidth/
  clientHeight are non-zero; previously the globe WebGL renderer was
  created at 0×0 (especially on warm-cache refreshes) and could not
  recover via the deferred resize calls
- Bump version to 2.22.2

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 20:25:05 +00:00
Smittix b1993847b5 docs: remove RF Heatmap references — feature was not shipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 19:40:15 +00:00
Smittix cde79f4619 fix: use official favicon.svg logo for all PWA and app icons
Regenerates icon-192.png, icon-512.png, apple-touch-icon.png, and
favicon-32.png from the official iNTERCEPT logo (favicon.svg) instead
of the placeholder icon.svg. Also replaces icon.svg with the official
logo so the SVG manifest entry is consistent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 19:37:44 +00:00
Smittix cc271819ad chore: bump version to 2.22.1 and update changelog
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 19:36:55 +00:00
Smittix 8cd64ce3ca fix: PWA install prompt - add PNG icons and fix apple-touch-icon
Browsers require PNG icons (192x192, 512x512) in the manifest to show
the install prompt. SVG-only manifests are not sufficient. Also adds the
180x180 apple-touch-icon PNG for iOS home screen, bumps SW cache to v3,
and adds scope to the manifest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 19:36:28 +00:00
Smittix 9705e58691 Release v2.22.0
Waterfall overhaul, new modes (fingerprint, RF heatmap, SignalID, voice
alerts), PWA support, mode stop responsiveness improvements, ADS-B MSG2
surface tracking, WebSDR overhaul, and full documentation audit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 19:31:10 +00:00
Smittix 3acdab816a Improve mode transitions and add nav perf instrumentation 2026-02-23 18:14:31 +00:00
Smittix c31ed14041 Improve mode stop responsiveness and timeout handling 2026-02-23 17:53:50 +00:00
Smittix 7241dbed35 chore: commit all pending changes 2026-02-23 16:51:32 +00:00
Smittix 94b358f686 Commit all pending workspace changes 2026-02-23 14:28:57 +00:00
Smittix 8e19f7e688 Fix ADS-B update flush timing and parse MSG2 surface data 2026-02-23 13:39:01 +00:00
Smittix 7ea06caaa2 Remove legacy RF modes and add SignalID route/tests 2026-02-23 13:34:00 +00:00
Smittix 5f480caa3f feat: ship waterfall receiver overhaul and platform mode updates 2026-02-22 23:22:37 +00:00
Smittix 5d4b61b4c3 Fix nested nav bar appearing in embedded dashboard iframes
When dashboards (satellite, ADS-B, AIS) are loaded via iframe with
?embedded=true, the full navigation bar was still rendered, creating
a "UI in UI" effect. Pass the embedded query param from route handlers
to templates and conditionally skip the nav include.

Fixes #144

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 13:16:51 +00:00
Smittix a8e2b9d98d Shrink hit areas and spread overlapping radar dots
Hit area: was Math.max(dotSize * 2, 15) — up to 24px radius around a 4px
dot. Now the CSS hover-flicker is fixed the large hit area is unnecessary
and was the reason dots activated when merely nearby. Changed to dotSize + 4
(proportional, 4px padding around the visual circle).

Overlap spread: compute all band positions first, then run an iterative
push-apart pass (spreadOverlappingDots) that nudges any two dots whose
arc gap is smaller than 2 * maxHitArea + 2px apart. Positions within a
band are stable across renders (same hash angle, same band = same output
before spreading) so dots don't shuffle on every update.

Z-order: sort visible devices by rssi_current ascending before rendering
so the strongest signal lands last in SVG order and receives clicks when
dots stack.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 14:51:45 +00:00
Smittix 4b225db9da Fix proximity radar jitter caused by CSS scale-on-hover feedback loop
The root cause was in proximity-viz.css, not the JS:

  .radar-device:hover { transform: scale(1.2); }

When the cursor entered a .radar-device, the 1.2x scale physically moved
the hit-area boundary, pushing the cursor outside it. The browser then
fired mouseout, the scale reverted, the cursor was back inside, mouseover
fired again, and the scale reapplied — a rapid enter/exit loop that looked
like the dot jumping and dancing.

Replace the geometry-changing scale with a brightness filter on the dot
circle only. filter: brightness() does not affect pointer-event hit testing
so there is no feedback loop, and the hover still gives clear visual
feedback. Also removes the transition: transform rule that was animating
the scale and contributing to the flicker.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 14:44:46 +00:00
Smittix aba4ccd040 Fix radar jitter by using band-only positioning
Replace continuous estimated_distance_m-based radius with proximity band
snapping (immediate/near/far/unknown → fixed radius ratios of 0.15/0.40/
0.70/0.90). The proximity_band is computed server-side from rssi_ema which
is already smoothed, so it changes infrequently — dots now only move when
a device genuinely crosses a band boundary rather than on every RSSI
fluctuation.

Also removes the client-side EMA and positionCache added in the previous
commit, and reverts CSS style.transform back to SVG transform attribute to
avoid coordinate-system mismatch when the SVG is displayed at a scaled size.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 14:38:50 +00:00
Smittix f8a6d0ae70 Smooth proximity radar positions with EMA and CSS transitions
The remaining jitter after the in-place DOM rewrite was caused by RSSI
fluctuations propagating directly into dot positions on every 200ms
update cycle.

Two fixes:
1. Client-side EMA (alpha=0.25) on x/y coordinates per device. Each
   render blends 25% toward the new raw position and retains 75% of the
   smoothed position, filtering high-frequency RSSI noise without hiding
   genuine distance changes. positionCache is keyed by device_key and
   cleared on device removal or radar reset.

2. CSS transition (transform 0.6s ease-out) on each wrapper element.
   Switching from SVG transform attribute to style.transform enables
   native CSS transitions, so any remaining position change (e.g. a band
   crossing) animates smoothly rather than snapping.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 14:35:42 +00:00
Smittix 00681840c8 Rewrite proximity radar to use in-place DOM updates
Instead of rebuilding devicesGroup.innerHTML on every render, mutate
existing SVG elements in-place (update transforms, attributes, class
names) and only create/remove elements when devices genuinely appear
or disappear from the visible set.

This eliminates the root cause of both the jitter and the blank-radar
regression: hover state can never be disrupted by a render because the
DOM elements under the cursor are never destroyed. The isHovered /
renderPending / interactionLockUntil state machine and its associated
mouseover/mouseout listeners are removed entirely — they are no longer
needed. A shared buildSelectRing() helper deduplicates the animated
selection ring construction used by renderDevices() and
applySelectionToElement(). Closes #143.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 14:29:41 +00:00
Smittix 00be3e940a Fix proximity radar hover jitter without breaking device rendering
Replace capture-phase mouseenter/mouseleave with bubbling mouseover/mouseout
for tracking hover state in the ProximityRadar component.

The capture-phase approach caused two problems:
1. Moving between sibling child elements (hit-area → dot circle) fired
   mouseleave, prematurely clearing isHovered and triggering a DOM rebuild
   that caused visible jitter.
2. When renderDevices() rebuilt innerHTML, the browser fired mouseleave for
   the destroyed element with relatedTarget pointing at the newly created
   element at the same position, leaving isHovered permanently stuck at true
   and suppressing all future renders.

The fix uses mouseover/mouseout (which bubble) with devicesGroup.contains()
to reliably detect whether the cursor genuinely left the device group, immune
to innerHTML rebuilds. Fixes both WiFi and Bluetooth proximity radars as they
share this component. Closes #143.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 14:22:59 +00:00
Smittix fb2a12773a Force local dashboard assets and quiet BT locate warnings 2026-02-20 19:11:21 +00:00
Smittix 167f10c7f7 Harden BT Locate handoff matching and start flow 2026-02-20 18:57:06 +00:00
Smittix e386016349 Default dashboard assets/fonts to local bundles 2026-02-20 18:03:06 +00:00
Smittix aec925753e Pause BT Locate processing when mode is hidden 2026-02-20 17:48:22 +00:00
Smittix c3bf30b49c Fix BT Locate startup/map rendering and CelesTrak import reliability 2026-02-20 17:35:57 +00:00
Smittix c0221ba53d Fix manual TLE parsing for pasted multiline input 2026-02-20 17:18:15 +00:00
Smittix af5b17e841 Remove Drone Ops feature end-to-end 2026-02-20 17:09:17 +00:00
Smittix b628a5f751 Add drone ops mode and retire DMR support 2026-02-20 17:02:16 +00:00
Smittix 9ec316fbe2 fix(bt-locate): stabilize first-load map and release v2.21.1 2026-02-20 00:49:08 +00:00
Smittix a407c7708d chore(release): v2.21.0 2026-02-20 00:37:37 +00:00
Smittix 1466fc2d30 Apply global map theme updates and UI improvements 2026-02-20 00:32:58 +00:00
Smittix 963bcdf9fa Improve cross-app UX: accessibility, mode consistency, and render performance 2026-02-19 22:32:08 +00:00
Smittix cfe03317c9 Fix weather sat auto-scheduler and Mercator tracking 2026-02-19 21:55:07 +00:00
Smittix 37ba12daaa Fix BT/WiFi run-state health and BT Locate tracking continuity 2026-02-19 21:39:09 +00:00
Smittix 5c47e9f10a feat: ship platform UX and reliability upgrades 2026-02-19 20:46:28 +00:00
Smittix 694786d4e0 Fix ADS-B SSE fanout for multi-client streams 2026-02-19 18:26:23 +00:00
Smittix 06a00ca6b5 Fix remote VDL2 streaming path and improve decoder reliability 2026-02-19 15:57:13 +00:00
Smittix bbc25ddaa0 Improve Bluetooth scanner filtering, stats, and layout 2026-02-19 14:04:12 +00:00
Smittix 02a94281c3 Improve Analytics with operational insights and temporal pattern panels 2026-02-19 12:59:39 +00:00
Smittix cbe5faab3b Enhance BT Locate with smoothing, confidence, strongest signal, and export 2026-02-19 12:51:25 +00:00
Smittix cacfbf5713 Update HF SSTV 2m preset to 145.500 MHz 2026-02-19 12:34:08 +00:00
Smittix 2faed68af4 Align ISS SSTV start flow with HF decoder contract 2026-02-19 12:29:27 +00:00
Smittix bec0881018 Set HF SSTV default modulation to FM 2026-02-19 12:23:25 +00:00
Smittix da2a700bcc Fix SSTV slant correction wedge artifact 2026-02-19 12:18:20 +00:00
Smittix cd3ed9a03b Fix weather satellite next-pass countdown timestamps 2026-02-19 12:12:12 +00:00
Smittix f7fad076c2 fix: Expand Scottie sync deviation search window to fix under-correction
The slant correction was severely under-correcting because bwd=50 caused
the sync deviation measurements to saturate after only ~25 lines (for a
2-sample/line SDR clock drift). Lines 25-256 all reported deviation=-50,
pulling the linear regression slope toward zero.

Increase bwd and fwd to 800 samples each — sufficient to track cumulative
drift from up to ~±200 ppm SDR clock offset across the full 256-line image.

Also use a full-sync-length (432-sample) Goertzel window instead of 1/3
length, giving ~111 Hz frequency resolution to cleanly separate the 1200 Hz
sync tone from 1500 Hz pixel data. Search is stepped at 5 samples (~0.1 ms)
for efficiency, keeping the goertzel_batch batch size at ~320 windows/line.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-19 11:04:06 +00:00
Smittix a397271553 fix: Slant correction via post-processing shear, not in-decoder sync fixup
Previous attempts to correct slant by altering R-channel placement and
buffer consumption caused cascading failures: a false positive in B pixel
data would misplace R, then the wrong consumed value misaligned the next
line's G, and the error compounded across all 256 lines.

New approach (safe by design):
- Sync search is measurement-only: never touches pos or consumed, so
  a noisy or wrong measurement cannot corrupt the current or future lines.
- Per-line deviation (measured sync position minus expected) is recorded
  in self._sync_deviations throughout the decode.
- get_image() fits a line through the deviations (linear regression) to
  estimate the per-line SDR clock drift rate, then applies a horizontal
  shear to the assembled PIL image: each row is shifted by
  -round(row × drift_rate × width / channel_samples) pixels.
- Worst case (all measurements fail): no correction applied, image
  quality identical to the pre-change baseline.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-19 10:43:16 +00:00
Smittix 83a54ccb20 fix: Replace coarse Scottie sync search with vectorised fine scan
The step-49 coarse scan introduced up to ±24 sample uncertainty in R
channel placement. When accumulated SDR clock drift pushed the actual
sync 35+ samples early in the search region, the step-49 windows could
land on the B-pixel tail and return position 0, misplacing R by ~50
samples (~16 pixel colour shift) — worse than no correction at all.

Replace with a vectorised goertzel_batch sliding-window scan at step=1
over a short window (sync_duration / 3 ≈ 3 ms), giving single-sample
accuracy. Use consumed=pos (instead of max(pos,line_samples)) when the
sync is found, so the next line starts at its correct separator and
per-line timing errors stop accumulating entirely.

Falls back to the fixed-offset path whenever the sync is not found
(e.g. noisy signal), preserving the pre-change baseline quality.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-19 10:29:19 +00:00
Smittix 2e9bab75b1 fix: Correct Scottie sync search to prevent decoder stall
The previous sync search used search_margin = line_samples/10 (~306
samples for Scottie2), reaching deep into B channel pixel data behind
pos and well past the expected sync end ahead of pos.

When _find_sync returned a position in the late portion of that wide
region, pos + R_channel_samples exceeded the buffer length. The
buffer-too-short guard in _decode_line then returned early without
consuming data or advancing the line counter, causing the stall guard
in feed() to permanently break the decode loop.

Fix: use a 50-sample backward margin (covers >130 ppm SDR drift) and
a forward margin capped to whatever the current buffer can safely
support for the R channel. A final candidate-position check before
committing pos ensures no overflow is possible.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-19 10:01:28 +00:00
Smittix 0dc40bbea3 fix: Correct Scottie SSTV image slant by resyncing to mid-line sync pulse
Scottie modes place their horizontal sync pulse between the Blue and Red
channels. The decoder was using a fixed offset to skip over it, so any
SDR clock error accumulated line-by-line and produced a visible diagonal
slant in the decoded image.

Fix: search for the actual 1200 Hz sync pulse in a ±10% window around
the expected position before decoding the Red channel, then align to the
real pulse. This resets accumulated clock drift on every scanline, the
same way Martin and Robot modes already handle their front-of-line sync.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-19 09:54:28 +00:00
Smittix 17f6947648 fix: Correct SSTV VIS codes and replace Goertzel pixel decoder with Hilbert transform
Fix wrong VIS codes for PD90 (96→99), PD120 (93→95), PD180 (95→97),
PD240 (113→96), and ScottieDX (55→76). This caused PD180 to be detected
as PD90 and PD120 to fail entirely.

Replace batch Goertzel pixel decoding with analytic signal (Hilbert
transform) FM demodulation. The Goertzel approach used 96-sample windows
with ~500 Hz resolution — wider than the 800 Hz pixel frequency range —
making accurate pixel decoding impossible for fast modes like Martin2
and Scottie2. The Hilbert method computes per-sample instantaneous
frequency, matching the approach used by QSSTV and other professional
SSTV decoders.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 09:23:15 +00:00
Smittix 481651c88d fix: Improve HF SSTV VIS detection reliability and error correction
Tolerate intermittent ambiguous windows during leader detection (up to
3 consecutive misses), use energy-based break detection when tone
classification fails at leader-break boundary, and add single-bit VIS
error correction for parity-bit and data-bit corruption on noisy HF.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 21:52:56 +00:00
Smittix ad4903d4ac fix: Add missing SSTV mode specs for HF decoding (PD90/PD160/PD240/ScottieDX)
VIS detection recognized these modes but ALL_MODES had no decoder specs,
causing silent decode failures on common HF frequencies like 14.230 MHz.
Also emit a user-visible SSE event when an unsupported VIS code is detected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 21:29:34 +00:00
Smittix 3a962ca207 fix: SSTV VIS detector stuck in DETECTED state on validation failure
The previous fix (f29ae3d) introduced a regression: when VIS parity
check failed or the VIS code was unrecognized, the detector entered
DETECTED state permanently and never resumed scanning. Now it resets
to IDLE on validation failure and only enters DETECTED on success.

Also resets partial image progress counter between consecutive decodes
and adds SDR device claiming to general SSTV route to prevent conflicts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 21:12:12 +00:00
Smittix f29ae3d5a8 fix: Preserve image-start samples across VIS-to-decoder boundary
VISDetector._process_window() was calling self.reset() inside the
STOP_BIT handler, wiping self._buffer before feed() could advance
past the triggering window. All audio samples buffered after the
VIS STOP_BIT (the start of the first scan line) were silently
discarded, causing the image decoder to begin decoding mid-stream
with no alignment reference. The result was every scan line being
desynchronised from the first, producing the diagonal stripes and
scrambled colours seen in decoded images.

Fix: remove the premature reset() from _process_window(). The
STOP_BIT handler now sets state=DETECTED and returns the result.
A new remaining_buffer property exposes the post-VIS samples.
_decode_audio_stream() and decode_file() capture those samples
before calling reset(), then immediately feed them into the newly
created SSTVImageDecoder so decoding begins from sample 0 of
the first sync pulse.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 19:06:32 +00:00
Smittix 37d24a539d fix: Remove stale dump1090 symlink before install check
If dump1090-mutability was installed by a previous run and later
removed (e.g. by apt removing it as a reverse dep), the symlink at
/usr/local/sbin/dump1090 is left pointing at a non-existent target.
cmd_exists finds the broken symlink and treats dump1090 as installed,
so the real install is skipped and running dump1090 gives
"No such file or directory".

Before the install check, resolve the command path and delete it if
it exists in PATH but is not executable (broken symlink).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 17:36:25 +00:00
Smittix 622f23c091 fix: Use ldconfig priority file instead of removing apt rtl-sdr packages
The apt-removal approach caused cascading failures: removing librtlsdr0
swept out dump1090-mutability and other reverse deps, then source builds
reinstalled librtlsdr-dev (pulling librtlsdr0 back), and the dump1090
subshell crashed because kill "" (empty progress_pid after progress_pid=)
returned non-zero and fired the global ERR trap.

Switch to a targeted ldconfig priority file instead:
- Write /etc/ld.so.conf.d/00-local-first.conf containing /usr/local/lib
- Files named 00-* sort before aarch64-linux-gnu.conf alphabetically,
  so ldconfig lists /usr/local/lib/librtlsdr.so.0 (Blog) first
- apt librtlsdr0, rtl-sdr, dump1090-mutability etc. are never touched
- Source build functions keep their unconditional apt_install librtlsdr-dev

Also fix the dump1090 EXIT trap: guard kill/wait against empty
progress_pid so it does not fire the ERR trap after a clean exit 0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 17:10:42 +00:00
Smittix b70db887b1 fix: Silence non-zero wait exit after killing dump1090 progress spinner
The global ERR trap (trap 'on_error $LINENO' ERR) fires on any non-zero
exit. After `kill $progress_pid`, `wait $progress_pid` returns 143
(128+SIGTERM), triggering the trap and aborting the build even when
make itself succeeded. Add `|| true` to all five wait calls in
install_dump1090_from_source_debian (inline and EXIT trap).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 17:05:07 +00:00
Smittix 7f13af3fcd fix: Prevent apt librtlsdr-dev reinstalling librtlsdr0 after Blog install
When Blog drivers are installed, apt rtl-sdr/librtlsdr0/librtlsdr-dev
are removed to ensure the Blog library in /usr/local/lib is the only
one ldconfig sees.  But four source-build functions each called
`apt_install librtlsdr-dev`, which re-pulled librtlsdr0 from apt and
immediately re-shadowed the Blog library.

Fix: each function now checks `pkg-config --exists librtlsdr` first;
if the Blog drivers (or any other /usr/local install) already provide
the headers and .pc file the apt install is skipped entirely.

Also add a post-removal guard in install_rtlsdr_blog_drivers_debian:
after apt removes librtlsdr0 it may silently sweep out dump1090-mutability
as a reverse dep.  The guard detects this and rebuilds dump1090 from
source immediately, using the Blog drivers' headers via pkg-config.

Affected functions:
- install_dump1090_from_source_debian
- install_acarsdec_from_source_debian
- install_dumpvdl2_from_source_debian
- install_aiscatcher_from_source_debian

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 17:01:13 +00:00
Smittix 9afff0f4b2 fix: Remove librtlsdr0 apt package when installing Blog drivers
Removing only the rtl-sdr binary package left librtlsdr0 (the library)
installed at /lib/aarch64-linux-gnu/librtlsdr.so.0. ldconfig lists the
multiarch path before /usr/local/lib, so even the Blog driver binary
(/usr/local/bin/rtl_test) was loading the old apt library — which has
no R828D/V4 tuner support — causing the PLL-not-locked / deaf dongle
symptom.

Now remove rtl-sdr, librtlsdr0, and librtlsdr-dev together so the only
librtlsdr.so.0 in the ldconfig cache is the Blog drivers' copy in
/usr/local/lib.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 16:55:30 +00:00
Smittix 5a7a6ce522 fix: Remove apt rtl-sdr conflict and always unload DVB modules on Pi
Two bugs caused RTL-SDR dongles to be deaf after setup on Raspberry Pi:

1. The apt `rtl-sdr` package was left installed alongside the Blog
   drivers, creating a binary/library ambiguity. Anything linking or
   calling the apt binaries in /usr/bin used the non-V4-aware library
   from /usr/lib instead of the Blog drivers in /usr/local. Fix: remove
   the apt package immediately after a successful Blog driver build.

2. `blacklist_kernel_drivers_debian` returned early with "already
   present" without ever running `modprobe -r`, so dvb_usb_rtl28xxu
   could remain loaded and hold the device in DVB mode (rtl_test sees
   the USB device but the tuner is unconfigured). Fix: always run the
   module unload loop regardless of whether the blacklist file is new.
   Also add `update-initramfs -u` so the blacklist survives reboots.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 16:22:45 +00:00
Smittix 36b6539044 fix: Prompt for RTL-SDR Blog V4 drivers instead of silently skipping
The previous logic installed rtl-sdr via apt first, then gated the Blog
driver install on cmd_exists rtl_test — which was always true, so V4
drivers were never installed. Replace with a yes/no prompt (default y,
backward-compatible) guarded by IS_DRAGONOS for pre-configured distros.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 16:12:12 +00:00
Smittix 6c6cd8a280 fix: Resolve light/dark theme issues across dashboards and settings
- Add missing setThemePreference() and setAnimationsEnabled() functions
  to settings-manager.js; sync theme/animations dropdowns in _updateUI
- Fix base.html toggleTheme() saving to wrong localStorage key ('theme'
  instead of 'intercept-theme'), causing theme not to persist in ADS-B
  and AIS dashboards; also sync button icon and persist to server
- Add [data-theme="light"] CSS variable overrides to adsb_dashboard.css
  and ais_dashboard.css so the dashboards respond to light theme
- Fix GPS sky view canvas (gps.js) to read grid/label colours from CSS
  variables instead of hardcoded dark hex values; add MutationObserver
  to redraw immediately on theme change
- Fix satellite_dashboard.html polar plot functions to read background,
  accent and text colours from CSS variables

Closes #139

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 13:58:49 +00:00
Smittix 4df112e712 fix: Disclaimer warning icon overlapping heading text
The .icon base class (global-nav.css) forces display:inline-flex and
width/height of 18-20px, overriding the intended 48px size and causing
the SVG to render inline inside the h2 rather than as a block above it.

Override with display:block, explicit 48px dimensions, and auto margins
so the icon renders centred above the DISCLAIMER heading.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 12:24:28 +00:00
Smittix 3d8b8bbfdc fix: Suppress noisy pip output during core package install
Replace the | tail -5 filter with pip --quiet and 2>/dev/null to
silence 'Requirement already satisfied' lines and the harmless
send2trash metadata warning that were leaking to the terminal.
The import verification step still catches real install failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 12:21:01 +00:00
Smittix 076339024f fix: Add newline before closing GCC pragma in SatDump lua_utils patch
If lua_utils.cpp has no trailing newline the closing pragma was appended
directly to the last line (};#pragma GCC diagnostic pop), causing a
stray '#' compile error on GCC 13+ / Raspberry Pi OS Bookworm.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 12:00:05 +00:00
Smittix e82f0f36d2 fix: Handle libvolk package name difference on Raspberry Pi OS
On Raspberry Pi OS Bookworm the package is libvolk2-dev, not libvolk-dev.
Also soft-fail optional SDR hardware libs (libjemalloc, libnng, SoapySDR,
HackRF, LimeSuite) so a missing package no longer aborts the SatDump build.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 11:51:37 +00:00
Smittix f4ade209f9 feat: Weather satellite and ADS-B trail rendering improvements
Weather Satellite:
- Fix duplicate event listeners on mode re-entry via locationListenersAttached guard
- Add suspend() to stop countdown/SSE stream when switching away from the mode
- Call WeatherSat.suspend() in switchMode() when leaving weathersat
- Fix toggleScheduler() to take the checkbox element as source of truth,
  preventing both checkboxes fighting each other
- Reset isRunning/UI state after auto-capture completes (scheduler path)
- Always re-select first pass and reset selectedPassIndex after loadPasses()
- Keep timeline cursor in sync inside selectPass()
- Add seconds to pass ID format to avoid collisions on concurrent passes
- Improve predict_passes() comment clarity; fix trajectory comment

ADS-B dashboard:
- Batch altitude-colour trail segments into runs of same-colour polylines,
  reducing Leaflet layer count from O(trail length) to O(colour changes)
  for significantly better rendering performance with many aircraft

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 11:43:47 +00:00
Smittix b0652595fa fix: Add parallel jobs and progress output to dump1090 Debian build
Single-threaded make on a Raspberry Pi 5 could take 5-10+ minutes
with no output, making the setup appear hung. Now uses all available
CPU cores and prints a "still compiling" heartbeat every 20s.
Also prints build log tail on failure for easier debugging.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 11:43:13 +00:00
Smittix 332172881e refactor: Reorganize nav groups into Signals, Tracking, Space, Wireless, Intel
Replaces the old SDR/RF, Wireless, Security, Space layout with a cleaner
five-group structure. Tracking (Aircraft, Vessels, APRS, GPS) becomes its
own top-level group; Meshtastic moves to Wireless; WebSDR and Spy Stations
move to Intel. Also fixes BT Locate overflow/min-height CSS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 09:30:11 +00:00
Smittix e05ac97749 feat: Zoom map to max on first GPS lock in BT Locate
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 22:44:04 +00:00
Smittix 615a83c23f docs: Add Space Weather screenshots to GitHub Pages site
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 22:26:50 +00:00
Smittix d017375f64 docs: Add APRS screenshot to GitHub Pages site
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 22:25:48 +00:00
Smittix 0b5235f619 feat: Add SONATE-2 satellite frequencies to APRS and HF SSTV
APRS: 145.825 MHz digipeater (shared with ISS)
HF SSTV: 145.880 MHz FM (Martin M1 mode)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 22:15:13 +00:00
Smittix 16239c1d31 feat: Add Space Weather mode with real-time solar and geomagnetic monitoring
New mode providing real-time space weather data from NOAA SWPC, NASA SDO,
and HamQSL APIs. Includes Kp index, solar wind, X-ray flux charts, HF band
conditions, D-RAP absorption maps, aurora forecast, solar imagery, flare
probability, and active solar regions. No SDR hardware required.

Bumps version to 2.20.0. Updates all documentation including README, FEATURES,
USAGE, UI_GUIDE, help modal, and GitHub Pages site.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 22:10:34 +00:00
Smittix cae7a0586f fix: Update North America ACARS frequencies and add ISS APRS option
Update default ACARS frequencies for North America to 131.725/131.825 MHz and add ISS (145.825 MHz) as a selectable APRS frequency region.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 18:37:15 +00:00
Smittix 23f28a8102 fix: Resolve multiple weather satellite decoder bugs
- Fix SatDump crash reported as "Capture complete" by collecting exit
  status via process.wait() before checking returncode
- Fix PTY file descriptor double-close race between stop() and reader
  thread by adding thread-safe _close_pty() helper with dedicated lock
- Fix image watcher missing final images by doing post-exit scans after
  SatDump process ends, using threading.Event for fast wakeup
- Fix failed image copy permanently skipping file by only marking as
  known after successful copy
- Fix frontend error handler not resetting isRunning, preventing new
  captures after a crash
- Fix console auto-hide timer leak on rapid complete/error events
- Fix ground track and auto-scheduler ignoring shared ObserverLocation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 16:16:28 +00:00
Smittix 34ecec3800 fix: Hide collapse sidebar button in analytics mode
The button is unnecessary since analytics expands the sidebar to
full width with no output panel to reveal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 15:21:18 +00:00
Smittix d40bd37406 fix: Expand analytics sections on mode switch
Sidebar sections are collapsed by default on DOMContentLoaded. When
switching to analytics mode, expand all its sections so the dashboard
content is visible immediately.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 15:18:15 +00:00
Smittix 4ed41434e2 fix: Hide output panel in analytics mode to prevent overlay
Analytics is a sidebar-only mode with no visuals container, so the
output panel was rendering on top of the analytics content. Add
analytics-active class to expand the sidebar full-width and hide
the output panel when in analytics mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 15:13:24 +00:00
Smittix 6a0b54fa0e fix: Hide output console when switching to analytics mode
The decoder output panel was not being hidden when entering analytics
mode, causing it to render on top of the analytics dashboard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 14:22:21 +00:00
Smittix b83ecfcc19 feat: Add ACARS, VDL2, APRS, and Meshtastic to analytics dashboard
Extend cross-mode analytics to include ACARS/VDL2 message counts, APRS
stations, and Meshtastic messages. Refactor count helpers into reusable
_safe_len() and _safe_route_attr() utilities. Add health checks for
rtlamr, dmr, and meshtastic modes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 14:13:28 +00:00
Smittix 671bf38083 fix: Read WiFi/BT data from v2 scanners in analytics dashboard
The analytics summary, health, and export were only reading from legacy
DataStores (app_module.wifi_networks, bt_devices) which the v2 WiFi and
Bluetooth scanners don't populate. Now checks v2 scanner singletons
first and falls back to legacy stores.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 13:48:56 +00:00
Smittix 0f5a414a09 feat: Add cross-mode analytics dashboard with geofencing, correlations, and data export
Adds a unified analytics mode under the Security nav group that aggregates
data across all signal modes. Includes emergency squawk alerting (7700/7600/7500),
vertical rate anomaly detection, ACARS/VDL2-to-ADS-B flight correlation,
geofence zones with enter/exit detection for aircraft/vessels/APRS stations,
temporal pattern detection, RSSI history tracking, Meshtastic topology mapping,
and JSON/CSV data export.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 12:59:31 +00:00
Smittix 831426948f fix: Reconnect VDL2/ACARS streams after navigating away from ADS-B dashboard
When navigating away from the dashboard and back, the page reloads with
no knowledge of running decoders. Add status checks on page load to sync
UI state and reconnect SSE streams. Also add auto-reconnect on SSE error
with guard conditions to prevent loops when intentionally stopped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:38:02 +00:00
Smittix df2c0a0d25 fix: Report SatDump crash as error instead of misleading "Capture complete"
Check process exit code when SatDump terminates — non-zero exit now
emits an error status with the exit code instead of falsely reporting
a successful capture completion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:11:33 +00:00
157 changed files with 23711 additions and 12256 deletions
+86
View File
@@ -2,6 +2,92 @@
All notable changes to iNTERCEPT will be documented in this file. All notable changes to iNTERCEPT will be documented in this file.
## [2.22.3] - 2026-02-23
### Fixed
- Waterfall control panel rendered as unstyled text for up to 20 seconds on first visit — CSS is now loaded eagerly with the rest of the page assets
- WebSDR globe failed to render on first page load — initialization now waits for a layout frame before mounting the WebGL renderer, ensuring the container has non-zero dimensions
- Waterfall monitor audio took minutes to start — `_waitForPlayback` now only reports success on actual audio playback (`playing`/`timeupdate`), not from the WAV header alone (`loadeddata`/`canplay`)
- Waterfall monitor could not be stopped — `stopMonitor()` now pauses audio and updates the UI immediately instead of waiting for the backend stop request (which blocked for 1+ seconds during SDR process cleanup)
- Stopping the waterfall no longer shows a stale "WebSocket closed before ready" message — the `onclose` handler now detects intentional closes
---
## [2.22.1] - 2026-02-23
### Fixed
- PWA install prompt not appearing — manifest now includes required PNG icons (192×192, 512×512)
- Apple touch icon updated to PNG for iOS Safari compatibility
- Service worker cache bumped to bust stale cached assets
---
## [2.22.0] - 2026-02-23
### Added
- **Waterfall Receiver Overhaul** - WebSocket-based I/Q streaming with server-side FFT, click-to-tune, zoom controls, and auto-scaling
- **Voice Alerts** - Configurable text-to-speech event notifications across modes
- **Signal Fingerprinting** - RF device identification and pattern analysis mode
- **SignalID** - Automatic signal classification via SigIDWiki API integration
- **PWA Support** - Installable web app with service worker caching and manifest
- **Real-time Signal Scope** - Live signal visualization for pager, sensor, and SSTV modes
- **ADS-B MSG2 Surface Parsing** - Ground vehicle movement tracking from MSG2 frames
- **Cheat Sheets** - Quick reference overlays for keyboard shortcuts and mode controls
- App icon (SVG) for PWA and browser tab
### Changed
- **WebSDR overhaul** - Improved receiver management, audio streaming, and UI
- **Mode stop responsiveness** - Faster timeout handling and improved WiFi/Bluetooth scanner shutdown
- **Mode transitions** - Smoother navigation with performance instrumentation
- **BT Locate** - Refactored JS engine with improved trail management and signal smoothing
- **Listening Post** - Refactored with cross-module frequency routing
- **SSTV decoder** - State machine improvements and partial image streaming
- Analytics mode removed; per-mode analytics panels integrated into existing dashboards
### Fixed
- ADS-B SSE multi-client fanout stability and update flush timing
- WiFi scanner robustness and monitor mode teardown reliability
- Agent client reliability improvements for remote sensor nodes
- SSTV VIS detector state reporting in signal monitor diagnostics
### Documentation
- Complete documentation audit across README, FEATURES, USAGE, help modal, and GitHub Pages
- Fixed license badge (MIT → Apache 2.0) to match actual LICENSE file
- Fixed tool name `rtl_amr``rtlamr` throughout all docs
- Fixed incorrect entry point examples (`python app.py``sudo -E venv/bin/python intercept.py`)
- Removed duplicate AIS Vessel Tracking section from FEATURES.md
- Updated SSTV requirements: pure Python decoder, no external `slowrx` needed
- Added ACARS and VDL2 mode descriptions to in-app help modal
- GitHub Pages site: corrected Docker command, license, and tool name references
---
## [2.21.1] - 2026-02-20
### Fixed
- BT Locate map first-load rendering race that could cause blank/late map initialization
- BT Locate mode switch timing so Leaflet invalidation runs after panel visibility settles
- BT Locate trail restore startup latency by batching historical GPS point rendering
---
## [2.21.0] - 2026-02-20
### Added
- Analytics panels for operational insights and temporal pattern analysis
### Changed
- Global map theme refresh with improved contrast and cross-dashboard consistency
- Cross-app UX refinements for accessibility, mode consistency, and render performance
- BT Locate enhancements including improved continuity, smoothing, and confidence reporting
### Fixed
- Weather satellite auto-scheduler and Mercator tracking reliability issues
- Bluetooth/WiFi runtime health issues affecting scanner continuity
- ADS-B SSE multi-client fanout stability and remote VDL2 streaming reliability
---
## [2.15.0] - 2026-02-09 ## [2.15.0] - 2026-02-09
### Added ### Added
+11 -24
View File
@@ -57,7 +57,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
soapysdr-module-airspy \ soapysdr-module-airspy \
airspy \ airspy \
limesuite \ limesuite \
hackrf \
# Utilities # Utilities
curl \ curl \
procps \ procps \
@@ -94,7 +93,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libpulse-dev \ libpulse-dev \
libfftw3-dev \ libfftw3-dev \
liblapack-dev \ liblapack-dev \
libcodec2-dev \
libglib2.0-dev \ libglib2.0-dev \
libxml2-dev \ libxml2-dev \
# Build dump1090 # Build dump1090
@@ -191,6 +189,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
fi \ fi \
&& cd /tmp \ && cd /tmp \
&& rm -rf /tmp/SatDump \ && rm -rf /tmp/SatDump \
# Build hackrf CLI tools from source — avoids libhackrf0 version conflict
# between the 'hackrf' apt package and soapysdr-module-hackrf's newer libhackrf0
&& cd /tmp \
&& git clone --depth 1 https://github.com/greatscottgadgets/hackrf.git \
&& cd hackrf/host \
&& mkdir build && cd build \
&& cmake .. \
&& make \
&& make install \
&& ldconfig \
&& rm -rf /tmp/hackrf \
# Build rtlamr (utility meter decoder - requires Go) # Build rtlamr (utility meter decoder - requires Go)
&& cd /tmp \ && cd /tmp \
&& curl -fsSL "https://go.dev/dl/go1.22.5.linux-$(dpkg --print-architecture).tar.gz" | tar -C /usr/local -xz \ && curl -fsSL "https://go.dev/dl/go1.22.5.linux-$(dpkg --print-architecture).tar.gz" | tar -C /usr/local -xz \
@@ -199,27 +208,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& go install github.com/bemasher/rtlamr@latest \ && go install github.com/bemasher/rtlamr@latest \
&& cp /tmp/gopath/bin/rtlamr /usr/bin/rtlamr \ && cp /tmp/gopath/bin/rtlamr /usr/bin/rtlamr \
&& rm -rf /usr/local/go /tmp/gopath \ && rm -rf /usr/local/go /tmp/gopath \
# Build mbelib (required by DSD)
&& cd /tmp \
&& git clone https://github.com/lwvmobile/mbelib.git \
&& cd mbelib \
&& (git checkout ambe_tones || true) \
&& mkdir build && cd build \
&& cmake .. \
&& make -j$(nproc) \
&& make install \
&& ldconfig \
&& rm -rf /tmp/mbelib \
# Build DSD-FME (Digital Speech Decoder for DMR/P25)
&& cd /tmp \
&& git clone --depth 1 https://github.com/lwvmobile/dsd-fme.git \
&& cd dsd-fme \
&& mkdir build && cd build \
&& cmake .. \
&& make -j$(nproc) \
&& make install \
&& ldconfig \
&& rm -rf /tmp/dsd-fme \
# Cleanup build tools to reduce image size # Cleanup build tools to reduce image size
# libgtk-3-dev is explicitly removed; runtime GTK libs remain for slowrx # libgtk-3-dev is explicitly removed; runtime GTK libs remain for slowrx
&& apt-get remove -y \ && apt-get remove -y \
@@ -247,7 +235,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libpulse-dev \ libpulse-dev \
libfftw3-dev \ libfftw3-dev \
liblapack-dev \ liblapack-dev \
libcodec2-dev \
&& apt-get autoremove -y \ && apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
+6 -7
View File
@@ -2,7 +2,7 @@
<p align="center"> <p align="center">
<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="Python 3.9+"> <img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="Python 3.9+">
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License"> <img src="https://img.shields.io/badge/license-Apache--2.0-green.svg" alt="Apache 2.0 License">
<img src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux-lightgrey.svg" alt="Platform"> <img src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux-lightgrey.svg" alt="Platform">
</p> </p>
@@ -40,7 +40,7 @@ Support the developer of this open-source project
- **HF SSTV** - Terrestrial SSTV on shortwave frequencies (80m-10m, VHF, UHF) - **HF SSTV** - Terrestrial SSTV on shortwave frequencies (80m-10m, VHF, UHF)
- **APRS** - Amateur packet radio position reports and telemetry via direwolf - **APRS** - Amateur packet radio position reports and telemetry via direwolf
- **Satellite Tracking** - Pass prediction with polar plot and ground track map - **Satellite Tracking** - Pass prediction with polar plot and ground track map
- **Utility Meters** - Electric, gas, and water meter reading via rtl_amr - **Utility Meters** - Electric, gas, and water meter reading via rtlamr
- **ADS-B History** - Persistent aircraft history with reporting dashboard (Postgres optional) - **ADS-B History** - Persistent aircraft history with reporting dashboard (Postgres optional)
- **WiFi Scanning** - Monitor mode reconnaissance via aircrack-ng - **WiFi Scanning** - Monitor mode reconnaissance via aircrack-ng
- **Bluetooth Scanning** - Device discovery and tracker detection (with Ubertooth support) - **Bluetooth Scanning** - Device discovery and tracker detection (with Ubertooth support)
@@ -48,6 +48,7 @@ Support the developer of this open-source project
- **GPS** - Real-time GPS position tracking with live map, speed, altitude, and satellite info - **GPS** - Real-time GPS position tracking with live map, speed, altitude, and satellite info
- **TSCM** - Counter-surveillance with RF baseline comparison and threat detection - **TSCM** - Counter-surveillance with RF baseline comparison and threat detection
- **Meshtastic** - LoRa mesh network integration - **Meshtastic** - LoRa mesh network integration
- **Space Weather** - Real-time solar and geomagnetic data from NOAA SWPC, NASA SDO, and HamQSL (no SDR required)
- **Spy Stations** - Number stations and diplomatic HF network database - **Spy Stations** - Number stations and diplomatic HF network database
- **Remote Agents** - Distributed SIGINT with remote sensor nodes - **Remote Agents** - Distributed SIGINT with remote sensor nodes
- **Offline Mode** - Bundled assets for air-gapped/field deployments - **Offline Mode** - Bundled assets for air-gapped/field deployments
@@ -56,8 +57,6 @@ Support the developer of this open-source project
## Installation / Debian / Ubuntu / MacOS ## Installation / Debian / Ubuntu / MacOS
```
**1. Clone and run:** **1. Clone and run:**
```bash ```bash
git clone https://github.com/smittix/intercept.git git clone https://github.com/smittix/intercept.git
@@ -149,7 +148,7 @@ Set these as environment variables for either local installs or Docker:
```bash ```bash
INTERCEPT_ADSB_AUTO_START=true \ INTERCEPT_ADSB_AUTO_START=true \
INTERCEPT_SHARED_OBSERVER_LOCATION=false \ INTERCEPT_SHARED_OBSERVER_LOCATION=false \
python app.py sudo -E venv/bin/python intercept.py
``` ```
**Docker example (.env)** **Docker example (.env)**
@@ -171,7 +170,7 @@ Then open **/adsb/history** for the reporting dashboard.
After starting, open **http://localhost:5050** in your browser. The username and password is <b>admin</b>:<b>admin</b> After starting, open **http://localhost:5050** in your browser. The username and password is <b>admin</b>:<b>admin</b>
The credentials can be change in the ADMIN_USERNAME & ADMIN_PASSWORD variables in config.py The credentials can be changed in the ADMIN_USERNAME & ADMIN_PASSWORD variables in config.py
--- ---
@@ -244,7 +243,7 @@ Created by **smittix** - [GitHub](https://github.com/smittix)
[AIS-catcher](https://github.com/jvde-github/AIS-catcher) | [AIS-catcher](https://github.com/jvde-github/AIS-catcher) |
[acarsdec](https://github.com/TLeconte/acarsdec) | [acarsdec](https://github.com/TLeconte/acarsdec) |
[direwolf](https://github.com/wb2osz/direwolf) | [direwolf](https://github.com/wb2osz/direwolf) |
[rtl_amr](https://github.com/bemasher/rtlamr) | [rtlamr](https://github.com/bemasher/rtlamr) |
[dumpvdl2](https://github.com/szpajder/dumpvdl2) | [dumpvdl2](https://github.com/szpajder/dumpvdl2) |
[aircrack-ng](https://www.aircrack-ng.org/) | [aircrack-ng](https://www.aircrack-ng.org/) |
[Leaflet.js](https://leafletjs.com/) | [Leaflet.js](https://leafletjs.com/) |
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,4 +1,4 @@
{ {
"version": "2026-02-01_ba81b697", "version": "2026-02-15_ae16bb62",
"downloaded": "2026-02-04T17:06:54.806043Z" "downloaded": "2026-02-20T00:29:06.228007Z"
} }
+86 -28
View File
@@ -25,7 +25,7 @@ import subprocess
from typing import Any from typing import Any
from flask import Flask, render_template, jsonify, send_file, Response, request,redirect, url_for, flash, session from flask import Flask, render_template, jsonify, send_file, Response, request,redirect, url_for, flash, session, send_from_directory
from werkzeug.security import check_password_hash from werkzeug.security import check_password_hash
from config import VERSION, CHANGELOG, SHARED_OBSERVER_LOCATION_ENABLED, DEFAULT_LATITUDE, DEFAULT_LONGITUDE from config import VERSION, CHANGELOG, SHARED_OBSERVER_LOCATION_ENABLED, DEFAULT_LATITUDE, DEFAULT_LONGITUDE
from utils.dependencies import check_tool, check_all_dependencies, TOOL_DEPENDENCIES from utils.dependencies import check_tool, check_all_dependencies, TOOL_DEPENDENCIES
@@ -100,11 +100,24 @@ def add_security_headers(response):
def inject_offline_settings(): def inject_offline_settings():
"""Inject offline settings into all templates.""" """Inject offline settings into all templates."""
from utils.database import get_setting from utils.database import get_setting
# Privacy-first defaults: keep dashboard assets/fonts local to avoid
# third-party tracker/storage defenses in strict browsers.
assets_source = str(get_setting('offline.assets_source', 'local') or 'local').lower()
fonts_source = str(get_setting('offline.fonts_source', 'local') or 'local').lower()
if assets_source not in ('local', 'cdn'):
assets_source = 'local'
if fonts_source not in ('local', 'cdn'):
fonts_source = 'local'
# Force local delivery for core dashboard pages.
assets_source = 'local'
fonts_source = 'local'
return { return {
'offline_settings': { 'offline_settings': {
'enabled': get_setting('offline.enabled', False), 'enabled': get_setting('offline.enabled', False),
'assets_source': get_setting('offline.assets_source', 'cdn'), 'assets_source': assets_source,
'fonts_source': get_setting('offline.fonts_source', 'cdn'), 'fonts_source': fonts_source,
'tile_provider': get_setting('offline.tile_provider', 'cartodb_dark_cyan'), 'tile_provider': get_setting('offline.tile_provider', 'cartodb_dark_cyan'),
'tile_server_url': get_setting('offline.tile_server_url', '') 'tile_server_url': get_setting('offline.tile_server_url', '')
} }
@@ -177,12 +190,6 @@ dsc_rtl_process = None
dsc_queue = queue.Queue(maxsize=QUEUE_MAX_SIZE) dsc_queue = queue.Queue(maxsize=QUEUE_MAX_SIZE)
dsc_lock = threading.Lock() dsc_lock = threading.Lock()
# DMR / Digital Voice
dmr_process = None
dmr_rtl_process = None
dmr_queue = queue.Queue(maxsize=QUEUE_MAX_SIZE)
dmr_lock = threading.Lock()
# TSCM (Technical Surveillance Countermeasures) # TSCM (Technical Surveillance Countermeasures)
tscm_queue = queue.Queue(maxsize=QUEUE_MAX_SIZE) tscm_queue = queue.Queue(maxsize=QUEUE_MAX_SIZE)
tscm_lock = threading.Lock() tscm_lock = threading.Lock()
@@ -389,6 +396,18 @@ def favicon() -> Response:
return send_file('favicon.svg', mimetype='image/svg+xml') return send_file('favicon.svg', mimetype='image/svg+xml')
@app.route('/sw.js')
def service_worker() -> Response:
resp = send_from_directory('static', 'sw.js', mimetype='application/javascript')
resp.headers['Service-Worker-Allowed'] = '/'
return resp
@app.route('/manifest.json')
def pwa_manifest() -> Response:
return send_from_directory('static', 'manifest.json', mimetype='application/manifest+json')
@app.route('/devices') @app.route('/devices')
def get_devices() -> Response: def get_devices() -> Response:
"""Get all detected SDR devices with hardware type info.""" """Get all detected SDR devices with hardware type info."""
@@ -661,20 +680,66 @@ def _get_subghz_active() -> bool:
return False return False
def _get_dmr_active() -> bool: def _get_bluetooth_health() -> tuple[bool, int]:
"""Check if Digital Voice decoder has an active process.""" """Return Bluetooth active state and best-effort device count."""
legacy_running = bt_process is not None and (bt_process.poll() is None if bt_process else False)
scanner_running = False
scanner_count = 0
try: try:
from routes import dmr as dmr_module from utils.bluetooth.scanner import _scanner_instance as bt_scanner
proc = dmr_module.dmr_dsd_process if bt_scanner is not None:
return bool(dmr_module.dmr_running and proc and proc.poll() is None) scanner_running = bool(bt_scanner.is_scanning)
scanner_count = int(bt_scanner.device_count)
except Exception: except Exception:
return False scanner_running = False
scanner_count = 0
locate_running = False
try:
from utils.bt_locate import get_locate_session
session = get_locate_session()
if session and getattr(session, 'active', False):
scanner = getattr(session, '_scanner', None)
locate_running = bool(scanner and scanner.is_scanning)
except Exception:
locate_running = False
return (legacy_running or scanner_running or locate_running), max(len(bt_devices), scanner_count)
def _get_wifi_health() -> tuple[bool, int, int]:
"""Return WiFi active state and best-effort network/client counts."""
legacy_running = wifi_process is not None and (wifi_process.poll() is None if wifi_process else False)
scanner_running = False
scanner_networks = 0
scanner_clients = 0
try:
from utils.wifi.scanner import _scanner_instance as wifi_scanner
if wifi_scanner is not None:
status = wifi_scanner.get_status()
scanner_running = bool(status.is_scanning)
scanner_networks = int(status.networks_found or 0)
scanner_clients = int(status.clients_found or 0)
except Exception:
scanner_running = False
scanner_networks = 0
scanner_clients = 0
return (
legacy_running or scanner_running,
max(len(wifi_networks), scanner_networks),
max(len(wifi_clients), scanner_clients),
)
@app.route('/health') @app.route('/health')
def health_check() -> Response: def health_check() -> Response:
"""Health check endpoint for monitoring.""" """Health check endpoint for monitoring."""
import time import time
bt_active, bt_device_count = _get_bluetooth_health()
wifi_active, wifi_network_count, wifi_client_count = _get_wifi_health()
return jsonify({ return jsonify({
'status': 'healthy', 'status': 'healthy',
'version': VERSION, 'version': VERSION,
@@ -687,18 +752,17 @@ def health_check() -> Response:
'acars': acars_process is not None and (acars_process.poll() is None if acars_process else False), 'acars': acars_process is not None and (acars_process.poll() is None if acars_process else False),
'vdl2': vdl2_process is not None and (vdl2_process.poll() is None if vdl2_process else False), 'vdl2': vdl2_process is not None and (vdl2_process.poll() is None if vdl2_process else False),
'aprs': aprs_process is not None and (aprs_process.poll() is None if aprs_process else False), 'aprs': aprs_process is not None and (aprs_process.poll() is None if aprs_process else False),
'wifi': wifi_process is not None and (wifi_process.poll() is None if wifi_process else False), 'wifi': wifi_active,
'bluetooth': bt_process is not None and (bt_process.poll() is None if bt_process else False), 'bluetooth': bt_active,
'dsc': dsc_process is not None and (dsc_process.poll() is None if dsc_process else False), 'dsc': dsc_process is not None and (dsc_process.poll() is None if dsc_process else False),
'dmr': _get_dmr_active(),
'subghz': _get_subghz_active(), 'subghz': _get_subghz_active(),
}, },
'data': { 'data': {
'aircraft_count': len(adsb_aircraft), 'aircraft_count': len(adsb_aircraft),
'vessel_count': len(ais_vessels), 'vessel_count': len(ais_vessels),
'wifi_networks_count': len(wifi_networks), 'wifi_networks_count': wifi_network_count,
'wifi_clients_count': len(wifi_clients), 'wifi_clients_count': wifi_client_count,
'bt_devices_count': len(bt_devices), 'bt_devices_count': bt_device_count,
'dsc_messages_count': len(dsc_messages), 'dsc_messages_count': len(dsc_messages),
} }
}) })
@@ -710,7 +774,6 @@ def kill_all() -> Response:
global current_process, sensor_process, wifi_process, adsb_process, ais_process, acars_process global current_process, sensor_process, wifi_process, adsb_process, ais_process, acars_process
global vdl2_process global vdl2_process
global aprs_process, aprs_rtl_process, dsc_process, dsc_rtl_process, bt_process global aprs_process, aprs_rtl_process, dsc_process, dsc_rtl_process, bt_process
global dmr_process, dmr_rtl_process
# Import adsb and ais modules to reset their state # Import adsb and ais modules to reset their state
from routes import adsb as adsb_module from routes import adsb as adsb_module
@@ -722,7 +785,7 @@ def kill_all() -> Response:
'rtl_fm', 'multimon-ng', 'rtl_433', 'rtl_fm', 'multimon-ng', 'rtl_433',
'airodump-ng', 'aireplay-ng', 'airmon-ng', 'airodump-ng', 'aireplay-ng', 'airmon-ng',
'dump1090', 'acarsdec', 'dumpvdl2', 'direwolf', 'AIS-catcher', 'dump1090', 'acarsdec', 'dumpvdl2', 'direwolf', 'AIS-catcher',
'hcitool', 'bluetoothctl', 'satdump', 'dsd', 'hcitool', 'bluetoothctl', 'satdump',
'rtl_tcp', 'rtl_power', 'rtlamr', 'ffmpeg', 'rtl_tcp', 'rtl_power', 'rtlamr', 'ffmpeg',
'hackrf_transfer', 'hackrf_sweep' 'hackrf_transfer', 'hackrf_sweep'
] ]
@@ -772,11 +835,6 @@ def kill_all() -> Response:
dsc_process = None dsc_process = None
dsc_rtl_process = None dsc_rtl_process = None
# Reset DMR state
with dmr_lock:
dmr_process = None
dmr_rtl_process = None
# Reset Bluetooth state (legacy) # Reset Bluetooth state (legacy)
with bt_lock: with bt_lock:
if bt_process: if bt_process:
+62 -4
View File
@@ -7,10 +7,71 @@ import os
import sys import sys
# Application version # Application version
VERSION = "2.19.0" VERSION = "2.22.3"
# Changelog - latest release notes (shown on welcome screen) # Changelog - latest release notes (shown on welcome screen)
CHANGELOG = [ CHANGELOG = [
{
"version": "2.22.3",
"date": "February 2026",
"highlights": [
"Waterfall control panel no longer shows as unstyled text on first visit",
"WebSDR globe renders correctly on first page load without requiring a refresh",
"Waterfall monitor audio no longer takes minutes to start — playback detection now waits for real audio data instead of just the WAV header",
"Waterfall monitor stop is now instant — audio pauses and UI updates immediately instead of waiting for backend cleanup",
"Stopping the waterfall no longer shows a stale 'WebSocket closed before ready' message",
]
},
{
"version": "2.22.1",
"date": "February 2026",
"highlights": [
"Waterfall receiver overhaul: WebSocket I/Q streaming with server-side FFT, click-to-tune, and zoom controls",
"Voice alerts for configurable event notifications across modes",
"Signal fingerprinting mode for RF device identification and pattern analysis",
"SignalID integration via SigIDWiki API for automatic signal classification",
"PWA support: installable web app with service worker and manifest",
"Mode stop responsiveness improvements with faster timeout handling",
"Navigation performance instrumentation and smoother mode transitions",
"Pager, sensor, and SSTV real-time signal scope visualization",
"ADS-B MSG2 surface movement parsing for ground vehicle tracking",
"WebSDR major overhaul with improved receiver management and audio streaming",
"Documentation audit: fixed license, tool names, entry points, and SSTV decoder references",
"Help modal updated with ACARS and VDL2 mode descriptions",
]
},
{
"version": "2.21.1",
"date": "February 2026",
"highlights": [
"BT Locate map first-load fix with render stabilization retries during initial mode open",
"BT Locate trail restore optimization for faster startup when historical GPS points exist",
"BT Locate mode-switch map invalidation timing fix to prevent delayed/blank map render",
]
},
{
"version": "2.21.0",
"date": "February 2026",
"highlights": [
"Global map theme refresh with improved contrast and cross-dashboard consistency",
"Cross-app UX updates for accessibility, mode consistency, and render performance",
"Weather satellite reliability fixes for auto-scheduler and Mercator pass tracking",
"Bluetooth/WiFi runtime health fixes with BT Locate continuity and confidence improvements",
"ADS-B/VDL2 streaming reliability upgrades for multi-client SSE fanout and remote decoding",
"Analytics enhancements with operational insights and temporal pattern panels",
]
},
{
"version": "2.20.0",
"date": "February 2026",
"highlights": [
"Space Weather mode: real-time solar and geomagnetic monitoring from NOAA SWPC, NASA SDO, and HamQSL",
"Kp index, solar wind, X-ray flux charts with Chart.js visualization",
"HF band conditions, D-RAP absorption maps, aurora forecast, and solar imagery",
"NOAA Space Weather Scales (G/S/R), flare probability, and active solar regions",
"No SDR hardware required — all data from public APIs with server-side caching",
]
},
{ {
"version": "2.19.0", "version": "2.19.0",
"date": "February 2026", "date": "February 2026",
@@ -67,7 +128,6 @@ CHANGELOG = [
"Pure Python SSTV decoder replacing broken slowrx dependency", "Pure Python SSTV decoder replacing broken slowrx dependency",
"Real-time signal scope for pager, sensor, and SSTV modes", "Real-time signal scope for pager, sensor, and SSTV modes",
"USB-level device probe to prevent cryptic rtl_fm crashes", "USB-level device probe to prevent cryptic rtl_fm crashes",
"DMR dsd-fme protocol fixes, tuning controls, and state sync",
"SDR device lock-up fix from unreleased device registry on crash", "SDR device lock-up fix from unreleased device registry on crash",
] ]
}, },
@@ -75,8 +135,6 @@ CHANGELOG = [
"version": "2.14.0", "version": "2.14.0",
"date": "February 2026", "date": "February 2026",
"highlights": [ "highlights": [
"DMR/P25/NXDN/D-STAR digital voice decoder with dsd-fme",
"DMR visual synthesizer with event-driven spring-physics bars",
"HF SSTV general mode with predefined shortwave frequencies", "HF SSTV general mode with predefined shortwave frequencies",
"WebSDR integration for remote HF/shortwave listening", "WebSDR integration for remote HF/shortwave listening",
"Listening Post signal scanner and audio pipeline improvements", "Listening Post signal scanner and audio pipeline improvements",
+16 -11
View File
@@ -24,17 +24,6 @@ Complete feature list for all modules.
- **Wideband spectrum analysis** with real-time visualization - **Wideband spectrum analysis** with real-time visualization
- **I/Q capture** - record raw samples for offline analysis - **I/Q capture** - record raw samples for offline analysis
## AIS Vessel Tracking
- **Real-time vessel tracking** via AIS-catcher on 161.975/162.025 MHz
- **Full-screen dashboard** - dedicated popout with interactive map
- **Interactive Leaflet map** with OpenStreetMap tiles (dark-themed)
- **Vessel details popup** - name, MMSI, callsign, destination, ETA
- **Navigation data** - speed, course, heading, rate of turn
- **Ship type classification** - cargo, tanker, passenger, fishing, etc.
- **Vessel dimensions** - length, width, draught
- **Multi-SDR support** - RTL-SDR, HackRF, LimeSDR, Airspy, SDRplay
## Spy Stations (Number Stations) ## Spy Stations (Number Stations)
- **Comprehensive database** of active number stations and diplomatic networks - **Comprehensive database** of active number stations and diplomatic networks
@@ -165,6 +154,22 @@ Digital Selective Calling (DSC) monitoring on the international maritime distres
- **Real-time JSON output** with meter ID, consumption, and signal data - **Real-time JSON output** with meter ID, consumption, and signal data
- **Multiple meter protocol support** via rtl_tcp integration - **Multiple meter protocol support** via rtl_tcp integration
## Space Weather
- **Real-time solar indices** - Solar Flux Index (SFI), Kp index, A-index, sunspot number
- **NOAA Space Weather Scales** - Geomagnetic storms (G), solar radiation (S), radio blackouts (R)
- **HF band conditions** - Day/night propagation from HamQSL for 80m through 10m bands
- **Solar wind monitoring** - Speed, density, and IMF Bz from DSCOVR satellite
- **X-ray flux chart** - GOES X-ray data with flare class scale (A/B/C/M/X)
- **Flare probability** - 1-day and 3-day C/M/X-class flare forecasts
- **Solar imagery** - NASA SDO 193A, 304A, and magnetogram images
- **D-RAP absorption maps** - HF radio absorption at 5-30 MHz frequency bands
- **Aurora forecast** - OVATION aurora oval visualization
- **SWPC alerts** - Real-time space weather alerts and warnings
- **Active solar regions** - Current sunspot region data with location and area
- **Auto-refresh** - 5-minute polling with manual refresh option
- **No SDR required** - Data fetched from NOAA SWPC, NASA SDO, and HamQSL public APIs
## Satellite Tracking ## Satellite Tracking
- **Full-screen dashboard** - dedicated popout with polar plot and ground track - **Full-screen dashboard** - dedicated popout with polar plot and ground track
+13 -5
View File
@@ -206,14 +206,22 @@ Extended base for full-screen dashboards (maps, visualizations).
| `listening` | Listening post | | `listening` | Listening post |
| `spystations` | Spy stations | | `spystations` | Spy stations |
| `meshtastic` | Mesh networking | | `meshtastic` | Mesh networking |
| `weathersat` | Weather satellites |
| `sstv_general` | HF SSTV |
| `gps` | GPS tracking |
| `websdr` | WebSDR |
| `subghz` | Sub-GHz analyzer |
| `bt_locate` | BT Locate |
| `analytics` | Analytics dashboard |
| `spaceweather` | Space weather |
### Navigation Groups ### Navigation Groups
The navigation is organized into groups: The navigation is organized into groups:
- **SDR / RF**: Pager, 433MHz, Meters, Aircraft, Vessels, APRS, Listening Post, Spy Stations, Meshtastic - **Signals**: Pager, 433MHz, Meters, Listening Post, SubGHz
- **Wireless**: WiFi, Bluetooth - **Tracking**: Aircraft, Vessels, APRS, GPS
- **Security**: TSCM - **Space**: Satellite, ISS SSTV, Weather Sat, HF SSTV, Space Weather
- **Space**: Satellite, ISS SSTV - **Wireless**: WiFi, Bluetooth, BT Locate, Meshtastic
- **Intel**: TSCM, Analytics, Spy Stations, WebSDR
--- ---
+20 -1
View File
@@ -172,7 +172,7 @@ Set the following environment variables (Docker recommended):
```bash ```bash
INTERCEPT_ADSB_AUTO_START=true \ INTERCEPT_ADSB_AUTO_START=true \
INTERCEPT_SHARED_OBSERVER_LOCATION=false \ INTERCEPT_SHARED_OBSERVER_LOCATION=false \
python app.py sudo -E venv/bin/python intercept.py
``` ```
**Docker example (.env)** **Docker example (.env)**
@@ -239,6 +239,25 @@ Enable the auto-scheduler to automatically capture passes:
- Starts SatDump at the correct time and frequency - Starts SatDump at the correct time and frequency
- Decoded images are saved with timestamps - Decoded images are saved with timestamps
## Space Weather
1. **Switch to Space Weather mode** - Select "Space Weather" from the Space navigation group
2. **View Dashboard** - Solar indices, NOAA scales, band conditions, and charts load automatically
3. **Solar Imagery** - Toggle between SDO 193A, 304A, and Magnetogram views
4. **D-RAP Maps** - Select frequency (5-30 MHz) to view HF radio absorption maps
5. **Aurora Forecast** - View the OVATION aurora oval for the northern hemisphere
6. **Alerts** - Review current SWPC space weather alerts and warnings
7. **Active Regions** - View solar active region data (number, location, area)
8. **Refresh** - Data auto-refreshes every 5 minutes, or click "Refresh Now"
### Tips
- No SDR hardware required — all data comes from public APIs (NOAA SWPC, NASA SDO, HamQSL)
- Check HF band conditions before operating on shortwave frequencies
- Kp >= 5 indicates geomagnetic storm conditions that may affect HF propagation
- D-RAP maps show where HF absorption is highest — useful for path planning
- Solar imagery updates approximately every 15 minutes from NASA SDO
## AIS Vessel Tracking ## AIS Vessel Tracking
1. **Select Hardware** - Choose your SDR type 1. **Select Hardware** - Choose your SDR type
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

+39 -21
View File
@@ -61,72 +61,73 @@
<div class="carousel-filters"> <div class="carousel-filters">
<button class="filter-btn active" data-filter="all">All</button> <button class="filter-btn active" data-filter="all">All</button>
<button class="filter-btn" data-filter="sdr">SDR / RF</button> <button class="filter-btn" data-filter="signals">Signals</button>
<button class="filter-btn" data-filter="aviation">Aviation & Maritime</button> <button class="filter-btn" data-filter="tracking">Tracking</button>
<button class="filter-btn" data-filter="space">Space & Satellite</button> <button class="filter-btn" data-filter="space">Space</button>
<button class="filter-btn" data-filter="wireless">Wireless & Security</button> <button class="filter-btn" data-filter="wireless">Wireless</button>
<button class="filter-btn" data-filter="intel">Intel</button>
<button class="filter-btn" data-filter="platform">Platform</button> <button class="filter-btn" data-filter="platform">Platform</button>
</div> </div>
<div class="carousel-wrapper"> <div class="carousel-wrapper">
<button class="carousel-arrow carousel-arrow-left" aria-label="Scroll left">&#8249;</button> <button class="carousel-arrow carousel-arrow-left" aria-label="Scroll left">&#8249;</button>
<div class="carousel-track"> <div class="carousel-track">
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="signals">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="20" height="14" rx="2"/><line x1="6" y1="9" x2="6" y2="15"/><line x1="10" y1="9" x2="10" y2="15"/><line x1="14" y1="11" x2="18" y2="11"/><line x1="14" y1="13" x2="18" y2="13"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="20" height="14" rx="2"/><line x1="6" y1="9" x2="6" y2="15"/><line x1="10" y1="9" x2="10" y2="15"/><line x1="14" y1="11" x2="18" y2="11"/><line x1="14" y1="13" x2="18" y2="13"/></svg></div>
<h3>Pager Decoding</h3> <h3>Pager Decoding</h3>
<p>Decode POCSAG and FLEX pager messages using rtl_fm and multimon-ng. Monitor emergency services and legacy paging systems.</p> <p>Decode POCSAG and FLEX pager messages using rtl_fm and multimon-ng. Monitor emergency services and legacy paging systems.</p>
</div> </div>
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="signals">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2v4"/><path d="M12 18v4"/><circle cx="12" cy="12" r="4"/><path d="M4.93 4.93l2.83 2.83"/><path d="M16.24 16.24l2.83 2.83"/><path d="M2 12h4"/><path d="M18 12h4"/><path d="M4.93 19.07l2.83-2.83"/><path d="M16.24 7.76l2.83-2.83"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2v4"/><path d="M12 18v4"/><circle cx="12" cy="12" r="4"/><path d="M4.93 4.93l2.83 2.83"/><path d="M16.24 16.24l2.83 2.83"/><path d="M2 12h4"/><path d="M18 12h4"/><path d="M4.93 19.07l2.83-2.83"/><path d="M16.24 7.76l2.83-2.83"/></svg></div>
<h3>433MHz Sensors</h3> <h3>433MHz Sensors</h3>
<p>Decode 200+ protocols including weather stations, TPMS, smart home devices, and IoT sensors via rtl_433.</p> <p>Decode 200+ protocols including weather stations, TPMS, smart home devices, and IoT sensors via rtl_433.</p>
</div> </div>
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="signals">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12h4l3-9 6 18 3-9h4"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12h4l3-9 6 18 3-9h4"/></svg></div>
<h3>Sub-GHz Analyzer</h3> <h3>Sub-GHz Analyzer</h3>
<p>HackRF-based signal capture and protocol decoding for 300-928 MHz ISM bands with spectrum analysis and replay.</p> <p>HackRF-based signal capture and protocol decoding for 300-928 MHz ISM bands with spectrum analysis and replay.</p>
</div> </div>
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="signals">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 18.5a6.5 6.5 0 1 1 0-13"/><path d="M17 12h5"/><path d="M12 7V2"/><circle cx="12" cy="12" r="2"/><path d="M8.5 8.5L5 5"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 18.5a6.5 6.5 0 1 1 0-13"/><path d="M17 12h5"/><path d="M12 7V2"/><circle cx="12" cy="12" r="2"/><path d="M8.5 8.5L5 5"/></svg></div>
<h3>Listening Post</h3> <h3>Listening Post</h3>
<p>Frequency scanner with real-time audio monitoring, fine-tuning controls, and customizable frequency presets.</p> <p>Frequency scanner with real-time audio monitoring, fine-tuning controls, and customizable frequency presets.</p>
</div> </div>
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="intel">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg></div>
<h3>WebSDR</h3> <h3>WebSDR</h3>
<p>Remote HF/shortwave listening via the KiwiSDR network. Access receivers worldwide with real-time audio streaming.</p> <p>Remote HF/shortwave listening via the KiwiSDR network. Access receivers worldwide with real-time audio streaming.</p>
</div> </div>
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="intel">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="2"/><path d="M8 8h2v2H8z"/><path d="M14 8h2v2h-2z"/><path d="M8 14h2v2H8z"/><path d="M14 14h2v2h-2z"/><path d="M11 8h2v2h-2z"/><path d="M11 11h2v2h-2z"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="2"/><path d="M8 8h2v2H8z"/><path d="M14 8h2v2h-2z"/><path d="M8 14h2v2H8z"/><path d="M14 14h2v2h-2z"/><path d="M11 8h2v2h-2z"/><path d="M11 11h2v2h-2z"/></svg></div>
<h3>Spy Stations</h3> <h3>Spy Stations</h3>
<p>Number stations and diplomatic HF network database. Frequencies, schedules, and background info from priyom.org.</p> <p>Number stations and diplomatic HF network database. Frequencies, schedules, and background info from priyom.org.</p>
</div> </div>
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="tracking">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg></div>
<h3>APRS</h3> <h3>APRS</h3>
<p>Amateur packet radio position reports and telemetry via direwolf. Track amateur radio operators on an interactive map.</p> <p>Amateur packet radio position reports and telemetry via direwolf. Track amateur radio operators on an interactive map.</p>
</div> </div>
<div class="feature-card" data-category="sdr"> <div class="feature-card" data-category="signals">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg></div>
<h3>Utility Meters</h3> <h3>Utility Meters</h3>
<p>Smart meter monitoring via rtl_amr. Receive electric, gas, and water meter broadcasts in real time.</p> <p>Smart meter monitoring via rtlamr. Receive electric, gas, and water meter broadcasts in real time.</p>
</div> </div>
<div class="feature-card" data-category="aviation"> <div class="feature-card" data-category="tracking">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M17.8 19.2L16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.1-.9.1-1.1.5l-.3.5c-.2.5-.1 1 .3 1.3L9 12l-2 3H4l-1 1 3 2 2 3 1-1v-3l3-2 3.5 5.3c.3.4.8.5 1.3.3l.5-.2c.4-.3.6-.7.5-1.2z"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M17.8 19.2L16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.1-.9.1-1.1.5l-.3.5c-.2.5-.1 1 .3 1.3L9 12l-2 3H4l-1 1 3 2 2 3 1-1v-3l3-2 3.5 5.3c.3.4.8.5 1.3.3l.5-.2c.4-.3.6-.7.5-1.2z"/></svg></div>
<h3>Aircraft Tracking</h3> <h3>Aircraft Tracking</h3>
<p>Real-time ADS-B tracking with interactive maps, aircraft photos, emergency squawk detection, and range visualization.</p> <p>Real-time ADS-B tracking with interactive maps, aircraft photos, emergency squawk detection, and range visualization.</p>
</div> </div>
<div class="feature-card" data-category="aviation"> <div class="feature-card" data-category="tracking">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="M7 8h10"/><path d="M7 12h6"/><path d="M7 16h8"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="M7 8h10"/><path d="M7 12h6"/><path d="M7 16h8"/></svg></div>
<h3>ACARS</h3> <h3>ACARS</h3>
<p>Aircraft datalink messages via acarsdec. Decode operational, weather, and position reports from commercial flights.</p> <p>Aircraft datalink messages via acarsdec. Decode operational, weather, and position reports from commercial flights.</p>
</div> </div>
<div class="feature-card" data-category="aviation"> <div class="feature-card" data-category="tracking">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14"/><path d="M5 12h14"/><circle cx="12" cy="12" r="9"/><path d="M3.5 9h17"/><path d="M3.5 15h17"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14"/><path d="M5 12h14"/><circle cx="12" cy="12" r="9"/><path d="M3.5 9h17"/><path d="M3.5 15h17"/></svg></div>
<h3>VDL2</h3> <h3>VDL2</h3>
<p>VHF Data Link Mode 2 aircraft datalink decoding via dumpvdl2. Real-time ACARS-over-AVLC message capture with signal analysis.</p> <p>VHF Data Link Mode 2 aircraft datalink decoding via dumpvdl2. Real-time ACARS-over-AVLC message capture with signal analysis.</p>
</div> </div>
<div class="feature-card" data-category="aviation"> <div class="feature-card" data-category="tracking">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 20l4-4h3l4-7 2 4h2l5-9"/><path d="M22 20H2"/><path d="M6 16v4"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 20l4-4h3l4-7 2 4h2l5-9"/><path d="M22 20H2"/><path d="M6 16v4"/></svg></div>
<h3>Vessel Tracking</h3> <h3>Vessel Tracking</h3>
<p>Real-time AIS ship tracking via AIS-catcher. Monitor maritime traffic with vessel details, course, speed, and destination.</p> <p>Real-time AIS ship tracking via AIS-catcher. Monitor maritime traffic with vessel details, course, speed, and destination.</p>
@@ -151,11 +152,16 @@
<h3>HF SSTV</h3> <h3>HF SSTV</h3>
<p>Terrestrial SSTV on shortwave frequencies. Decode amateur radio image transmissions across HF, VHF, and UHF bands.</p> <p>Terrestrial SSTV on shortwave frequencies. Decode amateur radio image transmissions across HF, VHF, and UHF bands.</p>
</div> </div>
<div class="feature-card" data-category="space"> <div class="feature-card" data-category="tracking">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/><path d="M12 8l4 4-4 4"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/><path d="M12 8l4 4-4 4"/></svg></div>
<h3>GPS Tracking</h3> <h3>GPS Tracking</h3>
<p>Real-time GPS position tracking with live map, speed, heading, altitude, satellite info, and track recording.</p> <p>Real-time GPS position tracking with live map, speed, heading, altitude, satellite info, and track recording.</p>
</div> </div>
<div class="feature-card" data-category="space">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></div>
<h3>Space Weather</h3>
<p>Real-time solar and geomagnetic monitoring. Kp index, HF band conditions, solar imagery, D-RAP maps, and aurora forecasts from NOAA SWPC.</p>
</div>
<div class="feature-card" data-category="wireless"> <div class="feature-card" data-category="wireless">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.55a11 11 0 0 1 14.08 0"/><path d="M1.42 9a16 16 0 0 1 21.16 0"/><path d="M8.53 16.11a6 6 0 0 1 6.95 0"/><circle cx="12" cy="20" r="1"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.55a11 11 0 0 1 14.08 0"/><path d="M1.42 9a16 16 0 0 1 21.16 0"/><path d="M8.53 16.11a6 6 0 0 1 6.95 0"/><circle cx="12" cy="20" r="1"/></svg></div>
<h3>WiFi Scanning</h3> <h3>WiFi Scanning</h3>
@@ -171,7 +177,7 @@
<h3>BT Locate</h3> <h3>BT Locate</h3>
<p>SAR Bluetooth device location with GPS-tagged signal trail mapping, IRK-based RPA resolution, and proximity audio alerts.</p> <p>SAR Bluetooth device location with GPS-tagged signal trail mapping, IRK-based RPA resolution, and proximity audio alerts.</p>
</div> </div>
<div class="feature-card" data-category="wireless"> <div class="feature-card" data-category="intel">
<div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s-8-4.5-8-11.8A8 8 0 0 1 12 2a8 8 0 0 1 8 8.2c0 7.3-8 11.8-8 11.8z"/><circle cx="12" cy="10" r="3"/><path d="M12 2v3"/><path d="M4.93 4.93l2.12 2.12"/><path d="M20 12h-3"/></svg></div> <div class="feature-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s-8-4.5-8-11.8A8 8 0 0 1 12 2a8 8 0 0 1 8 8.2c0 7.3-8 11.8-8 11.8z"/><circle cx="12" cy="10" r="3"/><path d="M12 2v3"/><path d="M4.93 4.93l2.12 2.12"/><path d="M20 12h-3"/></svg></div>
<h3>TSCM</h3> <h3>TSCM</h3>
<p>Counter-surveillance with baseline recording, threat detection, device correlation, and risk scoring.</p> <p>Counter-surveillance with baseline recording, threat detection, device correlation, and risk scoring.</p>
@@ -257,6 +263,10 @@
<img src="images/websdr.png" alt="WebSDR Remote Listening"> <img src="images/websdr.png" alt="WebSDR Remote Listening">
<span class="screenshot-label">WebSDR</span> <span class="screenshot-label">WebSDR</span>
</div> </div>
<div class="screenshot-item">
<img src="images/aprs.png" alt="APRS Tracker">
<span class="screenshot-label">APRS Tracker</span>
</div>
<div class="screenshot-item"> <div class="screenshot-item">
<img src="images/vdl2.png" alt="VDL2 Aircraft Datalink"> <img src="images/vdl2.png" alt="VDL2 Aircraft Datalink">
<span class="screenshot-label">VDL2 Aircraft Datalink</span> <span class="screenshot-label">VDL2 Aircraft Datalink</span>
@@ -265,6 +275,14 @@
<img src="images/weather-satellite.png" alt="Weather Satellite Decoder"> <img src="images/weather-satellite.png" alt="Weather Satellite Decoder">
<span class="screenshot-label">Weather Satellite</span> <span class="screenshot-label">Weather Satellite</span>
</div> </div>
<div class="screenshot-item">
<img src="images/space-weather-1.png" alt="Space Weather Dashboard">
<span class="screenshot-label">Space Weather</span>
</div>
<div class="screenshot-item">
<img src="images/space-weather-2.png" alt="Space Weather Solar Imagery">
<span class="screenshot-label">Space Weather — Solar &amp; Aurora</span>
</div>
<div class="screenshot-item"> <div class="screenshot-item">
<img src="images/satellite-tracker.png" alt="Satellite Tracker"> <img src="images/satellite-tracker.png" alt="Satellite Tracker">
<span class="screenshot-label">Satellite Tracker</span> <span class="screenshot-label">Satellite Tracker</span>
@@ -303,7 +321,7 @@ sudo -E venv/bin/python intercept.py</code></pre>
<div class="code-block"> <div class="code-block">
<pre><code>git clone https://github.com/smittix/intercept.git <pre><code>git clone https://github.com/smittix/intercept.git
cd intercept cd intercept
docker compose up -d</code></pre> docker compose --profile basic up -d --build</code></pre>
</div> </div>
<p class="install-note">Requires privileged mode for USB SDR access</p> <p class="install-note">Requires privileged mode for USB SDR access</p>
</div> </div>
@@ -404,7 +422,7 @@ docker compose up -d</code></pre>
</div> </div>
</div> </div>
<div class="footer-bottom"> <div class="footer-bottom">
<p>Created by <a href="https://github.com/smittix" target="_blank">smittix</a> · MIT License</p> <p>Created by <a href="https://github.com/smittix" target="_blank">smittix</a> · Apache 2.0 License</p>
<p class="disclaimer">For educational and authorized testing purposes only.</p> <p class="disclaimer">For educational and authorized testing purposes only.</p>
</div> </div>
</div> </div>
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "intercept" name = "intercept"
version = "2.19.0" version = "2.22.3"
description = "Signal Intelligence Platform - Pager/433MHz/ADS-B/Satellite/WiFi/Bluetooth" description = "Signal Intelligence Platform - Pager/433MHz/ADS-B/Satellite/WiFi/Bluetooth"
readme = "README.md" readme = "README.md"
requires-python = ">=3.9" requires-python = ">=3.9"
+33 -31
View File
@@ -2,39 +2,40 @@
def register_blueprints(app): def register_blueprints(app):
"""Register all route blueprints with the Flask app.""" """Register all route blueprints with the Flask app."""
from .pager import pager_bp from .acars import acars_bp
from .sensor import sensor_bp
from .rtlamr import rtlamr_bp
from .wifi import wifi_bp
from .wifi_v2 import wifi_v2_bp
from .bluetooth import bluetooth_bp
from .bluetooth_v2 import bluetooth_v2_bp
from .adsb import adsb_bp from .adsb import adsb_bp
from .ais import ais_bp from .ais import ais_bp
from .dsc import dsc_bp
from .acars import acars_bp
from .vdl2 import vdl2_bp
from .aprs import aprs_bp
from .satellite import satellite_bp
from .gps import gps_bp
from .settings import settings_bp
from .correlation import correlation_bp
from .listening_post import listening_post_bp
from .meshtastic import meshtastic_bp
from .tscm import tscm_bp, init_tscm_state
from .spy_stations import spy_stations_bp
from .controller import controller_bp
from .offline import offline_bp
from .updater import updater_bp
from .sstv import sstv_bp
from .weather_sat import weather_sat_bp
from .sstv_general import sstv_general_bp
from .dmr import dmr_bp
from .websdr import websdr_bp
from .alerts import alerts_bp from .alerts import alerts_bp
from .recordings import recordings_bp from .aprs import aprs_bp
from .subghz import subghz_bp from .bluetooth import bluetooth_bp
from .bluetooth_v2 import bluetooth_v2_bp
from .bt_locate import bt_locate_bp from .bt_locate import bt_locate_bp
from .controller import controller_bp
from .correlation import correlation_bp
from .dsc import dsc_bp
from .gps import gps_bp
from .listening_post import receiver_bp
from .meshtastic import meshtastic_bp
from .offline import offline_bp
from .pager import pager_bp
from .recordings import recordings_bp
from .rtlamr import rtlamr_bp
from .satellite import satellite_bp
from .sensor import sensor_bp
from .settings import settings_bp
from .signalid import signalid_bp
from .space_weather import space_weather_bp
from .spy_stations import spy_stations_bp
from .sstv import sstv_bp
from .sstv_general import sstv_general_bp
from .subghz import subghz_bp
from .tscm import init_tscm_state, tscm_bp
from .updater import updater_bp
from .vdl2 import vdl2_bp
from .weather_sat import weather_sat_bp
from .websdr import websdr_bp
from .wifi import wifi_bp
from .wifi_v2 import wifi_v2_bp
app.register_blueprint(pager_bp) app.register_blueprint(pager_bp)
app.register_blueprint(sensor_bp) app.register_blueprint(sensor_bp)
@@ -53,7 +54,7 @@ def register_blueprints(app):
app.register_blueprint(gps_bp) app.register_blueprint(gps_bp)
app.register_blueprint(settings_bp) app.register_blueprint(settings_bp)
app.register_blueprint(correlation_bp) app.register_blueprint(correlation_bp)
app.register_blueprint(listening_post_bp) app.register_blueprint(receiver_bp)
app.register_blueprint(meshtastic_bp) app.register_blueprint(meshtastic_bp)
app.register_blueprint(tscm_bp) app.register_blueprint(tscm_bp)
app.register_blueprint(spy_stations_bp) app.register_blueprint(spy_stations_bp)
@@ -63,12 +64,13 @@ def register_blueprints(app):
app.register_blueprint(sstv_bp) # ISS SSTV decoder app.register_blueprint(sstv_bp) # ISS SSTV decoder
app.register_blueprint(weather_sat_bp) # NOAA/Meteor weather satellite decoder app.register_blueprint(weather_sat_bp) # NOAA/Meteor weather satellite decoder
app.register_blueprint(sstv_general_bp) # General terrestrial SSTV app.register_blueprint(sstv_general_bp) # General terrestrial SSTV
app.register_blueprint(dmr_bp) # DMR / P25 / Digital Voice
app.register_blueprint(websdr_bp) # HF/Shortwave WebSDR app.register_blueprint(websdr_bp) # HF/Shortwave WebSDR
app.register_blueprint(alerts_bp) # Cross-mode alerts app.register_blueprint(alerts_bp) # Cross-mode alerts
app.register_blueprint(recordings_bp) # Session recordings app.register_blueprint(recordings_bp) # Session recordings
app.register_blueprint(subghz_bp) # SubGHz transceiver (HackRF) app.register_blueprint(subghz_bp) # SubGHz transceiver (HackRF)
app.register_blueprint(bt_locate_bp) # BT Locate SAR device tracking app.register_blueprint(bt_locate_bp) # BT Locate SAR device tracking
app.register_blueprint(space_weather_bp) # Space weather monitoring
app.register_blueprint(signalid_bp) # External signal ID enrichment
# Initialize TSCM state with queue and lock from app # Initialize TSCM state with queue and lock from app
import app as app_module import app as app_module
+23 -25
View File
@@ -21,7 +21,7 @@ import app as app_module
from utils.logging import sensor_logger as logger from utils.logging import sensor_logger as logger
from utils.validation import validate_device_index, validate_gain, validate_ppm from utils.validation import validate_device_index, validate_gain, validate_ppm
from utils.sdr import SDRFactory, SDRType from utils.sdr import SDRFactory, SDRType
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.constants import ( from utils.constants import (
PROCESS_TERMINATE_TIMEOUT, PROCESS_TERMINATE_TIMEOUT,
@@ -35,11 +35,8 @@ acars_bp = Blueprint('acars', __name__, url_prefix='/acars')
# Default VHF ACARS frequencies (MHz) - common worldwide # Default VHF ACARS frequencies (MHz) - common worldwide
DEFAULT_ACARS_FREQUENCIES = [ DEFAULT_ACARS_FREQUENCIES = [
'131.550', # Primary worldwide '131.725', # North America
'130.025', # Secondary USA/Canada '131.825', # North America
'129.125', # USA
'131.525', # Europe
'131.725', # Europe secondary
] ]
# Message counter for statistics # Message counter for statistics
@@ -129,6 +126,13 @@ def stream_acars_output(process: subprocess.Popen, is_text_mode: bool = False) -
app_module.acars_queue.put(data) app_module.acars_queue.put(data)
# Feed flight correlator
try:
from utils.flight_correlator import get_flight_correlator
get_flight_correlator().add_acars_message(data)
except Exception:
pass
# Log if enabled # Log if enabled
if app_module.logging_enabled: if app_module.logging_enabled:
try: try:
@@ -410,25 +414,19 @@ def stop_acars() -> Response:
@acars_bp.route('/stream') @acars_bp.route('/stream')
def stream_acars() -> Response: def stream_acars() -> Response:
"""SSE stream for ACARS messages.""" """SSE stream for ACARS messages."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('acars', msg, msg.get('type'))
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.acars_queue.get(timeout=SSE_QUEUE_TIMEOUT) source_queue=app_module.acars_queue,
last_keepalive = time.time() channel_key='acars',
try: timeout=SSE_QUEUE_TIMEOUT,
process_event('acars', msg, msg.get('type')) keepalive_interval=SSE_KEEPALIVE_INTERVAL,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
return response return response
@@ -440,7 +438,7 @@ def get_frequencies() -> Response:
return jsonify({ return jsonify({
'default': DEFAULT_ACARS_FREQUENCIES, 'default': DEFAULT_ACARS_FREQUENCIES,
'regions': { 'regions': {
'north_america': ['129.125', '130.025', '130.450', '131.550'], 'north_america': ['131.725', '131.825'],
'europe': ['131.525', '131.725', '131.550'], 'europe': ['131.525', '131.725', '131.550'],
'asia_pacific': ['131.550', '131.450'], 'asia_pacific': ['131.550', '131.450'],
} }
+168 -43
View File
@@ -77,6 +77,11 @@ _sbs_error_logged = False # Suppress repeated connection error logs
# Track ICAOs already looked up in aircraft database (avoid repeated lookups) # Track ICAOs already looked up in aircraft database (avoid repeated lookups)
_looked_up_icaos: set[str] = set() _looked_up_icaos: set[str] = set()
# Per-client SSE queues for ADS-B stream fanout.
_adsb_stream_subscribers: set[queue.Queue] = set()
_adsb_stream_subscribers_lock = threading.Lock()
_ADSB_STREAM_CLIENT_QUEUE_SIZE = 500
# Load aircraft database at module init # Load aircraft database at module init
aircraft_db.load_database() aircraft_db.load_database()
@@ -203,6 +208,31 @@ def _parse_int_param(value: str | None, default: int, min_value: int | None = No
return parsed return parsed
def _broadcast_adsb_update(payload: dict[str, Any]) -> None:
"""Fan out a payload to all active ADS-B SSE subscribers."""
with _adsb_stream_subscribers_lock:
subscribers = tuple(_adsb_stream_subscribers)
for subscriber in subscribers:
try:
subscriber.put_nowait(payload)
except queue.Full:
# Drop oldest queued event for that client and try once more.
try:
subscriber.get_nowait()
subscriber.put_nowait(payload)
except (queue.Empty, queue.Full):
# Client queue remains saturated; skip this payload.
continue
def _adsb_stream_queue_depth() -> int:
"""Best-effort aggregate queue depth across connected ADS-B SSE clients."""
with _adsb_stream_subscribers_lock:
subscribers = tuple(_adsb_stream_subscribers)
return sum(subscriber.qsize() for subscriber in subscribers)
def _get_active_session() -> dict[str, Any] | None: def _get_active_session() -> dict[str, Any] | None:
if not ADSB_HISTORY_ENABLED or not PSYCOPG2_AVAILABLE: if not ADSB_HISTORY_ENABLED or not PSYCOPG2_AVAILABLE:
return None return None
@@ -349,10 +379,62 @@ def parse_sbs_stream(service_addr):
adsb_bytes_received = 0 adsb_bytes_received = 0
adsb_lines_received = 0 adsb_lines_received = 0
def flush_pending_updates(force: bool = False) -> None:
nonlocal last_update
if not pending_updates:
return
now = time.time()
if not force and now - last_update < ADSB_UPDATE_INTERVAL:
return
captured_at = datetime.now(timezone.utc)
for update_icao in tuple(pending_updates):
if update_icao in app_module.adsb_aircraft:
snapshot = app_module.adsb_aircraft[update_icao]
_broadcast_adsb_update({
'type': 'aircraft',
**snapshot
})
adsb_snapshot_writer.enqueue({
'captured_at': captured_at,
'icao': update_icao,
'callsign': snapshot.get('callsign'),
'registration': snapshot.get('registration'),
'type_code': snapshot.get('type_code'),
'type_desc': snapshot.get('type_desc'),
'altitude': snapshot.get('altitude'),
'speed': snapshot.get('speed'),
'heading': snapshot.get('heading'),
'vertical_rate': snapshot.get('vertical_rate'),
'lat': snapshot.get('lat'),
'lon': snapshot.get('lon'),
'squawk': snapshot.get('squawk'),
'source_host': service_addr,
'snapshot': snapshot,
})
# Geofence check
_gf_lat = snapshot.get('lat')
_gf_lon = snapshot.get('lon')
if _gf_lat is not None and _gf_lon is not None:
try:
from utils.geofence import get_geofence_manager
for _gf_evt in get_geofence_manager().check_position(
update_icao, 'aircraft', _gf_lat, _gf_lon,
{'callsign': snapshot.get('callsign'), 'altitude': snapshot.get('altitude')}
):
process_event('adsb', _gf_evt, 'geofence')
except Exception:
pass
pending_updates.clear()
last_update = now
while adsb_using_service: while adsb_using_service:
try: try:
data = sock.recv(SOCKET_BUFFER_SIZE).decode('utf-8', errors='ignore') data = sock.recv(SOCKET_BUFFER_SIZE).decode('utf-8', errors='ignore')
if not data: if not data:
flush_pending_updates(force=True)
logger.warning("SBS connection closed (no data)") logger.warning("SBS connection closed (no data)")
break break
adsb_bytes_received += len(data) adsb_bytes_received += len(data)
@@ -439,6 +521,12 @@ def parse_sbs_stream(service_addr):
if parts[16]: if parts[16]:
try: try:
aircraft['vertical_rate'] = int(float(parts[16])) aircraft['vertical_rate'] = int(float(parts[16]))
if abs(aircraft['vertical_rate']) > 4000:
process_event('adsb', {
'type': 'vertical_rate_anomaly', 'icao': icao,
'callsign': aircraft.get('callsign', ''),
'vertical_rate': aircraft['vertical_rate'],
}, 'vertical_rate_anomaly')
except (ValueError, TypeError): except (ValueError, TypeError):
pass pass
@@ -456,44 +544,49 @@ def parse_sbs_stream(service_addr):
elif msg_type == '6' and len(parts) > 17: elif msg_type == '6' and len(parts) > 17:
if parts[17]: if parts[17]:
aircraft['squawk'] = parts[17] aircraft['squawk'] = parts[17]
sq = parts[17].strip()
_EMERGENCY_SQUAWKS = {'7700': 'General Emergency', '7600': 'Comms Failure', '7500': 'Hijack'}
if sq in _EMERGENCY_SQUAWKS:
process_event('adsb', {
'type': 'squawk_emergency', 'icao': icao,
'callsign': aircraft.get('callsign', ''),
'squawk': sq, 'meaning': _EMERGENCY_SQUAWKS[sq],
}, 'squawk_emergency')
elif msg_type == '2' and len(parts) > 15:
if parts[11]:
try:
aircraft['altitude'] = int(float(parts[11]))
except (ValueError, TypeError):
pass
if parts[12]:
try:
aircraft['speed'] = int(float(parts[12]))
except (ValueError, TypeError):
pass
if parts[13]:
try:
aircraft['heading'] = int(float(parts[13]))
except (ValueError, TypeError):
pass
if parts[14] and parts[15]:
try:
aircraft['lat'] = float(parts[14])
aircraft['lon'] = float(parts[15])
except (ValueError, TypeError):
pass
app_module.adsb_aircraft.set(icao, aircraft) app_module.adsb_aircraft.set(icao, aircraft)
pending_updates.add(icao) pending_updates.add(icao)
adsb_messages_received += 1 adsb_messages_received += 1
adsb_last_message_time = time.time() adsb_last_message_time = time.time()
flush_pending_updates()
now = time.time()
if now - last_update >= ADSB_UPDATE_INTERVAL:
for update_icao in pending_updates:
if update_icao in app_module.adsb_aircraft:
snapshot = app_module.adsb_aircraft[update_icao]
app_module.adsb_queue.put({
'type': 'aircraft',
**snapshot
})
adsb_snapshot_writer.enqueue({
'captured_at': datetime.now(timezone.utc),
'icao': update_icao,
'callsign': snapshot.get('callsign'),
'registration': snapshot.get('registration'),
'type_code': snapshot.get('type_code'),
'type_desc': snapshot.get('type_desc'),
'altitude': snapshot.get('altitude'),
'speed': snapshot.get('speed'),
'heading': snapshot.get('heading'),
'vertical_rate': snapshot.get('vertical_rate'),
'lat': snapshot.get('lat'),
'lon': snapshot.get('lon'),
'squawk': snapshot.get('squawk'),
'source_host': service_addr,
'snapshot': snapshot,
})
pending_updates.clear()
last_update = now
except socket.timeout: except socket.timeout:
flush_pending_updates()
continue continue
flush_pending_updates(force=True)
sock.close() sock.close()
adsb_connected = False adsb_connected = False
except OSError as e: except OSError as e:
@@ -553,7 +646,7 @@ def adsb_status():
'last_message_time': adsb_last_message_time, 'last_message_time': adsb_last_message_time,
'aircraft_count': len(app_module.adsb_aircraft), 'aircraft_count': len(app_module.adsb_aircraft),
'aircraft': dict(app_module.adsb_aircraft), # Full aircraft data 'aircraft': dict(app_module.adsb_aircraft), # Full aircraft data
'queue_size': app_module.adsb_queue.qsize(), 'queue_size': _adsb_stream_queue_depth(),
'dump1090_path': find_dump1090(), 'dump1090_path': find_dump1090(),
'dump1090_running': dump1090_running, 'dump1090_running': dump1090_running,
'port_30003_open': check_dump1090_service() is not None 'port_30003_open': check_dump1090_service() is not None
@@ -844,23 +937,39 @@ def stop_adsb():
@adsb_bp.route('/stream') @adsb_bp.route('/stream')
def stream_adsb(): def stream_adsb():
"""SSE stream for ADS-B aircraft.""" """SSE stream for ADS-B aircraft."""
client_queue: queue.Queue = queue.Queue(maxsize=_ADSB_STREAM_CLIENT_QUEUE_SIZE)
with _adsb_stream_subscribers_lock:
_adsb_stream_subscribers.add(client_queue)
# Prime new clients with current known aircraft so they don't wait for the
# next positional update before rendering.
for snapshot in list(app_module.adsb_aircraft.values()):
try:
client_queue.put_nowait({'type': 'aircraft', **snapshot})
except queue.Full:
break
def generate(): def generate():
last_keepalive = time.time() last_keepalive = time.time()
while True: try:
try: while True:
msg = app_module.adsb_queue.get(timeout=SSE_QUEUE_TIMEOUT)
last_keepalive = time.time()
try: try:
process_event('adsb', msg, msg.get('type')) msg = client_queue.get(timeout=SSE_QUEUE_TIMEOUT)
except Exception: last_keepalive = time.time()
pass try:
yield format_sse(msg) process_event('adsb', msg, msg.get('type'))
except queue.Empty: except Exception:
now = time.time() pass
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL: yield format_sse(msg)
yield format_sse({'type': 'keepalive'}) except queue.Empty:
last_keepalive = now now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
finally:
with _adsb_stream_subscribers_lock:
_adsb_stream_subscribers.discard(client_queue)
response = Response(generate(), mimetype='text/event-stream') response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
@@ -871,10 +980,12 @@ def stream_adsb():
@adsb_bp.route('/dashboard') @adsb_bp.route('/dashboard')
def adsb_dashboard(): def adsb_dashboard():
"""Popout ADS-B dashboard.""" """Popout ADS-B dashboard."""
embedded = request.args.get('embedded', 'false') == 'true'
return render_template( return render_template(
'adsb_dashboard.html', 'adsb_dashboard.html',
shared_observer_location=SHARED_OBSERVER_LOCATION_ENABLED, shared_observer_location=SHARED_OBSERVER_LOCATION_ENABLED,
adsb_auto_start=ADSB_AUTO_START, adsb_auto_start=ADSB_AUTO_START,
embedded=embedded,
) )
@@ -1103,3 +1214,17 @@ def aircraft_photo(registration: str):
except Exception as e: except Exception as e:
logger.debug(f"Error fetching aircraft photo: {e}") logger.debug(f"Error fetching aircraft photo: {e}")
return jsonify({'success': False, 'error': str(e)}), 500 return jsonify({'success': False, 'error': str(e)}), 500
@adsb_bp.route('/aircraft/<icao>/messages')
def get_aircraft_messages(icao: str):
"""Get correlated ACARS/VDL2 messages for an aircraft."""
if not icao or not all(c in '0123456789ABCDEFabcdef' for c in icao):
return jsonify({'status': 'error', 'message': 'Invalid ICAO'}), 400
aircraft = app_module.adsb_aircraft.get(icao.upper())
callsign = aircraft.get('callsign') if aircraft else None
from utils.flight_correlator import get_flight_correlator
messages = get_flight_correlator().get_messages_for_aircraft(icao=icao.upper(), callsign=callsign)
return jsonify({'status': 'success', 'icao': icao.upper(), **messages})
+57 -20
View File
@@ -18,7 +18,7 @@ import app as app_module
from config import SHARED_OBSERVER_LOCATION_ENABLED from config import SHARED_OBSERVER_LOCATION_ENABLED
from utils.logging import get_logger from utils.logging import get_logger
from utils.validation import validate_device_index, validate_gain from utils.validation import validate_device_index, validate_gain
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.sdr import SDRFactory, SDRType from utils.sdr import SDRFactory, SDRType
from utils.constants import ( from utils.constants import (
@@ -124,13 +124,27 @@ def parse_ais_stream(port: int):
if now - last_update >= AIS_UPDATE_INTERVAL: if now - last_update >= AIS_UPDATE_INTERVAL:
for mmsi in pending_updates: for mmsi in pending_updates:
if mmsi in app_module.ais_vessels: if mmsi in app_module.ais_vessels:
_vessel_snap = app_module.ais_vessels[mmsi]
try: try:
app_module.ais_queue.put_nowait({ app_module.ais_queue.put_nowait({
'type': 'vessel', 'type': 'vessel',
**app_module.ais_vessels[mmsi] **_vessel_snap
}) })
except queue.Full: except queue.Full:
pass pass
# Geofence check
_v_lat = _vessel_snap.get('lat')
_v_lon = _vessel_snap.get('lon')
if _v_lat and _v_lon:
try:
from utils.geofence import get_geofence_manager
for _gf_evt in get_geofence_manager().check_position(
mmsi, 'vessel', _v_lat, _v_lon,
{'name': _vessel_snap.get('name'), 'ship_type': _vessel_snap.get('ship_type_text')}
):
process_event('ais', _gf_evt, 'geofence')
except Exception:
pass
pending_updates.clear() pending_updates.clear()
last_update = now last_update = now
@@ -282,6 +296,16 @@ def process_ais_message(msg: dict) -> dict | None:
# Timestamp # Timestamp
vessel['last_seen'] = time.time() vessel['last_seen'] = time.time()
# Check for DSC DISTRESS matching this MMSI
try:
for _dsc_key, _dsc_msg in app_module.dsc_messages.items():
if (str(_dsc_msg.get('source_mmsi', '')) == mmsi
and _dsc_msg.get('category', '').upper() == 'DISTRESS'):
vessel['dsc_distress'] = True
break
except Exception:
pass
return vessel return vessel
@@ -478,34 +502,47 @@ def stop_ais():
@ais_bp.route('/stream') @ais_bp.route('/stream')
def stream_ais(): def stream_ais():
"""SSE stream for AIS vessels.""" """SSE stream for AIS vessels."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('ais', msg, msg.get('type'))
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.ais_queue.get(timeout=SSE_QUEUE_TIMEOUT) source_queue=app_module.ais_queue,
last_keepalive = time.time() channel_key='ais',
try: timeout=SSE_QUEUE_TIMEOUT,
process_event('ais', msg, msg.get('type')) keepalive_interval=SSE_KEEPALIVE_INTERVAL,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
return response return response
@ais_bp.route('/vessel/<mmsi>/dsc')
def get_vessel_dsc(mmsi: str):
"""Get DSC messages associated with a vessel MMSI."""
if not mmsi or not mmsi.isdigit():
return jsonify({'status': 'error', 'message': 'Invalid MMSI'}), 400
matches = []
try:
for key, msg in app_module.dsc_messages.items():
if str(msg.get('source_mmsi', '')) == mmsi:
matches.append(dict(msg))
except Exception:
pass
return jsonify({'status': 'success', 'mmsi': mmsi, 'dsc_messages': matches})
@ais_bp.route('/dashboard') @ais_bp.route('/dashboard')
def ais_dashboard(): def ais_dashboard():
"""Popout AIS dashboard.""" """Popout AIS dashboard."""
embedded = request.args.get('embedded', 'false') == 'true'
return render_template( return render_template(
'ais_dashboard.html', 'ais_dashboard.html',
shared_observer_location=SHARED_OBSERVER_LOCATION_ENABLED, shared_observer_location=SHARED_OBSERVER_LOCATION_ENABLED,
embedded=embedded,
) )
+28 -19
View File
@@ -21,7 +21,7 @@ from flask import Blueprint, jsonify, request, Response
import app as app_module import app as app_module
from utils.logging import sensor_logger as logger from utils.logging import sensor_logger as logger
from utils.validation import validate_device_index, validate_gain, validate_ppm from utils.validation import validate_device_index, validate_gain, validate_ppm
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.sdr import SDRFactory, SDRType from utils.sdr import SDRFactory, SDRType
from utils.constants import ( from utils.constants import (
@@ -47,6 +47,8 @@ APRS_FREQUENCIES = {
'brazil': '145.570', 'brazil': '145.570',
'japan': '144.640', 'japan': '144.640',
'china': '144.640', 'china': '144.640',
'iss': '145.825',
'sonate2': '145.825',
} }
# Statistics # Statistics
@@ -1378,6 +1380,19 @@ def stream_aprs_output(rtl_process: subprocess.Popen, decoder_process: subproces
'last_seen': packet.get('timestamp'), 'last_seen': packet.get('timestamp'),
'packet_type': packet.get('packet_type'), 'packet_type': packet.get('packet_type'),
} }
# Geofence check
_aprs_lat = packet.get('lat')
_aprs_lon = packet.get('lon')
if _aprs_lat and _aprs_lon:
try:
from utils.geofence import get_geofence_manager
for _gf_evt in get_geofence_manager().check_position(
callsign, 'aprs_station', _aprs_lat, _aprs_lon,
{'callsign': callsign}
):
process_event('aprs', _gf_evt, 'geofence')
except Exception:
pass
# Evict oldest stations when limit is exceeded # Evict oldest stations when limit is exceeded
if len(aprs_stations) > APRS_MAX_STATIONS: if len(aprs_stations) > APRS_MAX_STATIONS:
oldest = min( oldest = min(
@@ -1751,25 +1766,19 @@ def stop_aprs() -> Response:
@aprs_bp.route('/stream') @aprs_bp.route('/stream')
def stream_aprs() -> Response: def stream_aprs() -> Response:
"""SSE stream for APRS packets.""" """SSE stream for APRS packets."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('aprs', msg, msg.get('type'))
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.aprs_queue.get(timeout=SSE_QUEUE_TIMEOUT) source_queue=app_module.aprs_queue,
last_keepalive = time.time() channel_key='aprs',
try: timeout=SSE_QUEUE_TIMEOUT,
process_event('aprs', msg, msg.get('type')) keepalive_interval=SSE_KEEPALIVE_INTERVAL,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
return response return response
+13 -20
View File
@@ -20,7 +20,7 @@ from flask import Blueprint, jsonify, request, Response
import app as app_module import app as app_module
from utils.dependencies import check_tool from utils.dependencies import check_tool
from utils.logging import bluetooth_logger as logger from utils.logging import bluetooth_logger as logger
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.validation import validate_bluetooth_interface from utils.validation import validate_bluetooth_interface
from data.oui import OUI_DATABASE, load_oui_database, get_manufacturer from data.oui import OUI_DATABASE, load_oui_database, get_manufacturer
@@ -556,26 +556,19 @@ def get_bt_devices():
@bluetooth_bp.route('/stream') @bluetooth_bp.route('/stream')
def stream_bt(): def stream_bt():
"""SSE stream for Bluetooth events.""" """SSE stream for Bluetooth events."""
def generate(): def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('bluetooth', msg, msg.get('type'))
keepalive_interval = 30.0
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.bt_queue.get(timeout=1) source_queue=app_module.bt_queue,
last_keepalive = time.time() channel_key='bluetooth',
try: timeout=1.0,
process_event('bluetooth', msg, msg.get('type')) keepalive_interval=30.0,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+36 -6
View File
@@ -38,6 +38,8 @@ def start_session():
- name_pattern: Target name substring (optional) - name_pattern: Target name substring (optional)
- irk_hex: Identity Resolving Key hex string (optional) - irk_hex: Identity Resolving Key hex string (optional)
- device_id: Device ID from Bluetooth scanner (optional) - device_id: Device ID from Bluetooth scanner (optional)
- device_key: Stable device key from Bluetooth scanner (optional)
- fingerprint_id: Payload fingerprint ID from Bluetooth scanner (optional)
- known_name: Hand-off device name (optional) - known_name: Hand-off device name (optional)
- known_manufacturer: Hand-off manufacturer (optional) - known_manufacturer: Hand-off manufacturer (optional)
- last_known_rssi: Hand-off last RSSI (optional) - last_known_rssi: Hand-off last RSSI (optional)
@@ -55,14 +57,28 @@ def start_session():
name_pattern=data.get('name_pattern'), name_pattern=data.get('name_pattern'),
irk_hex=data.get('irk_hex'), irk_hex=data.get('irk_hex'),
device_id=data.get('device_id'), device_id=data.get('device_id'),
device_key=data.get('device_key'),
fingerprint_id=data.get('fingerprint_id'),
known_name=data.get('known_name'), known_name=data.get('known_name'),
known_manufacturer=data.get('known_manufacturer'), known_manufacturer=data.get('known_manufacturer'),
last_known_rssi=data.get('last_known_rssi'), last_known_rssi=data.get('last_known_rssi'),
) )
# At least one identifier required # At least one identifier required
if not any([target.mac_address, target.name_pattern, target.irk_hex, target.device_id]): if not any([
return jsonify({'error': 'At least one target identifier required (mac_address, name_pattern, irk_hex, or device_id)'}), 400 target.mac_address,
target.name_pattern,
target.irk_hex,
target.device_id,
target.device_key,
target.fingerprint_id,
]):
return jsonify({
'error': (
'At least one target identifier required '
'(mac_address, name_pattern, irk_hex, device_id, device_key, or fingerprint_id)'
)
}), 400
# Parse environment # Parse environment
env_str = data.get('environment', 'OUTDOOR').upper() env_str = data.get('environment', 'OUTDOOR').upper()
@@ -93,9 +109,22 @@ def start_session():
f"env={environment.name}, fallback=({fallback_lat}, {fallback_lon})" f"env={environment.name}, fallback=({fallback_lat}, {fallback_lon})"
) )
session = start_locate_session( try:
target, environment, custom_exponent, fallback_lat, fallback_lon session = start_locate_session(
) target, environment, custom_exponent, fallback_lat, fallback_lon
)
except RuntimeError as exc:
logger.warning(f"Unable to start BT Locate session: {exc}")
return jsonify({
'status': 'error',
'error': 'Bluetooth scanner could not be started. Check adapter permissions/capabilities.',
}), 503
except Exception as exc:
logger.exception(f"Unexpected error starting BT Locate session: {exc}")
return jsonify({
'status': 'error',
'error': 'Failed to start locate session',
}), 500
return jsonify({ return jsonify({
'status': 'started', 'status': 'started',
@@ -124,7 +153,8 @@ def get_status():
'target': None, 'target': None,
}) })
return jsonify(session.get_status()) include_debug = str(request.args.get('debug', '')).lower() in ('1', 'true', 'yes')
return jsonify(session.get_status(include_debug=include_debug))
@bt_locate_bp.route('/trail', methods=['GET']) @bt_locate_bp.route('/trail', methods=['GET'])
+49 -25
View File
@@ -13,6 +13,7 @@ from __future__ import annotations
import json import json
import logging import logging
import queue import queue
import threading
import time import time
from datetime import datetime, timezone from datetime import datetime, timezone
from typing import Generator from typing import Generator
@@ -38,8 +39,26 @@ logger = logging.getLogger('intercept.controller')
controller_bp = Blueprint('controller', __name__, url_prefix='/controller') controller_bp = Blueprint('controller', __name__, url_prefix='/controller')
# Multi-agent data queue for combined SSE stream # Multi-agent SSE fanout state (per-client queues).
agent_data_queue: queue.Queue = queue.Queue(maxsize=1000) _agent_stream_subscribers: set[queue.Queue] = set()
_agent_stream_subscribers_lock = threading.Lock()
_AGENT_STREAM_CLIENT_QUEUE_SIZE = 500
def _broadcast_agent_data(payload: dict) -> None:
"""Fan out an ingested payload to all active /controller/stream/all clients."""
with _agent_stream_subscribers_lock:
subscribers = tuple(_agent_stream_subscribers)
for subscriber in subscribers:
try:
subscriber.put_nowait(payload)
except queue.Full:
try:
subscriber.get_nowait()
subscriber.put_nowait(payload)
except (queue.Empty, queue.Full):
continue
# ============================================================================= # =============================================================================
@@ -625,19 +644,16 @@ def ingest_push_data():
received_at=data.get('received_at') received_at=data.get('received_at')
) )
# Emit to SSE stream # Emit to SSE stream (fanout to all connected clients)
try: _broadcast_agent_data({
agent_data_queue.put_nowait({ 'type': 'agent_data',
'type': 'agent_data', 'agent_id': agent['id'],
'agent_id': agent['id'], 'agent_name': agent_name,
'agent_name': agent_name, 'scan_type': data.get('scan_type'),
'scan_type': data.get('scan_type'), 'interface': data.get('interface'),
'interface': data.get('interface'), 'payload': data.get('payload'),
'payload': data.get('payload'), 'received_at': data.get('received_at') or datetime.now(timezone.utc).isoformat()
'received_at': data.get('received_at') or datetime.now(timezone.utc).isoformat() })
})
except queue.Full:
logger.warning("Agent data queue full, data may be lost")
return jsonify({ return jsonify({
'status': 'accepted', 'status': 'accepted',
@@ -681,20 +697,28 @@ def stream_all_agents():
This endpoint streams push data as it arrives from agents. This endpoint streams push data as it arrives from agents.
Each message is tagged with agent_id and agent_name. Each message is tagged with agent_id and agent_name.
""" """
client_queue: queue.Queue = queue.Queue(maxsize=_AGENT_STREAM_CLIENT_QUEUE_SIZE)
with _agent_stream_subscribers_lock:
_agent_stream_subscribers.add(client_queue)
def generate() -> Generator[str, None, None]: def generate() -> Generator[str, None, None]:
last_keepalive = time.time() last_keepalive = time.time()
keepalive_interval = 30.0 keepalive_interval = 30.0
while True: try:
try: while True:
msg = agent_data_queue.get(timeout=1.0) try:
last_keepalive = time.time() msg = client_queue.get(timeout=1.0)
yield format_sse(msg) last_keepalive = time.time()
except queue.Empty: yield format_sse(msg)
now = time.time() except queue.Empty:
if now - last_keepalive >= keepalive_interval: now = time.time()
yield format_sse({'type': 'keepalive'}) if now - last_keepalive >= keepalive_interval:
last_keepalive = now yield format_sse({'type': 'keepalive'})
last_keepalive = now
finally:
with _agent_stream_subscribers_lock:
_agent_stream_subscribers.discard(client_queue)
response = Response(generate(), mimetype='text/event-stream') response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
-758
View File
@@ -1,758 +0,0 @@
"""DMR / P25 / Digital Voice decoding routes."""
from __future__ import annotations
import os
import queue
import re
import select
import shutil
import subprocess
import threading
import time
from datetime import datetime
from typing import Generator, Optional
from flask import Blueprint, jsonify, request, Response
import app as app_module
from utils.logging import get_logger
from utils.sse import format_sse
from utils.event_pipeline import process_event
from utils.process import register_process, unregister_process
from utils.validation import validate_frequency, validate_gain, validate_device_index, validate_ppm
from utils.sdr import SDRFactory, SDRType
from utils.constants import (
SSE_QUEUE_TIMEOUT,
SSE_KEEPALIVE_INTERVAL,
QUEUE_MAX_SIZE,
)
logger = get_logger('intercept.dmr')
dmr_bp = Blueprint('dmr', __name__, url_prefix='/dmr')
# ============================================
# GLOBAL STATE
# ============================================
dmr_rtl_process: Optional[subprocess.Popen] = None
dmr_dsd_process: Optional[subprocess.Popen] = None
dmr_thread: Optional[threading.Thread] = None
dmr_running = False
dmr_has_audio = False # True when ffmpeg available and dsd outputs audio
dmr_lock = threading.Lock()
dmr_queue: queue.Queue = queue.Queue(maxsize=QUEUE_MAX_SIZE)
dmr_active_device: Optional[int] = None
# Audio mux: the sole reader of dsd-fme stdout. Fans out bytes to all
# active ffmpeg stdin sinks when streaming clients are connected.
# This prevents dsd-fme from blocking on stdout (which would also
# freeze stderr / text data output).
_ffmpeg_sinks: set[object] = set()
_ffmpeg_sinks_lock = threading.Lock()
VALID_PROTOCOLS = ['auto', 'dmr', 'p25', 'nxdn', 'dstar', 'provoice']
# Classic dsd flags
_DSD_PROTOCOL_FLAGS = {
'auto': [],
'dmr': ['-fd'],
'p25': ['-fp'],
'nxdn': ['-fn'],
'dstar': ['-fi'],
'provoice': ['-fv'],
}
# dsd-fme remapped several flags from classic DSD:
# -fs = DMR Simplex (NOT -fd which is D-STAR!),
# -fd = D-STAR (NOT DMR!), -fp = ProVoice (NOT P25),
# -fi = NXDN48 (NOT D-Star), -f1 = P25 Phase 1,
# -ft = XDMA multi-protocol decoder
_DSD_FME_PROTOCOL_FLAGS = {
'auto': ['-fa'], # Broad auto: P25 (P1/P2), DMR, D-STAR, YSF, X2-TDMA
'dmr': ['-fs'], # DMR Simplex (-fd is D-STAR in dsd-fme!)
'p25': ['-ft'], # P25 P1/P2 coverage (also includes DMR in dsd-fme)
'nxdn': ['-fn'], # NXDN96
'dstar': ['-fd'], # D-STAR (-fd in dsd-fme, NOT DMR!)
'provoice': ['-fp'], # ProVoice (-fp in dsd-fme, not -fv)
}
# Modulation hints: force C4FM for protocols that use it, improving
# sync reliability vs letting dsd-fme auto-detect modulation type.
_DSD_FME_MODULATION = {
'dmr': ['-mc'], # C4FM
'nxdn': ['-mc'], # C4FM
}
# ============================================
# HELPERS
# ============================================
def find_dsd() -> tuple[str | None, bool]:
"""Find DSD (Digital Speech Decoder) binary.
Checks for dsd-fme first (common fork), then falls back to dsd.
Returns (path, is_fme) tuple.
"""
path = shutil.which('dsd-fme')
if path:
return path, True
path = shutil.which('dsd')
if path:
return path, False
return None, False
def find_rtl_fm() -> str | None:
"""Find rtl_fm binary."""
return shutil.which('rtl_fm')
def find_rx_fm() -> str | None:
"""Find SoapySDR rx_fm binary."""
return shutil.which('rx_fm')
def find_ffmpeg() -> str | None:
"""Find ffmpeg for audio encoding."""
return shutil.which('ffmpeg')
def parse_dsd_output(line: str) -> dict | None:
"""Parse a line of DSD stderr output into a structured event.
Handles output from both classic ``dsd`` and ``dsd-fme`` which use
different formatting for talkgroup / source / voice frame lines.
"""
line = line.strip()
if not line:
return None
# Skip DSD/dsd-fme startup banner lines (ASCII art, version info, etc.)
# Only filter lines that are purely decorative — dsd-fme uses box-drawing
# characters (│, ─) as column separators in DATA lines, so we must not
# discard lines that also contain alphanumeric content.
stripped_of_box = re.sub(r'[╔╗╚╝║═██▀▄╗╝╩╦╠╣╬│┤├┘└┐┌─┼█▓▒░\s]', '', line)
if not stripped_of_box:
return None
if re.match(r'^\s*(Build Version|MBElib|CODEC2|Audio (Out|In)|Decoding )', line):
return None
ts = datetime.now().strftime('%H:%M:%S')
# Sync detection: "Sync: +DMR (data)" or "Sync: +P25 Phase 1"
sync_match = re.match(r'Sync:\s*\+?(\S+.*)', line)
if sync_match:
return {
'type': 'sync',
'protocol': sync_match.group(1).strip(),
'timestamp': ts,
}
# Talkgroup and Source — check BEFORE slot so "Slot 1 Voice LC, TG: …"
# is captured as a call event rather than a bare slot event.
# Classic dsd: "TG: 12345 Src: 67890"
# dsd-fme: "TG: 12345, Src: 67890" or "Talkgroup: 12345, Source: 67890"
# "TGT: 12345 | SRC: 67890" (pipe-delimited variant)
tg_match = re.search(
r'(?:TGT?|Talkgroup)[:\s]+(\d+)[,|│\s]+(?:Src|Source|SRC)[:\s]+(\d+)', line, re.IGNORECASE
)
if tg_match:
result = {
'type': 'call',
'talkgroup': int(tg_match.group(1)),
'source_id': int(tg_match.group(2)),
'timestamp': ts,
}
# Extract slot if present on the same line
slot_inline = re.search(r'Slot\s*(\d+)', line)
if slot_inline:
result['slot'] = int(slot_inline.group(1))
return result
# P25 NAC (Network Access Code) — check before voice/slot
nac_match = re.search(r'NAC[:\s]+([0-9A-Fa-f]+)', line)
if nac_match:
return {
'type': 'nac',
'nac': nac_match.group(1),
'timestamp': ts,
}
# Voice frame detection — check BEFORE bare slot match
# Classic dsd: "Voice" keyword in frame lines
# dsd-fme: "voice" or "Voice LC" or "VOICE" in output
if re.search(r'\bvoice\b', line, re.IGNORECASE):
result = {
'type': 'voice',
'detail': line,
'timestamp': ts,
}
slot_inline = re.search(r'Slot\s*(\d+)', line)
if slot_inline:
result['slot'] = int(slot_inline.group(1))
return result
# Bare slot info (only when line is *just* slot info, not voice/call)
slot_match = re.match(r'\s*Slot\s*(\d+)\s*$', line)
if slot_match:
return {
'type': 'slot',
'slot': int(slot_match.group(1)),
'timestamp': ts,
}
# dsd-fme status lines we can surface: "TDMA", "CACH", "PI", "BS", etc.
# Also catches "Closing", "Input", and other lifecycle lines.
# Forward as raw so the frontend can show decoder is alive.
return {
'type': 'raw',
'text': line[:200],
'timestamp': ts,
}
_HEARTBEAT_INTERVAL = 3.0 # seconds between heartbeats when decoder is idle
# 100ms of silence at 8kHz 16-bit mono = 1600 bytes
_SILENCE_CHUNK = b'\x00' * 1600
def _register_audio_sink(sink: object) -> None:
"""Register an ffmpeg stdin sink for mux fanout."""
with _ffmpeg_sinks_lock:
_ffmpeg_sinks.add(sink)
def _unregister_audio_sink(sink: object) -> None:
"""Remove an ffmpeg stdin sink from mux fanout."""
with _ffmpeg_sinks_lock:
_ffmpeg_sinks.discard(sink)
def _get_audio_sinks() -> tuple[object, ...]:
"""Snapshot current audio sinks for lock-free iteration."""
with _ffmpeg_sinks_lock:
return tuple(_ffmpeg_sinks)
def _stop_process(proc: Optional[subprocess.Popen]) -> None:
"""Terminate and unregister a subprocess if present."""
if not proc:
return
if proc.poll() is None:
try:
proc.terminate()
proc.wait(timeout=2)
except Exception:
try:
proc.kill()
except Exception:
pass
unregister_process(proc)
def _reset_runtime_state(*, release_device: bool) -> None:
"""Reset process + runtime state and optionally release SDR ownership."""
global dmr_rtl_process, dmr_dsd_process
global dmr_running, dmr_has_audio, dmr_active_device
_stop_process(dmr_dsd_process)
_stop_process(dmr_rtl_process)
dmr_rtl_process = None
dmr_dsd_process = None
dmr_running = False
dmr_has_audio = False
with _ffmpeg_sinks_lock:
_ffmpeg_sinks.clear()
if release_device and dmr_active_device is not None:
app_module.release_sdr_device(dmr_active_device)
dmr_active_device = None
def _dsd_audio_mux(dsd_stdout):
"""Mux thread: sole reader of dsd-fme stdout.
Always drains dsd-fme's audio output to prevent the process from
blocking on stdout writes (which would also freeze stderr / text
data). When streaming clients are connected, forwards data to all
active ffmpeg stdin sinks with silence fill during voice gaps.
"""
try:
while dmr_running:
ready, _, _ = select.select([dsd_stdout], [], [], 0.1)
if ready:
data = os.read(dsd_stdout.fileno(), 4096)
if not data:
break
sinks = _get_audio_sinks()
for sink in sinks:
try:
sink.write(data)
sink.flush()
except (BrokenPipeError, OSError, ValueError):
_unregister_audio_sink(sink)
else:
# No audio from decoder — feed silence if client connected
sinks = _get_audio_sinks()
for sink in sinks:
try:
sink.write(_SILENCE_CHUNK)
sink.flush()
except (BrokenPipeError, OSError, ValueError):
_unregister_audio_sink(sink)
except (OSError, ValueError):
pass
def _queue_put(event: dict):
"""Put an event on the DMR queue, dropping oldest if full."""
try:
dmr_queue.put_nowait(event)
except queue.Full:
try:
dmr_queue.get_nowait()
except queue.Empty:
pass
try:
dmr_queue.put_nowait(event)
except queue.Full:
pass
def stream_dsd_output(rtl_process: subprocess.Popen, dsd_process: subprocess.Popen):
"""Read DSD stderr output and push parsed events to the queue.
Uses select() with a timeout so we can send periodic heartbeat
events while readline() would otherwise block indefinitely during
silence (no signal being decoded).
"""
global dmr_running
try:
_queue_put({'type': 'status', 'text': 'started'})
last_heartbeat = time.time()
while dmr_running:
if dsd_process.poll() is not None:
break
# Wait up to 1s for data on stderr instead of blocking forever
ready, _, _ = select.select([dsd_process.stderr], [], [], 1.0)
if ready:
line = dsd_process.stderr.readline()
if not line:
if dsd_process.poll() is not None:
break
continue
text = line.decode('utf-8', errors='replace').strip()
if not text:
continue
logger.debug("DSD raw: %s", text)
parsed = parse_dsd_output(text)
if parsed:
_queue_put(parsed)
last_heartbeat = time.time()
else:
# No stderr output — send heartbeat so frontend knows
# decoder is still alive and listening
now = time.time()
if now - last_heartbeat >= _HEARTBEAT_INTERVAL:
_queue_put({
'type': 'heartbeat',
'timestamp': datetime.now().strftime('%H:%M:%S'),
})
last_heartbeat = now
except Exception as e:
logger.error(f"DSD stream error: {e}")
finally:
global dmr_active_device, dmr_rtl_process, dmr_dsd_process
global dmr_has_audio
dmr_running = False
dmr_has_audio = False
with _ffmpeg_sinks_lock:
_ffmpeg_sinks.clear()
# Capture exit info for diagnostics
rc = dsd_process.poll()
reason = 'stopped'
detail = ''
if rc is not None and rc != 0:
reason = 'crashed'
try:
remaining = dsd_process.stderr.read(1024)
if remaining:
detail = remaining.decode('utf-8', errors='replace').strip()[:200]
except Exception:
pass
logger.warning(f"DSD process exited with code {rc}: {detail}")
# Cleanup decoder + demod processes
_stop_process(dsd_process)
_stop_process(rtl_process)
dmr_rtl_process = None
dmr_dsd_process = None
_queue_put({'type': 'status', 'text': reason, 'exit_code': rc, 'detail': detail})
# Release SDR device
if dmr_active_device is not None:
app_module.release_sdr_device(dmr_active_device)
dmr_active_device = None
logger.info("DSD stream thread stopped")
# ============================================
# API ENDPOINTS
# ============================================
@dmr_bp.route('/tools')
def check_tools() -> Response:
"""Check for required tools."""
dsd_path, _ = find_dsd()
rtl_fm = find_rtl_fm()
rx_fm = find_rx_fm()
ffmpeg = find_ffmpeg()
return jsonify({
'dsd': dsd_path is not None,
'rtl_fm': rtl_fm is not None,
'rx_fm': rx_fm is not None,
'ffmpeg': ffmpeg is not None,
'available': dsd_path is not None and (rtl_fm is not None or rx_fm is not None),
'protocols': VALID_PROTOCOLS,
})
@dmr_bp.route('/start', methods=['POST'])
def start_dmr() -> Response:
"""Start digital voice decoding."""
global dmr_rtl_process, dmr_dsd_process, dmr_thread
global dmr_running, dmr_has_audio, dmr_active_device
dsd_path, is_fme = find_dsd()
if not dsd_path:
return jsonify({'status': 'error', 'message': 'dsd not found. Install dsd-fme or dsd.'}), 503
data = request.json or {}
try:
frequency = validate_frequency(data.get('frequency', 462.5625))
gain = int(validate_gain(data.get('gain', 40)))
device = validate_device_index(data.get('device', 0))
protocol = str(data.get('protocol', 'auto')).lower()
ppm = validate_ppm(data.get('ppm', 0))
except (ValueError, TypeError) as e:
return jsonify({'status': 'error', 'message': f'Invalid parameter: {e}'}), 400
sdr_type_str = str(data.get('sdr_type', 'rtlsdr')).lower()
try:
sdr_type = SDRType(sdr_type_str)
except ValueError:
sdr_type = SDRType.RTL_SDR
if protocol not in VALID_PROTOCOLS:
return jsonify({'status': 'error', 'message': f'Invalid protocol. Use: {", ".join(VALID_PROTOCOLS)}'}), 400
if sdr_type == SDRType.RTL_SDR:
if not find_rtl_fm():
return jsonify({'status': 'error', 'message': 'rtl_fm not found. Install rtl-sdr tools.'}), 503
else:
if not find_rx_fm():
return jsonify({
'status': 'error',
'message': f'rx_fm not found. Install SoapySDR tools for {sdr_type.value}.'
}), 503
# Clear stale queue
try:
while True:
dmr_queue.get_nowait()
except queue.Empty:
pass
# Reserve running state before we start claiming resources/processes
# so concurrent /start requests cannot race each other.
with dmr_lock:
if dmr_running:
return jsonify({'status': 'error', 'message': 'Already running'}), 409
dmr_running = True
dmr_has_audio = False
# Claim SDR device — use protocol name so the device panel shows
# "D-STAR", "P25", etc. instead of always "DMR"
mode_label = protocol.upper() if protocol != 'auto' else 'DMR'
error = app_module.claim_sdr_device(device, mode_label)
if error:
with dmr_lock:
dmr_running = False
return jsonify({'status': 'error', 'error_type': 'DEVICE_BUSY', 'message': error}), 409
dmr_active_device = device
# Build FM demodulation command via SDR abstraction.
try:
sdr_device = SDRFactory.create_default_device(sdr_type, index=device)
builder = SDRFactory.get_builder(sdr_type)
rtl_cmd = builder.build_fm_demod_command(
device=sdr_device,
frequency_mhz=frequency,
sample_rate=48000,
gain=float(gain) if gain > 0 else None,
ppm=int(ppm) if ppm != 0 else None,
modulation='fm',
squelch=None,
bias_t=bool(data.get('bias_t', False)),
)
if sdr_type == SDRType.RTL_SDR:
# Keep squelch fully open for digital bitstreams.
rtl_cmd.extend(['-l', '0'])
except Exception as e:
_reset_runtime_state(release_device=True)
return jsonify({'status': 'error', 'message': f'Failed to build SDR command: {e}'}), 500
# Build DSD command
# Audio output: pipe decoded audio (8kHz s16le PCM) to stdout for
# ffmpeg transcoding. Both dsd-fme and classic dsd support '-o -'.
# If ffmpeg is unavailable, fall back to discarding audio.
ffmpeg_path = find_ffmpeg()
if ffmpeg_path:
audio_out = '-'
else:
audio_out = 'null' if is_fme else '-'
logger.warning("ffmpeg not found — audio streaming disabled, data-only mode")
dsd_cmd = [dsd_path, '-i', '-', '-o', audio_out]
if is_fme:
dsd_cmd.extend(_DSD_FME_PROTOCOL_FLAGS.get(protocol, []))
dsd_cmd.extend(_DSD_FME_MODULATION.get(protocol, []))
# Event log to stderr so we capture TG/Source/Voice data that
# dsd-fme may not output on stderr by default.
dsd_cmd.extend(['-J', '/dev/stderr'])
# Relax CRC checks for marginal signals — lets more frames
# through at the cost of occasional decode errors.
if data.get('relaxCrc', False):
dsd_cmd.append('-F')
else:
dsd_cmd.extend(_DSD_PROTOCOL_FLAGS.get(protocol, []))
try:
dmr_rtl_process = subprocess.Popen(
rtl_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
register_process(dmr_rtl_process)
# DSD stdout → PIPE when ffmpeg available (audio pipeline),
# otherwise DEVNULL (data-only mode)
dsd_stdout = subprocess.PIPE if ffmpeg_path else subprocess.DEVNULL
dmr_dsd_process = subprocess.Popen(
dsd_cmd,
stdin=dmr_rtl_process.stdout,
stdout=dsd_stdout,
stderr=subprocess.PIPE,
)
register_process(dmr_dsd_process)
# Allow rtl_fm to send directly to dsd
dmr_rtl_process.stdout.close()
# Start mux thread: always drains dsd-fme stdout to prevent the
# process from blocking (which would freeze stderr / text data).
# ffmpeg is started lazily per-client in /dmr/audio/stream.
if ffmpeg_path and dmr_dsd_process.stdout:
dmr_has_audio = True
threading.Thread(
target=_dsd_audio_mux,
args=(dmr_dsd_process.stdout,),
daemon=True,
).start()
time.sleep(0.3)
rtl_rc = dmr_rtl_process.poll()
dsd_rc = dmr_dsd_process.poll()
if rtl_rc is not None or dsd_rc is not None:
# Process died — capture stderr for diagnostics
rtl_err = ''
if dmr_rtl_process.stderr:
rtl_err = dmr_rtl_process.stderr.read().decode('utf-8', errors='replace')[:500]
dsd_err = ''
if dmr_dsd_process.stderr:
dsd_err = dmr_dsd_process.stderr.read().decode('utf-8', errors='replace')[:500]
logger.error(f"DSD pipeline died: rtl_fm rc={rtl_rc} err={rtl_err!r}, dsd rc={dsd_rc} err={dsd_err!r}")
# Terminate surviving processes and release resources.
_reset_runtime_state(release_device=True)
# Surface a clear error to the user
detail = rtl_err.strip() or dsd_err.strip()
if 'usb_claim_interface' in rtl_err or 'Failed to open' in rtl_err:
msg = f'SDR device {device} is busy — it may be in use by another mode or process. Try a different device.'
elif detail:
msg = f'Failed to start DSD pipeline: {detail}'
else:
msg = 'Failed to start DSD pipeline'
return jsonify({'status': 'error', 'message': msg}), 500
# Drain rtl_fm stderr in background to prevent pipe blocking
def _drain_rtl_stderr(proc):
try:
for line in proc.stderr:
pass
except Exception:
pass
threading.Thread(target=_drain_rtl_stderr, args=(dmr_rtl_process,), daemon=True).start()
dmr_thread = threading.Thread(
target=stream_dsd_output,
args=(dmr_rtl_process, dmr_dsd_process),
daemon=True,
)
dmr_thread.start()
return jsonify({
'status': 'started',
'frequency': frequency,
'protocol': protocol,
'sdr_type': sdr_type.value,
'has_audio': dmr_has_audio,
})
except Exception as e:
logger.error(f"Failed to start DMR: {e}")
_reset_runtime_state(release_device=True)
return jsonify({'status': 'error', 'message': str(e)}), 500
@dmr_bp.route('/stop', methods=['POST'])
def stop_dmr() -> Response:
"""Stop digital voice decoding."""
with dmr_lock:
_reset_runtime_state(release_device=True)
return jsonify({'status': 'stopped'})
@dmr_bp.route('/status')
def dmr_status() -> Response:
"""Get DMR decoder status."""
return jsonify({
'running': dmr_running,
'device': dmr_active_device,
'has_audio': dmr_has_audio,
})
@dmr_bp.route('/audio/stream')
def stream_dmr_audio() -> Response:
"""Stream decoded digital voice audio as WAV.
Starts a per-client ffmpeg encoder. The global mux thread
(_dsd_audio_mux) forwards DSD audio to this ffmpeg's stdin while
the client is connected, and discards audio otherwise. This avoids
the pipe-buffer deadlock that occurs when ffmpeg is started at
decoder launch (its stdout fills up before any HTTP client reads
it, back-pressuring the entire pipeline and freezing stderr/text
data output).
"""
if not dmr_running or not dmr_has_audio:
return Response(b'', mimetype='audio/wav', status=204)
ffmpeg_path = find_ffmpeg()
if not ffmpeg_path:
return Response(b'', mimetype='audio/wav', status=503)
encoder_cmd = [
ffmpeg_path, '-hide_banner', '-loglevel', 'error',
'-fflags', 'nobuffer', '-flags', 'low_delay',
'-probesize', '32', '-analyzeduration', '0',
'-f', 's16le', '-ar', '8000', '-ac', '1', '-i', 'pipe:0',
'-acodec', 'pcm_s16le', '-ar', '44100', '-f', 'wav', 'pipe:1',
]
audio_proc = subprocess.Popen(
encoder_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
# Drain ffmpeg stderr to prevent blocking
threading.Thread(
target=lambda p: [None for _ in p.stderr],
args=(audio_proc,), daemon=True,
).start()
if audio_proc.stdin:
_register_audio_sink(audio_proc.stdin)
def generate():
try:
while dmr_running and audio_proc.poll() is None:
ready, _, _ = select.select([audio_proc.stdout], [], [], 2.0)
if ready:
chunk = audio_proc.stdout.read(4096)
if chunk:
yield chunk
else:
break
else:
if audio_proc.poll() is not None:
break
except GeneratorExit:
pass
except Exception as e:
logger.error(f"DMR audio stream error: {e}")
finally:
# Disconnect mux → ffmpeg, then clean up
if audio_proc.stdin:
_unregister_audio_sink(audio_proc.stdin)
try:
audio_proc.stdin.close()
except Exception:
pass
try:
audio_proc.terminate()
audio_proc.wait(timeout=2)
except Exception:
try:
audio_proc.kill()
except Exception:
pass
return Response(
generate(),
mimetype='audio/wav',
headers={
'Content-Type': 'audio/wav',
'Cache-Control': 'no-cache, no-store',
'X-Accel-Buffering': 'no',
'Transfer-Encoding': 'chunked',
},
)
@dmr_bp.route('/stream')
def stream_dmr() -> Response:
"""SSE stream for DMR decoder events."""
def generate() -> Generator[str, None, None]:
last_keepalive = time.time()
while True:
try:
msg = dmr_queue.get(timeout=SSE_QUEUE_TIMEOUT)
last_keepalive = time.time()
try:
process_event('dmr', msg, msg.get('type'))
except Exception:
pass
yield format_sse(msg)
except queue.Empty:
now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no'
return response
+13 -20
View File
@@ -35,7 +35,7 @@ from utils.database import (
get_dsc_alert_summary, get_dsc_alert_summary,
) )
from utils.dsc.parser import parse_dsc_message from utils.dsc.parser import parse_dsc_message
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.validation import validate_device_index, validate_gain from utils.validation import validate_device_index, validate_gain
from utils.sdr import SDRFactory, SDRType from utils.sdr import SDRFactory, SDRType
@@ -518,26 +518,19 @@ def stop_decoding() -> Response:
@dsc_bp.route('/stream') @dsc_bp.route('/stream')
def stream() -> Response: def stream() -> Response:
"""SSE stream for real-time DSC messages.""" """SSE stream for real-time DSC messages."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('dsc', msg, msg.get('type'))
keepalive_interval = 30.0
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.dsc_queue.get(timeout=1) source_queue=app_module.dsc_queue,
last_keepalive = time.time() channel_key='dsc',
try: timeout=1.0,
process_event('dsc', msg, msg.get('type')) keepalive_interval=30.0,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+10 -17
View File
@@ -21,7 +21,7 @@ from utils.gps import (
stop_gpsd_daemon, stop_gpsd_daemon,
) )
from utils.logging import get_logger from utils.logging import get_logger
from utils.sse import format_sse from utils.sse import sse_stream_fanout
logger = get_logger('intercept.gps') logger = get_logger('intercept.gps')
@@ -231,22 +231,15 @@ def get_satellites():
@gps_bp.route('/stream') @gps_bp.route('/stream')
def stream_gps(): def stream_gps():
"""SSE stream of GPS position and sky updates.""" """SSE stream of GPS position and sky updates."""
def generate() -> Generator[str, None, None]: response = Response(
last_keepalive = time.time() sse_stream_fanout(
keepalive_interval = 30.0 source_queue=_gps_queue,
channel_key='gps',
while True: timeout=1.0,
try: keepalive_interval=30.0,
data = _gps_queue.get(timeout=1) ),
last_keepalive = time.time() mimetype='text/event-stream',
yield format_sse(data) )
except queue.Empty:
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+310 -113
View File
@@ -1,4 +1,4 @@
"""Listening Post routes for radio monitoring and frequency scanning.""" """Receiver routes for radio monitoring and frequency scanning."""
from __future__ import annotations from __future__ import annotations
@@ -9,17 +9,18 @@ import queue
import select import select
import signal import signal
import shutil import shutil
import struct
import subprocess import subprocess
import threading import threading
import time import time
from datetime import datetime from datetime import datetime
from typing import Generator, Optional, List, Dict from typing import Any, Dict, Generator, List, Optional
from flask import Blueprint, jsonify, request, Response from flask import Blueprint, jsonify, request, Response
import app as app_module import app as app_module
from utils.logging import get_logger from utils.logging import get_logger
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.constants import ( from utils.constants import (
SSE_QUEUE_TIMEOUT, SSE_QUEUE_TIMEOUT,
@@ -28,9 +29,9 @@ from utils.constants import (
) )
from utils.sdr import SDRFactory, SDRType from utils.sdr import SDRFactory, SDRType
logger = get_logger('intercept.listening_post') logger = get_logger('intercept.receiver')
listening_post_bp = Blueprint('listening_post', __name__, url_prefix='/listening') receiver_bp = Blueprint('receiver', __name__, url_prefix='/receiver')
# ============================================ # ============================================
# GLOBAL STATE # GLOBAL STATE
@@ -43,6 +44,7 @@ audio_lock = threading.Lock()
audio_running = False audio_running = False
audio_frequency = 0.0 audio_frequency = 0.0
audio_modulation = 'fm' audio_modulation = 'fm'
audio_source = 'process'
# Scanner state # Scanner state
scanner_thread: Optional[threading.Thread] = None scanner_thread: Optional[threading.Thread] = None
@@ -51,7 +53,7 @@ scanner_lock = threading.Lock()
scanner_paused = False scanner_paused = False
scanner_current_freq = 0.0 scanner_current_freq = 0.0
scanner_active_device: Optional[int] = None scanner_active_device: Optional[int] = None
listening_active_device: Optional[int] = None receiver_active_device: Optional[int] = None
scanner_power_process: Optional[subprocess.Popen] = None scanner_power_process: Optional[subprocess.Popen] = None
scanner_config = { scanner_config = {
'start_freq': 88.0, 'start_freq': 88.0,
@@ -119,6 +121,22 @@ def _rtl_fm_demod_mode(modulation: str) -> str:
return 'wbfm' if mod == 'wfm' else mod return 'wbfm' if mod == 'wfm' else mod
def _wav_header(sample_rate: int = 48000, bits_per_sample: int = 16, channels: int = 1) -> bytes:
"""Create a streaming WAV header with unknown data length."""
bytes_per_sample = bits_per_sample // 8
byte_rate = sample_rate * channels * bytes_per_sample
block_align = channels * bytes_per_sample
return (
b'RIFF'
+ struct.pack('<I', 0xFFFFFFFF)
+ b'WAVE'
+ b'fmt '
+ struct.pack('<IHHIIHH', 16, 1, channels, sample_rate, byte_rate, block_align, bits_per_sample)
+ b'data'
+ struct.pack('<I', 0xFFFFFFFF)
)
def add_activity_log(event_type: str, frequency: float, details: str = ''): def add_activity_log(event_type: str, frequency: float, details: str = ''):
@@ -697,8 +715,8 @@ def _start_audio_stream(frequency: float, modulation: str):
] ]
if scanner_config.get('bias_t', False): if scanner_config.get('bias_t', False):
sdr_cmd.append('-T') sdr_cmd.append('-T')
# Explicitly output to stdout (some rtl_fm versions need this) # Omit explicit filename: rtl_fm defaults to stdout.
sdr_cmd.append('-') # (Some builds intermittently stall when '-' is passed explicitly.)
else: else:
# Use SDR abstraction layer for HackRF, Airspy, LimeSDR, SDRPlay # Use SDR abstraction layer for HackRF, Airspy, LimeSDR, SDRPlay
rx_fm_path = find_rx_fm() rx_fm_path = find_rx_fm()
@@ -842,15 +860,15 @@ def _start_audio_stream(frequency: float, modulation: str):
# Pipeline started successfully # Pipeline started successfully
break break
# Validate that audio is producing data quickly # Keep monitor startup tolerant: some demod chains can take
try: # several seconds before producing stream bytes.
ready, _, _ = select.select([audio_process.stdout], [], [], 4.0) if (
if not ready: not audio_process
logger.warning("Audio pipeline produced no data in startup window — killing stalled pipeline") or not audio_rtl_process
_stop_audio_stream_internal() or audio_process.poll() is not None
return or audio_rtl_process.poll() is not None
except Exception as e: ):
logger.warning(f"Audio startup check failed: {e}") logger.warning("Audio pipeline did not remain alive after startup")
_stop_audio_stream_internal() _stop_audio_stream_internal()
return return
@@ -871,11 +889,21 @@ def _stop_audio_stream():
def _stop_audio_stream_internal(): def _stop_audio_stream_internal():
"""Internal stop (must hold lock).""" """Internal stop (must hold lock)."""
global audio_process, audio_rtl_process, audio_running, audio_frequency global audio_process, audio_rtl_process, audio_running, audio_frequency, audio_source
# Set flag first to stop any streaming # Set flag first to stop any streaming
audio_running = False audio_running = False
audio_frequency = 0.0 audio_frequency = 0.0
previous_source = audio_source
audio_source = 'process'
if previous_source == 'waterfall':
try:
from routes.waterfall_websocket import stop_shared_monitor_from_capture
stop_shared_monitor_from_capture()
except Exception:
pass
had_processes = audio_process is not None or audio_rtl_process is not None had_processes = audio_process is not None or audio_rtl_process is not None
@@ -904,16 +932,18 @@ def _stop_audio_stream_internal():
audio_process = None audio_process = None
audio_rtl_process = None audio_rtl_process = None
# Pause for SDR device USB interface to be released by kernel # Brief pause for SDR device USB interface to be released by kernel.
# The _start_audio_stream retry loop handles longer contention windows
# so only a minimal delay is needed here.
if had_processes: if had_processes:
time.sleep(1.0) time.sleep(0.15)
# ============================================ # ============================================
# API ENDPOINTS # API ENDPOINTS
# ============================================ # ============================================
@listening_post_bp.route('/tools') @receiver_bp.route('/tools')
def check_tools() -> Response: def check_tools() -> Response:
"""Check for required tools.""" """Check for required tools."""
rtl_fm = find_rtl_fm() rtl_fm = find_rtl_fm()
@@ -939,10 +969,10 @@ def check_tools() -> Response:
}) })
@listening_post_bp.route('/scanner/start', methods=['POST']) @receiver_bp.route('/scanner/start', methods=['POST'])
def start_scanner() -> Response: def start_scanner() -> Response:
"""Start the frequency scanner.""" """Start the frequency scanner."""
global scanner_thread, scanner_running, scanner_config, scanner_active_device, listening_active_device global scanner_thread, scanner_running, scanner_config, scanner_active_device, receiver_active_device
with scanner_lock: with scanner_lock:
if scanner_running: if scanner_running:
@@ -1008,9 +1038,9 @@ def start_scanner() -> Response:
'message': 'rtl_power not found. Install rtl-sdr tools.' 'message': 'rtl_power not found. Install rtl-sdr tools.'
}), 503 }), 503
# Release listening device if active # Release listening device if active
if listening_active_device is not None: if receiver_active_device is not None:
app_module.release_sdr_device(listening_active_device) app_module.release_sdr_device(receiver_active_device)
listening_active_device = None receiver_active_device = None
# Claim device for scanner # Claim device for scanner
error = app_module.claim_sdr_device(scanner_config['device'], 'scanner') error = app_module.claim_sdr_device(scanner_config['device'], 'scanner')
if error: if error:
@@ -1036,9 +1066,9 @@ def start_scanner() -> Response:
'status': 'error', 'status': 'error',
'message': f'rx_fm not found. Install SoapySDR utilities for {sdr_type}.' 'message': f'rx_fm not found. Install SoapySDR utilities for {sdr_type}.'
}), 503 }), 503
if listening_active_device is not None: if receiver_active_device is not None:
app_module.release_sdr_device(listening_active_device) app_module.release_sdr_device(receiver_active_device)
listening_active_device = None receiver_active_device = None
error = app_module.claim_sdr_device(scanner_config['device'], 'scanner') error = app_module.claim_sdr_device(scanner_config['device'], 'scanner')
if error: if error:
return jsonify({ return jsonify({
@@ -1058,7 +1088,7 @@ def start_scanner() -> Response:
}) })
@listening_post_bp.route('/scanner/stop', methods=['POST']) @receiver_bp.route('/scanner/stop', methods=['POST'])
def stop_scanner() -> Response: def stop_scanner() -> Response:
"""Stop the frequency scanner.""" """Stop the frequency scanner."""
global scanner_running, scanner_active_device, scanner_power_process global scanner_running, scanner_active_device, scanner_power_process
@@ -1082,7 +1112,7 @@ def stop_scanner() -> Response:
return jsonify({'status': 'stopped'}) return jsonify({'status': 'stopped'})
@listening_post_bp.route('/scanner/pause', methods=['POST']) @receiver_bp.route('/scanner/pause', methods=['POST'])
def pause_scanner() -> Response: def pause_scanner() -> Response:
"""Pause/resume the scanner.""" """Pause/resume the scanner."""
global scanner_paused global scanner_paused
@@ -1104,7 +1134,7 @@ def pause_scanner() -> Response:
scanner_skip_signal = False scanner_skip_signal = False
@listening_post_bp.route('/scanner/skip', methods=['POST']) @receiver_bp.route('/scanner/skip', methods=['POST'])
def skip_signal() -> Response: def skip_signal() -> Response:
"""Skip current signal and continue scanning.""" """Skip current signal and continue scanning."""
global scanner_skip_signal global scanner_skip_signal
@@ -1124,7 +1154,7 @@ def skip_signal() -> Response:
}) })
@listening_post_bp.route('/scanner/config', methods=['POST']) @receiver_bp.route('/scanner/config', methods=['POST'])
def update_scanner_config() -> Response: def update_scanner_config() -> Response:
"""Update scanner config while running (step, squelch, gain, dwell).""" """Update scanner config while running (step, squelch, gain, dwell)."""
data = request.json or {} data = request.json or {}
@@ -1166,7 +1196,7 @@ def update_scanner_config() -> Response:
}) })
@listening_post_bp.route('/scanner/status') @receiver_bp.route('/scanner/status')
def scanner_status() -> Response: def scanner_status() -> Response:
"""Get scanner status.""" """Get scanner status."""
return jsonify({ return jsonify({
@@ -1179,34 +1209,28 @@ def scanner_status() -> Response:
}) })
@listening_post_bp.route('/scanner/stream') @receiver_bp.route('/scanner/stream')
def stream_scanner_events() -> Response: def stream_scanner_events() -> Response:
"""SSE stream for scanner events.""" """SSE stream for scanner events."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('receiver_scanner', msg, msg.get('type'))
while True: response = Response(
try: sse_stream_fanout(
msg = scanner_queue.get(timeout=SSE_QUEUE_TIMEOUT) source_queue=scanner_queue,
last_keepalive = time.time() channel_key='receiver_scanner',
try: timeout=SSE_QUEUE_TIMEOUT,
process_event('listening_scanner', msg, msg.get('type')) keepalive_interval=SSE_KEEPALIVE_INTERVAL,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
return response return response
@listening_post_bp.route('/scanner/log') @receiver_bp.route('/scanner/log')
def get_activity_log() -> Response: def get_activity_log() -> Response:
"""Get activity log.""" """Get activity log."""
limit = request.args.get('limit', 100, type=int) limit = request.args.get('limit', 100, type=int)
@@ -1217,7 +1241,7 @@ def get_activity_log() -> Response:
}) })
@listening_post_bp.route('/scanner/log/clear', methods=['POST']) @receiver_bp.route('/scanner/log/clear', methods=['POST'])
def clear_activity_log() -> Response: def clear_activity_log() -> Response:
"""Clear activity log.""" """Clear activity log."""
with activity_log_lock: with activity_log_lock:
@@ -1225,7 +1249,7 @@ def clear_activity_log() -> Response:
return jsonify({'status': 'cleared'}) return jsonify({'status': 'cleared'})
@listening_post_bp.route('/presets') @receiver_bp.route('/presets')
def get_presets() -> Response: def get_presets() -> Response:
"""Get scanner presets.""" """Get scanner presets."""
presets = [ presets = [
@@ -1245,10 +1269,11 @@ def get_presets() -> Response:
# MANUAL AUDIO ENDPOINTS (for direct listening) # MANUAL AUDIO ENDPOINTS (for direct listening)
# ============================================ # ============================================
@listening_post_bp.route('/audio/start', methods=['POST']) @receiver_bp.route('/audio/start', methods=['POST'])
def start_audio() -> Response: def start_audio() -> Response:
"""Start audio at specific frequency (manual mode).""" """Start audio at specific frequency (manual mode)."""
global scanner_running, scanner_active_device, listening_active_device, scanner_power_process, scanner_thread global scanner_running, scanner_active_device, receiver_active_device, scanner_power_process, scanner_thread
global audio_running, audio_frequency, audio_modulation, audio_source
# Stop scanner if running # Stop scanner if running
if scanner_running: if scanner_running:
@@ -1286,6 +1311,11 @@ def start_audio() -> Response:
gain = int(data.get('gain', 40)) gain = int(data.get('gain', 40))
device = int(data.get('device', 0)) device = int(data.get('device', 0))
sdr_type = str(data.get('sdr_type', 'rtlsdr')).lower() sdr_type = str(data.get('sdr_type', 'rtlsdr')).lower()
bias_t_raw = data.get('bias_t', scanner_config.get('bias_t', False))
if isinstance(bias_t_raw, str):
bias_t = bias_t_raw.strip().lower() in {'1', 'true', 'yes', 'on'}
else:
bias_t = bool(bias_t_raw)
except (ValueError, TypeError) as e: except (ValueError, TypeError) as e:
return jsonify({ return jsonify({
'status': 'error', 'status': 'error',
@@ -1310,6 +1340,43 @@ def start_audio() -> Response:
scanner_config['gain'] = gain scanner_config['gain'] = gain
scanner_config['device'] = device scanner_config['device'] = device
scanner_config['sdr_type'] = sdr_type scanner_config['sdr_type'] = sdr_type
scanner_config['bias_t'] = bias_t
# Preferred path: when waterfall WebSocket is active on the same SDR,
# derive monitor audio from that IQ stream instead of spawning rtl_fm.
try:
from routes.waterfall_websocket import (
get_shared_capture_status,
start_shared_monitor_from_capture,
)
shared = get_shared_capture_status()
if shared.get('running') and shared.get('device') == device:
_stop_audio_stream()
ok, msg = start_shared_monitor_from_capture(
device=device,
frequency_mhz=frequency,
modulation=modulation,
squelch=squelch,
)
if ok:
audio_running = True
audio_frequency = frequency
audio_modulation = modulation
audio_source = 'waterfall'
# Shared monitor uses the waterfall's existing SDR claim.
if receiver_active_device is not None:
app_module.release_sdr_device(receiver_active_device)
receiver_active_device = None
return jsonify({
'status': 'started',
'frequency': frequency,
'modulation': modulation,
'source': 'waterfall',
})
logger.warning(f"Shared waterfall monitor unavailable: {msg}")
except Exception as e:
logger.debug(f"Shared waterfall monitor probe failed: {e}")
# Stop waterfall if it's using the same SDR (SSE path) # Stop waterfall if it's using the same SDR (SSE path)
if waterfall_running and waterfall_active_device == device: if waterfall_running and waterfall_active_device == device:
@@ -1320,22 +1387,15 @@ def start_audio() -> Response:
# may still be tearing down its IQ capture process (thread join + # may still be tearing down its IQ capture process (thread join +
# safe_terminate can take several seconds), so we retry with back-off # safe_terminate can take several seconds), so we retry with back-off
# to give the USB device time to be fully released. # to give the USB device time to be fully released.
if listening_active_device is None or listening_active_device != device: if receiver_active_device is None or receiver_active_device != device:
if listening_active_device is not None: if receiver_active_device is not None:
app_module.release_sdr_device(listening_active_device) app_module.release_sdr_device(receiver_active_device)
listening_active_device = None receiver_active_device = None
error = None error = None
max_claim_attempts = 6 max_claim_attempts = 6
for attempt in range(max_claim_attempts): for attempt in range(max_claim_attempts):
# Force-release a stale waterfall registry entry on each error = app_module.claim_sdr_device(device, 'receiver')
# attempt — the WebSocket handler may not have finished
# cleanup yet.
device_status = app_module.get_sdr_device_status()
if device_status.get(device) == 'waterfall':
app_module.release_sdr_device(device)
error = app_module.claim_sdr_device(device, 'listening')
if not error: if not error:
break break
if attempt < max_claim_attempts - 1: if attempt < max_claim_attempts - 1:
@@ -1351,45 +1411,77 @@ def start_audio() -> Response:
'error_type': 'DEVICE_BUSY', 'error_type': 'DEVICE_BUSY',
'message': error 'message': error
}), 409 }), 409
listening_active_device = device receiver_active_device = device
_start_audio_stream(frequency, modulation) _start_audio_stream(frequency, modulation)
if audio_running: if audio_running:
audio_source = 'process'
return jsonify({ return jsonify({
'status': 'started', 'status': 'started',
'frequency': frequency, 'frequency': frequency,
'modulation': modulation 'modulation': modulation,
'source': 'process',
}) })
else: else:
# Avoid leaving a stale device claim after startup failure.
if receiver_active_device is not None:
app_module.release_sdr_device(receiver_active_device)
receiver_active_device = None
start_error = ''
for log_path in ('/tmp/rtl_fm_stderr.log', '/tmp/ffmpeg_stderr.log'):
try:
with open(log_path, 'r') as handle:
content = handle.read().strip()
if content:
start_error = content.splitlines()[-1]
break
except Exception:
continue
message = 'Failed to start audio. Check SDR device.'
if start_error:
message = f'Failed to start audio: {start_error}'
return jsonify({ return jsonify({
'status': 'error', 'status': 'error',
'message': 'Failed to start audio. Check SDR device.' 'message': message
}), 500 }), 500
@listening_post_bp.route('/audio/stop', methods=['POST']) @receiver_bp.route('/audio/stop', methods=['POST'])
def stop_audio() -> Response: def stop_audio() -> Response:
"""Stop audio.""" """Stop audio."""
global listening_active_device global receiver_active_device
_stop_audio_stream() _stop_audio_stream()
if listening_active_device is not None: if receiver_active_device is not None:
app_module.release_sdr_device(listening_active_device) app_module.release_sdr_device(receiver_active_device)
listening_active_device = None receiver_active_device = None
return jsonify({'status': 'stopped'}) return jsonify({'status': 'stopped'})
@listening_post_bp.route('/audio/status') @receiver_bp.route('/audio/status')
def audio_status() -> Response: def audio_status() -> Response:
"""Get audio status.""" """Get audio status."""
running = audio_running
if audio_source == 'waterfall':
try:
from routes.waterfall_websocket import get_shared_capture_status
shared = get_shared_capture_status()
running = bool(shared.get('running') and shared.get('monitor_enabled'))
except Exception:
running = False
return jsonify({ return jsonify({
'running': audio_running, 'running': running,
'frequency': audio_frequency, 'frequency': audio_frequency,
'modulation': audio_modulation 'modulation': audio_modulation,
'source': audio_source,
}) })
@listening_post_bp.route('/audio/debug') @receiver_bp.route('/audio/debug')
def audio_debug() -> Response: def audio_debug() -> Response:
"""Get audio debug status and recent stderr logs.""" """Get audio debug status and recent stderr logs."""
rtl_log_path = '/tmp/rtl_fm_stderr.log' rtl_log_path = '/tmp/rtl_fm_stderr.log'
@@ -1403,26 +1495,51 @@ def audio_debug() -> Response:
except Exception: except Exception:
return '' return ''
shared = {}
if audio_source == 'waterfall':
try:
from routes.waterfall_websocket import get_shared_capture_status
shared = get_shared_capture_status()
except Exception:
shared = {}
return jsonify({ return jsonify({
'running': audio_running, 'running': audio_running,
'frequency': audio_frequency, 'frequency': audio_frequency,
'modulation': audio_modulation, 'modulation': audio_modulation,
'source': audio_source,
'sdr_type': scanner_config.get('sdr_type', 'rtlsdr'), 'sdr_type': scanner_config.get('sdr_type', 'rtlsdr'),
'device': scanner_config.get('device', 0), 'device': scanner_config.get('device', 0),
'gain': scanner_config.get('gain', 0), 'gain': scanner_config.get('gain', 0),
'squelch': scanner_config.get('squelch', 0), 'squelch': scanner_config.get('squelch', 0),
'audio_process_alive': bool(audio_process and audio_process.poll() is None), 'audio_process_alive': bool(audio_process and audio_process.poll() is None),
'shared_capture': shared,
'rtl_fm_stderr': _read_log(rtl_log_path), 'rtl_fm_stderr': _read_log(rtl_log_path),
'ffmpeg_stderr': _read_log(ffmpeg_log_path), 'ffmpeg_stderr': _read_log(ffmpeg_log_path),
'audio_probe_bytes': os.path.getsize(sample_path) if os.path.exists(sample_path) else 0, 'audio_probe_bytes': os.path.getsize(sample_path) if os.path.exists(sample_path) else 0,
}) })
@listening_post_bp.route('/audio/probe') @receiver_bp.route('/audio/probe')
def audio_probe() -> Response: def audio_probe() -> Response:
"""Grab a small chunk of audio bytes from the pipeline for debugging.""" """Grab a small chunk of audio bytes from the pipeline for debugging."""
global audio_process global audio_process
if audio_source == 'waterfall':
try:
from routes.waterfall_websocket import read_shared_monitor_audio_chunk
data = read_shared_monitor_audio_chunk(timeout=2.0)
if not data:
return jsonify({'status': 'error', 'message': 'no shared audio data available'}), 504
sample_path = '/tmp/audio_probe.bin'
with open(sample_path, 'wb') as handle:
handle.write(data)
return jsonify({'status': 'ok', 'bytes': len(data), 'source': 'waterfall'})
except Exception as e:
return jsonify({'status': 'error', 'message': str(e)}), 500
if not audio_process or not audio_process.stdout: if not audio_process or not audio_process.stdout:
return jsonify({'status': 'error', 'message': 'audio process not running'}), 400 return jsonify({'status': 'error', 'message': 'audio process not running'}), 400
@@ -1444,17 +1561,61 @@ def audio_probe() -> Response:
return jsonify({'status': 'ok', 'bytes': size}) return jsonify({'status': 'ok', 'bytes': size})
@listening_post_bp.route('/audio/stream') @receiver_bp.route('/audio/stream')
def stream_audio() -> Response: def stream_audio() -> Response:
"""Stream WAV audio.""" """Stream WAV audio."""
# Wait for audio to be ready (up to 2 seconds for modulation/squelch changes) if audio_source == 'waterfall':
for _ in range(40):
if audio_running:
break
time.sleep(0.05)
if not audio_running:
return Response(b'', mimetype='audio/wav', status=204)
def generate_shared():
global audio_running, audio_source
try:
from routes.waterfall_websocket import (
get_shared_capture_status,
read_shared_monitor_audio_chunk,
)
except Exception:
return
# Browser expects an immediate WAV header.
yield _wav_header(sample_rate=48000)
while audio_running and audio_source == 'waterfall':
chunk = read_shared_monitor_audio_chunk(timeout=1.0)
if chunk:
yield chunk
continue
shared = get_shared_capture_status()
if not shared.get('running') or not shared.get('monitor_enabled'):
audio_running = False
audio_source = 'process'
break
return Response(
generate_shared(),
mimetype='audio/wav',
headers={
'Content-Type': 'audio/wav',
'Cache-Control': 'no-cache, no-store',
'X-Accel-Buffering': 'no',
'Transfer-Encoding': 'chunked',
}
)
# Wait for audio process to be ready (up to 2 seconds).
for _ in range(40): for _ in range(40):
if audio_running and audio_process: if audio_running and audio_process:
break break
time.sleep(0.05) time.sleep(0.05)
if not audio_running or not audio_process: if not audio_running or not audio_process:
return Response(b'', mimetype='audio/mpeg', status=204) return Response(b'', mimetype='audio/wav', status=204)
def generate(): def generate():
# Capture local reference to avoid race condition with stop # Capture local reference to avoid race condition with stop
@@ -1480,21 +1641,25 @@ def stream_audio() -> Response:
yield header_chunk yield header_chunk
# Stream real-time audio # Stream real-time audio
first_chunk_deadline = time.time() + 3.0 first_chunk_deadline = time.time() + 20.0
warned_wait = False
while audio_running and proc.poll() is None: while audio_running and proc.poll() is None:
# Use select to avoid blocking forever # Use select to avoid blocking forever
ready, _, _ = select.select([proc.stdout], [], [], 2.0) ready, _, _ = select.select([proc.stdout], [], [], 2.0)
if ready: if ready:
chunk = proc.stdout.read(8192) chunk = proc.stdout.read(8192)
if chunk: if chunk:
warned_wait = False
yield chunk yield chunk
else: else:
break break
else: else:
# If no data arrives shortly after start, exit so caller can retry # Keep connection open while demodulator settles.
if time.time() > first_chunk_deadline: if time.time() > first_chunk_deadline:
logger.warning("Audio stream timed out waiting for first chunk") if not warned_wait:
break logger.warning("Audio stream still waiting for first chunk")
warned_wait = True
continue
# Timeout - check if process died # Timeout - check if process died
if proc.poll() is not None: if proc.poll() is not None:
break break
@@ -1519,7 +1684,7 @@ def stream_audio() -> Response:
# SIGNAL IDENTIFICATION ENDPOINT # SIGNAL IDENTIFICATION ENDPOINT
# ============================================ # ============================================
@listening_post_bp.route('/signal/guess', methods=['POST']) @receiver_bp.route('/signal/guess', methods=['POST'])
def guess_signal() -> Response: def guess_signal() -> Response:
"""Identify a signal based on frequency, modulation, and other parameters.""" """Identify a signal based on frequency, modulation, and other parameters."""
data = request.json or {} data = request.json or {}
@@ -1627,9 +1792,20 @@ def _waterfall_loop():
"""Continuous rtl_power sweep loop emitting waterfall data.""" """Continuous rtl_power sweep loop emitting waterfall data."""
global waterfall_running, waterfall_process global waterfall_running, waterfall_process
def _queue_waterfall_error(message: str) -> None:
try:
waterfall_queue.put_nowait({
'type': 'waterfall_error',
'message': message,
'timestamp': datetime.now().isoformat(),
})
except queue.Full:
pass
rtl_power_path = find_rtl_power() rtl_power_path = find_rtl_power()
if not rtl_power_path: if not rtl_power_path:
logger.error("rtl_power not found for waterfall") logger.error("rtl_power not found for waterfall")
_queue_waterfall_error('rtl_power not found')
waterfall_running = False waterfall_running = False
return return
@@ -1652,17 +1828,33 @@ def _waterfall_loop():
waterfall_process = subprocess.Popen( waterfall_process = subprocess.Popen(
cmd, cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, stderr=subprocess.PIPE,
bufsize=1, bufsize=1,
text=True, text=True,
) )
# Detect immediate startup failures (e.g. device busy / no device).
time.sleep(0.35)
if waterfall_process.poll() is not None:
stderr_text = ''
try:
if waterfall_process.stderr:
stderr_text = waterfall_process.stderr.read().strip()
except Exception:
stderr_text = ''
msg = stderr_text or f'rtl_power exited early (code {waterfall_process.returncode})'
logger.error(f"Waterfall startup failed: {msg}")
_queue_waterfall_error(msg)
return
current_ts = None current_ts = None
all_bins: list[float] = [] all_bins: list[float] = []
sweep_start_hz = start_hz sweep_start_hz = start_hz
sweep_end_hz = end_hz sweep_end_hz = end_hz
received_any = False
if not waterfall_process.stdout: if not waterfall_process.stdout:
_queue_waterfall_error('rtl_power stdout unavailable')
return return
for line in waterfall_process.stdout: for line in waterfall_process.stdout:
@@ -1672,6 +1864,7 @@ def _waterfall_loop():
ts, seg_start, seg_end, bins = _parse_rtl_power_line(line) ts, seg_start, seg_end, bins = _parse_rtl_power_line(line)
if ts is None or not bins: if ts is None or not bins:
continue continue
received_any = True
if current_ts is None: if current_ts is None:
current_ts = ts current_ts = ts
@@ -1729,8 +1922,12 @@ def _waterfall_loop():
except queue.Full: except queue.Full:
pass pass
if waterfall_running and not received_any:
_queue_waterfall_error('No waterfall FFT data received from rtl_power')
except Exception as e: except Exception as e:
logger.error(f"Waterfall loop error: {e}") logger.error(f"Waterfall loop error: {e}")
_queue_waterfall_error(f"Waterfall loop error: {e}")
finally: finally:
waterfall_running = False waterfall_running = False
if waterfall_process and waterfall_process.poll() is None: if waterfall_process and waterfall_process.poll() is None:
@@ -1767,14 +1964,19 @@ def _stop_waterfall_internal() -> None:
waterfall_active_device = None waterfall_active_device = None
@listening_post_bp.route('/waterfall/start', methods=['POST']) @receiver_bp.route('/waterfall/start', methods=['POST'])
def start_waterfall() -> Response: def start_waterfall() -> Response:
"""Start the waterfall/spectrogram display.""" """Start the waterfall/spectrogram display."""
global waterfall_thread, waterfall_running, waterfall_config, waterfall_active_device global waterfall_thread, waterfall_running, waterfall_config, waterfall_active_device
with waterfall_lock: with waterfall_lock:
if waterfall_running: if waterfall_running:
return jsonify({'status': 'error', 'message': 'Waterfall already running'}), 409 return jsonify({
'status': 'started',
'already_running': True,
'message': 'Waterfall already running',
'config': waterfall_config,
})
if not find_rtl_power(): if not find_rtl_power():
return jsonify({'status': 'error', 'message': 'rtl_power not found'}), 503 return jsonify({'status': 'error', 'message': 'rtl_power not found'}), 503
@@ -1823,7 +2025,7 @@ def start_waterfall() -> Response:
return jsonify({'status': 'started', 'config': waterfall_config}) return jsonify({'status': 'started', 'config': waterfall_config})
@listening_post_bp.route('/waterfall/stop', methods=['POST']) @receiver_bp.route('/waterfall/stop', methods=['POST'])
def stop_waterfall() -> Response: def stop_waterfall() -> Response:
"""Stop the waterfall display.""" """Stop the waterfall display."""
_stop_waterfall_internal() _stop_waterfall_internal()
@@ -1831,27 +2033,22 @@ def stop_waterfall() -> Response:
return jsonify({'status': 'stopped'}) return jsonify({'status': 'stopped'})
@listening_post_bp.route('/waterfall/stream') @receiver_bp.route('/waterfall/stream')
def stream_waterfall() -> Response: def stream_waterfall() -> Response:
"""SSE stream for waterfall data.""" """SSE stream for waterfall data."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('waterfall', msg, msg.get('type'))
while True:
try:
msg = waterfall_queue.get(timeout=SSE_QUEUE_TIMEOUT)
last_keepalive = time.time()
try:
process_event('waterfall', msg, msg.get('type'))
except Exception:
pass
yield format_sse(msg)
except queue.Empty:
now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream') response = Response(
sse_stream_fanout(
source_queue=waterfall_queue,
channel_key='receiver_waterfall',
timeout=SSE_QUEUE_TIMEOUT,
keepalive_interval=SSE_KEEPALIVE_INTERVAL,
on_message=_on_msg,
),
mimetype='text/event-stream',
)
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
return response return response
+26 -17
View File
@@ -17,7 +17,7 @@ from typing import Generator
from flask import Blueprint, jsonify, request, Response from flask import Blueprint, jsonify, request, Response
from utils.logging import get_logger from utils.logging import get_logger
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.meshtastic import ( from utils.meshtastic import (
get_meshtastic_client, get_meshtastic_client,
start_meshtastic, start_meshtastic,
@@ -469,22 +469,15 @@ def stream_messages():
Returns: Returns:
SSE stream (text/event-stream) SSE stream (text/event-stream)
""" """
def generate() -> Generator[str, None, None]: response = Response(
last_keepalive = time.time() sse_stream_fanout(
keepalive_interval = 30.0 source_queue=_mesh_queue,
channel_key='meshtastic',
while True: timeout=1.0,
try: keepalive_interval=30.0,
msg = _mesh_queue.get(timeout=1) ),
last_keepalive = time.time() mimetype='text/event-stream',
yield format_sse(msg) )
except queue.Empty:
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
@@ -1051,3 +1044,19 @@ def request_store_forward():
'status': 'error', 'status': 'error',
'message': error or 'Failed to request S&F history' 'message': error or 'Failed to request S&F history'
}), 500 }), 500
@meshtastic_bp.route('/topology')
def mesh_topology():
"""Return mesh network topology graph."""
if not is_meshtastic_available():
return jsonify({'status': 'error', 'message': 'Meshtastic SDK not installed'}), 400
client = get_meshtastic_client()
if not client or not client.is_running:
return jsonify({'status': 'error', 'message': 'Not connected'}), 400
return jsonify({
'status': 'success',
'topology': client.get_topology(),
})
+3 -2
View File
@@ -11,8 +11,9 @@ offline_bp = Blueprint('offline', __name__, url_prefix='/offline')
# Default offline settings # Default offline settings
OFFLINE_DEFAULTS = { OFFLINE_DEFAULTS = {
'offline.enabled': False, 'offline.enabled': False,
'offline.assets_source': 'cdn', # Default to bundled assets/fonts to avoid third-party CDN privacy blocks.
'offline.fonts_source': 'cdn', 'offline.assets_source': 'local',
'offline.fonts_source': 'local',
'offline.tile_provider': 'cartodb_dark_cyan', 'offline.tile_provider': 'cartodb_dark_cyan',
'offline.tile_server_url': '' 'offline.tile_server_url': ''
} }
+29 -23
View File
@@ -24,7 +24,7 @@ from utils.validation import (
validate_frequency, validate_device_index, validate_gain, validate_ppm, validate_frequency, validate_device_index, validate_gain, validate_ppm,
validate_rtl_tcp_host, validate_rtl_tcp_port validate_rtl_tcp_host, validate_rtl_tcp_port
) )
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.process import safe_terminate, register_process, unregister_process from utils.process import safe_terminate, register_process, unregister_process
from utils.sdr import SDRFactory, SDRType, SDRValidationError from utils.sdr import SDRFactory, SDRType, SDRValidationError
@@ -108,6 +108,20 @@ def log_message(msg: dict[str, Any]) -> None:
logger.error(f"Failed to log message: {e}") logger.error(f"Failed to log message: {e}")
def _encode_scope_waveform(samples: tuple[int, ...], window_size: int = 256) -> list[int]:
"""Compress recent PCM samples into a signed 8-bit waveform for SSE."""
if not samples:
return []
window = samples[-window_size:] if len(samples) > window_size else samples
waveform: list[int] = []
for sample in window:
# Convert int16 PCM to int8 range for lightweight transport.
packed = int(round(sample / 256))
waveform.append(max(-127, min(127, packed)))
return waveform
def audio_relay_thread( def audio_relay_thread(
rtl_stdout, rtl_stdout,
multimon_stdin, multimon_stdin,
@@ -118,7 +132,7 @@ def audio_relay_thread(
Reads raw 16-bit LE PCM from *rtl_stdout*, writes every chunk straight Reads raw 16-bit LE PCM from *rtl_stdout*, writes every chunk straight
through to *multimon_stdin*, and every ~100 ms pushes an RMS / peak scope through to *multimon_stdin*, and every ~100 ms pushes an RMS / peak scope
event onto *output_queue*. event plus a compact waveform sample onto *output_queue*.
""" """
CHUNK = 4096 # bytes 2048 samples at 16-bit mono CHUNK = 4096 # bytes 2048 samples at 16-bit mono
INTERVAL = 0.1 # seconds between scope updates INTERVAL = 0.1 # seconds between scope updates
@@ -152,6 +166,7 @@ def audio_relay_thread(
'type': 'scope', 'type': 'scope',
'rms': rms, 'rms': rms,
'peak': peak, 'peak': peak,
'waveform': _encode_scope_waveform(samples),
}) })
except (struct.error, ValueError, queue.Full): except (struct.error, ValueError, queue.Full):
pass pass
@@ -540,28 +555,19 @@ def toggle_logging() -> Response:
@pager_bp.route('/stream') @pager_bp.route('/stream')
def stream() -> Response: def stream() -> Response:
import json def _on_msg(msg: dict[str, Any]) -> None:
process_event('pager', msg, msg.get('type'))
def generate() -> Generator[str, None, None]: response = Response(
last_keepalive = time.time() sse_stream_fanout(
keepalive_interval = 30.0 # Send keepalive every 30 seconds instead of 1 second source_queue=app_module.output_queue,
channel_key='pager',
while True: timeout=1.0,
try: keepalive_interval=30.0,
msg = app_module.output_queue.get(timeout=1) on_message=_on_msg,
last_keepalive = time.time() ),
try: mimetype='text/event-stream',
process_event('pager', msg, msg.get('type')) )
except Exception:
pass
yield format_sse(msg)
except queue.Empty:
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+57
View File
@@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import json
from pathlib import Path from pathlib import Path
from flask import Blueprint, jsonify, request, send_file from flask import Blueprint, jsonify, request, send_file
@@ -107,3 +108,59 @@ def download_recording(session_id: str):
as_attachment=True, as_attachment=True,
download_name=file_path.name, download_name=file_path.name,
) )
@recordings_bp.route('/<session_id>/events', methods=['GET'])
def get_recording_events(session_id: str):
"""Return parsed events from a recording for in-app replay."""
manager = get_recording_manager()
rec = manager.get_recording(session_id)
if not rec:
return jsonify({'status': 'error', 'message': 'Recording not found'}), 404
file_path = Path(rec['file_path'])
try:
resolved_root = RECORDING_ROOT.resolve()
resolved_file = file_path.resolve()
if resolved_root not in resolved_file.parents:
return jsonify({'status': 'error', 'message': 'Invalid recording path'}), 400
except Exception:
return jsonify({'status': 'error', 'message': 'Invalid recording path'}), 400
if not file_path.exists():
return jsonify({'status': 'error', 'message': 'Recording file missing'}), 404
limit = max(1, min(5000, request.args.get('limit', default=500, type=int)))
offset = max(0, request.args.get('offset', default=0, type=int))
events: list[dict] = []
seen = 0
with file_path.open('r', encoding='utf-8', errors='replace') as fh:
for idx, line in enumerate(fh):
if idx < offset:
continue
if seen >= limit:
break
line = line.strip()
if not line:
continue
try:
events.append(json.loads(line))
seen += 1
except json.JSONDecodeError:
continue
return jsonify({
'status': 'success',
'recording': {
'id': rec['id'],
'mode': rec['mode'],
'started_at': rec['started_at'],
'stopped_at': rec['stopped_at'],
'event_count': rec['event_count'],
},
'offset': offset,
'limit': limit,
'returned': len(events),
'events': events,
})
+13 -20
View File
@@ -17,7 +17,7 @@ from utils.logging import sensor_logger as logger
from utils.validation import ( from utils.validation import (
validate_frequency, validate_device_index, validate_gain, validate_ppm validate_frequency, validate_device_index, validate_gain, validate_ppm
) )
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.process import safe_terminate, register_process, unregister_process from utils.process import safe_terminate, register_process, unregister_process
@@ -288,26 +288,19 @@ def stop_rtlamr() -> Response:
@rtlamr_bp.route('/stream_rtlamr') @rtlamr_bp.route('/stream_rtlamr')
def stream_rtlamr() -> Response: def stream_rtlamr() -> Response:
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('rtlamr', msg, msg.get('type'))
keepalive_interval = 30.0
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.rtlamr_queue.get(timeout=1) source_queue=app_module.rtlamr_queue,
last_keepalive = time.time() channel_key='rtlamr',
try: timeout=1.0,
process_event('rtlamr', msg, msg.get('type')) keepalive_interval=30.0,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+36 -7
View File
@@ -166,9 +166,11 @@ def _fetch_iss_realtime(observer_lat: Optional[float] = None, observer_lon: Opti
@satellite_bp.route('/dashboard') @satellite_bp.route('/dashboard')
def satellite_dashboard(): def satellite_dashboard():
"""Popout satellite tracking dashboard.""" """Popout satellite tracking dashboard."""
embedded = request.args.get('embedded', 'false') == 'true'
return render_template( return render_template(
'satellite_dashboard.html', 'satellite_dashboard.html',
shared_observer_location=SHARED_OBSERVER_LOCATION_ENABLED, shared_observer_location=SHARED_OBSERVER_LOCATION_ENABLED,
embedded=embedded,
) )
@@ -588,14 +590,14 @@ def list_tracked_satellites():
def add_tracked_satellites_endpoint(): def add_tracked_satellites_endpoint():
"""Add one or more tracked satellites.""" """Add one or more tracked satellites."""
global _tle_cache global _tle_cache
data = request.json data = request.get_json(silent=True)
if not data: if not data:
return jsonify({'status': 'error', 'message': 'No data provided'}), 400 return jsonify({'status': 'error', 'message': 'No data provided'}), 400
# Accept a single satellite dict or a list # Accept a single satellite dict or a list
sat_list = data if isinstance(data, list) else [data] sat_list = data if isinstance(data, list) else [data]
added = 0 normalized: list[dict] = []
for sat in sat_list: for sat in sat_list:
norad_id = str(sat.get('norad_id', sat.get('norad', ''))) norad_id = str(sat.get('norad_id', sat.get('norad', '')))
name = sat.get('name', '') name = sat.get('name', '')
@@ -605,19 +607,46 @@ def add_tracked_satellites_endpoint():
tle2 = sat.get('tle_line2', sat.get('tle2')) tle2 = sat.get('tle_line2', sat.get('tle2'))
enabled = sat.get('enabled', True) enabled = sat.get('enabled', True)
if add_tracked_satellite(norad_id, name, tle1, tle2, enabled): normalized.append({
added += 1 'norad_id': norad_id,
'name': name,
'tle_line1': tle1,
'tle_line2': tle2,
'enabled': bool(enabled),
'builtin': False,
})
# Also inject into TLE cache if we have TLE data # Also inject into TLE cache if we have TLE data
if tle1 and tle2: if tle1 and tle2:
cache_key = name.replace(' ', '-').upper() cache_key = name.replace(' ', '-').upper()
_tle_cache[cache_key] = (name, tle1, tle2) _tle_cache[cache_key] = (name, tle1, tle2)
return jsonify({ # Single inserts preserve previous behavior; list inserts use DB-level bulk path.
if len(normalized) == 1:
sat = normalized[0]
added = 1 if add_tracked_satellite(
sat['norad_id'],
sat['name'],
sat.get('tle_line1'),
sat.get('tle_line2'),
sat.get('enabled', True),
sat.get('builtin', False),
) else 0
else:
added = bulk_add_tracked_satellites(normalized)
response_payload = {
'status': 'success', 'status': 'success',
'added': added, 'added': added,
'satellites': get_tracked_satellites(), 'processed': len(normalized),
}) }
# Returning all tracked satellites for very large imports can stall the UI.
include_satellites = request.args.get('include_satellites', '').lower() == 'true'
if include_satellites or len(normalized) <= 32:
response_payload['satellites'] = get_tracked_satellites()
return jsonify(response_payload)
@satellite_bp.route('/tracked/<norad_id>', methods=['PUT']) @satellite_bp.route('/tracked/<norad_id>', methods=['PUT'])
+81 -25
View File
@@ -3,12 +3,13 @@
from __future__ import annotations from __future__ import annotations
import json import json
import math
import queue import queue
import subprocess import subprocess
import threading import threading
import time import time
from datetime import datetime from datetime import datetime
from typing import Generator from typing import Any, Generator
from flask import Blueprint, jsonify, request, Response from flask import Blueprint, jsonify, request, Response
@@ -18,7 +19,7 @@ from utils.validation import (
validate_frequency, validate_device_index, validate_gain, validate_ppm, validate_frequency, validate_device_index, validate_gain, validate_ppm,
validate_rtl_tcp_host, validate_rtl_tcp_port validate_rtl_tcp_host, validate_rtl_tcp_port
) )
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.process import safe_terminate, register_process, unregister_process from utils.process import safe_terminate, register_process, unregister_process
from utils.sdr import SDRFactory, SDRType from utils.sdr import SDRFactory, SDRType
@@ -28,6 +29,40 @@ sensor_bp = Blueprint('sensor', __name__)
# Track which device is being used # Track which device is being used
sensor_active_device: int | None = None sensor_active_device: int | None = None
# RSSI history per device (model_id -> list of (timestamp, rssi))
sensor_rssi_history: dict[str, list[tuple[float, float]]] = {}
_MAX_RSSI_HISTORY = 60
def _build_scope_waveform(rssi: float, snr: float, noise: float, points: int = 256) -> list[int]:
"""Synthesize a compact waveform from rtl_433 level metrics."""
points = max(32, min(points, 512))
# rssi is usually negative; stronger signals are closer to 0 dBm.
rssi_norm = min(max(abs(rssi) / 40.0, 0.0), 1.0)
snr_norm = min(max((snr + 5.0) / 35.0, 0.0), 1.0)
noise_norm = min(max(abs(noise) / 40.0, 0.0), 1.0)
amplitude = max(0.06, min(1.0, (0.6 * rssi_norm + 0.4 * snr_norm) - (0.22 * noise_norm)))
cycles = 3.0 + (snr_norm * 8.0)
harmonic = 0.25 + (0.35 * snr_norm)
hiss = 0.08 + (0.18 * noise_norm)
phase = (time.monotonic() * (1.4 + (snr_norm * 2.2))) % (2.0 * math.pi)
waveform: list[int] = []
for i in range(points):
t = i / (points - 1)
base = math.sin((2.0 * math.pi * cycles * t) + phase)
overtone = math.sin((2.0 * math.pi * (cycles * 2.4) * t) + (phase * 0.7))
noise_wobble = math.sin((2.0 * math.pi * (cycles * 7.0) * t) + (phase * 2.1))
sample = amplitude * (base + (harmonic * overtone) + (hiss * noise_wobble))
sample /= (1.0 + harmonic + hiss)
packed = int(round(max(-1.0, min(1.0, sample)) * 127.0))
waveform.append(max(-127, min(127, packed)))
return waveform
def stream_sensor_output(process: subprocess.Popen[bytes]) -> None: def stream_sensor_output(process: subprocess.Popen[bytes]) -> None:
"""Stream rtl_433 JSON output to queue.""" """Stream rtl_433 JSON output to queue."""
@@ -45,19 +80,38 @@ def stream_sensor_output(process: subprocess.Popen[bytes]) -> None:
data['type'] = 'sensor' data['type'] = 'sensor'
app_module.sensor_queue.put(data) app_module.sensor_queue.put(data)
# Track RSSI history per device
_model = data.get('model', '')
_dev_id = data.get('id', '')
_rssi_val = data.get('rssi')
if _rssi_val is not None and _model:
_hist_key = f"{_model}_{_dev_id}"
hist = sensor_rssi_history.setdefault(_hist_key, [])
hist.append((time.time(), float(_rssi_val)))
if len(hist) > _MAX_RSSI_HISTORY:
del hist[: len(hist) - _MAX_RSSI_HISTORY]
# Push scope event when signal level data is present # Push scope event when signal level data is present
rssi = data.get('rssi') rssi = data.get('rssi')
snr = data.get('snr') snr = data.get('snr')
noise = data.get('noise') noise = data.get('noise')
if rssi is not None or snr is not None: if rssi is not None or snr is not None:
try: try:
rssi_value = float(rssi) if rssi is not None else 0.0
snr_value = float(snr) if snr is not None else 0.0
noise_value = float(noise) if noise is not None else 0.0
app_module.sensor_queue.put_nowait({ app_module.sensor_queue.put_nowait({
'type': 'scope', 'type': 'scope',
'rssi': rssi if rssi is not None else 0, 'rssi': rssi_value,
'snr': snr if snr is not None else 0, 'snr': snr_value,
'noise': noise if noise is not None else 0, 'noise': noise_value,
'waveform': _build_scope_waveform(
rssi=rssi_value,
snr=snr_value,
noise=noise_value,
),
}) })
except queue.Full: except (TypeError, ValueError, queue.Full):
pass pass
# Log if enabled # Log if enabled
@@ -259,27 +313,29 @@ def stop_sensor() -> Response:
@sensor_bp.route('/stream_sensor') @sensor_bp.route('/stream_sensor')
def stream_sensor() -> Response: def stream_sensor() -> Response:
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('sensor', msg, msg.get('type'))
keepalive_interval = 30.0
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.sensor_queue.get(timeout=1) source_queue=app_module.sensor_queue,
last_keepalive = time.time() channel_key='sensor',
try: timeout=1.0,
process_event('sensor', msg, msg.get('type')) keepalive_interval=30.0,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
return response return response
@sensor_bp.route('/sensor/rssi_history')
def get_rssi_history() -> Response:
"""Return RSSI history for all tracked sensor devices."""
result = {}
for key, entries in sensor_rssi_history.items():
result[key] = [{'t': round(t, 1), 'rssi': rssi} for t, rssi in entries]
return jsonify({'status': 'success', 'devices': result})
+352
View File
@@ -0,0 +1,352 @@
"""Signal identification enrichment routes (SigID Wiki proxy lookup)."""
from __future__ import annotations
import json
import time
import urllib.parse
import urllib.request
from typing import Any
from flask import Blueprint, Response, jsonify, request
from utils.logging import get_logger
logger = get_logger('intercept.signalid')
signalid_bp = Blueprint('signalid', __name__, url_prefix='/signalid')
SIGID_API_URL = 'https://www.sigidwiki.com/api.php'
SIGID_USER_AGENT = 'INTERCEPT-SignalID/1.0'
SIGID_TIMEOUT_SECONDS = 12
SIGID_CACHE_TTL_SECONDS = 600
_cache: dict[str, dict[str, Any]] = {}
def _cache_get(key: str) -> Any | None:
entry = _cache.get(key)
if not entry:
return None
if time.time() >= entry['expires']:
_cache.pop(key, None)
return None
return entry['data']
def _cache_set(key: str, data: Any, ttl_seconds: int = SIGID_CACHE_TTL_SECONDS) -> None:
_cache[key] = {
'data': data,
'expires': time.time() + ttl_seconds,
}
def _fetch_api_json(params: dict[str, str]) -> dict[str, Any] | None:
query = urllib.parse.urlencode(params, doseq=True)
url = f'{SIGID_API_URL}?{query}'
req = urllib.request.Request(url, headers={'User-Agent': SIGID_USER_AGENT})
try:
with urllib.request.urlopen(req, timeout=SIGID_TIMEOUT_SECONDS) as resp:
payload = resp.read().decode('utf-8', errors='replace')
data = json.loads(payload)
except Exception as exc:
logger.warning('SigID API request failed: %s', exc)
return None
if isinstance(data, dict) and data.get('error'):
logger.warning('SigID API returned error: %s', data.get('error'))
return None
return data if isinstance(data, dict) else None
def _ask_query(query: str) -> dict[str, Any] | None:
return _fetch_api_json({
'action': 'ask',
'query': query,
'format': 'json',
})
def _search_query(search_text: str, limit: int) -> dict[str, Any] | None:
return _fetch_api_json({
'action': 'query',
'list': 'search',
'srsearch': search_text,
'srlimit': str(limit),
'format': 'json',
})
def _to_float_list(values: Any) -> list[float]:
if not isinstance(values, list):
return []
out: list[float] = []
for value in values:
try:
out.append(float(value))
except (TypeError, ValueError):
continue
return out
def _to_text_list(values: Any) -> list[str]:
if not isinstance(values, list):
return []
out: list[str] = []
for value in values:
text = str(value or '').strip()
if text:
out.append(text)
return out
def _normalize_modes(values: list[str]) -> list[str]:
out: list[str] = []
for value in values:
for token in str(value).replace('/', ',').split(','):
mode = token.strip().upper()
if mode and mode not in out:
out.append(mode)
return out
def _extract_matches_from_ask(data: dict[str, Any]) -> list[dict[str, Any]]:
results = data.get('query', {}).get('results', {})
if not isinstance(results, dict):
return []
matches: list[dict[str, Any]] = []
for title, entry in results.items():
if not isinstance(entry, dict):
continue
printouts = entry.get('printouts', {})
if not isinstance(printouts, dict):
printouts = {}
frequencies_hz = _to_float_list(printouts.get('Frequencies'))
frequencies_mhz = [round(v / 1e6, 6) for v in frequencies_hz if v > 0]
modes = _normalize_modes(_to_text_list(printouts.get('Mode')))
modulations = _normalize_modes(_to_text_list(printouts.get('Modulation')))
match = {
'title': str(entry.get('fulltext') or title),
'url': str(entry.get('fullurl') or ''),
'frequencies_mhz': frequencies_mhz,
'modes': modes,
'modulations': modulations,
'source': 'SigID Wiki',
}
matches.append(match)
return matches
def _dedupe_matches(matches: list[dict[str, Any]]) -> list[dict[str, Any]]:
deduped: dict[str, dict[str, Any]] = {}
for match in matches:
key = f"{match.get('title', '')}|{match.get('url', '')}"
if key not in deduped:
deduped[key] = match
continue
# Merge frequencies/modes/modulations from duplicates.
existing = deduped[key]
for field in ('frequencies_mhz', 'modes', 'modulations'):
base = existing.get(field, [])
extra = match.get(field, [])
if not isinstance(base, list):
base = []
if not isinstance(extra, list):
extra = []
merged = list(base)
for item in extra:
if item not in merged:
merged.append(item)
existing[field] = merged
return list(deduped.values())
def _rank_matches(
matches: list[dict[str, Any]],
*,
frequency_mhz: float,
modulation: str,
) -> list[dict[str, Any]]:
target_hz = frequency_mhz * 1e6
wanted_mod = str(modulation or '').strip().upper()
def score(match: dict[str, Any]) -> tuple[int, float, str]:
score_value = 0
freqs_mhz = match.get('frequencies_mhz') or []
distances_hz: list[float] = []
for f_mhz in freqs_mhz:
try:
distances_hz.append(abs((float(f_mhz) * 1e6) - target_hz))
except (TypeError, ValueError):
continue
min_distance_hz = min(distances_hz) if distances_hz else 1e12
if min_distance_hz <= 100:
score_value += 120
elif min_distance_hz <= 1_000:
score_value += 90
elif min_distance_hz <= 10_000:
score_value += 70
elif min_distance_hz <= 100_000:
score_value += 40
if wanted_mod:
modes = [str(v).upper() for v in (match.get('modes') or [])]
modulations = [str(v).upper() for v in (match.get('modulations') or [])]
if wanted_mod in modes:
score_value += 25
if wanted_mod in modulations:
score_value += 25
title = str(match.get('title') or '')
title_lower = title.lower()
if 'unidentified' in title_lower or 'unknown' in title_lower:
score_value -= 10
return (score_value, min_distance_hz, title.lower())
ranked = sorted(matches, key=score, reverse=True)
for match in ranked:
try:
nearest = min(abs((float(f) * 1e6) - target_hz) for f in (match.get('frequencies_mhz') or []))
match['distance_hz'] = int(round(nearest))
except Exception:
match['distance_hz'] = None
return ranked
def _format_freq_variants_mhz(freq_mhz: float) -> list[str]:
variants = [
f'{freq_mhz:.6f}'.rstrip('0').rstrip('.'),
f'{freq_mhz:.4f}'.rstrip('0').rstrip('.'),
f'{freq_mhz:.3f}'.rstrip('0').rstrip('.'),
]
out: list[str] = []
for value in variants:
if value and value not in out:
out.append(value)
return out
def _lookup_sigidwiki_matches(frequency_mhz: float, modulation: str, limit: int) -> dict[str, Any]:
all_matches: list[dict[str, Any]] = []
exact_queries: list[str] = []
for freq_token in _format_freq_variants_mhz(frequency_mhz):
query = (
f'[[Category:Signal]][[Frequencies::{freq_token} MHz]]'
f'|?Frequencies|?Mode|?Modulation|limit={max(10, limit * 2)}'
)
exact_queries.append(query)
data = _ask_query(query)
if data:
all_matches.extend(_extract_matches_from_ask(data))
if all_matches:
break
search_used = False
if not all_matches:
search_used = True
search_terms = [f'{frequency_mhz:.4f} MHz']
if modulation:
search_terms.insert(0, f'{frequency_mhz:.4f} MHz {modulation.upper()}')
seen_titles: set[str] = set()
for term in search_terms:
search_data = _search_query(term, max(5, min(limit * 2, 10)))
search_results = search_data.get('query', {}).get('search', []) if isinstance(search_data, dict) else []
if not isinstance(search_results, list) or not search_results:
continue
for item in search_results:
title = str(item.get('title') or '').strip()
if not title or title in seen_titles:
continue
seen_titles.add(title)
page_query = f'[[{title}]]|?Frequencies|?Mode|?Modulation|limit=1'
page_data = _ask_query(page_query)
if page_data:
all_matches.extend(_extract_matches_from_ask(page_data))
if len(all_matches) >= max(limit * 3, 12):
break
if all_matches:
break
deduped = _dedupe_matches(all_matches)
ranked = _rank_matches(deduped, frequency_mhz=frequency_mhz, modulation=modulation)
return {
'matches': ranked[:limit],
'search_used': search_used,
'exact_queries': exact_queries,
}
@signalid_bp.route('/sigidwiki', methods=['POST'])
def sigidwiki_lookup() -> Response:
"""Lookup likely signal types from SigID Wiki by tuned frequency."""
payload = request.get_json(silent=True) or {}
freq_raw = payload.get('frequency_mhz')
if freq_raw is None:
return jsonify({'status': 'error', 'message': 'frequency_mhz is required'}), 400
try:
frequency_mhz = float(freq_raw)
except (TypeError, ValueError):
return jsonify({'status': 'error', 'message': 'Invalid frequency_mhz'}), 400
if frequency_mhz <= 0:
return jsonify({'status': 'error', 'message': 'frequency_mhz must be positive'}), 400
modulation = str(payload.get('modulation') or '').strip().upper()
if modulation and len(modulation) > 16:
modulation = modulation[:16]
limit_raw = payload.get('limit', 8)
try:
limit = int(limit_raw)
except (TypeError, ValueError):
limit = 8
limit = max(1, min(limit, 20))
cache_key = f'{round(frequency_mhz, 6)}|{modulation}|{limit}'
cached = _cache_get(cache_key)
if cached is not None:
return jsonify({
'status': 'ok',
'source': 'sigidwiki',
'frequency_mhz': round(frequency_mhz, 6),
'modulation': modulation or None,
'cached': True,
**cached,
})
try:
lookup = _lookup_sigidwiki_matches(frequency_mhz, modulation, limit)
except Exception as exc:
logger.error('SigID lookup failed: %s', exc)
return jsonify({'status': 'error', 'message': 'SigID lookup failed'}), 502
response_payload = {
'matches': lookup.get('matches', []),
'match_count': len(lookup.get('matches', [])),
'search_used': bool(lookup.get('search_used')),
'exact_queries': lookup.get('exact_queries', []),
}
_cache_set(cache_key, response_payload)
return jsonify({
'status': 'ok',
'source': 'sigidwiki',
'frequency_mhz': round(frequency_mhz, 6),
'modulation': modulation or None,
'cached': False,
**response_payload,
})
+300
View File
@@ -0,0 +1,300 @@
"""Space Weather routes - proxies NOAA SWPC, NASA SDO, and HamQSL data."""
from __future__ import annotations
import json
import time
import urllib.error
import urllib.request
import xml.etree.ElementTree as ET
from typing import Any
from flask import Blueprint, Response, jsonify
from utils.logging import get_logger
logger = get_logger('intercept.space_weather')
space_weather_bp = Blueprint('space_weather', __name__, url_prefix='/space-weather')
# ---------------------------------------------------------------------------
# TTL Cache
# ---------------------------------------------------------------------------
_cache: dict[str, dict[str, Any]] = {}
# Cache TTLs in seconds
TTL_REALTIME = 300 # 5 min for real-time data
TTL_FORECAST = 1800 # 30 min for forecasts
TTL_DAILY = 3600 # 1 hr for daily summaries
TTL_IMAGE = 600 # 10 min for images
def _cache_get(key: str) -> Any | None:
entry = _cache.get(key)
if entry and time.time() < entry['expires']:
return entry['data']
return None
def _cache_set(key: str, data: Any, ttl: int) -> None:
_cache[key] = {'data': data, 'expires': time.time() + ttl}
# ---------------------------------------------------------------------------
# HTTP helpers
# ---------------------------------------------------------------------------
_TIMEOUT = 15 # seconds
SWPC_BASE = 'https://services.swpc.noaa.gov'
SWPC_JSON = f'{SWPC_BASE}/products'
def _fetch_json(url: str, timeout: int = _TIMEOUT) -> Any | None:
try:
req = urllib.request.Request(url, headers={'User-Agent': 'INTERCEPT/1.0'})
with urllib.request.urlopen(req, timeout=timeout) as resp:
return json.loads(resp.read().decode())
except Exception as exc:
logger.warning('Failed to fetch %s: %s', url, exc)
return None
def _fetch_text(url: str, timeout: int = _TIMEOUT) -> str | None:
try:
req = urllib.request.Request(url, headers={'User-Agent': 'INTERCEPT/1.0'})
with urllib.request.urlopen(req, timeout=timeout) as resp:
return resp.read().decode()
except Exception as exc:
logger.warning('Failed to fetch %s: %s', url, exc)
return None
def _fetch_bytes(url: str, timeout: int = _TIMEOUT) -> bytes | None:
try:
req = urllib.request.Request(url, headers={'User-Agent': 'INTERCEPT/1.0'})
with urllib.request.urlopen(req, timeout=timeout) as resp:
return resp.read()
except Exception as exc:
logger.warning('Failed to fetch %s: %s', url, exc)
return None
# ---------------------------------------------------------------------------
# Data source fetchers
# ---------------------------------------------------------------------------
def _fetch_cached_json(cache_key: str, url: str, ttl: int) -> Any | None:
cached = _cache_get(cache_key)
if cached is not None:
return cached
data = _fetch_json(url)
if data is not None:
_cache_set(cache_key, data, ttl)
return data
def _fetch_kp_index() -> Any | None:
return _fetch_cached_json('kp_index', f'{SWPC_JSON}/noaa-planetary-k-index.json', TTL_REALTIME)
def _fetch_kp_forecast() -> Any | None:
return _fetch_cached_json('kp_forecast', f'{SWPC_JSON}/noaa-planetary-k-index-forecast.json', TTL_FORECAST)
def _fetch_scales() -> Any | None:
return _fetch_cached_json('scales', f'{SWPC_JSON}/noaa-scales.json', TTL_REALTIME)
def _fetch_flux() -> Any | None:
return _fetch_cached_json('flux', f'{SWPC_JSON}/10cm-flux-30-day.json', TTL_DAILY)
def _fetch_alerts() -> Any | None:
return _fetch_cached_json('alerts', f'{SWPC_JSON}/alerts.json', TTL_REALTIME)
def _fetch_solar_wind_plasma() -> Any | None:
return _fetch_cached_json('sw_plasma', f'{SWPC_JSON}/solar-wind/plasma-6-hour.json', TTL_REALTIME)
def _fetch_solar_wind_mag() -> Any | None:
return _fetch_cached_json('sw_mag', f'{SWPC_JSON}/solar-wind/mag-6-hour.json', TTL_REALTIME)
def _fetch_xrays() -> Any | None:
return _fetch_cached_json('xrays', f'{SWPC_BASE}/json/goes/primary/xrays-1-day.json', TTL_REALTIME)
def _fetch_xray_flares() -> Any | None:
return _fetch_cached_json('xray_flares', f'{SWPC_BASE}/json/goes/primary/xray-flares-7-day.json', TTL_REALTIME)
def _fetch_flare_probability() -> Any | None:
return _fetch_cached_json('flare_prob', f'{SWPC_BASE}/json/solar_probabilities.json', TTL_FORECAST)
def _fetch_solar_regions() -> Any | None:
return _fetch_cached_json('solar_regions', f'{SWPC_BASE}/json/solar_regions.json', TTL_DAILY)
def _fetch_sunspot_report() -> Any | None:
return _fetch_cached_json('sunspot_report', f'{SWPC_BASE}/json/sunspot_report.json', TTL_DAILY)
def _parse_hamqsl_xml(xml_text: str) -> dict[str, Any] | None:
"""Parse HamQSL solar XML into a dict of band conditions."""
try:
root = ET.fromstring(xml_text)
solar = root.find('.//solardata')
if solar is None:
return None
result: dict[str, Any] = {}
# Scalar fields
for tag in ('sfi', 'aindex', 'kindex', 'kindexnt', 'xray', 'sunspots',
'heliumline', 'protonflux', 'electonflux', 'aurora',
'normalization', 'latdegree', 'solarwind', 'magneticfield',
'calculatedconditions', 'calculatedvhfconditions',
'geomagfield', 'signalnoise', 'fof2', 'muffactor', 'muf'):
el = solar.find(tag)
if el is not None and el.text:
result[tag] = el.text.strip()
# Band conditions
bands: list[dict[str, str]] = []
for band_el in solar.findall('.//calculatedconditions/band'):
bands.append({
'name': band_el.get('name', ''),
'time': band_el.get('time', ''),
'condition': band_el.text.strip() if band_el.text else ''
})
result['bands'] = bands
# VHF conditions
vhf: list[dict[str, str]] = []
for phen_el in solar.findall('.//calculatedvhfconditions/phenomenon'):
vhf.append({
'name': phen_el.get('name', ''),
'location': phen_el.get('location', ''),
'condition': phen_el.text.strip() if phen_el.text else ''
})
result['vhf'] = vhf
return result
except ET.ParseError as exc:
logger.warning('Failed to parse HamQSL XML: %s', exc)
return None
def _fetch_band_conditions() -> dict[str, Any] | None:
cached = _cache_get('band_conditions')
if cached is not None:
return cached
xml_text = _fetch_text('https://www.hamqsl.com/solarxml.php')
if xml_text is None:
return None
data = _parse_hamqsl_xml(xml_text)
if data is not None:
_cache_set('band_conditions', data, TTL_FORECAST)
return data
# ---------------------------------------------------------------------------
# Image proxy whitelist
# ---------------------------------------------------------------------------
IMAGE_WHITELIST: dict[str, dict[str, str]] = {
# D-RAP absorption maps
'drap_global': {
'url': f'{SWPC_BASE}/images/animations/d-rap/global/latest.png',
'content_type': 'image/png',
},
'drap_5': {
'url': f'{SWPC_BASE}/images/d-rap/global_f05.png',
'content_type': 'image/png',
},
'drap_10': {
'url': f'{SWPC_BASE}/images/d-rap/global_f10.png',
'content_type': 'image/png',
},
'drap_15': {
'url': f'{SWPC_BASE}/images/d-rap/global_f15.png',
'content_type': 'image/png',
},
'drap_20': {
'url': f'{SWPC_BASE}/images/d-rap/global_f20.png',
'content_type': 'image/png',
},
'drap_25': {
'url': f'{SWPC_BASE}/images/d-rap/global_f25.png',
'content_type': 'image/png',
},
'drap_30': {
'url': f'{SWPC_BASE}/images/d-rap/global_f30.png',
'content_type': 'image/png',
},
# Aurora forecast
'aurora_north': {
'url': f'{SWPC_BASE}/images/animations/ovation/north/latest.jpg',
'content_type': 'image/jpeg',
},
# SDO solar imagery
'sdo_193': {
'url': 'https://sdo.gsfc.nasa.gov/assets/img/latest/latest_512_0193.jpg',
'content_type': 'image/jpeg',
},
'sdo_304': {
'url': 'https://sdo.gsfc.nasa.gov/assets/img/latest/latest_512_0304.jpg',
'content_type': 'image/jpeg',
},
'sdo_magnetogram': {
'url': 'https://sdo.gsfc.nasa.gov/assets/img/latest/latest_512_HMIBC.jpg',
'content_type': 'image/jpeg',
},
}
# ---------------------------------------------------------------------------
# Routes
# ---------------------------------------------------------------------------
@space_weather_bp.route('/data')
def get_data():
"""Return aggregated space weather data from all sources."""
data = {
'kp_index': _fetch_kp_index(),
'kp_forecast': _fetch_kp_forecast(),
'scales': _fetch_scales(),
'flux': _fetch_flux(),
'alerts': _fetch_alerts(),
'solar_wind_plasma': _fetch_solar_wind_plasma(),
'solar_wind_mag': _fetch_solar_wind_mag(),
'xrays': _fetch_xrays(),
'xray_flares': _fetch_xray_flares(),
'flare_probability': _fetch_flare_probability(),
'solar_regions': _fetch_solar_regions(),
'sunspot_report': _fetch_sunspot_report(),
'band_conditions': _fetch_band_conditions(),
'timestamp': time.time(),
}
return jsonify(data)
@space_weather_bp.route('/image/<key>')
def get_image(key: str):
"""Proxy and cache whitelisted space weather images."""
entry = IMAGE_WHITELIST.get(key)
if not entry:
return jsonify({'error': 'Unknown image key'}), 404
cache_key = f'img_{key}'
cached = _cache_get(cache_key)
if cached is not None:
return Response(cached, content_type=entry['content_type'],
headers={'Cache-Control': 'public, max-age=300'})
img_data = _fetch_bytes(entry['url'])
if img_data is None:
return jsonify({'error': 'Failed to fetch image'}), 502
_cache_set(cache_key, img_data, TTL_IMAGE)
return Response(img_data, content_type=entry['content_type'],
headers={'Cache-Control': 'public, max-age=300'})
+46 -23
View File
@@ -15,7 +15,7 @@ from flask import Blueprint, jsonify, request, Response, send_file
import app as app_module import app as app_module
from utils.logging import get_logger from utils.logging import get_logger
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.sstv import ( from utils.sstv import (
get_sstv_decoder, get_sstv_decoder,
@@ -27,6 +27,12 @@ logger = get_logger('intercept.sstv')
sstv_bp = Blueprint('sstv', __name__, url_prefix='/sstv') sstv_bp = Blueprint('sstv', __name__, url_prefix='/sstv')
# ISS SSTV runs on a fixed downlink; allow a small entry tolerance so users
# can type nearby values and still land on the canonical center frequency.
ISS_SSTV_MODULATION = 'fm'
ISS_SSTV_FREQUENCIES = (ISS_SSTV_FREQ,)
ISS_SSTV_FREQ_TOLERANCE_MHZ = 0.05
# Queue for SSE progress streaming # Queue for SSE progress streaming
_sstv_queue: queue.Queue = queue.Queue(maxsize=100) _sstv_queue: queue.Queue = queue.Queue(maxsize=100)
@@ -46,6 +52,14 @@ def _progress_callback(data: dict) -> None:
pass pass
def _normalize_iss_frequency(frequency_mhz: float) -> float | None:
"""Snap near-match user input to a supported ISS SSTV center frequency."""
for supported in ISS_SSTV_FREQUENCIES:
if abs(frequency_mhz - supported) <= ISS_SSTV_FREQ_TOLERANCE_MHZ:
return supported
return None
@sstv_bp.route('/status') @sstv_bp.route('/status')
def get_status(): def get_status():
""" """
@@ -62,6 +76,7 @@ def get_status():
'decoder': decoder.decoder_available, 'decoder': decoder.decoder_available,
'running': decoder.is_running, 'running': decoder.is_running,
'iss_frequency': ISS_SSTV_FREQ, 'iss_frequency': ISS_SSTV_FREQ,
'modulation': ISS_SSTV_MODULATION,
'image_count': len(decoder.get_images()), 'image_count': len(decoder.get_images()),
'doppler_enabled': decoder.doppler_enabled, 'doppler_enabled': decoder.doppler_enabled,
} }
@@ -82,6 +97,7 @@ def start_decoder():
JSON body (optional): JSON body (optional):
{ {
"frequency": 145.800, // Frequency in MHz (default: ISS 145.800) "frequency": 145.800, // Frequency in MHz (default: ISS 145.800)
"modulation": "fm", // ISS mode is FM-only
"device": 0, // RTL-SDR device index "device": 0, // RTL-SDR device index
"latitude": 40.7128, // Observer latitude for Doppler correction "latitude": 40.7128, // Observer latitude for Doppler correction
"longitude": -74.0060 // Observer longitude for Doppler correction "longitude": -74.0060 // Observer longitude for Doppler correction
@@ -106,6 +122,7 @@ def start_decoder():
return jsonify({ return jsonify({
'status': 'already_running', 'status': 'already_running',
'frequency': ISS_SSTV_FREQ, 'frequency': ISS_SSTV_FREQ,
'modulation': ISS_SSTV_MODULATION,
'doppler_enabled': decoder.doppler_enabled 'doppler_enabled': decoder.doppler_enabled
}) })
@@ -119,18 +136,29 @@ def start_decoder():
# Get parameters # Get parameters
data = request.get_json(silent=True) or {} data = request.get_json(silent=True) or {}
frequency = data.get('frequency', ISS_SSTV_FREQ) frequency = data.get('frequency', ISS_SSTV_FREQ)
modulation = str(data.get('modulation', ISS_SSTV_MODULATION)).strip().lower()
device_index = data.get('device', 0) device_index = data.get('device', 0)
latitude = data.get('latitude') latitude = data.get('latitude')
longitude = data.get('longitude') longitude = data.get('longitude')
# Validate modulation (ISS mode is FM-only)
if modulation != ISS_SSTV_MODULATION:
return jsonify({
'status': 'error',
'message': f'Modulation must be {ISS_SSTV_MODULATION} for ISS SSTV mode'
}), 400
# Validate frequency # Validate frequency
try: try:
frequency = float(frequency) frequency = float(frequency)
if not (100 <= frequency <= 500): # VHF range normalized_frequency = _normalize_iss_frequency(frequency)
if normalized_frequency is None:
supported = ', '.join(f'{freq:.3f}' for freq in ISS_SSTV_FREQUENCIES)
return jsonify({ return jsonify({
'status': 'error', 'status': 'error',
'message': 'Frequency must be between 100-500 MHz' 'message': f'Supported ISS SSTV frequency: {supported} MHz FM'
}), 400 }), 400
frequency = normalized_frequency
except (TypeError, ValueError): except (TypeError, ValueError):
return jsonify({ return jsonify({
'status': 'error', 'status': 'error',
@@ -178,7 +206,8 @@ def start_decoder():
frequency=frequency, frequency=frequency,
device_index=device_index, device_index=device_index,
latitude=latitude, latitude=latitude,
longitude=longitude longitude=longitude,
modulation=ISS_SSTV_MODULATION,
) )
if success: if success:
@@ -187,6 +216,7 @@ def start_decoder():
result = { result = {
'status': 'started', 'status': 'started',
'frequency': frequency, 'frequency': frequency,
'modulation': ISS_SSTV_MODULATION,
'device': device_index, 'device': device_index,
'doppler_enabled': decoder.doppler_enabled 'doppler_enabled': decoder.doppler_enabled
} }
@@ -392,26 +422,19 @@ def stream_progress():
Returns: Returns:
SSE stream (text/event-stream) SSE stream (text/event-stream)
""" """
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('sstv', msg, msg.get('type'))
keepalive_interval = 30.0
while True: response = Response(
try: sse_stream_fanout(
progress = _sstv_queue.get(timeout=1) source_queue=_sstv_queue,
last_keepalive = time.time() channel_key='sstv',
try: timeout=1.0,
process_event('sstv', progress, progress.get('type')) keepalive_interval=30.0,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(progress) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+37 -21
View File
@@ -13,8 +13,9 @@ from pathlib import Path
from flask import Blueprint, Response, jsonify, request, send_file from flask import Blueprint, Response, jsonify, request, send_file
import app as app_module
from utils.logging import get_logger from utils.logging import get_logger
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.sstv import ( from utils.sstv import (
get_general_sstv_decoder, get_general_sstv_decoder,
@@ -27,6 +28,9 @@ sstv_general_bp = Blueprint('sstv_general', __name__, url_prefix='/sstv-general'
# Queue for SSE progress streaming # Queue for SSE progress streaming
_sstv_general_queue: queue.Queue = queue.Queue(maxsize=100) _sstv_general_queue: queue.Queue = queue.Queue(maxsize=100)
# Track which device is being used
_sstv_general_active_device: int | None = None
# Predefined SSTV frequencies # Predefined SSTV frequencies
SSTV_FREQUENCIES = [ SSTV_FREQUENCIES = [
{'band': '80 m', 'frequency': 3.845, 'modulation': 'lsb', 'notes': 'Common US SSTV calling frequency', 'type': 'Terrestrial HF'}, {'band': '80 m', 'frequency': 3.845, 'modulation': 'lsb', 'notes': 'Common US SSTV calling frequency', 'type': 'Terrestrial HF'},
@@ -40,7 +44,7 @@ SSTV_FREQUENCIES = [
{'band': '15 m', 'frequency': 21.340, 'modulation': 'usb', 'notes': 'International calling frequency', 'type': 'Terrestrial HF'}, {'band': '15 m', 'frequency': 21.340, 'modulation': 'usb', 'notes': 'International calling frequency', 'type': 'Terrestrial HF'},
{'band': '10 m', 'frequency': 28.680, 'modulation': 'usb', 'notes': 'International calling frequency', 'type': 'Terrestrial HF'}, {'band': '10 m', 'frequency': 28.680, 'modulation': 'usb', 'notes': 'International calling frequency', 'type': 'Terrestrial HF'},
{'band': '6 m', 'frequency': 50.950, 'modulation': 'usb', 'notes': 'SSTV calling (less common)', 'type': 'Terrestrial VHF'}, {'band': '6 m', 'frequency': 50.950, 'modulation': 'usb', 'notes': 'SSTV calling (less common)', 'type': 'Terrestrial VHF'},
{'band': '2 m', 'frequency': 145.625, 'modulation': 'fm', 'notes': 'Australia/common simplex (FM sometimes used)', 'type': 'Terrestrial VHF'}, {'band': '2 m', 'frequency': 145.500, 'modulation': 'fm', 'notes': 'Australia/common simplex (FM sometimes used)', 'type': 'Terrestrial VHF'},
{'band': '70 cm', 'frequency': 433.775, 'modulation': 'fm', 'notes': 'Australia/common simplex', 'type': 'Terrestrial UHF'}, {'band': '70 cm', 'frequency': 433.775, 'modulation': 'fm', 'notes': 'Australia/common simplex', 'type': 'Terrestrial UHF'},
] ]
@@ -150,6 +154,17 @@ def start_decoder():
'message': 'Modulation must be fm, usb, or lsb', 'message': 'Modulation must be fm, usb, or lsb',
}), 400 }), 400
# Claim SDR device
global _sstv_general_active_device
device_int = int(device_index)
error = app_module.claim_sdr_device(device_int, 'sstv_general')
if error:
return jsonify({
'status': 'error',
'error_type': 'DEVICE_BUSY',
'message': error,
}), 409
# Set callback and start # Set callback and start
decoder.set_callback(_progress_callback) decoder.set_callback(_progress_callback)
success = decoder.start( success = decoder.start(
@@ -159,6 +174,7 @@ def start_decoder():
) )
if success: if success:
_sstv_general_active_device = device_int
return jsonify({ return jsonify({
'status': 'started', 'status': 'started',
'frequency': frequency, 'frequency': frequency,
@@ -166,6 +182,7 @@ def start_decoder():
'device': device_index, 'device': device_index,
}) })
else: else:
app_module.release_sdr_device(device_int)
return jsonify({ return jsonify({
'status': 'error', 'status': 'error',
'message': 'Failed to start decoder', 'message': 'Failed to start decoder',
@@ -175,8 +192,14 @@ def start_decoder():
@sstv_general_bp.route('/stop', methods=['POST']) @sstv_general_bp.route('/stop', methods=['POST'])
def stop_decoder(): def stop_decoder():
"""Stop general SSTV decoder.""" """Stop general SSTV decoder."""
global _sstv_general_active_device
decoder = get_general_sstv_decoder() decoder = get_general_sstv_decoder()
decoder.stop() decoder.stop()
if _sstv_general_active_device is not None:
app_module.release_sdr_device(_sstv_general_active_device)
_sstv_general_active_device = None
return jsonify({'status': 'stopped'}) return jsonify({'status': 'stopped'})
@@ -266,26 +289,19 @@ def delete_all_images():
@sstv_general_bp.route('/stream') @sstv_general_bp.route('/stream')
def stream_progress(): def stream_progress():
"""SSE stream of SSTV decode progress.""" """SSE stream of SSTV decode progress."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('sstv_general', msg, msg.get('type'))
keepalive_interval = 30.0
while True: response = Response(
try: sse_stream_fanout(
progress = _sstv_general_queue.get(timeout=1) source_queue=_sstv_general_queue,
last_keepalive = time.time() channel_key='sstv_general',
try: timeout=1.0,
process_event('sstv_general', progress, progress.get('type')) keepalive_interval=30.0,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(progress) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+5
View File
@@ -13,6 +13,7 @@ from flask import Blueprint, jsonify, request, Response, send_file
from utils.logging import get_logger from utils.logging import get_logger
from utils.sse import sse_stream from utils.sse import sse_stream
from utils.subghz import get_subghz_manager from utils.subghz import get_subghz_manager
from utils.event_pipeline import process_event
from utils.constants import ( from utils.constants import (
SUBGHZ_FREQ_MIN_MHZ, SUBGHZ_FREQ_MIN_MHZ,
SUBGHZ_FREQ_MAX_MHZ, SUBGHZ_FREQ_MAX_MHZ,
@@ -34,6 +35,10 @@ _subghz_queue: queue.Queue = queue.Queue(maxsize=200)
def _event_callback(event: dict) -> None: def _event_callback(event: dict) -> None:
"""Forward SubGhzManager events to the SSE queue.""" """Forward SubGhzManager events to the SSE queue."""
try:
process_event('subghz', event, event.get('type'))
except Exception:
pass
try: try:
_subghz_queue.put_nowait(event) _subghz_queue.put_nowait(event)
except queue.Full: except queue.Full:
+10 -16
View File
@@ -61,6 +61,7 @@ from utils.tscm.device_identity import (
ingest_wifi_dict, ingest_wifi_dict,
) )
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.sse import sse_stream_fanout
# Import unified Bluetooth scanner helper for TSCM integration # Import unified Bluetooth scanner helper for TSCM integration
try: try:
@@ -629,24 +630,17 @@ def sweep_status():
@tscm_bp.route('/sweep/stream') @tscm_bp.route('/sweep/stream')
def sweep_stream(): def sweep_stream():
"""SSE stream for real-time sweep updates.""" """SSE stream for real-time sweep updates."""
def generate(): def _on_msg(msg: dict[str, Any]) -> None:
while True: process_event('tscm', msg, msg.get('type'))
try:
if tscm_queue:
msg = tscm_queue.get(timeout=1)
try:
process_event('tscm', msg, msg.get('type'))
except Exception:
pass
yield f"data: {json.dumps(msg)}\n\n"
else:
time.sleep(1)
yield f"data: {json.dumps({'type': 'keepalive'})}\n\n"
except queue.Empty:
yield f"data: {json.dumps({'type': 'keepalive'})}\n\n"
return Response( return Response(
generate(), sse_stream_fanout(
source_queue=tscm_queue,
channel_key='tscm',
timeout=1.0,
keepalive_interval=30.0,
on_message=_on_msg,
),
mimetype='text/event-stream', mimetype='text/event-stream',
headers={ headers={
'Cache-Control': 'no-cache', 'Cache-Control': 'no-cache',
+55 -29
View File
@@ -2,7 +2,11 @@
from __future__ import annotations from __future__ import annotations
import io
import json import json
import os
import platform
import pty
import queue import queue
import shutil import shutil
import subprocess import subprocess
@@ -17,7 +21,7 @@ import app as app_module
from utils.logging import sensor_logger as logger from utils.logging import sensor_logger as logger
from utils.validation import validate_device_index, validate_gain, validate_ppm from utils.validation import validate_device_index, validate_gain, validate_ppm
from utils.sdr import SDRFactory, SDRType from utils.sdr import SDRFactory, SDRType
from utils.sse import format_sse from utils.sse import sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from utils.constants import ( from utils.constants import (
PROCESS_TERMINATE_TIMEOUT, PROCESS_TERMINATE_TIMEOUT,
@@ -51,15 +55,20 @@ def find_dumpvdl2():
return shutil.which('dumpvdl2') return shutil.which('dumpvdl2')
def stream_vdl2_output(process: subprocess.Popen) -> None: def stream_vdl2_output(process: subprocess.Popen, is_text_mode: bool = False) -> None:
"""Stream dumpvdl2 JSON output to queue.""" """Stream dumpvdl2 JSON output to queue."""
global vdl2_message_count, vdl2_last_message_time global vdl2_message_count, vdl2_last_message_time
try: try:
app_module.vdl2_queue.put({'type': 'status', 'status': 'started'}) app_module.vdl2_queue.put({'type': 'status', 'status': 'started'})
for line in iter(process.stdout.readline, b''): # Use appropriate sentinel based on mode (text mode for pty on macOS)
line = line.decode('utf-8', errors='replace').strip() sentinel = '' if is_text_mode else b''
for line in iter(process.stdout.readline, sentinel):
if is_text_mode:
line = line.strip()
else:
line = line.decode('utf-8', errors='replace').strip()
if not line: if not line:
continue continue
@@ -76,6 +85,13 @@ def stream_vdl2_output(process: subprocess.Popen) -> None:
app_module.vdl2_queue.put(data) app_module.vdl2_queue.put(data)
# Feed flight correlator
try:
from utils.flight_correlator import get_flight_correlator
get_flight_correlator().add_vdl2_message(data)
except Exception:
pass
# Log if enabled # Log if enabled
if app_module.logging_enabled: if app_module.logging_enabled:
try: try:
@@ -236,12 +252,28 @@ def start_vdl2() -> Response:
logger.info(f"Starting VDL2 decoder: {' '.join(cmd)}") logger.info(f"Starting VDL2 decoder: {' '.join(cmd)}")
try: try:
process = subprocess.Popen( is_text_mode = False
cmd,
stdout=subprocess.PIPE, # On macOS, use pty to avoid stdout buffering issues
stderr=subprocess.PIPE, if platform.system() == 'Darwin':
start_new_session=True master_fd, slave_fd = pty.openpty()
) process = subprocess.Popen(
cmd,
stdout=slave_fd,
stderr=subprocess.PIPE,
start_new_session=True
)
os.close(slave_fd)
# Wrap master_fd as a text file for line-buffered reading
process.stdout = io.open(master_fd, 'r', buffering=1)
is_text_mode = True
else:
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
start_new_session=True
)
# Wait briefly to check if process started # Wait briefly to check if process started
time.sleep(PROCESS_START_WAIT) time.sleep(PROCESS_START_WAIT)
@@ -266,7 +298,7 @@ def start_vdl2() -> Response:
# Start output streaming thread # Start output streaming thread
thread = threading.Thread( thread = threading.Thread(
target=stream_vdl2_output, target=stream_vdl2_output,
args=(process,), args=(process, is_text_mode),
daemon=True daemon=True
) )
thread.start() thread.start()
@@ -320,25 +352,19 @@ def stop_vdl2() -> Response:
@vdl2_bp.route('/stream') @vdl2_bp.route('/stream')
def stream_vdl2() -> Response: def stream_vdl2() -> Response:
"""SSE stream for VDL2 messages.""" """SSE stream for VDL2 messages."""
def generate() -> Generator[str, None, None]: def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('vdl2', msg, msg.get('type'))
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.vdl2_queue.get(timeout=SSE_QUEUE_TIMEOUT) source_queue=app_module.vdl2_queue,
last_keepalive = time.time() channel_key='vdl2',
try: timeout=SSE_QUEUE_TIMEOUT,
process_event('vdl2', msg, msg.get('type')) keepalive_interval=SSE_KEEPALIVE_INTERVAL,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= SSE_KEEPALIVE_INTERVAL:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
return response return response
+414 -48
View File
@@ -6,7 +6,10 @@ import socket
import subprocess import subprocess
import threading import threading
import time import time
from contextlib import suppress
from typing import Any
import numpy as np
from flask import Flask from flask import Flask
try: try:
@@ -17,18 +20,33 @@ except ImportError:
Sock = None Sock = None
from utils.logging import get_logger from utils.logging import get_logger
from utils.process import safe_terminate, register_process, unregister_process from utils.process import register_process, safe_terminate, unregister_process
from utils.sdr import SDRFactory, SDRType
from utils.sdr.base import SDRCapabilities, SDRDevice
from utils.waterfall_fft import ( from utils.waterfall_fft import (
build_binary_frame, build_binary_frame,
compute_power_spectrum, compute_power_spectrum,
cu8_to_complex, cu8_to_complex,
quantize_to_uint8, quantize_to_uint8,
) )
from utils.sdr import SDRFactory, SDRType
from utils.sdr.base import SDRCapabilities, SDRDevice
logger = get_logger('intercept.waterfall_ws') logger = get_logger('intercept.waterfall_ws')
AUDIO_SAMPLE_RATE = 48000
_shared_state_lock = threading.Lock()
_shared_audio_queue: queue.Queue[bytes] = queue.Queue(maxsize=80)
_shared_state: dict[str, Any] = {
'running': False,
'device': None,
'center_mhz': 0.0,
'span_mhz': 0.0,
'sample_rate': 0,
'monitor_enabled': False,
'monitor_freq_mhz': 0.0,
'monitor_modulation': 'wfm',
'monitor_squelch': 0,
}
# Maximum bandwidth per SDR type (Hz) # Maximum bandwidth per SDR type (Hz)
MAX_BANDWIDTH = { MAX_BANDWIDTH = {
SDRType.RTL_SDR: 2400000, SDRType.RTL_SDR: 2400000,
@@ -39,6 +57,237 @@ MAX_BANDWIDTH = {
} }
def _clear_shared_audio_queue() -> None:
while True:
try:
_shared_audio_queue.get_nowait()
except queue.Empty:
break
def _set_shared_capture_state(
*,
running: bool,
device: int | None = None,
center_mhz: float | None = None,
span_mhz: float | None = None,
sample_rate: int | None = None,
) -> None:
with _shared_state_lock:
_shared_state['running'] = bool(running)
_shared_state['device'] = device if running else None
if center_mhz is not None:
_shared_state['center_mhz'] = float(center_mhz)
if span_mhz is not None:
_shared_state['span_mhz'] = float(span_mhz)
if sample_rate is not None:
_shared_state['sample_rate'] = int(sample_rate)
if not running:
_shared_state['monitor_enabled'] = False
if not running:
_clear_shared_audio_queue()
def _set_shared_monitor(
*,
enabled: bool,
frequency_mhz: float | None = None,
modulation: str | None = None,
squelch: int | None = None,
) -> None:
was_enabled = False
with _shared_state_lock:
was_enabled = bool(_shared_state.get('monitor_enabled'))
_shared_state['monitor_enabled'] = bool(enabled)
if frequency_mhz is not None:
_shared_state['monitor_freq_mhz'] = float(frequency_mhz)
if modulation is not None:
_shared_state['monitor_modulation'] = str(modulation).lower().strip()
if squelch is not None:
_shared_state['monitor_squelch'] = max(0, min(100, int(squelch)))
if was_enabled and not enabled:
_clear_shared_audio_queue()
def get_shared_capture_status() -> dict[str, Any]:
with _shared_state_lock:
return {
'running': bool(_shared_state['running']),
'device': _shared_state['device'],
'center_mhz': float(_shared_state.get('center_mhz', 0.0) or 0.0),
'span_mhz': float(_shared_state.get('span_mhz', 0.0) or 0.0),
'sample_rate': int(_shared_state.get('sample_rate', 0) or 0),
'monitor_enabled': bool(_shared_state.get('monitor_enabled')),
'monitor_freq_mhz': float(_shared_state.get('monitor_freq_mhz', 0.0) or 0.0),
'monitor_modulation': str(_shared_state.get('monitor_modulation', 'wfm')),
'monitor_squelch': int(_shared_state.get('monitor_squelch', 0) or 0),
}
def start_shared_monitor_from_capture(
*,
device: int,
frequency_mhz: float,
modulation: str,
squelch: int,
) -> tuple[bool, str]:
with _shared_state_lock:
if not _shared_state['running']:
return False, 'Waterfall IQ stream not active'
if _shared_state['device'] != device:
return False, 'Waterfall stream is using a different SDR device'
_shared_state['monitor_enabled'] = True
_shared_state['monitor_freq_mhz'] = float(frequency_mhz)
_shared_state['monitor_modulation'] = str(modulation).lower().strip()
_shared_state['monitor_squelch'] = max(0, min(100, int(squelch)))
_clear_shared_audio_queue()
return True, 'started'
def stop_shared_monitor_from_capture() -> None:
_set_shared_monitor(enabled=False)
def read_shared_monitor_audio_chunk(timeout: float = 1.0) -> bytes | None:
with _shared_state_lock:
if not _shared_state['running'] or not _shared_state['monitor_enabled']:
return None
try:
return _shared_audio_queue.get(timeout=max(0.0, float(timeout)))
except queue.Empty:
return None
def _snapshot_monitor_config() -> dict[str, Any] | None:
with _shared_state_lock:
if not (_shared_state['running'] and _shared_state['monitor_enabled']):
return None
return {
'center_mhz': float(_shared_state['center_mhz']),
'monitor_freq_mhz': float(_shared_state['monitor_freq_mhz']),
'modulation': str(_shared_state['monitor_modulation']),
'squelch': int(_shared_state['monitor_squelch']),
}
def _push_shared_audio_chunk(chunk: bytes) -> None:
if not chunk:
return
if _shared_audio_queue.full():
with suppress(queue.Empty):
_shared_audio_queue.get_nowait()
with suppress(queue.Full):
_shared_audio_queue.put_nowait(chunk)
def _demodulate_monitor_audio(
samples: np.ndarray,
sample_rate: int,
center_mhz: float,
monitor_freq_mhz: float,
modulation: str,
squelch: int,
) -> bytes | None:
if samples.size < 32 or sample_rate <= 0:
return None
fs = float(sample_rate)
freq_offset_hz = (float(monitor_freq_mhz) - float(center_mhz)) * 1e6
nyquist = fs * 0.5
if abs(freq_offset_hz) > nyquist * 0.98:
return None
n = np.arange(samples.size, dtype=np.float32)
rotator = np.exp(-1j * (2.0 * np.pi * freq_offset_hz / fs) * n)
shifted = samples * rotator
mod = str(modulation or 'wfm').lower().strip()
target_bb = 220000.0 if mod == 'wfm' else 48000.0
pre_decim = max(1, int(fs // target_bb))
if pre_decim > 1:
usable = (shifted.size // pre_decim) * pre_decim
if usable < pre_decim:
return None
shifted = shifted[:usable].reshape(-1, pre_decim).mean(axis=1)
fs1 = fs / pre_decim
if shifted.size < 16:
return None
if mod in ('wfm', 'fm'):
audio = np.angle(shifted[1:] * np.conj(shifted[:-1])).astype(np.float32)
elif mod == 'am':
envelope = np.abs(shifted).astype(np.float32)
audio = envelope - float(np.mean(envelope))
elif mod == 'usb':
audio = np.real(shifted).astype(np.float32)
elif mod == 'lsb':
audio = -np.real(shifted).astype(np.float32)
else:
audio = np.real(shifted).astype(np.float32)
if audio.size < 8:
return None
audio = audio - float(np.mean(audio))
if mod in ('fm', 'am', 'usb', 'lsb'):
taps = int(max(1, min(31, fs1 / 12000.0)))
if taps > 1:
kernel = np.ones(taps, dtype=np.float32) / float(taps)
audio = np.convolve(audio, kernel, mode='same')
out_len = int(audio.size * AUDIO_SAMPLE_RATE / fs1)
if out_len < 32:
return None
x_old = np.linspace(0.0, 1.0, audio.size, endpoint=False, dtype=np.float32)
x_new = np.linspace(0.0, 1.0, out_len, endpoint=False, dtype=np.float32)
audio = np.interp(x_new, x_old, audio).astype(np.float32)
rms = float(np.sqrt(np.mean(audio * audio) + 1e-12))
level = min(100.0, rms * 450.0)
if squelch > 0 and level < float(squelch):
audio.fill(0.0)
peak = float(np.max(np.abs(audio))) if audio.size else 0.0
if peak > 0:
audio = audio * min(20.0, 0.85 / peak)
pcm = np.clip(audio, -1.0, 1.0)
return (pcm * 32767.0).astype(np.int16).tobytes()
def _parse_center_freq_mhz(payload: dict[str, Any]) -> float:
"""Parse center frequency from mixed legacy/new payload formats."""
if payload.get('center_freq_mhz') is not None:
return float(payload['center_freq_mhz'])
if payload.get('center_freq_hz') is not None:
return float(payload['center_freq_hz']) / 1e6
raw = float(payload.get('center_freq', 100.0))
# Backward compatibility: some clients still send center_freq in Hz.
if raw > 100000:
return raw / 1e6
return raw
def _parse_span_mhz(payload: dict[str, Any]) -> float:
"""Parse display span in MHz from mixed payload formats."""
if payload.get('span_hz') is not None:
return float(payload['span_hz']) / 1e6
return float(payload.get('span_mhz', 2.0))
def _pick_sample_rate(span_hz: int, caps: SDRCapabilities, sdr_type: SDRType) -> int:
"""Pick a valid hardware sample rate nearest the requested span."""
valid_rates = sorted({int(r) for r in caps.sample_rates if int(r) > 0})
if valid_rates:
return min(valid_rates, key=lambda rate: abs(rate - span_hz))
max_bw = MAX_BANDWIDTH.get(sdr_type, 2400000)
return max(62500, min(span_hz, max_bw))
def _resolve_sdr_type(sdr_type_str: str) -> SDRType: def _resolve_sdr_type(sdr_type_str: str) -> SDRType:
"""Convert client sdr_type string to SDRType enum.""" """Convert client sdr_type string to SDRType enum."""
mapping = { mapping = {
@@ -87,6 +336,10 @@ def init_waterfall_websocket(app: Flask):
reader_thread = None reader_thread = None
stop_event = threading.Event() stop_event = threading.Event()
claimed_device = None claimed_device = None
capture_center_mhz = 0.0
capture_start_freq = 0.0
capture_end_freq = 0.0
capture_span_mhz = 0.0
# Queue for outgoing messages — only the main loop touches ws.send() # Queue for outgoing messages — only the main loop touches ws.send()
send_queue = queue.Queue(maxsize=120) send_queue = queue.Queue(maxsize=120)
@@ -105,7 +358,7 @@ def init_waterfall_websocket(app: Flask):
break break
try: try:
msg = ws.receive(timeout=0.1) msg = ws.receive(timeout=0.01)
except Exception as e: except Exception as e:
err = str(e).lower() err = str(e).lower()
if "closed" in err: if "closed" in err:
@@ -143,6 +396,7 @@ def init_waterfall_websocket(app: Flask):
if claimed_device is not None: if claimed_device is not None:
app_module.release_sdr_device(claimed_device) app_module.release_sdr_device(claimed_device)
claimed_device = None claimed_device = None
_set_shared_capture_state(running=False)
stop_event.clear() stop_event.clear()
# Flush stale frames from previous capture # Flush stale frames from previous capture
while not send_queue.empty(): while not send_queue.empty():
@@ -155,34 +409,58 @@ def init_waterfall_websocket(app: Flask):
time.sleep(0.5) time.sleep(0.5)
# Parse config # Parse config
center_freq = float(data.get('center_freq', 100.0)) try:
span_mhz = float(data.get('span_mhz', 2.0)) center_freq_mhz = _parse_center_freq_mhz(data)
gain = data.get('gain') span_mhz = _parse_span_mhz(data)
if gain is not None: gain_raw = data.get('gain')
gain = float(gain) if gain_raw is None or str(gain_raw).lower() == 'auto':
device_index = int(data.get('device', 0)) gain = None
sdr_type_str = data.get('sdr_type', 'rtlsdr') else:
fft_size = int(data.get('fft_size', 1024)) gain = float(gain_raw)
fps = int(data.get('fps', 25)) device_index = int(data.get('device', 0))
avg_count = int(data.get('avg_count', 4)) sdr_type_str = data.get('sdr_type', 'rtlsdr')
ppm = data.get('ppm') fft_size = int(data.get('fft_size', 1024))
if ppm is not None: fps = int(data.get('fps', 25))
ppm = int(ppm) avg_count = int(data.get('avg_count', 4))
bias_t = bool(data.get('bias_t', False)) ppm = data.get('ppm')
if ppm is not None:
ppm = int(ppm)
bias_t = bool(data.get('bias_t', False))
db_min = data.get('db_min')
db_max = data.get('db_max')
if db_min is not None:
db_min = float(db_min)
if db_max is not None:
db_max = float(db_max)
except (TypeError, ValueError) as exc:
ws.send(json.dumps({
'status': 'error',
'message': f'Invalid waterfall configuration: {exc}',
}))
continue
# Clamp FFT size to valid powers of 2 # Clamp and normalize runtime settings
fft_size = max(256, min(8192, fft_size)) fft_size = max(256, min(8192, fft_size))
fps = max(2, min(60, fps))
avg_count = max(1, min(32, avg_count))
if center_freq_mhz <= 0 or span_mhz <= 0:
ws.send(json.dumps({
'status': 'error',
'message': 'center_freq_mhz and span_mhz must be > 0',
}))
continue
# Resolve SDR type and bandwidth # Resolve SDR type and choose a valid sample rate
sdr_type = _resolve_sdr_type(sdr_type_str) sdr_type = _resolve_sdr_type(sdr_type_str)
max_bw = MAX_BANDWIDTH.get(sdr_type, 2400000) builder = SDRFactory.get_builder(sdr_type)
span_hz = int(span_mhz * 1e6) caps = builder.get_capabilities()
sample_rate = min(span_hz, max_bw) requested_span_hz = max(1000, int(span_mhz * 1e6))
sample_rate = _pick_sample_rate(requested_span_hz, caps, sdr_type)
# Compute effective frequency range # Compute effective frequency range
effective_span_mhz = sample_rate / 1e6 effective_span_mhz = sample_rate / 1e6
start_freq = center_freq - effective_span_mhz / 2 start_freq = center_freq_mhz - effective_span_mhz / 2
end_freq = center_freq + effective_span_mhz / 2 end_freq = center_freq_mhz + effective_span_mhz / 2
# Claim the device # Claim the device
claim_err = app_module.claim_sdr_device(device_index, 'waterfall') claim_err = app_module.claim_sdr_device(device_index, 'waterfall')
@@ -197,11 +475,10 @@ def init_waterfall_websocket(app: Flask):
# Build I/Q capture command # Build I/Q capture command
try: try:
builder = SDRFactory.get_builder(sdr_type)
device = _build_dummy_device(device_index, sdr_type) device = _build_dummy_device(device_index, sdr_type)
iq_cmd = builder.build_iq_capture_command( iq_cmd = builder.build_iq_capture_command(
device=device, device=device,
frequency_mhz=center_freq, frequency_mhz=center_freq_mhz,
sample_rate=sample_rate, sample_rate=sample_rate,
gain=gain, gain=gain,
ppm=ppm, ppm=ppm,
@@ -221,7 +498,7 @@ def init_waterfall_websocket(app: Flask):
try: try:
for attempt in range(max_attempts): for attempt in range(max_attempts):
logger.info( logger.info(
f"Starting I/Q capture: {center_freq} MHz, " f"Starting I/Q capture: {center_freq_mhz:.6f} MHz, "
f"span={effective_span_mhz:.1f} MHz, " f"span={effective_span_mhz:.1f} MHz, "
f"sr={sample_rate}, fft={fft_size}" f"sr={sample_rate}, fft={fft_size}"
) )
@@ -263,23 +540,50 @@ def init_waterfall_websocket(app: Flask):
})) }))
continue continue
capture_center_mhz = center_freq_mhz
capture_start_freq = start_freq
capture_end_freq = end_freq
capture_span_mhz = effective_span_mhz
_set_shared_capture_state(
running=True,
device=device_index,
center_mhz=center_freq_mhz,
span_mhz=effective_span_mhz,
sample_rate=sample_rate,
)
_set_shared_monitor(
enabled=False,
frequency_mhz=center_freq_mhz,
modulation='wfm',
squelch=0,
)
# Send started confirmation # Send started confirmation
ws.send(json.dumps({ ws.send(json.dumps({
'status': 'started', 'status': 'started',
'center_mhz': center_freq_mhz,
'start_freq': start_freq, 'start_freq': start_freq,
'end_freq': end_freq, 'end_freq': end_freq,
'fft_size': fft_size, 'fft_size': fft_size,
'sample_rate': sample_rate, 'sample_rate': sample_rate,
'effective_span_mhz': effective_span_mhz,
'db_min': db_min,
'db_max': db_max,
'vfo_freq_mhz': center_freq_mhz,
})) }))
# Start reader thread — puts frames on queue, never calls ws.send() # Start reader thread — puts frames on queue, never calls ws.send()
def fft_reader( def fft_reader(
proc, _send_q, stop_evt, proc, _send_q, stop_evt,
_fft_size, _avg_count, _fps, _fft_size, _avg_count, _fps, _sample_rate,
_start_freq, _end_freq, _start_freq, _end_freq, _center_mhz,
_db_min=None, _db_max=None,
): ):
"""Read I/Q from subprocess, compute FFT, enqueue binary frames.""" """Read I/Q from subprocess, compute FFT, enqueue binary frames."""
bytes_per_frame = _fft_size * _avg_count * 2 required_fft_samples = _fft_size * _avg_count
timeslice_samples = max(required_fft_samples, int(_sample_rate / max(1, _fps)))
bytes_per_frame = timeslice_samples * 2
frame_interval = 1.0 / _fps frame_interval = 1.0 / _fps
try: try:
@@ -304,21 +608,37 @@ def init_waterfall_websocket(app: Flask):
# Process FFT pipeline # Process FFT pipeline
samples = cu8_to_complex(raw) samples = cu8_to_complex(raw)
fft_samples = samples[-required_fft_samples:] if len(samples) > required_fft_samples else samples
power_db = compute_power_spectrum( power_db = compute_power_spectrum(
samples, fft_samples,
fft_size=_fft_size, fft_size=_fft_size,
avg_count=_avg_count, avg_count=_avg_count,
) )
quantized = quantize_to_uint8(power_db) quantized = quantize_to_uint8(
power_db,
db_min=_db_min,
db_max=_db_max,
)
frame = build_binary_frame( frame = build_binary_frame(
_start_freq, _end_freq, quantized, _start_freq, _end_freq, quantized,
) )
try: # Drop frame if main loop cannot keep up.
with suppress(queue.Full):
_send_q.put_nowait(frame) _send_q.put_nowait(frame)
except queue.Full:
# Drop frame if main loop can't keep up monitor_cfg = _snapshot_monitor_config()
pass if monitor_cfg:
audio_chunk = _demodulate_monitor_audio(
samples=samples,
sample_rate=_sample_rate,
center_mhz=monitor_cfg.get('center_mhz', _center_mhz),
monitor_freq_mhz=monitor_cfg.get('monitor_freq_mhz', _center_mhz),
modulation=monitor_cfg.get('modulation', 'wfm'),
squelch=int(monitor_cfg.get('squelch', 0)),
)
if audio_chunk:
_push_shared_audio_chunk(audio_chunk)
# Pace to target FPS # Pace to target FPS
elapsed = time.monotonic() - frame_start elapsed = time.monotonic() - frame_start
@@ -333,13 +653,63 @@ def init_waterfall_websocket(app: Flask):
target=fft_reader, target=fft_reader,
args=( args=(
iq_process, send_queue, stop_event, iq_process, send_queue, stop_event,
fft_size, avg_count, fps, fft_size, avg_count, fps, sample_rate,
start_freq, end_freq, start_freq, end_freq, center_freq_mhz,
db_min, db_max,
), ),
daemon=True, daemon=True,
) )
reader_thread.start() reader_thread.start()
elif cmd in ('tune', 'set_vfo'):
if not iq_process or claimed_device is None or iq_process.poll() is not None:
ws.send(json.dumps({
'status': 'error',
'message': 'Waterfall capture is not running',
}))
continue
try:
shared = get_shared_capture_status()
vfo_freq_mhz = float(
data.get(
'vfo_freq_mhz',
data.get('frequency_mhz', data.get('center_freq_mhz', capture_center_mhz)),
)
)
squelch = int(data.get('squelch', shared.get('monitor_squelch', 0)))
modulation = str(data.get('modulation', shared.get('monitor_modulation', 'wfm')))
except (TypeError, ValueError) as exc:
ws.send(json.dumps({
'status': 'error',
'message': f'Invalid tune request: {exc}',
}))
continue
if not (capture_start_freq <= vfo_freq_mhz <= capture_end_freq):
ws.send(json.dumps({
'status': 'retune_required',
'message': 'Frequency outside current capture span',
'capture_start_freq': capture_start_freq,
'capture_end_freq': capture_end_freq,
'vfo_freq_mhz': vfo_freq_mhz,
}))
continue
monitor_enabled = bool(shared.get('monitor_enabled'))
_set_shared_monitor(
enabled=monitor_enabled,
frequency_mhz=vfo_freq_mhz,
modulation=modulation,
squelch=squelch,
)
ws.send(json.dumps({
'status': 'tuned',
'vfo_freq_mhz': vfo_freq_mhz,
'start_freq': capture_start_freq,
'end_freq': capture_end_freq,
'center_mhz': capture_center_mhz,
}))
elif cmd == 'stop': elif cmd == 'stop':
stop_event.set() stop_event.set()
if reader_thread and reader_thread.is_alive(): if reader_thread and reader_thread.is_alive():
@@ -352,6 +722,7 @@ def init_waterfall_websocket(app: Flask):
if claimed_device is not None: if claimed_device is not None:
app_module.release_sdr_device(claimed_device) app_module.release_sdr_device(claimed_device)
claimed_device = None claimed_device = None
_set_shared_capture_state(running=False)
stop_event.clear() stop_event.clear()
ws.send(json.dumps({'status': 'stopped'})) ws.send(json.dumps({'status': 'stopped'}))
@@ -367,20 +738,15 @@ def init_waterfall_websocket(app: Flask):
unregister_process(iq_process) unregister_process(iq_process)
if claimed_device is not None: if claimed_device is not None:
app_module.release_sdr_device(claimed_device) app_module.release_sdr_device(claimed_device)
_set_shared_capture_state(running=False)
# Complete WebSocket close handshake, then shut down the # Complete WebSocket close handshake, then shut down the
# raw socket so Werkzeug cannot write its HTTP 200 response # raw socket so Werkzeug cannot write its HTTP 200 response
# on top of the WebSocket stream (which browsers see as # on top of the WebSocket stream (which browsers see as
# "Invalid frame header"). # "Invalid frame header").
try: with suppress(Exception):
ws.close() ws.close()
except Exception: with suppress(Exception):
pass
try:
ws.sock.shutdown(socket.SHUT_RDWR) ws.sock.shutdown(socket.SHUT_RDWR)
except Exception: with suppress(Exception):
pass
try:
ws.sock.close() ws.sock.close()
except Exception:
pass
logger.info("WebSocket waterfall client disconnected") logger.info("WebSocket waterfall client disconnected")
+15 -8
View File
@@ -566,14 +566,21 @@ def enable_schedule():
scheduler = get_weather_sat_scheduler() scheduler = get_weather_sat_scheduler()
scheduler.set_callbacks(_progress_callback, _scheduler_event_callback) scheduler.set_callbacks(_progress_callback, _scheduler_event_callback)
result = scheduler.enable( try:
lat=lat, result = scheduler.enable(
lon=lon, lat=lat,
min_elevation=min_elev, lon=lon,
device=device, min_elevation=min_elev,
gain=gain_val, device=device,
bias_t=bool(data.get('bias_t', False)), gain=gain_val,
) bias_t=bool(data.get('bias_t', False)),
)
except Exception as e:
logger.exception("Failed to enable weather sat scheduler")
return jsonify({
'status': 'error',
'message': 'Failed to enable scheduler'
}), 500
return jsonify({'status': 'ok', **result}) return jsonify({'status': 'ok', **result})
+22 -37
View File
@@ -20,7 +20,7 @@ from utils.dependencies import check_tool, get_tool_path
from utils.logging import wifi_logger as logger from utils.logging import wifi_logger as logger
from utils.process import is_valid_mac, is_valid_channel from utils.process import is_valid_mac, is_valid_channel
from utils.validation import validate_wifi_channel, validate_mac_address, validate_network_interface from utils.validation import validate_wifi_channel, validate_mac_address, validate_network_interface
from utils.sse import format_sse from utils.sse import format_sse, sse_stream_fanout
from utils.event_pipeline import process_event from utils.event_pipeline import process_event
from data.oui import get_manufacturer from data.oui import get_manufacturer
from utils.constants import ( from utils.constants import (
@@ -1135,26 +1135,19 @@ def get_wifi_networks():
@wifi_bp.route('/stream') @wifi_bp.route('/stream')
def stream_wifi(): def stream_wifi():
"""SSE stream for WiFi events.""" """SSE stream for WiFi events."""
def generate(): def _on_msg(msg: dict[str, Any]) -> None:
last_keepalive = time.time() process_event('wifi', msg, msg.get('type'))
keepalive_interval = 30.0
while True: response = Response(
try: sse_stream_fanout(
msg = app_module.wifi_queue.get(timeout=1) source_queue=app_module.wifi_queue,
last_keepalive = time.time() channel_key='wifi',
try: timeout=1.0,
process_event('wifi', msg, msg.get('type')) keepalive_interval=30.0,
except Exception: on_message=_on_msg,
pass ),
yield format_sse(msg) mimetype='text/event-stream',
except queue.Empty: )
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
@@ -1557,23 +1550,15 @@ def v2_deauth_stream():
- deauth_error: An error occurred - deauth_error: An error occurred
- keepalive: Periodic keepalive - keepalive: Periodic keepalive
""" """
def generate(): response = Response(
last_keepalive = time.time() sse_stream_fanout(
keepalive_interval = SSE_KEEPALIVE_INTERVAL source_queue=app_module.deauth_detector_queue,
channel_key='wifi_deauth',
while True: timeout=SSE_QUEUE_TIMEOUT,
try: keepalive_interval=SSE_KEEPALIVE_INTERVAL,
# Try to get from the dedicated deauth queue ),
msg = app_module.deauth_detector_queue.get(timeout=SSE_QUEUE_TIMEOUT) mimetype='text/event-stream',
last_keepalive = time.time() )
yield format_sse(msg)
except queue.Empty:
now = time.time()
if now - last_keepalive >= keepalive_interval:
yield format_sse({'type': 'keepalive'})
last_keepalive = now
response = Response(generate(), mimetype='text/event-stream')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no' response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive' response.headers['Connection'] = 'keep-alive'
+98 -142
View File
@@ -233,10 +233,6 @@ check_tools() {
info "GPS:" info "GPS:"
check_required "gpsd" "GPS daemon" gpsd check_required "gpsd" "GPS daemon" gpsd
echo
info "Digital Voice:"
check_optional "dsd" "Digital Speech Decoder (DMR/P25)" dsd dsd-fme
echo echo
info "Audio:" info "Audio:"
check_required "ffmpeg" "Audio encoder/decoder" ffmpeg check_required "ffmpeg" "Audio encoder/decoder" ffmpeg
@@ -325,9 +321,8 @@ install_python_deps() {
# (C extension packages like scipy/numpy can fail on newer Python versions # (C extension packages like scipy/numpy can fail on newer Python versions
# and cause pip to roll back pure-Python packages like flask) # and cause pip to roll back pure-Python packages like flask)
info "Installing core packages..." info "Installing core packages..."
$PIP install "flask>=3.0.0" "flask-limiter>=2.5.4" "requests>=2.28.0" \ $PIP install --quiet "flask>=3.0.0" "flask-limiter>=2.5.4" "requests>=2.28.0" \
"Werkzeug>=3.1.5" "pyserial>=3.5" "flask-sock" "websocket-client>=1.6.0" 2>&1 \ "Werkzeug>=3.1.5" "pyserial>=3.5" "flask-sock" "websocket-client>=1.6.0" 2>/dev/null || true
| tail -5 || true
# Verify critical packages # Verify critical packages
$PY -c "import flask; import requests; from flask_limiter import Limiter" 2>/dev/null || { $PY -c "import flask; import requests; from flask_limiter import Limiter" 2>/dev/null || {
@@ -459,95 +454,6 @@ install_multimon_ng_from_source_macos() {
) )
} }
install_dsd_from_source() {
info "Building DSD (Digital Speech Decoder) from source..."
info "This requires mbelib (vocoder library) as a prerequisite."
if [[ "$OS" == "macos" ]]; then
brew_install cmake
brew_install libsndfile
brew_install ncurses
brew_install fftw
brew_install codec2
brew_install librtlsdr
brew_install pulseaudio || true
else
apt_install build-essential git cmake libsndfile1-dev libpulse-dev \
libfftw3-dev liblapack-dev libncurses-dev librtlsdr-dev libcodec2-dev
fi
(
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
# Step 1: Build and install mbelib (required dependency)
info "Building mbelib (vocoder library)..."
git clone https://github.com/lwvmobile/mbelib.git "$tmp_dir/mbelib" >/dev/null 2>&1 \
|| { warn "Failed to clone mbelib"; exit 1; }
cd "$tmp_dir/mbelib"
git checkout ambe_tones >/dev/null 2>&1 || true
mkdir -p build && cd build
if cmake .. >/dev/null 2>&1 && make -j "$(nproc 2>/dev/null || sysctl -n hw.ncpu)" >/dev/null 2>&1; then
if [[ "$OS" == "macos" ]]; then
if [[ -w /usr/local/lib ]]; then
make install >/dev/null 2>&1
else
refresh_sudo
$SUDO make install >/dev/null 2>&1
fi
else
$SUDO make install >/dev/null 2>&1
$SUDO ldconfig 2>/dev/null || true
fi
ok "mbelib installed"
else
warn "Failed to build mbelib. Cannot build DSD without it."
exit 1
fi
# Step 2: Build dsd-fme (or fall back to original dsd)
info "Building dsd-fme..."
git clone --depth 1 https://github.com/lwvmobile/dsd-fme.git "$tmp_dir/dsd-fme" >/dev/null 2>&1 \
|| { warn "Failed to clone dsd-fme, trying original DSD...";
git clone --depth 1 https://github.com/szechyjs/dsd.git "$tmp_dir/dsd-fme" >/dev/null 2>&1 \
|| { warn "Failed to clone DSD"; exit 1; }; }
cd "$tmp_dir/dsd-fme"
mkdir -p build && cd build
# On macOS, help cmake find Homebrew ncurses
local cmake_flags=""
if [[ "$OS" == "macos" ]]; then
local ncurses_prefix
ncurses_prefix="$(brew --prefix ncurses 2>/dev/null || echo /opt/homebrew/opt/ncurses)"
cmake_flags="-DCMAKE_PREFIX_PATH=$ncurses_prefix"
fi
info "Compiling DSD..."
if cmake .. $cmake_flags >/dev/null 2>&1 && make -j "$(nproc 2>/dev/null || sysctl -n hw.ncpu)" >/dev/null 2>&1; then
if [[ "$OS" == "macos" ]]; then
if [[ -w /usr/local/bin ]]; then
install -m 0755 dsd-fme /usr/local/bin/dsd 2>/dev/null || install -m 0755 dsd /usr/local/bin/dsd 2>/dev/null || true
else
refresh_sudo
$SUDO install -m 0755 dsd-fme /usr/local/bin/dsd 2>/dev/null || $SUDO install -m 0755 dsd /usr/local/bin/dsd 2>/dev/null || true
fi
else
$SUDO make install >/dev/null 2>&1 \
|| $SUDO install -m 0755 dsd-fme /usr/local/bin/dsd 2>/dev/null \
|| $SUDO install -m 0755 dsd /usr/local/bin/dsd 2>/dev/null \
|| true
$SUDO ldconfig 2>/dev/null || true
fi
ok "DSD installed successfully"
else
warn "Failed to build DSD from source. DMR/P25 decoding will not be available."
fi
)
}
install_dump1090_from_source_macos() { install_dump1090_from_source_macos() {
info "dump1090 not available via Homebrew. Building from source..." info "dump1090 not available via Homebrew. Building from source..."
@@ -761,11 +667,23 @@ install_aiscatcher_from_source_macos() {
install_satdump_from_source_debian() { install_satdump_from_source_debian() {
info "Building SatDump v1.2.2 from source (weather satellite decoder)..." info "Building SatDump v1.2.2 from source (weather satellite decoder)..."
# Core deps — hard-fail if missing
apt_install build-essential git cmake pkg-config \ apt_install build-essential git cmake pkg-config \
libpng-dev libtiff-dev libjemalloc-dev libvolk-dev libnng-dev \ libpng-dev libtiff-dev libzstd-dev \
libzstd-dev libsoapysdr-dev libhackrf-dev liblimesuite-dev \
libsqlite3-dev libcurl4-openssl-dev zlib1g-dev libzmq3-dev libfftw3-dev libsqlite3-dev libcurl4-openssl-dev zlib1g-dev libzmq3-dev libfftw3-dev
# libvolk: package name differs between distros
# Ubuntu / Debian Trixie+: libvolk-dev
# Raspberry Pi OS Bookworm / Debian Bookworm: libvolk2-dev
apt_try_install_any libvolk-dev libvolk2-dev \
|| warn "libvolk not found — SatDump will build without VOLK acceleration"
# Optional SDR hardware libs — soft-fail so missing hardware doesn't abort
for pkg in libjemalloc-dev libnng-dev libsoapysdr-dev libhackrf-dev liblimesuite-dev; do
$SUDO apt-get install -y --no-install-recommends "$pkg" >/dev/null 2>&1 \
|| warn "${pkg} not available — skipping (SatDump can build without it)"
done
# Run in subshell to isolate EXIT trap # Run in subshell to isolate EXIT trap
( (
tmp_dir="$(mktemp -d)" tmp_dir="$(mktemp -d)"
@@ -787,6 +705,7 @@ install_satdump_from_source_debian() {
echo '#pragma GCC diagnostic ignored "-Wdeprecated"' echo '#pragma GCC diagnostic ignored "-Wdeprecated"'
echo '#pragma GCC diagnostic ignored "-Wdeprecated-declarations"' echo '#pragma GCC diagnostic ignored "-Wdeprecated-declarations"'
cat "$lua_utils" cat "$lua_utils"
echo # ensure the file ends with a newline before the closing pragma
echo '#pragma GCC diagnostic pop' echo '#pragma GCC diagnostic pop'
} > "${lua_utils}.patched" && mv "${lua_utils}.patched" "$lua_utils" } > "${lua_utils}.patched" && mv "${lua_utils}.patched" "$lua_utils"
fi fi
@@ -906,7 +825,7 @@ install_macos_packages() {
sudo -v || { fail "sudo authentication failed"; exit 1; } sudo -v || { fail "sudo authentication failed"; exit 1; }
fi fi
TOTAL_STEPS=22 TOTAL_STEPS=21
CURRENT_STEP=0 CURRENT_STEP=0
progress "Checking Homebrew" progress "Checking Homebrew"
@@ -929,19 +848,6 @@ install_macos_packages() {
progress "SSTV decoder" progress "SSTV decoder"
ok "SSTV uses built-in pure Python decoder (no external tools needed)" ok "SSTV uses built-in pure Python decoder (no external tools needed)"
progress "Installing DSD (Digital Speech Decoder, optional)"
if ! cmd_exists dsd && ! cmd_exists dsd-fme; then
echo
info "DSD is used for DMR, P25, NXDN, and D-STAR digital voice decoding."
if ask_yes_no "Do you want to install DSD?"; then
install_dsd_from_source || warn "DSD build failed. DMR/P25 decoding will not be available."
else
warn "Skipping DSD installation. DMR/P25 decoding will not be available."
fi
else
ok "DSD already installed"
fi
progress "Installing ffmpeg" progress "Installing ffmpeg"
brew_install ffmpeg brew_install ffmpeg
@@ -1079,10 +985,13 @@ install_dump1090_from_source_debian() {
librtlsdr-dev libusb-1.0-0-dev \ librtlsdr-dev libusb-1.0-0-dev \
libncurses-dev tcl-dev python3-dev libncurses-dev tcl-dev python3-dev
local JOBS
JOBS="$(nproc 2>/dev/null || echo 1)"
# Run in subshell to isolate EXIT trap # Run in subshell to isolate EXIT trap
( (
tmp_dir="$(mktemp -d)" tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT trap '{ [[ -n "${progress_pid:-}" ]] && kill "$progress_pid" 2>/dev/null && wait "$progress_pid" 2>/dev/null || true; }; rm -rf "$tmp_dir"' EXIT
info "Cloning FlightAware dump1090..." info "Cloning FlightAware dump1090..."
git clone --depth 1 https://github.com/flightaware/dump1090.git "$tmp_dir/dump1090" >/dev/null 2>&1 \ git clone --depth 1 https://github.com/flightaware/dump1090.git "$tmp_dir/dump1090" >/dev/null 2>&1 \
@@ -1091,22 +1000,44 @@ install_dump1090_from_source_debian() {
cd "$tmp_dir/dump1090" cd "$tmp_dir/dump1090"
# Remove -Werror to prevent build failures on newer GCC versions # Remove -Werror to prevent build failures on newer GCC versions
sed -i 's/-Werror//g' Makefile 2>/dev/null || true sed -i 's/-Werror//g' Makefile 2>/dev/null || true
info "Compiling FlightAware dump1090..." info "Compiling FlightAware dump1090 (using ${JOBS} CPU cores)..."
if make BLADERF=no RTLSDR=yes >/dev/null 2>&1; then build_log="$tmp_dir/dump1090-build.log"
(while true; do sleep 20; printf " [*] Still compiling dump1090...\n"; done) &
progress_pid=$!
if make -j "$JOBS" BLADERF=no RTLSDR=yes >"$build_log" 2>&1; then
kill "$progress_pid" 2>/dev/null; wait "$progress_pid" 2>/dev/null || true; progress_pid=
$SUDO install -m 0755 dump1090 /usr/local/bin/dump1090 $SUDO install -m 0755 dump1090 /usr/local/bin/dump1090
ok "dump1090 installed successfully (FlightAware)." ok "dump1090 installed successfully (FlightAware)."
exit 0 exit 0
fi fi
kill "$progress_pid" 2>/dev/null; wait "$progress_pid" 2>/dev/null || true; progress_pid=
warn "FlightAware build failed. Falling back to wiedehopf/readsb..." warn "FlightAware build failed. Falling back to wiedehopf/readsb..."
warn "Build log (last 20 lines):"
tail -20 "$build_log" | while IFS= read -r line; do warn " $line"; done
rm -rf "$tmp_dir/dump1090" rm -rf "$tmp_dir/dump1090"
git clone --depth 1 https://github.com/wiedehopf/readsb.git "$tmp_dir/dump1090" >/dev/null 2>&1 \ git clone --depth 1 https://github.com/wiedehopf/readsb.git "$tmp_dir/dump1090" >/dev/null 2>&1 \
|| { fail "Failed to clone wiedehopf/readsb"; exit 1; } || { fail "Failed to clone wiedehopf/readsb"; exit 1; }
cd "$tmp_dir/dump1090" cd "$tmp_dir/dump1090"
info "Compiling readsb..." info "Compiling readsb (using ${JOBS} CPU cores)..."
make RTLSDR=yes >/dev/null 2>&1 || { fail "Failed to build readsb from source (required)."; exit 1; } build_log="$tmp_dir/readsb-build.log"
(while true; do sleep 20; printf " [*] Still compiling readsb...\n"; done) &
progress_pid=$!
if ! make -j "$JOBS" RTLSDR=yes >"$build_log" 2>&1; then
kill "$progress_pid" 2>/dev/null; wait "$progress_pid" 2>/dev/null || true; progress_pid=
warn "Build log (last 20 lines):"
tail -20 "$build_log" | while IFS= read -r line; do warn " $line"; done
fail "Failed to build readsb from source (required)."
exit 1
fi
kill "$progress_pid" 2>/dev/null; wait "$progress_pid" 2>/dev/null || true; progress_pid=
$SUDO install -m 0755 readsb /usr/local/bin/dump1090 $SUDO install -m 0755 readsb /usr/local/bin/dump1090
ok "dump1090 installed successfully (via readsb)." ok "dump1090 installed successfully (via readsb)."
) )
@@ -1278,6 +1209,17 @@ install_rtlsdr_blog_drivers_debian() {
$SUDO udevadm trigger || true $SUDO udevadm trigger || true
fi fi
# Make the Blog drivers' library take priority over the apt-installed
# librtlsdr. Removing apt packages is too destructive (dump1090-mutability
# and other tools depend on librtlsdr0 and get swept out). Instead,
# prepend /usr/local/lib to ldconfig's search path — files named 00-*
# sort before the distro's aarch64-linux-gnu.conf — so ldconfig lists
# /usr/local/lib/librtlsdr.so.0 first and the dynamic linker uses it.
if [[ -d /etc/ld.so.conf.d ]]; then
echo '/usr/local/lib' | $SUDO tee /etc/ld.so.conf.d/00-local-first.conf >/dev/null
fi
$SUDO ldconfig
ok "RTL-SDR Blog drivers installed successfully." ok "RTL-SDR Blog drivers installed successfully."
info "These drivers provide improved support for RTL-SDR Blog V4 and other devices." info "These drivers provide improved support for RTL-SDR Blog V4 and other devices."
warn "Unplug and replug your RTL-SDR devices for the new drivers to take effect." warn "Unplug and replug your RTL-SDR devices for the new drivers to take effect."
@@ -1287,6 +1229,7 @@ install_rtlsdr_blog_drivers_debian() {
warn "See: https://github.com/rtlsdrblog/rtl-sdr-blog" warn "See: https://github.com/rtlsdrblog/rtl-sdr-blog"
fi fi
) )
} }
setup_udev_rules_debian() { setup_udev_rules_debian() {
@@ -1311,24 +1254,35 @@ blacklist_kernel_drivers_debian() {
if [[ -f "$blacklist_file" ]]; then if [[ -f "$blacklist_file" ]]; then
ok "RTL-SDR kernel driver blacklist already present" ok "RTL-SDR kernel driver blacklist already present"
return 0 else
fi info "Blacklisting conflicting DVB kernel drivers..."
$SUDO tee "$blacklist_file" >/dev/null <<'EOF'
info "Blacklisting conflicting DVB kernel drivers..."
$SUDO tee "$blacklist_file" >/dev/null <<'EOF'
# Blacklist DVB-T drivers to allow rtl-sdr to access RTL2832U devices # Blacklist DVB-T drivers to allow rtl-sdr to access RTL2832U devices
blacklist dvb_usb_rtl28xxu blacklist dvb_usb_rtl28xxu
blacklist rtl2832 blacklist rtl2832
blacklist rtl2830 blacklist rtl2830
blacklist r820t blacklist r820t
EOF EOF
fi
# Unload modules if currently loaded # Always unload modules if currently loaded — this must happen even on
# re-runs where the blacklist file already exists, since the modules may
# still be live from the current boot (e.g. blacklist wasn't in initramfs).
local unloaded=false
for mod in dvb_usb_rtl28xxu rtl2832 rtl2830 r820t; do for mod in dvb_usb_rtl28xxu rtl2832 rtl2830 r820t; do
if lsmod | grep -q "^$mod"; then if lsmod | grep -q "^$mod"; then
$SUDO modprobe -r "$mod" 2>/dev/null || true $SUDO modprobe -r "$mod" 2>/dev/null || true
unloaded=true
fi fi
done done
$unloaded && info "Unloaded conflicting DVB kernel modules from current session."
# Bake the blacklist into the initramfs so it survives reboots on
# Raspberry Pi OS / Debian (without this the modules can reload on boot).
if cmd_exists update-initramfs; then
info "Updating initramfs to persist driver blacklist across reboots..."
$SUDO update-initramfs -u >/dev/null 2>&1 || true
fi
ok "Kernel drivers blacklisted. Unplug/replug your RTL-SDR if connected." ok "Kernel drivers blacklisted. Unplug/replug your RTL-SDR if connected."
echo echo
@@ -1349,7 +1303,7 @@ install_debian_packages() {
export NEEDRESTART_MODE=a export NEEDRESTART_MODE=a
fi fi
TOTAL_STEPS=28 TOTAL_STEPS=27
CURRENT_STEP=0 CURRENT_STEP=0
progress "Updating APT package lists" progress "Updating APT package lists"
@@ -1391,12 +1345,18 @@ install_debian_packages() {
apt_install_if_missing rtl-sdr apt_install_if_missing rtl-sdr
progress "RTL-SDR Blog drivers" progress "RTL-SDR Blog drivers (V4 support)"
if cmd_exists rtl_test; then if $IS_DRAGONOS; then
ok "RTL-SDR drivers already installed" info "DragonOS: skipping RTL-SDR Blog driver install (pre-configured)."
else else
info "RTL-SDR drivers not found, installing RTL-SDR Blog drivers..." echo
install_rtlsdr_blog_drivers_debian info "RTL-SDR Blog drivers add V4 (R828D tuner) support and bias-tee improvements."
info "They are backward-compatible with all RTL-SDR devices."
if ask_yes_no "Install RTL-SDR Blog drivers? (recommended for V4 users, safe for all)" "y"; then
install_rtlsdr_blog_drivers_debian
else
warn "Skipping RTL-SDR Blog drivers. V4 devices may not work correctly."
fi
fi fi
progress "Installing multimon-ng" progress "Installing multimon-ng"
@@ -1408,19 +1368,6 @@ install_debian_packages() {
progress "SSTV decoder" progress "SSTV decoder"
ok "SSTV uses built-in pure Python decoder (no external tools needed)" ok "SSTV uses built-in pure Python decoder (no external tools needed)"
progress "Installing DSD (Digital Speech Decoder, optional)"
if ! cmd_exists dsd && ! cmd_exists dsd-fme; then
echo
info "DSD is used for DMR, P25, NXDN, and D-STAR digital voice decoding."
if ask_yes_no "Do you want to install DSD?"; then
install_dsd_from_source || warn "DSD build failed. DMR/P25 decoding will not be available."
else
warn "Skipping DSD installation. DMR/P25 decoding will not be available."
fi
else
ok "DSD already installed"
fi
progress "Installing ffmpeg" progress "Installing ffmpeg"
apt_install ffmpeg apt_install ffmpeg
@@ -1486,6 +1433,15 @@ install_debian_packages() {
$SUDO apt-get install -y python3-bleak >/dev/null 2>&1 || true $SUDO apt-get install -y python3-bleak >/dev/null 2>&1 || true
progress "Installing dump1090" progress "Installing dump1090"
# Remove any stale symlink left from a previous run where dump1090-mutability
# was later uninstalled — cmd_exists finds the broken symlink and skips the
# real install, leaving dump1090 seemingly present but non-functional.
local dump1090_path
dump1090_path="$(command -v dump1090 2>/dev/null || true)"
if [[ -n "$dump1090_path" ]] && [[ ! -x "$dump1090_path" ]]; then
info "Removing broken dump1090 symlink: $dump1090_path"
$SUDO rm -f "$dump1090_path"
fi
if ! cmd_exists dump1090 && ! cmd_exists dump1090-mutability; then if ! cmd_exists dump1090 && ! cmd_exists dump1090-mutability; then
apt_try_install_any dump1090-fa dump1090-mutability dump1090 || true apt_try_install_any dump1090-fa dump1090-mutability dump1090 || true
fi fi
+107
View File
@@ -27,6 +27,27 @@
--radar-bg: #101823; --radar-bg: #101823;
} }
[data-theme="light"] {
--bg-dark: #f4f7fb;
--bg-panel: #e9eef5;
--bg-card: #ffffff;
--border-color: #d1d9e6;
--border-glow: #1f5fa8;
--text-primary: #122034;
--text-secondary: #3a4a5f;
--text-dim: #6b7c93;
--accent-green: #1f8a57;
--accent-cyan: #1f5fa8;
--accent-orange: #b5863a;
--accent-red: #c74444;
--accent-yellow: #b5863a;
--accent-amber: #b5863a;
--grid-line: rgba(31, 95, 168, 0.12);
--noise-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='40'%20height='40'%20viewBox='0%200%2040%2040'%3E%3Cg%20fill='%23000000'%20fill-opacity='0.05'%3E%3Ccircle%20cx='3'%20cy='5'%20r='1'/%3E%3Ccircle%20cx='11'%20cy='9'%20r='1'/%3E%3Ccircle%20cx='18'%20cy='3'%20r='1'/%3E%3Ccircle%20cx='26'%20cy='12'%20r='1'/%3E%3Ccircle%20cx='34'%20cy='6'%20r='1'/%3E%3Ccircle%20cx='7'%20cy='19'%20r='1'/%3E%3Ccircle%20cx='15'%20cy='24'%20r='1'/%3E%3Ccircle%20cx='28'%20cy='22'%20r='1'/%3E%3Ccircle%20cx='36'%20cy='18'%20r='1'/%3E%3Ccircle%20cx='5'%20cy='33'%20r='1'/%3E%3Ccircle%20cx='19'%20cy='32'%20r='1'/%3E%3Ccircle%20cx='31'%20cy='34'%20r='1'/%3E%3C/g%3E%3C/svg%3E");
--radar-cyan: #1f5fa8;
--radar-bg: #e9eef5;
}
body { body {
font-family: var(--font-sans); font-family: var(--font-sans);
background: var(--bg-dark); background: var(--bg-dark);
@@ -872,6 +893,92 @@ body {
display: block; display: block;
} }
.map-crosshair-overlay {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 1200;
--crosshair-x-start: 100%;
--crosshair-y-start: 100%;
--crosshair-x-end: 50%;
--crosshair-y-end: 50%;
--crosshair-duration: 1500ms;
}
.map-crosshair-line {
position: absolute;
opacity: 0;
background: var(--accent-cyan);
box-shadow: none;
will-change: transform, opacity;
}
.map-crosshair-vertical {
top: 0;
bottom: 0;
width: 1px;
left: 0;
transform: translateX(var(--crosshair-x-start));
}
.map-crosshair-horizontal {
left: 0;
right: 0;
height: 1px;
top: 0;
transform: translateY(var(--crosshair-y-start));
}
.map-crosshair-overlay.active .map-crosshair-vertical {
animation: mapCrosshairSweepX var(--crosshair-duration) cubic-bezier(0.2, 0.85, 0.28, 1) forwards;
}
.map-crosshair-overlay.active .map-crosshair-horizontal {
animation: mapCrosshairSweepY var(--crosshair-duration) cubic-bezier(0.2, 0.85, 0.28, 1) forwards;
}
@keyframes mapCrosshairSweepX {
0% {
transform: translateX(var(--crosshair-x-start));
opacity: 0;
}
12% {
opacity: 1;
}
85% {
opacity: 1;
}
100% {
transform: translateX(var(--crosshair-x-end));
opacity: 0;
}
}
@keyframes mapCrosshairSweepY {
0% {
transform: translateY(var(--crosshair-y-start));
opacity: 0;
}
12% {
opacity: 1;
}
85% {
opacity: 1;
}
100% {
transform: translateY(var(--crosshair-y-end));
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
.map-crosshair-overlay.active .map-crosshair-vertical,
.map-crosshair-overlay.active .map-crosshair-horizontal {
animation-duration: 220ms;
}
}
/* Right sidebar - Mobile first */ /* Right sidebar - Mobile first */
.sidebar { .sidebar {
display: flex; display: flex;
+21
View File
@@ -30,6 +30,27 @@
--radar-bg: #101823; --radar-bg: #101823;
} }
[data-theme="light"] {
--bg-dark: #f4f7fb;
--bg-panel: #e9eef5;
--bg-card: #ffffff;
--border-color: #d1d9e6;
--border-glow: #1f5fa8;
--text-primary: #122034;
--text-secondary: #3a4a5f;
--text-dim: #6b7c93;
--accent-green: #1f8a57;
--accent-cyan: #1f5fa8;
--accent-orange: #b5863a;
--accent-red: #c74444;
--accent-yellow: #b5863a;
--accent-amber: #b5863a;
--grid-line: rgba(31, 95, 168, 0.12);
--noise-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='40'%20height='40'%20viewBox='0%200%2040%2040'%3E%3Cg%20fill='%23000000'%20fill-opacity='0.05'%3E%3Ccircle%20cx='3'%20cy='5'%20r='1'/%3E%3Ccircle%20cx='11'%20cy='9'%20r='1'/%3E%3Ccircle%20cx='18'%20cy='3'%20r='1'/%3E%3Ccircle%20cx='26'%20cy='12'%20r='1'/%3E%3Ccircle%20cx='34'%20cy='6'%20r='1'/%3E%3Ccircle%20cx='7'%20cy='19'%20r='1'/%3E%3Ccircle%20cx='15'%20cy='24'%20r='1'/%3E%3Ccircle%20cx='28'%20cy='22'%20r='1'/%3E%3Ccircle%20cx='36'%20cy='18'%20r='1'/%3E%3Ccircle%20cx='5'%20cy='33'%20r='1'/%3E%3Ccircle%20cx='19'%20cy='32'%20r='1'/%3E%3Ccircle%20cx='31'%20cy='34'%20r='1'/%3E%3C/g%3E%3C/svg%3E");
--radar-cyan: #1f5fa8;
--radar-bg: #e9eef5;
}
body { body {
font-family: var(--font-sans); font-family: var(--font-sans);
background: var(--bg-dark); background: var(--bg-dark);
+2 -4
View File
@@ -13,13 +13,11 @@
} }
.radar-device { .radar-device {
transition: transform 0.2s ease;
transform-origin: center center;
cursor: pointer; cursor: pointer;
} }
.radar-device:hover { .radar-device:hover .radar-dot {
transform: scale(1.2); filter: brightness(1.5);
} }
/* Invisible larger hit area to prevent hover flicker */ /* Invisible larger hit area to prevent hover flicker */
+440
View File
@@ -0,0 +1,440 @@
/* Shared UX platform components: run-state strip, command palette, setup assistant, and toasts */
.run-state-strip {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 8px 14px;
margin: 6px 12px 0;
border: 1px solid rgba(74, 163, 255, 0.32);
border-radius: 8px;
background: linear-gradient(180deg, rgba(19, 30, 44, 0.96), rgba(11, 18, 28, 0.97));
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.run-state-left {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
min-width: 0;
}
#runStateChips {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.run-state-label {
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--text-dim, #8697aa);
font-weight: 600;
}
.run-state-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 3px 7px;
border-radius: 999px;
border: 1px solid rgba(74, 163, 255, 0.25);
background: linear-gradient(180deg, rgba(17, 26, 38, 0.82), rgba(12, 18, 28, 0.84));
font-size: 10px;
color: var(--text-secondary, #b1c2d4);
white-space: nowrap;
}
.run-state-chip .dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #667788;
box-shadow: 0 0 0 0 rgba(102, 119, 136, 0.45);
}
.run-state-chip.running .dot {
background: var(--accent-green, #28c27a);
box-shadow: 0 0 0 4px rgba(40, 194, 122, 0.16), 0 0 12px rgba(40, 194, 122, 0.35);
}
.run-state-chip.active {
border-color: rgba(74, 163, 255, 0.65);
color: var(--text-primary, #e6edf5);
box-shadow: inset 0 0 0 1px rgba(74, 163, 255, 0.18);
}
.run-state-right {
display: inline-flex;
align-items: center;
gap: 8px;
}
.run-state-value {
font-size: 10px;
color: var(--text-dim, #8697aa);
}
.run-state-btn {
background: linear-gradient(180deg, rgba(17, 27, 41, 0.9), rgba(10, 16, 25, 0.92));
color: var(--accent-cyan, #4aa3ff);
border: 1px solid rgba(74, 163, 255, 0.45);
border-radius: 6px;
font-size: 10px;
padding: 4px 8px;
cursor: pointer;
transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}
.run-state-btn:hover {
background: rgba(74, 163, 255, 0.14);
border-color: rgba(74, 163, 255, 0.7);
transform: translateY(-1px);
}
.command-palette-overlay {
position: fixed;
inset: 0;
display: none;
align-items: flex-start;
justify-content: center;
padding: 10vh 18px 0;
z-index: 25000;
background: rgba(4, 8, 14, 0.65);
backdrop-filter: blur(3px);
}
.command-palette-overlay.open {
display: flex;
}
.command-palette {
width: min(760px, 100%);
border: 1px solid rgba(74, 163, 255, 0.32);
border-radius: 12px;
background: linear-gradient(180deg, rgba(16, 26, 39, 0.98), rgba(10, 17, 27, 0.98));
box-shadow: 0 26px 60px rgba(0, 0, 0, 0.56), inset 0 1px 0 rgba(255, 255, 255, 0.04);
overflow: hidden;
}
.command-palette-header {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border-bottom: 1px solid var(--border-color, #1e2d3d);
}
.command-palette-input {
width: 100%;
border: none;
outline: none;
background: transparent;
color: var(--text-primary, #e6edf5);
font-size: 14px;
padding: 2px 0;
}
.command-palette-hint {
font-size: 10px;
color: var(--text-dim, #8697aa);
white-space: nowrap;
}
.command-palette-list {
max-height: min(62vh, 520px);
overflow-y: auto;
}
.command-palette-item {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 10px 12px;
border: none;
border-bottom: 1px solid rgba(255, 255, 255, 0.04);
background: transparent;
color: var(--text-secondary, #b1c2d4);
cursor: pointer;
text-align: left;
}
.command-palette-item:last-child {
border-bottom: none;
}
.command-palette-item .meta {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
}
.command-palette-item .title {
color: var(--text-primary, #e6edf5);
font-size: 12px;
font-weight: 600;
}
.command-palette-item .desc {
color: var(--text-dim, #8697aa);
font-size: 10px;
}
.command-palette-item .kbd {
font-size: 9px;
color: var(--text-dim, #8697aa);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 4px;
padding: 1px 5px;
}
.command-palette-item.active,
.command-palette-item:hover,
.command-palette-item:focus-visible {
background: rgba(74, 163, 255, 0.12);
outline: none;
}
.command-palette-empty {
padding: 22px 16px;
color: var(--text-dim, #8697aa);
font-size: 11px;
text-align: center;
}
.setup-overlay {
position: fixed;
inset: 0;
display: none;
align-items: center;
justify-content: center;
z-index: 26000;
background: rgba(4, 8, 14, 0.72);
backdrop-filter: blur(4px);
padding: 14px;
}
.setup-overlay.open {
display: flex;
}
.setup-modal {
width: min(760px, 100%);
max-height: 84vh;
overflow-y: auto;
border: 1px solid var(--border-color, #1e2d3d);
border-radius: 12px;
background: #101926;
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
.setup-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 8px;
border-bottom: 1px solid var(--border-color, #1e2d3d);
padding: 14px;
}
.setup-title {
font-size: 16px;
margin: 0;
color: var(--text-primary, #e6edf5);
}
.setup-subtitle {
margin: 4px 0 0;
font-size: 11px;
color: var(--text-dim, #8697aa);
}
.setup-close {
background: transparent;
border: none;
color: var(--text-dim, #8697aa);
font-size: 22px;
cursor: pointer;
line-height: 1;
}
.setup-content {
padding: 14px;
display: grid;
gap: 10px;
}
.setup-step {
border: 1px solid var(--border-color, #1e2d3d);
border-radius: 8px;
padding: 10px;
background: rgba(255, 255, 255, 0.02);
}
.setup-step-header {
display: flex;
justify-content: space-between;
gap: 8px;
margin-bottom: 6px;
}
.setup-step-title {
font-size: 12px;
color: var(--text-primary, #e6edf5);
font-weight: 600;
}
.setup-step-status {
font-size: 10px;
color: var(--text-dim, #8697aa);
}
.setup-step-status.done {
color: var(--accent-green, #28c27a);
}
.setup-step-desc {
font-size: 11px;
color: var(--text-secondary, #b1c2d4);
margin: 0 0 8px;
}
.setup-step-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.setup-btn {
padding: 6px 10px;
border-radius: 6px;
border: 1px solid var(--border-color, #1e2d3d);
background: var(--bg-tertiary, #121f2d);
color: var(--text-secondary, #b1c2d4);
font-size: 11px;
cursor: pointer;
}
.setup-btn.primary {
color: #fff;
background: var(--accent-cyan, #4aa3ff);
border-color: var(--accent-cyan, #4aa3ff);
}
.setup-footer {
padding: 12px 14px;
border-top: 1px solid var(--border-color, #1e2d3d);
display: flex;
justify-content: space-between;
gap: 8px;
flex-wrap: wrap;
align-items: center;
}
.setup-footer-note {
color: var(--text-dim, #8697aa);
font-size: 10px;
}
.app-toast-stack {
position: fixed;
right: 14px;
bottom: 16px;
z-index: 25500;
display: flex;
flex-direction: column;
gap: 8px;
max-width: min(380px, calc(100vw - 24px));
}
.app-toast {
border: 1px solid var(--border-color, #1e2d3d);
border-left: 3px solid var(--accent-cyan, #4aa3ff);
border-radius: 8px;
background: rgba(15, 24, 35, 0.97);
color: var(--text-secondary, #b1c2d4);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
padding: 8px 10px;
font-size: 11px;
}
.app-toast.error {
border-left-color: var(--accent-red, #e25d5d);
}
.app-toast.warning {
border-left-color: var(--accent-orange, #d6a85e);
}
.app-toast-title {
font-size: 11px;
color: var(--text-primary, #e6edf5);
font-weight: 600;
margin-bottom: 4px;
}
.app-toast-msg {
color: var(--text-secondary, #b1c2d4);
}
.app-toast-actions {
margin-top: 7px;
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.app-toast-actions button {
border: 1px solid var(--border-color, #1e2d3d);
border-radius: 4px;
background: var(--bg-tertiary, #132133);
color: var(--text-secondary, #b1c2d4);
font-size: 10px;
padding: 3px 6px;
cursor: pointer;
}
.app-toast-actions button:hover {
border-color: rgba(74, 163, 255, 0.5);
color: var(--text-primary, #e6edf5);
}
@media (max-width: 920px) {
.run-state-strip {
flex-direction: column;
align-items: stretch;
}
.run-state-right {
justify-content: space-between;
}
}
@media (max-width: 640px) {
.command-palette-overlay {
padding: 8vh 10px 0;
}
.command-palette-item {
padding: 9px 10px;
}
.setup-header,
.setup-content,
.setup-footer {
padding: 10px;
}
.app-toast-stack {
left: 10px;
right: 10px;
max-width: none;
}
}
+5 -3
View File
@@ -28,14 +28,16 @@ body {
color: var(--text-primary); color: var(--text-primary);
background-color: var(--bg-primary); background-color: var(--bg-primary);
background-image: background-image:
radial-gradient(1200px 620px at 8% -12%, var(--ambient-top-left), transparent 62%),
radial-gradient(980px 560px at 92% -16%, var(--ambient-top-right), transparent 64%),
radial-gradient(900px 520px at 50% 126%, var(--ambient-bottom), transparent 68%),
var(--noise-image), var(--noise-image),
radial-gradient(circle at 15% 0%, var(--grid-dot), transparent 45%),
linear-gradient(180deg, var(--grid-dot), transparent 35%),
linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(var(--grid-line) 1px, transparent 1px),
linear-gradient(90deg, var(--grid-line) 1px, transparent 1px); linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
background-size: 40px 40px, auto, auto, 48px 48px, 48px 48px; background-size: auto, auto, auto, 40px 40px, 48px 48px, 48px 48px;
background-attachment: fixed; background-attachment: fixed;
min-height: 100vh; min-height: 100vh;
font-variant-numeric: tabular-nums;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
+26 -11
View File
@@ -123,11 +123,12 @@
CARDS / PANELS CARDS / PANELS
============================================ */ ============================================ */
.card { .card {
background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-secondary) 100%); background: var(--surface-panel-gradient);
border: 1px solid var(--border-color); border: 1px solid rgba(74, 163, 255, 0.24);
border-radius: var(--radius-lg); border-radius: var(--radius-lg);
overflow: hidden; overflow: hidden;
box-shadow: var(--shadow-sm); box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(5px);
} }
.card-header { .card-header {
@@ -135,8 +136,8 @@
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: var(--space-3) var(--space-4); padding: var(--space-3) var(--space-4);
border-bottom: 1px solid var(--border-color); border-bottom: 1px solid rgba(74, 163, 255, 0.18);
background: var(--bg-secondary); background: linear-gradient(180deg, rgba(25, 38, 55, 0.88) 0%, rgba(17, 27, 40, 0.9) 100%);
position: relative; position: relative;
} }
@@ -160,11 +161,12 @@
/* Panel variant (used in dashboards) */ /* Panel variant (used in dashboards) */
.panel { .panel {
background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-secondary) 100%); background: var(--surface-panel-gradient);
border: 1px solid var(--border-color); border: 1px solid rgba(74, 163, 255, 0.24);
border-radius: var(--radius-lg); border-radius: var(--radius-lg);
overflow: hidden; overflow: hidden;
box-shadow: var(--shadow-sm); box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(5px);
} }
@supports (clip-path: polygon(0 0)) { @supports (clip-path: polygon(0 0)) {
@@ -190,8 +192,8 @@
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: var(--space-2) var(--space-3); padding: var(--space-2) var(--space-3);
border-bottom: 1px solid var(--border-color); border-bottom: 1px solid rgba(74, 163, 255, 0.18);
background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-secondary) 100%); background: linear-gradient(180deg, rgba(25, 38, 55, 0.88) 0%, rgba(17, 27, 40, 0.9) 100%);
font-size: var(--text-xs); font-size: var(--text-xs);
font-weight: var(--font-semibold); font-weight: var(--font-semibold);
text-transform: uppercase; text-transform: uppercase;
@@ -722,7 +724,20 @@
.card:hover, .card:hover,
.panel:hover { .panel:hover {
border-color: var(--border-light); border-color: var(--border-glow);
box-shadow: var(--shadow-md), var(--shadow-glow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
transform: translateY(-1px);
}
[data-theme="light"] .card,
[data-theme="light"] .panel {
border-color: rgba(31, 95, 168, 0.24);
}
[data-theme="light"] .card-header,
[data-theme="light"] .panel-header {
border-bottom-color: rgba(31, 95, 168, 0.2);
background: linear-gradient(180deg, rgba(243, 247, 252, 0.96) 0%, rgba(233, 239, 247, 0.95) 100%);
} }
/* Stats strip value highlight on hover */ /* Stats strip value highlight on hover */
+10
View File
@@ -16,6 +16,11 @@
--bg-card: #121a25; --bg-card: #121a25;
--bg-elevated: #1b2734; --bg-elevated: #1b2734;
--bg-overlay: rgba(8, 13, 20, 0.75); --bg-overlay: rgba(8, 13, 20, 0.75);
--surface-glass: rgba(16, 25, 37, 0.82);
--surface-panel-gradient: linear-gradient(160deg, rgba(20, 32, 47, 0.94) 0%, rgba(11, 18, 27, 0.96) 100%);
--ambient-top-left: rgba(74, 163, 255, 0.14);
--ambient-top-right: rgba(56, 193, 128, 0.09);
--ambient-bottom: rgba(214, 168, 94, 0.06);
/* Background aliases for components */ /* Background aliases for components */
--bg-dark: var(--bg-primary); --bg-dark: var(--bg-primary);
@@ -158,6 +163,11 @@
--bg-card: #ffffff; --bg-card: #ffffff;
--bg-elevated: #f1f4f9; --bg-elevated: #f1f4f9;
--bg-overlay: rgba(244, 247, 251, 0.92); --bg-overlay: rgba(244, 247, 251, 0.92);
--surface-glass: rgba(255, 255, 255, 0.84);
--surface-panel-gradient: linear-gradient(160deg, rgba(255, 255, 255, 0.96) 0%, rgba(241, 245, 251, 0.97) 100%);
--ambient-top-left: rgba(31, 95, 168, 0.1);
--ambient-top-right: rgba(31, 138, 87, 0.06);
--ambient-bottom: rgba(181, 134, 58, 0.05);
/* Background aliases for components */ /* Background aliases for components */
--bg-dark: var(--bg-primary); --bg-dark: var(--bg-primary);
+752 -11
View File
@@ -1556,7 +1556,7 @@ header h1 .tagline {
background: var(--bg-tertiary); background: var(--bg-tertiary);
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
border-radius: 6px; border-radius: 6px;
overflow: visible; overflow: hidden;
padding: 12px; padding: 12px;
position: relative; position: relative;
} }
@@ -1802,6 +1802,14 @@ header h1 .tagline {
box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3); box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
} }
@keyframes stop-btn-pulse {
0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(239,68,68,0); }
50% { opacity: 0.75; box-shadow: 0 0 8px 2px rgba(239,68,68,0.45); }
}
.stop-btn {
animation: stop-btn-pulse 1.2s ease-in-out infinite;
}
.output-panel { .output-panel {
background: var(--bg-primary); background: var(--bg-primary);
display: flex; display: flex;
@@ -2172,6 +2180,10 @@ header h1 .tagline {
} }
.control-btn { .control-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
padding: 6px 12px; padding: 6px 12px;
background: transparent; background: transparent;
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
@@ -2182,6 +2194,14 @@ header h1 .tagline {
letter-spacing: 1px; letter-spacing: 1px;
transition: all 0.2s ease; transition: all 0.2s ease;
font-family: var(--font-sans); font-family: var(--font-sans);
line-height: 1.1;
white-space: nowrap;
}
.control-btn .icon {
display: inline-flex;
align-items: center;
justify-content: center;
} }
.control-btn:hover { .control-btn:hover {
@@ -3586,6 +3606,7 @@ header h1 .tagline {
.wifi-networks-table-wrapper { .wifi-networks-table-wrapper {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
overscroll-behavior: contain;
} }
.wifi-networks-table { .wifi-networks-table {
@@ -3694,6 +3715,22 @@ header h1 .tagline {
color: var(--text-dim); color: var(--text-dim);
} }
.app-collection-state-row td {
text-align: center;
padding: 0;
}
.app-collection-state {
color: var(--text-dim);
padding: 16px 12px;
font-size: 11px;
text-align: center;
}
.app-collection-state.is-loading {
color: var(--accent-cyan);
}
/* WiFi Radar Panel (CENTER) */ /* WiFi Radar Panel (CENTER) */
.wifi-radar-panel { .wifi-radar-panel {
display: flex; display: flex;
@@ -4060,8 +4097,8 @@ header h1 .tagline {
/* Bluetooth Layout Container */ /* Bluetooth Layout Container */
.bt-layout-container { .bt-layout-container {
display: flex; display: flex;
gap: 15px; gap: 12px;
padding: 15px; padding: 12px;
background: var(--bg-secondary); background: var(--bg-secondary);
margin: 0 15px 10px 15px; margin: 0 15px 10px 15px;
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
@@ -4075,20 +4112,21 @@ header h1 .tagline {
flex-direction: column; flex-direction: column;
gap: 12px; gap: 12px;
min-width: 0; min-width: 0;
overflow-y: auto; /* scroll rather than squash when detail panel + radar exceed available height */
} }
.bt-main-area { .bt-main-area {
display: flex; display: flex;
gap: 12px; gap: 12px;
flex: 1; flex: 1;
min-height: 0; min-height: 420px;
} }
.bt-side-panels { .bt-side-panels {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 12px; gap: 12px;
width: 220px; width: 300px;
flex-shrink: 0; flex-shrink: 0;
} }
@@ -4096,6 +4134,21 @@ header h1 .tagline {
flex: 1; flex: 1;
min-height: 0; min-height: 0;
overflow: hidden; overflow: hidden;
display: flex;
flex-direction: column;
}
.bt-tracker-panel h5 {
margin-bottom: 8px;
}
.bt-tracker-list {
font-size: 11px;
flex: 1;
min-height: 0;
overflow-y: auto;
padding-right: 2px;
overscroll-behavior: contain;
} }
.bt-radar-panel { .bt-radar-panel {
@@ -4106,6 +4159,90 @@ header h1 .tagline {
flex-direction: column; flex-direction: column;
} }
#btRadarControls {
gap: 6px;
}
.bt-radar-filter-btn,
#btRadarPauseBtn {
min-width: 84px;
padding: 4px 10px;
font-size: 10px;
background: var(--bg-tertiary);
border: 1px solid var(--border-color);
border-radius: 4px;
color: var(--text-dim);
cursor: pointer;
transition: all 0.2s ease;
}
.bt-radar-filter-btn:hover,
#btRadarPauseBtn:hover {
color: var(--text-primary);
border-color: var(--accent-cyan);
}
.bt-radar-filter-btn.active,
#btRadarPauseBtn.active {
color: #0f172a;
background: var(--accent-cyan);
border-color: var(--accent-cyan);
}
.bt-zone-summary {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
margin-top: 12px;
font-size: 11px;
}
.bt-zone-card {
text-align: center;
border-radius: 6px;
padding: 8px 6px;
background: var(--bg-secondary);
border: 1px solid var(--border-color);
}
.bt-zone-card.immediate {
border-color: rgba(34, 197, 94, 0.35);
}
.bt-zone-card.near {
border-color: rgba(234, 179, 8, 0.35);
}
.bt-zone-card.far {
border-color: rgba(239, 68, 68, 0.35);
}
.bt-zone-value {
display: block;
font-size: 19px;
font-weight: 700;
}
.bt-zone-card.immediate .bt-zone-value {
color: #22c55e;
}
.bt-zone-card.near .bt-zone-value {
color: #eab308;
}
.bt-zone-card.far .bt-zone-value {
color: #ef4444;
}
.bt-zone-label {
color: var(--text-dim);
font-size: 10px;
margin-top: 3px;
text-transform: uppercase;
letter-spacing: 0.4px;
}
.bt-radar-panel #btProximityRadar { .bt-radar-panel #btProximityRadar {
flex: 1; flex: 1;
min-height: 0; min-height: 0;
@@ -4247,6 +4384,70 @@ header h1 .tagline {
color: #9ca3af; color: #9ca3af;
} }
.bt-detail-badge.tracker-high {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
}
.bt-detail-badge.tracker-medium {
background: rgba(249, 115, 22, 0.2);
color: #f97316;
}
.bt-detail-badge.tracker-low {
background: rgba(234, 179, 8, 0.2);
color: #eab308;
}
.bt-detail-tracker-analysis {
background: rgba(239, 68, 68, 0.08);
border: 1px solid rgba(239, 68, 68, 0.25);
border-radius: 6px;
padding: 8px 10px;
margin-bottom: 8px;
}
.bt-analysis-header {
color: #fca5a5;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.35px;
text-transform: uppercase;
margin-bottom: 6px;
}
.bt-analysis-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
font-size: 10px;
margin-top: 4px;
}
.bt-analysis-label {
color: var(--text-dim);
font-size: 9px;
}
.bt-analysis-section {
margin-top: 6px;
}
.bt-evidence-list {
margin: 4px 0 0 0;
padding-left: 14px;
color: var(--text-primary);
font-size: 10px;
}
.bt-analysis-warning {
margin-top: 8px;
color: #fca5a5;
font-size: 9px;
line-height: 1.35;
}
.bt-detail-grid { .bt-detail-grid {
display: grid; display: grid;
grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
@@ -4282,6 +4483,8 @@ header h1 .tagline {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
gap: 6px;
flex-wrap: wrap;
} }
.bt-detail-services { .bt-detail-services {
@@ -4437,8 +4640,8 @@ header h1 .tagline {
border-left-color: var(--accent-purple) !important; border-left-color: var(--accent-purple) !important;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-width: 280px; min-width: 330px;
max-width: 320px; max-width: 420px;
max-height: 100%; max-height: 100%;
background: var(--bg-primary); background: var(--bg-primary);
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
@@ -4450,6 +4653,9 @@ header h1 .tagline {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
min-height: 0; min-height: 0;
padding: 8px 10px 12px;
background: var(--bg-primary);
overscroll-behavior: contain;
} }
.bt-device-list .wifi-device-list-header { .bt-device-list .wifi-device-list-header {
@@ -4459,6 +4665,10 @@ header h1 .tagline {
padding: 10px 12px; padding: 10px 12px;
border-bottom: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color);
flex-shrink: 0; flex-shrink: 0;
position: sticky;
top: 0;
z-index: 4;
background: var(--bg-primary);
} }
.bt-device-list .wifi-device-list-header h5 { .bt-device-list .wifi-device-list-header h5 {
@@ -4468,6 +4678,101 @@ header h1 .tagline {
font-weight: 600; font-weight: 600;
} }
.bt-list-summary {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 6px;
padding: 8px 12px;
border-bottom: 1px solid var(--border-color);
background: var(--bg-primary);
}
.bt-summary-item {
background: var(--bg-tertiary);
border: 1px solid var(--border-color);
border-radius: 4px;
padding: 5px 6px;
min-width: 0;
}
.bt-summary-label {
display: block;
font-size: 8px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.35px;
}
.bt-summary-value {
display: block;
font-size: 11px;
font-weight: 700;
color: var(--text-primary);
margin-top: 2px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.bt-list-signal-strip {
padding: 8px 12px;
border-bottom: 1px solid var(--border-color);
background: var(--bg-primary);
}
.bt-list-signal-title {
font-size: 9px;
font-weight: 600;
letter-spacing: 0.45px;
text-transform: uppercase;
color: var(--text-dim);
margin-bottom: 6px;
}
.bt-signal-dist-compact {
gap: 6px;
padding: 0;
}
.bt-signal-dist-compact .signal-range {
gap: 8px;
}
.bt-signal-dist-compact .signal-range span:first-child {
width: 50px;
font-size: 9px;
}
.bt-signal-dist-compact .signal-range span:last-child {
width: 22px;
font-size: 10px;
}
.bt-signal-dist-compact .signal-bar-bg {
height: 10px;
}
.bt-device-toolbar {
padding: 8px 12px;
border-bottom: 1px solid var(--border-color);
background: var(--bg-primary);
}
.bt-device-search {
width: 100%;
border: 1px solid var(--border-color);
border-radius: 4px;
background: var(--bg-tertiary);
color: var(--text-primary);
font-size: 11px;
padding: 7px 8px;
}
.bt-device-search:focus {
outline: none;
border-color: var(--accent-cyan);
}
/* Bluetooth Device Filters */ /* Bluetooth Device Filters */
.bt-device-filters { .bt-device-filters {
display: flex; display: flex;
@@ -4476,6 +4781,10 @@ header h1 .tagline {
border-bottom: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color);
flex-wrap: wrap; flex-wrap: wrap;
flex-shrink: 0; flex-shrink: 0;
background: var(--bg-primary);
position: sticky;
top: 44px;
z-index: 3;
} }
.bt-filter-btn { .bt-filter-btn {
@@ -4500,6 +4809,112 @@ header h1 .tagline {
color: white; color: white;
} }
.bt-tracker-item {
padding: 8px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
transition: background 0.15s ease;
cursor: pointer;
}
.bt-tracker-item:hover {
background: rgba(239, 68, 68, 0.08);
}
.bt-tracker-item:focus-visible {
outline: 1px solid var(--accent-cyan);
outline-offset: -1px;
}
.bt-tracker-row-top {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
}
.bt-tracker-left,
.bt-tracker-right {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.bt-tracker-confidence {
font-size: 9px;
padding: 2px 5px;
border-radius: 3px;
font-weight: 700;
letter-spacing: 0.2px;
}
.bt-tracker-confidence-high .bt-tracker-confidence {
color: #ef4444;
background: rgba(239, 68, 68, 0.2);
}
.bt-tracker-confidence-medium .bt-tracker-confidence {
color: #f97316;
background: rgba(249, 115, 22, 0.2);
}
.bt-tracker-confidence-low .bt-tracker-confidence {
color: #eab308;
background: rgba(234, 179, 8, 0.2);
}
.bt-tracker-type {
font-size: 11px;
color: var(--text-primary);
font-weight: 500;
}
.bt-tracker-risk {
font-size: 9px;
font-weight: 700;
}
.bt-risk-high {
color: #ef4444;
}
.bt-risk-medium {
color: #f97316;
}
.bt-risk-low {
color: var(--text-dim);
}
.bt-tracker-rssi,
.bt-tracker-seen {
font-size: 10px;
color: var(--text-dim);
}
.bt-tracker-row-bottom {
display: flex;
justify-content: space-between;
margin-top: 3px;
gap: 10px;
}
.bt-tracker-address {
font-size: 9px;
color: var(--text-dim);
font-family: var(--font-mono);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bt-tracker-evidence {
margin-top: 3px;
font-size: 9px;
color: var(--text-dim);
font-style: italic;
}
/* Bluetooth Signal Distribution */ /* Bluetooth Signal Distribution */
.bt-signal-dist { .bt-signal-dist {
display: flex; display: flex;
@@ -4569,11 +4984,20 @@ header h1 .tagline {
transition: all 0.15s ease; transition: all 0.15s ease;
} }
.bt-device-row:last-child {
margin-bottom: 0;
}
.bt-device-row:hover { .bt-device-row:hover {
background: rgba(0, 212, 255, 0.05); background: rgba(0, 212, 255, 0.05);
border-color: var(--accent-cyan); border-color: var(--accent-cyan);
} }
.bt-device-row:focus-visible {
outline: 1px solid var(--accent-cyan);
outline-offset: 1px;
}
.bt-row-main { .bt-row-main {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@@ -4711,6 +5135,50 @@ header h1 .tagline {
padding: 4px 4px 0 42px; padding: 4px 4px 0 42px;
} }
/* Locate action on Bluetooth device rows (must be in index.css so it styles in scanner mode) */
.bt-row-actions .bt-locate-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
min-height: 28px;
padding: 5px 10px;
font-size: 10px;
line-height: 1;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.07em;
color: var(--accent-green, #38c180);
background: linear-gradient(180deg, rgba(56, 193, 128, 0.2), rgba(56, 193, 128, 0.12));
border: 1px solid rgba(56, 193, 128, 0.42);
border-radius: 999px;
cursor: pointer;
white-space: nowrap;
transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
.bt-row-actions .bt-locate-btn:hover {
background: linear-gradient(180deg, rgba(56, 193, 128, 0.28), rgba(56, 193, 128, 0.18));
border-color: rgba(56, 193, 128, 0.72);
box-shadow: 0 0 0 1px rgba(56, 193, 128, 0.2), 0 6px 16px rgba(20, 80, 54, 0.35);
transform: translateY(-1px);
}
.bt-row-actions .bt-locate-btn:active {
transform: translateY(0);
}
.bt-row-actions .bt-locate-btn svg {
width: 12px;
height: 12px;
stroke: currentColor;
flex-shrink: 0;
}
.bt-device-filter-state {
margin-top: 8px;
}
/* Bluetooth Device Modal */ /* Bluetooth Device Modal */
.bt-modal-overlay { .bt-modal-overlay {
position: fixed; position: fixed;
@@ -4921,14 +5389,31 @@ header h1 .tagline {
min-height: 0; min-height: 0;
} }
.bt-layout-container .wifi-visuals { .bt-layout-container .bt-visuals-column {
max-height: 50vh; max-height: 50vh;
} }
.bt-main-area {
min-height: 0;
}
.bt-side-panels {
width: 100%;
}
.bt-tracker-list {
max-height: 280px;
}
.bt-device-list { .bt-device-list {
width: 100%; width: 100%;
min-width: auto; min-width: auto;
max-height: 300px; max-width: none;
max-height: 320px;
}
.bt-list-summary {
grid-template-columns: repeat(2, minmax(0, 1fr));
} }
} }
@@ -5208,8 +5693,11 @@ body::before {
} }
.disclaimer-modal .warning-icon { .disclaimer-modal .warning-icon {
font-size: 48px; display: block;
margin-bottom: 15px; width: 48px;
height: 48px;
margin: 0 auto 15px;
color: var(--accent-red);
} }
.disclaimer-modal p { .disclaimer-modal p {
@@ -6656,3 +7144,256 @@ body::before {
[data-animations="off"] .welcome-logo { [data-animations="off"] .welcome-logo {
animation: none !important; animation: none !important;
} }
/* ============================================
VISUAL REFRESH OVERRIDES
============================================ */
:root {
--visual-surface-soft: linear-gradient(180deg, rgba(18, 28, 40, 0.9) 0%, rgba(10, 16, 24, 0.95) 100%);
--visual-surface-panel: linear-gradient(160deg, rgba(20, 33, 48, 0.95) 0%, rgba(11, 18, 27, 0.96) 100%);
--visual-edge-cyan: rgba(74, 163, 255, 0.34);
--visual-edge-green: rgba(56, 193, 128, 0.28);
--visual-glow-soft: 0 14px 30px rgba(0, 0, 0, 0.32);
--visual-glow-cyan: 0 0 24px rgba(74, 163, 255, 0.16);
--mode-ambient-left: rgba(74, 163, 255, 0.12);
--mode-ambient-right: rgba(56, 193, 128, 0.08);
--mode-ambient-bottom: rgba(214, 168, 94, 0.05);
--top-rail-gutter: 12px;
--top-rail-gap: 6px;
--top-rail-height: 44px;
}
body {
background-image:
radial-gradient(1200px 560px at 8% -10%, var(--mode-ambient-left), transparent 60%),
radial-gradient(900px 520px at 92% -18%, var(--mode-ambient-right), transparent 60%),
radial-gradient(800px 440px at 50% 130%, var(--mode-ambient-bottom), transparent 65%),
var(--noise-image),
linear-gradient(var(--grid-line) 1px, transparent 1px),
linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
background-size: auto, auto, auto, 40px 40px, 48px 48px, 48px 48px;
}
body[data-mode="wifi"],
body[data-mode="bluetooth"],
body[data-mode="bt_locate"] {
--mode-ambient-left: rgba(56, 193, 128, 0.14);
--mode-ambient-right: rgba(74, 163, 255, 0.08);
}
body[data-mode="satellite"],
body[data-mode="weathersat"],
body[data-mode="sstv"],
body[data-mode="sstv_general"] {
--mode-ambient-left: rgba(74, 163, 255, 0.14);
--mode-ambient-right: rgba(143, 123, 214, 0.09);
--mode-ambient-bottom: rgba(56, 193, 128, 0.05);
}
body[data-mode="analytics"],
body[data-mode="spystations"],
body[data-mode="tscm"] {
--mode-ambient-left: rgba(214, 168, 94, 0.12);
--mode-ambient-right: rgba(74, 163, 255, 0.08);
}
[data-theme="light"] body {
--mode-ambient-left: rgba(31, 95, 168, 0.09);
--mode-ambient-right: rgba(31, 138, 87, 0.05);
--mode-ambient-bottom: rgba(181, 134, 58, 0.04);
}
.mode-nav {
background: linear-gradient(180deg, rgba(22, 33, 48, 0.96) 0%, rgba(14, 22, 33, 0.98) 100%);
border-bottom-color: rgba(74, 163, 255, 0.24);
}
#mainNav.mode-nav {
margin: var(--top-rail-gap) var(--top-rail-gutter) 0;
padding: 0 12px;
min-height: var(--top-rail-height);
height: var(--top-rail-height);
border: 1px solid rgba(74, 163, 255, 0.22);
border-radius: 10px;
box-shadow: var(--visual-glow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.run-state-strip {
margin: 8px var(--top-rail-gutter) 0;
border-color: rgba(74, 163, 255, 0.3);
background: linear-gradient(180deg, rgba(20, 31, 44, 0.96) 0%, rgba(12, 19, 29, 0.97) 100%);
box-shadow: var(--visual-glow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.04);
min-height: var(--top-rail-height);
padding: 6px 12px;
border-radius: 10px;
}
.run-state-strip .run-state-chip {
min-height: 22px;
padding: 2px 8px;
}
.run-state-strip .run-state-btn {
min-height: 26px;
padding: 4px 10px;
}
.run-state-strip .run-state-right {
gap: 6px;
}
.main-content {
margin: 0 12px;
border: 1px solid rgba(74, 163, 255, 0.22);
border-radius: 10px;
box-shadow: var(--visual-glow-soft), inset 0 0 0 1px rgba(255, 255, 255, 0.02);
backdrop-filter: blur(6px);
}
.sidebar {
background: var(--visual-surface-soft);
border-right-color: rgba(74, 163, 255, 0.22);
}
.section {
background: var(--visual-surface-panel);
border-color: rgba(74, 163, 255, 0.22);
border-radius: 8px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.section:hover {
border-color: var(--visual-edge-cyan);
box-shadow: var(--visual-glow-cyan), inset 0 1px 0 rgba(255, 255, 255, 0.06);
transform: translateY(-1px);
}
.section h3 {
background: linear-gradient(180deg, rgba(28, 44, 63, 0.88) 0%, rgba(20, 31, 44, 0.9) 100%);
border-bottom-color: rgba(74, 163, 255, 0.2);
}
.section h3::before {
background: linear-gradient(180deg, var(--accent-cyan) 0%, var(--accent-green) 100%);
}
.section h3::after {
background: rgba(12, 18, 28, 0.9);
border: 1px solid rgba(74, 163, 255, 0.24);
}
.form-group input,
.form-group select {
background: rgba(8, 13, 20, 0.72);
border-color: rgba(74, 163, 255, 0.2);
border-radius: 6px;
}
.preset-btn,
.control-btn,
.clear-btn,
.run-btn,
.stop-btn {
border-radius: 7px;
}
.preset-btn,
.control-btn,
.clear-btn {
border-color: rgba(74, 163, 255, 0.24);
background: linear-gradient(180deg, rgba(16, 24, 35, 0.88) 0%, rgba(10, 15, 24, 0.9) 100%);
}
.output-panel {
background: linear-gradient(180deg, rgba(8, 13, 19, 0.98) 0%, rgba(7, 11, 18, 0.99) 100%);
}
.output-header {
background: linear-gradient(180deg, rgba(18, 28, 42, 0.95) 0%, rgba(13, 21, 31, 0.98) 100%);
border-bottom-color: rgba(74, 163, 255, 0.22);
}
.output-content {
background: linear-gradient(180deg, rgba(8, 13, 19, 0.6) 0%, rgba(8, 13, 19, 0.9) 100%);
}
.stats > div {
border-color: rgba(74, 163, 255, 0.2);
background: linear-gradient(180deg, rgba(19, 28, 40, 0.8) 0%, rgba(12, 18, 27, 0.82) 100%);
}
.message {
border-color: rgba(74, 163, 255, 0.26);
border-left-width: 4px;
border-radius: 8px;
background: linear-gradient(180deg, rgba(21, 31, 44, 0.8) 0%, rgba(15, 23, 33, 0.82) 100%);
box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}
.status-bar {
position: sticky;
bottom: 0;
z-index: 9;
border-top-color: rgba(74, 163, 255, 0.24);
background: linear-gradient(180deg, rgba(17, 26, 39, 0.96) 0%, rgba(10, 16, 24, 0.97) 100%);
backdrop-filter: blur(7px);
}
.status-indicator,
.control-group {
border-color: rgba(74, 163, 255, 0.2);
background: linear-gradient(180deg, rgba(15, 23, 34, 0.78) 0%, rgba(9, 14, 23, 0.8) 100%);
border-radius: 6px;
}
.status-dot.running {
box-shadow: 0 0 0 4px rgba(56, 193, 128, 0.15), 0 0 14px rgba(56, 193, 128, 0.4);
}
.mode-content.active {
animation: modePanelEntrance 220ms ease both;
}
@keyframes modePanelEntrance {
from {
opacity: 0;
transform: translateY(5px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
[data-theme="light"] .run-state-strip,
[data-theme="light"] .main-content,
[data-theme="light"] .section,
[data-theme="light"] #mainNav.mode-nav,
[data-theme="light"] .output-header,
[data-theme="light"] .status-bar,
[data-theme="light"] .status-indicator,
[data-theme="light"] .control-group {
box-shadow: 0 10px 24px rgba(18, 40, 66, 0.08);
}
[data-theme="light"] .section,
[data-theme="light"] .stats > div,
[data-theme="light"] .message,
[data-theme="light"] .preset-btn,
[data-theme="light"] .control-btn,
[data-theme="light"] .clear-btn {
border-color: rgba(31, 95, 168, 0.26);
}
[data-animations="off"] .mode-content.active {
animation: none !important;
}
@media (max-width: 1023px) {
.run-state-strip {
margin-left: 8px;
margin-right: 8px;
}
}
+201 -3
View File
@@ -170,6 +170,23 @@
flex-shrink: 0; flex-shrink: 0;
} }
.btl-hud-export-row {
display: flex;
gap: 5px;
align-items: center;
}
.btl-hud-export-format {
min-width: 62px;
padding: 3px 6px;
font-size: 10px;
font-family: var(--font-mono);
color: var(--text-secondary);
background: rgba(0, 0, 0, 0.45);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 4px;
}
.btl-hud-audio-toggle { .btl-hud-audio-toggle {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -249,24 +266,115 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 8px; gap: 8px;
height: 100%; flex: 1;
min-height: 0;
overflow: hidden;
padding: 8px; padding: 8px;
} }
.btl-map-container { .btl-map-container {
flex: 1; flex: 1;
min-height: 250px; min-height: 250px;
position: relative;
border-radius: 8px; border-radius: 8px;
overflow: hidden; overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.1);
} }
#btLocateMap { #btLocateMap {
width: 100%; position: absolute;
height: 100%; inset: 0;
background: #1a1a2e; background: #1a1a2e;
} }
.btl-map-overlay-controls {
position: absolute;
top: 10px;
right: 10px;
z-index: 450;
display: flex;
flex-direction: column;
gap: 4px;
padding: 7px 8px;
border-radius: 7px;
background: rgba(0, 0, 0, 0.6);
border: 1px solid rgba(255, 255, 255, 0.15);
backdrop-filter: blur(4px);
}
.btl-map-overlay-toggle {
display: flex;
align-items: center;
gap: 5px;
font-size: 10px;
color: var(--text-secondary);
font-family: var(--font-mono);
cursor: pointer;
white-space: nowrap;
}
.btl-map-overlay-toggle input[type="checkbox"] {
margin: 0;
}
.btl-map-overlay-toggle input[type="checkbox"]:disabled + span {
opacity: 0.45;
}
.btl-map-heat-legend {
position: absolute;
left: 10px;
bottom: 10px;
z-index: 430;
min-width: 120px;
padding: 6px 8px;
border-radius: 7px;
background: rgba(0, 0, 0, 0.6);
border: 1px solid rgba(255, 255, 255, 0.14);
backdrop-filter: blur(4px);
}
.btl-map-heat-label {
display: block;
font-size: 9px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.7px;
margin-bottom: 4px;
}
.btl-map-heat-bar {
height: 7px;
border-radius: 4px;
background: linear-gradient(90deg, #2563eb 0%, #16a34a 40%, #f59e0b 70%, #ef4444 100%);
border: 1px solid rgba(255, 255, 255, 0.15);
}
.btl-map-heat-scale {
display: flex;
justify-content: space-between;
margin-top: 3px;
font-size: 8px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.btl-map-track-stats {
position: absolute;
right: 10px;
bottom: 10px;
z-index: 430;
padding: 5px 8px;
border-radius: 7px;
background: rgba(0, 0, 0, 0.6);
border: 1px solid rgba(255, 255, 255, 0.14);
color: var(--text-secondary);
font-size: 10px;
font-family: var(--font-mono);
backdrop-filter: blur(4px);
}
.btl-rssi-chart-container { .btl-rssi-chart-container {
height: 100px; height: 100px;
background: rgba(0, 0, 0, 0.3); background: rgba(0, 0, 0, 0.3);
@@ -426,5 +534,95 @@
flex-direction: row; flex-direction: row;
width: 100%; width: 100%;
justify-content: center; justify-content: center;
flex-wrap: wrap;
}
.btl-hud-export-row {
width: 100%;
justify-content: center;
}
.btl-map-overlay-controls {
top: 8px;
right: 8px;
gap: 3px;
padding: 6px 7px;
}
.btl-map-heat-legend {
left: 8px;
bottom: 8px;
}
.btl-map-track-stats {
right: 8px;
bottom: 8px;
font-size: 9px;
}
}
/* ── Crosshair sweep animation ───────────────────────────────────── */
.btl-crosshair-overlay {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 1200;
--btl-crosshair-x-start: 100%;
--btl-crosshair-y-start: 100%;
--btl-crosshair-x-end: 50%;
--btl-crosshair-y-end: 50%;
--btl-crosshair-duration: 1500ms;
}
.btl-crosshair-line {
position: absolute;
opacity: 0;
background: var(--accent-cyan);
will-change: transform, opacity;
}
.btl-crosshair-vertical {
top: 0;
bottom: 0;
width: 1px;
left: 0;
transform: translateX(var(--btl-crosshair-x-start));
}
.btl-crosshair-horizontal {
left: 0;
right: 0;
height: 1px;
top: 0;
transform: translateY(var(--btl-crosshair-y-start));
}
.btl-crosshair-overlay.active .btl-crosshair-vertical {
animation: btlCrosshairSweepX var(--btl-crosshair-duration) cubic-bezier(0.2, 0.85, 0.28, 1) forwards;
}
.btl-crosshair-overlay.active .btl-crosshair-horizontal {
animation: btlCrosshairSweepY var(--btl-crosshair-duration) cubic-bezier(0.2, 0.85, 0.28, 1) forwards;
}
@keyframes btlCrosshairSweepX {
0% { transform: translateX(var(--btl-crosshair-x-start)); opacity: 0; }
12% { opacity: 1; }
85% { opacity: 1; }
100% { transform: translateX(var(--btl-crosshair-x-end)); opacity: 0; }
}
@keyframes btlCrosshairSweepY {
0% { transform: translateY(var(--btl-crosshair-y-start)); opacity: 0; }
12% { opacity: 1; }
85% { opacity: 1; }
100% { transform: translateY(var(--btl-crosshair-y-end)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
.btl-crosshair-overlay.active .btl-crosshair-vertical,
.btl-crosshair-overlay.active .btl-crosshair-horizontal {
animation-duration: 220ms;
} }
} }
+56 -5
View File
@@ -140,14 +140,65 @@
} }
.gps-skyview-canvas-wrap { .gps-skyview-canvas-wrap {
display: flex; position: relative;
justify-content: center; display: block;
align-items: center; width: min(100%, 430px);
aspect-ratio: 1 / 1;
margin: 0 auto;
border: 1px solid var(--border-color);
border-radius: 6px;
background: var(--bg-primary);
overflow: hidden;
} }
#gpsSkyCanvas { #gpsSkyCanvas {
max-width: 100%; display: block;
height: auto; width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#gpsSkyCanvas:active {
cursor: grabbing;
}
.gps-sky-overlay {
position: absolute;
inset: 0;
pointer-events: none;
font-family: var(--font-mono);
}
.gps-sky-label {
position: absolute;
transform: translate(-50%, -50%);
font-size: 9px;
letter-spacing: 0.2px;
text-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
white-space: nowrap;
}
.gps-sky-label-cardinal {
font-weight: 700;
color: var(--text-secondary);
opacity: 0.85;
}
.gps-sky-label-sat {
font-weight: 600;
}
.gps-sky-label-sat.unused {
opacity: 0.75;
}
.gps-sky-hint {
margin-top: 8px;
font-size: 9px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.4px;
} }
/* Position info panel */ /* Position info panel */
+467
View File
@@ -0,0 +1,467 @@
/* Space Weather Mode Styles */
/* Main container */
.sw-visuals-container {
display: flex;
flex-direction: column;
gap: 12px;
padding: 12px;
height: 100%;
overflow-y: auto;
}
/* Header metrics strip */
.sw-header-strip {
display: flex;
align-items: center;
gap: 2px;
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 6px;
padding: 8px 12px;
flex-wrap: wrap;
}
.sw-header-stat {
display: flex;
flex-direction: column;
align-items: center;
padding: 4px 12px;
min-width: 60px;
}
.sw-header-stat + .sw-header-stat {
border-left: 1px solid var(--border-color);
}
.sw-header-value {
font-family: var(--font-mono, 'Roboto Condensed', monospace);
font-size: 18px;
font-weight: 700;
color: var(--text-primary);
line-height: 1.2;
}
.sw-header-label {
font-size: 9px;
font-weight: 600;
letter-spacing: 0.5px;
color: var(--text-dim);
text-transform: uppercase;
}
.sw-header-value.accent-cyan { color: var(--accent-cyan); }
.sw-header-value.accent-green { color: #00ff88; }
.sw-header-value.accent-yellow { color: #ffcc00; }
.sw-header-value.accent-orange { color: #ff8800; }
.sw-header-value.accent-red { color: #ff3366; }
/* Refresh controls in strip */
.sw-strip-controls {
display: flex;
align-items: center;
gap: 8px;
margin-left: auto;
padding-left: 12px;
}
.sw-refresh-btn {
background: transparent;
border: 1px solid var(--border-color);
color: var(--text-secondary);
padding: 4px 10px;
border-radius: 4px;
font-size: 11px;
cursor: pointer;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
transition: border-color 0.2s, color 0.2s;
}
.sw-refresh-btn:hover {
border-color: var(--accent-cyan);
color: var(--accent-cyan);
}
.sw-last-update {
font-size: 10px;
color: var(--text-dim);
font-family: var(--font-mono, 'Roboto Condensed', monospace);
}
/* NOAA G/S/R Scale cards */
.sw-scales-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.sw-scale-card {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 6px;
padding: 10px;
text-align: center;
}
.sw-scale-label {
font-size: 10px;
font-weight: 600;
letter-spacing: 0.5px;
color: var(--text-dim);
text-transform: uppercase;
margin-bottom: 4px;
}
.sw-scale-value {
font-family: var(--font-mono, 'Roboto Condensed', monospace);
font-size: 24px;
font-weight: 700;
line-height: 1.2;
}
.sw-scale-desc {
font-size: 10px;
color: var(--text-dim);
margin-top: 2px;
}
/* Scale severity colors */
.sw-scale-0 { color: #00ff88; border-color: #00ff8833; }
.sw-scale-1 { color: #88ff00; border-color: #88ff0033; }
.sw-scale-2 { color: #ffcc00; border-color: #ffcc0033; }
.sw-scale-3 { color: #ff8800; border-color: #ff880033; }
.sw-scale-4 { color: #ff4400; border-color: #ff440033; }
.sw-scale-5 { color: #ff0044; border-color: #ff004433; }
/* HF Band conditions grid */
.sw-band-panel {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 6px;
padding: 12px;
}
.sw-band-title {
font-size: 11px;
font-weight: 600;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 8px;
}
.sw-band-grid {
display: grid;
grid-template-columns: auto repeat(2, 1fr);
gap: 4px 8px;
font-size: 11px;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
}
.sw-band-header {
font-size: 10px;
font-weight: 600;
color: var(--text-dim);
text-transform: uppercase;
padding-bottom: 4px;
border-bottom: 1px solid var(--border-color);
}
.sw-band-name {
color: var(--text-secondary);
font-weight: 500;
}
.sw-band-cond {
text-align: center;
padding: 2px 6px;
border-radius: 3px;
font-size: 10px;
font-weight: 600;
}
.sw-band-good { color: #00ff88; background: #00ff8815; }
.sw-band-fair { color: #ffcc00; background: #ffcc0015; }
.sw-band-poor { color: #ff3366; background: #ff336615; }
/* 2-column dashboard grid */
.sw-dashboard-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
/* Chart containers */
.sw-chart-card {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 6px;
padding: 12px;
}
.sw-chart-title {
font-size: 11px;
font-weight: 600;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 8px;
}
.sw-chart-wrap {
position: relative;
height: 180px;
}
.sw-chart-wrap canvas {
width: 100% !important;
height: 100% !important;
}
/* Flare probability table */
.sw-prob-table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
}
.sw-prob-table th {
font-size: 10px;
font-weight: 600;
color: var(--text-dim);
text-transform: uppercase;
text-align: left;
padding: 4px 6px;
border-bottom: 1px solid var(--border-color);
}
.sw-prob-table td {
padding: 4px 6px;
color: var(--text-secondary);
border-bottom: 1px solid var(--border-color);
}
/* Solar image gallery */
.sw-image-panel {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 6px;
padding: 12px;
}
.sw-image-tabs {
display: flex;
gap: 4px;
margin-bottom: 8px;
}
.sw-image-tab {
background: transparent;
border: 1px solid var(--border-color);
color: var(--text-dim);
padding: 4px 10px;
border-radius: 4px;
font-size: 10px;
font-weight: 600;
cursor: pointer;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
transition: all 0.2s;
}
.sw-image-tab:hover {
border-color: var(--text-secondary);
color: var(--text-secondary);
}
.sw-image-tab.active {
border-color: var(--accent-cyan);
color: var(--accent-cyan);
background: var(--accent-cyan)10;
}
.sw-image-frame {
display: flex;
align-items: center;
justify-content: center;
min-height: 200px;
background: var(--bg-primary);
border-radius: 4px;
overflow: hidden;
}
.sw-image-frame img {
max-width: 100%;
max-height: 400px;
object-fit: contain;
border-radius: 4px;
}
/* D-RAP frequency selector */
.sw-drap-freqs {
display: flex;
gap: 4px;
margin-bottom: 8px;
flex-wrap: wrap;
}
.sw-drap-freq-btn {
background: transparent;
border: 1px solid var(--border-color);
color: var(--text-dim);
padding: 3px 8px;
border-radius: 3px;
font-size: 10px;
cursor: pointer;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
transition: all 0.2s;
}
.sw-drap-freq-btn:hover {
border-color: var(--text-secondary);
color: var(--text-secondary);
}
.sw-drap-freq-btn.active {
border-color: var(--accent-cyan);
color: var(--accent-cyan);
}
/* Alerts list */
.sw-alerts-panel {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 6px;
padding: 12px;
max-height: 300px;
overflow-y: auto;
}
.sw-alert-item {
padding: 8px;
border-bottom: 1px solid var(--border-color);
font-size: 11px;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
}
.sw-alert-item:last-child {
border-bottom: none;
}
.sw-alert-type {
font-weight: 600;
color: var(--accent-cyan);
font-size: 10px;
text-transform: uppercase;
margin-bottom: 2px;
}
.sw-alert-time {
font-size: 10px;
color: var(--text-dim);
margin-bottom: 4px;
}
.sw-alert-msg {
color: var(--text-secondary);
line-height: 1.4;
white-space: pre-wrap;
font-size: 10px;
}
/* Active regions table */
.sw-regions-panel {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 6px;
padding: 12px;
max-height: 300px;
overflow-y: auto;
}
.sw-regions-table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
}
.sw-regions-table th {
font-weight: 600;
color: var(--text-dim);
text-transform: uppercase;
text-align: left;
padding: 4px 6px;
border-bottom: 1px solid var(--border-color);
position: sticky;
top: 0;
background: var(--bg-card);
}
.sw-regions-table td {
padding: 4px 6px;
color: var(--text-secondary);
border-bottom: 1px solid var(--border-color);
}
/* Empty / loading states */
.sw-empty {
text-align: center;
padding: 20px;
color: var(--text-dim);
font-size: 11px;
font-family: var(--font-mono, 'Roboto Condensed', monospace);
}
.sw-loading {
text-align: center;
padding: 20px;
color: var(--text-dim);
font-size: 11px;
}
.sw-loading::after {
content: '';
display: inline-block;
width: 12px;
height: 12px;
border: 2px solid var(--border-color);
border-top-color: var(--accent-cyan);
border-radius: 50%;
animation: sw-spin 0.8s linear infinite;
margin-left: 8px;
vertical-align: middle;
}
@keyframes sw-spin {
to { transform: rotate(360deg); }
}
/* Full-width card */
.sw-full-width {
grid-column: 1 / -1;
}
/* Responsive */
@media (max-width: 768px) {
.sw-dashboard-grid {
grid-template-columns: 1fr;
}
.sw-scales-row {
grid-template-columns: 1fr;
}
.sw-header-strip {
gap: 0;
}
.sw-header-stat {
padding: 4px 8px;
min-width: 50px;
}
.sw-header-value {
font-size: 14px;
}
}
File diff suppressed because it is too large Load Diff
+86 -1
View File
@@ -510,8 +510,93 @@
} }
.wxsat-ground-map { .wxsat-ground-map {
position: relative;
height: 200px; height: 200px;
background: var(--bg-primary, #0d1117); overflow: hidden;
background: linear-gradient(180deg, #061329 0%, #050d1a 54%, #061325 100%);
}
.wxsat-ground-map .leaflet-container {
width: 100%;
height: 100%;
font-family: 'Roboto Condensed', 'Arial Narrow', sans-serif;
}
.leaflet-container.map-theme-cyber .leaflet-overlay-pane path.wxsat-pass-track {
filter: drop-shadow(0 0 5px rgba(91, 240, 255, 0.35));
}
.leaflet-container.map-theme-cyber .leaflet-overlay-pane path.wxsat-pass-track.lrpt {
filter: drop-shadow(0 0 6px rgba(0, 255, 190, 0.35));
}
.wxsat-crosshair-icon {
background: transparent;
border: none;
}
.wxsat-crosshair-marker {
position: relative;
width: 30px;
height: 30px;
}
.wxsat-crosshair-h,
.wxsat-crosshair-v,
.wxsat-crosshair-ring,
.wxsat-crosshair-dot {
position: absolute;
display: block;
}
.wxsat-crosshair-h {
top: 50%;
left: 2px;
right: 2px;
height: 1px;
background: rgba(255, 93, 93, 0.95);
transform: translateY(-50%);
}
.wxsat-crosshair-v {
left: 50%;
top: 2px;
bottom: 2px;
width: 1px;
background: rgba(255, 93, 93, 0.95);
transform: translateX(-50%);
}
.wxsat-crosshair-ring {
inset: 6px;
border: 1.5px solid rgba(255, 93, 93, 0.95);
border-radius: 50%;
box-shadow: 0 0 10px rgba(255, 93, 93, 0.55);
}
.wxsat-crosshair-dot {
width: 5px;
height: 5px;
left: 50%;
top: 50%;
border-radius: 50%;
background: #ffa0a0;
box-shadow: 0 0 6px rgba(255, 100, 100, 0.65);
transform: translate(-50%, -50%);
}
.wxsat-map-tooltip {
background: rgba(5, 15, 32, 0.92);
border: 1px solid rgba(102, 229, 255, 0.65);
border-radius: 4px;
color: #8fe8ff;
box-shadow: 0 0 12px rgba(0, 210, 255, 0.24);
font-size: 10px;
letter-spacing: 0.25px;
}
.wxsat-map-tooltip.leaflet-tooltip-top:before {
border-top-color: rgba(102, 229, 255, 0.65);
} }
/* ===== Image Gallery Panel ===== */ /* ===== Image Gallery Panel ===== */
+30 -2
View File
@@ -428,7 +428,7 @@
/* Visual panels should be scrollable, not clipped */ /* Visual panels should be scrollable, not clipped */
.wifi-visuals, .wifi-visuals,
.bt-visuals { .bt-visuals-column {
max-height: none !important; max-height: none !important;
overflow: visible !important; overflow: visible !important;
margin-bottom: 15px; margin-bottom: 15px;
@@ -444,7 +444,7 @@
/* Visual panels should stack in single column on mobile when visible */ /* Visual panels should stack in single column on mobile when visible */
.wifi-visuals, .wifi-visuals,
.bt-visuals { .bt-visuals-column {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 10px; gap: 10px;
@@ -465,6 +465,34 @@
.wifi-visual-panel { .wifi-visual-panel {
grid-column: auto !important; grid-column: auto !important;
} }
.bt-main-area {
flex-direction: column !important;
min-height: auto !important;
}
.bt-side-panels {
width: 100% !important;
flex-direction: column !important;
}
.bt-detail-grid {
grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}
.bt-row-secondary {
padding-left: 0 !important;
white-space: normal !important;
}
.bt-row-actions {
padding-left: 0 !important;
justify-content: flex-start !important;
}
.bt-list-summary {
grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}
} }
/* ============== MOBILE MAP FIXES ============== */ /* ============== MOBILE MAP FIXES ============== */
+48
View File
@@ -479,6 +479,54 @@
filter: sepia(0.35) hue-rotate(185deg) saturate(1.75) brightness(1.06) contrast(1.05); filter: sepia(0.35) hue-rotate(185deg) saturate(1.75) brightness(1.06) contrast(1.05);
} }
/* Global Leaflet map theme: cyber overlay */
.leaflet-container.map-theme-cyber {
position: relative;
background: #020813;
isolation: isolate;
}
.leaflet-container.map-theme-cyber .leaflet-tile-pane {
filter: sepia(0.74) hue-rotate(176deg) saturate(1.72) brightness(1.05) contrast(1.08);
opacity: 1;
}
/* Hard global fallback: enforce cyber tint on all Leaflet tile images */
html.map-cyber-enabled .leaflet-container .leaflet-tile {
filter: sepia(0.74) hue-rotate(176deg) saturate(1.72) brightness(1.05) contrast(1.08) !important;
}
/* Hard global fallback: cyber glow + grid overlay */
html.map-cyber-enabled .leaflet-container {
position: relative;
isolation: isolate;
}
html.map-cyber-enabled .leaflet-container::before {
content: '';
position: absolute;
inset: 0;
pointer-events: none;
z-index: 620;
background:
radial-gradient(95% 78% at 50% 44%, rgba(18, 170, 255, 0.17), rgba(18, 170, 255, 0) 64%),
linear-gradient(180deg, rgba(24, 118, 255, 0.045), rgba(24, 118, 255, 0));
}
html.map-cyber-enabled .leaflet-container::after {
content: '';
position: absolute;
inset: 0;
pointer-events: none;
z-index: 621;
opacity: 0.42;
mix-blend-mode: screen;
background-image:
linear-gradient(rgba(78, 188, 255, 0.14) 1px, transparent 1px),
linear-gradient(90deg, rgba(78, 188, 255, 0.14) 1px, transparent 1px);
background-size: 52px 52px, 52px 52px;
}
/* Responsive */ /* Responsive */
@media (max-width: 960px) { @media (max-width: 960px) {
.settings-tabs { .settings-tabs {
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+20
View File
@@ -0,0 +1,20 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<!-- Background -->
<rect width="100" height="100" fill="#0a0a0f"/>
<!-- Signal brackets - left side -->
<path d="M15 30 Q5 50, 15 70" stroke="#00d4ff" stroke-width="4" fill="none" stroke-linecap="round" opacity="0.5"/>
<path d="M22 35 Q14 50, 22 65" stroke="#00d4ff" stroke-width="3.5" fill="none" stroke-linecap="round" opacity="0.7"/>
<path d="M29 40 Q23 50, 29 60" stroke="#00d4ff" stroke-width="3" fill="none" stroke-linecap="round"/>
<!-- Signal brackets - right side -->
<path d="M85 30 Q95 50, 85 70" stroke="#00d4ff" stroke-width="4" fill="none" stroke-linecap="round" opacity="0.5"/>
<path d="M78 35 Q86 50, 78 65" stroke="#00d4ff" stroke-width="3.5" fill="none" stroke-linecap="round" opacity="0.7"/>
<path d="M71 40 Q77 50, 71 60" stroke="#00d4ff" stroke-width="3" fill="none" stroke-linecap="round"/>
<!-- The 'i' letter -->
<circle cx="50" cy="22" r="7" fill="#00ff88"/>
<rect x="43" y="35" width="14" height="45" rx="2" fill="#00d4ff"/>
<rect x="36" y="35" width="28" height="5" rx="1" fill="#00d4ff"/>
<rect x="36" y="75" width="28" height="5" rx="1" fill="#00d4ff"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

+2 -2
View File
@@ -1,7 +1,7 @@
/** /**
* Activity Timeline Component * Activity Timeline Component
* Reusable, configuration-driven timeline visualization for time-based metadata * Reusable, configuration-driven timeline visualization for time-based metadata
* Supports multiple modes: TSCM, Listening Post, Bluetooth, WiFi, Monitoring * Supports multiple modes: TSCM, RF Receiver, Bluetooth, WiFi, Monitoring
*/ */
const ActivityTimeline = (function() { const ActivityTimeline = (function() {
@@ -176,7 +176,7 @@ const ActivityTimeline = (function() {
*/ */
function categorizeById(id, mode) { function categorizeById(id, mode) {
// RF frequency categorization // RF frequency categorization
if (mode === 'rf' || mode === 'tscm' || mode === 'listening-post') { if (mode === 'rf' || mode === 'tscm' || mode === 'waterfall') {
const f = parseFloat(id); const f = parseFloat(id);
if (!isNaN(f)) { if (!isNaN(f)) {
if (f >= 2400 && f <= 2500) return '2.4 GHz wireless band'; if (f >= 2400 && f <= 2500) return '2.4 GHz wireless band';
+225 -78
View File
@@ -33,10 +33,7 @@ const ProximityRadar = (function() {
let activeFilter = null; let activeFilter = null;
let onDeviceClick = null; let onDeviceClick = null;
let selectedDeviceKey = null; let selectedDeviceKey = null;
let isHovered = false;
let renderPending = false;
let renderTimer = null; let renderTimer = null;
let interactionLockUntil = 0; // timestamp: suppress renders briefly after click
/** /**
* Initialize the radar component * Initialize the radar component
@@ -128,28 +125,10 @@ const ProximityRadar = (function() {
if (!deviceEl) return; if (!deviceEl) return;
const deviceKey = deviceEl.getAttribute('data-device-key'); const deviceKey = deviceEl.getAttribute('data-device-key');
if (onDeviceClick && deviceKey) { if (onDeviceClick && deviceKey) {
// Lock out re-renders briefly so the DOM stays stable after click
interactionLockUntil = Date.now() + 500;
onDeviceClick(deviceKey); onDeviceClick(deviceKey);
} }
}); });
devicesGroup.addEventListener('mouseenter', (e) => {
if (e.target.closest('.radar-device')) {
isHovered = true;
}
}, true); // capture phase so we catch enter on child elements
devicesGroup.addEventListener('mouseleave', (e) => {
if (e.target.closest('.radar-device')) {
isHovered = false;
if (renderPending) {
renderPending = false;
renderDevices();
}
}
}, true);
// Add sweep animation // Add sweep animation
animateSweep(); animateSweep();
} }
@@ -191,17 +170,10 @@ const ProximityRadar = (function() {
function updateDevices(deviceList) { function updateDevices(deviceList) {
if (isPaused) return; if (isPaused) return;
// Update device map
deviceList.forEach(device => { deviceList.forEach(device => {
devices.set(device.device_key, device); devices.set(device.device_key, device);
}); });
// Defer render while user is hovering or interacting to prevent DOM rebuild flicker
if (isHovered || Date.now() < interactionLockUntil) {
renderPending = true;
return;
}
// Debounce rapid updates (e.g. per-device SSE events) // Debounce rapid updates (e.g. per-device SSE events)
if (renderTimer) clearTimeout(renderTimer); if (renderTimer) clearTimeout(renderTimer);
renderTimer = setTimeout(() => { renderTimer = setTimeout(() => {
@@ -211,7 +183,9 @@ const ProximityRadar = (function() {
} }
/** /**
* Render device dots on the radar * Render device dots on the radar using in-place DOM updates.
* Elements are never destroyed and recreated only their attributes and
* transforms are mutated so hover state is never disturbed by a render.
*/ */
function renderDevices() { function renderDevices() {
const devicesGroup = svg.querySelector('.radar-devices'); const devicesGroup = svg.querySelector('.radar-devices');
@@ -219,6 +193,7 @@ const ProximityRadar = (function() {
const center = CONFIG.size / 2; const center = CONFIG.size / 2;
const maxRadius = center - CONFIG.padding; const maxRadius = center - CONFIG.padding;
const ns = 'http://www.w3.org/2000/svg';
// Filter devices // Filter devices
let visibleDevices = Array.from(devices.values()); let visibleDevices = Array.from(devices.values());
@@ -234,69 +209,195 @@ const ProximityRadar = (function() {
visibleDevices = visibleDevices.filter(d => !d.in_baseline); visibleDevices = visibleDevices.filter(d => !d.in_baseline);
} }
// Build SVG for each device const visibleKeys = new Set(visibleDevices.map(d => d.device_key));
const dots = visibleDevices.map(device => {
// Calculate position
const { x, y, radius } = calculateDevicePosition(device, center, maxRadius);
// Calculate dot size based on confidence // Remove elements for devices no longer in the visible set
devicesGroup.querySelectorAll('.radar-device-wrapper').forEach(el => {
if (!visibleKeys.has(el.getAttribute('data-device-key'))) {
el.remove();
}
});
// Sort weakest signal first so strongest renders on top (SVG z-order)
visibleDevices.sort((a, b) => (a.rssi_current || -100) - (b.rssi_current || -100));
// Compute all positions upfront so we can spread overlapping dots
const posMap = new Map();
visibleDevices.forEach(device => {
posMap.set(device.device_key, calculateDevicePosition(device, center, maxRadius));
});
// Spread dots that land too close together within the same band.
// minGapPx = diameter of largest possible hit area + 2px breathing room.
const maxHitArea = CONFIG.dotMaxSize + 4;
spreadOverlappingDots(Array.from(posMap.values()), center, maxHitArea * 2 + 2);
visibleDevices.forEach(device => {
const { x, y } = posMap.get(device.device_key);
const confidence = device.distance_confidence || 0.5; const confidence = device.distance_confidence || 0.5;
const dotSize = CONFIG.dotMinSize + (CONFIG.dotMaxSize - CONFIG.dotMinSize) * confidence; const dotSize = CONFIG.dotMinSize + (CONFIG.dotMaxSize - CONFIG.dotMinSize) * confidence;
// Get color based on proximity band
const color = getBandColor(device.proximity_band); const color = getBandColor(device.proximity_band);
// Check if newly seen (pulse animation)
const isNew = device.age_seconds < 5; const isNew = device.age_seconds < 5;
const pulseClass = isNew ? 'radar-dot-pulse' : ''; const isSelected = !!(selectedDeviceKey && device.device_key === selectedDeviceKey);
const isSelected = selectedDeviceKey && device.device_key === selectedDeviceKey; const hitAreaSize = dotSize + 4;
const key = device.device_key;
// Hit area size (prevents hover flicker when scaling) const existing = devicesGroup.querySelector(
const hitAreaSize = Math.max(dotSize * 2, 15); `.radar-device-wrapper[data-device-key="${CSS.escape(key)}"]`
);
return ` if (existing) {
<g transform="translate(${x}, ${y})"> // ── In-place update: mutate attributes, never recreate ──
<g class="radar-device ${pulseClass}${isSelected ? ' selected' : ''}" data-device-key="${escapeAttr(device.device_key)}" existing.setAttribute('transform', `translate(${x}, ${y})`);
style="cursor: pointer;">
<!-- Invisible hit area to prevent hover flicker -->
<circle class="radar-device-hitarea" r="${hitAreaSize}" fill="transparent" />
${isSelected ? `<circle class="radar-select-ring" r="${dotSize + 8}" fill="none" stroke="#00d4ff" stroke-width="2" stroke-opacity="0.8">
<animate attributeName="r" values="${dotSize + 6};${dotSize + 10};${dotSize + 6}" dur="1.5s" repeatCount="indefinite"/>
<animate attributeName="stroke-opacity" values="0.8;0.4;0.8" dur="1.5s" repeatCount="indefinite"/>
</circle>` : ''}
<circle r="${dotSize}" fill="${color}"
fill-opacity="${isSelected ? 1 : 0.4 + confidence * 0.5}"
stroke="${isSelected ? '#00d4ff' : color}" stroke-width="${isSelected ? 2 : 1}" />
${device.is_new && !isSelected ? `<circle r="${dotSize + 3}" fill="none" stroke="#3b82f6" stroke-width="1" stroke-dasharray="2,2" />` : ''}
<title>${escapeHtml(device.name || device.address)} (${device.rssi_current || '--'} dBm)</title>
</g>
</g>
`;
}).join('');
devicesGroup.innerHTML = dots; const innerG = existing.querySelector('.radar-device');
if (innerG) {
innerG.className.baseVal =
`radar-device${isNew ? ' radar-dot-pulse' : ''}${isSelected ? ' selected' : ''}`;
const hitArea = innerG.querySelector('.radar-device-hitarea');
if (hitArea) hitArea.setAttribute('r', hitAreaSize);
const dot = innerG.querySelector('.radar-dot');
if (dot) {
dot.setAttribute('r', dotSize);
dot.setAttribute('fill', color);
dot.setAttribute('fill-opacity', isSelected ? 1 : 0.4 + confidence * 0.5);
dot.setAttribute('stroke', isSelected ? '#00d4ff' : color);
dot.setAttribute('stroke-width', isSelected ? 2 : 1);
}
const title = innerG.querySelector('title');
if (title) {
title.textContent =
`${escapeHtml(device.name || device.address)} (${device.rssi_current || '--'} dBm)`;
}
// Selection ring: add if newly selected, remove if deselected
let ring = innerG.querySelector('.radar-select-ring');
if (isSelected && !ring) {
ring = buildSelectRing(ns, dotSize);
const hitAreaEl = innerG.querySelector('.radar-device-hitarea');
innerG.insertBefore(ring, hitAreaEl ? hitAreaEl.nextSibling : innerG.firstChild);
} else if (!isSelected && ring) {
ring.remove();
}
// New-device indicator ring
let newRing = innerG.querySelector('.radar-new-ring');
if (device.is_new && !isSelected) {
if (!newRing) {
newRing = document.createElementNS(ns, 'circle');
newRing.classList.add('radar-new-ring');
newRing.setAttribute('fill', 'none');
newRing.setAttribute('stroke', '#3b82f6');
newRing.setAttribute('stroke-width', '1');
newRing.setAttribute('stroke-dasharray', '2,2');
innerG.appendChild(newRing);
}
newRing.setAttribute('r', dotSize + 3);
} else if (newRing) {
newRing.remove();
}
}
} else {
// ── Create new element ──
const wrapperG = document.createElementNS(ns, 'g');
wrapperG.classList.add('radar-device-wrapper');
wrapperG.setAttribute('data-device-key', key);
wrapperG.setAttribute('transform', `translate(${x}, ${y})`);
const innerG = document.createElementNS(ns, 'g');
innerG.classList.add('radar-device');
if (isNew) innerG.classList.add('radar-dot-pulse');
if (isSelected) innerG.classList.add('selected');
innerG.setAttribute('data-device-key', escapeAttr(key));
innerG.style.cursor = 'pointer';
const hitArea = document.createElementNS(ns, 'circle');
hitArea.classList.add('radar-device-hitarea');
hitArea.setAttribute('r', hitAreaSize);
hitArea.setAttribute('fill', 'transparent');
innerG.appendChild(hitArea);
if (isSelected) {
innerG.appendChild(buildSelectRing(ns, dotSize));
}
const dot = document.createElementNS(ns, 'circle');
dot.classList.add('radar-dot');
dot.setAttribute('r', dotSize);
dot.setAttribute('fill', color);
dot.setAttribute('fill-opacity', isSelected ? 1 : 0.4 + confidence * 0.5);
dot.setAttribute('stroke', isSelected ? '#00d4ff' : color);
dot.setAttribute('stroke-width', isSelected ? 2 : 1);
innerG.appendChild(dot);
if (device.is_new && !isSelected) {
const newRing = document.createElementNS(ns, 'circle');
newRing.classList.add('radar-new-ring');
newRing.setAttribute('r', dotSize + 3);
newRing.setAttribute('fill', 'none');
newRing.setAttribute('stroke', '#3b82f6');
newRing.setAttribute('stroke-width', '1');
newRing.setAttribute('stroke-dasharray', '2,2');
innerG.appendChild(newRing);
}
const title = document.createElementNS(ns, 'title');
title.textContent =
`${escapeHtml(device.name || device.address)} (${device.rssi_current || '--'} dBm)`;
innerG.appendChild(title);
wrapperG.appendChild(innerG);
devicesGroup.appendChild(wrapperG);
}
});
}
/**
* Build an animated SVG selection ring element
*/
function buildSelectRing(ns, dotSize) {
const ring = document.createElementNS(ns, 'circle');
ring.classList.add('radar-select-ring');
ring.setAttribute('r', dotSize + 8);
ring.setAttribute('fill', 'none');
ring.setAttribute('stroke', '#00d4ff');
ring.setAttribute('stroke-width', '2');
ring.setAttribute('stroke-opacity', '0.8');
const animR = document.createElementNS(ns, 'animate');
animR.setAttribute('attributeName', 'r');
animR.setAttribute('values', `${dotSize + 6};${dotSize + 10};${dotSize + 6}`);
animR.setAttribute('dur', '1.5s');
animR.setAttribute('repeatCount', 'indefinite');
ring.appendChild(animR);
const animO = document.createElementNS(ns, 'animate');
animO.setAttribute('attributeName', 'stroke-opacity');
animO.setAttribute('values', '0.8;0.4;0.8');
animO.setAttribute('dur', '1.5s');
animO.setAttribute('repeatCount', 'indefinite');
ring.appendChild(animO);
return ring;
} }
/** /**
* Calculate device position on radar * Calculate device position on radar
*/ */
function calculateDevicePosition(device, center, maxRadius) { function calculateDevicePosition(device, center, maxRadius) {
// Calculate radius based on proximity band/distance // Position is band-only — the band is computed server-side from rssi_ema
// (already smoothed), so it changes infrequently and never jitters.
// Using raw estimated_distance_m caused constant micro-movement as RSSI
// fluctuated on every update cycle.
let radiusRatio; let radiusRatio;
const band = device.proximity_band || 'unknown'; switch (device.proximity_band || 'unknown') {
case 'immediate': radiusRatio = 0.15; break;
if (device.estimated_distance_m != null) { case 'near': radiusRatio = 0.40; break;
// Use actual distance (log scale) case 'far': radiusRatio = 0.70; break;
const maxDistance = 15; default: radiusRatio = 0.90; break;
radiusRatio = Math.min(1, Math.log10(device.estimated_distance_m + 1) / Math.log10(maxDistance + 1));
} else {
// Use band-based positioning
switch (band) {
case 'immediate': radiusRatio = 0.15; break;
case 'near': radiusRatio = 0.4; break;
case 'far': radiusRatio = 0.7; break;
default: radiusRatio = 0.9; break;
}
} }
// Calculate angle based on device key hash (stable positioning) // Calculate angle based on device key hash (stable positioning)
@@ -306,7 +407,53 @@ const ProximityRadar = (function() {
const x = center + Math.sin(angle) * radius; const x = center + Math.sin(angle) * radius;
const y = center - Math.cos(angle) * radius; const y = center - Math.cos(angle) * radius;
return { x, y, radius }; return { x, y, angle, radius };
}
/**
* Spread dots within the same band that land too close together.
* Groups entries by radius, sorts by angle, then nudges neighbours
* apart until the arc gap between any two dots is at least minGapPx.
* Positions are updated in-place on the entry objects.
*/
function spreadOverlappingDots(entries, center, minGapPx) {
const groups = new Map();
entries.forEach(e => {
const key = Math.round(e.radius);
if (!groups.has(key)) groups.set(key, []);
groups.get(key).push(e);
});
groups.forEach((group, r) => {
if (group.length < 2 || r < 1) return;
const minSep = minGapPx / r; // radians
group.sort((a, b) => a.angle - b.angle);
// Iterative push-apart (up to 8 passes)
for (let iter = 0; iter < 8; iter++) {
let moved = false;
for (let i = 0; i < group.length; i++) {
const j = (i + 1) % group.length;
let gap = group[j].angle - group[i].angle;
if (gap < 0) gap += 2 * Math.PI;
if (gap < minSep) {
const push = (minSep - gap) / 2;
group[i].angle -= push;
group[j].angle += push;
moved = true;
}
}
if (!moved) break;
}
// Normalise angles back to [0, 2π) and recompute x/y
group.forEach(e => {
e.angle = ((e.angle % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI);
e.x = center + Math.sin(e.angle) * r;
e.y = center - Math.cos(e.angle) * r;
});
});
} }
/** /**
-13
View File
@@ -289,19 +289,6 @@ const SignalGuess = (function() {
regions: ['GLOBAL'] regions: ['GLOBAL']
}, },
// LoRaWAN
{
label: 'LoRaWAN / LoRa Device',
tags: ['iot', 'lora', 'lpwan', 'telemetry'],
description: 'LoRa long-range IoT device',
frequencyRanges: [[863000000, 870000000], [902000000, 928000000]],
modulationHints: ['LoRa', 'CSS', 'FSK'],
bandwidthRange: [125000, 500000],
baseScore: 11,
isBurstType: true,
regions: ['UK/EU', 'US']
},
// Key Fob // Key Fob
{ {
label: 'Remote Control / Key Fob', label: 'Remote Control / Key Fob',
@@ -1,7 +1,7 @@
/** /**
* RF Signal Timeline Adapter * RF Signal Timeline Adapter
* Normalizes RF signal data for the Activity Timeline component * Normalizes RF signal data for the Activity Timeline component
* Used by: Listening Post, TSCM * Used by: Spectrum Waterfall, TSCM
*/ */
const RFTimelineAdapter = (function() { const RFTimelineAdapter = (function() {
@@ -158,12 +158,12 @@ const RFTimelineAdapter = (function() {
} }
/** /**
* Create timeline configuration for Listening Post mode * Create timeline configuration for spectrum waterfall mode.
*/ */
function getListeningPostConfig() { function getWaterfallConfig() {
return { return {
title: 'Signal Activity', title: 'Spectrum Activity',
mode: 'listening-post', mode: 'waterfall',
visualMode: 'enriched', visualMode: 'enriched',
collapsed: false, collapsed: false,
showAnnotations: true, showAnnotations: true,
@@ -188,6 +188,11 @@ const RFTimelineAdapter = (function() {
}; };
} }
// Backward compatibility alias for legacy callers.
function getListeningPostConfig() {
return getWaterfallConfig();
}
/** /**
* Create timeline configuration for TSCM mode * Create timeline configuration for TSCM mode
*/ */
@@ -224,6 +229,7 @@ const RFTimelineAdapter = (function() {
categorizeFrequency: categorizeFrequency, categorizeFrequency: categorizeFrequency,
// Configuration presets // Configuration presets
getWaterfallConfig: getWaterfallConfig,
getListeningPostConfig: getListeningPostConfig, getListeningPostConfig: getListeningPostConfig,
getTscmConfig: getTscmConfig, getTscmConfig: getTscmConfig,
+2 -2
View File
@@ -485,7 +485,7 @@ async function syncLocalModeStates() {
*/ */
function showAgentModeWarnings(runningModes, modesDetail = {}) { function showAgentModeWarnings(runningModes, modesDetail = {}) {
// SDR modes that can't run simultaneously on same device // SDR modes that can't run simultaneously on same device
const sdrModes = ['sensor', 'pager', 'adsb', 'ais', 'acars', 'aprs', 'rtlamr', 'listening_post', 'tscm', 'dsc']; const sdrModes = ['sensor', 'pager', 'adsb', 'ais', 'acars', 'vdl2', 'aprs', 'rtlamr', 'listening_post', 'tscm', 'dsc'];
const runningSdrModes = runningModes.filter(m => sdrModes.includes(m)); const runningSdrModes = runningModes.filter(m => sdrModes.includes(m));
let warning = document.getElementById('agentModeWarning'); let warning = document.getElementById('agentModeWarning');
@@ -621,7 +621,7 @@ function checkAgentModeConflict(modeToStart, deviceToUse = null) {
return false; return false;
} }
const sdrModes = ['sensor', 'pager', 'adsb', 'ais', 'acars', 'aprs', 'rtlamr', 'listening_post', 'tscm', 'dsc']; const sdrModes = ['sensor', 'pager', 'adsb', 'ais', 'acars', 'vdl2', 'aprs', 'rtlamr', 'listening_post', 'tscm', 'dsc'];
// If we're trying to start an SDR mode // If we're trying to start an SDR mode
if (sdrModes.includes(modeToStart)) { if (sdrModes.includes(modeToStart)) {
+247 -37
View File
@@ -1,11 +1,12 @@
const AlertCenter = (function() { const AlertCenter = (function() {
'use strict'; 'use strict';
const TRACKER_RULE_NAME = 'Tracker Detected';
let alerts = []; let alerts = [];
let rules = []; let rules = [];
let eventSource = null; let eventSource = null;
let reconnectTimer = null;
const TRACKER_RULE_NAME = 'Tracker Detected';
function init() { function init() {
loadRules(); loadRules();
@@ -17,6 +18,7 @@ const AlertCenter = (function() {
if (eventSource) { if (eventSource) {
eventSource.close(); eventSource.close();
} }
eventSource = new EventSource('/alerts/stream'); eventSource = new EventSource('/alerts/stream');
eventSource.onmessage = function(e) { eventSource.onmessage = function(e) {
try { try {
@@ -27,21 +29,26 @@ const AlertCenter = (function() {
console.error('[Alerts] SSE parse error', err); console.error('[Alerts] SSE parse error', err);
} }
}; };
eventSource.onerror = function() { eventSource.onerror = function() {
console.warn('[Alerts] SSE connection error'); console.warn('[Alerts] SSE connection error');
if (reconnectTimer) clearTimeout(reconnectTimer);
reconnectTimer = setTimeout(connect, 2500);
}; };
} }
function handleAlert(alert) { function handleAlert(alert) {
alerts.unshift(alert); alerts.unshift(alert);
alerts = alerts.slice(0, 50); alerts = alerts.slice(0, 60);
updateFeedUI(); updateFeedUI();
if (typeof showNotification === 'function') { const severity = String(alert.severity || '').toLowerCase();
const severity = (alert.severity || '').toLowerCase(); if (typeof showNotification === 'function' && ['high', 'critical'].includes(severity)) {
if (['high', 'critical'].includes(severity)) { showNotification(alert.title || 'Alert', alert.message || 'Alert triggered');
showNotification(alert.title || 'Alert', alert.message || 'Alert triggered'); }
}
if (typeof showAppToast === 'function' && ['high', 'critical'].includes(severity)) {
showAppToast(alert.title || 'Alert', alert.message || 'Alert triggered', 'warning');
} }
} }
@@ -56,7 +63,7 @@ const AlertCenter = (function() {
return; return;
} }
list.innerHTML = alerts.map(alert => { list.innerHTML = alerts.map((alert) => {
const title = escapeHtml(alert.title || 'Alert'); const title = escapeHtml(alert.title || 'Alert');
const message = escapeHtml(alert.message || ''); const message = escapeHtml(alert.message || '');
const severity = escapeHtml(alert.severity || 'medium'); const severity = escapeHtml(alert.severity || 'medium');
@@ -74,27 +81,218 @@ const AlertCenter = (function() {
}).join(''); }).join('');
} }
function renderRulesUI() {
const list = document.getElementById('alertsRulesList');
if (!list) return;
if (!rules.length) {
list.innerHTML = '<div class="settings-feed-empty">No rules yet</div>';
return;
}
list.innerHTML = rules.map((rule) => {
const enabled = Boolean(rule.enabled);
const mode = rule.mode || 'all';
const eventType = rule.event_type || 'any';
const severity = (rule.severity || 'medium').toUpperCase();
const match = formatMatch(rule.match);
const statusText = enabled ? 'ENABLED' : 'DISABLED';
return `
<div class="settings-feed-item" style="border-left: 2px solid ${enabled ? 'var(--accent-green)' : 'var(--text-dim)'};">
<div class="settings-feed-title" style="display:flex; gap:8px; align-items:center; justify-content:space-between;">
<span>${escapeHtml(rule.name || 'Rule')}</span>
<span style="color: var(--text-dim); font-size: 10px;">${statusText}</span>
</div>
<div class="settings-feed-meta">Mode: ${escapeHtml(mode)} | Event: ${escapeHtml(eventType)} | Severity: ${escapeHtml(severity)}</div>
<div class="settings-feed-meta">Match: ${escapeHtml(match)}</div>
<div style="display:flex; gap:8px; margin-top: 8px;">
<button class="preset-btn" style="font-size: 10px; padding: 3px 8px;" onclick="AlertCenter.editRule(${Number(rule.id)})">Edit</button>
<button class="preset-btn" style="font-size: 10px; padding: 3px 8px;" onclick="AlertCenter.toggleRule(${Number(rule.id)}, ${enabled ? 'false' : 'true'})">${enabled ? 'Disable' : 'Enable'}</button>
<button class="preset-btn" style="font-size: 10px; padding: 3px 8px; border-color: var(--accent-red); color: var(--accent-red);" onclick="AlertCenter.deleteRule(${Number(rule.id)})">Delete</button>
</div>
</div>
`;
}).join('');
}
function formatMatch(match) {
if (!match || typeof match !== 'object' || !Object.keys(match).length) {
return 'none';
}
const [k, v] = Object.entries(match)[0];
return `${k}=${v}`;
}
function loadFeed() { function loadFeed() {
fetch('/alerts/events?limit=20') fetch('/alerts/events?limit=30')
.then(r => r.json()) .then((r) => r.json())
.then(data => { .then((data) => {
if (data.status === 'success') { if (data.status === 'success') {
alerts = data.events || []; alerts = data.events || [];
updateFeedUI(); updateFeedUI();
} }
}) })
.catch(err => console.error('[Alerts] Load feed failed', err)); .catch((err) => console.error('[Alerts] Load feed failed', err));
} }
function loadRules() { function loadRules() {
fetch('/alerts/rules?all=1') return fetch('/alerts/rules?all=1')
.then(r => r.json()) .then((r) => r.json())
.then(data => { .then((data) => {
if (data.status === 'success') { if (data.status === 'success') {
rules = data.rules || []; rules = data.rules || [];
renderRulesUI();
} }
}) })
.catch(err => console.error('[Alerts] Load rules failed', err)); .catch((err) => {
console.error('[Alerts] Load rules failed', err);
if (typeof reportActionableError === 'function') {
reportActionableError('Alert Rules', err, { onRetry: loadRules });
}
});
}
function saveRule() {
const editingId = getEditingRuleId();
const payload = buildRulePayload();
if (!payload.name) {
payload.name = payload.mode ? `${payload.mode} alert` : 'Alert Rule';
}
const url = editingId ? `/alerts/rules/${editingId}` : '/alerts/rules';
const method = editingId ? 'PATCH' : 'POST';
fetch(url, {
method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
.then((r) => r.json())
.then((data) => {
if (data.status !== 'success') {
throw new Error(data.message || 'Failed to save rule');
}
clearRuleForm();
return loadRules();
})
.then(() => {
if (typeof showAppToast === 'function') {
showAppToast('Alerts', editingId ? 'Rule updated' : 'Rule created', 'info');
}
})
.catch((err) => {
if (typeof reportActionableError === 'function') {
reportActionableError('Save Alert Rule', err);
}
});
}
function buildRulePayload() {
const nameEl = document.getElementById('alertsRuleName');
const modeEl = document.getElementById('alertsRuleMode');
const eventTypeEl = document.getElementById('alertsRuleEventType');
const keyEl = document.getElementById('alertsRuleMatchKey');
const valueEl = document.getElementById('alertsRuleMatchValue');
const severityEl = document.getElementById('alertsRuleSeverity');
const match = {};
const key = keyEl ? String(keyEl.value || '').trim() : '';
const value = valueEl ? String(valueEl.value || '').trim() : '';
if (key && value) {
match[key] = value;
}
return {
name: nameEl ? String(nameEl.value || '').trim() : 'Alert Rule',
mode: modeEl ? String(modeEl.value || '').trim() || null : null,
event_type: eventTypeEl ? String(eventTypeEl.value || '').trim() || null : null,
match,
severity: severityEl ? String(severityEl.value || 'medium') : 'medium',
enabled: true,
notify: { webhook: true },
};
}
function clearRuleForm() {
setField('alertsRuleName', '');
setField('alertsRuleMode', '');
setField('alertsRuleEventType', '');
setField('alertsRuleMatchKey', '');
setField('alertsRuleMatchValue', '');
setField('alertsRuleSeverity', 'medium');
setField('alertsRuleEditingId', '');
}
function editRule(ruleId) {
const rule = rules.find((r) => Number(r.id) === Number(ruleId));
if (!rule) return;
const matchEntries = Object.entries(rule.match || {});
const firstMatch = matchEntries.length ? matchEntries[0] : ['', ''];
setField('alertsRuleName', rule.name || '');
setField('alertsRuleMode', rule.mode || '');
setField('alertsRuleEventType', rule.event_type || '');
setField('alertsRuleMatchKey', firstMatch[0] || '');
setField('alertsRuleMatchValue', firstMatch[1] == null ? '' : String(firstMatch[1]));
setField('alertsRuleSeverity', rule.severity || 'medium');
setField('alertsRuleEditingId', String(rule.id));
}
function toggleRule(ruleId, enabled) {
fetch(`/alerts/rules/${ruleId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled: Boolean(enabled) }),
})
.then((r) => r.json())
.then((data) => {
if (data.status !== 'success') {
throw new Error(data.message || 'Failed to update rule');
}
return loadRules();
})
.catch((err) => {
if (typeof reportActionableError === 'function') {
reportActionableError('Toggle Alert Rule', err);
}
});
}
function deleteRule(ruleId) {
if (!confirm('Delete this alert rule?')) return;
fetch(`/alerts/rules/${ruleId}`, { method: 'DELETE' })
.then((r) => r.json())
.then((data) => {
if (data.status !== 'success') {
throw new Error(data.message || 'Failed to delete rule');
}
if (Number(getEditingRuleId()) === Number(ruleId)) {
clearRuleForm();
}
return loadRules();
})
.catch((err) => {
if (typeof reportActionableError === 'function') {
reportActionableError('Delete Alert Rule', err);
}
});
}
function getEditingRuleId() {
const el = document.getElementById('alertsRuleEditingId');
if (!el || !el.value) return null;
const parsed = Number(el.value);
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
}
function setField(id, value) {
const el = document.getElementById(id);
if (!el) return;
el.value = value;
} }
function enableTrackerAlerts() { function enableTrackerAlerts() {
@@ -106,17 +304,18 @@ const AlertCenter = (function() {
} }
function ensureTrackerRule(enabled) { function ensureTrackerRule(enabled) {
loadRules(); loadRules().then(() => {
setTimeout(() => { const existing = rules.find((r) => r.name === TRACKER_RULE_NAME);
const existing = rules.find(r => r.name === TRACKER_RULE_NAME);
if (existing) { if (existing) {
fetch(`/alerts/rules/${existing.id}`, { return fetch(`/alerts/rules/${existing.id}`, {
method: 'PATCH', method: 'PATCH',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled }) body: JSON.stringify({ enabled }),
}).then(() => loadRules()); }).then(() => loadRules());
} else if (enabled) { }
fetch('/alerts/rules', {
if (enabled) {
return fetch('/alerts/rules', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({
@@ -126,44 +325,49 @@ const AlertCenter = (function() {
match: { is_tracker: true }, match: { is_tracker: true },
severity: 'high', severity: 'high',
enabled: true, enabled: true,
notify: { webhook: true } notify: { webhook: true },
}) }),
}).then(() => loadRules()); }).then(() => loadRules());
} }
}, 150); return null;
});
} }
function addBluetoothWatchlist(address, name) { function addBluetoothWatchlist(address, name) {
if (!address) return; if (!address) return;
const existing = rules.find(r => r.mode === 'bluetooth' && r.match && r.match.address === address); const upper = String(address).toUpperCase();
if (existing) { const existing = rules.find((r) => r.mode === 'bluetooth' && r.match && String(r.match.address || '').toUpperCase() === upper);
return; if (existing) return;
}
fetch('/alerts/rules', { fetch('/alerts/rules', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({
name: name ? `Watchlist ${name}` : `Watchlist ${address}`, name: name ? `Watchlist ${name}` : `Watchlist ${upper}`,
mode: 'bluetooth', mode: 'bluetooth',
event_type: 'device_update', event_type: 'device_update',
match: { address: address }, match: { address: upper },
severity: 'medium', severity: 'medium',
enabled: true, enabled: true,
notify: { webhook: true } notify: { webhook: true },
}) }),
}).then(() => loadRules()); }).then(() => loadRules());
} }
function removeBluetoothWatchlist(address) { function removeBluetoothWatchlist(address) {
if (!address) return; if (!address) return;
const existing = rules.find(r => r.mode === 'bluetooth' && r.match && r.match.address === address); const upper = String(address).toUpperCase();
const existing = rules.find((r) => r.mode === 'bluetooth' && r.match && String(r.match.address || '').toUpperCase() === upper);
if (!existing) return; if (!existing) return;
fetch(`/alerts/rules/${existing.id}`, { method: 'DELETE' }) fetch(`/alerts/rules/${existing.id}`, { method: 'DELETE' })
.then(() => loadRules()); .then(() => loadRules());
} }
function isWatchlisted(address) { function isWatchlisted(address) {
return rules.some(r => r.mode === 'bluetooth' && r.match && r.match.address === address && r.enabled); if (!address) return false;
const upper = String(address).toUpperCase();
return rules.some((r) => r.mode === 'bluetooth' && r.match && String(r.match.address || '').toUpperCase() === upper && r.enabled);
} }
function escapeHtml(str) { function escapeHtml(str) {
@@ -179,6 +383,12 @@ const AlertCenter = (function() {
return { return {
init, init,
loadFeed, loadFeed,
loadRules,
saveRule,
clearRuleForm,
editRule,
toggleRule,
deleteRule,
enableTrackerAlerts, enableTrackerAlerts,
disableTrackerAlerts, disableTrackerAlerts,
addBluetoothWatchlist, addBluetoothWatchlist,
+10 -19
View File
@@ -36,12 +36,12 @@ let observerLocation = (function() {
return ObserverLocation.getForModule('observerLocation'); return ObserverLocation.getForModule('observerLocation');
} }
const saved = localStorage.getItem('observerLocation'); const saved = localStorage.getItem('observerLocation');
if (saved) { if (saved) {
try { try {
const parsed = JSON.parse(saved); const parsed = JSON.parse(saved);
if (parsed.lat && parsed.lon) return parsed; if (parsed.lat !== undefined && parsed.lat !== null && parsed.lon !== undefined && parsed.lon !== null) return parsed;
} catch (e) {} } catch (e) {}
} }
return { lat: 51.5074, lon: -0.1278 }; return { lat: 51.5074, lon: -0.1278 };
})(); })();
@@ -98,7 +98,7 @@ function switchMode(mode) {
const modeMap = { const modeMap = {
'pager': 'pager', 'sensor': '433', 'aircraft': 'aircraft', 'pager': 'pager', 'sensor': '433', 'aircraft': 'aircraft',
'satellite': 'satellite', 'wifi': 'wifi', 'bluetooth': 'bluetooth', 'satellite': 'satellite', 'wifi': 'wifi', 'bluetooth': 'bluetooth',
'listening': 'listening', 'meshtastic': 'meshtastic' 'meshtastic': 'meshtastic'
}; };
document.querySelectorAll('.mode-nav-btn').forEach(btn => { document.querySelectorAll('.mode-nav-btn').forEach(btn => {
const label = btn.querySelector('.nav-label'); const label = btn.querySelector('.nav-label');
@@ -114,7 +114,6 @@ function switchMode(mode) {
document.getElementById('satelliteMode').classList.toggle('active', mode === 'satellite'); document.getElementById('satelliteMode').classList.toggle('active', mode === 'satellite');
document.getElementById('wifiMode').classList.toggle('active', mode === 'wifi'); document.getElementById('wifiMode').classList.toggle('active', mode === 'wifi');
document.getElementById('bluetoothMode').classList.toggle('active', mode === 'bluetooth'); document.getElementById('bluetoothMode').classList.toggle('active', mode === 'bluetooth');
document.getElementById('listeningPostMode').classList.toggle('active', mode === 'listening');
document.getElementById('aprsMode')?.classList.toggle('active', mode === 'aprs'); document.getElementById('aprsMode')?.classList.toggle('active', mode === 'aprs');
document.getElementById('tscmMode')?.classList.toggle('active', mode === 'tscm'); document.getElementById('tscmMode')?.classList.toggle('active', mode === 'tscm');
document.getElementById('rtlamrMode')?.classList.toggle('active', mode === 'rtlamr'); document.getElementById('rtlamrMode')?.classList.toggle('active', mode === 'rtlamr');
@@ -143,7 +142,6 @@ function switchMode(mode) {
'satellite': 'SATELLITE', 'satellite': 'SATELLITE',
'wifi': 'WIFI', 'wifi': 'WIFI',
'bluetooth': 'BLUETOOTH', 'bluetooth': 'BLUETOOTH',
'listening': 'LISTENING POST',
'tscm': 'TSCM', 'tscm': 'TSCM',
'aprs': 'APRS', 'aprs': 'APRS',
'meshtastic': 'MESHTASTIC' 'meshtastic': 'MESHTASTIC'
@@ -166,7 +164,6 @@ function switchMode(mode) {
const showRadar = document.getElementById('adsbEnableMap')?.checked; const showRadar = document.getElementById('adsbEnableMap')?.checked;
document.getElementById('aircraftVisuals').style.display = (mode === 'aircraft' && showRadar) ? 'grid' : 'none'; document.getElementById('aircraftVisuals').style.display = (mode === 'aircraft' && showRadar) ? 'grid' : 'none';
document.getElementById('satelliteVisuals').style.display = mode === 'satellite' ? 'block' : 'none'; document.getElementById('satelliteVisuals').style.display = mode === 'satellite' ? 'block' : 'none';
document.getElementById('listeningPostVisuals').style.display = mode === 'listening' ? 'grid' : 'none';
// Update output panel title based on mode // Update output panel title based on mode
const titles = { const titles = {
@@ -176,7 +173,6 @@ function switchMode(mode) {
'satellite': 'Satellite Monitor', 'satellite': 'Satellite Monitor',
'wifi': 'WiFi Scanner', 'wifi': 'WiFi Scanner',
'bluetooth': 'Bluetooth Scanner', 'bluetooth': 'Bluetooth Scanner',
'listening': 'Listening Post',
'meshtastic': 'Meshtastic Mesh Monitor' 'meshtastic': 'Meshtastic Mesh Monitor'
}; };
document.getElementById('outputTitle').textContent = titles[mode] || 'Signal Monitor'; document.getElementById('outputTitle').textContent = titles[mode] || 'Signal Monitor';
@@ -184,7 +180,7 @@ function switchMode(mode) {
// Show/hide Device Intelligence for modes that use it // Show/hide Device Intelligence for modes that use it
const reconBtn = document.getElementById('reconBtn'); const reconBtn = document.getElementById('reconBtn');
const intelBtn = document.querySelector('[onclick="exportDeviceDB()"]'); const intelBtn = document.querySelector('[onclick="exportDeviceDB()"]');
if (mode === 'satellite' || mode === 'aircraft' || mode === 'listening') { if (mode === 'satellite' || mode === 'aircraft') {
document.getElementById('reconPanel').style.display = 'none'; document.getElementById('reconPanel').style.display = 'none';
if (reconBtn) reconBtn.style.display = 'none'; if (reconBtn) reconBtn.style.display = 'none';
if (intelBtn) intelBtn.style.display = 'none'; if (intelBtn) intelBtn.style.display = 'none';
@@ -198,7 +194,7 @@ function switchMode(mode) {
// Show RTL-SDR device section for modes that use it // Show RTL-SDR device section for modes that use it
document.getElementById('rtlDeviceSection').style.display = document.getElementById('rtlDeviceSection').style.display =
(mode === 'pager' || mode === 'sensor' || mode === 'aircraft' || mode === 'listening') ? 'block' : 'none'; (mode === 'pager' || mode === 'sensor' || mode === 'aircraft') ? 'block' : 'none';
// Toggle mode-specific tool status displays // Toggle mode-specific tool status displays
document.getElementById('toolStatusPager').style.display = (mode === 'pager') ? 'grid' : 'none'; document.getElementById('toolStatusPager').style.display = (mode === 'pager') ? 'grid' : 'none';
@@ -207,7 +203,7 @@ function switchMode(mode) {
// Hide waterfall and output console for modes with their own visualizations // Hide waterfall and output console for modes with their own visualizations
document.querySelector('.waterfall-container').style.display = document.querySelector('.waterfall-container').style.display =
(mode === 'satellite' || mode === 'listening' || mode === 'aircraft' || mode === 'wifi' || mode === 'bluetooth' || mode === 'meshtastic' || mode === 'aprs' || mode === 'tscm' || mode === 'spystations') ? 'none' : 'block'; (mode === 'satellite' || mode === 'aircraft' || mode === 'wifi' || mode === 'bluetooth' || mode === 'meshtastic' || mode === 'aprs' || mode === 'tscm' || mode === 'spystations') ? 'none' : 'block';
document.getElementById('output').style.display = document.getElementById('output').style.display =
(mode === 'satellite' || mode === 'aircraft' || mode === 'wifi' || mode === 'bluetooth' || mode === 'meshtastic' || mode === 'aprs' || mode === 'tscm' || mode === 'spystations') ? 'none' : 'block'; (mode === 'satellite' || mode === 'aircraft' || mode === 'wifi' || mode === 'bluetooth' || mode === 'meshtastic' || mode === 'aprs' || mode === 'tscm' || mode === 'spystations') ? 'none' : 'block';
document.querySelector('.status-bar').style.display = (mode === 'satellite' || mode === 'tscm' || mode === 'meshtastic' || mode === 'aprs' || mode === 'spystations') ? 'none' : 'flex'; document.querySelector('.status-bar').style.display = (mode === 'satellite' || mode === 'tscm' || mode === 'meshtastic' || mode === 'aprs' || mode === 'spystations') ? 'none' : 'flex';
@@ -226,11 +222,6 @@ function switchMode(mode) {
} else if (mode === 'satellite') { } else if (mode === 'satellite') {
if (typeof initPolarPlot === 'function') initPolarPlot(); if (typeof initPolarPlot === 'function') initPolarPlot();
if (typeof initSatelliteList === 'function') initSatelliteList(); if (typeof initSatelliteList === 'function') initSatelliteList();
} else if (mode === 'listening') {
if (typeof checkScannerTools === 'function') checkScannerTools();
if (typeof checkAudioTools === 'function') checkAudioTools();
if (typeof populateScannerDeviceSelect === 'function') populateScannerDeviceSelect();
if (typeof populateAudioDeviceSelect === 'function') populateAudioDeviceSelect();
} else if (mode === 'meshtastic') { } else if (mode === 'meshtastic') {
if (typeof Meshtastic !== 'undefined' && Meshtastic.init) Meshtastic.init(); if (typeof Meshtastic !== 'undefined' && Meshtastic.init) Meshtastic.init();
} }
+74
View File
@@ -0,0 +1,74 @@
/* INTERCEPT Per-Mode Cheat Sheets */
const CheatSheets = (function () {
'use strict';
const CONTENT = {
pager: { title: 'Pager Decoder', icon: '📟', hardware: 'RTL-SDR dongle', description: 'Decodes POCSAG and FLEX pager protocols via rtl_fm + multimon-ng.', whatToExpect: 'Numeric and alphanumeric pager messages with address codes.', tips: ['Try frequencies 152.240, 157.450, 462.9625 MHz', 'Gain 3845 dB works well for most dongles', 'POCSAG 512/1200/2400 baud are common'] },
sensor: { title: '433MHz Sensors', icon: '🌡️', hardware: 'RTL-SDR dongle', description: 'Decodes 433MHz IoT sensors via rtl_433.', whatToExpect: 'JSON events from weather stations, door sensors, car key fobs.', tips: ['Leave gain on AUTO', 'Walk around to discover hidden sensors', 'Protocol filter narrows false positives'] },
wifi: { title: 'WiFi Scanner', icon: '📡', hardware: 'WiFi adapter (monitor mode)', description: 'Scans WiFi networks and clients via airodump-ng or nmcli.', whatToExpect: 'SSIDs, BSSIDs, channel, signal strength, encryption type.', tips: ['Run airmon-ng check kill before monitoring', 'Proximity radar shows signal strength', 'TSCM baseline detects rogue APs'] },
bluetooth: { title: 'Bluetooth Scanner', icon: '🔵', hardware: 'Built-in or USB Bluetooth adapter', description: 'Scans BLE and classic Bluetooth devices. Identifies trackers.', whatToExpect: 'Device names, MACs, RSSI, manufacturer, tracker type.', tips: ['Proximity radar shows device distance', 'Known tracker DB has 47K+ fingerprints', 'Use BT Locate to physically find a tracker'] },
bt_locate: { title: 'BT Locate (SAR)', icon: '🎯', hardware: 'Bluetooth adapter + optional GPS', description: 'SAR Bluetooth locator. Tracks RSSI over time to triangulate position.', whatToExpect: 'RSSI chart, proximity band (IMMEDIATE/NEAR/FAR), GPS trail.', tips: ['Handoff from Bluetooth mode to lock onto a device', 'Indoor n=3.0 gives better distance estimates', 'Follow the heat trail toward stronger signal'] },
meshtastic: { title: 'Meshtastic', icon: '🕸️', hardware: 'Meshtastic LoRa node (USB)', description: 'Monitors Meshtastic LoRa mesh network messages and positions.', whatToExpect: 'Text messages, node map, telemetry.', tips: ['Default channel must match your mesh', 'Long-Fast has best range', 'GPS nodes appear on map automatically'] },
adsb: { title: 'ADS-B Aircraft', icon: '✈️', hardware: 'RTL-SDR + 1090MHz antenna', description: 'Tracks aircraft via ADS-B Mode S transponders using dump1090.', whatToExpect: 'Flight numbers, positions, altitude, speed, squawk codes.', tips: ['1090MHz — use a dedicated antenna', 'Emergency squawks: 7500 hijack, 7600 radio fail, 7700 emergency', 'Full Dashboard shows map view'] },
ais: { title: 'AIS Vessels', icon: '🚢', hardware: 'RTL-SDR + VHF antenna (162 MHz)', description: 'Tracks marine vessels via AIS using AIS-catcher.', whatToExpect: 'MMSI, vessel names, positions, speed, heading, cargo type.', tips: ['VHF antenna centered at 162MHz works best', 'DSC distress alerts appear in red', 'Coastline range ~40 nautical miles'] },
aprs: { title: 'APRS', icon: '📻', hardware: 'RTL-SDR + VHF + direwolf', description: 'Decodes APRS amateur packet radio via direwolf TNC modem.', whatToExpect: 'Station positions, weather reports, messages, telemetry.', tips: ['Primary APRS frequency: 144.390 MHz (North America)', 'direwolf must be running', 'Positions appear on the map'] },
satellite: { title: 'Satellite Tracker', icon: '🛰️', hardware: 'None (pass prediction only)', description: 'Predicts satellite pass times using TLE data from CelesTrak.', whatToExpect: 'Pass windows with AOS/LOS times, max elevation, bearing.', tips: ['Set observer location in Settings', 'Plan ISS SSTV using pass times', 'TLEs auto-update every 24 hours'] },
sstv: { title: 'ISS SSTV', icon: '🖼️', hardware: 'RTL-SDR + 145MHz antenna', description: 'Receives ISS SSTV images via slowrx.', whatToExpect: 'Color images during ISS SSTV events (PD180 mode).', tips: ['ISS SSTV: 145.800 MHz', 'Check ARISS for active event dates', 'ISS must be overhead — check pass times'] },
weathersat: { title: 'Weather Satellites', icon: '🌤️', hardware: 'RTL-SDR + 137MHz turnstile/QFH antenna', description: 'Decodes NOAA APT and Meteor LRPT weather imagery via SatDump.', whatToExpect: 'Infrared/visible cloud imagery.', tips: ['NOAA 15/18/19: 137.1137.9 MHz APT', 'Meteor M2-3: 137.9 MHz LRPT', 'Use circular polarized antenna (QFH or turnstile)'] },
sstv_general:{ title: 'HF SSTV', icon: '📷', hardware: 'RTL-SDR + HF upconverter', description: 'Receives HF SSTV transmissions.', whatToExpect: 'Amateur radio images on 14.230 MHz (USB mode).', tips: ['14.230 MHz USB is primary HF SSTV frequency', 'Scottie 1 and Martin 1 most common', 'Best during daylight hours'] },
gps: { title: 'GPS Receiver', icon: '🗺️', hardware: 'USB GPS receiver (NMEA)', description: 'Streams GPS position and feeds location to other modes.', whatToExpect: 'Lat/lon, altitude, speed, heading, satellite count.', tips: ['BT Locate uses GPS for trail logging', 'Set observer location for satellite prediction', 'Verify a 3D fix before relying on altitude'] },
spaceweather:{ title: 'Space Weather', icon: '☀️', hardware: 'None (NOAA/SpaceWeatherLive data)', description: 'Monitors solar activity and geomagnetic storm indices.', whatToExpect: 'Kp index, solar flux, X-ray flare alerts, CME tracking.', tips: ['High Kp (≥5) = geomagnetic storm', 'X-class flares cause HF radio blackouts', 'Check before HF or satellite operations'] },
tscm: { title: 'TSCM Counter-Surveillance', icon: '🔍', hardware: 'WiFi + Bluetooth adapters', description: 'Technical Surveillance Countermeasures — detects hidden devices.', whatToExpect: 'RF baseline comparison, rogue device alerts, tracker detection.', tips: ['Take baseline in a known-clean environment', 'New strong signals = potential bug', 'Correlate WiFi + Bluetooth observations'] },
spystations: { title: 'Spy Stations', icon: '🕵️', hardware: 'RTL-SDR + HF antenna', description: 'Database of known number stations, military, and diplomatic HF signals.', whatToExpect: 'Scheduled broadcasts, frequency database, tune-to links.', tips: ['Numbers stations often broadcast on the hour', 'Use Spectrum Waterfall to tune directly', 'STANAG and HF mil signals are common'] },
websdr: { title: 'WebSDR', icon: '🌐', hardware: 'None (uses remote SDR servers)', description: 'Access remote WebSDR receivers worldwide for HF shortwave listening.', whatToExpect: 'Live audio from global HF receivers, waterfall display.', tips: ['websdr.org lists available servers', 'Good for HF when local antenna is lacking', 'Use in-app player for seamless experience'] },
subghz: { title: 'SubGHz Transceiver', icon: '📡', hardware: 'HackRF One', description: 'Transmit and receive sub-GHz RF signals for IoT and industrial protocols.', whatToExpect: 'Raw signal capture, replay, and protocol analysis.', tips: ['Only use on licensed frequencies', 'Capture mode records raw IQ for replay', 'Common: garage doors, keyfobs, 315/433/868/915 MHz'] },
rtlamr: { title: 'Utility Meter Reader', icon: '⚡', hardware: 'RTL-SDR dongle', description: 'Reads AMI/AMR smart utility meter broadcasts via rtlamr.', whatToExpect: 'Meter IDs, consumption readings, interval data.', tips: ['Most meters broadcast on 915 MHz', 'MSG types 5, 7, 13, 21 most common', 'Consumption data is read-only public broadcast'] },
waterfall: { title: 'Spectrum Waterfall', icon: '🌊', hardware: 'RTL-SDR or HackRF (WebSocket)', description: 'Full-screen real-time FFT spectrum waterfall display.', whatToExpect: 'Color-coded signal intensity scrolling over time.', tips: ['Turbo palette has best contrast for weak signals', 'Peak hold shows max power in red', 'Hover over waterfall to see frequency'] },
};
function show(mode) {
const data = CONTENT[mode];
const modal = document.getElementById('cheatSheetModal');
const content = document.getElementById('cheatSheetContent');
if (!modal || !content) return;
if (!data) {
content.innerHTML = `<p style="color:var(--text-dim); font-family:var(--font-mono);">No cheat sheet for: ${mode}</p>`;
} else {
content.innerHTML = `
<div style="font-family:var(--font-mono, monospace);">
<div style="font-size:24px; margin-bottom:4px;">${data.icon}</div>
<h2 style="margin:0 0 8px; font-size:16px; color:var(--accent-cyan, #4aa3ff);">${data.title}</h2>
<div style="font-size:11px; color:var(--text-dim); margin-bottom:12px; border-bottom:1px solid rgba(255,255,255,0.08); padding-bottom:8px;">
Hardware: <span style="color:var(--text-secondary);">${data.hardware}</span>
</div>
<p style="font-size:12px; color:var(--text-secondary); margin:0 0 12px;">${data.description}</p>
<div style="margin-bottom:12px;">
<div style="font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:0.08em; color:var(--text-dim); margin-bottom:4px;">What to expect</div>
<p style="font-size:12px; color:var(--text-secondary); margin:0;">${data.whatToExpect}</p>
</div>
<div>
<div style="font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:0.08em; color:var(--text-dim); margin-bottom:6px;">Tips</div>
<ul style="margin:0; padding-left:16px; display:flex; flex-direction:column; gap:4px;">
${data.tips.map(t => `<li style="font-size:11px; color:var(--text-secondary);">${t}</li>`).join('')}
</ul>
</div>
</div>`;
}
modal.style.display = 'flex';
}
function hide() {
const modal = document.getElementById('cheatSheetModal');
if (modal) modal.style.display = 'none';
}
function showForCurrentMode() {
const mode = document.body.getAttribute('data-mode');
if (mode) show(mode);
}
return { show, hide, showForCurrentMode };
})();
window.CheatSheets = CheatSheets;
+378
View File
@@ -0,0 +1,378 @@
const CommandPalette = (function() {
'use strict';
let overlayEl = null;
let inputEl = null;
let listEl = null;
let isOpen = false;
let activeIndex = 0;
let filteredItems = [];
const fallbackModeCommands = [
{ mode: 'pager', label: 'Pager' },
{ mode: 'sensor', label: '433MHz Sensors' },
{ mode: 'rtlamr', label: 'Meters' },
{ mode: 'subghz', label: 'SubGHz' },
{ mode: 'waterfall', label: 'Spectrum Waterfall' },
{ mode: 'aprs', label: 'APRS' },
{ mode: 'wifi', label: 'WiFi Scanner' },
{ mode: 'bluetooth', label: 'Bluetooth Scanner' },
{ mode: 'bt_locate', label: 'BT Locate' },
{ mode: 'satellite', label: 'Satellite' },
{ mode: 'sstv', label: 'ISS SSTV' },
{ mode: 'weathersat', label: 'Weather Sat' },
{ mode: 'sstv_general', label: 'HF SSTV' },
{ mode: 'gps', label: 'GPS' },
{ mode: 'meshtastic', label: 'Meshtastic' },
{ mode: 'websdr', label: 'WebSDR' },
{ mode: 'spaceweather', label: 'Space Weather' },
];
function getModeCommands() {
const commands = [];
const seenModes = new Set();
const catalog = window.interceptModeCatalog;
if (catalog && typeof catalog === 'object') {
for (const [mode, meta] of Object.entries(catalog)) {
if (!mode || seenModes.has(mode)) continue;
const label = String((meta && meta.label) || mode).trim();
commands.push({ mode, label });
seenModes.add(mode);
}
if (commands.length > 0) return commands;
}
const navNodes = document.querySelectorAll('.mode-nav-btn[data-mode], .mobile-nav-btn[data-mode]');
navNodes.forEach((node) => {
if (node.tagName === 'A') {
const href = String(node.getAttribute('href') || '');
if (href.includes('/dashboard')) return;
}
const mode = String(node.dataset.mode || '').trim();
if (!mode || seenModes.has(mode)) return;
const label = String(node.dataset.modeLabel || node.textContent || mode).trim();
commands.push({ mode, label });
seenModes.add(mode);
});
if (commands.length > 0) return commands;
return fallbackModeCommands.slice();
}
function init() {
buildDOM();
registerHotkeys();
renderItems('');
}
function buildDOM() {
overlayEl = document.createElement('div');
overlayEl.className = 'command-palette-overlay';
overlayEl.id = 'commandPaletteOverlay';
overlayEl.addEventListener('click', (event) => {
if (event.target === overlayEl) close();
});
const palette = document.createElement('div');
palette.className = 'command-palette';
const header = document.createElement('div');
header.className = 'command-palette-header';
inputEl = document.createElement('input');
inputEl.className = 'command-palette-input';
inputEl.type = 'text';
inputEl.autocomplete = 'off';
inputEl.placeholder = 'Search commands and modes...';
inputEl.setAttribute('aria-label', 'Command Palette Search');
inputEl.addEventListener('input', () => {
renderItems(inputEl.value || '');
});
inputEl.addEventListener('keydown', onInputKeyDown);
const hint = document.createElement('span');
hint.className = 'command-palette-hint';
hint.textContent = 'Esc close';
header.appendChild(inputEl);
header.appendChild(hint);
listEl = document.createElement('div');
listEl.className = 'command-palette-list';
listEl.id = 'commandPaletteList';
palette.appendChild(header);
palette.appendChild(listEl);
overlayEl.appendChild(palette);
document.body.appendChild(overlayEl);
}
function registerHotkeys() {
document.addEventListener('keydown', (event) => {
const cmdK = (event.key.toLowerCase() === 'k') && (event.ctrlKey || event.metaKey);
if (cmdK) {
event.preventDefault();
if (isOpen) {
close();
} else {
open();
}
return;
}
if (!isOpen) return;
if (event.key === 'Escape') {
event.preventDefault();
close();
}
});
}
function onInputKeyDown(event) {
if (event.key === 'ArrowDown') {
event.preventDefault();
activeIndex = Math.min(activeIndex + 1, Math.max(filteredItems.length - 1, 0));
renderSelection();
return;
}
if (event.key === 'ArrowUp') {
event.preventDefault();
activeIndex = Math.max(activeIndex - 1, 0);
renderSelection();
return;
}
if (event.key === 'Enter') {
event.preventDefault();
const item = filteredItems[activeIndex];
if (item && typeof item.run === 'function') {
item.run();
}
close();
}
}
function getCommands() {
const commands = [
{
title: 'Open Settings',
description: 'Open global settings panel',
keyword: 'settings configure tools',
shortcut: 'S',
run: () => {
if (typeof showSettings === 'function') showSettings();
}
},
{
title: 'Settings: Alerts',
description: 'Open alert rules and feed',
keyword: 'settings alerts rule',
run: () => openSettingsTab('alerts')
},
{
title: 'Settings: Recording',
description: 'Open recording manager',
keyword: 'settings recording replay',
run: () => openSettingsTab('recording')
},
{
title: 'Settings: Location',
description: 'Configure observer location',
keyword: 'settings location gps lat lon',
run: () => openSettingsTab('location')
},
{
title: 'View Aircraft Dashboard',
description: 'Open dedicated ADS-B dashboard page',
keyword: 'aircraft adsb dashboard',
run: () => {
if (window.InterceptNavPerf && typeof window.InterceptNavPerf.markStart === 'function') {
window.InterceptNavPerf.markStart({
targetPath: '/adsb/dashboard',
trigger: 'command-palette',
sourceMode: (typeof currentMode === 'string' && currentMode) ? currentMode : null,
activeScans: (typeof getActiveScanSummary === 'function') ? getActiveScanSummary() : null,
});
}
if (typeof stopActiveLocalScansForNavigation === 'function') {
stopActiveLocalScansForNavigation();
}
window.location.href = '/adsb/dashboard';
}
},
{
title: 'View Vessel Dashboard',
description: 'Open dedicated AIS dashboard page',
keyword: 'vessel ais dashboard',
run: () => {
if (window.InterceptNavPerf && typeof window.InterceptNavPerf.markStart === 'function') {
window.InterceptNavPerf.markStart({
targetPath: '/ais/dashboard',
trigger: 'command-palette',
sourceMode: (typeof currentMode === 'string' && currentMode) ? currentMode : null,
activeScans: (typeof getActiveScanSummary === 'function') ? getActiveScanSummary() : null,
});
}
if (typeof stopActiveLocalScansForNavigation === 'function') {
stopActiveLocalScansForNavigation();
}
window.location.href = '/ais/dashboard';
}
},
{
title: 'Kill All Running Processes',
description: 'Stop all decoders and scans',
keyword: 'kill stop processes emergency',
run: () => {
if (typeof killAll === 'function') {
killAll();
} else if (typeof fetch === 'function') {
fetch('/killall', { method: 'POST' });
}
}
},
{
title: 'Toggle Sidebar Width',
description: 'Collapse or expand the left sidebar',
keyword: 'sidebar collapse layout',
run: () => {
if (typeof toggleMainSidebarCollapse === 'function') {
toggleMainSidebarCollapse();
}
}
},
];
for (const modeEntry of getModeCommands()) {
commands.push({
title: `Switch Mode: ${modeEntry.label}`,
description: 'Navigate directly to mode',
keyword: `mode ${modeEntry.mode} ${modeEntry.label.toLowerCase()}`,
run: () => goToMode(modeEntry.mode),
});
}
return commands;
}
function renderItems(query) {
const q = String(query || '').trim().toLowerCase();
const allItems = getCommands();
filteredItems = allItems.filter((item) => {
if (!q) return true;
const haystack = `${item.title} ${item.description || ''} ${item.keyword || ''}`.toLowerCase();
return haystack.includes(q);
}).slice(0, 80);
activeIndex = 0;
listEl.innerHTML = '';
if (filteredItems.length === 0) {
const empty = document.createElement('div');
empty.className = 'command-palette-empty';
empty.textContent = 'No matching commands';
listEl.appendChild(empty);
return;
}
filteredItems.forEach((item, idx) => {
const row = document.createElement('button');
row.type = 'button';
row.className = 'command-palette-item';
row.dataset.index = String(idx);
row.addEventListener('click', () => {
item.run();
close();
});
const meta = document.createElement('span');
meta.className = 'meta';
const title = document.createElement('span');
title.className = 'title';
title.textContent = item.title;
meta.appendChild(title);
const desc = document.createElement('span');
desc.className = 'desc';
desc.textContent = item.description || '';
meta.appendChild(desc);
row.appendChild(meta);
if (item.shortcut) {
const kbd = document.createElement('span');
kbd.className = 'kbd';
kbd.textContent = item.shortcut;
row.appendChild(kbd);
}
listEl.appendChild(row);
});
renderSelection();
}
function renderSelection() {
const rows = listEl.querySelectorAll('.command-palette-item');
rows.forEach((row) => {
const idx = Number(row.dataset.index || 0);
row.classList.toggle('active', idx === activeIndex);
});
const activeRow = listEl.querySelector(`.command-palette-item[data-index="${activeIndex}"]`);
if (activeRow) {
activeRow.scrollIntoView({ block: 'nearest' });
}
}
function goToMode(mode) {
const welcome = document.getElementById('welcomePage');
if (welcome && getComputedStyle(welcome).display !== 'none') {
welcome.style.display = 'none';
}
if (typeof switchMode === 'function') {
switchMode(mode, { updateUrl: true });
}
}
function openSettingsTab(tab) {
if (typeof showSettings === 'function') {
showSettings();
}
if (typeof switchSettingsTab === 'function') {
switchSettingsTab(tab);
}
}
function open() {
if (!overlayEl) return;
isOpen = true;
overlayEl.classList.add('open');
renderItems('');
inputEl.value = '';
requestAnimationFrame(() => {
inputEl.focus();
});
}
function close() {
if (!overlayEl) return;
isOpen = false;
overlayEl.classList.remove('open');
}
return {
init,
open,
close,
};
})();
document.addEventListener('DOMContentLoaded', () => {
CommandPalette.init();
});
+376
View File
@@ -0,0 +1,376 @@
const FirstRunSetup = (function() {
'use strict';
const COMPLETE_KEY = 'intercept.setup.complete.v1';
const DEFAULT_MODE_KEY = 'intercept.default_mode';
let overlayEl = null;
let depsStatusEl = null;
let locationStatusEl = null;
let notifyStatusEl = null;
let modeStatusEl = null;
let modeSelectEl = null;
let dependencyReady = null;
function init() {
buildDOM();
maybeShow();
}
function maybeShow() {
if (localStorage.getItem(COMPLETE_KEY) === 'true') return;
if (localStorage.getItem('disclaimerAccepted') === 'true') {
open();
refreshStatuses();
return;
}
let attempts = 0;
const waitTimer = setInterval(() => {
attempts += 1;
if (localStorage.getItem(COMPLETE_KEY) === 'true') {
clearInterval(waitTimer);
return;
}
if (localStorage.getItem('disclaimerAccepted') === 'true') {
clearInterval(waitTimer);
open();
refreshStatuses();
}
if (attempts > 30) {
clearInterval(waitTimer);
}
}, 1000);
}
function buildDOM() {
overlayEl = document.createElement('div');
overlayEl.id = 'firstRunSetupOverlay';
overlayEl.className = 'setup-overlay';
const modal = document.createElement('div');
modal.className = 'setup-modal';
const header = document.createElement('div');
header.className = 'setup-header';
const headingWrap = document.createElement('div');
const title = document.createElement('h2');
title.className = 'setup-title';
title.textContent = 'Quick Setup';
headingWrap.appendChild(title);
const subtitle = document.createElement('p');
subtitle.className = 'setup-subtitle';
subtitle.textContent = 'Complete these checks once so all modes work reliably.';
headingWrap.appendChild(subtitle);
const closeBtn = document.createElement('button');
closeBtn.type = 'button';
closeBtn.className = 'setup-close';
closeBtn.textContent = '×';
closeBtn.setAttribute('aria-label', 'Close setup assistant');
closeBtn.addEventListener('click', close);
header.appendChild(headingWrap);
header.appendChild(closeBtn);
const content = document.createElement('div');
content.className = 'setup-content';
const depsStep = createStep(
'Dependencies',
'Verify required tools are installed for enabled modes.',
(statusEl, actionsEl) => {
depsStatusEl = statusEl;
const checkBtn = buildButton('Recheck', () => checkDependencies());
const openToolsBtn = buildButton('Open Tools', () => {
if (typeof showSettings === 'function') showSettings();
if (typeof switchSettingsTab === 'function') switchSettingsTab('tools');
});
actionsEl.appendChild(checkBtn);
actionsEl.appendChild(openToolsBtn);
}
);
const locationStep = createStep(
'Observer Location',
'Set latitude/longitude for pass prediction and mapping features.',
(statusEl, actionsEl) => {
locationStatusEl = statusEl;
actionsEl.appendChild(buildButton('Open Location', () => {
if (typeof showSettings === 'function') showSettings();
if (typeof switchSettingsTab === 'function') switchSettingsTab('location');
}));
actionsEl.appendChild(buildButton('Recheck', refreshStatuses));
}
);
const notifyStep = createStep(
'Desktop Alerts',
'Allow notifications so high-priority alerts are visible when the tab is hidden.',
(statusEl, actionsEl) => {
notifyStatusEl = statusEl;
actionsEl.appendChild(buildButton('Enable Notifications', requestNotifications));
}
);
const modeStep = createStep(
'Default Start Mode',
'Choose which mode should be selected by default.',
(statusEl, actionsEl) => {
modeStatusEl = statusEl;
modeSelectEl = document.createElement('select');
modeSelectEl.className = 'setup-btn';
const modes = [
['pager', 'Pager'],
['sensor', '433MHz'],
['rtlamr', 'Meters'],
['waterfall', 'Waterfall'],
['wifi', 'WiFi'],
['bluetooth', 'Bluetooth'],
['bt_locate', 'BT Locate'],
['aprs', 'APRS'],
['satellite', 'Satellite'],
['sstv', 'ISS SSTV'],
['weathersat', 'Weather Sat'],
['sstv_general', 'HF SSTV'],
];
for (const [value, label] of modes) {
const opt = document.createElement('option');
opt.value = value;
opt.textContent = label;
modeSelectEl.appendChild(opt);
}
const savedDefaultMode = localStorage.getItem(DEFAULT_MODE_KEY);
if (savedDefaultMode) {
const normalizedMode = savedDefaultMode === 'listening' ? 'waterfall' : savedDefaultMode;
modeSelectEl.value = normalizedMode;
if (normalizedMode !== savedDefaultMode) {
localStorage.setItem(DEFAULT_MODE_KEY, normalizedMode);
}
}
actionsEl.appendChild(modeSelectEl);
actionsEl.appendChild(buildButton('Save', () => {
const selected = modeSelectEl.value || 'pager';
localStorage.setItem(DEFAULT_MODE_KEY, selected);
refreshStatuses();
if (typeof showAppToast === 'function') {
showAppToast('Default Mode Saved', `New sessions will default to ${selected}.`, 'info');
}
}));
}
);
content.appendChild(depsStep);
content.appendChild(locationStep);
content.appendChild(notifyStep);
content.appendChild(modeStep);
const footer = document.createElement('div');
footer.className = 'setup-footer';
const note = document.createElement('span');
note.className = 'setup-footer-note';
note.textContent = 'You can reopen these options anytime in Settings.';
const footerActions = document.createElement('div');
footerActions.style.display = 'inline-flex';
footerActions.style.gap = '8px';
const laterBtn = buildButton('Remind Me Later', close);
const completeBtn = buildButton('Mark Setup Complete', completeSetup, true);
completeBtn.id = 'setupCompleteBtn';
footerActions.appendChild(laterBtn);
footerActions.appendChild(completeBtn);
footer.appendChild(note);
footer.appendChild(footerActions);
modal.appendChild(header);
modal.appendChild(content);
modal.appendChild(footer);
overlayEl.appendChild(modal);
document.body.appendChild(overlayEl);
}
function createStep(title, description, initActions) {
const root = document.createElement('div');
root.className = 'setup-step';
const header = document.createElement('div');
header.className = 'setup-step-header';
const titleEl = document.createElement('span');
titleEl.className = 'setup-step-title';
titleEl.textContent = title;
const statusEl = document.createElement('span');
statusEl.className = 'setup-step-status';
statusEl.textContent = 'Pending';
header.appendChild(titleEl);
header.appendChild(statusEl);
const descEl = document.createElement('p');
descEl.className = 'setup-step-desc';
descEl.textContent = description;
const actionsEl = document.createElement('div');
actionsEl.className = 'setup-step-actions';
if (typeof initActions === 'function') {
initActions(statusEl, actionsEl);
}
root.appendChild(header);
root.appendChild(descEl);
root.appendChild(actionsEl);
return root;
}
function buildButton(label, onClick, primary) {
const btn = document.createElement('button');
btn.type = 'button';
btn.className = `setup-btn${primary ? ' primary' : ''}`;
btn.textContent = label;
btn.addEventListener('click', onClick);
return btn;
}
async function checkDependencies() {
if (depsStatusEl) depsStatusEl.textContent = 'Checking...';
try {
const response = await fetch('/dependencies');
const data = await response.json();
if (data.status !== 'success') {
dependencyReady = false;
} else {
const modes = Object.values(data.modes || {});
dependencyReady = modes.every((modeInfo) => Boolean(modeInfo.ready));
}
} catch (err) {
dependencyReady = false;
if (typeof reportActionableError === 'function') {
reportActionableError('Dependency Check', err, {
onRetry: checkDependencies,
});
}
}
refreshStatuses();
}
function refreshStatuses() {
const hasLocation = hasValidLocation();
const notifications = notificationStatus();
const hasDefaultMode = Boolean(localStorage.getItem(DEFAULT_MODE_KEY));
setStatus(locationStatusEl, hasLocation, hasLocation ? 'Configured' : 'Not set');
setStatus(notifyStatusEl, notifications.ready, notifications.label);
setStatus(modeStatusEl, hasDefaultMode, hasDefaultMode ? localStorage.getItem(DEFAULT_MODE_KEY) : 'Not set');
if (dependencyReady === null) {
checkDependencies();
return;
}
setStatus(depsStatusEl, dependencyReady, dependencyReady ? 'Ready' : 'Missing tools');
const doneCount = Number(dependencyReady) + Number(hasLocation) + Number(notifications.ready) + Number(hasDefaultMode);
const completeBtn = document.getElementById('setupCompleteBtn');
if (completeBtn) {
completeBtn.textContent = doneCount >= 3 ? 'Mark Setup Complete' : 'Complete Anyway';
}
}
function setStatus(el, done, label) {
if (!el) return;
el.classList.toggle('done', Boolean(done));
el.textContent = String(label || (done ? 'Done' : 'Pending'));
}
function hasValidLocation() {
const rawLat = localStorage.getItem('observerLat');
const rawLon = localStorage.getItem('observerLon');
if (rawLat === null || rawLon === null || rawLat === '' || rawLon === '') {
return false;
}
const lat = Number(rawLat);
const lon = Number(rawLon);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return false;
return lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180;
}
function notificationStatus() {
if (!('Notification' in window)) {
return { ready: true, label: 'Unsupported (optional)' };
}
if (Notification.permission === 'granted') {
return { ready: true, label: 'Enabled' };
}
if (Notification.permission === 'denied') {
return { ready: false, label: 'Blocked in browser' };
}
return { ready: false, label: 'Permission needed' };
}
async function requestNotifications() {
if (!('Notification' in window)) {
refreshStatuses();
return;
}
try {
await Notification.requestPermission();
} catch (err) {
if (typeof reportActionableError === 'function') {
reportActionableError('Notifications', err);
}
}
refreshStatuses();
}
function completeSetup() {
localStorage.setItem(COMPLETE_KEY, 'true');
close();
if (typeof showAppToast === 'function') {
showAppToast('Setup Complete', 'You can revisit these options in Settings.', 'info');
}
}
function open() {
if (!overlayEl) return;
overlayEl.classList.add('open');
}
function close() {
if (!overlayEl) return;
overlayEl.classList.remove('open');
}
return {
init,
open,
close,
refreshStatuses,
completeSetup,
};
})();
document.addEventListener('DOMContentLoaded', () => {
FirstRunSetup.init();
});
+12
View File
@@ -18,6 +18,18 @@
if (menuLink) { if (menuLink) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
try {
const target = new URL(menuLink.href, window.location.href);
if (window.InterceptNavPerf && typeof window.InterceptNavPerf.markStart === 'function') {
window.InterceptNavPerf.markStart({
targetPath: target.pathname,
trigger: 'global-nav',
sourceMode: document.body?.getAttribute('data-mode') || null,
});
}
} catch (_) {
// Ignore malformed link targets.
}
window.location.href = menuLink.href; window.location.href = menuLink.href;
return; return;
} }
+72
View File
@@ -0,0 +1,72 @@
/* INTERCEPT Keyboard Shortcuts — global hotkey handler + help modal */
const KeyboardShortcuts = (function () {
'use strict';
const GUARD_SELECTOR = 'input, textarea, select, [contenteditable], .CodeMirror *';
let _handler = null;
function _handle(e) {
if (e.target.matches(GUARD_SELECTOR)) return;
if (e.altKey) {
switch (e.code) {
case 'KeyW': e.preventDefault(); window.switchMode && switchMode('waterfall'); break;
case 'KeyM': e.preventDefault(); window.VoiceAlerts && VoiceAlerts.toggleMute(); break;
case 'KeyS': e.preventDefault(); _toggleSidebar(); break;
case 'KeyK': e.preventDefault(); showHelp(); break;
case 'KeyC': e.preventDefault(); window.CheatSheets && CheatSheets.showForCurrentMode(); break;
default:
if (e.code >= 'Digit1' && e.code <= 'Digit9') {
e.preventDefault();
_switchToNthMode(parseInt(e.code.replace('Digit', '')) - 1);
}
}
} else if (!e.ctrlKey && !e.metaKey) {
if (e.key === '?') { showHelp(); }
if (e.key === 'Escape') {
const kbModal = document.getElementById('kbShortcutsModal');
if (kbModal && kbModal.style.display !== 'none') { hideHelp(); return; }
const csModal = document.getElementById('cheatSheetModal');
if (csModal && csModal.style.display !== 'none') {
window.CheatSheets && CheatSheets.hide(); return;
}
}
}
}
function _toggleSidebar() {
const mc = document.querySelector('.main-content');
if (mc) mc.classList.toggle('sidebar-collapsed');
}
function _switchToNthMode(n) {
if (!window.interceptModeCatalog) return;
const mode = document.body.getAttribute('data-mode');
if (!mode) return;
const catalog = window.interceptModeCatalog;
const entry = catalog[mode];
if (!entry) return;
const groupModes = Object.keys(catalog).filter(k => catalog[k].group === entry.group);
if (groupModes[n]) window.switchMode && switchMode(groupModes[n]);
}
function showHelp() {
const modal = document.getElementById('kbShortcutsModal');
if (modal) modal.style.display = 'flex';
}
function hideHelp() {
const modal = document.getElementById('kbShortcutsModal');
if (modal) modal.style.display = 'none';
}
function init() {
if (_handler) document.removeEventListener('keydown', _handler);
_handler = _handle;
document.addEventListener('keydown', _handler);
}
return { init, showHelp, hideHelp };
})();
window.KeyboardShortcuts = KeyboardShortcuts;
+10 -1
View File
@@ -96,7 +96,10 @@ const RecordingUI = (function() {
<div class="settings-feed-item"> <div class="settings-feed-item">
<div class="settings-feed-title"> <div class="settings-feed-title">
<span>${escapeHtml(rec.mode)}${rec.label ? `${escapeHtml(rec.label)}` : ''}</span> <span>${escapeHtml(rec.mode)}${rec.label ? `${escapeHtml(rec.label)}` : ''}</span>
<button class="preset-btn" style="font-size: 9px; padding: 2px 6px;" onclick="RecordingUI.download('${rec.id}')">Download</button> <div style="display:flex; gap:6px;">
<button class="preset-btn" style="font-size: 9px; padding: 2px 6px;" onclick="RecordingUI.openReplay('${rec.id}')">Replay</button>
<button class="preset-btn" style="font-size: 9px; padding: 2px 6px;" onclick="RecordingUI.download('${rec.id}')">Download</button>
</div>
</div> </div>
<div class="settings-feed-meta">${new Date(rec.started_at).toLocaleString()}${rec.stopped_at ? `${new Date(rec.stopped_at).toLocaleString()}` : ''}</div> <div class="settings-feed-meta">${new Date(rec.started_at).toLocaleString()}${rec.stopped_at ? `${new Date(rec.stopped_at).toLocaleString()}` : ''}</div>
<div class="settings-feed-meta">Events: ${rec.event_count || 0} ${(rec.size_bytes || 0) / 1024.0 > 0 ? (rec.size_bytes / 1024).toFixed(1) + ' KB' : '0 KB'}</div> <div class="settings-feed-meta">Events: ${rec.event_count || 0} ${(rec.size_bytes || 0) / 1024.0 > 0 ? (rec.size_bytes / 1024).toFixed(1) + ' KB' : '0 KB'}</div>
@@ -109,6 +112,11 @@ const RecordingUI = (function() {
window.open(`/recordings/${sessionId}/download`, '_blank'); window.open(`/recordings/${sessionId}/download`, '_blank');
} }
function openReplay(sessionId) {
if (!sessionId) return;
window.open(`/recordings/${sessionId}/download`, '_blank');
}
function escapeHtml(str) { function escapeHtml(str) {
if (!str) return ''; if (!str) return '';
return String(str) return String(str)
@@ -126,6 +134,7 @@ const RecordingUI = (function() {
stop, stop,
stopById, stopById,
download, download,
openReplay,
}; };
})(); })();
+238
View File
@@ -0,0 +1,238 @@
const RunState = (function() {
'use strict';
const REFRESH_MS = 5000;
const CHIP_MODES = ['pager', 'sensor', 'wifi', 'bluetooth', 'adsb', 'ais', 'acars', 'vdl2', 'aprs', 'dsc', 'subghz'];
const MODE_ALIASES = {
bt: 'bluetooth',
bt_locate: 'bluetooth',
btlocate: 'bluetooth',
aircraft: 'adsb',
};
const modeLabels = {
pager: 'Pager',
sensor: '433',
wifi: 'WiFi',
bluetooth: 'BT',
adsb: 'ADS-B',
ais: 'AIS',
acars: 'ACARS',
vdl2: 'VDL2',
aprs: 'APRS',
dsc: 'DSC',
subghz: 'SubGHz',
};
let refreshTimer = null;
let activeMode = null;
let lastHealth = null;
let lastErrorToastAt = 0;
function init() {
const root = document.getElementById('runStateStrip');
if (!root) return;
wireActions();
wrapModeSwitch();
activeMode = inferCurrentMode();
renderHealth(null);
refresh();
if (!refreshTimer) {
refreshTimer = window.setInterval(refresh, REFRESH_MS);
}
document.addEventListener('visibilitychange', () => {
if (!document.hidden) refresh();
});
}
function wireActions() {
const refreshBtn = document.getElementById('runStateRefreshBtn');
if (refreshBtn) {
refreshBtn.addEventListener('click', () => refresh());
}
const settingsBtn = document.getElementById('runStateSettingsBtn');
if (settingsBtn) {
settingsBtn.addEventListener('click', () => {
if (typeof showSettings === 'function') {
showSettings();
if (typeof switchSettingsTab === 'function') {
switchSettingsTab('tools');
}
}
});
}
}
function wrapModeSwitch() {
if (typeof window.switchMode !== 'function') return;
if (window.switchMode.__runStateWrapped) return;
const original = window.switchMode;
const wrapped = function(mode) {
if (mode) {
activeMode = normalizeMode(String(mode));
}
const result = original.apply(this, arguments);
markActiveChip();
return result;
};
wrapped.__runStateWrapped = true;
window.switchMode = wrapped;
}
async function refresh() {
try {
const response = await fetch('/health');
const data = await response.json();
lastHealth = data;
renderHealth(data);
} catch (err) {
renderHealth(null, err);
const now = Date.now();
if (typeof reportActionableError === 'function' && (now - lastErrorToastAt) > 30000) {
lastErrorToastAt = now;
reportActionableError('Run State', err, { persistent: false });
}
}
}
function renderHealth(data, err) {
const chipsContainer = document.getElementById('runStateChips');
const summaryEl = document.getElementById('runStateSummary');
if (!chipsContainer || !summaryEl) return;
chipsContainer.innerHTML = '';
if (!data || data.status !== 'healthy') {
const offline = buildChip('API', false);
offline.classList.add('active');
chipsContainer.appendChild(offline);
summaryEl.textContent = err ? `Health unavailable: ${extractMessage(err)}` : 'Health unavailable';
return;
}
const processes = normalizeProcesses(data.processes || {});
for (const mode of CHIP_MODES) {
const isRunning = Boolean(processes[mode]);
chipsContainer.appendChild(buildChip(modeLabels[mode] || mode.toUpperCase(), isRunning, mode));
}
const counts = data.data || {};
summaryEl.textContent = `Aircraft ${counts.aircraft_count || 0} | Vessels ${counts.vessel_count || 0} | WiFi ${counts.wifi_networks_count || 0} | BT ${counts.bt_devices_count || 0}`;
markActiveChip();
}
function buildChip(label, running, mode) {
const chip = document.createElement('span');
chip.className = `run-state-chip${running ? ' running' : ''}`;
if (mode) {
chip.dataset.mode = mode;
}
const dot = document.createElement('span');
dot.className = 'dot';
chip.appendChild(dot);
const text = document.createElement('span');
text.textContent = label;
chip.appendChild(text);
return chip;
}
function markActiveChip() {
if (!activeMode) {
activeMode = inferCurrentMode();
}
document.querySelectorAll('#runStateChips .run-state-chip').forEach((chip) => {
chip.classList.remove('active');
if (chip.dataset.mode && chip.dataset.mode === normalizeMode(activeMode)) {
chip.classList.add('active');
}
});
}
function inferCurrentMode() {
const modeParam = new URLSearchParams(window.location.search).get('mode');
if (modeParam) return normalizeMode(modeParam);
if (typeof window.currentMode === 'string' && window.currentMode) {
return normalizeMode(window.currentMode);
}
const indicator = document.getElementById('activeModeIndicator');
if (!indicator) return 'pager';
const text = indicator.textContent || '';
const normalized = text.toLowerCase();
if (normalized.includes('wifi')) return 'wifi';
if (normalized.includes('bluetooth')) return 'bluetooth';
if (normalized.includes('bt locate')) return 'bluetooth';
if (normalized.includes('ads-b')) return 'adsb';
if (normalized.includes('ais')) return 'ais';
if (normalized.includes('acars')) return 'acars';
if (normalized.includes('vdl2')) return 'vdl2';
if (normalized.includes('aprs')) return 'aprs';
if (normalized.includes('dsc')) return 'dsc';
if (normalized.includes('subghz')) return 'subghz';
if (normalized.includes('433')) return 'sensor';
return 'pager';
}
function normalizeMode(mode) {
const value = String(mode || '').trim().toLowerCase();
if (!value) return 'pager';
return MODE_ALIASES[value] || value;
}
function normalizeProcesses(raw) {
const processes = Object.assign({}, raw || {});
processes.bluetooth = Boolean(
processes.bluetooth ||
processes.bt ||
processes.bt_scan ||
processes.btlocate ||
processes.bt_locate
);
processes.wifi = Boolean(
processes.wifi ||
processes.wifi_scan ||
processes.wlan
);
return processes;
}
function extractMessage(err) {
if (!err) return 'Unknown error';
if (typeof err === 'string') return err;
if (err.message) return err.message;
return String(err);
}
function getLastHealth() {
return lastHealth;
}
function destroy() {
if (refreshTimer) {
clearInterval(refreshTimer);
refreshTimer = null;
}
}
return {
init,
refresh,
destroy,
getLastHealth,
};
})();
document.addEventListener('DOMContentLoaded', () => {
RunState.init();
});
+487 -54
View File
@@ -6,8 +6,8 @@ const Settings = {
// Default settings // Default settings
defaults: { defaults: {
'offline.enabled': false, 'offline.enabled': false,
'offline.assets_source': 'cdn', 'offline.assets_source': 'local',
'offline.fonts_source': 'cdn', 'offline.fonts_source': 'local',
'offline.tile_provider': 'cartodb_dark_cyan', 'offline.tile_provider': 'cartodb_dark_cyan',
'offline.tile_server_url': '' 'offline.tile_server_url': ''
}, },
@@ -22,15 +22,16 @@ const Settings = {
cartodb_dark: { cartodb_dark: {
url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png', url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png',
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OSM</a> &copy; <a href="https://carto.com/">CARTO</a>', attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OSM</a> &copy; <a href="https://carto.com/">CARTO</a>',
subdomains: 'abcd' subdomains: 'abcd',
mapTheme: 'cyber',
options: {}
}, },
cartodb_dark_cyan: { cartodb_dark_cyan: {
url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png', url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png',
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OSM</a> &copy; <a href="https://carto.com/">CARTO</a>', attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OSM</a> &copy; <a href="https://carto.com/">CARTO</a>',
subdomains: 'abcd', subdomains: 'abcd',
options: { mapTheme: 'cyber',
className: 'tile-layer-cyan' options: {}
}
}, },
cartodb_light: { cartodb_light: {
url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png',
@@ -50,26 +51,144 @@ const Settings = {
// Current settings cache // Current settings cache
_cache: {}, _cache: {},
// Init guard to prevent concurrent fetch races across pages/modes
_initialized: false,
_initPromise: null,
_themeObserver: null,
_themeObserverStarted: false,
_themeObserverRaf: null,
/**
* Check if a tile provider key is valid.
* @param {string} provider
* @returns {boolean}
*/
_isKnownTileProvider(provider) {
if (typeof provider !== 'string') return false;
const key = provider.trim();
return key === 'custom' || Object.prototype.hasOwnProperty.call(this.tileProviders, key);
},
/**
* Normalize tile provider values from storage/UI.
* @param {string} provider
* @returns {string}
*/
_normalizeTileProvider(provider) {
if (typeof provider !== 'string') return this.defaults['offline.tile_provider'];
const key = provider.trim();
if (this._isKnownTileProvider(key)) return key;
return this.defaults['offline.tile_provider'];
},
/**
* Persist and retrieve preferred map theme behavior for dark Carto tiles.
* Helps keep Cyber style enabled even if server-side tile provider drifts.
*/
_getMapThemePreference() {
if (typeof localStorage === 'undefined') return 'cyber';
const pref = localStorage.getItem('intercept_map_theme_pref');
if (pref === 'none' || pref === 'cyber') return pref;
return 'cyber';
},
_setMapThemePreference(pref) {
if (typeof localStorage === 'undefined') return;
if (pref !== 'none' && pref !== 'cyber') return;
localStorage.setItem('intercept_map_theme_pref', pref);
},
/**
* Toggle root class used for hard global Leaflet theming.
* @param {Object} [config]
*/
_syncRootMapThemeClass(config) {
if (typeof document === 'undefined' || !document.documentElement) return;
const resolvedConfig = config || this.getTileConfig();
const themeClass = this._getMapThemeClass(resolvedConfig);
document.documentElement.classList.toggle('map-cyber-enabled', themeClass === 'map-theme-cyber');
},
/**
* Prefer localStorage tile settings when available to avoid stale server values.
*/
_applyLocalTileOverrides() {
const stored = localStorage.getItem('intercept_settings');
if (!stored) return;
try {
const local = JSON.parse(stored) || {};
const localProvider = this._normalizeTileProvider(local['offline.tile_provider']);
if (localProvider) {
this._cache['offline.tile_provider'] = localProvider;
}
if (typeof local['offline.tile_server_url'] === 'string') {
this._cache['offline.tile_server_url'] = local['offline.tile_server_url'];
}
} catch (e) {
// Ignore malformed local settings and keep current cache.
}
},
/** /**
* Initialize settings - load from server/localStorage * Initialize settings - load from server/localStorage
*/ */
async init() { async init(options = {}) {
try { const force = Boolean(options && options.force);
const response = await fetch('/offline/settings');
if (response.ok) { if (!force && this._initialized) {
const data = await response.json(); return this._cache;
this._cache = { ...this.defaults, ...data.settings };
} else {
// Fall back to localStorage
this._loadFromLocalStorage();
}
} catch (e) {
console.warn('Failed to load settings from server, using localStorage:', e);
this._loadFromLocalStorage();
} }
this._updateUI(); if (!force && this._initPromise) {
return this._cache; return this._initPromise;
}
this._initPromise = (async () => {
try {
const response = await fetch('/offline/settings');
if (response.ok) {
const data = await response.json();
this._cache = { ...this.defaults, ...data.settings };
} else {
// Fall back to localStorage
this._loadFromLocalStorage();
}
} catch (e) {
console.warn('Failed to load settings from server, using localStorage:', e);
this._loadFromLocalStorage();
}
this._applyLocalTileOverrides();
this._cache['offline.tile_provider'] = this._normalizeTileProvider(this._cache['offline.tile_provider']);
// If dark Carto was restored by stale server settings but user prefers Cyber,
// keep the visible provider aligned with Cyber selection.
if (this._cache['offline.tile_provider'] === 'cartodb_dark' && this._getMapThemePreference() === 'cyber') {
this._cache['offline.tile_provider'] = 'cartodb_dark_cyan';
}
this._updateUI();
// Re-apply map theme to already-registered maps in case init happened after map creation.
const allMaps = this._collectMaps();
if (allMaps.length > 0) {
const config = this.getTileConfig();
allMaps.forEach((map) => this._applyMapTheme(map, config));
}
const activeConfig = this.getTileConfig();
this._syncRootMapThemeClass(activeConfig);
this._applyThemeToAllContainers(activeConfig);
this._ensureThemeObserver();
this._initialized = true;
return this._cache;
})();
try {
return await this._initPromise;
} finally {
this._initPromise = null;
}
}, },
/** /**
@@ -99,11 +218,14 @@ const Settings = {
// Save to server // Save to server
try { try {
await fetch('/offline/settings', { const response = await fetch('/offline/settings', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key, value }) body: JSON.stringify({ key, value })
}); });
if (!response.ok) {
throw new Error(`Save failed (${response.status})`);
}
} catch (e) { } catch (e) {
console.warn('Failed to save setting to server:', e); console.warn('Failed to save setting to server:', e);
} }
@@ -152,6 +274,16 @@ const Settings = {
* Set tile provider * Set tile provider
*/ */
async setTileProvider(provider) { async setTileProvider(provider) {
provider = this._normalizeTileProvider(provider);
if (provider === 'cartodb_dark_cyan') {
this._setMapThemePreference('cyber');
} else if (provider === 'cartodb_dark') {
this._setMapThemePreference('none');
} else {
this._setMapThemePreference('none');
}
await this._save('offline.tile_provider', provider); await this._save('offline.tile_provider', provider);
// Show/hide custom URL input // Show/hide custom URL input
@@ -160,10 +292,11 @@ const Settings = {
customRow.style.display = provider === 'custom' ? 'block' : 'none'; customRow.style.display = provider === 'custom' ? 'block' : 'none';
} }
// If not custom and we have a map, update tiles immediately // Update tiles immediately for all providers.
if (provider !== 'custom') { this._updateMapTiles();
this._updateMapTiles(); const activeConfig = this.getTileConfig();
} this._syncRootMapThemeClass(activeConfig);
this._applyThemeToAllContainers(activeConfig);
}, },
/** /**
@@ -178,7 +311,7 @@ const Settings = {
* Get current tile configuration * Get current tile configuration
*/ */
getTileConfig() { getTileConfig() {
const provider = this.get('offline.tile_provider'); const provider = this._normalizeTileProvider(this.get('offline.tile_provider'));
if (provider === 'custom') { if (provider === 'custom') {
const customUrl = this.get('offline.tile_server_url'); const customUrl = this.get('offline.tile_server_url');
@@ -189,7 +322,172 @@ const Settings = {
}; };
} }
return this.tileProviders[provider] || this.tileProviders.cartodb_dark; const config = this.tileProviders[provider] || this.tileProviders.cartodb_dark;
// Robust fallback: if dark Carto is active and Cyber is preferred,
// keep Cyber theme enabled even when provider temporarily reverts.
if (provider === 'cartodb_dark' && this._getMapThemePreference() === 'cyber') {
return { ...config, mapTheme: 'cyber' };
}
return config;
},
/**
* Resolve map theme class from tile config.
* @param {Object} config
* @returns {string|null}
*/
_getMapThemeClass(config) {
if (!config || !config.mapTheme) return null;
if (config.mapTheme === 'cyber') return 'map-theme-cyber';
return null;
},
/**
* Apply or clear map theme styles for a Leaflet container.
* @param {HTMLElement} container
* @param {Object} [config]
*/
_applyThemeToContainer(container, config) {
if (!container || !container.classList) return;
const tilePane = container.querySelector('.leaflet-tile-pane');
container.querySelectorAll('.intercept-map-theme-overlay').forEach((el) => el.remove());
if (tilePane && tilePane.style) {
tilePane.style.filter = '';
tilePane.style.opacity = '';
tilePane.style.willChange = '';
}
if (container.style) {
container.style.background = '';
}
container.classList.remove('map-theme-cyber');
const resolvedConfig = config || this.getTileConfig();
const themeClass = this._getMapThemeClass(resolvedConfig);
if (!themeClass) return;
container.classList.add(themeClass);
if (themeClass === 'map-theme-cyber') {
if (container.style) {
container.style.background = '#020813';
}
if (tilePane && tilePane.style) {
tilePane.style.filter = 'sepia(0.74) hue-rotate(176deg) saturate(1.72) brightness(1.05) contrast(1.08)';
tilePane.style.opacity = '1';
tilePane.style.willChange = 'filter';
}
}
// Map overlays are rendered via CSS pseudo elements on
// `html.map-*-enabled .leaflet-container` for consistent stacking.
},
/**
* Apply/remove map theme class on a Leaflet map container.
* @param {L.Map} map
* @param {Object} [config]
*/
_applyMapTheme(map, config) {
if (!map || typeof map.getContainer !== 'function') return;
const container = map.getContainer();
this._applyThemeToContainer(container, config);
},
/**
* Apply current map theme to all rendered Leaflet containers.
* Covers maps that were not explicitly registered with Settings.
* @param {Object} [config]
*/
_applyThemeToAllContainers(config) {
if (typeof document === 'undefined') return;
const containers = document.querySelectorAll('.leaflet-container');
if (!containers.length) return;
const resolvedConfig = config || this.getTileConfig();
this._syncRootMapThemeClass(resolvedConfig);
containers.forEach((container) => this._applyThemeToContainer(container, resolvedConfig));
},
/**
* Watch the DOM for new Leaflet maps and apply current theme automatically.
*/
_ensureThemeObserver() {
if (this._themeObserverStarted || typeof MutationObserver === 'undefined') return;
if (typeof document === 'undefined' || !document.body) return;
const scheduleApply = () => {
if (this._themeObserverRaf && typeof cancelAnimationFrame === 'function') {
cancelAnimationFrame(this._themeObserverRaf);
}
if (typeof requestAnimationFrame === 'function') {
this._themeObserverRaf = requestAnimationFrame(() => {
this._themeObserverRaf = null;
this._applyThemeToAllContainers(this.getTileConfig());
});
} else {
this._applyThemeToAllContainers(this.getTileConfig());
}
};
this._themeObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (!mutation.addedNodes || mutation.addedNodes.length === 0) continue;
for (const node of mutation.addedNodes) {
if (!(node instanceof Element)) continue;
if (node.classList.contains('leaflet-container') || node.querySelector('.leaflet-container')) {
scheduleApply();
return;
}
}
}
});
this._themeObserver.observe(document.body, {
childList: true,
subtree: true
});
this._themeObserverStarted = true;
},
/**
* Collect all known map instances.
* @returns {L.Map[]}
*/
_collectMaps() {
const windowMaps = [
window.map,
window.leafletMap,
window.aprsMap,
window.radarMap,
window.vesselMap,
window.groundMap,
window.groundTrackMap,
window.meshMap,
window.issMap
].filter(m => m && typeof m.eachLayer === 'function');
return [...new Set([...this._registeredMaps, ...windowMaps])];
},
/**
* Keep map theme stable if map internals or layers are refreshed.
* @param {L.Map} map - Leaflet map instance
*/
_attachMapThemeHooks(map) {
if (!map || typeof map.on !== 'function' || map._interceptThemeHookBound) return;
const reapplyTheme = () => this._applyMapTheme(map);
const hookEvents = ['layeradd', 'layerremove', 'zoomend', 'resize', 'load'];
hookEvents.forEach((eventName) => map.on(eventName, reapplyTheme));
map._interceptThemeHookBound = true;
map._interceptThemeHookHandler = reapplyTheme;
}, },
/** /**
@@ -200,6 +498,18 @@ const Settings = {
if (map && typeof map.eachLayer === 'function' && !this._registeredMaps.includes(map)) { if (map && typeof map.eachLayer === 'function' && !this._registeredMaps.includes(map)) {
this._registeredMaps.push(map); this._registeredMaps.push(map);
} }
this._ensureThemeObserver();
this._attachMapThemeHooks(map);
this._applyMapTheme(map);
this._applyThemeToAllContainers(this.getTileConfig());
// Some maps create tile DOM asynchronously; re-apply after first paint.
if (typeof window !== 'undefined' && typeof window.setTimeout === 'function') {
window.setTimeout(() => {
this._applyMapTheme(map);
this._applyThemeToAllContainers(this.getTileConfig());
}, 120);
}
}, },
/** /**
@@ -211,6 +521,15 @@ const Settings = {
if (idx > -1) { if (idx > -1) {
this._registeredMaps.splice(idx, 1); this._registeredMaps.splice(idx, 1);
} }
if (map && map._interceptThemeHookBound && typeof map.off === 'function') {
const handler = map._interceptThemeHookHandler;
['layeradd', 'layerremove', 'zoomend', 'resize', 'load'].forEach((eventName) => {
map.off(eventName, handler);
});
delete map._interceptThemeHookBound;
delete map._interceptThemeHookHandler;
}
}, },
/** /**
@@ -323,31 +642,29 @@ const Settings = {
if (customRow) { if (customRow) {
customRow.style.display = this.get('offline.tile_provider') === 'custom' ? 'block' : 'none'; customRow.style.display = this.get('offline.tile_provider') === 'custom' ? 'block' : 'none';
} }
// Theme select
const themeSelect = document.getElementById('themeSelect');
if (themeSelect) {
themeSelect.value = localStorage.getItem('intercept-theme') || 'dark';
}
// Animations toggle
const animationsEnabled = document.getElementById('animationsEnabled');
if (animationsEnabled) {
animationsEnabled.checked = localStorage.getItem('intercept-animations') !== 'off';
}
}, },
/** /**
* Update map tiles on all known maps * Update map tiles on all known maps
*/ */
_updateMapTiles() { _updateMapTiles() {
// Combine registered maps with common window map variables const allMaps = this._collectMaps();
const windowMaps = [
window.map,
window.leafletMap,
window.aprsMap,
window.radarMap,
window.vesselMap,
window.groundMap,
window.groundTrackMap,
window.meshMap,
window.issMap
].filter(m => m && typeof m.eachLayer === 'function');
// Combine with registered maps, removing duplicates
const allMaps = [...new Set([...this._registeredMaps, ...windowMaps])];
if (allMaps.length === 0) return; if (allMaps.length === 0) return;
const config = this.getTileConfig(); const config = this.getTileConfig();
this._syncRootMapThemeClass(config);
allMaps.forEach(map => { allMaps.forEach(map => {
// Remove existing tile layers // Remove existing tile layers
@@ -368,7 +685,10 @@ const Settings = {
} }
L.tileLayer(config.url, options).addTo(map); L.tileLayer(config.url, options).addTo(map);
this._applyMapTheme(map, config);
}); });
this._applyThemeToAllContainers(config);
}, },
/** /**
@@ -423,10 +743,16 @@ const Settings = {
}; };
// Settings modal functions // Settings modal functions
let lastSettingsFocusEl = null;
function showSettings() { function showSettings() {
const modal = document.getElementById('settingsModal'); const modal = document.getElementById('settingsModal');
if (modal) { if (modal) {
lastSettingsFocusEl = document.activeElement;
modal.classList.add('active'); modal.classList.add('active');
modal.setAttribute('aria-hidden', 'false');
const content = modal.querySelector('.settings-content');
if (content) content.focus();
Settings.init().then(() => { Settings.init().then(() => {
Settings.checkAssets(); Settings.checkAssets();
}); });
@@ -437,18 +763,27 @@ function hideSettings() {
const modal = document.getElementById('settingsModal'); const modal = document.getElementById('settingsModal');
if (modal) { if (modal) {
modal.classList.remove('active'); modal.classList.remove('active');
modal.setAttribute('aria-hidden', 'true');
if (lastSettingsFocusEl && typeof lastSettingsFocusEl.focus === 'function') {
lastSettingsFocusEl.focus();
}
} }
} }
function switchSettingsTab(tabName) { function switchSettingsTab(tabName) {
// Update tab buttons // Update tab buttons
document.querySelectorAll('.settings-tab').forEach(tab => { document.querySelectorAll('.settings-tab').forEach(tab => {
tab.classList.toggle('active', tab.dataset.tab === tabName); const isActive = tab.dataset.tab === tabName;
tab.classList.toggle('active', isActive);
tab.setAttribute('aria-selected', isActive ? 'true' : 'false');
}); });
// Update sections // Update sections
document.querySelectorAll('.settings-section').forEach(section => { document.querySelectorAll('.settings-section').forEach(section => {
section.classList.toggle('active', section.id === `settings-${tabName}`); const isActive = section.id === `settings-${tabName}`;
section.classList.toggle('active', isActive);
section.hidden = !isActive;
section.setAttribute('role', 'tabpanel');
}); });
// Load tools/dependencies when that tab is selected // Load tools/dependencies when that tab is selected
@@ -545,11 +880,6 @@ function loadSettingsTools() {
}); });
} }
// Initialize settings on page load
document.addEventListener('DOMContentLoaded', () => {
Settings.init();
});
// ============================================================================= // =============================================================================
// Location Settings Functions // Location Settings Functions
// ============================================================================= // =============================================================================
@@ -582,7 +912,7 @@ function loadObserverLocation() {
} }
// Sync dashboard-specific location keys for backward compatibility // Sync dashboard-specific location keys for backward compatibility
if (lat && lon) { if (lat !== undefined && lat !== null && lat !== '' && lon !== undefined && lon !== null && lon !== '') {
const locationObj = JSON.stringify({ lat: parseFloat(lat), lon: parseFloat(lon) }); const locationObj = JSON.stringify({ lat: parseFloat(lat), lon: parseFloat(lon) });
if (!localStorage.getItem('observerLocation')) { if (!localStorage.getItem('observerLocation')) {
localStorage.setItem('observerLocation', locationObj); localStorage.setItem('observerLocation', locationObj);
@@ -907,12 +1237,17 @@ const _originalSwitchSettingsTab = typeof switchSettingsTab !== 'undefined' ? sw
function switchSettingsTab(tabName) { function switchSettingsTab(tabName) {
// Update tab buttons // Update tab buttons
document.querySelectorAll('.settings-tab').forEach(tab => { document.querySelectorAll('.settings-tab').forEach(tab => {
tab.classList.toggle('active', tab.dataset.tab === tabName); const isActive = tab.dataset.tab === tabName;
tab.classList.toggle('active', isActive);
tab.setAttribute('aria-selected', isActive ? 'true' : 'false');
}); });
// Update sections // Update sections
document.querySelectorAll('.settings-section').forEach(section => { document.querySelectorAll('.settings-section').forEach(section => {
section.classList.toggle('active', section.id === `settings-${tabName}`); const isActive = section.id === `settings-${tabName}`;
section.classList.toggle('active', isActive);
section.hidden = !isActive;
section.setAttribute('role', 'tabpanel');
}); });
// Load content based on tab // Load content based on tab
@@ -923,6 +1258,7 @@ function switchSettingsTab(tabName) {
} else if (tabName === 'location') { } else if (tabName === 'location') {
loadObserverLocation(); loadObserverLocation();
} else if (tabName === 'alerts') { } else if (tabName === 'alerts') {
loadVoiceAlertConfig();
if (typeof AlertCenter !== 'undefined') { if (typeof AlertCenter !== 'undefined') {
AlertCenter.loadFeed(); AlertCenter.loadFeed();
} }
@@ -935,6 +1271,61 @@ function switchSettingsTab(tabName) {
} }
} }
/**
* Load voice alert configuration into Settings > Alerts tab
*/
function loadVoiceAlertConfig() {
if (typeof VoiceAlerts === 'undefined') return;
const cfg = VoiceAlerts.getConfig();
const pager = document.getElementById('voiceCfgPager');
const tscm = document.getElementById('voiceCfgTscm');
const tracker = document.getElementById('voiceCfgTracker');
const squawk = document.getElementById('voiceCfgSquawk');
const rate = document.getElementById('voiceCfgRate');
const pitch = document.getElementById('voiceCfgPitch');
const rateVal = document.getElementById('voiceCfgRateVal');
const pitchVal = document.getElementById('voiceCfgPitchVal');
if (pager) pager.checked = cfg.streams.pager !== false;
if (tscm) tscm.checked = cfg.streams.tscm !== false;
if (tracker) tracker.checked = cfg.streams.bluetooth !== false;
if (squawk) squawk.checked = cfg.streams.squawks !== false;
if (rate) rate.value = cfg.rate;
if (pitch) pitch.value = cfg.pitch;
if (rateVal) rateVal.textContent = cfg.rate;
if (pitchVal) pitchVal.textContent = cfg.pitch;
// Populate voice dropdown
VoiceAlerts.getAvailableVoices().then(function (voices) {
var sel = document.getElementById('voiceCfgVoice');
if (!sel) return;
sel.innerHTML = '<option value="">Default</option>' +
voices.filter(function (v) { return v.lang.startsWith('en'); }).map(function (v) {
return '<option value="' + v.name + '"' + (v.name === cfg.voiceName ? ' selected' : '') + '>' + v.name + '</option>';
}).join('');
});
}
function saveVoiceAlertConfig() {
if (typeof VoiceAlerts === 'undefined') return;
VoiceAlerts.setConfig({
rate: parseFloat(document.getElementById('voiceCfgRate')?.value) || 1.1,
pitch: parseFloat(document.getElementById('voiceCfgPitch')?.value) || 0.9,
voiceName: document.getElementById('voiceCfgVoice')?.value || '',
streams: {
pager: !!document.getElementById('voiceCfgPager')?.checked,
tscm: !!document.getElementById('voiceCfgTscm')?.checked,
bluetooth: !!document.getElementById('voiceCfgTracker')?.checked,
squawks: !!document.getElementById('voiceCfgSquawk')?.checked,
},
});
}
function testVoiceAlert() {
if (typeof VoiceAlerts !== 'undefined') VoiceAlerts.testVoice();
}
/** /**
* Load API key status into the API Keys settings tab * Load API key status into the API Keys settings tab
*/ */
@@ -983,3 +1374,45 @@ function toggleApiKeyVisibility() {
if (!input) return; if (!input) return;
input.type = input.type === 'password' ? 'text' : 'password'; input.type = input.type === 'password' ? 'text' : 'password';
} }
/**
* Set theme preference from the Display settings tab
*/
function setThemePreference(value) {
document.documentElement.setAttribute('data-theme', value);
localStorage.setItem('intercept-theme', value);
const btn = document.getElementById('themeToggle');
if (btn) {
btn.textContent = value === 'light' ? '🌙' : '☀️';
}
fetch('/settings', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ theme: value })
}).catch(() => {});
}
/**
* Set animations preference from the Display settings tab
*/
function setAnimationsEnabled(enabled) {
if (enabled) {
document.documentElement.removeAttribute('data-animations');
} else {
document.documentElement.setAttribute('data-animations', 'off');
}
localStorage.setItem('intercept-animations', enabled ? 'on' : 'off');
}
if (!window._settingsEscapeHandlerBound) {
window._settingsEscapeHandlerBound = true;
document.addEventListener('keydown', (event) => {
if (event.key !== 'Escape') return;
const modal = document.getElementById('settingsModal');
if (modal && modal.classList.contains('active')) {
hideSettings();
}
});
}
+248
View File
@@ -0,0 +1,248 @@
const AppFeedback = (function() {
'use strict';
let stackEl = null;
let nextToastId = 1;
function init() {
ensureStack();
installGlobalHandlers();
}
function ensureStack() {
if (stackEl && document.body.contains(stackEl)) return stackEl;
stackEl = document.getElementById('appToastStack');
if (!stackEl) {
stackEl = document.createElement('div');
stackEl.id = 'appToastStack';
stackEl.className = 'app-toast-stack';
document.body.appendChild(stackEl);
}
return stackEl;
}
function toast(options) {
const opts = options || {};
const type = normalizeType(opts.type);
const id = nextToastId++;
const durationMs = Number.isFinite(opts.durationMs) ? opts.durationMs : 6500;
const root = document.createElement('div');
root.className = `app-toast ${type}`;
root.dataset.toastId = String(id);
const titleEl = document.createElement('div');
titleEl.className = 'app-toast-title';
titleEl.textContent = String(opts.title || defaultTitle(type));
root.appendChild(titleEl);
const msgEl = document.createElement('div');
msgEl.className = 'app-toast-msg';
msgEl.textContent = String(opts.message || '');
root.appendChild(msgEl);
const actions = Array.isArray(opts.actions) ? opts.actions.filter(Boolean).slice(0, 3) : [];
if (actions.length > 0) {
const actionsEl = document.createElement('div');
actionsEl.className = 'app-toast-actions';
for (const action of actions) {
const btn = document.createElement('button');
btn.type = 'button';
btn.textContent = String(action.label || 'Action');
btn.addEventListener('click', () => {
try {
if (typeof action.onClick === 'function') {
action.onClick();
}
} finally {
removeToast(id);
}
});
actionsEl.appendChild(btn);
}
root.appendChild(actionsEl);
}
ensureStack().appendChild(root);
if (durationMs > 0) {
window.setTimeout(() => {
removeToast(id);
}, durationMs);
}
return id;
}
function removeToast(id) {
if (!stackEl) return;
const toastEl = stackEl.querySelector(`[data-toast-id="${id}"]`);
if (!toastEl) return;
toastEl.remove();
}
function reportError(context, error, options) {
const opts = options || {};
const message = extractMessage(error);
const actions = [];
if (isSettingsError(message)) {
actions.push({
label: 'Open Settings',
onClick: () => {
if (typeof showSettings === 'function') {
showSettings();
}
}
});
}
if (isNetworkError(message)) {
actions.push({
label: 'Retry',
onClick: () => {
if (typeof opts.onRetry === 'function') {
opts.onRetry();
}
}
});
}
if (typeof opts.extraAction === 'function' && opts.extraActionLabel) {
actions.push({
label: String(opts.extraActionLabel),
onClick: opts.extraAction,
});
}
return toast({
type: 'error',
title: context || 'Action Failed',
message,
actions,
durationMs: opts.persistent ? 0 : 8500,
});
}
function installGlobalHandlers() {
window.addEventListener('error', (event) => {
const target = event && event.target;
if (target && (target.tagName === 'IMG' || target.tagName === 'SCRIPT')) {
return;
}
const message = extractMessage(event && event.error) || String(event.message || 'Unknown error');
if (shouldIgnore(message)) return;
toast({
type: 'warning',
title: 'Unhandled Error',
message,
});
});
window.addEventListener('unhandledrejection', (event) => {
const message = extractMessage(event && event.reason);
if (shouldIgnore(message)) return;
toast({
type: 'warning',
title: 'Promise Rejection',
message,
});
});
}
function normalizeType(type) {
const t = String(type || 'info').toLowerCase();
if (t === 'error' || t === 'warning') return t;
return 'info';
}
function defaultTitle(type) {
if (type === 'error') return 'Error';
if (type === 'warning') return 'Warning';
return 'Notice';
}
function extractMessage(error) {
if (!error) return 'Unknown error';
if (typeof error === 'string') return error;
if (error instanceof Error) return error.message || error.name;
if (typeof error.message === 'string') return error.message;
return String(error);
}
function shouldIgnore(message) {
const text = String(message || '').toLowerCase();
return text.includes('script error') || text.includes('resizeobserver loop limit exceeded');
}
function renderCollectionState(container, options) {
if (!container) return null;
const opts = options || {};
const type = String(opts.type || 'empty').toLowerCase();
const message = String(opts.message || (type === 'loading' ? 'Loading...' : 'No data available'));
const className = opts.className || `app-collection-state is-${type}`;
container.innerHTML = '';
if (container.tagName === 'TBODY') {
const row = document.createElement('tr');
row.className = 'app-collection-state-row';
const cell = document.createElement('td');
const columns = Number.isFinite(opts.columns) ? opts.columns : 1;
cell.colSpan = Math.max(1, columns);
const state = document.createElement('div');
state.className = className;
state.textContent = message;
cell.appendChild(state);
row.appendChild(cell);
container.appendChild(row);
return row;
}
const state = document.createElement('div');
state.className = className;
state.textContent = message;
container.appendChild(state);
return state;
}
function isNetworkError(message) {
const text = String(message || '').toLowerCase();
return text.includes('networkerror') || text.includes('failed to fetch') || text.includes('timeout');
}
function isSettingsError(message) {
const text = String(message || '').toLowerCase();
return text.includes('permission') || text.includes('denied') || text.includes('dependency') || text.includes('tool');
}
return {
init,
toast,
reportError,
removeToast,
renderCollectionState,
};
})();
window.showAppToast = function(title, message, type) {
return AppFeedback.toast({
title,
message,
type,
});
};
window.reportActionableError = function(context, error, options) {
return AppFeedback.reportError(context, error, options);
};
window.renderCollectionState = function(container, options) {
return AppFeedback.renderCollectionState(container, options);
};
document.addEventListener('DOMContentLoaded', () => {
AppFeedback.init();
});
+36 -8
View File
@@ -81,6 +81,7 @@ const Updater = {
showUpdateToast(data) { showUpdateToast(data) {
// Remove existing toast if present // Remove existing toast if present
this.hideToast(); this.hideToast();
const latestVersion = this._escape(data.latest_version || '');
const toast = document.createElement('div'); const toast = document.createElement('div');
toast.className = 'update-toast'; toast.className = 'update-toast';
@@ -99,7 +100,7 @@ const Updater = {
<button class="update-toast-close" onclick="Updater.dismissUpdate()">&times;</button> <button class="update-toast-close" onclick="Updater.dismissUpdate()">&times;</button>
</div> </div>
<div class="update-toast-body"> <div class="update-toast-body">
Version <strong>${data.latest_version}</strong> is ready Version <strong>${latestVersion}</strong> is ready
</div> </div>
<div class="update-toast-actions"> <div class="update-toast-actions">
<button class="update-toast-btn update-toast-btn-primary" onclick="Updater.showUpdateModal()"> <button class="update-toast-btn update-toast-btn-primary" onclick="Updater.showUpdateModal()">
@@ -177,6 +178,9 @@ const Updater = {
const data = this._updateData; const data = this._updateData;
const releaseNotes = this._formatReleaseNotes(data.release_notes || 'No release notes available.'); const releaseNotes = this._formatReleaseNotes(data.release_notes || 'No release notes available.');
const safeCurrentVersion = this._escape(data.current_version || '');
const safeLatestVersion = this._escape(data.latest_version || '');
const safeReleaseUrl = this._safeUrl(data.release_url || '');
const modal = document.createElement('div'); const modal = document.createElement('div');
modal.className = 'update-modal-overlay'; modal.className = 'update-modal-overlay';
@@ -203,7 +207,7 @@ const Updater = {
<div class="update-version-info"> <div class="update-version-info">
<div class="update-version-current"> <div class="update-version-current">
<span class="update-version-label">Current</span> <span class="update-version-label">Current</span>
<span class="update-version-value">v${data.current_version}</span> <span class="update-version-value">v${safeCurrentVersion}</span>
</div> </div>
<div class="update-version-arrow"> <div class="update-version-arrow">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
@@ -213,7 +217,7 @@ const Updater = {
</div> </div>
<div class="update-version-latest"> <div class="update-version-latest">
<span class="update-version-label">Latest</span> <span class="update-version-label">Latest</span>
<span class="update-version-value update-version-new">v${data.latest_version}</span> <span class="update-version-value update-version-new">v${safeLatestVersion}</span>
</div> </div>
</div> </div>
@@ -251,7 +255,7 @@ const Updater = {
<div class="update-result" id="updateResult" style="display: none;"></div> <div class="update-result" id="updateResult" style="display: none;"></div>
</div> </div>
<div class="update-modal-footer"> <div class="update-modal-footer">
<a href="${data.release_url || '#'}" target="_blank" class="update-modal-link" ${!data.release_url ? 'style="display:none"' : ''}> <a href="${safeReleaseUrl || '#'}" target="_blank" class="update-modal-link" ${!safeReleaseUrl ? 'style="display:none"' : ''}>
View on GitHub View on GitHub
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/> <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
@@ -361,6 +365,8 @@ const Updater = {
if (!resultEl) return; if (!resultEl) return;
resultEl.style.display = 'block'; resultEl.style.display = 'block';
const safeMessage = this._escape(data.message || data.error || 'An error occurred during the update.');
const safeDetails = data.details ? this._escape(String(data.details).substring(0, 200)) : '';
if (success) { if (success) {
if (data.updated) { if (data.updated) {
@@ -390,7 +396,7 @@ const Updater = {
<line x1="12" y1="8" x2="12.01" y2="8"/> <line x1="12" y1="8" x2="12.01" y2="8"/>
</svg> </svg>
</div> </div>
<div class="update-result-text">${data.message || 'Already up to date.'}</div> <div class="update-result-text">${this._escape(data.message || 'Already up to date.')}</div>
`; `;
} }
} else { } else {
@@ -406,7 +412,7 @@ const Updater = {
</div> </div>
<div class="update-result-text"> <div class="update-result-text">
<strong>Manual update required</strong><br> <strong>Manual update required</strong><br>
${data.message || 'Please download the latest release from GitHub.'} ${safeMessage || 'Please download the latest release from GitHub.'}
</div> </div>
`; `;
} else { } else {
@@ -421,8 +427,8 @@ const Updater = {
</div> </div>
<div class="update-result-text"> <div class="update-result-text">
<strong>Update failed</strong><br> <strong>Update failed</strong><br>
${data.message || data.error || 'An error occurred during the update.'} ${safeMessage}
${data.details ? '<br><code style="font-size: 10px; margin-top: 8px; display: block;">' + data.details.substring(0, 200) + '</code>' : ''} ${safeDetails ? '<br><code style="font-size: 10px; margin-top: 8px; display: block;">' + safeDetails + '</code>' : ''}
</div> </div>
`; `;
} }
@@ -467,6 +473,28 @@ const Updater = {
return '<p>' + html + '</p>'; return '<p>' + html + '</p>';
}, },
_escape(value) {
return String(value == null ? '' : value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
},
_safeUrl(url) {
if (!url) return '';
try {
const parsed = new URL(url, window.location.origin);
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
return parsed.href;
}
} catch (e) {
return '';
}
return '';
},
/** /**
* Manual trigger for settings panel * Manual trigger for settings panel
*/ */
+255
View File
@@ -0,0 +1,255 @@
/* INTERCEPT Voice Alerts — Web Speech API queue with priority system */
const VoiceAlerts = (function () {
'use strict';
const PRIORITY = { LOW: 0, MEDIUM: 1, HIGH: 2 };
let _enabled = true;
let _muted = false;
let _queue = [];
let _speaking = false;
let _sources = {};
const STORAGE_KEY = 'intercept-voice-muted';
const CONFIG_KEY = 'intercept-voice-config';
const RATE_MIN = 0.5;
const RATE_MAX = 2.0;
const PITCH_MIN = 0.5;
const PITCH_MAX = 2.0;
// Default config
let _config = {
rate: 1.1,
pitch: 0.9,
voiceName: '',
streams: { pager: true, tscm: true, bluetooth: true },
};
function _toNumberInRange(value, fallback, min, max) {
const n = Number(value);
if (!Number.isFinite(n)) return fallback;
return Math.min(max, Math.max(min, n));
}
function _normalizeConfig() {
_config.rate = _toNumberInRange(_config.rate, 1.1, RATE_MIN, RATE_MAX);
_config.pitch = _toNumberInRange(_config.pitch, 0.9, PITCH_MIN, PITCH_MAX);
_config.voiceName = typeof _config.voiceName === 'string' ? _config.voiceName : '';
}
function _isSpeechSupported() {
return !!(window.speechSynthesis && typeof window.SpeechSynthesisUtterance !== 'undefined');
}
function _showVoiceToast(title, message, type) {
if (typeof window.showAppToast === 'function') {
window.showAppToast(title, message, type || 'warning');
}
}
function _loadConfig() {
_muted = localStorage.getItem(STORAGE_KEY) === 'true';
try {
const stored = localStorage.getItem(CONFIG_KEY);
if (stored) {
const parsed = JSON.parse(stored);
_config.rate = parsed.rate ?? _config.rate;
_config.pitch = parsed.pitch ?? _config.pitch;
_config.voiceName = parsed.voiceName ?? _config.voiceName;
if (parsed.streams) {
Object.assign(_config.streams, parsed.streams);
}
}
} catch (_) {}
_normalizeConfig();
_updateMuteButton();
}
function _updateMuteButton() {
const btn = document.getElementById('voiceMuteBtn');
if (!btn) return;
btn.classList.toggle('voice-muted', _muted);
btn.title = _muted ? 'Unmute voice alerts' : 'Mute voice alerts';
btn.style.opacity = _muted ? '0.4' : '1';
}
function _getVoice() {
if (!_config.voiceName) return null;
const voices = window.speechSynthesis ? speechSynthesis.getVoices() : [];
return voices.find(v => v.name === _config.voiceName) || null;
}
function _createUtterance(text) {
const utt = new SpeechSynthesisUtterance(text);
utt.rate = _toNumberInRange(_config.rate, 1.1, RATE_MIN, RATE_MAX);
utt.pitch = _toNumberInRange(_config.pitch, 0.9, PITCH_MIN, PITCH_MAX);
const voice = _getVoice();
if (voice) utt.voice = voice;
return utt;
}
function speak(text, priority) {
if (priority === undefined) priority = PRIORITY.MEDIUM;
if (!_enabled || _muted) return;
if (!window.speechSynthesis) return;
if (priority === PRIORITY.LOW && _speaking) return;
if (priority === PRIORITY.HIGH && _speaking) {
window.speechSynthesis.cancel();
_queue = [];
_speaking = false;
}
_queue.push({ text, priority });
if (!_speaking) _dequeue();
}
function _dequeue() {
if (_queue.length === 0) { _speaking = false; return; }
_speaking = true;
const item = _queue.shift();
const utt = _createUtterance(item.text);
utt.onend = () => { _speaking = false; _dequeue(); };
utt.onerror = () => { _speaking = false; _dequeue(); };
window.speechSynthesis.speak(utt);
}
function toggleMute() {
_muted = !_muted;
localStorage.setItem(STORAGE_KEY, _muted ? 'true' : 'false');
_updateMuteButton();
if (_muted && window.speechSynthesis) window.speechSynthesis.cancel();
}
function _openStream(url, handler, key) {
if (_sources[key]) return;
const es = new EventSource(url);
es.onmessage = handler;
es.onerror = () => { es.close(); delete _sources[key]; };
_sources[key] = es;
}
function _startStreams() {
if (!_enabled) return;
// Pager stream
if (_config.streams.pager) {
_openStream('/stream', (ev) => {
try {
const d = JSON.parse(ev.data);
if (d.address && d.message) {
speak(`Pager message to ${d.address}: ${String(d.message).slice(0, 60)}`, PRIORITY.MEDIUM);
}
} catch (_) {}
}, 'pager');
}
// TSCM stream
if (_config.streams.tscm) {
_openStream('/tscm/sweep/stream', (ev) => {
try {
const d = JSON.parse(ev.data);
if (d.threat_level && d.description) {
speak(`TSCM alert: ${d.threat_level}${d.description}`, PRIORITY.HIGH);
}
} catch (_) {}
}, 'tscm');
}
// Bluetooth stream — tracker detection only
if (_config.streams.bluetooth) {
_openStream('/api/bluetooth/stream', (ev) => {
try {
const d = JSON.parse(ev.data);
if (d.service_data && d.service_data.tracker_type) {
speak(`Tracker detected: ${d.service_data.tracker_type}`, PRIORITY.HIGH);
}
} catch (_) {}
}, 'bluetooth');
}
}
function _stopStreams() {
Object.values(_sources).forEach(es => { try { es.close(); } catch (_) {} });
_sources = {};
}
function init() {
_loadConfig();
if (_isSpeechSupported()) {
// Prime voices list early so user-triggered test calls are less likely to be silent.
speechSynthesis.getVoices();
}
_startStreams();
}
function setEnabled(val) {
_enabled = val;
if (!val) {
_stopStreams();
if (window.speechSynthesis) window.speechSynthesis.cancel();
} else {
_startStreams();
}
}
// ── Config API (used by Ops Center voice config panel) ─────────────
function getConfig() {
return JSON.parse(JSON.stringify(_config));
}
function setConfig(cfg) {
if (cfg.rate !== undefined) _config.rate = _toNumberInRange(cfg.rate, _config.rate, RATE_MIN, RATE_MAX);
if (cfg.pitch !== undefined) _config.pitch = _toNumberInRange(cfg.pitch, _config.pitch, PITCH_MIN, PITCH_MAX);
if (cfg.voiceName !== undefined) _config.voiceName = cfg.voiceName;
if (cfg.streams) Object.assign(_config.streams, cfg.streams);
_normalizeConfig();
localStorage.setItem(CONFIG_KEY, JSON.stringify(_config));
// Restart streams to apply per-stream toggle changes
_stopStreams();
_startStreams();
}
function getAvailableVoices() {
return new Promise(resolve => {
if (!window.speechSynthesis) { resolve([]); return; }
let voices = speechSynthesis.getVoices();
if (voices.length > 0) { resolve(voices); return; }
speechSynthesis.onvoiceschanged = () => {
resolve(speechSynthesis.getVoices());
};
// Timeout fallback
setTimeout(() => resolve(speechSynthesis.getVoices()), 500);
});
}
function testVoice(text) {
if (!_isSpeechSupported()) {
_showVoiceToast('Voice Unavailable', 'This browser does not support speech synthesis.', 'warning');
return;
}
// Make the test immediate and recover from a paused/stalled synthesis engine.
try {
speechSynthesis.getVoices();
if (speechSynthesis.paused) speechSynthesis.resume();
speechSynthesis.cancel();
} catch (_) {}
const utt = _createUtterance(text || 'Voice alert test. All systems nominal.');
let started = false;
utt.onstart = () => { started = true; };
utt.onerror = () => {
_showVoiceToast('Voice Test Failed', 'Speech synthesis failed to start. Check browser audio output.', 'warning');
};
speechSynthesis.speak(utt);
window.setTimeout(() => {
if (!started && !speechSynthesis.speaking && !speechSynthesis.pending) {
_showVoiceToast('No Voice Output', 'Test speech did not play. Verify browser audio and selected voice.', 'warning');
}
}, 1200);
}
return { init, speak, toggleMute, setEnabled, getConfig, setConfig, getAvailableVoices, testVoice, PRIORITY };
})();
window.VoiceAlerts = VoiceAlerts;
+250 -102
View File
@@ -28,7 +28,7 @@ const BluetoothMode = (function() {
}; };
// Zone counts for proximity display // Zone counts for proximity display
let zoneCounts = { veryClose: 0, close: 0, nearby: 0, far: 0 }; let zoneCounts = { immediate: 0, near: 0, far: 0 };
// New visualization components // New visualization components
let radarInitialized = false; let radarInitialized = false;
@@ -36,6 +36,13 @@ const BluetoothMode = (function() {
// Device list filter // Device list filter
let currentDeviceFilter = 'all'; let currentDeviceFilter = 'all';
let currentSearchTerm = '';
let visibleDeviceCount = 0;
let pendingDeviceFlush = false;
let selectedDeviceNeedsRefresh = false;
let filterListenersBound = false;
let listListenersBound = false;
const pendingDeviceIds = new Set();
// Agent support // Agent support
let showAllAgentsMode = false; let showAllAgentsMode = false;
@@ -111,6 +118,7 @@ const BluetoothMode = (function() {
// Initialize device list filters // Initialize device list filters
initDeviceFilters(); initDeviceFilters();
initListInteractions();
// Set initial panel states // Set initial panel states
updateVisualizationPanels(); updateVisualizationPanels();
@@ -120,24 +128,62 @@ const BluetoothMode = (function() {
* Initialize device list filter buttons * Initialize device list filter buttons
*/ */
function initDeviceFilters() { function initDeviceFilters() {
if (filterListenersBound) return;
const filterContainer = document.getElementById('btDeviceFilters'); const filterContainer = document.getElementById('btDeviceFilters');
if (!filterContainer) return; if (filterContainer) {
filterContainer.addEventListener('click', (e) => {
const btn = e.target.closest('.bt-filter-btn');
if (!btn) return;
filterContainer.addEventListener('click', (e) => { const filter = btn.dataset.filter;
const btn = e.target.closest('.bt-filter-btn'); if (!filter) return;
if (!btn) return;
const filter = btn.dataset.filter; // Update active state
if (!filter) return; filterContainer.querySelectorAll('.bt-filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// Update active state // Apply filter
filterContainer.querySelectorAll('.bt-filter-btn').forEach(b => b.classList.remove('active')); currentDeviceFilter = filter;
btn.classList.add('active'); applyDeviceFilter();
});
}
// Apply filter const searchInput = document.getElementById('btDeviceSearch');
currentDeviceFilter = filter; if (searchInput) {
applyDeviceFilter(); searchInput.addEventListener('input', () => {
}); currentSearchTerm = searchInput.value.trim().toLowerCase();
applyDeviceFilter();
});
}
filterListenersBound = true;
}
function initListInteractions() {
if (listListenersBound) return;
if (deviceContainer) {
deviceContainer.addEventListener('click', (event) => {
const locateBtn = event.target.closest('.bt-locate-btn[data-locate-id]');
if (locateBtn) {
event.preventDefault();
locateById(locateBtn.dataset.locateId);
return;
}
const row = event.target.closest('.bt-device-row[data-bt-device-id]');
if (!row) return;
selectDevice(row.dataset.btDeviceId);
});
}
const trackerList = document.getElementById('btTrackerList');
if (trackerList) {
trackerList.addEventListener('click', (event) => {
const row = event.target.closest('.bt-tracker-item[data-device-id]');
if (!row) return;
selectDevice(row.dataset.deviceId);
});
}
listListenersBound = true;
} }
/** /**
@@ -147,34 +193,53 @@ const BluetoothMode = (function() {
if (!deviceContainer) return; if (!deviceContainer) return;
const cards = deviceContainer.querySelectorAll('[data-bt-device-id]'); const cards = deviceContainer.querySelectorAll('[data-bt-device-id]');
let visibleCount = 0;
cards.forEach(card => { cards.forEach(card => {
const isNew = card.dataset.isNew === 'true'; const isNew = card.dataset.isNew === 'true';
const hasName = card.dataset.hasName === 'true'; const hasName = card.dataset.hasName === 'true';
const rssi = parseInt(card.dataset.rssi) || -100; const rssi = parseInt(card.dataset.rssi) || -100;
const isTracker = card.dataset.isTracker === 'true'; const isTracker = card.dataset.isTracker === 'true';
const searchHaystack = (card.dataset.search || '').toLowerCase();
let visible = true; let matchesFilter = true;
switch (currentDeviceFilter) { switch (currentDeviceFilter) {
case 'new': case 'new':
visible = isNew; matchesFilter = isNew;
break; break;
case 'named': case 'named':
visible = hasName; matchesFilter = hasName;
break; break;
case 'strong': case 'strong':
visible = rssi >= -70; matchesFilter = rssi >= -70;
break; break;
case 'trackers': case 'trackers':
visible = isTracker; matchesFilter = isTracker;
break; break;
case 'all': case 'all':
default: default:
visible = true; matchesFilter = true;
} }
const matchesSearch = !currentSearchTerm || searchHaystack.includes(currentSearchTerm);
const visible = matchesFilter && matchesSearch;
card.style.display = visible ? '' : 'none'; card.style.display = visible ? '' : 'none';
if (visible) visibleCount++;
}); });
visibleDeviceCount = visibleCount;
let stateEl = deviceContainer.querySelector('.bt-device-filter-state');
if (visibleCount === 0 && devices.size > 0) {
if (!stateEl) {
stateEl = document.createElement('div');
stateEl.className = 'bt-device-filter-state app-collection-state is-empty';
deviceContainer.appendChild(stateEl);
}
stateEl.textContent = 'No devices match current filters';
} else if (stateEl) {
stateEl.remove();
}
// Update visible count // Update visible count
updateFilteredCount(); updateFilteredCount();
} }
@@ -186,12 +251,8 @@ const BluetoothMode = (function() {
const countEl = document.getElementById('btDeviceListCount'); const countEl = document.getElementById('btDeviceListCount');
if (!countEl || !deviceContainer) return; if (!countEl || !deviceContainer) return;
if (currentDeviceFilter === 'all') { const hasFilter = currentDeviceFilter !== 'all' || currentSearchTerm.length > 0;
countEl.textContent = devices.size; countEl.textContent = hasFilter ? `${visibleDeviceCount}/${devices.size}` : devices.size;
} else {
const visible = deviceContainer.querySelectorAll('[data-bt-device-id]:not([style*="display: none"])').length;
countEl.textContent = visible + '/' + devices.size;
}
} }
/** /**
@@ -309,28 +370,18 @@ const BluetoothMode = (function() {
* Update proximity zone counts (simple HTML, no canvas) * Update proximity zone counts (simple HTML, no canvas)
*/ */
function updateProximityZones() { function updateProximityZones() {
zoneCounts = { veryClose: 0, close: 0, nearby: 0, far: 0 }; zoneCounts = { immediate: 0, near: 0, far: 0 };
devices.forEach(device => { devices.forEach(device => {
const rssi = device.rssi_current; const rssi = device.rssi_current;
if (rssi == null) return; if (rssi == null) return;
if (rssi >= -40) zoneCounts.veryClose++; if (rssi >= -50) zoneCounts.immediate++;
else if (rssi >= -55) zoneCounts.close++; else if (rssi >= -70) zoneCounts.near++;
else if (rssi >= -70) zoneCounts.nearby++;
else zoneCounts.far++; else zoneCounts.far++;
}); });
// Update DOM elements updateProximityZoneCounts(zoneCounts);
const veryCloseEl = document.getElementById('btZoneVeryClose');
const closeEl = document.getElementById('btZoneClose');
const nearbyEl = document.getElementById('btZoneNearby');
const farEl = document.getElementById('btZoneFar');
if (veryCloseEl) veryCloseEl.textContent = zoneCounts.veryClose;
if (closeEl) closeEl.textContent = zoneCounts.close;
if (nearbyEl) nearbyEl.textContent = zoneCounts.nearby;
if (farEl) farEl.textContent = zoneCounts.far;
} }
// Currently selected device // Currently selected device
@@ -895,17 +946,32 @@ const BluetoothMode = (function() {
async function stopScan() { async function stopScan() {
const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local'; const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local';
const timeoutMs = isAgentMode ? 8000 : 2200;
const controller = (typeof AbortController !== 'undefined') ? new AbortController() : null;
const timeoutId = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
// Optimistic UI teardown keeps mode changes responsive.
setScanning(false);
stopEventStream();
try { try {
if (isAgentMode) { if (isAgentMode) {
await fetch(`/controller/agents/${currentAgent}/bluetooth/stop`, { method: 'POST' }); await fetch(`/controller/agents/${currentAgent}/bluetooth/stop`, {
method: 'POST',
...(controller ? { signal: controller.signal } : {}),
});
} else { } else {
await fetch('/api/bluetooth/scan/stop', { method: 'POST' }); await fetch('/api/bluetooth/scan/stop', {
method: 'POST',
...(controller ? { signal: controller.signal } : {}),
});
} }
setScanning(false);
stopEventStream();
} catch (err) { } catch (err) {
console.error('Failed to stop scan:', err); console.error('Failed to stop scan:', err);
} finally {
if (timeoutId) {
clearTimeout(timeoutId);
}
} }
} }
@@ -916,9 +982,20 @@ const BluetoothMode = (function() {
if (stopBtn) stopBtn.style.display = scanning ? 'block' : 'none'; if (stopBtn) stopBtn.style.display = scanning ? 'block' : 'none';
if (scanning && deviceContainer) { if (scanning && deviceContainer) {
deviceContainer.innerHTML = ''; pendingDeviceIds.clear();
selectedDeviceNeedsRefresh = false;
pendingDeviceFlush = false;
if (typeof renderCollectionState === 'function') {
renderCollectionState(deviceContainer, { type: 'loading', message: 'Scanning for Bluetooth devices...' });
} else {
deviceContainer.innerHTML = '';
}
devices.clear(); devices.clear();
resetStats(); resetStats();
} else if (!scanning && deviceContainer && devices.size === 0) {
if (typeof renderCollectionState === 'function') {
renderCollectionState(deviceContainer, { type: 'empty', message: 'Start scanning to discover Bluetooth devices' });
}
} }
const statusDot = document.getElementById('statusDot'); const statusDot = document.getElementById('statusDot');
@@ -934,8 +1011,10 @@ const BluetoothMode = (function() {
weak: 0, weak: 0,
trackers: [] trackers: []
}; };
visibleDeviceCount = 0;
updateVisualizationPanels(); updateVisualizationPanels();
updateProximityZones(); updateProximityZones();
updateFilteredCount();
// Clear radar // Clear radar
if (radarInitialized && typeof ProximityRadar !== 'undefined') { if (radarInitialized && typeof ProximityRadar !== 'undefined') {
@@ -1084,14 +1163,40 @@ const BluetoothMode = (function() {
function handleDeviceUpdate(device) { function handleDeviceUpdate(device) {
devices.set(device.device_id, device); devices.set(device.device_id, device);
renderDevice(device); pendingDeviceIds.add(device.device_id);
updateDeviceCount(); if (selectedDeviceId === device.device_id) {
updateStatsFromDevices(); selectedDeviceNeedsRefresh = true;
updateVisualizationPanels(); }
updateProximityZones(); scheduleDeviceFlush();
}
// Update new proximity radar function scheduleDeviceFlush() {
updateRadar(); if (pendingDeviceFlush) return;
pendingDeviceFlush = true;
requestAnimationFrame(() => {
pendingDeviceFlush = false;
pendingDeviceIds.forEach((deviceId) => {
const device = devices.get(deviceId);
if (device) {
renderDevice(device, false);
}
});
pendingDeviceIds.clear();
applyDeviceFilter();
updateDeviceCount();
updateStatsFromDevices();
updateVisualizationPanels();
updateProximityZones();
updateRadar();
if (selectedDeviceNeedsRefresh && selectedDeviceId && devices.has(selectedDeviceId)) {
showDeviceDetail(selectedDeviceId);
}
selectedDeviceNeedsRefresh = false;
});
} }
/** /**
@@ -1144,13 +1249,41 @@ const BluetoothMode = (function() {
if (mediumCount) mediumCount.textContent = deviceStats.medium; if (mediumCount) mediumCount.textContent = deviceStats.medium;
if (weakCount) weakCount.textContent = deviceStats.weak; if (weakCount) weakCount.textContent = deviceStats.weak;
// Device summary strip
const totalEl = document.getElementById('btSummaryTotal');
const newEl = document.getElementById('btSummaryNew');
const trackersEl = document.getElementById('btSummaryTrackers');
const strongestEl = document.getElementById('btSummaryStrongest');
if (totalEl || newEl || trackersEl || strongestEl) {
let newCount = 0;
let strongest = null;
devices.forEach(d => {
if (!d.in_baseline) newCount++;
if (d.rssi_current != null) {
strongest = strongest == null ? d.rssi_current : Math.max(strongest, d.rssi_current);
}
});
if (totalEl) totalEl.textContent = devices.size;
if (newEl) newEl.textContent = newCount;
if (trackersEl) trackersEl.textContent = deviceStats.trackers.length;
if (strongestEl) strongestEl.textContent = strongest == null ? '--' : `${strongest} dBm`;
}
// Tracker Detection - Enhanced display with confidence and evidence // Tracker Detection - Enhanced display with confidence and evidence
const trackerList = document.getElementById('btTrackerList'); const trackerList = document.getElementById('btTrackerList');
if (trackerList) { if (trackerList) {
if (devices.size === 0) { if (devices.size === 0) {
trackerList.innerHTML = '<div style="color:#666;padding:10px;text-align:center;font-size:11px;">Start scanning to detect trackers</div>'; if (typeof renderCollectionState === 'function') {
renderCollectionState(trackerList, { type: 'empty', message: 'Start scanning to detect trackers' });
} else {
trackerList.innerHTML = '<div class="app-collection-state is-empty">Start scanning to detect trackers</div>';
}
} else if (deviceStats.trackers.length === 0) { } else if (deviceStats.trackers.length === 0) {
trackerList.innerHTML = '<div style="color:#22c55e;padding:10px;text-align:center;font-size:11px;">No trackers detected</div>'; if (typeof renderCollectionState === 'function') {
renderCollectionState(trackerList, { type: 'empty', message: 'No trackers detected' });
} else {
trackerList.innerHTML = '<div class="app-collection-state is-empty">No trackers detected</div>';
}
} else { } else {
// Sort by risk score (highest first), then confidence // Sort by risk score (highest first), then confidence
const sortedTrackers = [...deviceStats.trackers].sort((a, b) => { const sortedTrackers = [...deviceStats.trackers].sort((a, b) => {
@@ -1162,48 +1295,38 @@ const BluetoothMode = (function() {
return confB - confA; return confB - confA;
}); });
trackerList.innerHTML = sortedTrackers.map(t => { trackerList.innerHTML = sortedTrackers.map((t) => {
// Get tracker type badge color based on confidence
const confidence = t.tracker_confidence || 'low'; const confidence = t.tracker_confidence || 'low';
const confColor = confidence === 'high' ? '#ef4444' :
confidence === 'medium' ? '#f97316' : '#eab308';
const confBg = confidence === 'high' ? 'rgba(239,68,68,0.2)' :
confidence === 'medium' ? 'rgba(249,115,22,0.2)' : 'rgba(234,179,8,0.2)';
// Risk score indicator
const riskScore = t.risk_score || 0; const riskScore = t.risk_score || 0;
const riskColor = riskScore >= 0.5 ? '#ef4444' : riskScore >= 0.3 ? '#f97316' : '#666';
// Tracker type label
const trackerType = t.tracker_name || t.tracker_type || 'Unknown Tracker'; const trackerType = t.tracker_name || t.tracker_type || 'Unknown Tracker';
// Build evidence tooltip (first 2 items)
const evidence = (t.tracker_evidence || []).slice(0, 2); const evidence = (t.tracker_evidence || []).slice(0, 2);
const evidenceHtml = evidence.length > 0 const evidenceHtml = evidence.length > 0
? '<div style="font-size:9px;color:#888;margin-top:3px;font-style:italic;">' + ? `<div class="bt-tracker-evidence">${evidence.map((e) => `${escapeHtml(e)}`).join('<br>')}</div>`
evidence.map(e => '• ' + escapeHtml(e)).join('<br>') + : '';
'</div>' const riskClass = riskScore >= 0.5 ? 'high' : riskScore >= 0.3 ? 'medium' : 'low';
const riskHtml = riskScore >= 0.3
? `<span class="bt-tracker-risk bt-risk-${riskClass}">RISK ${Math.round(riskScore * 100)}%</span>`
: ''; : '';
const deviceIdEscaped = escapeHtml(t.device_id).replace(/'/g, "\\'"); return `
<div class="bt-tracker-item bt-tracker-confidence-${escapeHtml(confidence)}" data-device-id="${escapeAttr(t.device_id)}" role="button" tabindex="0" data-keyboard-activate="true">
return '<div class="bt-tracker-item" style="padding:8px;border-bottom:1px solid rgba(255,255,255,0.05);cursor:pointer;" onclick="BluetoothMode.selectDevice(\'' + deviceIdEscaped + '\')">' + <div class="bt-tracker-row-top">
'<div style="display:flex;justify-content:space-between;align-items:center;">' + <div class="bt-tracker-left">
'<div style="display:flex;align-items:center;gap:6px;">' + <span class="bt-tracker-confidence">${escapeHtml(confidence.toUpperCase())}</span>
'<span style="background:' + confBg + ';color:' + confColor + ';font-size:9px;padding:2px 5px;border-radius:3px;font-weight:600;">' + confidence.toUpperCase() + '</span>' + <span class="bt-tracker-type">${escapeHtml(trackerType)}</span>
'<span style="color:#fff;font-size:11px;">' + escapeHtml(trackerType) + '</span>' + </div>
'</div>' + <div class="bt-tracker-right">
'<div style="display:flex;align-items:center;gap:8px;">' + ${riskHtml}
(riskScore >= 0.3 ? '<span style="color:' + riskColor + ';font-size:9px;font-weight:600;">RISK ' + Math.round(riskScore * 100) + '%</span>' : '') + <span class="bt-tracker-rssi">${t.rssi_current != null ? t.rssi_current : '--'} dBm</span>
'<span style="color:#666;font-size:10px;">' + (t.rssi_current || '--') + ' dBm</span>' + </div>
'</div>' + </div>
'</div>' + <div class="bt-tracker-row-bottom">
'<div style="display:flex;justify-content:space-between;margin-top:3px;">' + <span class="bt-tracker-address">${escapeHtml(t.address_type === 'uuid' ? formatAddress(t) : (t.address || '--'))}</span>
'<span style="font-size:9px;color:#888;font-family:monospace;">' + (t.address_type === 'uuid' ? formatAddress(t) : t.address) + '</span>' + <span class="bt-tracker-seen">Seen ${t.seen_count || 0}x</span>
'<span style="font-size:9px;color:#666;">Seen ' + (t.seen_count || 0) + 'x</span>' + </div>
'</div>' + ${evidenceHtml}
evidenceHtml + </div>
'</div>'; `;
}).join(''); }).join('');
} }
} }
@@ -1214,12 +1337,14 @@ const BluetoothMode = (function() {
updateFilteredCount(); updateFilteredCount();
} }
function renderDevice(device) { function renderDevice(device, reapplyFilter = true) {
if (!deviceContainer) { if (!deviceContainer) {
deviceContainer = document.getElementById('btDeviceListContent'); deviceContainer = document.getElementById('btDeviceListContent');
if (!deviceContainer) return; if (!deviceContainer) return;
} }
deviceContainer.querySelectorAll('.app-collection-state, .bt-device-filter-state').forEach((el) => el.remove());
const escapedId = CSS.escape(device.device_id); const escapedId = CSS.escape(device.device_id);
const existingCard = deviceContainer.querySelector('[data-bt-device-id="' + escapedId + '"]'); const existingCard = deviceContainer.querySelector('[data-bt-device-id="' + escapedId + '"]');
const cardHtml = createSimpleDeviceCard(device); const cardHtml = createSimpleDeviceCard(device);
@@ -1230,8 +1355,7 @@ const BluetoothMode = (function() {
deviceContainer.insertAdjacentHTML('afterbegin', cardHtml); deviceContainer.insertAdjacentHTML('afterbegin', cardHtml);
} }
// Re-apply filter after rendering if (reapplyFilter) {
if (currentDeviceFilter !== 'all') {
applyDeviceFilter(); applyDeviceFilter();
} }
} }
@@ -1259,7 +1383,14 @@ const BluetoothMode = (function() {
const addr = escapeHtml(isUuidAddress(device) ? formatAddress(device) : (device.address || 'Unknown')); const addr = escapeHtml(isUuidAddress(device) ? formatAddress(device) : (device.address || 'Unknown'));
const mfr = device.manufacturer_name ? escapeHtml(device.manufacturer_name) : ''; const mfr = device.manufacturer_name ? escapeHtml(device.manufacturer_name) : '';
const seenCount = device.seen_count || 0; const seenCount = device.seen_count || 0;
const deviceIdEscaped = escapeHtml(device.device_id).replace(/'/g, "\\'"); const searchIndex = [
displayName,
device.address,
device.manufacturer_name,
device.tracker_name,
device.tracker_type,
agentName
].filter(Boolean).join(' ').toLowerCase();
// Protocol badge - compact // Protocol badge - compact
const protoBadge = protocol === 'ble' const protoBadge = protocol === 'ble'
@@ -1346,7 +1477,7 @@ const BluetoothMode = (function() {
const borderColor = isTracker && trackerConfidence === 'high' ? '#ef4444' : const borderColor = isTracker && trackerConfidence === 'high' ? '#ef4444' :
isTracker ? '#f97316' : rssiColor; isTracker ? '#f97316' : rssiColor;
return '<div class="bt-device-row' + (isTracker ? ' is-tracker' : '') + '" data-bt-device-id="' + escapeHtml(device.device_id) + '" data-is-new="' + isNew + '" data-has-name="' + hasName + '" data-rssi="' + (rssi || -100) + '" data-is-tracker="' + isTracker + '" onclick="BluetoothMode.selectDevice(\'' + deviceIdEscaped + '\')" style="border-left-color:' + borderColor + ';">' + return '<div class="bt-device-row' + (isTracker ? ' is-tracker' : '') + '" data-bt-device-id="' + escapeAttr(device.device_id) + '" data-is-new="' + isNew + '" data-has-name="' + hasName + '" data-rssi="' + (rssi || -100) + '" data-is-tracker="' + isTracker + '" data-search="' + escapeAttr(searchIndex) + '" role="button" tabindex="0" data-keyboard-activate="true" style="border-left-color:' + borderColor + ';">' +
'<div class="bt-row-main">' + '<div class="bt-row-main">' +
'<div class="bt-row-left">' + '<div class="bt-row-left">' +
protoBadge + protoBadge +
@@ -1367,7 +1498,7 @@ const BluetoothMode = (function() {
'</div>' + '</div>' +
'<div class="bt-row-secondary">' + secondaryInfo + '</div>' + '<div class="bt-row-secondary">' + secondaryInfo + '</div>' +
'<div class="bt-row-actions">' + '<div class="bt-row-actions">' +
'<button class="bt-locate-btn" data-locate-id="' + escapeHtml(device.device_id) + '" onclick="event.stopPropagation(); BluetoothMode.locateById(this.dataset.locateId)">' + '<button type="button" class="bt-locate-btn" data-locate-id="' + escapeAttr(device.device_id) + '">' +
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="10" r="3"/><path d="M12 21.7C17.3 17 20 13 20 10a8 8 0 1 0-16 0c0 3 2.7 7 8 11.7z"/></svg>' + '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="10" r="3"/><path d="M12 21.7C17.3 17 20 13 20 10a8 8 0 1 0-16 0c0 3 2.7 7 8 11.7z"/></svg>' +
'Locate</button>' + 'Locate</button>' +
'</div>' + '</div>' +
@@ -1390,6 +1521,10 @@ const BluetoothMode = (function() {
return div.innerHTML; return div.innerHTML;
} }
function escapeAttr(text) {
return escapeHtml(text).replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}
async function setBaseline() { async function setBaseline() {
try { try {
const response = await fetch('/api/bluetooth/baseline/set', { method: 'POST' }); const response = await fetch('/api/bluetooth/baseline/set', { method: 'POST' });
@@ -1499,15 +1634,19 @@ const BluetoothMode = (function() {
*/ */
function clearData() { function clearData() {
devices.clear(); devices.clear();
pendingDeviceIds.clear();
pendingDeviceFlush = false;
selectedDeviceNeedsRefresh = false;
resetStats(); resetStats();
clearSelection();
if (deviceContainer) { if (deviceContainer) {
deviceContainer.innerHTML = ''; if (typeof renderCollectionState === 'function') {
renderCollectionState(deviceContainer, { type: 'empty', message: 'Start scanning to discover Bluetooth devices' });
} else {
deviceContainer.innerHTML = '';
}
} }
updateDeviceCount();
updateProximityZones();
updateRadar();
} }
/** /**
@@ -1548,7 +1687,15 @@ const BluetoothMode = (function() {
// Re-render device list // Re-render device list
if (deviceContainer) { if (deviceContainer) {
deviceContainer.innerHTML = ''; deviceContainer.innerHTML = '';
devices.forEach(device => renderDevice(device)); devices.forEach(device => renderDevice(device, false));
applyDeviceFilter();
if (devices.size === 0 && typeof renderCollectionState === 'function') {
renderCollectionState(deviceContainer, { type: 'empty', message: 'No devices for current agent' });
}
}
if (selectedDeviceId && !devices.has(selectedDeviceId)) {
clearSelection();
} }
updateDeviceCount(); updateDeviceCount();
@@ -1586,6 +1733,7 @@ const BluetoothMode = (function() {
if (typeof BtLocate !== 'undefined') { if (typeof BtLocate !== 'undefined') {
BtLocate.handoff({ BtLocate.handoff({
device_id: device.device_id, device_id: device.device_id,
device_key: device.device_key || null,
mac_address: device.address, mac_address: device.address,
address_type: device.address_type || null, address_type: device.address_type || null,
irk_hex: device.irk_hex || null, irk_hex: device.irk_hex || null,
@@ -1594,7 +1742,7 @@ const BluetoothMode = (function() {
last_known_rssi: device.rssi_current, last_known_rssi: device.rssi_current,
tx_power: device.tx_power || null, tx_power: device.tx_power || null,
appearance_name: device.appearance_name || null, appearance_name: device.appearance_name || null,
fingerprint_id: device.fingerprint_id || null, fingerprint_id: device.fingerprint_id || device.fingerprint?.id || null,
mac_cluster_count: device.mac_cluster_count || 0 mac_cluster_count: device.mac_cluster_count || 0
}); });
} }
+1269 -103
View File
File diff suppressed because it is too large Load Diff
-852
View File
@@ -1,852 +0,0 @@
/**
* Intercept - DMR / Digital Voice Mode
* Decoding DMR, P25, NXDN, D-STAR digital voice protocols
*/
// ============== STATE ==============
let isDmrRunning = false;
let dmrEventSource = null;
let dmrCallCount = 0;
let dmrSyncCount = 0;
let dmrCallHistory = [];
let dmrCurrentProtocol = '--';
let dmrModeLabel = 'dmr'; // Protocol label for device reservation
let dmrHasAudio = false;
// ============== BOOKMARKS ==============
let dmrBookmarks = [];
const DMR_BOOKMARKS_KEY = 'dmrBookmarks';
const DMR_SETTINGS_KEY = 'dmrSettings';
const DMR_BOOKMARK_PROTOCOLS = new Set(['auto', 'dmr', 'p25', 'nxdn', 'dstar', 'provoice']);
// ============== SYNTHESIZER STATE ==============
let dmrSynthCanvas = null;
let dmrSynthCtx = null;
let dmrSynthBars = [];
let dmrSynthAnimationId = null;
let dmrSynthInitialized = false;
let dmrActivityLevel = 0;
let dmrActivityTarget = 0;
let dmrEventType = 'idle';
let dmrLastEventTime = 0;
const DMR_BAR_COUNT = 48;
const DMR_DECAY_RATE = 0.015;
const DMR_BURST_SYNC = 0.6;
const DMR_BURST_CALL = 0.85;
const DMR_BURST_VOICE = 0.95;
// ============== TOOLS CHECK ==============
function checkDmrTools() {
fetch('/dmr/tools')
.then(r => r.json())
.then(data => {
const warning = document.getElementById('dmrToolsWarning');
const warningText = document.getElementById('dmrToolsWarningText');
if (!warning) return;
const selectedType = (typeof getSelectedSDRType === 'function')
? getSelectedSDRType()
: 'rtlsdr';
const missing = [];
if (!data.dsd) missing.push('dsd (Digital Speech Decoder)');
if (selectedType === 'rtlsdr') {
if (!data.rtl_fm) missing.push('rtl_fm (RTL-SDR)');
} else if (!data.rx_fm) {
missing.push('rx_fm (SoapySDR demodulator)');
}
if (!data.ffmpeg) missing.push('ffmpeg (audio output — optional)');
if (missing.length > 0) {
warning.style.display = 'block';
if (warningText) warningText.textContent = missing.join(', ');
} else {
warning.style.display = 'none';
}
// Update audio panel availability
updateDmrAudioStatus(data.ffmpeg ? 'OFF' : 'UNAVAILABLE');
})
.catch(() => {});
}
// ============== START / STOP ==============
function startDmr() {
const frequency = parseFloat(document.getElementById('dmrFrequency')?.value || 462.5625);
const protocol = document.getElementById('dmrProtocol')?.value || 'auto';
const gain = parseInt(document.getElementById('dmrGain')?.value || 40);
const ppm = parseInt(document.getElementById('dmrPPM')?.value || 0);
const relaxCrc = document.getElementById('dmrRelaxCrc')?.checked || false;
const device = typeof getSelectedDevice === 'function' ? getSelectedDevice() : 0;
const sdrType = (typeof getSelectedSDRType === 'function') ? getSelectedSDRType() : 'rtlsdr';
// Use protocol name for device reservation so panel shows "D-STAR", "P25", etc.
dmrModeLabel = protocol !== 'auto' ? protocol : 'dmr';
// Check device availability before starting
if (typeof checkDeviceAvailability === 'function' && !checkDeviceAvailability(dmrModeLabel)) {
return;
}
// Save settings to localStorage for persistence
try {
localStorage.setItem(DMR_SETTINGS_KEY, JSON.stringify({
frequency, protocol, gain, ppm, relaxCrc
}));
} catch (e) { /* localStorage unavailable */ }
fetch('/dmr/start', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ frequency, protocol, gain, device, ppm, relaxCrc, sdr_type: sdrType })
})
.then(r => r.json())
.then(data => {
if (data.status === 'started') {
isDmrRunning = true;
dmrCallCount = 0;
dmrSyncCount = 0;
dmrCallHistory = [];
updateDmrUI();
connectDmrSSE();
dmrEventType = 'idle';
dmrActivityTarget = 0.1;
dmrLastEventTime = Date.now();
if (!dmrSynthInitialized) initDmrSynthesizer();
updateDmrSynthStatus();
const statusEl = document.getElementById('dmrStatus');
if (statusEl) statusEl.textContent = 'DECODING';
if (typeof reserveDevice === 'function') {
reserveDevice(parseInt(device), dmrModeLabel);
}
// Start audio if available
dmrHasAudio = !!data.has_audio;
if (dmrHasAudio) startDmrAudio();
updateDmrAudioStatus(dmrHasAudio ? 'STREAMING' : 'UNAVAILABLE');
if (typeof showNotification === 'function') {
showNotification('Digital Voice', `Decoding ${frequency} MHz (${protocol.toUpperCase()})`);
}
} else if (data.status === 'error' && data.message === 'Already running') {
// Backend has an active session the frontend lost track of — resync
isDmrRunning = true;
updateDmrUI();
connectDmrSSE();
if (!dmrSynthInitialized) initDmrSynthesizer();
dmrEventType = 'idle';
dmrActivityTarget = 0.1;
dmrLastEventTime = Date.now();
updateDmrSynthStatus();
const statusEl = document.getElementById('dmrStatus');
if (statusEl) statusEl.textContent = 'DECODING';
if (typeof showNotification === 'function') {
showNotification('DMR', 'Reconnected to active session');
}
} else {
if (typeof showNotification === 'function') {
showNotification('Error', data.message || 'Failed to start DMR');
}
}
})
.catch(err => console.error('[DMR] Start error:', err));
}
function stopDmr() {
stopDmrAudio();
fetch('/dmr/stop', { method: 'POST' })
.then(r => r.json())
.then(() => {
isDmrRunning = false;
if (dmrEventSource) { dmrEventSource.close(); dmrEventSource = null; }
updateDmrUI();
dmrEventType = 'stopped';
dmrActivityTarget = 0;
updateDmrSynthStatus();
updateDmrAudioStatus('OFF');
const statusEl = document.getElementById('dmrStatus');
if (statusEl) statusEl.textContent = 'STOPPED';
if (typeof releaseDevice === 'function') {
releaseDevice(dmrModeLabel);
}
})
.catch(err => console.error('[DMR] Stop error:', err));
}
// ============== SSE STREAMING ==============
function connectDmrSSE() {
if (dmrEventSource) dmrEventSource.close();
dmrEventSource = new EventSource('/dmr/stream');
dmrEventSource.onmessage = function(event) {
const msg = JSON.parse(event.data);
handleDmrMessage(msg);
};
dmrEventSource.onerror = function() {
if (isDmrRunning) {
setTimeout(connectDmrSSE, 2000);
}
};
}
function handleDmrMessage(msg) {
if (dmrSynthInitialized) dmrSynthPulse(msg.type);
if (msg.type === 'sync') {
dmrCurrentProtocol = msg.protocol || '--';
const protocolEl = document.getElementById('dmrActiveProtocol');
if (protocolEl) protocolEl.textContent = dmrCurrentProtocol;
const mainProtocolEl = document.getElementById('dmrMainProtocol');
if (mainProtocolEl) mainProtocolEl.textContent = dmrCurrentProtocol;
dmrSyncCount++;
const syncCountEl = document.getElementById('dmrSyncCount');
if (syncCountEl) syncCountEl.textContent = dmrSyncCount;
} else if (msg.type === 'call') {
dmrCallCount++;
const countEl = document.getElementById('dmrCallCount');
if (countEl) countEl.textContent = dmrCallCount;
const mainCountEl = document.getElementById('dmrMainCallCount');
if (mainCountEl) mainCountEl.textContent = dmrCallCount;
// Update current call display
const slotInfo = msg.slot != null ? `
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: var(--text-muted);">Slot</span>
<span style="color: var(--accent-orange); font-family: var(--font-mono);">${msg.slot}</span>
</div>` : '';
const callEl = document.getElementById('dmrCurrentCall');
if (callEl) {
callEl.innerHTML = `
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: var(--text-muted);">Talkgroup</span>
<span style="color: var(--accent-green); font-weight: bold; font-family: var(--font-mono);">${msg.talkgroup}</span>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: var(--text-muted);">Source ID</span>
<span style="color: var(--accent-cyan); font-family: var(--font-mono);">${msg.source_id}</span>
</div>${slotInfo}
<div style="display: flex; justify-content: space-between;">
<span style="color: var(--text-muted);">Time</span>
<span style="color: var(--text-primary);">${msg.timestamp}</span>
</div>
`;
}
// Add to history
dmrCallHistory.unshift({
talkgroup: msg.talkgroup,
source_id: msg.source_id,
protocol: dmrCurrentProtocol,
time: msg.timestamp,
});
if (dmrCallHistory.length > 50) dmrCallHistory.length = 50;
renderDmrHistory();
} else if (msg.type === 'slot') {
// Update slot info in current call
} else if (msg.type === 'raw') {
// Raw DSD output — triggers synthesizer activity via dmrSynthPulse
} else if (msg.type === 'heartbeat') {
// Decoder is alive and listening — keep synthesizer in listening state
if (isDmrRunning && dmrSynthInitialized) {
if (dmrEventType === 'idle' || dmrEventType === 'raw') {
dmrEventType = 'raw';
dmrActivityTarget = Math.max(dmrActivityTarget, 0.15);
dmrLastEventTime = Date.now();
updateDmrSynthStatus();
}
}
} else if (msg.type === 'status') {
const statusEl = document.getElementById('dmrStatus');
if (msg.text === 'started') {
if (statusEl) statusEl.textContent = 'DECODING';
} else if (msg.text === 'crashed') {
isDmrRunning = false;
stopDmrAudio();
updateDmrUI();
dmrEventType = 'stopped';
dmrActivityTarget = 0;
updateDmrSynthStatus();
updateDmrAudioStatus('OFF');
if (statusEl) statusEl.textContent = 'CRASHED';
if (typeof releaseDevice === 'function') releaseDevice(dmrModeLabel);
const detail = msg.detail || `Decoder exited (code ${msg.exit_code})`;
if (typeof showNotification === 'function') {
showNotification('DMR Error', detail);
}
} else if (msg.text === 'stopped') {
isDmrRunning = false;
stopDmrAudio();
updateDmrUI();
dmrEventType = 'stopped';
dmrActivityTarget = 0;
updateDmrSynthStatus();
updateDmrAudioStatus('OFF');
if (statusEl) statusEl.textContent = 'STOPPED';
if (typeof releaseDevice === 'function') releaseDevice(dmrModeLabel);
}
}
}
// ============== UI ==============
function updateDmrUI() {
const startBtn = document.getElementById('startDmrBtn');
const stopBtn = document.getElementById('stopDmrBtn');
if (startBtn) startBtn.style.display = isDmrRunning ? 'none' : 'block';
if (stopBtn) stopBtn.style.display = isDmrRunning ? 'block' : 'none';
}
function renderDmrHistory() {
const container = document.getElementById('dmrHistoryBody');
if (!container) return;
const historyCountEl = document.getElementById('dmrHistoryCount');
if (historyCountEl) historyCountEl.textContent = `${dmrCallHistory.length} calls`;
if (dmrCallHistory.length === 0) {
container.innerHTML = '<tr><td colspan="4" style="padding: 10px; text-align: center; color: var(--text-muted);">No calls recorded</td></tr>';
return;
}
container.innerHTML = dmrCallHistory.slice(0, 20).map(call => `
<tr>
<td style="padding: 3px 6px; font-family: var(--font-mono);">${call.time}</td>
<td style="padding: 3px 6px; color: var(--accent-green);">${call.talkgroup}</td>
<td style="padding: 3px 6px; color: var(--accent-cyan);">${call.source_id}</td>
<td style="padding: 3px 6px;">${call.protocol}</td>
</tr>
`).join('');
}
// ============== SYNTHESIZER ==============
function initDmrSynthesizer() {
dmrSynthCanvas = document.getElementById('dmrSynthCanvas');
if (!dmrSynthCanvas) return;
// Use the canvas element's own rendered size for the backing buffer
const rect = dmrSynthCanvas.getBoundingClientRect();
const w = Math.round(rect.width) || 600;
const h = Math.round(rect.height) || 70;
dmrSynthCanvas.width = w;
dmrSynthCanvas.height = h;
dmrSynthCtx = dmrSynthCanvas.getContext('2d');
dmrSynthBars = [];
for (let i = 0; i < DMR_BAR_COUNT; i++) {
dmrSynthBars[i] = { height: 2, targetHeight: 2, velocity: 0 };
}
dmrActivityLevel = 0;
dmrActivityTarget = 0;
dmrEventType = isDmrRunning ? 'idle' : 'stopped';
dmrSynthInitialized = true;
updateDmrSynthStatus();
if (dmrSynthAnimationId) cancelAnimationFrame(dmrSynthAnimationId);
drawDmrSynthesizer();
}
function drawDmrSynthesizer() {
if (!dmrSynthCtx || !dmrSynthCanvas) return;
const width = dmrSynthCanvas.width;
const height = dmrSynthCanvas.height;
const barWidth = (width / DMR_BAR_COUNT) - 2;
const now = Date.now();
// Clear canvas
dmrSynthCtx.fillStyle = 'rgba(0, 0, 0, 0.3)';
dmrSynthCtx.fillRect(0, 0, width, height);
// Decay activity toward target. Window must exceed the backend
// heartbeat interval (3s) so the status doesn't flip-flop between
// LISTENING and IDLE on every heartbeat cycle.
const timeSinceEvent = now - dmrLastEventTime;
if (timeSinceEvent > 5000) {
// No events for 5s — decay target toward idle
dmrActivityTarget = Math.max(0, dmrActivityTarget - DMR_DECAY_RATE);
if (dmrActivityTarget < 0.1 && dmrEventType !== 'stopped') {
dmrEventType = 'idle';
updateDmrSynthStatus();
}
}
// Smooth approach to target
dmrActivityLevel += (dmrActivityTarget - dmrActivityLevel) * 0.08;
// Determine effective activity (idle breathing when stopped/idle)
let effectiveActivity = dmrActivityLevel;
if (dmrEventType === 'stopped') {
effectiveActivity = 0;
} else if (effectiveActivity < 0.1 && isDmrRunning) {
// Visible idle breathing — shows decoder is alive and listening
effectiveActivity = 0.12 + Math.sin(now / 1000) * 0.06;
}
// Ripple timing for sync events
const syncRippleAge = (dmrEventType === 'sync' && timeSinceEvent < 500) ? 1 - (timeSinceEvent / 500) : 0;
// Voice ripple overlay
const voiceRipple = (dmrEventType === 'voice') ? Math.sin(now / 60) * 0.15 : 0;
// Update bar targets and physics
for (let i = 0; i < DMR_BAR_COUNT; i++) {
const time = now / 200;
const wave1 = Math.sin(time + i * 0.3) * 0.2;
const wave2 = Math.sin(time * 1.7 + i * 0.5) * 0.15;
const randomAmount = 0.05 + effectiveActivity * 0.25;
const random = (Math.random() - 0.5) * randomAmount;
// Bell curve — center bars taller
const centerDist = Math.abs(i - DMR_BAR_COUNT / 2) / (DMR_BAR_COUNT / 2);
const centerBoost = 1 - centerDist * 0.5;
// Sync ripple: center-outward wave burst
let rippleBoost = 0;
if (syncRippleAge > 0) {
const ripplePos = (1 - syncRippleAge) * DMR_BAR_COUNT / 2;
const distFromRipple = Math.abs(i - DMR_BAR_COUNT / 2) - ripplePos;
rippleBoost = Math.max(0, 1 - Math.abs(distFromRipple) / 4) * syncRippleAge * 0.4;
}
const baseHeight = 0.1 + effectiveActivity * 0.55;
dmrSynthBars[i].targetHeight = Math.max(2,
(baseHeight + wave1 + wave2 + random + rippleBoost + voiceRipple) *
effectiveActivity * centerBoost * height
);
// Spring physics
const springStrength = effectiveActivity > 0.3 ? 0.15 : 0.1;
const diff = dmrSynthBars[i].targetHeight - dmrSynthBars[i].height;
dmrSynthBars[i].velocity += diff * springStrength;
dmrSynthBars[i].velocity *= 0.78;
dmrSynthBars[i].height += dmrSynthBars[i].velocity;
dmrSynthBars[i].height = Math.max(2, Math.min(height - 4, dmrSynthBars[i].height));
}
// Draw bars
for (let i = 0; i < DMR_BAR_COUNT; i++) {
const x = i * (barWidth + 2) + 1;
const barHeight = dmrSynthBars[i].height;
const y = (height - barHeight) / 2;
// HSL color by event type
let hue, saturation, lightness;
if (dmrEventType === 'voice' && timeSinceEvent < 3000) {
hue = 30; // Orange
saturation = 85;
lightness = 40 + (barHeight / height) * 25;
} else if (dmrEventType === 'call' && timeSinceEvent < 3000) {
hue = 120; // Green
saturation = 80;
lightness = 35 + (barHeight / height) * 30;
} else if (dmrEventType === 'sync' && timeSinceEvent < 2000) {
hue = 185; // Cyan
saturation = 85;
lightness = 38 + (barHeight / height) * 25;
} else if (dmrEventType === 'stopped') {
hue = 220;
saturation = 20;
lightness = 18 + (barHeight / height) * 8;
} else {
// Idle / decayed
hue = 210;
saturation = 40;
lightness = 25 + (barHeight / height) * 15;
}
// Vertical gradient per bar
const gradient = dmrSynthCtx.createLinearGradient(x, y, x, y + barHeight);
gradient.addColorStop(0, `hsla(${hue}, ${saturation}%, ${lightness + 18}%, 0.85)`);
gradient.addColorStop(0.5, `hsla(${hue}, ${saturation}%, ${lightness}%, 1)`);
gradient.addColorStop(1, `hsla(${hue}, ${saturation}%, ${lightness + 18}%, 0.85)`);
dmrSynthCtx.fillStyle = gradient;
dmrSynthCtx.fillRect(x, y, barWidth, barHeight);
// Glow on tall bars
if (barHeight > height * 0.5 && effectiveActivity > 0.4) {
dmrSynthCtx.shadowColor = `hsla(${hue}, ${saturation}%, 60%, 0.5)`;
dmrSynthCtx.shadowBlur = 8;
dmrSynthCtx.fillRect(x, y, barWidth, barHeight);
dmrSynthCtx.shadowBlur = 0;
}
}
// Center line
dmrSynthCtx.strokeStyle = 'rgba(0, 212, 255, 0.15)';
dmrSynthCtx.lineWidth = 1;
dmrSynthCtx.beginPath();
dmrSynthCtx.moveTo(0, height / 2);
dmrSynthCtx.lineTo(width, height / 2);
dmrSynthCtx.stroke();
dmrSynthAnimationId = requestAnimationFrame(drawDmrSynthesizer);
}
function dmrSynthPulse(type) {
dmrLastEventTime = Date.now();
if (type === 'sync') {
dmrActivityTarget = Math.max(dmrActivityTarget, DMR_BURST_SYNC);
dmrEventType = 'sync';
} else if (type === 'call') {
dmrActivityTarget = DMR_BURST_CALL;
dmrEventType = 'call';
} else if (type === 'voice') {
dmrActivityTarget = DMR_BURST_VOICE;
dmrEventType = 'voice';
} else if (type === 'slot' || type === 'nac') {
dmrActivityTarget = Math.max(dmrActivityTarget, 0.5);
} else if (type === 'raw') {
// Any DSD output means the decoder is alive and processing
dmrActivityTarget = Math.max(dmrActivityTarget, 0.25);
if (dmrEventType === 'idle') dmrEventType = 'raw';
}
// keepalive and status don't change visuals
updateDmrSynthStatus();
}
function updateDmrSynthStatus() {
const el = document.getElementById('dmrSynthStatus');
if (!el) return;
const labels = {
stopped: 'STOPPED',
idle: 'IDLE',
raw: 'LISTENING',
sync: 'SYNC',
call: 'CALL',
voice: 'VOICE'
};
const colors = {
stopped: 'var(--text-muted)',
idle: 'var(--text-muted)',
raw: '#607d8b',
sync: '#00e5ff',
call: '#4caf50',
voice: '#ff9800'
};
el.textContent = labels[dmrEventType] || 'IDLE';
el.style.color = colors[dmrEventType] || 'var(--text-muted)';
}
function resizeDmrSynthesizer() {
if (!dmrSynthCanvas) return;
const rect = dmrSynthCanvas.getBoundingClientRect();
if (rect.width > 0) {
dmrSynthCanvas.width = Math.round(rect.width);
dmrSynthCanvas.height = Math.round(rect.height) || 70;
}
}
function stopDmrSynthesizer() {
if (dmrSynthAnimationId) {
cancelAnimationFrame(dmrSynthAnimationId);
dmrSynthAnimationId = null;
}
}
window.addEventListener('resize', resizeDmrSynthesizer);
// ============== AUDIO ==============
function startDmrAudio() {
const audioPlayer = document.getElementById('dmrAudioPlayer');
if (!audioPlayer) return;
const streamUrl = `/dmr/audio/stream?t=${Date.now()}`;
audioPlayer.src = streamUrl;
const volSlider = document.getElementById('dmrAudioVolume');
if (volSlider) audioPlayer.volume = volSlider.value / 100;
audioPlayer.onplaying = () => updateDmrAudioStatus('STREAMING');
audioPlayer.onerror = () => {
// Retry if decoder is still running (stream may have dropped)
if (isDmrRunning && dmrHasAudio) {
console.warn('[DMR] Audio stream error, retrying in 2s...');
updateDmrAudioStatus('RECONNECTING');
setTimeout(() => {
if (isDmrRunning && dmrHasAudio) startDmrAudio();
}, 2000);
} else {
updateDmrAudioStatus('OFF');
}
};
audioPlayer.play().catch(e => {
console.warn('[DMR] Audio autoplay blocked:', e);
if (typeof showNotification === 'function') {
showNotification('Audio Ready', 'Click the page or interact to enable audio playback');
}
});
}
function stopDmrAudio() {
const audioPlayer = document.getElementById('dmrAudioPlayer');
if (audioPlayer) {
audioPlayer.pause();
audioPlayer.src = '';
}
dmrHasAudio = false;
}
function setDmrAudioVolume(value) {
const audioPlayer = document.getElementById('dmrAudioPlayer');
if (audioPlayer) audioPlayer.volume = value / 100;
}
function updateDmrAudioStatus(status) {
const el = document.getElementById('dmrAudioStatus');
if (!el) return;
el.textContent = status;
const colors = {
'OFF': 'var(--text-muted)',
'STREAMING': 'var(--accent-green)',
'ERROR': 'var(--accent-red)',
'UNAVAILABLE': 'var(--text-muted)',
};
el.style.color = colors[status] || 'var(--text-muted)';
}
// ============== SETTINGS PERSISTENCE ==============
function restoreDmrSettings() {
try {
const saved = localStorage.getItem(DMR_SETTINGS_KEY);
if (!saved) return;
const s = JSON.parse(saved);
const freqEl = document.getElementById('dmrFrequency');
const protoEl = document.getElementById('dmrProtocol');
const gainEl = document.getElementById('dmrGain');
const ppmEl = document.getElementById('dmrPPM');
const crcEl = document.getElementById('dmrRelaxCrc');
if (freqEl && s.frequency != null) freqEl.value = s.frequency;
if (protoEl && s.protocol) protoEl.value = s.protocol;
if (gainEl && s.gain != null) gainEl.value = s.gain;
if (ppmEl && s.ppm != null) ppmEl.value = s.ppm;
if (crcEl && s.relaxCrc != null) crcEl.checked = s.relaxCrc;
} catch (e) { /* localStorage unavailable */ }
}
// ============== BOOKMARKS ==============
function loadDmrBookmarks() {
try {
const saved = localStorage.getItem(DMR_BOOKMARKS_KEY);
const parsed = saved ? JSON.parse(saved) : [];
if (!Array.isArray(parsed)) {
dmrBookmarks = [];
} else {
dmrBookmarks = parsed
.map((entry) => {
const freq = Number(entry?.freq);
if (!Number.isFinite(freq) || freq <= 0) return null;
const protocol = sanitizeDmrBookmarkProtocol(entry?.protocol);
const rawLabel = String(entry?.label || '').trim();
const label = rawLabel || `${freq.toFixed(4)} MHz`;
return {
freq,
protocol,
label,
added: entry?.added,
};
})
.filter(Boolean);
}
} catch (e) {
dmrBookmarks = [];
}
renderDmrBookmarks();
}
function saveDmrBookmarks() {
try {
localStorage.setItem(DMR_BOOKMARKS_KEY, JSON.stringify(dmrBookmarks));
} catch (e) { /* localStorage unavailable */ }
}
function sanitizeDmrBookmarkProtocol(protocol) {
const value = String(protocol || 'auto').toLowerCase();
return DMR_BOOKMARK_PROTOCOLS.has(value) ? value : 'auto';
}
function addDmrBookmark() {
const freqInput = document.getElementById('dmrBookmarkFreq');
const labelInput = document.getElementById('dmrBookmarkLabel');
if (!freqInput) return;
const freq = parseFloat(freqInput.value);
if (isNaN(freq) || freq <= 0) {
if (typeof showNotification === 'function') {
showNotification('Invalid Frequency', 'Enter a valid frequency');
}
return;
}
const protocol = sanitizeDmrBookmarkProtocol(document.getElementById('dmrProtocol')?.value || 'auto');
const label = (labelInput?.value || '').trim() || `${freq.toFixed(4)} MHz`;
// Duplicate check
if (dmrBookmarks.some(b => b.freq === freq && b.protocol === protocol)) {
if (typeof showNotification === 'function') {
showNotification('Duplicate', 'This frequency/protocol is already bookmarked');
}
return;
}
dmrBookmarks.push({ freq, protocol, label, added: new Date().toISOString() });
saveDmrBookmarks();
renderDmrBookmarks();
freqInput.value = '';
if (labelInput) labelInput.value = '';
if (typeof showNotification === 'function') {
showNotification('Bookmark Added', `${freq.toFixed(4)} MHz saved`);
}
}
function addCurrentDmrFreqBookmark() {
const freqEl = document.getElementById('dmrFrequency');
const freqInput = document.getElementById('dmrBookmarkFreq');
if (freqEl && freqInput) {
freqInput.value = freqEl.value;
}
addDmrBookmark();
}
function removeDmrBookmark(index) {
dmrBookmarks.splice(index, 1);
saveDmrBookmarks();
renderDmrBookmarks();
}
function dmrQuickTune(freq, protocol) {
const freqEl = document.getElementById('dmrFrequency');
const protoEl = document.getElementById('dmrProtocol');
if (freqEl && Number.isFinite(freq)) freqEl.value = freq;
if (protoEl) protoEl.value = sanitizeDmrBookmarkProtocol(protocol);
}
function renderDmrBookmarks() {
const container = document.getElementById('dmrBookmarksList');
if (!container) return;
container.replaceChildren();
if (dmrBookmarks.length === 0) {
const emptyEl = document.createElement('div');
emptyEl.style.color = 'var(--text-muted)';
emptyEl.style.textAlign = 'center';
emptyEl.style.padding = '10px';
emptyEl.style.fontSize = '11px';
emptyEl.textContent = 'No bookmarks saved';
container.appendChild(emptyEl);
return;
}
dmrBookmarks.forEach((b, i) => {
const row = document.createElement('div');
row.style.display = 'flex';
row.style.justifyContent = 'space-between';
row.style.alignItems = 'center';
row.style.padding = '4px 6px';
row.style.background = 'rgba(0,0,0,0.2)';
row.style.borderRadius = '3px';
row.style.marginBottom = '3px';
const tuneBtn = document.createElement('button');
tuneBtn.type = 'button';
tuneBtn.style.cursor = 'pointer';
tuneBtn.style.color = 'var(--accent-cyan)';
tuneBtn.style.fontSize = '11px';
tuneBtn.style.flex = '1';
tuneBtn.style.background = 'none';
tuneBtn.style.border = 'none';
tuneBtn.style.textAlign = 'left';
tuneBtn.style.padding = '0';
tuneBtn.textContent = b.label;
tuneBtn.title = `${b.freq.toFixed(4)} MHz (${b.protocol.toUpperCase()})`;
tuneBtn.addEventListener('click', () => dmrQuickTune(b.freq, b.protocol));
const protocolEl = document.createElement('span');
protocolEl.style.color = 'var(--text-muted)';
protocolEl.style.fontSize = '9px';
protocolEl.style.margin = '0 6px';
protocolEl.textContent = b.protocol.toUpperCase();
const deleteBtn = document.createElement('button');
deleteBtn.type = 'button';
deleteBtn.style.background = 'none';
deleteBtn.style.border = 'none';
deleteBtn.style.color = 'var(--accent-red)';
deleteBtn.style.cursor = 'pointer';
deleteBtn.style.fontSize = '12px';
deleteBtn.style.padding = '0 4px';
deleteBtn.textContent = '\u00d7';
deleteBtn.addEventListener('click', () => removeDmrBookmark(i));
row.appendChild(tuneBtn);
row.appendChild(protocolEl);
row.appendChild(deleteBtn);
container.appendChild(row);
});
}
// ============== STATUS SYNC ==============
function checkDmrStatus() {
fetch('/dmr/status')
.then(r => r.json())
.then(data => {
if (data.running && !isDmrRunning) {
// Backend is running but frontend lost track — resync
isDmrRunning = true;
updateDmrUI();
connectDmrSSE();
if (!dmrSynthInitialized) initDmrSynthesizer();
dmrEventType = 'idle';
dmrActivityTarget = 0.1;
dmrLastEventTime = Date.now();
updateDmrSynthStatus();
const statusEl = document.getElementById('dmrStatus');
if (statusEl) statusEl.textContent = 'DECODING';
} else if (!data.running && isDmrRunning) {
// Backend stopped but frontend didn't know
isDmrRunning = false;
if (dmrEventSource) { dmrEventSource.close(); dmrEventSource = null; }
updateDmrUI();
dmrEventType = 'stopped';
dmrActivityTarget = 0;
updateDmrSynthStatus();
const statusEl = document.getElementById('dmrStatus');
if (statusEl) statusEl.textContent = 'STOPPED';
}
})
.catch(() => {});
}
// ============== INIT ==============
document.addEventListener('DOMContentLoaded', () => {
restoreDmrSettings();
loadDmrBookmarks();
});
// ============== EXPORTS ==============
window.startDmr = startDmr;
window.stopDmr = stopDmr;
window.checkDmrTools = checkDmrTools;
window.checkDmrStatus = checkDmrStatus;
window.initDmrSynthesizer = initDmrSynthesizer;
window.setDmrAudioVolume = setDmrAudioVolume;
window.addDmrBookmark = addDmrBookmark;
window.addCurrentDmrFreqBookmark = addCurrentDmrFreqBookmark;
window.removeDmrBookmark = removeDmrBookmark;
window.dmrQuickTune = dmrQuickTune;
+686 -28
View File
@@ -9,6 +9,9 @@ const GPS = (function() {
let lastPosition = null; let lastPosition = null;
let lastSky = null; let lastSky = null;
let skyPollTimer = null; let skyPollTimer = null;
let themeObserver = null;
let skyRenderer = null;
let skyRendererInitAttempted = false;
// Constellation color map // Constellation color map
const CONST_COLORS = { const CONST_COLORS = {
@@ -21,8 +24,43 @@ const GPS = (function() {
}; };
function init() { function init() {
initSkyRenderer();
drawEmptySkyView(); drawEmptySkyView();
connect(); if (!connected) connect();
// Redraw sky view when theme changes
if (!themeObserver) {
themeObserver = new MutationObserver(() => {
if (skyRenderer && typeof skyRenderer.requestRender === 'function') {
skyRenderer.requestRender();
}
if (lastSky) {
drawSkyView(lastSky.satellites || []);
} else {
drawEmptySkyView();
}
});
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
}
if (lastPosition) updatePositionUI(lastPosition);
if (lastSky) updateSkyUI(lastSky);
}
function initSkyRenderer() {
if (skyRendererInitAttempted) return;
skyRendererInitAttempted = true;
const canvas = document.getElementById('gpsSkyCanvas');
if (!canvas) return;
const overlay = document.getElementById('gpsSkyOverlay');
try {
skyRenderer = createWebGlSkyRenderer(canvas, overlay);
} catch (err) {
skyRenderer = null;
console.warn('GPS sky WebGL renderer failed, falling back to 2D', err);
}
} }
function connect() { function connect() {
@@ -243,41 +281,61 @@ const GPS = (function() {
} }
// ======================== // ========================
// Sky View Polar Plot // Sky View Globe (WebGL with 2D fallback)
// ======================== // ========================
function drawEmptySkyView() { function drawEmptySkyView() {
if (!skyRendererInitAttempted) {
initSkyRenderer();
}
if (skyRenderer) {
skyRenderer.setSatellites([]);
return;
}
const canvas = document.getElementById('gpsSkyCanvas'); const canvas = document.getElementById('gpsSkyCanvas');
if (!canvas) return; if (!canvas) return;
drawSkyViewBase(canvas); drawSkyViewBase2D(canvas);
} }
function drawSkyView(satellites) { function drawSkyView(satellites) {
if (!skyRendererInitAttempted) {
initSkyRenderer();
}
const sats = Array.isArray(satellites) ? satellites : [];
if (skyRenderer) {
skyRenderer.setSatellites(sats);
return;
}
const canvas = document.getElementById('gpsSkyCanvas'); const canvas = document.getElementById('gpsSkyCanvas');
if (!canvas) return; if (!canvas) return;
drawSkyViewBase2D(canvas);
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
if (!ctx) return;
const w = canvas.width; const w = canvas.width;
const h = canvas.height; const h = canvas.height;
const cx = w / 2; const cx = w / 2;
const cy = h / 2; const cy = h / 2;
const r = Math.min(cx, cy) - 24; const r = Math.min(cx, cy) - 24;
drawSkyViewBase(canvas); sats.forEach(sat => {
// Plot satellites
satellites.forEach(sat => {
if (sat.elevation == null || sat.azimuth == null) return; if (sat.elevation == null || sat.azimuth == null) return;
const elRad = (90 - sat.elevation) / 90; const elRad = (90 - sat.elevation) / 90;
const azRad = (sat.azimuth - 90) * Math.PI / 180; // N = up const azRad = (sat.azimuth - 90) * Math.PI / 180;
const px = cx + r * elRad * Math.cos(azRad); const px = cx + r * elRad * Math.cos(azRad);
const py = cy + r * elRad * Math.sin(azRad); const py = cy + r * elRad * Math.sin(azRad);
const color = CONST_COLORS[sat.constellation] || CONST_COLORS['GPS']; const color = CONST_COLORS[sat.constellation] || CONST_COLORS.GPS;
const dotSize = sat.used ? 6 : 4; const dotSize = sat.used ? 6 : 4;
// Draw dot
ctx.beginPath(); ctx.beginPath();
ctx.arc(px, py, dotSize, 0, Math.PI * 2); ctx.arc(px, py, dotSize, 0, Math.PI * 2);
if (sat.used) { if (sat.used) {
@@ -289,14 +347,12 @@ const GPS = (function() {
ctx.stroke(); ctx.stroke();
} }
// PRN label
ctx.fillStyle = color; ctx.fillStyle = color;
ctx.font = '8px Roboto Condensed, monospace'; ctx.font = '8px Roboto Condensed, monospace';
ctx.textAlign = 'center'; ctx.textAlign = 'center';
ctx.textBaseline = 'bottom'; ctx.textBaseline = 'bottom';
ctx.fillText(sat.prn, px, py - dotSize - 2); ctx.fillText(sat.prn, px, py - dotSize - 2);
// SNR value
if (sat.snr != null) { if (sat.snr != null) {
ctx.fillStyle = 'rgba(255,255,255,0.4)'; ctx.fillStyle = 'rgba(255,255,255,0.4)';
ctx.font = '7px Roboto Condensed, monospace'; ctx.font = '7px Roboto Condensed, monospace';
@@ -306,8 +362,10 @@ const GPS = (function() {
}); });
} }
function drawSkyViewBase(canvas) { function drawSkyViewBase2D(canvas) {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
if (!ctx) return;
const w = canvas.width; const w = canvas.width;
const h = canvas.height; const h = canvas.height;
const cx = w / 2; const cx = w / 2;
@@ -316,36 +374,37 @@ const GPS = (function() {
ctx.clearRect(0, 0, w, h); ctx.clearRect(0, 0, w, h);
// Background const cs = getComputedStyle(document.documentElement);
const bgStyle = getComputedStyle(document.documentElement).getPropertyValue('--bg-card').trim(); const bgColor = cs.getPropertyValue('--bg-card').trim() || '#0d1117';
ctx.fillStyle = bgStyle || '#0d1117'; const gridColor = cs.getPropertyValue('--border-color').trim() || '#2a3040';
const dimColor = cs.getPropertyValue('--text-dim').trim() || '#555';
const secondaryColor = cs.getPropertyValue('--text-secondary').trim() || '#888';
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, w, h); ctx.fillRect(0, 0, w, h);
// Elevation rings (0, 30, 60, 90) ctx.strokeStyle = gridColor;
ctx.strokeStyle = '#2a3040';
ctx.lineWidth = 0.5; ctx.lineWidth = 0.5;
[90, 60, 30].forEach(el => { [90, 60, 30].forEach(el => {
const gr = r * (1 - el / 90); const gr = r * (1 - el / 90);
ctx.beginPath(); ctx.beginPath();
ctx.arc(cx, cy, gr, 0, Math.PI * 2); ctx.arc(cx, cy, gr, 0, Math.PI * 2);
ctx.stroke(); ctx.stroke();
// Label
ctx.fillStyle = '#555'; ctx.fillStyle = dimColor;
ctx.font = '9px Roboto Condensed, monospace'; ctx.font = '9px Roboto Condensed, monospace';
ctx.textAlign = 'left'; ctx.textAlign = 'left';
ctx.textBaseline = 'middle'; ctx.textBaseline = 'middle';
ctx.fillText(el + '\u00b0', cx + gr + 3, cy - 2); ctx.fillText(el + '\u00b0', cx + gr + 3, cy - 2);
}); });
// Horizon circle ctx.strokeStyle = gridColor;
ctx.strokeStyle = '#3a4050';
ctx.lineWidth = 1; ctx.lineWidth = 1;
ctx.beginPath(); ctx.beginPath();
ctx.arc(cx, cy, r, 0, Math.PI * 2); ctx.arc(cx, cy, r, 0, Math.PI * 2);
ctx.stroke(); ctx.stroke();
// Cardinal directions ctx.fillStyle = secondaryColor;
ctx.fillStyle = '#888';
ctx.font = 'bold 11px Roboto Condensed, monospace'; ctx.font = 'bold 11px Roboto Condensed, monospace';
ctx.textAlign = 'center'; ctx.textAlign = 'center';
ctx.textBaseline = 'middle'; ctx.textBaseline = 'middle';
@@ -354,8 +413,7 @@ const GPS = (function() {
ctx.fillText('E', cx + r + 12, cy); ctx.fillText('E', cx + r + 12, cy);
ctx.fillText('W', cx - r - 12, cy); ctx.fillText('W', cx - r - 12, cy);
// Crosshairs ctx.strokeStyle = gridColor;
ctx.strokeStyle = '#2a3040';
ctx.lineWidth = 0.5; ctx.lineWidth = 0.5;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(cx, cy - r); ctx.moveTo(cx, cy - r);
@@ -364,13 +422,604 @@ const GPS = (function() {
ctx.lineTo(cx + r, cy); ctx.lineTo(cx + r, cy);
ctx.stroke(); ctx.stroke();
// Zenith dot ctx.fillStyle = dimColor;
ctx.fillStyle = '#333';
ctx.beginPath(); ctx.beginPath();
ctx.arc(cx, cy, 2, 0, Math.PI * 2); ctx.arc(cx, cy, 2, 0, Math.PI * 2);
ctx.fill(); ctx.fill();
} }
function createWebGlSkyRenderer(canvas, overlay) {
const gl = canvas.getContext('webgl', { antialias: true, alpha: false, depth: true });
if (!gl) return null;
const lineProgram = createProgram(
gl,
[
'attribute vec3 aPosition;',
'uniform mat4 uMVP;',
'void main(void) {',
' gl_Position = uMVP * vec4(aPosition, 1.0);',
'}',
].join('\n'),
[
'precision mediump float;',
'uniform vec4 uColor;',
'void main(void) {',
' gl_FragColor = uColor;',
'}',
].join('\n'),
);
const pointProgram = createProgram(
gl,
[
'attribute vec3 aPosition;',
'attribute vec4 aColor;',
'attribute float aSize;',
'attribute float aUsed;',
'uniform mat4 uMVP;',
'uniform float uDevicePixelRatio;',
'uniform vec3 uCameraDir;',
'varying vec4 vColor;',
'varying float vUsed;',
'varying float vFacing;',
'void main(void) {',
' vec3 normPos = normalize(aPosition);',
' vFacing = dot(normPos, normalize(uCameraDir));',
' gl_Position = uMVP * vec4(aPosition, 1.0);',
' gl_PointSize = aSize * uDevicePixelRatio;',
' vColor = aColor;',
' vUsed = aUsed;',
'}',
].join('\n'),
[
'precision mediump float;',
'varying vec4 vColor;',
'varying float vUsed;',
'varying float vFacing;',
'void main(void) {',
' if (vFacing <= 0.0) discard;',
' vec2 c = gl_PointCoord * 2.0 - 1.0;',
' float d = dot(c, c);',
' if (d > 1.0) discard;',
' if (vUsed < 0.5 && d < 0.45) discard;',
' float edge = smoothstep(1.0, 0.75, d);',
' gl_FragColor = vec4(vColor.rgb, vColor.a * edge);',
'}',
].join('\n'),
);
if (!lineProgram || !pointProgram) return null;
const lineLoc = {
position: gl.getAttribLocation(lineProgram, 'aPosition'),
mvp: gl.getUniformLocation(lineProgram, 'uMVP'),
color: gl.getUniformLocation(lineProgram, 'uColor'),
};
const pointLoc = {
position: gl.getAttribLocation(pointProgram, 'aPosition'),
color: gl.getAttribLocation(pointProgram, 'aColor'),
size: gl.getAttribLocation(pointProgram, 'aSize'),
used: gl.getAttribLocation(pointProgram, 'aUsed'),
mvp: gl.getUniformLocation(pointProgram, 'uMVP'),
dpr: gl.getUniformLocation(pointProgram, 'uDevicePixelRatio'),
cameraDir: gl.getUniformLocation(pointProgram, 'uCameraDir'),
};
const gridVertices = buildSkyGridVertices();
const horizonVertices = buildSkyRingVertices(0, 4);
const gridBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, gridBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gridVertices, gl.STATIC_DRAW);
const horizonBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, horizonBuffer);
gl.bufferData(gl.ARRAY_BUFFER, horizonVertices, gl.STATIC_DRAW);
const satPosBuffer = gl.createBuffer();
const satColorBuffer = gl.createBuffer();
const satSizeBuffer = gl.createBuffer();
const satUsedBuffer = gl.createBuffer();
let satCount = 0;
let satLabels = [];
let cssWidth = 0;
let cssHeight = 0;
let devicePixelRatio = 1;
let mvpMatrix = identityMat4();
let cameraDir = [0, 1, 0];
let yaw = 0.8;
let pitch = 0.6;
let distance = 2.7;
let rafId = null;
let destroyed = false;
let activePointerId = null;
let lastPointerX = 0;
let lastPointerY = 0;
const resizeObserver = (typeof ResizeObserver !== 'undefined')
? new ResizeObserver(() => {
requestRender();
})
: null;
if (resizeObserver) resizeObserver.observe(canvas);
canvas.addEventListener('pointerdown', onPointerDown);
canvas.addEventListener('pointermove', onPointerMove);
canvas.addEventListener('pointerup', onPointerUp);
canvas.addEventListener('pointercancel', onPointerUp);
canvas.addEventListener('wheel', onWheel, { passive: false });
requestRender();
function onPointerDown(evt) {
activePointerId = evt.pointerId;
lastPointerX = evt.clientX;
lastPointerY = evt.clientY;
if (canvas.setPointerCapture) canvas.setPointerCapture(evt.pointerId);
}
function onPointerMove(evt) {
if (activePointerId == null || evt.pointerId !== activePointerId) return;
const dx = evt.clientX - lastPointerX;
const dy = evt.clientY - lastPointerY;
lastPointerX = evt.clientX;
lastPointerY = evt.clientY;
yaw += dx * 0.01;
pitch += dy * 0.01;
pitch = Math.max(0.1, Math.min(1.45, pitch));
requestRender();
}
function onPointerUp(evt) {
if (activePointerId == null || evt.pointerId !== activePointerId) return;
if (canvas.releasePointerCapture) {
try {
canvas.releasePointerCapture(evt.pointerId);
} catch (_) {}
}
activePointerId = null;
}
function onWheel(evt) {
evt.preventDefault();
distance += evt.deltaY * 0.002;
distance = Math.max(2.0, Math.min(5.0, distance));
requestRender();
}
function setSatellites(satellites) {
const positions = [];
const colors = [];
const sizes = [];
const usedFlags = [];
const labels = [];
(satellites || []).forEach(sat => {
if (sat.elevation == null || sat.azimuth == null) return;
const xyz = skyToCartesian(sat.azimuth, sat.elevation);
const hex = CONST_COLORS[sat.constellation] || CONST_COLORS.GPS;
const rgb = hexToRgb01(hex);
positions.push(xyz[0], xyz[1], xyz[2]);
colors.push(rgb[0], rgb[1], rgb[2], sat.used ? 1 : 0.85);
sizes.push(sat.used ? 8 : 7);
usedFlags.push(sat.used ? 1 : 0);
labels.push({
text: String(sat.prn),
point: xyz,
color: hex,
used: !!sat.used,
});
});
satLabels = labels;
satCount = positions.length / 3;
gl.bindBuffer(gl.ARRAY_BUFFER, satPosBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.DYNAMIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, satColorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.DYNAMIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, satSizeBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(sizes), gl.DYNAMIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, satUsedBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(usedFlags), gl.DYNAMIC_DRAW);
requestRender();
}
function requestRender() {
if (destroyed || rafId != null) return;
rafId = requestAnimationFrame(render);
}
function render() {
rafId = null;
if (destroyed) return;
resizeCanvas();
updateCameraMatrices();
const palette = getThemePalette();
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(palette.bg[0], palette.bg[1], palette.bg[2], 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
gl.useProgram(lineProgram);
gl.uniformMatrix4fv(lineLoc.mvp, false, mvpMatrix);
gl.bindBuffer(gl.ARRAY_BUFFER, gridBuffer);
gl.enableVertexAttribArray(lineLoc.position);
gl.vertexAttribPointer(lineLoc.position, 3, gl.FLOAT, false, 0, 0);
gl.uniform4fv(lineLoc.color, palette.grid);
gl.drawArrays(gl.LINES, 0, gridVertices.length / 3);
gl.bindBuffer(gl.ARRAY_BUFFER, horizonBuffer);
gl.vertexAttribPointer(lineLoc.position, 3, gl.FLOAT, false, 0, 0);
gl.uniform4fv(lineLoc.color, palette.horizon);
gl.drawArrays(gl.LINES, 0, horizonVertices.length / 3);
if (satCount > 0) {
gl.useProgram(pointProgram);
gl.uniformMatrix4fv(pointLoc.mvp, false, mvpMatrix);
gl.uniform1f(pointLoc.dpr, devicePixelRatio);
gl.uniform3fv(pointLoc.cameraDir, new Float32Array(cameraDir));
gl.bindBuffer(gl.ARRAY_BUFFER, satPosBuffer);
gl.enableVertexAttribArray(pointLoc.position);
gl.vertexAttribPointer(pointLoc.position, 3, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, satColorBuffer);
gl.enableVertexAttribArray(pointLoc.color);
gl.vertexAttribPointer(pointLoc.color, 4, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, satSizeBuffer);
gl.enableVertexAttribArray(pointLoc.size);
gl.vertexAttribPointer(pointLoc.size, 1, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, satUsedBuffer);
gl.enableVertexAttribArray(pointLoc.used);
gl.vertexAttribPointer(pointLoc.used, 1, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.POINTS, 0, satCount);
}
drawOverlayLabels();
}
function resizeCanvas() {
cssWidth = Math.max(1, Math.floor(canvas.clientWidth || 400));
cssHeight = Math.max(1, Math.floor(canvas.clientHeight || 400));
devicePixelRatio = Math.min(window.devicePixelRatio || 1, 2);
const renderWidth = Math.floor(cssWidth * devicePixelRatio);
const renderHeight = Math.floor(cssHeight * devicePixelRatio);
if (canvas.width !== renderWidth || canvas.height !== renderHeight) {
canvas.width = renderWidth;
canvas.height = renderHeight;
}
}
function updateCameraMatrices() {
const cosPitch = Math.cos(pitch);
const eye = [
distance * Math.sin(yaw) * cosPitch,
distance * Math.sin(pitch),
distance * Math.cos(yaw) * cosPitch,
];
const eyeLen = Math.hypot(eye[0], eye[1], eye[2]) || 1;
cameraDir = [eye[0] / eyeLen, eye[1] / eyeLen, eye[2] / eyeLen];
const view = mat4LookAt(eye, [0, 0, 0], [0, 1, 0]);
const proj = mat4Perspective(degToRad(48), Math.max(cssWidth / cssHeight, 0.01), 0.1, 20);
mvpMatrix = mat4Multiply(proj, view);
}
function drawOverlayLabels() {
if (!overlay) return;
const fragment = document.createDocumentFragment();
const cardinals = [
{ text: 'N', point: [0, 0, 1] },
{ text: 'E', point: [1, 0, 0] },
{ text: 'S', point: [0, 0, -1] },
{ text: 'W', point: [-1, 0, 0] },
{ text: 'Z', point: [0, 1, 0] },
];
cardinals.forEach(entry => {
addLabel(fragment, entry.text, entry.point, 'gps-sky-label gps-sky-label-cardinal');
});
satLabels.forEach(sat => {
const cls = 'gps-sky-label gps-sky-label-sat' + (sat.used ? '' : ' unused');
addLabel(fragment, sat.text, sat.point, cls, sat.color);
});
overlay.replaceChildren(fragment);
}
function addLabel(fragment, text, point, className, color) {
const facing = point[0] * cameraDir[0] + point[1] * cameraDir[1] + point[2] * cameraDir[2];
if (facing <= 0.02) return;
const projected = projectPoint(point, mvpMatrix, cssWidth, cssHeight);
if (!projected) return;
const label = document.createElement('span');
label.className = className;
label.textContent = text;
label.style.left = projected.x.toFixed(1) + 'px';
label.style.top = projected.y.toFixed(1) + 'px';
if (color) label.style.color = color;
fragment.appendChild(label);
}
function getThemePalette() {
const cs = getComputedStyle(document.documentElement);
const bg = parseCssColor(cs.getPropertyValue('--bg-card').trim(), '#0d1117');
const grid = parseCssColor(cs.getPropertyValue('--border-color').trim(), '#3a4254');
const accent = parseCssColor(cs.getPropertyValue('--accent-cyan').trim(), '#4aa3ff');
return {
bg: bg,
grid: [grid[0], grid[1], grid[2], 0.42],
horizon: [accent[0], accent[1], accent[2], 0.56],
};
}
function destroy() {
destroyed = true;
if (rafId != null) cancelAnimationFrame(rafId);
canvas.removeEventListener('pointerdown', onPointerDown);
canvas.removeEventListener('pointermove', onPointerMove);
canvas.removeEventListener('pointerup', onPointerUp);
canvas.removeEventListener('pointercancel', onPointerUp);
canvas.removeEventListener('wheel', onWheel);
if (resizeObserver) {
try {
resizeObserver.disconnect();
} catch (_) {}
}
if (overlay) overlay.replaceChildren();
}
return {
setSatellites: setSatellites,
requestRender: requestRender,
destroy: destroy,
};
}
function buildSkyGridVertices() {
const vertices = [];
[15, 30, 45, 60, 75].forEach(el => {
appendLineStrip(vertices, buildRingPoints(el, 6));
});
for (let az = 0; az < 360; az += 30) {
appendLineStrip(vertices, buildMeridianPoints(az, 5));
}
return new Float32Array(vertices);
}
function buildSkyRingVertices(elevation, stepAz) {
const vertices = [];
appendLineStrip(vertices, buildRingPoints(elevation, stepAz));
return new Float32Array(vertices);
}
function buildRingPoints(elevation, stepAz) {
const points = [];
for (let az = 0; az <= 360; az += stepAz) {
points.push(skyToCartesian(az, elevation));
}
return points;
}
function buildMeridianPoints(azimuth, stepEl) {
const points = [];
for (let el = 0; el <= 90; el += stepEl) {
points.push(skyToCartesian(azimuth, el));
}
return points;
}
function appendLineStrip(target, points) {
for (let i = 1; i < points.length; i += 1) {
const a = points[i - 1];
const b = points[i];
target.push(a[0], a[1], a[2], b[0], b[1], b[2]);
}
}
function skyToCartesian(azimuthDeg, elevationDeg) {
const az = degToRad(azimuthDeg);
const el = degToRad(elevationDeg);
const cosEl = Math.cos(el);
return [
cosEl * Math.sin(az),
Math.sin(el),
cosEl * Math.cos(az),
];
}
function degToRad(deg) {
return deg * Math.PI / 180;
}
function createProgram(gl, vertexSource, fragmentSource) {
const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
if (!vertexShader || !fragmentShader) return null;
const program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.warn('WebGL program link failed:', gl.getProgramInfoLog(program));
gl.deleteProgram(program);
return null;
}
return program;
}
function compileShader(gl, type, source) {
const shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
console.warn('WebGL shader compile failed:', gl.getShaderInfoLog(shader));
gl.deleteShader(shader);
return null;
}
return shader;
}
function identityMat4() {
return new Float32Array([
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
]);
}
function mat4Perspective(fovy, aspect, near, far) {
const f = 1 / Math.tan(fovy / 2);
const nf = 1 / (near - far);
return new Float32Array([
f / aspect, 0, 0, 0,
0, f, 0, 0,
0, 0, (far + near) * nf, -1,
0, 0, (2 * far * near) * nf, 0,
]);
}
function mat4LookAt(eye, center, up) {
const zx = eye[0] - center[0];
const zy = eye[1] - center[1];
const zz = eye[2] - center[2];
const zLen = Math.hypot(zx, zy, zz) || 1;
const znx = zx / zLen;
const zny = zy / zLen;
const znz = zz / zLen;
const xx = up[1] * znz - up[2] * zny;
const xy = up[2] * znx - up[0] * znz;
const xz = up[0] * zny - up[1] * znx;
const xLen = Math.hypot(xx, xy, xz) || 1;
const xnx = xx / xLen;
const xny = xy / xLen;
const xnz = xz / xLen;
const ynx = zny * xnz - znz * xny;
const yny = znz * xnx - znx * xnz;
const ynz = znx * xny - zny * xnx;
return new Float32Array([
xnx, ynx, znx, 0,
xny, yny, zny, 0,
xnz, ynz, znz, 0,
-(xnx * eye[0] + xny * eye[1] + xnz * eye[2]),
-(ynx * eye[0] + yny * eye[1] + ynz * eye[2]),
-(znx * eye[0] + zny * eye[1] + znz * eye[2]),
1,
]);
}
function mat4Multiply(a, b) {
const out = new Float32Array(16);
for (let col = 0; col < 4; col += 1) {
for (let row = 0; row < 4; row += 1) {
out[col * 4 + row] =
a[row] * b[col * 4] +
a[4 + row] * b[col * 4 + 1] +
a[8 + row] * b[col * 4 + 2] +
a[12 + row] * b[col * 4 + 3];
}
}
return out;
}
function projectPoint(point, matrix, width, height) {
const x = point[0];
const y = point[1];
const z = point[2];
const clipX = matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12];
const clipY = matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13];
const clipW = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15];
if (clipW <= 0.0001) return null;
const ndcX = clipX / clipW;
const ndcY = clipY / clipW;
if (Math.abs(ndcX) > 1.2 || Math.abs(ndcY) > 1.2) return null;
return {
x: (ndcX * 0.5 + 0.5) * width,
y: (1 - (ndcY * 0.5 + 0.5)) * height,
};
}
function parseCssColor(raw, fallbackHex) {
const value = (raw || '').trim();
if (value.startsWith('#')) {
return hexToRgb01(value);
}
const match = value.match(/rgba?\(([^)]+)\)/i);
if (match) {
const parts = match[1].split(',').map(part => parseFloat(part.trim()));
if (parts.length >= 3 && parts.every(n => Number.isFinite(n))) {
return [parts[0] / 255, parts[1] / 255, parts[2] / 255];
}
}
return hexToRgb01(fallbackHex || '#0d1117');
}
function hexToRgb01(hex) {
let clean = (hex || '').trim().replace('#', '');
if (clean.length === 3) {
clean = clean.split('').map(ch => ch + ch).join('');
}
if (!/^[0-9a-fA-F]{6}$/.test(clean)) {
return [0, 0, 0];
}
const num = parseInt(clean, 16);
return [
((num >> 16) & 255) / 255,
((num >> 8) & 255) / 255,
(num & 255) / 255,
];
}
// ======================== // ========================
// Signal Strength Bars // Signal Strength Bars
// ======================== // ========================
@@ -427,6 +1076,15 @@ const GPS = (function() {
function destroy() { function destroy() {
unsubscribeFromStream(); unsubscribeFromStream();
stopSkyPolling(); stopSkyPolling();
if (themeObserver) {
themeObserver.disconnect();
themeObserver = null;
}
if (skyRenderer) {
skyRenderer.destroy();
skyRenderer = null;
}
skyRendererInitAttempted = false;
} }
return { return {
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -401,7 +401,7 @@ const Meshtastic = (function() {
// Position is nested in the response // Position is nested in the response
const pos = info.position; const pos = info.position;
if (pos && pos.latitude && pos.longitude) { if (pos && pos.latitude !== undefined && pos.latitude !== null && pos.longitude !== undefined && pos.longitude !== null) {
if (posRow) posRow.style.display = 'flex'; if (posRow) posRow.style.display = 'flex';
if (posEl) posEl.textContent = `${pos.latitude.toFixed(5)}, ${pos.longitude.toFixed(5)}`; if (posEl) posEl.textContent = `${pos.latitude.toFixed(5)}, ${pos.longitude.toFixed(5)}`;
} else { } else {
+677
View File
@@ -0,0 +1,677 @@
/**
* Space Weather Mode IIFE module
* Polls /space-weather/data every 5 min, renders dashboard with Chart.js
*/
const SpaceWeather = (function () {
'use strict';
let _initialized = false;
let _pollTimer = null;
let _autoRefresh = true;
const POLL_INTERVAL = 5 * 60 * 1000; // 5 min
// Chart.js instances
let _kpChart = null;
let _windChart = null;
let _xrayChart = null;
// Current image selections
let _solarImageKey = 'sdo_193';
let _drapFreq = 'drap_global';
// -------------------------------------------------------------------
// Public API
// -------------------------------------------------------------------
function init() {
if (!_initialized) {
_initialized = true;
}
refresh();
_startAutoRefresh();
}
function destroy() {
_stopAutoRefresh();
_destroyCharts();
_initialized = false;
}
function refresh() {
_fetchData();
}
function selectSolarImage(key) {
_solarImageKey = key;
_updateSolarImageTabs();
const frame = document.getElementById('swSolarImageFrame');
if (frame) {
frame.innerHTML = '<div class="sw-loading">Loading</div>';
const img = new Image();
img.onload = function () { frame.innerHTML = ''; frame.appendChild(img); };
img.onerror = function () { frame.innerHTML = '<div class="sw-empty">Failed to load image</div>'; };
img.src = '/space-weather/image/' + key + '?t=' + Date.now();
img.alt = key;
}
}
function selectDrapFreq(key) {
_drapFreq = key;
_updateDrapTabs();
const frame = document.getElementById('swDrapImageFrame');
if (frame) {
frame.innerHTML = '<div class="sw-loading">Loading</div>';
const img = new Image();
img.onload = function () { frame.innerHTML = ''; frame.appendChild(img); };
img.onerror = function () { frame.innerHTML = '<div class="sw-empty">Failed to load image</div>'; };
img.src = '/space-weather/image/' + key + '?t=' + Date.now();
img.alt = key;
}
}
function toggleAutoRefresh() {
const cb = document.getElementById('swAutoRefresh');
_autoRefresh = cb ? cb.checked : !_autoRefresh;
if (_autoRefresh) _startAutoRefresh();
else _stopAutoRefresh();
}
// -------------------------------------------------------------------
// Polling
// -------------------------------------------------------------------
function _startAutoRefresh() {
_stopAutoRefresh();
if (_autoRefresh) {
_pollTimer = setInterval(_fetchData, POLL_INTERVAL);
}
}
function _stopAutoRefresh() {
if (_pollTimer) { clearInterval(_pollTimer); _pollTimer = null; }
}
function _fetchData() {
fetch('/space-weather/data')
.then(function (r) { return r.json(); })
.then(function (data) {
_renderAll(data);
_updateTimestamp();
})
.catch(function (err) {
console.warn('SpaceWeather fetch error:', err);
});
}
// -------------------------------------------------------------------
// Master render
// -------------------------------------------------------------------
function _renderAll(data) {
_renderHeaderStrip(data);
_renderScales(data);
_renderBandConditions(data);
_renderKpChart(data);
_renderWindChart(data);
_renderXrayChart(data);
_renderFlareProb(data);
_renderSolarImage();
_renderDrapImage();
_renderAuroraImage();
_renderAlerts(data);
_renderRegions(data);
_updateSidebar(data);
}
// -------------------------------------------------------------------
// Header strip
// -------------------------------------------------------------------
function _renderHeaderStrip(data) {
var sfi = '--', kp = '--', aIndex = '--', ssn = '--', wind = '--', bz = '--';
// SFI from band_conditions (HamQSL) or flux
if (data.band_conditions && data.band_conditions.sfi) {
sfi = data.band_conditions.sfi;
} else if (data.flux && data.flux.length > 1) {
var last = data.flux[data.flux.length - 1];
sfi = last[1] || '--';
}
// Kp from kp_index
if (data.kp_index && data.kp_index.length > 1) {
var lastKp = data.kp_index[data.kp_index.length - 1];
kp = lastKp[1] || '--';
}
// A-index from band_conditions
if (data.band_conditions && data.band_conditions.aindex) {
aIndex = data.band_conditions.aindex;
}
// Sunspot number
if (data.band_conditions && data.band_conditions.sunspots) {
ssn = data.band_conditions.sunspots;
}
// Solar wind speed — last non-null entry
if (data.solar_wind_plasma && data.solar_wind_plasma.length > 1) {
for (var i = data.solar_wind_plasma.length - 1; i >= 1; i--) {
if (data.solar_wind_plasma[i][2]) {
wind = Math.round(parseFloat(data.solar_wind_plasma[i][2]));
break;
}
}
}
// IMF Bz — last non-null entry
if (data.solar_wind_mag && data.solar_wind_mag.length > 1) {
for (var j = data.solar_wind_mag.length - 1; j >= 1; j--) {
if (data.solar_wind_mag[j][3]) {
bz = parseFloat(data.solar_wind_mag[j][3]).toFixed(1);
break;
}
}
}
_setText('swStripSfi', sfi);
_setText('swStripKp', kp);
_setText('swStripA', aIndex);
_setText('swStripSsn', ssn);
_setText('swStripWind', wind !== '--' ? wind + ' km/s' : '--');
_setText('swStripBz', bz !== '--' ? bz + ' nT' : '--');
// Color Kp by severity
var kpEl = document.getElementById('swStripKp');
if (kpEl) {
var kpNum = parseFloat(kp);
kpEl.className = 'sw-header-value';
if (kpNum >= 7) kpEl.classList.add('accent-red');
else if (kpNum >= 5) kpEl.classList.add('accent-orange');
else if (kpNum >= 4) kpEl.classList.add('accent-yellow');
else kpEl.classList.add('accent-green');
}
// Color Bz — negative is bad
var bzEl = document.getElementById('swStripBz');
if (bzEl) {
var bzNum = parseFloat(bz);
bzEl.className = 'sw-header-value';
if (bzNum < -10) bzEl.classList.add('accent-red');
else if (bzNum < -5) bzEl.classList.add('accent-orange');
else if (bzNum < 0) bzEl.classList.add('accent-yellow');
else bzEl.classList.add('accent-green');
}
}
// -------------------------------------------------------------------
// NOAA Scales
// -------------------------------------------------------------------
function _renderScales(data) {
if (!data.scales) return;
var s = data.scales;
// Structure: { "0": { R: {Scale, Text}, S: {Scale, Text}, G: {Scale, Text} }, ... }
// Key "0" = current conditions
var current = s['0'];
if (!current) return;
var scaleMap = {
'G': { el: 'swScaleG', label: 'Geomagnetic Storms' },
'S': { el: 'swScaleS', label: 'Solar Radiation' },
'R': { el: 'swScaleR', label: 'Radio Blackouts' }
};
['G', 'S', 'R'].forEach(function (k) {
var info = scaleMap[k];
var scaleData = current[k];
var val = '0', text = info.label;
if (scaleData) {
val = String(scaleData.Scale || '0').replace(/[^0-9]/g, '') || '0';
if (scaleData.Text && scaleData.Text !== 'none') {
text = scaleData.Text;
}
}
var el = document.getElementById(info.el);
if (el) {
el.querySelector('.sw-scale-value').textContent = k + val;
el.querySelector('.sw-scale-value').className = 'sw-scale-value sw-scale-' + val;
var descEl = el.querySelector('.sw-scale-desc');
if (descEl) descEl.textContent = text;
}
});
}
// -------------------------------------------------------------------
// Band conditions
// -------------------------------------------------------------------
function _renderBandConditions(data) {
var grid = document.getElementById('swBandGrid');
if (!grid) return;
if (!data.band_conditions || !data.band_conditions.bands || data.band_conditions.bands.length === 0) {
grid.innerHTML = '<div class="sw-empty" style="grid-column:1/-1">No band data available</div>';
return;
}
// Group by band name, collect day/night
var bands = {};
data.band_conditions.bands.forEach(function (b) {
if (!bands[b.name]) bands[b.name] = {};
bands[b.name][b.time.toLowerCase()] = b.condition;
});
var html = '<div class="sw-band-header">Band</div><div class="sw-band-header" style="text-align:center">Day</div><div class="sw-band-header" style="text-align:center">Night</div>';
Object.keys(bands).forEach(function (name) {
html += '<div class="sw-band-name">' + name + '</div>';
['day', 'night'].forEach(function (t) {
var cond = bands[name][t] || '--';
var cls = 'sw-band-cond';
var cl = cond.toLowerCase();
if (cl === 'good') cls += ' sw-band-good';
else if (cl === 'fair') cls += ' sw-band-fair';
else if (cl === 'poor') cls += ' sw-band-poor';
html += '<div class="' + cls + '">' + cond + '</div>';
});
});
grid.innerHTML = html;
}
// -------------------------------------------------------------------
// Kp bar chart
// -------------------------------------------------------------------
function _renderKpChart(data) {
var canvas = document.getElementById('swKpChart');
if (!canvas) return;
if (!data.kp_index || data.kp_index.length < 2) return;
var rows = data.kp_index.slice(1); // skip header
var labels = [];
var values = [];
var colors = [];
// Take last 24 entries
var subset = rows.slice(-24);
subset.forEach(function (r) {
var dt = r[0] || '';
labels.push(dt.slice(5, 16)); // MM-DD HH:MM
var v = parseFloat(r[1]) || 0;
values.push(v);
if (v >= 7) colors.push('#ff3366');
else if (v >= 5) colors.push('#ff8800');
else if (v >= 4) colors.push('#ffcc00');
else colors.push('#00ff88');
});
if (_kpChart) { _kpChart.destroy(); _kpChart = null; }
_kpChart = new Chart(canvas, {
type: 'bar',
data: {
labels: labels,
datasets: [{
data: values,
backgroundColor: colors,
borderWidth: 0,
barPercentage: 0.8
}]
},
options: _chartOpts('Kp', 0, 9, false)
});
}
// -------------------------------------------------------------------
// Solar wind chart
// -------------------------------------------------------------------
function _renderWindChart(data) {
var canvas = document.getElementById('swWindChart');
if (!canvas) return;
if (!data.solar_wind_plasma || data.solar_wind_plasma.length < 2) return;
var rows = data.solar_wind_plasma.slice(1);
var labels = [];
var speedData = [];
var densityData = [];
// Sample every 3rd point to avoid overcrowding
for (var i = 0; i < rows.length; i += 3) {
var r = rows[i];
labels.push(r[0] ? r[0].slice(11, 16) : '');
speedData.push(r[2] ? parseFloat(r[2]) : null);
densityData.push(r[1] ? parseFloat(r[1]) : null);
}
if (_windChart) { _windChart.destroy(); _windChart = null; }
_windChart = new Chart(canvas, {
type: 'line',
data: {
labels: labels,
datasets: [
{
label: 'Speed (km/s)',
data: speedData,
borderColor: '#00ccff',
backgroundColor: '#00ccff22',
borderWidth: 1.5,
pointRadius: 0,
fill: true,
tension: 0.3,
yAxisID: 'y'
},
{
label: 'Density (p/cm³)',
data: densityData,
borderColor: '#ff8800',
borderWidth: 1,
pointRadius: 0,
borderDash: [4, 2],
tension: 0.3,
yAxisID: 'y1'
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: true, position: 'top', labels: { color: '#888', font: { size: 10 }, boxWidth: 12, padding: 8 } }
},
scales: {
x: { display: true, ticks: { color: '#555', font: { size: 9 }, maxTicksLimit: 8 }, grid: { color: '#ffffff08' } },
y: { display: true, position: 'left', ticks: { color: '#00ccff', font: { size: 9 } }, grid: { color: '#ffffff08' }, title: { display: false } },
y1: { display: true, position: 'right', ticks: { color: '#ff8800', font: { size: 9 } }, grid: { drawOnChartArea: false } }
},
interaction: { mode: 'index', intersect: false }
}
});
}
// -------------------------------------------------------------------
// X-ray flux chart
// -------------------------------------------------------------------
function _renderXrayChart(data) {
var canvas = document.getElementById('swXrayChart');
if (!canvas) return;
if (!data.xrays || data.xrays.length < 2) return;
// New format: array of objects with time_tag, flux, energy
// Filter to short-wavelength (0.1-0.8nm) only
var filtered = data.xrays.filter(function (r) {
return r.energy && r.energy === '0.1-0.8nm';
});
if (filtered.length === 0) filtered = data.xrays;
var labels = [];
var values = [];
// Sample every 3rd point
for (var i = 0; i < filtered.length; i += 3) {
var r = filtered[i];
var tag = r.time_tag || '';
labels.push(tag.slice(11, 16));
values.push(r.flux ? parseFloat(r.flux) : null);
}
if (_xrayChart) { _xrayChart.destroy(); _xrayChart = null; }
_xrayChart = new Chart(canvas, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'X-Ray Flux (W/m²)',
data: values,
borderColor: '#ff3366',
backgroundColor: '#ff336622',
borderWidth: 1.5,
pointRadius: 0,
fill: true,
tension: 0.3
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false }
},
scales: {
x: { display: true, ticks: { color: '#555', font: { size: 9 }, maxTicksLimit: 8 }, grid: { color: '#ffffff08' } },
y: {
display: true,
type: 'logarithmic',
ticks: {
color: '#888',
font: { size: 9 },
callback: function (v) {
if (v >= 1e-4) return 'X';
if (v >= 1e-5) return 'M';
if (v >= 1e-6) return 'C';
if (v >= 1e-7) return 'B';
if (v >= 1e-8) return 'A';
return '';
}
},
grid: { color: '#ffffff08' }
}
}
}
});
}
// -------------------------------------------------------------------
// Flare probability
// -------------------------------------------------------------------
function _renderFlareProb(data) {
var el = document.getElementById('swFlareProb');
if (!el) return;
if (!data.flare_probability || data.flare_probability.length === 0) {
el.innerHTML = '<div class="sw-empty">No flare data</div>';
return;
}
// New format: array of objects with date, c_class_1_day, m_class_1_day, x_class_1_day, etc.
var latest = data.flare_probability.slice(-3);
var html = '<table class="sw-prob-table"><thead><tr>';
html += '<th>Date</th><th>C 1-day</th><th>M 1-day</th><th>X 1-day</th><th>Proton</th>';
html += '</tr></thead><tbody>';
latest.forEach(function (row) {
html += '<tr>';
html += '<td>' + _escHtml(row.date || '--') + '</td>';
html += '<td>' + _escHtml(row.c_class_1_day || '--') + '%</td>';
html += '<td>' + _escHtml(row.m_class_1_day || '--') + '%</td>';
html += '<td>' + _escHtml(row.x_class_1_day || '--') + '%</td>';
html += '<td>' + _escHtml(row['10mev_protons_1_day'] || '--') + '%</td>';
html += '</tr>';
});
html += '</tbody></table>';
el.innerHTML = html;
}
// -------------------------------------------------------------------
// Images
// -------------------------------------------------------------------
function _renderSolarImage() {
selectSolarImage(_solarImageKey);
}
function _renderDrapImage() {
selectDrapFreq(_drapFreq);
}
function _renderAuroraImage() {
var frame = document.getElementById('swAuroraFrame');
if (!frame) return;
var img = new Image();
img.onload = function () { frame.innerHTML = ''; frame.appendChild(img); };
img.onerror = function () { frame.innerHTML = '<div class="sw-empty">Failed to load aurora image</div>'; };
img.src = '/space-weather/image/aurora_north?t=' + Date.now();
img.alt = 'Aurora Forecast';
}
function _updateSolarImageTabs() {
document.querySelectorAll('.sw-solar-tab').forEach(function (btn) {
btn.classList.toggle('active', btn.dataset.key === _solarImageKey);
});
}
function _updateDrapTabs() {
document.querySelectorAll('.sw-drap-freq-btn').forEach(function (btn) {
btn.classList.toggle('active', btn.dataset.key === _drapFreq);
});
}
// -------------------------------------------------------------------
// Alerts
// -------------------------------------------------------------------
function _renderAlerts(data) {
var el = document.getElementById('swAlertsList');
if (!el) return;
if (!data.alerts || data.alerts.length === 0) {
el.innerHTML = '<div class="sw-empty">No active alerts</div>';
return;
}
var html = '';
// Show latest 10
var items = data.alerts.slice(0, 10);
items.forEach(function (a) {
var msg = a.message || a.product_text || '';
// Truncate long messages
if (msg.length > 300) msg = msg.substring(0, 300) + '...';
html += '<div class="sw-alert-item">';
html += '<div class="sw-alert-type">' + _escHtml(a.product_id || 'Alert') + '</div>';
html += '<div class="sw-alert-time">' + _escHtml(a.issue_datetime || '') + '</div>';
html += '<div class="sw-alert-msg">' + _escHtml(msg) + '</div>';
html += '</div>';
});
el.innerHTML = html;
}
// -------------------------------------------------------------------
// Active regions
// -------------------------------------------------------------------
function _renderRegions(data) {
var el = document.getElementById('swRegionsBody');
if (!el) return;
if (!data.solar_regions || data.solar_regions.length === 0) {
el.innerHTML = '<tr><td colspan="5" class="sw-empty">No active regions</td></tr>';
return;
}
// New format: array of objects with region, observed_date, location, longitude, area, etc.
// De-duplicate by region number (keep latest observed_date per region)
var byRegion = {};
data.solar_regions.forEach(function (r) {
var key = r.region || '';
if (!byRegion[key] || (r.observed_date > byRegion[key].observed_date)) {
byRegion[key] = r;
}
});
var regions = Object.values(byRegion);
var html = '';
regions.forEach(function (r) {
html += '<tr>';
html += '<td>' + _escHtml(String(r.region || '')) + '</td>';
html += '<td>' + _escHtml(r.observed_date || '') + '</td>';
html += '<td>' + _escHtml(r.location || '') + '</td>';
html += '<td>' + _escHtml(String(r.longitude || '')) + '</td>';
html += '<td>' + _escHtml(String(r.area || '')) + '</td>';
html += '</tr>';
});
el.innerHTML = html;
}
// -------------------------------------------------------------------
// Sidebar quick status
// -------------------------------------------------------------------
function _updateSidebar(data) {
var sfi = '--', kp = '--', aIdx = '--', ssn = '--', wind = '--', bz = '--';
if (data.band_conditions) {
if (data.band_conditions.sfi) sfi = data.band_conditions.sfi;
if (data.band_conditions.aindex) aIdx = data.band_conditions.aindex;
if (data.band_conditions.sunspots) ssn = data.band_conditions.sunspots;
}
if (data.kp_index && data.kp_index.length > 1) {
kp = data.kp_index[data.kp_index.length - 1][1] || '--';
}
if (data.solar_wind_plasma && data.solar_wind_plasma.length > 1) {
for (var i = data.solar_wind_plasma.length - 1; i >= 1; i--) {
if (data.solar_wind_plasma[i][2]) {
wind = Math.round(parseFloat(data.solar_wind_plasma[i][2])) + ' km/s';
break;
}
}
}
if (data.solar_wind_mag && data.solar_wind_mag.length > 1) {
for (var j = data.solar_wind_mag.length - 1; j >= 1; j--) {
if (data.solar_wind_mag[j][3]) {
bz = parseFloat(data.solar_wind_mag[j][3]).toFixed(1) + ' nT';
break;
}
}
}
_setText('swSidebarSfi', sfi);
_setText('swSidebarKp', kp);
_setText('swSidebarA', aIdx);
_setText('swSidebarSsn', ssn);
_setText('swSidebarWind', wind);
_setText('swSidebarBz', bz);
}
// -------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------
function _setText(id, text) {
var el = document.getElementById(id);
if (el) el.textContent = text;
}
function _escHtml(s) {
var d = document.createElement('div');
d.textContent = s;
return d.innerHTML;
}
function _updateTimestamp() {
var el = document.getElementById('swLastUpdate');
if (el) el.textContent = 'Updated: ' + new Date().toLocaleTimeString();
}
function _chartOpts(yLabel, yMin, yMax, showLegend) {
return {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: !!showLegend, labels: { color: '#888', font: { size: 10 } } }
},
scales: {
x: { display: true, ticks: { color: '#555', font: { size: 9 }, maxRotation: 45, maxTicksLimit: 8 }, grid: { color: '#ffffff08' } },
y: { display: true, min: yMin, max: yMax, ticks: { color: '#888', font: { size: 9 }, stepSize: 1 }, grid: { color: '#ffffff08' } }
}
};
}
function _destroyCharts() {
if (_kpChart) { _kpChart.destroy(); _kpChart = null; }
if (_windChart) { _windChart.destroy(); _windChart = null; }
if (_xrayChart) { _xrayChart.destroy(); _xrayChart = null; }
}
// -------------------------------------------------------------------
// Expose public API
// -------------------------------------------------------------------
return {
init: init,
destroy: destroy,
refresh: refresh,
selectSolarImage: selectSolarImage,
selectDrapFreq: selectDrapFreq,
toggleAutoRefresh: toggleAutoRefresh
};
})();
+13 -9
View File
@@ -269,12 +269,10 @@ const SpyStations = (function() {
*/ */
function tuneToStation(stationId, freqKhz) { function tuneToStation(stationId, freqKhz) {
const freqMhz = freqKhz / 1000; const freqMhz = freqKhz / 1000;
sessionStorage.setItem('tuneFrequency', freqMhz.toString());
// Find the station and determine mode // Find the station and determine mode
const station = stations.find(s => s.id === stationId); const station = stations.find(s => s.id === stationId);
const tuneMode = station ? getModeFromStation(station.mode) : 'usb'; const tuneMode = station ? getModeFromStation(station.mode) : 'usb';
sessionStorage.setItem('tuneMode', tuneMode);
const stationName = station ? station.name : 'Station'; const stationName = station ? station.name : 'Station';
@@ -282,12 +280,18 @@ const SpyStations = (function() {
showNotification('Tuning to ' + stationName, formatFrequency(freqKhz) + ' (' + tuneMode.toUpperCase() + ')'); showNotification('Tuning to ' + stationName, formatFrequency(freqKhz) + ' (' + tuneMode.toUpperCase() + ')');
} }
// Switch to listening post mode // Switch to spectrum waterfall mode and tune after mode init.
if (typeof selectMode === 'function') { if (typeof switchMode === 'function') {
selectMode('listening'); switchMode('waterfall');
} else if (typeof switchMode === 'function') { } else if (typeof selectMode === 'function') {
switchMode('listening'); selectMode('waterfall');
} }
setTimeout(() => {
if (typeof Waterfall !== 'undefined' && typeof Waterfall.quickTune === 'function') {
Waterfall.quickTune(freqMhz, tuneMode);
}
}, 220);
} }
/** /**
@@ -305,7 +309,7 @@ const SpyStations = (function() {
* Check if we arrived from another page with a tune request * Check if we arrived from another page with a tune request
*/ */
function checkTuneFrequency() { function checkTuneFrequency() {
// This is for the listening post to check - spy stations sets, listening post reads // Reserved for cross-mode tune handoff behavior.
} }
/** /**
@@ -445,7 +449,7 @@ const SpyStations = (function() {
<div class="signal-details-section"> <div class="signal-details-section">
<div class="signal-details-title">How to Listen</div> <div class="signal-details-title">How to Listen</div>
<p style="color: var(--text-secondary); font-size: 12px; line-height: 1.6;"> <p style="color: var(--text-secondary); font-size: 12px; line-height: 1.6;">
Click "Tune In" on any station to open the Listening Post with the frequency pre-configured. Click "Tune In" on any station to open Spectrum Waterfall with the frequency pre-configured.
Most number stations use USB (Upper Sideband) mode. You'll need an SDR capable of receiving Most number stations use USB (Upper Sideband) mode. You'll need an SDR capable of receiving
HF frequencies (typically 3-30 MHz) and an appropriate antenna. HF frequencies (typically 3-30 MHz) and an appropriate antenna.
</p> </p>
+142 -24
View File
@@ -15,13 +15,21 @@ const SSTVGeneral = (function() {
let sstvGeneralScopeCtx = null; let sstvGeneralScopeCtx = null;
let sstvGeneralScopeAnim = null; let sstvGeneralScopeAnim = null;
let sstvGeneralScopeHistory = []; let sstvGeneralScopeHistory = [];
let sstvGeneralScopeWaveBuffer = [];
let sstvGeneralScopeDisplayWave = [];
const SSTV_GENERAL_SCOPE_LEN = 200; const SSTV_GENERAL_SCOPE_LEN = 200;
const SSTV_GENERAL_SCOPE_WAVE_BUFFER_LEN = 2048;
const SSTV_GENERAL_SCOPE_WAVE_INPUT_SMOOTH_ALPHA = 0.55;
const SSTV_GENERAL_SCOPE_WAVE_DISPLAY_SMOOTH_ALPHA = 0.22;
const SSTV_GENERAL_SCOPE_WAVE_IDLE_DECAY = 0.96;
let sstvGeneralScopeRms = 0; let sstvGeneralScopeRms = 0;
let sstvGeneralScopePeak = 0; let sstvGeneralScopePeak = 0;
let sstvGeneralScopeTargetRms = 0; let sstvGeneralScopeTargetRms = 0;
let sstvGeneralScopeTargetPeak = 0; let sstvGeneralScopeTargetPeak = 0;
let sstvGeneralScopeMsgBurst = 0; let sstvGeneralScopeMsgBurst = 0;
let sstvGeneralScopeTone = null; let sstvGeneralScopeTone = null;
let sstvGeneralScopeLastWaveAt = 0;
let sstvGeneralScopeLastInputSample = 0;
/** /**
* Initialize the SSTV General mode * Initialize the SSTV General mode
@@ -91,7 +99,7 @@ const SSTVGeneral = (function() {
const deviceSelect = document.getElementById('deviceSelect'); const deviceSelect = document.getElementById('deviceSelect');
const frequency = parseFloat(freqInput?.value || '14.230'); const frequency = parseFloat(freqInput?.value || '14.230');
const modulation = modSelect?.value || 'usb'; const modulation = modSelect?.value || 'fm';
const device = parseInt(deviceSelect?.value || '0', 10); const device = parseInt(deviceSelect?.value || '0', 10);
updateStatusUI('connecting', 'Starting...'); updateStatusUI('connecting', 'Starting...');
@@ -205,20 +213,64 @@ const SSTVGeneral = (function() {
/** /**
* Initialize signal scope canvas * Initialize signal scope canvas
*/ */
function resizeSstvGeneralScopeCanvas(canvas) {
if (!canvas) return;
const rect = canvas.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
const width = Math.max(1, Math.floor(rect.width * dpr));
const height = Math.max(1, Math.floor(rect.height * dpr));
if (canvas.width !== width || canvas.height !== height) {
canvas.width = width;
canvas.height = height;
}
}
function applySstvGeneralScopeData(scopeData) {
if (!scopeData || typeof scopeData !== 'object') return;
sstvGeneralScopeTargetRms = Number(scopeData.rms) || 0;
sstvGeneralScopeTargetPeak = Number(scopeData.peak) || 0;
if (scopeData.tone !== undefined) {
sstvGeneralScopeTone = scopeData.tone;
}
if (Array.isArray(scopeData.waveform) && scopeData.waveform.length) {
for (const packedSample of scopeData.waveform) {
const sample = Number(packedSample);
if (!Number.isFinite(sample)) continue;
const normalized = Math.max(-127, Math.min(127, sample)) / 127;
sstvGeneralScopeLastInputSample += (normalized - sstvGeneralScopeLastInputSample) * SSTV_GENERAL_SCOPE_WAVE_INPUT_SMOOTH_ALPHA;
sstvGeneralScopeWaveBuffer.push(sstvGeneralScopeLastInputSample);
}
if (sstvGeneralScopeWaveBuffer.length > SSTV_GENERAL_SCOPE_WAVE_BUFFER_LEN) {
sstvGeneralScopeWaveBuffer.splice(0, sstvGeneralScopeWaveBuffer.length - SSTV_GENERAL_SCOPE_WAVE_BUFFER_LEN);
}
sstvGeneralScopeLastWaveAt = performance.now();
}
}
function initSstvGeneralScope() { function initSstvGeneralScope() {
const canvas = document.getElementById('sstvGeneralScopeCanvas'); const canvas = document.getElementById('sstvGeneralScopeCanvas');
if (!canvas) return; if (!canvas) return;
const rect = canvas.getBoundingClientRect();
canvas.width = rect.width * (window.devicePixelRatio || 1); if (sstvGeneralScopeAnim) {
canvas.height = rect.height * (window.devicePixelRatio || 1); cancelAnimationFrame(sstvGeneralScopeAnim);
sstvGeneralScopeAnim = null;
}
resizeSstvGeneralScopeCanvas(canvas);
sstvGeneralScopeCtx = canvas.getContext('2d'); sstvGeneralScopeCtx = canvas.getContext('2d');
sstvGeneralScopeHistory = new Array(SSTV_GENERAL_SCOPE_LEN).fill(0); sstvGeneralScopeHistory = new Array(SSTV_GENERAL_SCOPE_LEN).fill(0);
sstvGeneralScopeWaveBuffer = [];
sstvGeneralScopeDisplayWave = [];
sstvGeneralScopeRms = 0; sstvGeneralScopeRms = 0;
sstvGeneralScopePeak = 0; sstvGeneralScopePeak = 0;
sstvGeneralScopeTargetRms = 0; sstvGeneralScopeTargetRms = 0;
sstvGeneralScopeTargetPeak = 0; sstvGeneralScopeTargetPeak = 0;
sstvGeneralScopeMsgBurst = 0; sstvGeneralScopeMsgBurst = 0;
sstvGeneralScopeTone = null; sstvGeneralScopeTone = null;
sstvGeneralScopeLastWaveAt = 0;
sstvGeneralScopeLastInputSample = 0;
drawSstvGeneralScope(); drawSstvGeneralScope();
} }
@@ -228,12 +280,14 @@ const SSTVGeneral = (function() {
function drawSstvGeneralScope() { function drawSstvGeneralScope() {
const ctx = sstvGeneralScopeCtx; const ctx = sstvGeneralScopeCtx;
if (!ctx) return; if (!ctx) return;
resizeSstvGeneralScopeCanvas(ctx.canvas);
const W = ctx.canvas.width; const W = ctx.canvas.width;
const H = ctx.canvas.height; const H = ctx.canvas.height;
const midY = H / 2; const midY = H / 2;
// Phosphor persistence // Phosphor persistence
ctx.fillStyle = 'rgba(5, 5, 16, 0.3)'; ctx.fillStyle = 'rgba(5, 5, 16, 0.26)';
ctx.fillRect(0, 0, W, H); ctx.fillRect(0, 0, W, H);
// Smooth towards target // Smooth towards target
@@ -256,32 +310,84 @@ const SSTVGeneral = (function() {
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke(); ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke();
} }
// Waveform // Envelope
const stepX = W / (SSTV_GENERAL_SCOPE_LEN - 1); const envStepX = W / (SSTV_GENERAL_SCOPE_LEN - 1);
ctx.strokeStyle = '#c080ff'; ctx.strokeStyle = 'rgba(168, 110, 255, 0.45)';
ctx.lineWidth = 1.5; ctx.lineWidth = 1;
ctx.shadowColor = '#c080ff';
ctx.shadowBlur = 4;
// Upper half
ctx.beginPath(); ctx.beginPath();
for (let i = 0; i < sstvGeneralScopeHistory.length; i++) { for (let i = 0; i < sstvGeneralScopeHistory.length; i++) {
const x = i * stepX; const x = i * envStepX;
const amp = sstvGeneralScopeHistory[i] * midY * 0.9; const amp = sstvGeneralScopeHistory[i] * midY * 0.85;
const y = midY - amp; const y = midY - amp;
if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
} }
ctx.stroke(); ctx.stroke();
// Lower half (mirror)
ctx.beginPath(); ctx.beginPath();
for (let i = 0; i < sstvGeneralScopeHistory.length; i++) { for (let i = 0; i < sstvGeneralScopeHistory.length; i++) {
const x = i * stepX; const x = i * envStepX;
const amp = sstvGeneralScopeHistory[i] * midY * 0.9; const amp = sstvGeneralScopeHistory[i] * midY * 0.85;
const y = midY + amp; const y = midY + amp;
if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
} }
ctx.stroke(); ctx.stroke();
// Actual waveform trace
const waveformPointCount = Math.min(Math.max(120, Math.floor(W / 3.2)), 420);
if (sstvGeneralScopeWaveBuffer.length > 1) {
const waveIsFresh = (performance.now() - sstvGeneralScopeLastWaveAt) < 1000;
const sourceLen = sstvGeneralScopeWaveBuffer.length;
const sourceWindow = Math.min(sourceLen, 1536);
const sourceStart = sourceLen - sourceWindow;
if (sstvGeneralScopeDisplayWave.length !== waveformPointCount) {
sstvGeneralScopeDisplayWave = new Array(waveformPointCount).fill(0);
}
for (let i = 0; i < waveformPointCount; i++) {
const a = sourceStart + Math.floor((i / waveformPointCount) * sourceWindow);
const b = sourceStart + Math.floor(((i + 1) / waveformPointCount) * sourceWindow);
const start = Math.max(sourceStart, Math.min(sourceLen - 1, a));
const end = Math.max(start + 1, Math.min(sourceLen, b));
let sum = 0;
let count = 0;
for (let j = start; j < end; j++) {
sum += sstvGeneralScopeWaveBuffer[j];
count++;
}
const targetSample = count > 0 ? (sum / count) : 0;
sstvGeneralScopeDisplayWave[i] += (targetSample - sstvGeneralScopeDisplayWave[i]) * SSTV_GENERAL_SCOPE_WAVE_DISPLAY_SMOOTH_ALPHA;
}
ctx.strokeStyle = waveIsFresh ? '#c080ff' : 'rgba(192, 128, 255, 0.45)';
ctx.lineWidth = 1.7;
ctx.shadowColor = '#c080ff';
ctx.shadowBlur = waveIsFresh ? 6 : 2;
const stepX = waveformPointCount > 1 ? (W / (waveformPointCount - 1)) : W;
ctx.beginPath();
const firstY = midY - (sstvGeneralScopeDisplayWave[0] * midY * 0.9);
ctx.moveTo(0, firstY);
for (let i = 1; i < waveformPointCount - 1; i++) {
const x = i * stepX;
const y = midY - (sstvGeneralScopeDisplayWave[i] * midY * 0.9);
const nx = (i + 1) * stepX;
const ny = midY - (sstvGeneralScopeDisplayWave[i + 1] * midY * 0.9);
const cx = (x + nx) / 2;
const cy = (y + ny) / 2;
ctx.quadraticCurveTo(x, y, cx, cy);
}
const lastX = (waveformPointCount - 1) * stepX;
const lastY = midY - (sstvGeneralScopeDisplayWave[waveformPointCount - 1] * midY * 0.9);
ctx.lineTo(lastX, lastY);
ctx.stroke();
if (!waveIsFresh) {
for (let i = 0; i < sstvGeneralScopeDisplayWave.length; i++) {
sstvGeneralScopeDisplayWave[i] *= SSTV_GENERAL_SCOPE_WAVE_IDLE_DECAY;
}
}
}
ctx.shadowBlur = 0; ctx.shadowBlur = 0;
// Peak indicator // Peak indicator
@@ -317,8 +423,17 @@ const SSTVGeneral = (function() {
else { toneLabel.textContent = 'QUIET'; toneLabel.style.color = '#444'; } else { toneLabel.textContent = 'QUIET'; toneLabel.style.color = '#444'; }
} }
if (statusLabel) { if (statusLabel) {
if (sstvGeneralScopeRms > 500) { statusLabel.textContent = 'SIGNAL'; statusLabel.style.color = '#0f0'; } const waveIsFresh = (performance.now() - sstvGeneralScopeLastWaveAt) < 1000;
else { statusLabel.textContent = 'MONITORING'; statusLabel.style.color = '#555'; } if (sstvGeneralScopeRms > 900 && waveIsFresh) {
statusLabel.textContent = 'DEMODULATING';
statusLabel.style.color = '#c080ff';
} else if (sstvGeneralScopeRms > 500) {
statusLabel.textContent = 'CARRIER';
statusLabel.style.color = '#e0b8ff';
} else {
statusLabel.textContent = 'QUIET';
statusLabel.style.color = '#555';
}
} }
sstvGeneralScopeAnim = requestAnimationFrame(drawSstvGeneralScope); sstvGeneralScopeAnim = requestAnimationFrame(drawSstvGeneralScope);
@@ -330,6 +445,11 @@ const SSTVGeneral = (function() {
function stopSstvGeneralScope() { function stopSstvGeneralScope() {
if (sstvGeneralScopeAnim) { cancelAnimationFrame(sstvGeneralScopeAnim); sstvGeneralScopeAnim = null; } if (sstvGeneralScopeAnim) { cancelAnimationFrame(sstvGeneralScopeAnim); sstvGeneralScopeAnim = null; }
sstvGeneralScopeCtx = null; sstvGeneralScopeCtx = null;
sstvGeneralScopeWaveBuffer = [];
sstvGeneralScopeDisplayWave = [];
sstvGeneralScopeHistory = [];
sstvGeneralScopeLastWaveAt = 0;
sstvGeneralScopeLastInputSample = 0;
} }
/** /**
@@ -353,9 +473,7 @@ const SSTVGeneral = (function() {
if (data.type === 'sstv_progress') { if (data.type === 'sstv_progress') {
handleProgress(data); handleProgress(data);
} else if (data.type === 'sstv_scope') { } else if (data.type === 'sstv_scope') {
sstvGeneralScopeTargetRms = data.rms; applySstvGeneralScopeData(data);
sstvGeneralScopeTargetPeak = data.peak;
if (data.tone !== undefined) sstvGeneralScopeTone = data.tone;
} }
} catch (err) { } catch (err) {
console.error('Failed to parse SSE message:', err); console.error('Failed to parse SSE message:', err);
+54 -6
View File
@@ -17,9 +17,11 @@ const SSTV = (function() {
let issUpdateInterval = null; let issUpdateInterval = null;
let countdownInterval = null; let countdownInterval = null;
let nextPassData = null; let nextPassData = null;
let pendingMapInvalidate = false;
// ISS frequency // ISS frequency
const ISS_FREQ = 145.800; const ISS_FREQ = 145.800;
const ISS_MODULATION = 'fm';
// Signal scope state // Signal scope state
let sstvScopeCtx = null; let sstvScopeCtx = null;
@@ -44,6 +46,22 @@ const SSTV = (function() {
initMap(); initMap();
startIssTracking(); startIssTracking();
startCountdown(); startCountdown();
// Ensure Leaflet recomputes dimensions after the SSTV pane becomes visible.
setTimeout(() => invalidateMap(), 80);
setTimeout(() => invalidateMap(), 260);
}
function isMapContainerVisible() {
if (!issMap || typeof issMap.getContainer !== 'function') return false;
const container = issMap.getContainer();
if (!container) return false;
if (container.offsetWidth <= 0 || container.offsetHeight <= 0) return false;
if (container.style && container.style.display === 'none') return false;
if (typeof window.getComputedStyle === 'function') {
const style = window.getComputedStyle(container);
if (style.display === 'none' || style.visibility === 'hidden') return false;
}
return true;
} }
/** /**
@@ -219,6 +237,14 @@ const SSTV = (function() {
opacity: 0.6, opacity: 0.6,
dashArray: '5, 5' dashArray: '5, 5'
}).addTo(issMap); }).addTo(issMap);
issMap.on('resize moveend zoomend', () => {
if (pendingMapInvalidate) invalidateMap();
});
// Initial layout passes for first-time mode load.
setTimeout(() => invalidateMap(), 40);
setTimeout(() => invalidateMap(), 180);
} }
/** /**
@@ -430,6 +456,7 @@ const SSTV = (function() {
*/ */
function updateMap() { function updateMap() {
if (!issMap || !issPosition) return; if (!issMap || !issPosition) return;
if (pendingMapInvalidate) invalidateMap();
const lat = issPosition.lat; const lat = issPosition.lat;
const lon = issPosition.lon; const lon = issPosition.lon;
@@ -489,8 +516,12 @@ const SSTV = (function() {
issTrackLine.setLatLngs(segments.length > 0 ? segments : []); issTrackLine.setLatLngs(segments.length > 0 ? segments : []);
} }
// Pan map to follow ISS // Pan map to follow ISS only when the map pane is currently renderable.
issMap.panTo([lat, lon], { animate: true, duration: 0.5 }); if (isMapContainerVisible()) {
issMap.panTo([lat, lon], { animate: true, duration: 0.5 });
} else {
pendingMapInvalidate = true;
}
} }
/** /**
@@ -544,7 +575,7 @@ const SSTV = (function() {
const response = await fetch('/sstv/start', { const response = await fetch('/sstv/start', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ frequency, device }) body: JSON.stringify({ frequency, modulation: ISS_MODULATION, device })
}); });
const data = await response.json(); const data = await response.json();
@@ -554,9 +585,11 @@ const SSTV = (function() {
if (typeof reserveDevice === 'function') { if (typeof reserveDevice === 'function') {
reserveDevice(device, 'sstv'); reserveDevice(device, 'sstv');
} }
updateStatusUI('listening', `${frequency} MHz`); const tunedFrequency = Number(data.frequency || frequency);
const modulationText = String(data.modulation || ISS_MODULATION).toUpperCase();
updateStatusUI('listening', `${tunedFrequency.toFixed(3)} MHz ${modulationText}`);
startStream(); startStream();
showNotification('SSTV', `Listening on ${frequency} MHz`); showNotification('SSTV', `Listening on ${tunedFrequency.toFixed(3)} MHz ${modulationText}`);
} else { } else {
updateStatusUI('idle', 'Start failed'); updateStatusUI('idle', 'Start failed');
showStatusMessage(data.message || 'Failed to start decoder', 'error'); showStatusMessage(data.message || 'Failed to start decoder', 'error');
@@ -1310,6 +1343,20 @@ const SSTV = (function() {
} }
} }
/**
* Invalidate ISS map size after pane/layout changes.
*/
function invalidateMap() {
if (!issMap) return false;
if (!isMapContainerVisible()) {
pendingMapInvalidate = true;
return false;
}
issMap.invalidateSize({ pan: false, animate: false });
pendingMapInvalidate = false;
return true;
}
// Public API // Public API
return { return {
init, init,
@@ -1325,7 +1372,8 @@ const SSTV = (function() {
useGPS, useGPS,
updateTLE, updateTLE,
stopIssTracking, stopIssTracking,
stopCountdown stopCountdown,
invalidateMap
}; };
})(); })();
File diff suppressed because it is too large Load Diff
+492 -73
View File
@@ -1,7 +1,7 @@
/** /**
* Weather Satellite Mode * Weather Satellite Mode
* NOAA APT and Meteor LRPT decoder interface with auto-scheduler, * NOAA APT and Meteor LRPT decoder interface with auto-scheduler,
* polar plot, ground track map, countdown, and timeline. * polar plot, styled real-world map, countdown, and timeline.
*/ */
const WeatherSat = (function() { const WeatherSat = (function() {
@@ -16,12 +16,16 @@ const WeatherSat = (function() {
let schedulerEnabled = false; let schedulerEnabled = false;
let groundMap = null; let groundMap = null;
let groundTrackLayer = null; let groundTrackLayer = null;
let groundOverlayLayer = null;
let groundGridLayer = null;
let satCrosshairMarker = null;
let observerMarker = null; let observerMarker = null;
let consoleEntries = []; let consoleEntries = [];
let consoleCollapsed = false; let consoleCollapsed = false;
let currentPhase = 'idle'; let currentPhase = 'idle';
let consoleAutoHideTimer = null; let consoleAutoHideTimer = null;
let currentModalFilename = null; let currentModalFilename = null;
let locationListenersAttached = false;
/** /**
* Initialize the Weather Satellite mode * Initialize the Weather Satellite mode
@@ -36,6 +40,39 @@ const WeatherSat = (function() {
initGroundMap(); initGroundMap();
} }
/**
* Get observer coordinates from shared location or local storage.
*/
function getObserverCoords() {
let lat;
let lon;
if (window.ObserverLocation && ObserverLocation.isSharedEnabled()) {
const shared = ObserverLocation.getShared();
lat = Number(shared?.lat);
lon = Number(shared?.lon);
} else {
lat = Number(localStorage.getItem('observerLat'));
lon = Number(localStorage.getItem('observerLon'));
}
if (!isFinite(lat) || !isFinite(lon)) return null;
if (lat < -90 || lat > 90 || lon < -180 || lon > 180) return null;
return { lat, lon };
}
/**
* Center the ground map on current observer coordinates when available.
*/
function centerGroundMapOnObserver(zoom = 1) {
if (!groundMap) return;
const observer = getObserverCoords();
if (!observer) return;
const lat = Math.max(-85, Math.min(85, observer.lat));
const lon = normalizeLon(observer.lon);
groundMap.setView([lat, lon], zoom, { animate: false });
}
/** /**
* Load observer location into input fields * Load observer location into input fields
*/ */
@@ -54,8 +91,13 @@ const WeatherSat = (function() {
if (latInput && storedLat) latInput.value = storedLat; if (latInput && storedLat) latInput.value = storedLat;
if (lonInput && storedLon) lonInput.value = storedLon; if (lonInput && storedLon) lonInput.value = storedLon;
if (latInput) latInput.addEventListener('change', saveLocationFromInputs); // Only attach listeners once — re-calling init() on mode switch must not
if (lonInput) lonInput.addEventListener('change', saveLocationFromInputs); // accumulate duplicate listeners that fire loadPasses() multiple times.
if (!locationListenersAttached) {
if (latInput) latInput.addEventListener('change', saveLocationFromInputs);
if (lonInput) lonInput.addEventListener('change', saveLocationFromInputs);
locationListenersAttached = true;
}
} }
/** /**
@@ -77,6 +119,7 @@ const WeatherSat = (function() {
localStorage.setItem('observerLon', lon.toString()); localStorage.setItem('observerLon', lon.toString());
} }
loadPasses(); loadPasses();
centerGroundMapOnObserver(1);
} }
} }
@@ -115,6 +158,7 @@ const WeatherSat = (function() {
btn.disabled = false; btn.disabled = false;
showNotification('Weather Sat', 'Location updated'); showNotification('Weather Sat', 'Location updated');
loadPasses(); loadPasses();
centerGroundMapOnObserver(1);
}, },
(err) => { (err) => {
btn.innerHTML = originalText; btn.innerHTML = originalText;
@@ -399,16 +443,20 @@ const WeatherSat = (function() {
addConsoleEntry('Capture complete', 'signal'); addConsoleEntry('Capture complete', 'signal');
updatePhaseIndicator('complete'); updatePhaseIndicator('complete');
if (consoleAutoHideTimer) clearTimeout(consoleAutoHideTimer);
consoleAutoHideTimer = setTimeout(() => showConsole(false), 30000); consoleAutoHideTimer = setTimeout(() => showConsole(false), 30000);
} }
} else if (data.status === 'error') { } else if (data.status === 'error') {
isRunning = false;
if (!schedulerEnabled) stopStream();
updateStatusUI('idle', 'Error'); updateStatusUI('idle', 'Error');
showNotification('Weather Sat', data.message || 'Capture error'); showNotification('Weather Sat', data.message || 'Capture error');
if (captureStatus) captureStatus.classList.remove('active'); if (captureStatus) captureStatus.classList.remove('active');
if (data.message) addConsoleEntry(data.message, 'error'); if (data.message) addConsoleEntry(data.message, 'error');
updatePhaseIndicator('error'); updatePhaseIndicator('error');
if (consoleAutoHideTimer) clearTimeout(consoleAutoHideTimer);
consoleAutoHideTimer = setTimeout(() => showConsole(false), 15000); consoleAutoHideTimer = setTimeout(() => showConsole(false), 15000);
} }
} }
@@ -424,8 +472,17 @@ const WeatherSat = (function() {
updateStatusUI('capturing', `Auto: ${p.name || p.satellite} ${p.frequency} MHz`); updateStatusUI('capturing', `Auto: ${p.name || p.satellite} ${p.frequency} MHz`);
showNotification('Weather Sat', `Auto-capture started: ${p.name || p.satellite}`); showNotification('Weather Sat', `Auto-capture started: ${p.name || p.satellite}`);
} else if (data.type === 'schedule_capture_complete') { } else if (data.type === 'schedule_capture_complete') {
showNotification('Weather Sat', `Auto-capture complete: ${(data.pass || {}).name || ''}`); const p = data.pass || {};
showNotification('Weather Sat', `Auto-capture complete: ${p.name || ''}`);
// Reset UI — the decoder's stop() doesn't emit a progress complete event
// when called internally by the scheduler, so we handle it here.
isRunning = false;
updateStatusUI('idle', 'Auto-capture complete');
const captureStatus = document.getElementById('wxsatCaptureStatus');
if (captureStatus) captureStatus.classList.remove('active');
updatePhaseIndicator('complete');
loadImages(); loadImages();
loadPasses();
} else if (data.type === 'schedule_capture_skipped') { } else if (data.type === 'schedule_capture_skipped') {
const reason = data.reason || 'unknown'; const reason = data.reason || 'unknown';
const p = data.pass || {}; const p = data.pass || {};
@@ -442,6 +499,26 @@ const WeatherSat = (function() {
return `${m}:${s.toString().padStart(2, '0')}`; return `${m}:${s.toString().padStart(2, '0')}`;
} }
/**
* Parse pass timestamps, accepting legacy malformed UTC strings (+00:00Z).
*/
function parsePassDate(value) {
if (!value || typeof value !== 'string') return null;
let parsed = new Date(value);
if (!Number.isNaN(parsed.getTime())) {
return parsed;
}
// Backward-compatible cleanup for accidentally double-suffixed UTC timestamps.
parsed = new Date(value.replace(/\+00:00Z$/, 'Z'));
if (!Number.isNaN(parsed.getTime())) {
return parsed;
}
return null;
}
/** /**
* Load pass predictions (with trajectory + ground track) * Load pass predictions (with trajectory + ground track)
*/ */
@@ -459,7 +536,12 @@ const WeatherSat = (function() {
} }
if (!storedLat || !storedLon) { if (!storedLat || !storedLon) {
passes = [];
selectedPassIndex = -1;
renderPasses([]); renderPasses([]);
renderTimeline([]);
updateCountdownFromPasses();
updateGroundTrack(null);
return; return;
} }
@@ -470,12 +552,16 @@ const WeatherSat = (function() {
if (data.status === 'ok') { if (data.status === 'ok') {
passes = data.passes || []; passes = data.passes || [];
selectedPassIndex = -1;
renderPasses(passes); renderPasses(passes);
renderTimeline(passes); renderTimeline(passes);
updateCountdownFromPasses(); updateCountdownFromPasses();
// Auto-select first pass // Always select the first upcoming pass so the polar plot
if (passes.length > 0 && selectedPassIndex < 0) { // and ground track reflect the current list after every refresh.
if (passes.length > 0) {
selectPass(0); selectPass(0);
} else {
updateGroundTrack(null);
} }
} }
} catch (err) { } catch (err) {
@@ -532,13 +618,15 @@ const WeatherSat = (function() {
const modeClass = pass.mode === 'APT' ? 'apt' : 'lrpt'; const modeClass = pass.mode === 'APT' ? 'apt' : 'lrpt';
const timeStr = pass.startTime || '--'; const timeStr = pass.startTime || '--';
const now = new Date(); const now = new Date();
const passStart = new Date(pass.startTimeISO); const passStart = parsePassDate(pass.startTimeISO);
const diffMs = passStart - now; const diffMs = passStart ? passStart - now : NaN;
const diffMins = Math.floor(diffMs / 60000); const diffMins = Number.isFinite(diffMs) ? Math.floor(diffMs / 60000) : NaN;
const isSelected = idx === selectedPassIndex; const isSelected = idx === selectedPassIndex;
let countdown = ''; let countdown = '--';
if (diffMs < 0) { if (!Number.isFinite(diffMs)) {
countdown = '--';
} else if (diffMs < 0) {
countdown = 'NOW'; countdown = 'NOW';
} else if (diffMins < 60) { } else if (diffMins < 60) {
countdown = `in ${diffMins}m`; countdown = `in ${diffMins}m`;
@@ -702,79 +790,336 @@ const WeatherSat = (function() {
// ======================== // ========================
/** /**
* Initialize Leaflet ground track map * Initialize styled real-world map panel.
*/ */
function initGroundMap() { async function initGroundMap() {
const container = document.getElementById('wxsatGroundMap'); const container = document.getElementById('wxsatGroundMap');
if (!container || groundMap) return; if (!container) return;
if (typeof L === 'undefined') return; if (typeof L === 'undefined') return;
const observer = getObserverCoords();
const defaultCenter = observer
? [Math.max(-85, Math.min(85, observer.lat)), normalizeLon(observer.lon)]
: [12, 0];
const defaultZoom = 1;
groundMap = L.map(container, { if (!groundMap) {
center: [20, 0], groundMap = L.map(container, {
zoom: 2, center: defaultCenter,
zoomControl: false, zoom: defaultZoom,
attributionControl: false, minZoom: 1,
}); maxZoom: 7,
zoomControl: false,
attributionControl: false,
worldCopyJump: true,
preferCanvas: true,
});
// Check tile provider from settings if (typeof Settings !== 'undefined' && Settings.createTileLayer) {
let tileUrl = 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png'; await Settings.init();
try { Settings.createTileLayer().addTo(groundMap);
const provider = localStorage.getItem('tileProvider'); Settings.registerMap(groundMap);
if (provider === 'osm') { } else {
tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', {
subdomains: 'abcd',
maxZoom: 18,
noWrap: false,
crossOrigin: true,
className: 'tile-layer-cyan',
}).addTo(groundMap);
} }
} catch (e) {}
L.tileLayer(tileUrl, { maxZoom: 10 }).addTo(groundMap); groundGridLayer = L.layerGroup().addTo(groundMap);
addStyledGridOverlay(groundGridLayer);
groundTrackLayer = L.layerGroup().addTo(groundMap); groundTrackLayer = L.layerGroup().addTo(groundMap);
groundOverlayLayer = L.layerGroup().addTo(groundMap);
}
// Delayed invalidation to fix sizing setTimeout(() => {
setTimeout(() => { if (groundMap) groundMap.invalidateSize(); }, 200); if (!groundMap) return;
groundMap.invalidateSize(false);
groundMap.setView(defaultCenter, defaultZoom, { animate: false });
updateGroundTrack(getSelectedPass());
}, 140);
} }
/** /**
* Update ground track on the map * Update map panel subtitle.
*/
function updateProjectionInfo(text) {
const infoEl = document.getElementById('wxsatMapInfo');
if (infoEl) infoEl.textContent = text || '--';
}
/**
* Normalize longitude to [-180, 180).
*/
function normalizeLon(value) {
const lon = Number(value);
if (!isFinite(lon)) return 0;
return ((((lon + 180) % 360) + 360) % 360) - 180;
}
/**
* Build track segments that do not cross the date line.
*/
function buildTrackSegments(track) {
const segments = [];
let currentSegment = [];
track.forEach((point) => {
const lat = Number(point?.lat);
const lon = normalizeLon(point?.lon);
if (!isFinite(lat) || !isFinite(lon)) return;
if (currentSegment.length > 0) {
const prevLon = currentSegment[currentSegment.length - 1][1];
if (Math.abs(lon - prevLon) > 180) {
if (currentSegment.length > 1) segments.push(currentSegment);
currentSegment = [];
}
}
currentSegment.push([lat, lon]);
});
if (currentSegment.length > 1) segments.push(currentSegment);
return segments;
}
/**
* Draw a subtle graticule over the base map for a cyber/wireframe look.
*/
function addStyledGridOverlay(layer) {
if (!layer || typeof L === 'undefined') return;
layer.clearLayers();
for (let lon = -180; lon <= 180; lon += 30) {
const line = [];
for (let lat = -85; lat <= 85; lat += 5) line.push([lat, lon]);
L.polyline(line, {
color: '#4ed2ff',
weight: lon % 60 === 0 ? 1.1 : 0.8,
opacity: lon % 60 === 0 ? 0.2 : 0.12,
interactive: false,
lineCap: 'round',
}).addTo(layer);
}
for (let lat = -75; lat <= 75; lat += 15) {
const line = [];
for (let lon = -180; lon <= 180; lon += 5) line.push([lat, lon]);
L.polyline(line, {
color: '#5be7ff',
weight: lat % 30 === 0 ? 1.1 : 0.8,
opacity: lat % 30 === 0 ? 0.2 : 0.12,
interactive: false,
lineCap: 'round',
}).addTo(layer);
}
}
function clearSatelliteCrosshair() {
if (!groundOverlayLayer || !satCrosshairMarker) return;
groundOverlayLayer.removeLayer(satCrosshairMarker);
satCrosshairMarker = null;
}
function createSatelliteCrosshairIcon() {
return L.divIcon({
className: 'wxsat-crosshair-icon',
iconSize: [30, 30],
iconAnchor: [15, 15],
html: `
<div class="wxsat-crosshair-marker">
<span class="wxsat-crosshair-h"></span>
<span class="wxsat-crosshair-v"></span>
<span class="wxsat-crosshair-ring"></span>
<span class="wxsat-crosshair-dot"></span>
</div>
`,
});
}
/**
* Update selected ground track and redraw map overlays.
*/ */
function updateGroundTrack(pass) { function updateGroundTrack(pass) {
if (!groundMap || !groundTrackLayer) return; if (!groundMap || !groundTrackLayer) return;
groundTrackLayer.clearLayers(); groundTrackLayer.clearLayers();
observerMarker = null;
const track = pass.groundTrack; if (!pass) {
if (!track || track.length === 0) return; clearSatelliteCrosshair();
updateProjectionInfo('--');
return;
}
const color = pass.mode === 'LRPT' ? '#00ff88' : '#00d4ff'; const track = pass?.groundTrack;
if (!Array.isArray(track) || track.length === 0) {
clearSatelliteCrosshair();
updateProjectionInfo(`${pass.name || pass.satellite || '--'} --`);
return;
}
// Draw polyline const color = pass.mode === 'LRPT' ? '#27ffc6' : '#58ddff';
const latlngs = track.map(p => [p.lat, p.lon]); const glowClass = pass.mode === 'LRPT' ? 'wxsat-pass-track lrpt' : 'wxsat-pass-track apt';
L.polyline(latlngs, { color, weight: 2, opacity: 0.8 }).addTo(groundTrackLayer); const segments = buildTrackSegments(track);
const validPoints = track
.map((point) => [Number(point?.lat), normalizeLon(point?.lon)])
.filter((point) => isFinite(point[0]) && isFinite(point[1]));
// Start marker segments.forEach((segment) => {
L.circleMarker(latlngs[0], { L.polyline(segment, {
radius: 5, color: '#00ff88', fillColor: '#00ff88', fillOpacity: 1, weight: 0, color,
}).addTo(groundTrackLayer); weight: 2.3,
opacity: 0.9,
className: glowClass,
interactive: false,
lineJoin: 'round',
}).addTo(groundTrackLayer);
});
// End marker if (validPoints.length > 0) {
L.circleMarker(latlngs[latlngs.length - 1], { L.circleMarker(validPoints[0], {
radius: 5, color: '#ff4444', fillColor: '#ff4444', fillOpacity: 1, weight: 0, radius: 4.5,
}).addTo(groundTrackLayer); color: '#00ffa2',
fillColor: '#00ffa2',
fillOpacity: 0.95,
weight: 0,
interactive: false,
}).addTo(groundTrackLayer);
// Observer marker L.circleMarker(validPoints[validPoints.length - 1], {
const lat = parseFloat(localStorage.getItem('observerLat')); radius: 4.5,
const lon = parseFloat(localStorage.getItem('observerLon')); color: '#ff5e5e',
if (!isNaN(lat) && !isNaN(lon)) { fillColor: '#ff5e5e',
L.circleMarker([lat, lon], { fillOpacity: 0.95,
radius: 6, color: '#ffbb00', fillColor: '#ffbb00', fillOpacity: 0.8, weight: 1, weight: 0,
interactive: false,
}).addTo(groundTrackLayer); }).addTo(groundTrackLayer);
} }
// Fit bounds let obsLat;
try { let obsLon;
const bounds = L.latLngBounds(latlngs); if (window.ObserverLocation && ObserverLocation.isSharedEnabled()) {
if (!isNaN(lat) && !isNaN(lon)) bounds.extend([lat, lon]); const shared = ObserverLocation.getShared();
groundMap.fitBounds(bounds, { padding: [20, 20] }); obsLat = shared?.lat;
} catch (e) {} obsLon = shared?.lon;
} else {
obsLat = parseFloat(localStorage.getItem('observerLat'));
obsLon = parseFloat(localStorage.getItem('observerLon'));
}
if (isFinite(obsLat) && isFinite(obsLon)) {
observerMarker = L.circleMarker([obsLat, obsLon], {
radius: 5.5,
color: '#ffd45b',
fillColor: '#ffd45b',
fillOpacity: 0.8,
weight: 1,
className: 'wxsat-observer-marker',
interactive: false,
}).addTo(groundTrackLayer);
}
updateSatelliteCrosshair(pass);
}
function getSelectedPass() {
if (selectedPassIndex < 0 || selectedPassIndex >= passes.length) return null;
return passes[selectedPassIndex];
}
function getSatellitePositionForPass(pass, atTime = new Date()) {
const track = pass?.groundTrack;
if (!Array.isArray(track) || track.length === 0) return null;
const first = track[0];
if (track.length === 1) {
const lat = Number(first.lat);
const lon = Number(first.lon);
if (!isFinite(lat) || !isFinite(lon)) return null;
return { lat, lon };
}
const start = parsePassDate(pass.startTimeISO);
const end = parsePassDate(pass.endTimeISO);
let fraction = 0;
if (start && end && end > start) {
const totalMs = end.getTime() - start.getTime();
const elapsedMs = atTime.getTime() - start.getTime();
fraction = Math.max(0, Math.min(1, elapsedMs / totalMs));
}
const lastIndex = track.length - 1;
const idxFloat = fraction * lastIndex;
const idx0 = Math.floor(idxFloat);
const idx1 = Math.min(lastIndex, idx0 + 1);
const t = idxFloat - idx0;
const p0 = track[idx0];
const p1 = track[idx1];
const lat0 = Number(p0?.lat);
const lon0 = Number(p0?.lon);
const lat1 = Number(p1?.lat);
const lon1 = Number(p1?.lon);
if (!isFinite(lat0) || !isFinite(lon0) || !isFinite(lat1) || !isFinite(lon1)) {
return null;
}
return {
lat: lat0 + ((lat1 - lat0) * t),
lon: lon0 + ((lon1 - lon0) * t),
};
}
function updateSatelliteCrosshair(pass) {
if (!groundMap || !groundOverlayLayer || typeof L === 'undefined') return;
if (!pass) {
clearSatelliteCrosshair();
updateProjectionInfo('--');
return;
}
const position = getSatellitePositionForPass(pass);
if (!position) {
clearSatelliteCrosshair();
updateProjectionInfo(`${pass.name || pass.satellite || '--'} --`);
return;
}
const latlng = [position.lat, normalizeLon(position.lon)];
if (!satCrosshairMarker) {
satCrosshairMarker = L.marker(latlng, {
icon: createSatelliteCrosshairIcon(),
interactive: false,
keyboard: false,
zIndexOffset: 900,
}).addTo(groundOverlayLayer);
} else {
satCrosshairMarker.setLatLng(latlng);
}
const infoText =
`${pass.name || pass.satellite || 'Satellite'} ` +
`${position.lat.toFixed(2)}°, ${normalizeLon(position.lon).toFixed(2)}°`;
updateProjectionInfo(infoText);
if (!satCrosshairMarker.getTooltip()) {
satCrosshairMarker.bindTooltip(infoText, {
direction: 'top',
offset: [0, -12],
opacity: 0.92,
className: 'wxsat-map-tooltip',
});
} else {
satCrosshairMarker.setTooltipContent(infoText);
}
} }
// ======================== // ========================
@@ -798,8 +1143,11 @@ const WeatherSat = (function() {
let isActive = false; let isActive = false;
for (const pass of passes) { for (const pass of passes) {
const start = new Date(pass.startTimeISO); const start = parsePassDate(pass.startTimeISO);
const end = new Date(pass.endTimeISO); const end = parsePassDate(pass.endTimeISO);
if (!start || !end) {
continue;
}
if (end > now) { if (end > now) {
nextPass = pass; nextPass = pass;
isActive = start <= now; isActive = start <= now;
@@ -828,7 +1176,19 @@ const WeatherSat = (function() {
return; return;
} }
const target = new Date(nextPass.startTimeISO); const target = parsePassDate(nextPass.startTimeISO);
if (!target) {
if (daysEl) daysEl.textContent = '--';
if (hoursEl) hoursEl.textContent = '--';
if (minsEl) minsEl.textContent = '--';
if (secsEl) secsEl.textContent = '--';
if (satEl) satEl.textContent = '--';
if (detailEl) detailEl.textContent = 'Invalid pass time';
if (boxes) boxes.querySelectorAll('.wxsat-countdown-box').forEach(b => {
b.classList.remove('imminent', 'active');
});
return;
}
let diffMs = target - now; let diffMs = target - now;
if (isActive) { if (isActive) {
@@ -862,6 +1222,11 @@ const WeatherSat = (function() {
b.classList.toggle('active', isActive); b.classList.toggle('active', isActive);
}); });
} }
// Keep timeline cursor in sync
updateTimelineCursor();
// Keep selected satellite marker synchronized with time progression.
updateSatelliteCrosshair(getSelectedPass());
} }
// ======================== // ========================
@@ -885,8 +1250,9 @@ const WeatherSat = (function() {
const dayMs = 24 * 60 * 60 * 1000; const dayMs = 24 * 60 * 60 * 1000;
passList.forEach((pass, idx) => { passList.forEach((pass, idx) => {
const start = new Date(pass.startTimeISO); const start = parsePassDate(pass.startTimeISO);
const end = new Date(pass.endTimeISO); const end = parsePassDate(pass.endTimeISO);
if (!start || !end) return;
const startPct = Math.max(0, Math.min(100, ((start - dayStart) / dayMs) * 100)); const startPct = Math.max(0, Math.min(100, ((start - dayStart) / dayMs) * 100));
const endPct = Math.max(0, Math.min(100, ((end - dayStart) / dayMs) * 100)); const endPct = Math.max(0, Math.min(100, ((end - dayStart) / dayMs) * 100));
@@ -926,12 +1292,13 @@ const WeatherSat = (function() {
/** /**
* Toggle auto-scheduler * Toggle auto-scheduler
*/ */
async function toggleScheduler() { async function toggleScheduler(source) {
const checked = source?.checked ?? false;
const stripCheckbox = document.getElementById('wxsatAutoSchedule'); const stripCheckbox = document.getElementById('wxsatAutoSchedule');
const sidebarCheckbox = document.getElementById('wxsatSidebarAutoSchedule'); const sidebarCheckbox = document.getElementById('wxsatSidebarAutoSchedule');
const checked = stripCheckbox?.checked || sidebarCheckbox?.checked;
// Sync both checkboxes // Sync both checkboxes to the source of truth
if (stripCheckbox) stripCheckbox.checked = checked; if (stripCheckbox) stripCheckbox.checked = checked;
if (sidebarCheckbox) sidebarCheckbox.checked = checked; if (sidebarCheckbox) sidebarCheckbox.checked = checked;
@@ -946,8 +1313,15 @@ const WeatherSat = (function() {
* Enable auto-scheduler * Enable auto-scheduler
*/ */
async function enableScheduler() { async function enableScheduler() {
const lat = parseFloat(localStorage.getItem('observerLat')); let lat, lon;
const lon = parseFloat(localStorage.getItem('observerLon')); if (window.ObserverLocation && ObserverLocation.isSharedEnabled()) {
const shared = ObserverLocation.getShared();
lat = shared?.lat;
lon = shared?.lon;
} else {
lat = parseFloat(localStorage.getItem('observerLat'));
lon = parseFloat(localStorage.getItem('observerLon'));
}
if (isNaN(lat) || isNaN(lon)) { if (isNaN(lat) || isNaN(lon)) {
showNotification('Weather Sat', 'Set observer location first'); showNotification('Weather Sat', 'Set observer location first');
@@ -975,13 +1349,28 @@ const WeatherSat = (function() {
}), }),
}); });
const data = await response.json(); let data = {};
try {
data = await response.json();
} catch (err) {
data = {};
}
if (!response.ok || !data || data.enabled !== true) {
schedulerEnabled = false;
updateSchedulerUI({ enabled: false, scheduled_count: 0 });
showNotification('Weather Sat', data.message || 'Failed to enable auto-scheduler');
return;
}
schedulerEnabled = true; schedulerEnabled = true;
updateSchedulerUI(data); updateSchedulerUI(data);
startStream(); startStream();
showNotification('Weather Sat', `Auto-scheduler enabled (${data.scheduled_count || 0} passes)`); showNotification('Weather Sat', `Auto-scheduler enabled (${data.scheduled_count || 0} passes)`);
} catch (err) { } catch (err) {
console.error('Failed to enable scheduler:', err); console.error('Failed to enable scheduler:', err);
schedulerEnabled = false;
updateSchedulerUI({ enabled: false, scheduled_count: 0 });
showNotification('Weather Sat', 'Failed to enable auto-scheduler'); showNotification('Weather Sat', 'Failed to enable auto-scheduler');
} }
} }
@@ -991,7 +1380,11 @@ const WeatherSat = (function() {
*/ */
async function disableScheduler() { async function disableScheduler() {
try { try {
await fetch('/weather-sat/schedule/disable', { method: 'POST' }); const response = await fetch('/weather-sat/schedule/disable', { method: 'POST' });
if (!response.ok) {
showNotification('Weather Sat', 'Failed to disable auto-scheduler');
return;
}
schedulerEnabled = false; schedulerEnabled = false;
updateSchedulerUI({ enabled: false }); updateSchedulerUI({ enabled: false });
if (!isRunning) stopStream(); if (!isRunning) stopStream();
@@ -1007,6 +1400,7 @@ const WeatherSat = (function() {
async function checkSchedulerStatus() { async function checkSchedulerStatus() {
try { try {
const response = await fetch('/weather-sat/schedule/status'); const response = await fetch('/weather-sat/schedule/status');
if (!response.ok) return;
const data = await response.json(); const data = await response.json();
schedulerEnabled = data.enabled; schedulerEnabled = data.enabled;
updateSchedulerUI(data); updateSchedulerUI(data);
@@ -1259,9 +1653,14 @@ const WeatherSat = (function() {
* Invalidate ground map size (call after container becomes visible) * Invalidate ground map size (call after container becomes visible)
*/ */
function invalidateMap() { function invalidateMap() {
if (groundMap) { setTimeout(() => {
setTimeout(() => groundMap.invalidateSize(), 100); if (!groundMap) {
} initGroundMap();
return;
}
groundMap.invalidateSize(false);
updateGroundTrack(getSelectedPass());
}, 100);
} }
// ======================== // ========================
@@ -1366,9 +1765,29 @@ const WeatherSat = (function() {
} }
} }
/**
* Suspend background activity when leaving the mode.
* Closes the SSE stream and stops the countdown interval so they don't
* keep running while another mode is active. The stream is re-opened
* by init() or startStream() when the mode is next entered.
*/
function suspend() {
if (countdownInterval) {
clearInterval(countdownInterval);
countdownInterval = null;
}
// Only close the stream if nothing is actively capturing/scheduling —
// if a capture or scheduler is running we want it to continue on the
// server and the stream will reconnect on next init().
if (!isRunning && !schedulerEnabled) {
stopStream();
}
}
// Public API // Public API
return { return {
init, init,
suspend,
start, start,
stop, stop,
startPass, startPass,
+444 -34
View File
@@ -9,6 +9,20 @@ let websdrMarkers = [];
let websdrReceivers = []; let websdrReceivers = [];
let websdrInitialized = false; let websdrInitialized = false;
let websdrSpyStationsLoaded = false; let websdrSpyStationsLoaded = false;
let websdrMapType = null;
let websdrGlobe = null;
let websdrGlobePopup = null;
let websdrSelectedReceiverIndex = null;
let websdrGlobeScriptPromise = null;
let websdrResizeObserver = null;
let websdrResizeHooked = false;
let websdrGlobeFallbackNotified = false;
const WEBSDR_GLOBE_SCRIPT_URLS = [
'https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js',
'https://cdn.jsdelivr.net/npm/globe.gl@2.33.1/dist/globe.gl.min.js',
];
const WEBSDR_GLOBE_TEXTURE_URL = '/static/images/globe/earth-dark.jpg';
// KiwiSDR audio state // KiwiSDR audio state
let kiwiWebSocket = null; let kiwiWebSocket = null;
@@ -27,38 +41,39 @@ const KIWI_SAMPLE_RATE = 12000;
// ============== INITIALIZATION ============== // ============== INITIALIZATION ==============
function initWebSDR() { async function initWebSDR() {
if (websdrInitialized) { if (websdrInitialized) {
if (websdrMap) { setTimeout(invalidateWebSDRViewport, 100);
setTimeout(() => websdrMap.invalidateSize(), 100);
}
return; return;
} }
const mapEl = document.getElementById('websdrMap'); const mapEl = document.getElementById('websdrMap');
if (!mapEl || typeof L === 'undefined') return; if (!mapEl) return;
// Calculate minimum zoom so tiles fill the container vertically const globeReady = await ensureWebsdrGlobeLibrary();
const mapHeight = mapEl.clientHeight || 500;
const minZoom = Math.ceil(Math.log2(mapHeight / 256));
websdrMap = L.map('websdrMap', { // Wait for a paint frame so the browser computes layout after the
center: [20, 0], // display:flex change in switchMode. Without this, Globe()(mapEl) can
zoom: Math.max(minZoom, 2), // run before clientWidth/clientHeight are non-zero (especially when
minZoom: Math.max(minZoom, 2), // scripts are served from cache and resolve before the first layout pass).
zoomControl: true, await new Promise(resolve => requestAnimationFrame(resolve));
maxBounds: [[-85, -360], [85, 360]],
maxBoundsViscosity: 1.0,
});
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', { // If the mode was switched away while scripts were loading, abort so
attribution: '&copy; OpenStreetMap contributors &copy; CARTO', // websdrInitialized stays false and we retry cleanly next time.
subdomains: 'abcd', if (!mapEl.clientWidth || !mapEl.clientHeight) return;
maxZoom: 19,
}).addTo(websdrMap);
// Match background to tile ocean color so any remaining edge is seamless if (globeReady && initWebsdrGlobe(mapEl)) {
mapEl.style.background = '#1a1d29'; websdrMapType = 'globe';
} else if (typeof L !== 'undefined' && await initWebsdrLeaflet(mapEl)) {
websdrMapType = 'leaflet';
if (!websdrGlobeFallbackNotified && typeof showNotification === 'function') {
showNotification('WebSDR', '3D globe unavailable, using fallback map');
websdrGlobeFallbackNotified = true;
}
} else {
console.error('[WEBSDR] Unable to initialize globe or map renderer');
return;
}
websdrInitialized = true; websdrInitialized = true;
@@ -66,10 +81,12 @@ function initWebSDR() {
loadSpyStationPresets(); loadSpyStationPresets();
} }
setupWebsdrResizeHandling(mapEl);
if (websdrReceivers.length > 0) {
plotReceiversOnMap(websdrReceivers);
}
[100, 300, 600, 1000].forEach(delay => { [100, 300, 600, 1000].forEach(delay => {
setTimeout(() => { setTimeout(invalidateWebSDRViewport, delay);
if (websdrMap) websdrMap.invalidateSize();
}, delay);
}); });
} }
@@ -87,6 +104,8 @@ function searchReceivers(refresh) {
.then(data => { .then(data => {
if (data.status === 'success') { if (data.status === 'success') {
websdrReceivers = data.receivers || []; websdrReceivers = data.receivers || [];
websdrSelectedReceiverIndex = null;
hideWebsdrGlobePopup();
renderReceiverList(websdrReceivers); renderReceiverList(websdrReceivers);
plotReceiversOnMap(websdrReceivers); plotReceiversOnMap(websdrReceivers);
@@ -100,6 +119,11 @@ function searchReceivers(refresh) {
// ============== MAP ============== // ============== MAP ==============
function plotReceiversOnMap(receivers) { function plotReceiversOnMap(receivers) {
if (websdrMapType === 'globe' && websdrGlobe) {
plotReceiversOnGlobe(receivers);
return;
}
if (!websdrMap) return; if (!websdrMap) return;
websdrMarkers.forEach(m => websdrMap.removeLayer(m)); websdrMarkers.forEach(m => websdrMap.removeLayer(m));
@@ -137,6 +161,369 @@ function plotReceiversOnMap(receivers) {
} }
} }
async function ensureWebsdrGlobeLibrary() {
if (typeof window.Globe === 'function') return true;
if (!isWebglSupported()) return false;
if (!websdrGlobeScriptPromise) {
websdrGlobeScriptPromise = WEBSDR_GLOBE_SCRIPT_URLS
.reduce(
(promise, src) => promise.then(() => loadWebsdrScript(src)),
Promise.resolve()
)
.then(() => typeof window.Globe === 'function')
.catch((error) => {
console.warn('[WEBSDR] Failed to load globe scripts:', error);
return false;
});
}
const loaded = await websdrGlobeScriptPromise;
if (!loaded) {
websdrGlobeScriptPromise = null;
}
return loaded;
}
function loadWebsdrScript(src) {
return new Promise((resolve, reject) => {
const selector = `script[data-websdr-src="${src}"]`;
const existing = document.querySelector(selector);
if (existing) {
if (existing.dataset.loaded === 'true') {
resolve();
return;
}
if (existing.dataset.failed === 'true') {
existing.remove();
} else {
existing.addEventListener('load', () => resolve(), { once: true });
existing.addEventListener('error', () => reject(new Error(`Failed to load ${src}`)), { once: true });
return;
}
}
const script = document.createElement('script');
script.src = src;
script.async = true;
script.crossOrigin = 'anonymous';
script.dataset.websdrSrc = src;
script.onload = () => {
script.dataset.loaded = 'true';
resolve();
};
script.onerror = () => {
script.dataset.failed = 'true';
reject(new Error(`Failed to load ${src}`));
};
document.head.appendChild(script);
});
}
function isWebglSupported() {
try {
const canvas = document.createElement('canvas');
return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
} catch (_) {
return false;
}
}
function initWebsdrGlobe(mapEl) {
if (typeof window.Globe !== 'function' || !isWebglSupported()) return false;
mapEl.innerHTML = '';
mapEl.style.background = 'radial-gradient(circle at 30% 20%, rgba(14, 42, 68, 0.9), rgba(4, 9, 16, 0.95) 58%, rgba(2, 4, 9, 0.98) 100%)';
mapEl.style.cursor = 'grab';
websdrGlobe = window.Globe()(mapEl)
.backgroundColor('rgba(0,0,0,0)')
.globeImageUrl(WEBSDR_GLOBE_TEXTURE_URL)
.showAtmosphere(true)
.atmosphereColor('#3bb9ff')
.atmosphereAltitude(0.17)
.pointRadius('radius')
.pointAltitude('altitude')
.pointColor('color')
.pointsTransitionDuration(250)
.pointLabel(point => point.label || '')
.onPointHover(point => {
mapEl.style.cursor = point ? 'pointer' : 'grab';
})
.onPointClick((point, event) => {
if (!point) return;
showWebsdrGlobePopup(point, event);
});
const controls = websdrGlobe.controls();
if (controls) {
controls.autoRotate = true;
controls.autoRotateSpeed = 0.25;
controls.enablePan = false;
controls.minDistance = 140;
controls.maxDistance = 380;
controls.rotateSpeed = 0.7;
controls.zoomSpeed = 0.8;
}
ensureWebsdrGlobePopup(mapEl);
resizeWebsdrGlobe();
return true;
}
async function initWebsdrLeaflet(mapEl) {
if (typeof L === 'undefined') return false;
mapEl.innerHTML = '';
const mapHeight = mapEl.clientHeight || 500;
const minZoom = Math.ceil(Math.log2(mapHeight / 256));
websdrMap = L.map('websdrMap', {
center: [20, 0],
zoom: Math.max(minZoom, 2),
minZoom: Math.max(minZoom, 2),
zoomControl: true,
maxBounds: [[-85, -360], [85, 360]],
maxBoundsViscosity: 1.0,
});
if (typeof Settings !== 'undefined' && Settings.createTileLayer) {
await Settings.init();
Settings.createTileLayer().addTo(websdrMap);
Settings.registerMap(websdrMap);
} else {
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', {
attribution: '&copy; OpenStreetMap contributors &copy; CARTO',
subdomains: 'abcd',
maxZoom: 19,
className: 'tile-layer-cyan',
}).addTo(websdrMap);
}
mapEl.style.background = '#1a1d29';
return true;
}
function setupWebsdrResizeHandling(mapEl) {
if (typeof ResizeObserver !== 'undefined') {
if (websdrResizeObserver) {
websdrResizeObserver.disconnect();
}
websdrResizeObserver = new ResizeObserver(() => invalidateWebSDRViewport());
websdrResizeObserver.observe(mapEl);
}
if (!websdrResizeHooked) {
window.addEventListener('resize', invalidateWebSDRViewport);
window.addEventListener('orientationchange', () => setTimeout(invalidateWebSDRViewport, 120));
websdrResizeHooked = true;
}
}
function invalidateWebSDRViewport() {
if (websdrMapType === 'globe') {
resizeWebsdrGlobe();
return;
}
if (websdrMap && typeof websdrMap.invalidateSize === 'function') {
websdrMap.invalidateSize({ pan: false, animate: false });
}
}
function resizeWebsdrGlobe() {
if (!websdrGlobe) return;
const mapEl = document.getElementById('websdrMap');
if (!mapEl) return;
const width = mapEl.clientWidth;
const height = mapEl.clientHeight;
if (!width || !height) return;
websdrGlobe.width(width);
websdrGlobe.height(height);
}
function plotReceiversOnGlobe(receivers) {
if (!websdrGlobe) return;
const points = [];
receivers.forEach((rx, idx) => {
const lat = Number(rx.lat);
const lon = Number(rx.lon);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return;
const selected = idx === websdrSelectedReceiverIndex;
points.push({
lat: lat,
lng: lon,
receiverIndex: idx,
radius: selected ? 0.52 : 0.38,
altitude: selected ? 0.1 : 0.04,
color: selected ? '#00ff88' : (rx.available ? '#00d4ff' : '#5f6976'),
label: buildWebsdrPointLabel(rx, idx),
});
});
websdrGlobe.pointsData(points);
if (points.length > 0) {
if (websdrSelectedReceiverIndex != null) {
const selectedPoint = points.find(point => point.receiverIndex === websdrSelectedReceiverIndex);
if (selectedPoint) {
websdrGlobe.pointOfView({ lat: selectedPoint.lat, lng: selectedPoint.lng, altitude: 1.45 }, 900);
return;
}
}
const center = computeWebsdrGlobeCenter(points);
websdrGlobe.pointOfView(center, 900);
}
}
function computeWebsdrGlobeCenter(points) {
if (!points.length) return { lat: 20, lng: 0, altitude: 2.1 };
let x = 0;
let y = 0;
let z = 0;
points.forEach(point => {
const latRad = point.lat * Math.PI / 180;
const lonRad = point.lng * Math.PI / 180;
x += Math.cos(latRad) * Math.cos(lonRad);
y += Math.cos(latRad) * Math.sin(lonRad);
z += Math.sin(latRad);
});
const count = points.length;
x /= count;
y /= count;
z /= count;
const hyp = Math.sqrt((x * x) + (y * y));
const centerLat = Math.atan2(z, hyp) * 180 / Math.PI;
const centerLng = Math.atan2(y, x) * 180 / Math.PI;
let meanAngularDistance = 0;
const centerLatRad = centerLat * Math.PI / 180;
const centerLngRad = centerLng * Math.PI / 180;
points.forEach(point => {
const latRad = point.lat * Math.PI / 180;
const lonRad = point.lng * Math.PI / 180;
const cosAngle = (
(Math.sin(centerLatRad) * Math.sin(latRad)) +
(Math.cos(centerLatRad) * Math.cos(latRad) * Math.cos(lonRad - centerLngRad))
);
const safeCos = Math.max(-1, Math.min(1, cosAngle));
meanAngularDistance += Math.acos(safeCos) * 180 / Math.PI;
});
meanAngularDistance /= count;
const altitude = Math.min(2.9, Math.max(1.35, 1.35 + (meanAngularDistance / 45)));
return { lat: centerLat, lng: centerLng, altitude: altitude };
}
function ensureWebsdrGlobePopup(mapEl) {
if (websdrGlobePopup) {
if (websdrGlobePopup.parentElement !== mapEl) {
mapEl.appendChild(websdrGlobePopup);
}
return;
}
websdrGlobePopup = document.createElement('div');
websdrGlobePopup.id = 'websdrGlobePopup';
websdrGlobePopup.style.position = 'absolute';
websdrGlobePopup.style.minWidth = '220px';
websdrGlobePopup.style.maxWidth = '260px';
websdrGlobePopup.style.padding = '10px';
websdrGlobePopup.style.borderRadius = '8px';
websdrGlobePopup.style.border = '1px solid rgba(0, 212, 255, 0.35)';
websdrGlobePopup.style.background = 'rgba(5, 13, 20, 0.92)';
websdrGlobePopup.style.backdropFilter = 'blur(4px)';
websdrGlobePopup.style.boxShadow = '0 8px 24px rgba(0, 0, 0, 0.4)';
websdrGlobePopup.style.color = 'var(--text-primary)';
websdrGlobePopup.style.display = 'none';
websdrGlobePopup.style.zIndex = '20';
mapEl.appendChild(websdrGlobePopup);
if (!mapEl.dataset.websdrPopupHooked) {
mapEl.addEventListener('click', (event) => {
if (!websdrGlobePopup || websdrGlobePopup.style.display === 'none') return;
if (event.target.closest('#websdrGlobePopup')) return;
hideWebsdrGlobePopup();
});
mapEl.dataset.websdrPopupHooked = 'true';
}
}
function showWebsdrGlobePopup(point, event) {
if (!websdrGlobePopup || !point || point.receiverIndex == null) return;
const rx = websdrReceivers[point.receiverIndex];
if (!rx) return;
const mapEl = document.getElementById('websdrMap');
if (!mapEl) return;
websdrSelectedReceiverIndex = point.receiverIndex;
renderReceiverList(websdrReceivers);
plotReceiversOnGlobe(websdrReceivers);
websdrGlobePopup.innerHTML = `
<div style="display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 6px;">
<strong style="font-size: 12px; color: var(--accent-cyan);">${escapeHtmlWebsdr(rx.name)}</strong>
<button type="button" data-websdr-popup-close style="border: none; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 14px; line-height: 1;">&times;</button>
</div>
${rx.location ? `<div style="font-size: 10px; color: var(--text-secondary); margin-bottom: 3px;">${escapeHtmlWebsdr(rx.location)}</div>` : ''}
<div style="font-size: 10px; color: var(--text-muted); margin-bottom: 2px;">Antenna: ${escapeHtmlWebsdr(rx.antenna || 'Unknown')}</div>
<div style="font-size: 10px; color: var(--text-muted); margin-bottom: 10px;">Users: ${rx.users}/${rx.users_max}</div>
<button type="button" data-websdr-listen style="width: 100%; padding: 5px 10px; background: #00d4ff; color: #041018; border: none; border-radius: 4px; cursor: pointer; font-weight: 700;">Listen</button>
`;
websdrGlobePopup.style.display = 'block';
const rect = mapEl.getBoundingClientRect();
const x = event && Number.isFinite(event.clientX) ? (event.clientX - rect.left) : (rect.width / 2);
const y = event && Number.isFinite(event.clientY) ? (event.clientY - rect.top) : (rect.height / 2);
const popupWidth = 260;
const popupHeight = 155;
const left = Math.max(12, Math.min(rect.width - popupWidth - 12, x + 12));
const top = Math.max(12, Math.min(rect.height - popupHeight - 12, y + 12));
websdrGlobePopup.style.left = `${left}px`;
websdrGlobePopup.style.top = `${top}px`;
const closeBtn = websdrGlobePopup.querySelector('[data-websdr-popup-close]');
if (closeBtn) {
closeBtn.onclick = () => hideWebsdrGlobePopup();
}
const listenBtn = websdrGlobePopup.querySelector('[data-websdr-listen]');
if (listenBtn) {
listenBtn.onclick = () => selectReceiver(point.receiverIndex);
}
if (event && typeof event.stopPropagation === 'function') {
event.stopPropagation();
}
}
function hideWebsdrGlobePopup() {
if (websdrGlobePopup) {
websdrGlobePopup.style.display = 'none';
}
}
function buildWebsdrPointLabel(rx, idx) {
const location = rx.location ? escapeHtmlWebsdr(rx.location) : 'Unknown location';
const antenna = escapeHtmlWebsdr(rx.antenna || 'Unknown antenna');
return `
<div style="padding: 4px 6px; font-size: 11px; background: rgba(4, 12, 19, 0.9); border: 1px solid rgba(0,212,255,0.28); border-radius: 4px;">
<div style="color: #00d4ff; font-weight: 600;">${escapeHtmlWebsdr(rx.name)}</div>
<div style="color: #a5b1c3;">${location}</div>
<div style="color: #8f9fb3;">${antenna} · ${rx.users}/${rx.users_max}</div>
<div style="color: #7a899b; margin-top: 2px;">Receiver #${idx + 1}</div>
</div>
`;
}
// ============== RECEIVER LIST ============== // ============== RECEIVER LIST ==============
function renderReceiverList(receivers) { function renderReceiverList(receivers) {
@@ -148,12 +535,16 @@ function renderReceiverList(receivers) {
return; return;
} }
container.innerHTML = receivers.slice(0, 50).map((rx, idx) => ` container.innerHTML = receivers.slice(0, 50).map((rx, idx) => {
<div style="padding: 8px; border-bottom: 1px solid rgba(255,255,255,0.05); cursor: pointer; transition: background 0.2s;" const selected = idx === websdrSelectedReceiverIndex;
onmouseover="this.style.background='rgba(0,212,255,0.05)'" onmouseout="this.style.background='transparent'" const baseBg = selected ? 'rgba(0,212,255,0.14)' : 'transparent';
const hoverBg = selected ? 'rgba(0,212,255,0.18)' : 'rgba(0,212,255,0.05)';
return `
<div style="padding: 8px 8px 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.05); cursor: pointer; transition: background 0.2s; border-left: 2px solid ${selected ? 'var(--accent-cyan)' : 'transparent'}; background: ${baseBg};"
onmouseover="this.style.background='${hoverBg}'" onmouseout="this.style.background='${baseBg}'"
onclick="selectReceiver(${idx})"> onclick="selectReceiver(${idx})">
<div style="display: flex; justify-content: space-between; align-items: center;"> <div style="display: flex; justify-content: space-between; align-items: center;">
<strong style="font-size: 11px; color: var(--text-primary);">${escapeHtmlWebsdr(rx.name)}</strong> <strong style="font-size: 11px; color: ${selected ? 'var(--accent-cyan)' : 'var(--text-primary)'};">${escapeHtmlWebsdr(rx.name)}</strong>
<span style="font-size: 9px; padding: 1px 6px; background: ${rx.available ? 'rgba(0,230,118,0.15)' : 'rgba(158,158,158,0.15)'}; color: ${rx.available ? '#00e676' : '#9e9e9e'}; border-radius: 3px;">${rx.users}/${rx.users_max}</span> <span style="font-size: 9px; padding: 1px 6px; background: ${rx.available ? 'rgba(0,230,118,0.15)' : 'rgba(158,158,158,0.15)'}; color: ${rx.available ? '#00e676' : '#9e9e9e'}; border-radius: 3px;">${rx.users}/${rx.users_max}</span>
</div> </div>
<div style="font-size: 9px; color: var(--text-muted); margin-top: 2px;"> <div style="font-size: 9px; color: var(--text-muted); margin-top: 2px;">
@@ -161,7 +552,8 @@ function renderReceiverList(receivers) {
${rx.distance_km !== undefined ? ` · ${rx.distance_km} km` : ''} ${rx.distance_km !== undefined ? ` · ${rx.distance_km} km` : ''}
</div> </div>
</div> </div>
`).join(''); `;
}).join('');
} }
// ============== SELECT RECEIVER ============== // ============== SELECT RECEIVER ==============
@@ -173,14 +565,30 @@ function selectReceiver(index) {
const freqKhz = parseFloat(document.getElementById('websdrFrequency')?.value || 7000); const freqKhz = parseFloat(document.getElementById('websdrFrequency')?.value || 7000);
const mode = document.getElementById('websdrMode_select')?.value || 'am'; const mode = document.getElementById('websdrMode_select')?.value || 'am';
websdrSelectedReceiverIndex = index;
renderReceiverList(websdrReceivers);
focusReceiverOnMap(rx);
hideWebsdrGlobePopup();
kiwiReceiverName = rx.name; kiwiReceiverName = rx.name;
// Connect via backend proxy // Connect via backend proxy
connectToReceiver(rx.url, freqKhz, mode); connectToReceiver(rx.url, freqKhz, mode);
}
// Highlight on map function focusReceiverOnMap(rx) {
if (websdrMap && rx.lat != null && rx.lon != null) { const lat = Number(rx.lat);
websdrMap.setView([rx.lat, rx.lon], 6); const lon = Number(rx.lon);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return;
if (websdrMapType === 'globe' && websdrGlobe) {
plotReceiversOnGlobe(websdrReceivers);
websdrGlobe.pointOfView({ lat: lat, lng: lon, altitude: 1.4 }, 900);
return;
}
if (websdrMap) {
websdrMap.setView([lat, lon], 6);
} }
} }
@@ -544,6 +952,8 @@ function tuneToSpyStation(stationId, freqKhz) {
.then(data => { .then(data => {
if (data.status === 'success') { if (data.status === 'success') {
websdrReceivers = data.receivers || []; websdrReceivers = data.receivers || [];
websdrSelectedReceiverIndex = null;
hideWebsdrGlobePopup();
renderReceiverList(websdrReceivers); renderReceiverList(websdrReceivers);
plotReceiversOnMap(websdrReceivers); plotReceiversOnMap(websdrReceivers);
+163 -42
View File
@@ -124,6 +124,19 @@ const WiFiMode = (function() {
let selectedNetwork = null; let selectedNetwork = null;
let currentFilter = 'all'; let currentFilter = 'all';
let currentSort = { field: 'rssi', order: 'desc' }; let currentSort = { field: 'rssi', order: 'desc' };
let renderFramePending = false;
const pendingRender = {
table: false,
stats: false,
radar: false,
chart: false,
detail: false,
};
const listenersBound = {
scanTabs: false,
filters: false,
sort: false,
};
// Agent state // Agent state
let showAllAgentsMode = false; // Show combined results from all agents let showAllAgentsMode = false; // Show combined results from all agents
@@ -156,6 +169,7 @@ const WiFiMode = (function() {
initSortControls(); initSortControls();
initProximityRadar(); initProximityRadar();
initChannelChart(); initChannelChart();
scheduleRender({ table: true, stats: true, radar: true, chart: true });
// Check if already scanning // Check if already scanning
checkScanStatus(); checkScanStatus();
@@ -365,12 +379,14 @@ const WiFiMode = (function() {
// ========================================================================== // ==========================================================================
function initScanModeTabs() { function initScanModeTabs() {
if (listenersBound.scanTabs) return;
if (elements.scanModeQuick) { if (elements.scanModeQuick) {
elements.scanModeQuick.addEventListener('click', () => setScanMode('quick')); elements.scanModeQuick.addEventListener('click', () => setScanMode('quick'));
} }
if (elements.scanModeDeep) { if (elements.scanModeDeep) {
elements.scanModeDeep.addEventListener('click', () => setScanMode('deep')); elements.scanModeDeep.addEventListener('click', () => setScanMode('deep'));
} }
listenersBound.scanTabs = true;
} }
function setScanMode(mode) { function setScanMode(mode) {
@@ -574,20 +590,35 @@ const WiFiMode = (function() {
eventSource = null; eventSource = null;
} }
// Update UI immediately so mode transitions are responsive even if the
// backend needs extra time to terminate subprocesses.
setScanning(false);
// Stop scan on server (local or agent) // Stop scan on server (local or agent)
const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local'; const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local';
const timeoutMs = isAgentMode ? 8000 : 2200;
const controller = (typeof AbortController !== 'undefined') ? new AbortController() : null;
const timeoutId = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
try { try {
if (isAgentMode) { if (isAgentMode) {
await fetch(`/controller/agents/${currentAgent}/wifi/stop`, { method: 'POST' }); await fetch(`/controller/agents/${currentAgent}/wifi/stop`, {
method: 'POST',
...(controller ? { signal: controller.signal } : {}),
});
} else if (scanMode === 'deep') { } else if (scanMode === 'deep') {
await fetch(`${CONFIG.apiBase}/scan/stop`, { method: 'POST' }); await fetch(`${CONFIG.apiBase}/scan/stop`, {
method: 'POST',
...(controller ? { signal: controller.signal } : {}),
});
} }
} catch (error) { } catch (error) {
console.warn('[WiFiMode] Error stopping scan:', error); console.warn('[WiFiMode] Error stopping scan:', error);
} finally {
if (timeoutId) {
clearTimeout(timeoutId);
}
} }
setScanning(false);
} }
function setScanning(scanning, mode = null) { function setScanning(scanning, mode = null) {
@@ -698,10 +729,7 @@ const WiFiMode = (function() {
} }
// Update UI // Update UI
updateNetworkTable(); scheduleRender({ table: true, stats: true, radar: true, chart: true });
updateStats();
updateProximityRadar();
updateChannelChart();
// Callbacks // Callbacks
result.access_points.forEach(ap => { result.access_points.forEach(ap => {
@@ -912,17 +940,20 @@ const WiFiMode = (function() {
function handleNetworkUpdate(network) { function handleNetworkUpdate(network) {
networks.set(network.bssid, network); networks.set(network.bssid, network);
updateNetworkRow(network); scheduleRender({
updateStats(); table: true,
updateProximityRadar(); stats: true,
updateChannelChart(); radar: true,
chart: true,
detail: selectedNetwork === network.bssid,
});
if (onNetworkUpdate) onNetworkUpdate(network); if (onNetworkUpdate) onNetworkUpdate(network);
} }
function handleClientUpdate(client) { function handleClientUpdate(client) {
clients.set(client.mac, client); clients.set(client.mac, client);
updateStats(); scheduleRender({ stats: true });
// Update client display if this client belongs to the selected network // Update client display if this client belongs to the selected network
updateClientInList(client); updateClientInList(client);
@@ -944,7 +975,10 @@ const WiFiMode = (function() {
if (network) { if (network) {
network.revealed_essid = revealedSsid; network.revealed_essid = revealedSsid;
network.display_name = `${revealedSsid} (revealed)`; network.display_name = `${revealedSsid} (revealed)`;
updateNetworkRow(network); scheduleRender({
table: true,
detail: selectedNetwork === bssid,
});
// Show notification // Show notification
showInfo(`Hidden SSID revealed: ${revealedSsid}`); showInfo(`Hidden SSID revealed: ${revealedSsid}`);
@@ -956,6 +990,7 @@ const WiFiMode = (function() {
// ========================================================================== // ==========================================================================
function initNetworkFilters() { function initNetworkFilters() {
if (listenersBound.filters) return;
if (!elements.networkFilters) return; if (!elements.networkFilters) return;
elements.networkFilters.addEventListener('click', (e) => { elements.networkFilters.addEventListener('click', (e) => {
@@ -964,6 +999,7 @@ const WiFiMode = (function() {
setNetworkFilter(filter); setNetworkFilter(filter);
} }
}); });
listenersBound.filters = true;
} }
function setNetworkFilter(filter) { function setNetworkFilter(filter) {
@@ -980,6 +1016,7 @@ const WiFiMode = (function() {
} }
function initSortControls() { function initSortControls() {
if (listenersBound.sort) return;
if (!elements.networkTable) return; if (!elements.networkTable) return;
elements.networkTable.addEventListener('click', (e) => { elements.networkTable.addEventListener('click', (e) => {
@@ -995,6 +1032,44 @@ const WiFiMode = (function() {
updateNetworkTable(); updateNetworkTable();
} }
}); });
if (elements.networkTableBody) {
elements.networkTableBody.addEventListener('click', (e) => {
const row = e.target.closest('tr[data-bssid]');
if (!row) return;
selectNetwork(row.dataset.bssid);
});
}
listenersBound.sort = true;
}
function scheduleRender(flags = {}) {
pendingRender.table = pendingRender.table || Boolean(flags.table);
pendingRender.stats = pendingRender.stats || Boolean(flags.stats);
pendingRender.radar = pendingRender.radar || Boolean(flags.radar);
pendingRender.chart = pendingRender.chart || Boolean(flags.chart);
pendingRender.detail = pendingRender.detail || Boolean(flags.detail);
if (renderFramePending) return;
renderFramePending = true;
requestAnimationFrame(() => {
renderFramePending = false;
if (pendingRender.table) updateNetworkTable();
if (pendingRender.stats) updateStats();
if (pendingRender.radar) updateProximityRadar();
if (pendingRender.chart) updateChannelChart();
if (pendingRender.detail && selectedNetwork) {
updateDetailPanel(selectedNetwork, { refreshClients: false });
}
pendingRender.table = false;
pendingRender.stats = false;
pendingRender.radar = false;
pendingRender.chart = false;
pendingRender.detail = false;
});
} }
function updateNetworkTable() { function updateNetworkTable() {
@@ -1054,19 +1129,41 @@ const WiFiMode = (function() {
} }
}); });
if (filtered.length === 0) {
let message = 'Start scanning to discover networks';
let type = 'empty';
if (isScanning) {
message = 'Scanning for networks...';
type = 'loading';
} else if (networks.size > 0) {
message = 'No networks match current filters';
}
if (typeof renderCollectionState === 'function') {
renderCollectionState(elements.networkTableBody, {
type,
message,
columns: 7,
});
} else {
elements.networkTableBody.innerHTML = `<tr class="wifi-network-placeholder"><td colspan="7"><div class="placeholder-text">${escapeHtml(message)}</div></td></tr>`;
}
return;
}
// Render table // Render table
elements.networkTableBody.innerHTML = filtered.map(n => createNetworkRow(n)).join(''); elements.networkTableBody.innerHTML = filtered.map(n => createNetworkRow(n)).join('');
} }
function createNetworkRow(network) { function createNetworkRow(network) {
const rssi = network.rssi_current; const rssi = network.rssi_current;
const security = network.security || 'Unknown';
const signalClass = rssi >= -50 ? 'signal-strong' : const signalClass = rssi >= -50 ? 'signal-strong' :
rssi >= -70 ? 'signal-medium' : rssi >= -70 ? 'signal-medium' :
rssi >= -85 ? 'signal-weak' : 'signal-very-weak'; rssi >= -85 ? 'signal-weak' : 'signal-very-weak';
const securityClass = network.security === 'Open' ? 'security-open' : const securityClass = security === 'Open' ? 'security-open' :
network.security === 'WEP' ? 'security-wep' : security === 'WEP' ? 'security-wep' :
network.security.includes('WPA3') ? 'security-wpa3' : 'security-wpa'; security.includes('WPA3') ? 'security-wpa3' : 'security-wpa';
const hiddenBadge = network.is_hidden ? '<span class="badge badge-hidden">Hidden</span>' : ''; const hiddenBadge = network.is_hidden ? '<span class="badge badge-hidden">Hidden</span>' : '';
const newBadge = network.is_new ? '<span class="badge badge-new">New</span>' : ''; const newBadge = network.is_new ? '<span class="badge badge-new">New</span>' : '';
@@ -1078,7 +1175,10 @@ const WiFiMode = (function() {
return ` return `
<tr class="wifi-network-row ${network.bssid === selectedNetwork ? 'selected' : ''}" <tr class="wifi-network-row ${network.bssid === selectedNetwork ? 'selected' : ''}"
data-bssid="${escapeHtml(network.bssid)}" data-bssid="${escapeHtml(network.bssid)}"
onclick="WiFiMode.selectNetwork('${escapeHtml(network.bssid)}')"> role="button"
tabindex="0"
data-keyboard-activate="true"
aria-label="Select network ${escapeHtml(network.display_name || network.essid || '[Hidden]')}">
<td class="col-essid"> <td class="col-essid">
<span class="essid">${escapeHtml(network.display_name || network.essid || '[Hidden]')}</span> <span class="essid">${escapeHtml(network.display_name || network.essid || '[Hidden]')}</span>
${hiddenBadge}${newBadge} ${hiddenBadge}${newBadge}
@@ -1086,10 +1186,10 @@ const WiFiMode = (function() {
<td class="col-bssid"><code>${escapeHtml(network.bssid)}</code></td> <td class="col-bssid"><code>${escapeHtml(network.bssid)}</code></td>
<td class="col-channel">${network.channel || '-'}</td> <td class="col-channel">${network.channel || '-'}</td>
<td class="col-rssi"> <td class="col-rssi">
<span class="rssi-value ${signalClass}">${rssi !== null ? rssi : '-'}</span> <span class="rssi-value ${signalClass}">${rssi != null ? rssi : '-'}</span>
</td> </td>
<td class="col-security"> <td class="col-security">
<span class="security-badge ${securityClass}">${escapeHtml(network.security)}</span> <span class="security-badge ${securityClass}">${escapeHtml(security)}</span>
</td> </td>
<td class="col-clients">${network.client_count || 0}</td> <td class="col-clients">${network.client_count || 0}</td>
<td class="col-agent"> <td class="col-agent">
@@ -1100,13 +1200,10 @@ const WiFiMode = (function() {
} }
function updateNetworkRow(network) { function updateNetworkRow(network) {
const row = elements.networkTableBody?.querySelector(`tr[data-bssid="${network.bssid}"]`); scheduleRender({
if (row) { table: true,
row.outerHTML = createNetworkRow(network); detail: selectedNetwork === network.bssid,
} else { });
// Add new row
updateNetworkTable();
}
} }
function selectNetwork(bssid) { function selectNetwork(bssid) {
@@ -1130,7 +1227,8 @@ const WiFiMode = (function() {
// Detail Panel // Detail Panel
// ========================================================================== // ==========================================================================
function updateDetailPanel(bssid) { function updateDetailPanel(bssid, options = {}) {
const { refreshClients = true } = options;
if (!elements.detailDrawer) return; if (!elements.detailDrawer) return;
const network = networks.get(bssid); const network = networks.get(bssid);
@@ -1177,7 +1275,9 @@ const WiFiMode = (function() {
elements.detailDrawer.classList.add('open'); elements.detailDrawer.classList.add('open');
// Fetch and display clients for this network // Fetch and display clients for this network
fetchClientsForNetwork(network.bssid); if (refreshClients) {
fetchClientsForNetwork(network.bssid);
}
} }
function closeDetail() { function closeDetail() {
@@ -1196,6 +1296,12 @@ const WiFiMode = (function() {
async function fetchClientsForNetwork(bssid) { async function fetchClientsForNetwork(bssid) {
if (!elements.detailClientList) return; if (!elements.detailClientList) return;
const listContainer = elements.detailClientList.querySelector('.wifi-client-list');
if (listContainer && typeof renderCollectionState === 'function') {
renderCollectionState(listContainer, { type: 'loading', message: 'Loading clients...' });
elements.detailClientList.style.display = 'block';
}
try { try {
const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local'; const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local';
@@ -1209,8 +1315,12 @@ const WiFiMode = (function() {
} }
if (!response.ok) { if (!response.ok) {
// Hide client list on error if (listContainer && typeof renderCollectionState === 'function') {
elements.detailClientList.style.display = 'none'; renderCollectionState(listContainer, { type: 'empty', message: 'Client list unavailable' });
elements.detailClientList.style.display = 'block';
} else {
elements.detailClientList.style.display = 'none';
}
return; return;
} }
@@ -1223,11 +1333,23 @@ const WiFiMode = (function() {
renderClientList(clientList, bssid); renderClientList(clientList, bssid);
elements.detailClientList.style.display = 'block'; elements.detailClientList.style.display = 'block';
} else { } else {
elements.detailClientList.style.display = 'none'; const countBadge = document.getElementById('wifiClientCountBadge');
if (countBadge) countBadge.textContent = '0';
if (listContainer && typeof renderCollectionState === 'function') {
renderCollectionState(listContainer, { type: 'empty', message: 'No associated clients' });
elements.detailClientList.style.display = 'block';
} else {
elements.detailClientList.style.display = 'none';
}
} }
} catch (error) { } catch (error) {
console.debug('[WiFiMode] Error fetching clients:', error); console.debug('[WiFiMode] Error fetching clients:', error);
elements.detailClientList.style.display = 'none'; if (listContainer && typeof renderCollectionState === 'function') {
renderCollectionState(listContainer, { type: 'empty', message: 'Client list unavailable' });
elements.detailClientList.style.display = 'block';
} else {
elements.detailClientList.style.display = 'none';
}
} }
} }
@@ -1592,11 +1714,10 @@ const WiFiMode = (function() {
probeRequests = []; probeRequests = [];
channelStats = []; channelStats = [];
recommendations = []; recommendations = [];
if (selectedNetwork) {
updateNetworkTable(); closeDetail();
updateStats(); }
updateProximityRadar(); scheduleRender({ table: true, stats: true, radar: true, chart: true });
updateChannelChart();
} }
/** /**
@@ -1643,10 +1764,10 @@ const WiFiMode = (function() {
} }
}); });
clientsToRemove.forEach(mac => clients.delete(mac)); clientsToRemove.forEach(mac => clients.delete(mac));
if (selectedNetwork && !networks.has(selectedNetwork)) {
updateNetworkTable(); closeDetail();
updateStats(); }
updateProximityRadar(); scheduleRender({ table: true, stats: true, radar: true, chart: true });
} }
/** /**
+297
View File
@@ -0,0 +1,297 @@
/*
* Leaflet.heat a tiny, fast Leaflet heatmap plugin
* https://github.com/Leaflet/Leaflet.heat
* (c) 2014, Vladimir Agafonkin
* MIT License
*
* Bundled local copy for INTERCEPT avoids CDN dependency.
* Includes simpleheat (https://github.com/mourner/simpleheat), MIT License.
*/
// ---- simpleheat ----
(function (global, factory) {
typeof define === 'function' && define.amd ? define(factory) :
typeof exports !== 'undefined' ? module.exports = factory() :
global.simpleheat = factory();
}(this, function () {
'use strict';
function simpleheat(canvas) {
if (!(this instanceof simpleheat)) return new simpleheat(canvas);
this._canvas = canvas = typeof canvas === 'string' ? document.getElementById(canvas) : canvas;
this._ctx = canvas.getContext('2d');
this._width = canvas.width;
this._height = canvas.height;
this._max = 1;
this._data = [];
}
simpleheat.prototype = {
defaultRadius: 25,
defaultGradient: {
0.4: 'blue',
0.6: 'cyan',
0.7: 'lime',
0.8: 'yellow',
1.0: 'red'
},
data: function (data) {
this._data = data;
return this;
},
max: function (max) {
this._max = max;
return this;
},
add: function (point) {
this._data.push(point);
return this;
},
clear: function () {
this._data = [];
return this;
},
radius: function (r, blur) {
blur = blur === undefined ? 15 : blur;
var circle = this._circle = this._createCanvas(),
ctx = circle.getContext('2d'),
r2 = this._r = r + blur;
circle.width = circle.height = r2 * 2;
ctx.shadowOffsetX = ctx.shadowOffsetY = r2 * 2;
ctx.shadowBlur = blur;
ctx.shadowColor = 'black';
ctx.beginPath();
ctx.arc(-r2, -r2, r, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
return this;
},
resize: function () {
this._width = this._canvas.width;
this._height = this._canvas.height;
},
gradient: function (grad) {
var canvas = this._createCanvas(),
ctx = canvas.getContext('2d'),
gradient = ctx.createLinearGradient(0, 0, 0, 256);
canvas.width = 1;
canvas.height = 256;
for (var i in grad) {
gradient.addColorStop(+i, grad[i]);
}
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 1, 256);
this._grad = ctx.getImageData(0, 0, 1, 256).data;
return this;
},
draw: function (minOpacity) {
if (!this._circle) this.radius(this.defaultRadius);
if (!this._grad) this.gradient(this.defaultGradient);
var ctx = this._ctx;
ctx.clearRect(0, 0, this._width, this._height);
for (var i = 0, len = this._data.length, p; i < len; i++) {
p = this._data[i];
ctx.globalAlpha = Math.min(Math.max(p[2] / this._max, minOpacity === undefined ? 0.05 : minOpacity), 1);
ctx.drawImage(this._circle, p[0] - this._r, p[1] - this._r);
}
var colored = ctx.getImageData(0, 0, this._width, this._height);
this._colorize(colored.data, this._grad);
ctx.putImageData(colored, 0, 0);
return this;
},
_colorize: function (pixels, gradient) {
for (var i = 3, len = pixels.length, j; i < len; i += 4) {
j = pixels[i] * 4;
if (j) {
pixels[i - 3] = gradient[j];
pixels[i - 2] = gradient[j + 1];
pixels[i - 1] = gradient[j + 2];
}
}
},
_createCanvas: function () {
if (typeof document !== 'undefined') {
return document.createElement('canvas');
}
return { getContext: function () {} };
}
};
return simpleheat;
}));
// ---- Leaflet.heat plugin ----
(function () {
if (typeof L === 'undefined') return;
L.HeatLayer = (L.Layer ? L.Layer : L.Class).extend({
initialize: function (latlngs, options) {
this._latlngs = latlngs;
L.setOptions(this, options);
},
setLatLngs: function (latlngs) {
this._latlngs = latlngs;
return this.redraw();
},
addLatLng: function (latlng) {
this._latlngs.push(latlng);
return this.redraw();
},
setOptions: function (options) {
L.setOptions(this, options);
if (this._heat) this._updateOptions();
return this.redraw();
},
redraw: function () {
if (this._heat && !this._frame && this._map && !this._map._animating) {
this._frame = L.Util.requestAnimFrame(this._redraw, this);
}
return this;
},
onAdd: function (map) {
this._map = map;
if (!this._canvas) this._initCanvas();
if (this.options.pane) this.getPane().appendChild(this._canvas);
else map._panes.overlayPane.appendChild(this._canvas);
map.on('moveend', this._reset, this);
if (map.options.zoomAnimation && L.Browser.any3d) {
map.on('zoomanim', this._animateZoom, this);
}
this._reset();
},
onRemove: function (map) {
if (this.options.pane) this.getPane().removeChild(this._canvas);
else map.getPanes().overlayPane.removeChild(this._canvas);
map.off('moveend', this._reset, this);
if (map.options.zoomAnimation) {
map.off('zoomanim', this._animateZoom, this);
}
},
addTo: function (map) {
map.addLayer(this);
return this;
},
_initCanvas: function () {
var canvas = this._canvas = L.DomUtil.create('canvas', 'leaflet-heatmap-layer leaflet-layer');
var originProp = L.DomUtil.testProp(['transformOrigin', 'WebkitTransformOrigin', 'msTransformOrigin']);
canvas.style[originProp] = '50% 50%';
var size = this._map.getSize();
canvas.width = size.x;
canvas.height = size.y;
var animated = this._map.options.zoomAnimation && L.Browser.any3d;
L.DomUtil.addClass(canvas, 'leaflet-zoom-' + (animated ? 'animated' : 'hide'));
this._heat = simpleheat(canvas);
this._updateOptions();
},
_updateOptions: function () {
this._heat.radius(this.options.radius || this._heat.defaultRadius, this.options.blur);
if (this.options.gradient) this._heat.gradient(this.options.gradient);
if (this.options.minOpacity) this._heat.minOpacity = this.options.minOpacity;
},
_reset: function () {
var topLeft = this._map.containerPointToLayerPoint([0, 0]);
L.DomUtil.setPosition(this._canvas, topLeft);
var size = this._map.getSize();
if (this._heat._width !== size.x) {
this._canvas.width = this._heat._width = size.x;
}
if (this._heat._height !== size.y) {
this._canvas.height = this._heat._height = size.y;
}
this._redraw();
},
_redraw: function () {
this._frame = null;
if (!this._map) return;
var data = [],
r = this._heat._r,
size = this._map.getSize(),
bounds = new L.Bounds(L.point([-r, -r]), size.add([r, r])),
max = this.options.max === undefined ? 1 : this.options.max,
maxZoom = this.options.maxZoom === undefined ? this._map.getMaxZoom() : this.options.maxZoom,
v = 1 / Math.pow(2, Math.max(0, Math.min(maxZoom - this._map.getZoom(), 12))),
cellSize = r / 2,
grid = [],
panePos = this._map._getMapPanePos(),
offsetX = panePos.x % cellSize,
offsetY = panePos.y % cellSize,
i, len, p, cell, x, y, j, len2, k;
for (i = 0, len = this._latlngs.length; i < len; i++) {
p = this._map.latLngToContainerPoint(this._latlngs[i]);
if (bounds.contains(p)) {
x = Math.floor((p.x - offsetX) / cellSize) + 2;
y = Math.floor((p.y - offsetY) / cellSize) + 2;
var alt = this._latlngs[i].alt !== undefined ? this._latlngs[i].alt :
this._latlngs[i][2] !== undefined ? +this._latlngs[i][2] : 1;
k = alt * v;
grid[y] = grid[y] || [];
cell = grid[y][x];
if (!cell) {
grid[y][x] = [p.x, p.y, k];
} else {
cell[0] = (cell[0] * cell[2] + p.x * k) / (cell[2] + k);
cell[1] = (cell[1] * cell[2] + p.y * k) / (cell[2] + k);
cell[2] += k;
}
}
}
for (i = 0, len = grid.length; i < len; i++) {
if (grid[i]) {
for (j = 0, len2 = grid[i].length; j < len2; j++) {
cell = grid[i][j];
if (cell) {
data.push([
Math.round(cell[0]),
Math.round(cell[1]),
Math.min(cell[2], max)
]);
}
}
}
}
this._heat.data(data).draw(this.options.minOpacity);
},
_animateZoom: function (e) {
var scale = this._map.getZoomScale(e.zoom),
offset = this._map._getCenterOffset(e.center)._multiplyBy(-scale).subtract(this._map._getMapPanePos());
if (L.DomUtil.setTransform) {
L.DomUtil.setTransform(this._canvas, offset, scale);
} else {
this._canvas.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(offset) + ' scale(' + scale + ')';
}
}
});
L.heatLayer = function (latlngs, options) {
return new L.HeatLayer(latlngs, options);
};
}());
+27
View File
@@ -0,0 +1,27 @@
{
"name": "INTERCEPT Signal Intelligence",
"short_name": "INTERCEPT",
"description": "Unified SIGINT platform for software-defined radio analysis",
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#0b1118",
"theme_color": "#0b1118",
"icons": [
{
"src": "/static/icons/icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/static/icons/icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "/static/icons/icon.svg",
"sizes": "any",
"type": "image/svg+xml"
}
]
}

Some files were not shown because too many files have changed in this diff Show More