# Civil equipment onboarding and acceptance

## Scope and qualification

Read-only MQTT health ingestion, RTSP stream-health checks, vendor JSON metadata mapping and NMEA receiver fix-health. These are local gateway tools, not certified drivers for every vendor. No video playback, object detection, navigation position output, command publishing, autopilot connection or weapon-control channel. RMC/GGA `ok` means the receiver reported a fix, not verified location accuracy. RTSP `ok` means ffprobe found a video stream, not that every frame or camera sensor is healthy.

Designed for Python 3.8+ on Windows/macOS/Linux; automated checks run on Linux. MQTT uses Paho MQTT 2.1.0; serial uses pySerial 3.5. Their installation does not qualify client hardware. See upstream documentation at https://github.com/eclipse-paho/paho.mqtt.python and https://github.com/pyserial/pyserial . FFmpeg/ffprobe is an external prerequisite for the RTSP probe: https://ffmpeg.org/ . No vendor SDK or ONVIF analytics parser is included.

## 1. Record the client interface

- Equipment model, firmware, vendor interface document version and diagnostic fields.
- Owner-approved host/topic/serial port, network segmentation, certificate issuer and data permissions.
- Expected sample interval, units, time source, maximum acceptable delay and outage threshold.
- Required operating system, Python version, MQTT broker and camera transport support.
- Assign a client equipment owner and an integration tester; keep credentials in local environment variables or the client's secret manager, never in exports or the platform.

## 2. Local installation

Download `civil-protocols.py`, `equipment-health.py`, `requirements-civil.txt`, mappings and samples into the same folder. Use an isolated environment:

```sh
python3 -m venv .venv
# Linux/macOS
.venv/bin/python -m pip install -r requirements-civil.txt
# Windows
.venv\Scripts\python.exe -m pip install -r requirements-civil.txt
```

The examples below use `python3`; replace with your environment's Python executable. Serial-file and JSON metadata modes use only the standard library. Install FFmpeg locally only if using RTSP. No dependency auto-installs, device discovery or automatic deployment occur in the browser.

## 3. MQTT health

```sh
python3 civil-protocols.py mqtt --host broker.client.example --topic civil/lab01/health --config equipment-health.example.json --ca client-ca.pem > health.jsonl
```

Use your real host and one exact diagnostics topic. TLS certificate/hostname checking is enabled; default port 8883. Set `MQTT_USERNAME` and `MQTT_PASSWORD` locally if needed; the adapter never logs them. Give the broker account subscribe-only permission for that topic and deny publish permissions. Wildcards are rejected. Retained messages are ignored; original device timestamps are preserved. Payloads above 128 KiB and invalid rows are rejected without printing source data. QoS 1 may duplicate messages; the platform snapshot replaces records with the same device ID. `--plaintext-local --host 127.0.0.1` is for loopback bench tests only, default port 1883.

The subscriber runs until interrupted, reconnects through Paho's loop, and writes normalized JSONL to stdout. Connection refusal returns exit 2; malformed messages are rejected while the subscriber continues. Broker-side ACLs are required even though this script never publishes.

## 4. RTSP stream health and metadata

Set `RTSP_URL` locally to the owner-approved RTSP/RTSPS endpoint; do not place credentials in the command line or upload them. The value is passed only to local ffprobe. Local privileged users may inspect child process arguments; use an isolated client gateway and preferably credential-free access on a restricted sensor LAN.

```sh
python3 civil-protocols.py rtsp --device CIVIL-CAMERA-01 --timeout 10 > camera-health.jsonl
```

This is a one-shot read-only connection over TCP. Timeout/unavailable/no video produces `warning`; missing prerequisites or invalid output exit 2. The probe returns exit 0 for a valid health record, even if its status is `warning`. It discards imagery, codecs, URLs and ffprobe stderr. Schedule checks using the client's own approved service manager if needed. RTSPS support depends on the camera and installed FFmpeg build; it is not certified here.

For vendor-exported sidecar JSON metadata:

```sh
python3 equipment-health.py --config camera-health.example.json --input camera-health.sample.jsonl > camera-metadata-health.jsonl
```

Customize the mapping to documented vendor fields. This normalizes health only; it does not extract ONVIF XML, RTP metadata, detections, pan/tilt commands or sensor calibration from RTSP.

## 5. NMEA receiver health

```sh
python3 civil-protocols.py nmea --device CIVIL-GNSS-01 --input nmea-health.sample.txt > receiver-health.jsonl
python3 civil-protocols.py nmea --device CIVIL-GNSS-01 --serial /dev/ttyUSB0 --baud 4800 > receiver-health.jsonl
# Windows: --serial COM3; macOS: owner-selected /dev/cu.* port
```

Only checksum-valid RMC/GGA sentences are accepted. Standard two-letter talker IDs are supported. RMC A = ok, V = warning; GGA quality 1–5 = ok, 0/6/7/8 = warning. Coordinates, speed, course and altitude are discarded. Timestamp is local UTC receipt time, not the NMEA date/time; keep the gateway clock synchronized. Other sentence types are rejected, so configure the receiver's diagnostic output accordingly. Nothing is written to serial. Use an appropriate read-only serial tap when DTR/RTS or opening a port can affect a device; OS serial drivers may toggle those lines even without data writes. File mode exit codes: 0 valid, 1 rejected rows, 2 setup failure.

## 6. Platform handoff

Import normalized JSONL through Developer hub → Import health file. The file must contain 1–200 records and be no more than 128 KiB. A continuous log will grow beyond these bounds: select a small recent batch before import. Imports stay in the current browser tab. The platform expires readings after 30 minutes of receipt, but retains source timestamps; check source freshness separately.

Optional HTTPS validation uses the existing client in `/integration/monitoring_client.py` or `/integration/monitoring-client.mjs` with `/api/public/integration/normalize`. It validates caller data and stores nothing. The adapter does not automatically upload, continuously synchronize, or establish a private equipment feed.

## 7. Field acceptance checklist

- [ ] Compare each mapped field and unit with the vendor document and independent bench reading.
- [ ] Confirm serial wiring, baud, checksum, talker IDs and no unintended device actions.
- [ ] Test valid/no-fix NMEA, invalid checksum, simulation mode and unplugged receiver.
- [ ] Test MQTT valid/invalid health, retained messages, duplicate delivery, wrong certificate, rejected credentials, broker restart and denied publish rights.
- [ ] Test camera video, audio-only/no-video response, timeout, disconnect and metadata schema drift.
- [ ] Confirm no credentials, raw imagery, coordinates or extra vendor fields appear in JSONL or error logs.
- [ ] Import a recent real-device batch in Developer hub; confirm ID, status, units, source time and client-reported evidence. Export and read back the snapshot.
- [ ] Measure actual end-to-end delay on the target network and OS; compare with the client's acceptance threshold. No latency guarantee is supplied.
- [ ] Run outage recovery, restart and rollback tests; define who handles warnings and how stale data is identified.
- [ ] Record equipment/firmware versions, test dates, results and owner acceptance before operational use.

## Acceptance record template

Client / equipment owner:
Equipment model / firmware:
Interface document / revision:
Gateway OS / Python / dependencies:
Mapped fields / units / time source:
Expected interval / freshness / delay threshold:
Bench tests / observed delay / outage behavior:
Security and credential handling checked by:
Remaining failures / restrictions:
Approved read-only deployment scope / date:

Client equipment, credentials, network access and interface documentation are still required for real-device qualification. Passing synthetic or local protocol checks alone is not field acceptance.