# 4. Sensor & Data Acquisition

## Overview
Reliable data acquisition is the core of the ASF system. The strategy focuses on abstraction, redundancy, and data validation to ensure that the system operates on accurate information.

## Sensor Abstraction Layer (SAL)
To ensure long-term maintainability and the ability to swap hardware components, a Sensor Abstraction Layer is implemented. Every sensor driver must implement the following interface:

*   `sensor_read()`: Retrieve the latest value.
*   `sensor_calibrate()`: Perform sensor-specific calibration.
*   `sensor_validate()`: Check if the reading is within physical bounds.
*   `sensor_health_check()`: Verify the operational status of the hardware.

## Industrial Sensor Strategy
For critical parameters, a primary and backup sensor strategy is employed, often using different technologies or interfaces to avoid common-mode failures.

### Example: CO₂ Monitoring
| Feature | Primary Sensor | Backup Sensor |
| :--- | :--- | :--- |
| **Model** | Sensirion SCD41 | Senseair S8 |
| **Interface** | I²C | UART |
| **Calibration** | Self-calibration | Manual calibration |

**Rule:** Every critical parameter must have two qualified sensor options.

## Warm-Up & Validity States
Sensors do not provide valid data immediately upon power-up. The system explicitly tracks sensor states:

> **INIT** → **WARMUP** → **STABLE** → **DEGRADED** → **FAILED**

Raw values are never published without an accompanying **validity flag** indicating the current state.

## Data Filtering
To ensure data stability without excessive complexity, a simple and robust filtering approach is used:

1.  **Median Filter (N=5):** Removes outliers and transient noise.
2.  **Rate-of-Change Limiter:** Prevents physically impossible jumps in values.
3.  **Physical Bounds Check:** Rejects readings that are outside the sensor's or environment's possible range.

This approach provides high reliability without the overhead of complex algorithms like Kalman filters.
