Metadata-Version: 2.4
Name: mist-client
Version: 0.1.0
Summary: CLI tool for downloading telemetry from MIST Yamcs mission control system
Author: MIST Team
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: yamcs-client>=1.12.1
Requires-Dist: click>=8.0
Requires-Dist: python-dateutil>=2.8
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"

# MIST CLI

CLI tool for downloading telemetry from MIST Yamcs mission control system.

## Features

- Download telemetry packets from Yamcs by packet name and time range
- Support for defragmented telemetry blocks (complete and incomplete)
- Strips PUS TM headers (14 bytes)
- Both CLI and library interfaces
- Hole filling for incomplete defragmented blocks

## Installation

### From PyPI (Recommended)

```bash
# Install the package
pip install mist-client

# Or create a virtual environment first (recommended)
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install mist-client
```

### From Source

It's recommended to use a virtual environment to avoid conflicts with system packages:

```bash
# Navigate to the cli directory
cd yamcs/cli

# Create a virtual environment
python3 -m venv venv

# Activate the virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate

# Install the package
pip install -e ".[dev]"
```

## Quick Start

### Command Line Usage

```bash
# List available telemetry packet formats
mist-cli tm list

# Download housekeeping telemetry from the last hour
mist-cli tm get -p "/PUS/HOUSEKEEPING" -f /tmp/telemetry

# Download with specific time range
mist-cli tm get -p "/PUS/TC_VERIFICATION" \
  -a "2026-03-26T00:00:00" \
  -b "2026-03-27T00:00:00" \
  -f ./output

# Download defragmented telemetry (all blocks including incomplete)
mist-cli tm get -p "/PUS/Large_Data" --defrag all -f ./fragments

# Show help
mist-cli --help
mist-cli tm get --help
```

### Library Usage

```python
from mist_client import TelemetryDownloader
from datetime import datetime, timedelta, timezone

# Create downloader
td = TelemetryDownloader(url="localhost:8090", instance="mist")

# Download telemetry
now = datetime.now(tz=timezone.utc)
start = now - timedelta(hours=1)

telemetries = td.get_telemetry(
    packet_name="/PUS/HOUSEKEEPING",
    start=start,
    stop=now
)

# Process in memory
for tm in telemetries:
    print(f"APID={tm.apid}, packet={tm.packet_name}")
    print(f"Data length: {len(tm.data)} bytes")
    print(f"Complete: {tm.is_complete()}")
```

## Library API Reference

### `TelemetryDownloader`

Main class for downloading telemetry.

```python
TelemetryDownloader(url: str = "localhost:8090", instance: Optional[str] = None)
```

**Methods:**

#### `get_telemetry(packet_name, start, stop, defrag=None) -> List[Telemetry]`

Retrieve telemetry packets from Yamcs.

**Parameters:**
- `packet_name` (str): Yamcs packet name
- `start` (datetime, optional): Start time (inclusive)
- `stop` (datetime, optional): Stop time (exclusive)
- `defrag` (str, optional): `"complete"`, `"all"`, or `None`

**Returns:** List of `Telemetry` objects

### `Telemetry`

Dataclass representing a telemetry packet or defragmented block.

**Attributes:**
- `apid` (int): Application Process ID
- `packet_name` (str): Yamcs packet name (e.g., "/PUS/HOUSEKEEPING")
- `time` (datetime): Generation timestamp
- `data` (bytes): Source data (headers stripped)
- `holes` (List[Tuple[int, int]]): Missing byte ranges (empty if complete)

**Methods:**
- `is_complete() -> bool`: Check if telemetry has no missing fragments

## Running Tests

```bash
pytest
```

## Troubleshooting

### "Could not connect to Yamcs"

- Verify Yamcs is running: Check `http://localhost:8090/` in a browser
- Check the URL: Use `--url` to specify the correct server
- Check the instance: Use `--instance` or set `YAMCS_INSTANCE`

### "No telemetry found"

- Verify the packet name exists in Yamcs MDB
- Check the time range includes actual telemetry data
- Use the Yamcs web interface to verify data availability

### Import errors

- Make sure you installed the package: `pip install -e .`
- Check Python version: Requires Python 3.8+
