TinyMeasurement 配置¶
Info
这个头文件起到配置整个TinyMeasurement模块的作用,每个子模块都包含了此头文件。它定义了TinyMeasurement的配置选项和宏,允许用户根据需要进行自定义设置。通过修改这个头文件中的配置选项,用户可以轻松地调整TinyMeasurement的行为和功能,以满足特定的需求。文档更新速度较慢,可能会与实际代码不一致,请以代码为准。
概述¶
tiny_measurement_config.h 头文件包含 TinyMeasurement 中间件的所有配置宏。所有配置选项都使用 #ifndef 模式,这意味着您可以在包含此头文件之前定义宏来覆盖任何默认值。
配置类别¶
在线感知配置¶
这些宏控制在线感知操作的默认行为:
- 采样频率:连续数据采集的默认速率(0.1 - 1000 Hz,实测上限:~200 Hz,主要受MQTT传输带宽限制)
- 注意:代码注释说 "Default: 20.0 Hz",但实际默认值是 1.0 Hz
- MQTT传输:启用/禁用自动MQTT数据传输
- 串口输出:启用/禁用通过printf和ESP_LOG的控制台输出
- LCD显示:可选的LCD显示支持(需要编译标志)
离线感知配置¶
这些宏控制高频批量数据采集:
- 采样频率:离线采集的更高默认速率(1 - 4000 Hz)
- 采样时长:数据采集的持续时间(0.1 - 3600 秒)
- 存储选项:启用/禁用SD卡和内存缓冲区存储
- MQTT报告:采样完成后启用/禁用MQTT报告
实时处理架构配置¶
这些宏控制实时数据处理,提供三种架构选项:
- 采样频率:实时处理的默认速率(架构1:0.1 - 1000 Hz,架构⅔:0.1 - 10000 Hz)
- 注意:配置默认值为 20.0 Hz,但实际架构实现中使用 100.0 Hz 作为硬编码默认值
- MQTT/串口输出:启用/禁用输出通道
- 加速度检测:启用/禁用实时检测,带 LCD 反馈
- 架构特定配置:每个架构的缓冲区大小、任务优先级、堆栈大小和核心分配
- 通用设置:LCD 更新间隔和加速度检测阈值
自定义配置¶
要自定义任何默认值,请在包含头文件之前定义宏:
// 覆盖默认在线感知频率
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_FREQ_HZ 10.0f
#include "tiny_measurement.h"
/**
* @file tiny_measurement_config.h
* @author SHUAIWEN CUI (SHUAIWEN001@e.ntu.edu.sg)
* @brief The configuration file for the tiny_measurement middleware.
* @version 1.0
* @date 2025-12-17
* @copyright Copyright (c) 2025
*
*/
#pragma once
/* DEPENDENCIES */
// lower level dependencies
#include "tiny_ai.h"
#ifdef __cplusplus
extern "C"
{
#endif
/* ============================================================================
* ONLINE SENSING CONFIGURATION MACROS
* ============================================================================ */
/**
* @brief Default sampling frequency for online sensing (Hz)
* @note Valid range: 0.1 - 1000 Hz (代码验证上限为 300 Hz)
* @note Default: 1.0 Hz
* @note 注意:代码注释说 "Default: 20.0 Hz",但实际默认值是 1.0 Hz
*/
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_FREQ_HZ
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_FREQ_HZ 1.0f
#endif
/**
* @brief Default MQTT transmission enable state for online sensing
* @note true: Enable MQTT transmission
* @note false: Disable MQTT transmission
* @note Default: true
*/
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_MQTT
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_MQTT true
#endif
/**
* @brief Default serial output enable state for online sensing
* @note true: Enable serial output (printf and ESP_LOG)
* @note false: Disable serial output
* @note Default: true
*/
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_SERIAL
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_SERIAL true
#endif
/* ============================================================================
* LCD DISPLAY FEATURE COMPILATION CONTROL
* ============================================================================ */
/**
* @brief Enable LCD display feature compilation
* @note Define this macro to enable LCD display support in online sensing
* @note If not defined, all LCD-related code will be excluded from compilation
* @note Default: NOT DEFINED (LCD feature disabled by default)
* @note To enable: Add -DTINY_MEASUREMENT_ENABLE_LCD to compiler flags
*/
#ifdef TINY_MEASUREMENT_ENABLE_LCD
/**
* @brief Default LCD display enable state for online sensing
* @note Only available when TINY_MEASUREMENT_ENABLE_LCD is defined
* @note true: Enable LCD display output
* @note false: Disable LCD display output
* @note Default: false
*/
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_LCD
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_LCD true
#endif
#endif /* TINY_MEASUREMENT_ENABLE_LCD */
/* ============================================================================
* OFFLINE SENSING CONFIGURATION MACROS
* ============================================================================ */
/**
* @brief Default sampling frequency for offline sensing (Hz)
* @note Valid range: 1 - 4000 Hz
* @note Maximum frequency (4000 Hz) is limited by ADXL355 sensor's maximum output data rate (ODR)
* @note ADXL355 hardware supports up to 4000 Hz ODR, which is the sensor's physical limit
* @note Default: 100.0 Hz (high frequency for offline sensing)
*/
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_FREQ_HZ
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_FREQ_HZ 100.0f
#endif
/**
* @brief Default sampling duration for offline sensing (seconds)
* @note Valid range: 0.1 - 3600 seconds
* @note Default: 10.0 seconds
*/
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_DURATION_SEC
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_DURATION_SEC 10.0f
#endif
/**
* @brief Default SD card storage enable state for offline sensing
* @note true: Enable SD card storage
* @note false: Disable SD card storage (only memory buffer)
* @note Default: true
*/
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_SD
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_SD true
#endif
/**
* @brief Default memory buffer storage enable state for offline sensing
* @note true: Enable memory buffer storage
* @note false: Disable memory buffer storage (only SD card)
* @note Default: true
*/
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MEMORY
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MEMORY true
#endif
/**
* @brief Default MQTT report enable state for offline sensing
* @note true: Enable MQTT report after sampling
* @note false: Disable MQTT report
* @note Default: true
*/
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MQTT_REPORT
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MQTT_REPORT true
#endif
/* ============================================================================
* REAL-TIME PROCESSING ARCHITECTURE CONFIGURATION MACROS
* ============================================================================ */
/**
* @brief Default sampling frequency for real-time processing (Hz)
* @note Valid range: Architecture 1: 0.1 - 1000 Hz, Architecture 2/3: 0.1 - 10000 Hz
* @note Default: 20.0 Hz (in config), but actual code uses 100.0 Hz as default
* @note 注意:实际架构实现中使用 100.0 Hz 作为硬编码默认值
*/
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_FREQ_HZ
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_FREQ_HZ 20.0f
#endif
/**
* @brief Default MQTT transmission enable state for real-time processing
* @note true: Enable MQTT transmission
* @note false: Disable MQTT transmission
* @note Default: false (disabled for real-time processing)
*/
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_MQTT
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_MQTT false
#endif
/**
* @brief Default serial output enable state for real-time processing
* @note true: Enable serial output (printf and ESP_LOG)
* @note false: Disable serial output
* @note Default: true
*/
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_SERIAL
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_SERIAL true
#endif
/**
* @brief Default acceleration detection enable state for real-time processing
* @note true: Enable acceleration detection with LCD feedback
* @note false: Disable acceleration detection
* @note Default: true
*/
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_ACCEL_DETECTION
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_ACCEL_DETECTION true
#endif
/* ============================================================================
* PRODUCER-CONSUMER ARCHITECTURE CONFIGURATION
* ============================================================================ */
/**
* @brief Circular buffer size for Producer-Consumer architecture
* @note Number of samples stored in the circular buffer
* @note Default: 512 samples
* @note Memory usage: buffer_size × sizeof(rt_process_sample_t) ≈ buffer_size × 28 bytes
*/
#ifndef TINY_MEASUREMENT_RT_PC_CIRCULAR_BUFFER_SIZE
#define TINY_MEASUREMENT_RT_PC_CIRCULAR_BUFFER_SIZE 512
#endif
/**
* @brief Consumer processing interval for Producer-Consumer architecture (milliseconds)
* @note How often the consumer task processes data from the buffer
* @note Default: 50 ms (20 times per second)
*/
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_INTERVAL_MS
#define TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_INTERVAL_MS 50
#endif
/**
* @brief Number of recent samples to process in Producer-Consumer architecture
* @note Consumer processes the last N samples for real-time response
* @note Default: 10 samples
*/
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_SAMPLE_COUNT
#define TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_SAMPLE_COUNT 10
#endif
/**
* @brief Default queue size for Producer-Consumer architecture (legacy, not used with circular buffer)
* @note Default: 50
*/
#ifndef TINY_MEASUREMENT_RT_PC_QUEUE_SIZE_DEFAULT
#define TINY_MEASUREMENT_RT_PC_QUEUE_SIZE_DEFAULT 50
#endif
/**
* @brief Producer task priority for Producer-Consumer architecture
* @note Higher priority ensures timely data acquisition
* @note Default: 10 (high priority)
*/
#ifndef TINY_MEASUREMENT_RT_PC_PRODUCER_PRIORITY
#define TINY_MEASUREMENT_RT_PC_PRODUCER_PRIORITY 10
#endif
/**
* @brief Consumer task priority for Producer-Consumer architecture
* @note Default: 8 (high priority, slightly lower than producer)
*/
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_PRIORITY
#define TINY_MEASUREMENT_RT_PC_CONSUMER_PRIORITY 8
#endif
/**
* @brief Producer task stack size for Producer-Consumer architecture (bytes)
* @note Default: 4096 bytes
*/
#ifndef TINY_MEASUREMENT_RT_PC_PRODUCER_STACK_SIZE
#define TINY_MEASUREMENT_RT_PC_PRODUCER_STACK_SIZE 4096
#endif
/**
* @brief Consumer task stack size for Producer-Consumer architecture (bytes)
* @note Default: 8192 bytes (larger for processing tasks)
*/
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_STACK_SIZE
#define TINY_MEASUREMENT_RT_PC_CONSUMER_STACK_SIZE 8192
#endif
/* ============================================================================
* DMA + DOUBLE BUFFER ARCHITECTURE CONFIGURATION
* ============================================================================ */
/**
* @brief Buffer size for each buffer in DMA + Double Buffer architecture
* @note Each buffer (A and B) holds this many samples
* @note Default: 512 samples per buffer
* @note Total memory: 2 × buffer_size × sizeof(rt_process_sample_t) ≈ 2 × buffer_size × 28 bytes
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DB_BUFFER_SIZE
#define TINY_MEASUREMENT_RT_DMA_DB_BUFFER_SIZE 512
#endif
/**
* @brief Producer task priority for DMA + Double Buffer architecture
* @note Default: 10 (high priority)
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_PRIORITY 10
#endif
/**
* @brief Consumer task priority for DMA + Double Buffer architecture
* @note Default: 8 (high priority)
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_PRIORITY 8
#endif
/**
* @brief Producer task stack size for DMA + Double Buffer architecture (bytes)
* @note Default: 4096 bytes
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_STACK_SIZE 4096
#endif
/**
* @brief Consumer task stack size for DMA + Double Buffer architecture (bytes)
* @note Default: 8192 bytes
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_STACK_SIZE 8192
#endif
/* ============================================================================
* DMA + DUAL CORE ARCHITECTURE CONFIGURATION
* ============================================================================ */
/**
* @brief Buffer size for each buffer in DMA + Dual Core architecture
* @note Each buffer (A and B) holds this many samples
* @note Default: 256 samples per buffer
* @note Total memory: 2 × buffer_size × sizeof(rt_process_sample_t) ≈ 2 × buffer_size × 28 bytes
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DC_BUFFER_SIZE
#define TINY_MEASUREMENT_RT_DMA_DC_BUFFER_SIZE 256
#endif
/**
* @brief Producer task priority for DMA + Dual Core architecture
* @note Runs on Core 0
* @note Default: 10 (high priority)
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_PRIORITY 10
#endif
/**
* @brief Consumer task priority for DMA + Dual Core architecture
* @note Runs on Core 1
* @note Default: 10 (high priority)
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_PRIORITY 10
#endif
/**
* @brief Producer task stack size for DMA + Dual Core architecture (bytes)
* @note Default: 4096 bytes
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_STACK_SIZE 4096
#endif
/**
* @brief Consumer task stack size for DMA + Dual Core architecture (bytes)
* @note Default: 8192 bytes
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_STACK_SIZE 8192
#endif
/**
* @brief Core assignment for producer task in DMA + Dual Core architecture
* @note Default: 0 (Core 0 for data acquisition)
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_CORE
#define TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_CORE 0
#endif
/**
* @brief Core assignment for consumer task in DMA + Dual Core architecture
* @note Default: 1 (Core 1 for data processing)
*/
#ifndef TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_CORE
#define TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_CORE 1
#endif
/* ============================================================================
* COMMON REAL-TIME PROCESSING CONFIGURATION
* ============================================================================ */
/**
* @brief LCD color hold duration for acceleration detection (microseconds)
* @note How long the LCD color change persists after condition is detected
* @note Default: 300000 us (0.3 seconds = 300 ms)
*/
#ifndef TINY_MEASUREMENT_RT_LCD_COLOR_HOLD_DURATION_US
#define TINY_MEASUREMENT_RT_LCD_COLOR_HOLD_DURATION_US 300000U
#endif
/**
* @brief Minimum interval between LCD updates to avoid SPI bus conflicts (microseconds)
* @note Prevents concurrent LCD updates that could cause SPI bus errors
* @note Default: 100000 us (0.1 seconds = 100 ms)
*/
#ifndef TINY_MEASUREMENT_RT_LCD_UPDATE_MIN_INTERVAL_US
#define TINY_MEASUREMENT_RT_LCD_UPDATE_MIN_INTERVAL_US 100000U
#endif
/**
* @brief Acceleration detection threshold for X axis (g)
* @note Condition: |x| > threshold triggers detection
* @note Default: 0.5g
*/
#ifndef TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_X
#define TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_X 0.5f
#endif
/**
* @brief Acceleration detection threshold for Y axis (g)
* @note Condition: |y| > threshold triggers detection
* @note Default: 0.5g
*/
#ifndef TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Y
#define TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Y 0.5f
#endif
/**
* @brief Acceleration detection threshold for Z axis (g)
* @note Condition: |z| < threshold triggers detection
* @note Default: 0.5g
*/
#ifndef TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Z
#define TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Z 0.5f
#endif
#ifdef __cplusplus
}
#endif