# Sensor Emulator

Standalone Synapse-compatible emulators for:
- Radar TCP control/data protocol
- MAVLink telemetry stream
- LiDAR collector subprocess contract

## Why this exists

`synapse` expects real hardware and device access. This repo emulates the same interfaces so development and CI can run without hardware.

## Install

```bash
cd sensor-emulator
python3 -m venv .venv
source .venv/bin/activate
pip install -e .[test]
```

## Run emulators

Radar only:

```bash
sensor-emulator radar --host 127.0.0.1 --ctrl-port 8100 --data-port 8101
```

MAVLink only:

```bash
sensor-emulator mavlink --host 127.0.0.1 --port 14550 --stream-hz 10
```

Radar + MAVLink:

```bash
sensor-emulator all --host 127.0.0.1 --ctrl-port 8100 --data-port 8101 --mavlink-port 14550
```

LiDAR collector mode (drop-in for `LidarRunner` subprocess):

```bash
export POINT_CLOUD_CSV_PATH=/tmp/lidar_point_cloud.csv
export IMU_DATA_CSV_PATH=/tmp/lidar_imu_data.csv
sensor-lidar-collector dummy-config-path
```

## Synapse wiring

For Synapse LiDAR:

```bash
export LIDAR_EXEC_PATH=$(which python3)
export LIDAR_CONFIG_PATH=/absolute/path/to/sensor-emulator/src/sensor_emulator/lidar_collector.py
```

For Synapse radar, set `RADAR_CONFIG_PATH` to a config like:

```json
{
  "ip": "127.0.0.1",
  "ctrlPort": 8100,
  "dataPort": 8101,
  "nSamples": 511,
  "headerFields": 16,
  "sampleBytes": 4,
  "timeout": 1.0
}
```

For Synapse MAVLink:

Use `getMavlinkController(port=\"udpin:127.0.0.1:14550\", ...)` in local tests.

## Test suite

Run all tests:

```bash
pytest -q
```

Coverage intent:
- Radar command compatibility (`STA?`, `IRF1`, `FMT?`, `#IRF`, `RUN `, `STOP`)
- Radar frame binary layout + CSV generation through Synapse `RadarController`
- MAVLink heartbeat and required message set + Synapse `MavlinkController` CSV output
- LiDAR subprocess env contract + Synapse `LidarRunner` CSV output
