cleanup sw req
This commit is contained in:
727
1 software design/components/sensor_manager/COMPONENT.md
Normal file
727
1 software design/components/sensor_manager/COMPONENT.md
Normal file
@@ -0,0 +1,727 @@
|
||||
# Sensor Manager Component Specification
|
||||
|
||||
**Component ID:** C-SENSOR-001
|
||||
**Version:** 1.0
|
||||
**Date:** 2025-02-01
|
||||
**Location:** `application_layer/business_stack/sensor_manager/`
|
||||
|
||||
## 1. Component Overview and Scope
|
||||
|
||||
The Sensor Manager component coordinates all sensor-related operations including lifecycle management, data acquisition scheduling, high-frequency sampling, local filtering, and sensor state management. It serves as the central coordinator for the Sensor Data Acquisition feature (F-DAQ).
|
||||
|
||||
**Primary Purpose:** Provide centralized sensor lifecycle management and data acquisition coordination for environmental sensors.
|
||||
|
||||
**Scope:** Multi-sensor data acquisition, sensor state management, high-frequency sampling, local filtering, and sensor fault detection.
|
||||
|
||||
## 2. Responsibilities and Functions
|
||||
|
||||
### 2.1 Primary Responsibilities
|
||||
|
||||
- **Sensor Lifecycle Management:** Detection, initialization, configuration, and teardown of all sensor types
|
||||
- **Data Acquisition Coordination:** Scheduling and executing 1-second sensor sampling cycles
|
||||
- **High-Frequency Sampling:** Multiple samples per sensor per cycle (default: 10 samples)
|
||||
- **Local Data Filtering:** Apply configurable filters (median, moving average, rate-of-change limiter)
|
||||
- **Sensor State Management:** Track and manage sensor operational states and transitions
|
||||
- **Data Record Generation:** Create timestamped sensor data records with validity status
|
||||
- **Event Publication:** Publish sensor data updates and state changes via Event System
|
||||
- **Sensor Fault Detection:** Detect and report sensor communication failures and out-of-range values
|
||||
|
||||
### 2.2 Non-Responsibilities
|
||||
|
||||
- **Hardware Access:** Delegates to sensor drivers (no direct I2C/SPI/UART access)
|
||||
- **Data Persistence:** Delegates to Data Persistence component
|
||||
- **Communication:** Delegates to Communication components
|
||||
- **Time Management:** Uses Time Utils for timestamp generation
|
||||
- **Fault Classification:** Uses Error Handler for fault reporting and escalation
|
||||
|
||||
## 3. Provided Interfaces
|
||||
|
||||
### 3.1 Initialization and Configuration Interface
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief Initialize Sensor Manager component
|
||||
* @return true if initialization successful, false otherwise
|
||||
*/
|
||||
bool sensorMgr_initialize(void);
|
||||
|
||||
/**
|
||||
* @brief Load sensor configuration from Machine Constants
|
||||
* @param mc Machine constants structure
|
||||
* @return true if configuration loaded, false on error
|
||||
*/
|
||||
bool sensorMgr_loadConfiguration(const machine_constants_t* mc);
|
||||
|
||||
/**
|
||||
* @brief Detect all connected sensors
|
||||
* @return Number of sensors detected
|
||||
*/
|
||||
uint8_t sensorMgr_detectSensors(void);
|
||||
|
||||
/**
|
||||
* @brief Shutdown Sensor Manager (cleanup resources)
|
||||
* @return true if shutdown successful, false otherwise
|
||||
*/
|
||||
bool sensorMgr_shutdown(void);
|
||||
```
|
||||
|
||||
### 3.2 Acquisition Control Interface
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief Start sensor data acquisition
|
||||
* @return true if acquisition started, false on error
|
||||
*/
|
||||
bool sensorMgr_startAcquisition(void);
|
||||
|
||||
/**
|
||||
* @brief Stop sensor data acquisition
|
||||
* @return true if acquisition stopped, false on error
|
||||
*/
|
||||
bool sensorMgr_stopAcquisition(void);
|
||||
|
||||
/**
|
||||
* @brief Pause sensor data acquisition
|
||||
* @return true if acquisition paused, false on error
|
||||
*/
|
||||
bool sensorMgr_pauseAcquisition(void);
|
||||
|
||||
/**
|
||||
* @brief Resume sensor data acquisition
|
||||
* @return true if acquisition resumed, false on error
|
||||
*/
|
||||
bool sensorMgr_resumeAcquisition(void);
|
||||
|
||||
/**
|
||||
* @brief Check if acquisition is active
|
||||
* @return true if acquisition is running, false otherwise
|
||||
*/
|
||||
bool sensorMgr_isAcquisitionActive(void);
|
||||
```
|
||||
|
||||
### 3.3 Sensor Control Interface
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief Enable a specific sensor
|
||||
* @param sensor_id Sensor identifier (0-6)
|
||||
* @return true if sensor enabled, false on error
|
||||
*/
|
||||
bool sensorMgr_enableSensor(uint8_t sensor_id);
|
||||
|
||||
/**
|
||||
* @brief Disable a specific sensor
|
||||
* @param sensor_id Sensor identifier (0-6)
|
||||
* @return true if sensor disabled, false on error
|
||||
*/
|
||||
bool sensorMgr_disableSensor(uint8_t sensor_id);
|
||||
|
||||
/**
|
||||
* @brief Configure sensor parameters
|
||||
* @param sensor_id Sensor identifier
|
||||
* @param config Sensor configuration structure
|
||||
* @return true if configuration applied, false on error
|
||||
*/
|
||||
bool sensorMgr_configureSensor(uint8_t sensor_id, const sensor_config_t* config);
|
||||
|
||||
/**
|
||||
* @brief Recalibrate a sensor
|
||||
* @param sensor_id Sensor identifier
|
||||
* @param calibration_data Calibration parameters
|
||||
* @return true if calibration applied, false on error
|
||||
*/
|
||||
bool sensorMgr_calibrateSensor(uint8_t sensor_id, const sensor_calibration_t* calibration_data);
|
||||
```
|
||||
|
||||
### 3.4 Data Access Interface
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief Get latest data from a specific sensor
|
||||
* @param sensor_id Sensor identifier
|
||||
* @param record Output buffer for sensor data record
|
||||
* @return true if data retrieved, false on error
|
||||
*/
|
||||
bool sensorMgr_getLatestData(uint8_t sensor_id, sensor_data_record_t* record);
|
||||
|
||||
/**
|
||||
* @brief Get latest data from all sensors
|
||||
* @param records Output buffer for sensor data records
|
||||
* @param count Input: buffer size, Output: number of records filled
|
||||
* @return true if data retrieved, false on error
|
||||
*/
|
||||
bool sensorMgr_getAllSensorData(sensor_data_record_t* records, size_t* count);
|
||||
|
||||
/**
|
||||
* @brief Get sensor data with history (last N samples)
|
||||
* @param sensor_id Sensor identifier
|
||||
* @param records Output buffer for historical records
|
||||
* @param count Input: requested count, Output: actual count returned
|
||||
* @return true if data retrieved, false on error
|
||||
*/
|
||||
bool sensorMgr_getSensorHistory(uint8_t sensor_id, sensor_data_record_t* records, size_t* count);
|
||||
```
|
||||
|
||||
### 3.5 State Management Interface
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief Get sensor operational state
|
||||
* @param sensor_id Sensor identifier
|
||||
* @return Current sensor state
|
||||
*/
|
||||
sensor_state_t sensorMgr_getSensorState(uint8_t sensor_id);
|
||||
|
||||
/**
|
||||
* @brief Check if sensor is present (detected)
|
||||
* @param sensor_id Sensor identifier
|
||||
* @return true if sensor is present, false otherwise
|
||||
*/
|
||||
bool sensorMgr_isSensorPresent(uint8_t sensor_id);
|
||||
|
||||
/**
|
||||
* @brief Check if sensor is enabled for acquisition
|
||||
* @param sensor_id Sensor identifier
|
||||
* @return true if sensor is enabled, false otherwise
|
||||
*/
|
||||
bool sensorMgr_isSensorEnabled(uint8_t sensor_id);
|
||||
|
||||
/**
|
||||
* @brief Check if sensor is healthy (no faults)
|
||||
* @param sensor_id Sensor identifier
|
||||
* @return true if sensor is healthy, false if faulty
|
||||
*/
|
||||
bool sensorMgr_isSensorHealthy(uint8_t sensor_id);
|
||||
|
||||
/**
|
||||
* @brief Get sensor information
|
||||
* @param sensor_id Sensor identifier
|
||||
* @param info Output buffer for sensor information
|
||||
* @return true if information retrieved, false on error
|
||||
*/
|
||||
bool sensorMgr_getSensorInfo(uint8_t sensor_id, sensor_info_t* info);
|
||||
```
|
||||
|
||||
### 3.6 Statistics and Diagnostics Interface
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief Get sensor acquisition statistics
|
||||
* @param sensor_id Sensor identifier
|
||||
* @param stats Output buffer for statistics
|
||||
* @return true if statistics retrieved, false on error
|
||||
*/
|
||||
bool sensorMgr_getSensorStatistics(uint8_t sensor_id, sensor_stats_t* stats);
|
||||
|
||||
/**
|
||||
* @brief Reset sensor statistics
|
||||
* @param sensor_id Sensor identifier (SENSOR_ID_ALL for all sensors)
|
||||
* @return true if statistics reset, false on error
|
||||
*/
|
||||
bool sensorMgr_resetSensorStatistics(uint8_t sensor_id);
|
||||
|
||||
/**
|
||||
* @brief Get overall acquisition performance metrics
|
||||
* @param metrics Output buffer for performance metrics
|
||||
* @return true if metrics retrieved, false on error
|
||||
*/
|
||||
bool sensorMgr_getPerformanceMetrics(acquisition_metrics_t* metrics);
|
||||
```
|
||||
|
||||
## 4. Required Interfaces
|
||||
|
||||
### 4.1 Sensor Driver Interfaces
|
||||
|
||||
- **Interface:** Sensor hardware abstraction layer
|
||||
- **Providers:** Temperature, Humidity, CO2, NH3, VOC, PM, Light sensor drivers
|
||||
- **Usage:** Hardware-specific sensor communication and data reading
|
||||
- **Data Types:** `sensor_driver_t`, `sensor_reading_t`
|
||||
|
||||
### 4.2 Event System Interface
|
||||
|
||||
- **Interface:** Event publishing and subscription
|
||||
- **Provider:** Event System component
|
||||
- **Usage:** Publish sensor data updates and state changes
|
||||
- **Data Types:** `event_type_t`, `sensor_data_event_t`
|
||||
|
||||
### 4.3 Time Utils Interface
|
||||
|
||||
- **Interface:** Timestamp generation
|
||||
- **Provider:** Time Utils component
|
||||
- **Usage:** Generate timestamps for sensor data records
|
||||
- **Data Types:** `uint64_t` timestamp in milliseconds
|
||||
|
||||
### 4.4 Machine Constants Manager Interface
|
||||
|
||||
- **Interface:** Configuration data access
|
||||
- **Provider:** Machine Constants Manager component
|
||||
- **Usage:** Load sensor configuration and calibration parameters
|
||||
- **Data Types:** `machine_constants_t`, `sensor_config_t`
|
||||
|
||||
### 4.5 Error Handler Interface
|
||||
|
||||
- **Interface:** Fault reporting
|
||||
- **Provider:** Error Handler component
|
||||
- **Usage:** Report sensor faults and failures
|
||||
- **Data Types:** `fault_severity_t`, `sensor_fault_info_t`
|
||||
|
||||
### 4.6 Logger Interface
|
||||
|
||||
- **Interface:** Diagnostic logging
|
||||
- **Provider:** Logger component
|
||||
- **Usage:** Log sensor operations and diagnostics
|
||||
- **Data Types:** Log levels, message strings
|
||||
|
||||
## 5. External Interfaces
|
||||
|
||||
### 5.1 Environmental Sensors Interface
|
||||
|
||||
- **Interface:** Physical sensor hardware
|
||||
- **Consumers:** Sensor drivers
|
||||
- **Usage:** Read environmental data (temperature, humidity, CO2, etc.)
|
||||
- **Protocols:** I2C, SPI, UART, Analog
|
||||
|
||||
## 6. Internal Interfaces
|
||||
|
||||
### 6.1 Acquisition Scheduler Interface
|
||||
|
||||
- **Interface:** Internal acquisition timing control
|
||||
- **Usage:** Schedule and coordinate sensor sampling cycles
|
||||
- **Implementation:** Private to Sensor Manager
|
||||
|
||||
### 6.2 Filter Engine Interface
|
||||
|
||||
- **Interface:** Internal data filtering
|
||||
- **Usage:** Apply configurable filters to raw sensor data
|
||||
- **Implementation:** Private to Sensor Manager
|
||||
|
||||
### 6.3 State Machine Interface
|
||||
|
||||
- **Interface:** Internal sensor state management
|
||||
- **Usage:** Manage sensor state transitions
|
||||
- **Implementation:** Private to Sensor Manager
|
||||
|
||||
## 7. Static View
|
||||
|
||||
### 7.1 Component Structure
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph SensorManager["Sensor Manager"]
|
||||
AcqScheduler[Acquisition Scheduler]
|
||||
SensorStateMgr[Sensor State Manager]
|
||||
FilterEngine[Filter Engine]
|
||||
DataRecordGen[Data Record Generator]
|
||||
FaultDetector[Fault Detector]
|
||||
end
|
||||
|
||||
subgraph SensorDrivers["Sensor Drivers"]
|
||||
TempDriver[Temperature Driver]
|
||||
HumidityDriver[Humidity Driver]
|
||||
CO2Driver[CO2 Driver]
|
||||
NH3Driver[NH3 Driver]
|
||||
VOCDriver[VOC Driver]
|
||||
PMDriver[PM Driver]
|
||||
LightDriver[Light Driver]
|
||||
end
|
||||
|
||||
subgraph External["External Components"]
|
||||
EventSys[Event System]
|
||||
TimeUtils[Time Utils]
|
||||
MCMgr[MC Manager]
|
||||
ErrorHandler[Error Handler]
|
||||
Logger[Logger]
|
||||
end
|
||||
|
||||
AcqScheduler --> SensorDrivers
|
||||
AcqScheduler --> FilterEngine
|
||||
FilterEngine --> DataRecordGen
|
||||
DataRecordGen --> TimeUtils
|
||||
DataRecordGen --> EventSys
|
||||
SensorStateMgr --> EventSys
|
||||
FaultDetector --> ErrorHandler
|
||||
SensorManager --> MCMgr
|
||||
SensorManager --> Logger
|
||||
```
|
||||
|
||||
### 7.2 Sensor Type Mapping
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
subgraph PhysicalSlots["Physical Sensor Slots"]
|
||||
Slot0[Slot 0<br/>Temperature]
|
||||
Slot1[Slot 1<br/>Humidity]
|
||||
Slot2[Slot 2<br/>CO2]
|
||||
Slot3[Slot 3<br/>NH3]
|
||||
Slot4[Slot 4<br/>VOC]
|
||||
Slot5[Slot 5<br/>PM]
|
||||
Slot6[Slot 6<br/>Light]
|
||||
end
|
||||
|
||||
subgraph SensorManager["Sensor Manager"]
|
||||
SensorArray[Sensor Array<br/>sensor_instance_t[7]]
|
||||
end
|
||||
|
||||
subgraph SensorDrivers["Sensor Drivers"]
|
||||
DriverArray[Driver Interface Array<br/>sensor_driver_t[7]]
|
||||
end
|
||||
|
||||
Slot0 --> SensorArray
|
||||
Slot1 --> SensorArray
|
||||
Slot2 --> SensorArray
|
||||
Slot3 --> SensorArray
|
||||
Slot4 --> SensorArray
|
||||
Slot5 --> SensorArray
|
||||
Slot6 --> SensorArray
|
||||
|
||||
SensorArray --> DriverArray
|
||||
```
|
||||
|
||||
## 8. Dynamic View
|
||||
|
||||
### 8.1 Sensor Acquisition Cycle Sequence
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Timer as Acquisition Timer
|
||||
participant SM as Sensor Manager
|
||||
participant Driver as Sensor Driver
|
||||
participant Filter as Filter Engine
|
||||
participant TimeUtil as Time Utils
|
||||
participant EventSys as Event System
|
||||
|
||||
Note over Timer,EventSys: 1-Second Acquisition Cycle
|
||||
|
||||
Timer->>SM: acquisitionCycleStart()
|
||||
|
||||
loop For each enabled sensor (0-6)
|
||||
SM->>SM: checkSensorState(sensor_id)
|
||||
|
||||
alt Sensor is healthy and enabled
|
||||
loop 10 samples
|
||||
SM->>Driver: readSensor(sensor_id)
|
||||
Driver-->>SM: raw_sample
|
||||
SM->>SM: validateSample(raw_sample)
|
||||
end
|
||||
|
||||
SM->>Filter: applyFilter(raw_samples, filter_config)
|
||||
Filter-->>SM: filtered_value
|
||||
|
||||
SM->>TimeUtil: getCurrentTimestamp()
|
||||
TimeUtil-->>SM: timestamp
|
||||
|
||||
SM->>SM: createDataRecord(sensor_id, filtered_value, timestamp)
|
||||
SM->>EventSys: publish(SENSOR_DATA_UPDATE, record)
|
||||
|
||||
else Sensor is faulty or disabled
|
||||
SM->>SM: skipSensor(sensor_id)
|
||||
end
|
||||
end
|
||||
|
||||
SM->>SM: updateAcquisitionStatistics()
|
||||
SM->>EventSys: publish(ACQUISITION_CYCLE_COMPLETE)
|
||||
|
||||
Note over Timer,EventSys: Next cycle in 1 second
|
||||
```
|
||||
|
||||
### 8.2 Sensor State Management Sequence
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant SM as Sensor Manager
|
||||
participant Driver as Sensor Driver
|
||||
participant EventSys as Event System
|
||||
participant ErrorHandler as Error Handler
|
||||
participant MCMgr as MC Manager
|
||||
|
||||
Note over SM,MCMgr: Sensor Detection and Initialization
|
||||
|
||||
SM->>Driver: detectSensorPresence(sensor_id)
|
||||
Driver-->>SM: presence_detected
|
||||
|
||||
alt Sensor newly detected
|
||||
SM->>SM: transitionState(UNKNOWN -> DETECTED)
|
||||
SM->>Driver: initializeSensor(sensor_id)
|
||||
Driver-->>SM: init_result
|
||||
|
||||
alt Initialization successful
|
||||
SM->>SM: transitionState(DETECTED -> INITIALIZED)
|
||||
SM->>MCMgr: getSensorConfig(sensor_id)
|
||||
MCMgr-->>SM: sensor_config
|
||||
SM->>SM: applySensorConfig(sensor_config)
|
||||
SM->>SM: transitionState(INITIALIZED -> ENABLED)
|
||||
SM->>EventSys: publish(SENSOR_STATE_CHANGED, state_info)
|
||||
|
||||
else Initialization failed
|
||||
SM->>SM: transitionState(DETECTED -> UNKNOWN)
|
||||
SM->>ErrorHandler: reportFault(SENSOR_INIT_FAILED)
|
||||
end
|
||||
|
||||
else Sensor fault detected during operation
|
||||
SM->>SM: transitionState(ENABLED -> FAULTY)
|
||||
SM->>ErrorHandler: reportFault(SENSOR_COMMUNICATION_FAILED)
|
||||
SM->>EventSys: publish(SENSOR_FAULT_DETECTED, fault_info)
|
||||
|
||||
Note over SM,MCMgr: Schedule recovery attempt
|
||||
SM->>SM: scheduleRecoveryAttempt(sensor_id, delay_ms)
|
||||
|
||||
else Sensor removed
|
||||
SM->>SM: transitionState(current -> REMOVED)
|
||||
SM->>EventSys: publish(SENSOR_REMOVED, sensor_info)
|
||||
end
|
||||
```
|
||||
|
||||
### 8.3 High-Frequency Sampling and Filtering
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant SM as Sensor Manager
|
||||
participant Driver as Sensor Driver
|
||||
participant Filter as Filter Engine
|
||||
participant Validator as Data Validator
|
||||
|
||||
Note over SM,Validator: High-Frequency Sampling (10 samples)
|
||||
|
||||
SM->>SM: startSampling(sensor_id)
|
||||
|
||||
loop 10 samples
|
||||
SM->>Driver: readSensorValue(sensor_id)
|
||||
Driver-->>SM: raw_value
|
||||
SM->>Validator: validateRange(raw_value, min, max)
|
||||
|
||||
alt Value in valid range
|
||||
Validator-->>SM: valid
|
||||
SM->>SM: addToSampleBuffer(raw_value)
|
||||
else Value out of range
|
||||
Validator-->>SM: invalid
|
||||
SM->>SM: incrementOutlierCount()
|
||||
end
|
||||
|
||||
SM->>SM: delay(sampling_interval_ms)
|
||||
end
|
||||
|
||||
SM->>Filter: processBuffer(sample_buffer, filter_type)
|
||||
|
||||
alt Median Filter
|
||||
Filter->>Filter: sortSamples()
|
||||
Filter->>Filter: selectMedian()
|
||||
else Moving Average Filter
|
||||
Filter->>Filter: calculateAverage()
|
||||
Filter->>Filter: applySmoothing()
|
||||
else Rate Limited Filter
|
||||
Filter->>Filter: checkRateOfChange()
|
||||
Filter->>Filter: applyRateLimit()
|
||||
end
|
||||
|
||||
Filter-->>SM: filtered_value
|
||||
SM->>SM: calculateStatistics(sample_buffer)
|
||||
```
|
||||
|
||||
## 9. Interface Definitions
|
||||
|
||||
### 9.1 Data Types
|
||||
|
||||
```c
|
||||
// Sensor Types
|
||||
typedef enum {
|
||||
SENSOR_TYPE_TEMPERATURE = 0,
|
||||
SENSOR_TYPE_HUMIDITY,
|
||||
SENSOR_TYPE_CO2,
|
||||
SENSOR_TYPE_NH3,
|
||||
SENSOR_TYPE_VOC,
|
||||
SENSOR_TYPE_PM,
|
||||
SENSOR_TYPE_LIGHT,
|
||||
SENSOR_TYPE_COUNT
|
||||
} sensor_type_t;
|
||||
|
||||
// Sensor States
|
||||
typedef enum {
|
||||
SENSOR_STATE_UNKNOWN = 0, // Initial state, not yet detected
|
||||
SENSOR_STATE_DETECTED, // Sensor presence confirmed
|
||||
SENSOR_STATE_INITIALIZED, // Driver loaded and configured
|
||||
SENSOR_STATE_ENABLED, // Active data acquisition
|
||||
SENSOR_STATE_DISABLED, // Present but not acquiring data
|
||||
SENSOR_STATE_FAULTY, // Detected failure condition
|
||||
SENSOR_STATE_REMOVED, // Previously present, now absent
|
||||
SENSOR_STATE_CALIBRATING, // Calibration in progress
|
||||
SENSOR_STATE_COUNT
|
||||
} sensor_state_t;
|
||||
|
||||
// Data Validity Status
|
||||
typedef enum {
|
||||
DATA_VALIDITY_VALID = 0,
|
||||
DATA_VALIDITY_INVALID_RANGE,
|
||||
DATA_VALIDITY_INVALID_TIMEOUT,
|
||||
DATA_VALIDITY_INVALID_COMMUNICATION,
|
||||
DATA_VALIDITY_INVALID_CALIBRATION,
|
||||
DATA_VALIDITY_INVALID_OUTLIER
|
||||
} data_validity_t;
|
||||
|
||||
// Sensor Data Record
|
||||
typedef struct {
|
||||
uint8_t sensor_id; // Sensor identifier (0-6)
|
||||
sensor_type_t sensor_type; // Type of sensor
|
||||
float filtered_value; // Processed sensor value
|
||||
char unit[8]; // Unit of measurement (e.g., "°C", "%RH")
|
||||
uint64_t timestamp_ms; // Timestamp in milliseconds
|
||||
data_validity_t validity; // Data validity status
|
||||
uint16_t sample_count; // Number of samples used for filtering
|
||||
float raw_min, raw_max; // Min/max of raw samples
|
||||
float raw_stddev; // Standard deviation of raw samples
|
||||
uint32_t acquisition_time_us; // Time taken for acquisition (microseconds)
|
||||
} sensor_data_record_t;
|
||||
|
||||
// Sensor Configuration
|
||||
typedef struct {
|
||||
uint16_t sampling_count; // Number of samples per cycle (5-20)
|
||||
uint32_t sampling_interval_ms; // Interval between samples
|
||||
filter_type_t filter_type; // Filter algorithm to use
|
||||
filter_params_t filter_params; // Filter-specific parameters
|
||||
float min_valid_value; // Minimum valid sensor value
|
||||
float max_valid_value; // Maximum valid sensor value
|
||||
float rate_limit_per_sec; // Maximum rate of change per second
|
||||
bool enable_outlier_rejection; // Enable outlier detection
|
||||
float outlier_threshold; // Outlier detection threshold (std devs)
|
||||
uint32_t recovery_delay_ms; // Delay before recovery attempt
|
||||
uint8_t max_consecutive_failures; // Max failures before marking faulty
|
||||
} sensor_config_t;
|
||||
|
||||
// Filter Types and Parameters
|
||||
typedef enum {
|
||||
FILTER_TYPE_NONE = 0, // No filtering (use raw average)
|
||||
FILTER_TYPE_MEDIAN, // Median filter
|
||||
FILTER_TYPE_MOVING_AVERAGE, // Moving average filter
|
||||
FILTER_TYPE_RATE_LIMITED, // Rate-of-change limiter
|
||||
FILTER_TYPE_COMBINED, // Combination of filters
|
||||
FILTER_TYPE_COUNT
|
||||
} filter_type_t;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
uint8_t window_size; // Window size for median filter
|
||||
} median;
|
||||
struct {
|
||||
uint8_t window_size; // Window size for moving average
|
||||
float alpha; // Exponential smoothing factor
|
||||
} moving_avg;
|
||||
struct {
|
||||
float max_rate; // Maximum rate of change per second
|
||||
float recovery_time; // Time to recover from rate limiting
|
||||
} rate_limit;
|
||||
};
|
||||
} filter_params_t;
|
||||
|
||||
// Sensor Statistics
|
||||
typedef struct {
|
||||
uint32_t total_acquisitions; // Total number of acquisition cycles
|
||||
uint32_t successful_acquisitions; // Successful acquisitions
|
||||
uint32_t failed_acquisitions; // Failed acquisitions
|
||||
uint32_t timeout_count; // Number of timeouts
|
||||
uint32_t outlier_count; // Number of outliers detected
|
||||
float avg_acquisition_time_ms; // Average acquisition time
|
||||
float max_acquisition_time_ms; // Maximum acquisition time
|
||||
float min_value, max_value; // Min/max values recorded
|
||||
float avg_value; // Average value
|
||||
uint64_t last_acquisition_time; // Timestamp of last acquisition
|
||||
uint32_t consecutive_failures; // Current consecutive failure count
|
||||
sensor_state_t current_state; // Current sensor state
|
||||
} sensor_stats_t;
|
||||
|
||||
// Acquisition Performance Metrics
|
||||
typedef struct {
|
||||
uint32_t total_cycles; // Total acquisition cycles
|
||||
uint32_t successful_cycles; // Successful cycles
|
||||
uint32_t failed_cycles; // Failed cycles
|
||||
float avg_cycle_time_ms; // Average cycle time
|
||||
float max_cycle_time_ms; // Maximum cycle time
|
||||
uint8_t active_sensor_count; // Number of active sensors
|
||||
uint8_t faulty_sensor_count; // Number of faulty sensors
|
||||
uint32_t memory_usage_bytes; // Current memory usage
|
||||
} acquisition_metrics_t;
|
||||
```
|
||||
|
||||
### 9.2 Configuration Constants
|
||||
|
||||
```c
|
||||
// Sensor Configuration
|
||||
#define SENSOR_COUNT 7 // Total number of sensor slots
|
||||
#define SENSOR_ID_ALL 0xFF // Special ID for all sensors
|
||||
#define DEFAULT_SAMPLING_COUNT 10 // Default samples per cycle
|
||||
#define DEFAULT_SAMPLING_INTERVAL 50 // Default interval between samples (ms)
|
||||
#define MAX_SAMPLING_COUNT 20 // Maximum samples per cycle
|
||||
#define MIN_SAMPLING_COUNT 5 // Minimum samples per cycle
|
||||
|
||||
// Timing Configuration
|
||||
#define ACQUISITION_CYCLE_PERIOD 1000 // Acquisition cycle period (ms)
|
||||
#define MAX_ACQUISITION_TIME 800 // Maximum time per cycle (ms)
|
||||
#define SENSOR_TIMEOUT 100 // Individual sensor timeout (ms)
|
||||
#define RECOVERY_DELAY_DEFAULT 5000 // Default recovery delay (ms)
|
||||
|
||||
// Memory Configuration
|
||||
#define SENSOR_DATA_HISTORY_SIZE 10 // Number of historical records per sensor
|
||||
#define SAMPLE_BUFFER_SIZE 20 // Maximum samples per sensor
|
||||
#define SENSOR_NAME_MAX_LENGTH 16 // Maximum sensor name length
|
||||
```
|
||||
|
||||
## 10. Assumptions and Constraints
|
||||
|
||||
### 10.1 Assumptions
|
||||
|
||||
- **Sensor Hardware Compatibility:** All sensors are compatible with their assigned slots
|
||||
- **Driver Availability:** Sensor drivers are available and functional
|
||||
- **Timing Accuracy:** System timer provides accurate 1-second intervals
|
||||
- **Memory Availability:** Sufficient memory for sensor data buffers and state
|
||||
- **Configuration Validity:** Machine Constants provide valid sensor configurations
|
||||
|
||||
### 10.2 Constraints
|
||||
|
||||
- **Acquisition Timing:** Complete all sensor acquisition within 800ms per cycle
|
||||
- **Memory Usage:** Total memory usage limited to 32KB
|
||||
- **CPU Usage:** Maximum 20% of available CPU time
|
||||
- **Sensor Count:** Maximum 7 sensors (fixed hardware slots)
|
||||
- **Sample Count:** 5-20 samples per sensor per cycle
|
||||
|
||||
### 10.3 Design Constraints
|
||||
|
||||
- **No Dynamic Memory:** Use pre-allocated buffers for sensor data
|
||||
- **Deterministic Timing:** All operations must have bounded execution time
|
||||
- **State Persistence:** Sensor states must survive system resets
|
||||
- **Thread Safety:** All public interfaces must be thread-safe
|
||||
|
||||
## 11. Traceability
|
||||
|
||||
### 11.1 System Requirements
|
||||
|
||||
- **SR-DAQ-001:** Multi-sensor support for 7 environmental sensor types
|
||||
- **SR-DAQ-002:** High-frequency sampling (minimum 10 samples per cycle)
|
||||
- **SR-DAQ-003:** Local data filtering with configurable algorithms
|
||||
- **SR-DAQ-004:** Timestamped data generation with ±1 second accuracy
|
||||
- **SR-DAQ-005:** Sensor state management and lifecycle control
|
||||
|
||||
### 11.2 Software Requirements
|
||||
|
||||
- **SWR-DAQ-001 to SWR-DAQ-015:** Complete sensor data acquisition implementation
|
||||
- **SWR-DQC-001 to SWR-DQC-018:** Data quality and calibration requirements
|
||||
- **SWR-PERF-001:** Acquisition cycle timing constraints (100ms per sensor)
|
||||
|
||||
### 11.3 Features
|
||||
|
||||
- **F-DAQ-01:** Multi-Sensor Data Acquisition
|
||||
- **F-DAQ-02:** High-Frequency Sampling and Local Filtering
|
||||
- **F-DAQ-03:** Timestamped Sensor Data Generation
|
||||
- **F-DQC-01:** Automatic Sensor Detection
|
||||
- **F-DQC-02:** Sensor Type Enforcement
|
||||
- **F-DQC-03:** Sensor Failure Detection
|
||||
|
||||
### 11.4 Cross-Feature Constraints
|
||||
|
||||
- **CFC-TIME-01:** Non-blocking operation
|
||||
- **CFC-TIME-02:** Deterministic behavior with bounded timing
|
||||
- **CFC-ARCH-02:** State-aware execution (respects system states)
|
||||
|
||||
---
|
||||
|
||||
**Document Status:** Final for Implementation
|
||||
**Dependencies:** Sensor Drivers, Event System, Time Utils, MC Manager, Error Handler
|
||||
**Next Review:** After component implementation and integration testing
|
||||
Reference in New Issue
Block a user