# SatMaster — F4BPO Satellite Tracker

Amateur satellite tracking application with Doppler correction for FlexRadio 8600 and rotor control via PstRotator.

**Stack:** Go + Wails v2 + Svelte  
**Platform:** Windows (primary), Linux/macOS (compilable)

---

## Features

- 🗺️ **World map** — real-time satellite positions on NASA GIBS Blue Marble, footprint + groundtrack overlay, satellite SVG icon for tracked sat
- 📡 **Polar plot** — az/el pass track with AOS/LOS markers, current position animation
- 🕐 **Pass prediction** — 24h upcoming passes, Max El, duration, quality rating, single sat or full watchlist view
- 📻 **Doppler correction** — automatic TX/RX frequency correction via FlexRadio 8600 TCP API, configurable RX/TX slices
- 🔄 **Rotor control** — Az/El or Az-only commands to PstRotator via UDP XML protocol
- 🛰️ **TLE management** — parallel fetch from Celestrak + PE0SAT, merged with deduplication, local cache fallback
- 🔊 **AOS voice alerts** — Windows TTS announcement at AOS for all watchlist satellites, configurable voice
- 📋 **Satellite frequency database** — 40+ satellites with nominal frequencies, auto-applied on selection
- 🔍 **Watchlist** — persistent satellite selection with alphabetical sorting and duplicate prevention

---

## Architecture

```
SatMaster/
├── main.go                    # Wails entry point
├── app.go                     # App struct, Wails bindings, position loop, tracking
├── wails.json                 # Wails project config
│
├── backend/
│   ├── tle/
│   │   └── manager.go         # Parallel TLE fetch (Celestrak + PE0SAT), merge, cache, parse
│   │
│   ├── propagator/
│   │   └── engine.go          # SGP4 propagation (akhenakh/sgp4), az/el, pass prediction
│   │
│   ├── doppler/
│   │   └── calculator.go      # Doppler shift computation (range rate → Hz correction)
│   │
│   ├── flexradio/
│   │   └── client.go          # FlexRadio SmartSDR TCP API (port 4992)
│   │
│   └── rotor/
│       └── pstrotator.go      # PstRotator UDP XML protocol (port 12000)
│
└── frontend/src/
    ├── App.svelte              # Root layout, Wails events, AOS voice alert engine
    ├── stores/satstore.js      # Svelte stores + localStorage persistence
    ├── lib/
    │   ├── wails.js            # Wails Go call bridge + dev stubs
    │   ├── utils.js            # Formatting helpers (freq, az, el, range, etc.)
    │   ├── satdb.js            # Satellite frequency database (40+ sats)
    │   └── maidenhead.js       # Maidenhead locator ↔ lat/lon conversion
    └── components/
        ├── StatusBar.svelte    # Top bar: clock, sat data, Doppler, SOUND/DOPPLER/ROTATOR toggles
        ├── SatSelector.svelte  # Left sidebar: watchlist, frequencies, track toggles, sat info
        ├── WorldMap.svelte     # Leaflet map, sat markers, SVG icon, footprint, groundtrack
        ├── PolarPlot.svelte    # SVG polar az/el plot
        ├── PassesPanel.svelte  # Pass list + detail + embedded polar plot
        └── SettingsPanel.svelte # QTH, FlexRadio, PstRotator, slices, voice alerts, TLE
```

---

## Prerequisites

```bash
# Go 1.21+
# Node.js 18+
# Wails v2
go install github.com/wailsapp/wails/v2/cmd/wails@latest

# Verify
wails doctor
```

---

## Setup & Build

```bash
# 1. Clone / copy project
cd SatMaster

# 2. Download Go dependencies
go mod tidy

# 3. Install frontend deps
cd frontend && npm install && cd ..

# 4. Development mode (hot reload)
wails dev

# 5. Production build (single .exe)
wails build
# → build/bin/SatMaster.exe
```

---

## FlexRadio 8600 — Protocol Notes

SatMaster uses the SmartSDR **TCP API** on port **4992**.

Commands sent:
```
slice t 0 145.800000    # Set RX slice frequency (MHz)
slice t 1 145.200000    # Set TX slice frequency (MHz)
slice s 0 mode=FM       # Set slice mode
```

