# SA1 architecture :id=top

------

> _Doc Ver:_ 1.2  
_App Ver:_ 2.6.6.53  
_Date:_ 09/14/2026

------

**SA1 2.x** is the field demodulator stack: **sa-di** + **sa-web** + **csdfu**. Display and control are Web only. This is **not** SA2 / 3.x (`sa_daq` + `sa_web` + `sa_broker` + `sa_run`).

SA1 and SA2 are **mutually exclusive**. They both use demodulator UDP **8190** and 7090 / 7094 / 80 / 8080 / 81. Run only one stack on a machine.

Detail (ports, persist, HTTP ops): [Architecture (detail)](architecture_v2.md). Field cookbook: [Start, check, upgrade](operate.md). Ops trio: [Ops tools](ops.md).

------

## 1. Overview :id=overview

<img src="_images/architecture-flow.png" alt="SA1 control and data flow" width="100%">

```text
demodulator UDP 8190 ──► sa-di
                            ▲
                            │ loopback 7090 / 7094 / 7082
browser ──HTTP 80/8080/81──► sa-web ── /ws ──► sa-di
sa-doctor / sa-cli / sa-mcp ──HTTP only──► sa-web
Modbus master ──TCP 1502──► sa-di (off until Addon Save)
```

## 1.1 System map :id=map

- SA1 device (2.x)
  - Supervised daemons
    - `sa-di` — demodulate, persist, SCPI on 127.0.0.1:7090 / :7094
    - `sa-web` — `/login`, pages, `/ws`, `/api/*`
    - `csdfu` — data file upload, Web `:8787`
  - Init
    - Debian: `sa-di.service` + `sa-web.service` + `csdfu.service`
    - BusyBox: `/etc/init.d/sa1` → `sa1-supervise` (not 3.x `sa_run`)
  - Package CLI (not supervise)
    - `sa-doctor` — read-only checkup
    - `sa-cli` — small HTTP CLI
    - `sa-mcp` — stdio MCP for agents
    - `sa-file` — on-box CSV (`wl` / `pv` / `raw`)
  - Install
    - `sa1-upgrader` in `/usr/local/bin`
    - portal `sa1/install/` · cspkg engine `sa1_upgrader`
    - handbook `sa1/help/` (this tree)
- Protocols
  - Browser: HTTP 80 / 8080 / 81 and `/ws` only
  - Interrogator: UDP **8190** (mutex with SA2)
  - Loopback only: TCP 7090 / 7094, optional UDP 7082
  - Optional LAN: TCP **1502** Modbus TCP slave (**off** until Addon Save). [Handbook](modbus_tcp_slave.md)
- Runtime
  - `/home/debian/sa1` → `releases/` `current` `persist/{conf,data,log}`
  - `/var/sa` and `/home/debian/sa` → `current`

This is not SA2: no `sa_broker`, EMQX, Influx, `sa_run`, `sa_tui`, `sax`, or cluster `sa_control`.

------

## 2. Programs :id=programs

| Program | Role | Docs |
|---------|------|------|
| **sa-di** | Demodulate, persist, SCPI on **127.0.0.1:7090**, optional Modbus TCP **1502**; idle `*rst!;` after IP lock | [API](api.md) · [Modbus](modbus_tcp_slave.md) · [Device reset](device-rst.md) |
| **sa-web** | Pages, `/login`, `/ws`, `/api/*` | this Handbook |
| **csdfu** | Off-box file send, Web **`:8787`** | [Data file upload](dtfu.md) |
| **sa-file** | On-box CSV (`wl` / `pv` / `raw`), no port | [Data save](data_save.md) · [Save protocol](data-save-proto.md) |
| **sa-doctor** | Read-only checkup | [sa-doctor](sa-doctor.md) |
| **sa-cli** | Small HTTP CLI | [sa-cli](sa-cli.md) |
| **sa-mcp** | stdio MCP for agents | [sa-mcp](sa-mcp.md) |
| **sa1-upgrader** | Install / upgrade / rollback (`/usr/local/bin`) | [Upgrade](upgrade.md) |

**In systemd / `sa1-supervise`:** `sa-di`, `sa-web`, and `csdfu`.  
**Not daemons:** sa-doctor, sa-cli, sa-mcp, sa1-upgrader.

Not in SA1: MQTT `sa_broker`, `sa_run`, `sa_control`, `sa_tui`, `sax`, GTK, shared memory.

------

## 3. Runtime layout :id=layout

<img src="_images/architecture-runtime.png" alt="SA1 runtime tree" width="100%">

| Path | Meaning |
|------|---------|
| `/home/debian/sa1` | Root: `releases/<ver>`, `current`, `previous`, `persist/{conf,data,log}` |
| `/var/sa` | Compatibility symlink to `current` |
| `/home/debian/sa` | Same symlink |
| `/var/sa/bin` | `sa-di` `sa-web` `csdfu` `sa-file` `sa-doctor` `sa-cli` `sa-mcp` |
| `/usr/local/bin/sa1-upgrader` | Not replaced by the business tar |

Processes read **`/var/sa`**, not the git tree. After editing `web/` in source, copy with `scripts/sync-runtime.sh --web`. Do not rsync `conf/` onto persist.

On-disk `persist/data/wl` and `pv` default to original (`0x00` / `0x04`/`0x05`). Data save **1.11** (`DS_SAVE_PROTO=1`) writes SA2 v1.7 (`0x10` / `0x15`). Live UDP **8190**, `:DATA:RAW?`, and Modbus **1502** stay original. [Save protocol and integration](data-save-proto.md).

------

## 4. Ports :id=ports

| Port | Who | Notes |
|------|-----|--------|
| HTTP **80 / 8080 / 81** | sa-web | If 80 is taken, 8080 or 81 still count as `/login` |
| HTTP **8787** | csdfu | Signed-in `/csdfu` redirects here |
| TCP **7090** | sa-di command | **127.0.0.1 only** |
| TCP **7094** | sa-di spectrum | **127.0.0.1 only**; browser uses `/ws` |
| UDP **7000** | sa-di → LAN | Discovery. `Port` is the web UI port, default 80. See [LAN discovery](discovery.md) |
| UDP **8190** | interrogator → sa-di | Mutex with SA2. Idle reset after IP lock: [Device reset watchdog](device-rst.md) |
| UDP **8193** | sa-di → interrogator command | Device receive port; idle Watchdog unicasts `*rst!;` to the locked **dataIp** |
| UDP **7082** | optional PV text | loopback |
| TCP **1502** | sa-di Modbus TCP slave | **Off by default**; Addon → Modbus Configure then `:SYS:RELOAD`. See [Modbus TCP slave](modbus_tcp_slave.md) |

------

## 5. Check :id=check

On the device:

```bash
sa-doctor
sa-doctor --json
```

Expect exactly one `sa-di`, one `sa-web`, and one `csdfu` (missing csdfu is warn), no SA2 processes, `/login` open, `*IDN?` non-empty. Full page: [Start, check, upgrade](operate.md).

------

### [Top](#top)