- Connect: Settings → FlexRadio → enter IP → Connect
- RX slice (downlink) defaults to Slice A (index 0), TX to Slice B (index 1)
- Configurable in Settings → FlexRadio → Satellite Slices
- Doppler correction fires every second during active tracking
- Dead-band: 1 Hz — updates only sent when shift exceeds threshold
- Track Freq/Mode button is disabled if satellite has no known frequencies

---

## PstRotator — Protocol Notes

SatMaster sends **UDP XML** to PstRotator on port **12000** (default).

```xml
<PST><AZIMUTH>180</AZIMUTH></PST>
<PST><AZIMUTH>180</AZIMUTH><ELEVATION>45</ELEVATION></PST>
```

- Configure in PstRotator: Setup → UDP Server → Port 12000
- Az-only or Az+El mode configurable in Settings → PstRotator → Rotor Mode
- Dead-band: 5° Az and El to prevent rotor hunting
- Elevation clamped to [0°, 90°] — no negative elevation commands sent
- `ResetDeadband()` called when Track Azimuth is enabled to force immediate move

---

## TLE Data

- **Primary source:** `https://celestrak.org/NORAD/elements/gp.php?GROUP=amateur&FORMAT=tle`
- **Secondary source:** `http://tle.pe0sat.nl/kepler/amateur.txt`
- Both sources fetched **in parallel** and merged — Celestrak takes priority on duplicates, PE0SAT contributes satellites not present in Celestrak
- **Cache:** `%LOCALAPPDATA%\SatMaster\satmaster_tle_cache.txt` (Windows)
- **Bundled fallback:** ISS, AO-7, AO-27, SO-50, FO-29, RS-44 (always available offline)
- TLE age shown in status bar; use Settings → TLE Data → Refresh TLE to force update

---

## Pass Prediction

- Step: 10s (30s when satellite below -15° elevation)
- AOS/LOS bisection precision: 1 second
- Horizon: passes below configured Min El are filtered from the list
- 24-hour prediction window
- Passes panel: single satellite view or full watchlist view

---

## Doppler Formula

```
f_corrected_down = f_nominal × (1 - v_range / c)
f_corrected_up   = f_nominal / (1 - v_range / c)

where:
  v_range = range rate in km/s (+ = receding, - = approaching)
  c       = 299792.458 km/s
```

Range rate is computed by finite difference (2-second interval) on the SGP4 position.

---

## AOS Voice Alerts

SatMaster announces AOS for all watchlist satellites using Windows TTS (Web Speech API).

- Announcement format: *"AOS [satellite name] is rising. Pass will last for X minutes."*
- Toggle: StatusBar → 🔊 SOUND ON/OFF
- Voice selection: Settings → Voice Alerts → TTS Voice dropdown
- Recommended voices: **Microsoft David** or **Microsoft Zira** (English)
- To install English voices: Windows Settings → Time & Language → Speech → Add voices → English (United States)

---

## Keyboard Shortcuts

| Key | Action |
|-----|--------|
| `M` | Switch to Map tab |
| `P` | Switch to Passes tab |
| `S` | Switch to Settings tab |

---

## Satellite Frequency Database

Built-in frequency database (`frontend/src/lib/satdb.js`) covers 40+ satellites including:

| Satellite | Type | Downlink | Uplink |
|-----------|------|----------|--------|
| ISS | FM | 145.800 MHz | 437.800 MHz |
| SO-50 | FM | 436.795 MHz | 145.850 MHz |
| AO-91 | FM | 145.960 MHz | 435.250 MHz |
| RS-44 | Linear | 435.640 MHz | 145.965 MHz |
| AO-73 | Linear | 145.960 MHz | 435.140 MHz |
| FO-29 | Linear | 435.850 MHz | 145.950 MHz |
| QO-100 | Linear | 10489.750 MHz | 2400.250 MHz |
| TEVEL2-1…9 | FM | 436.400 MHz | 145.970 MHz |
| … | … | … | … |

Frequencies are auto-applied when a satellite is selected. Multiple frequency entries per satellite are supported (e.g. ISS has FM voice + APRS).

---

## Future Enhancements

- [ ] Multiple satellite tracking (split-screen polar)
- [ ] Audio squelch mute between passes
- [ ] Log4OM integration for contact logging
- [ ] Export pass schedule to CSV/PDF
- [ ] Linux/macOS rotor backend