Piezo 측정 파라미터 FDS 저장/측정 경로 범위 검증 통일
- frequency: 1.7M(3) / 1.8M(0) / 1.9M(9) / 2.0M(2) / 2.1M(1) / 2.2M(4) * 그 외의 값이 들어올 경우 1로 저장(기본 fallback 2.1MHz) - cycles: 최소 3 ~ 최대 7 * 3 미만의 값이 들어올 경우 3, 7 초과의 값이 들어올 경우 7 저장 - avgeraging: 최소 1 ~ 최대 10 * 1 미만의 값이 들어올 경우 1, 10 초과의 값이 들어올 경우 10 저장 - dealy_us: 최소 0 ~ 최대 50 * 0 미만의 값이 들어올 경우 0, 50 초과의 값이 들어올 경우 50 저장 - num samples: 최소 80 ~ 최대 119 * 80 미만의 값이 들어올 경우 80, 119 초과의 값이 들어올 경우 119 저장
This commit is contained in:
+89
-49
@@ -57,6 +57,74 @@ extern void dr_piezo_power_off(void);
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal helpers
|
||||
*----------------------------------------------------------------------------*/
|
||||
static uint8_t normalize_freq_option(uint8_t freq_option)
|
||||
{
|
||||
switch (freq_option)
|
||||
{
|
||||
case 0: /* 1.8MHz */
|
||||
case 1: /* 2.1MHz */
|
||||
case 2: /* 2.0MHz */
|
||||
case 3: /* 1.7MHz */
|
||||
case 4: /* 2.2MHz */
|
||||
case 9: /* 1.9MHz */
|
||||
return freq_option;
|
||||
|
||||
default:
|
||||
return 1; /* Invalid -> default to 2.1MHz */
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t clamp_measure_cycles(uint8_t cycles)
|
||||
{
|
||||
if (cycles < 3)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (cycles > 7)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
return cycles;
|
||||
}
|
||||
|
||||
static uint16_t clamp_measure_averaging(uint16_t averaging)
|
||||
{
|
||||
if (averaging < 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (averaging > 10)
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
return averaging;
|
||||
}
|
||||
|
||||
static uint16_t clamp_measure_num_samples(uint16_t num_samples)
|
||||
{
|
||||
if (num_samples < 80)
|
||||
{
|
||||
return 80;
|
||||
}
|
||||
if (num_samples > 119)
|
||||
{
|
||||
return 119;
|
||||
}
|
||||
return num_samples;
|
||||
}
|
||||
|
||||
static uint16_t clamp_measure_delay_us(uint16_t delay_us)
|
||||
{
|
||||
if (delay_us > 50)
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
return delay_us;
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* DEBUG CONFIGURATION
|
||||
*============================================================================*/
|
||||
@@ -579,26 +647,11 @@ dr_adc_err_t dr_adc_burst_capture_transmit(uint8_t freq_option, uint16_t delay_u
|
||||
{
|
||||
return DR_ADC_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (num_samples == 0 || num_samples > DR_ADC_ECHO_SAMPLES_MAX)
|
||||
{
|
||||
return DR_ADC_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (freq_option > 9)
|
||||
{
|
||||
freq_option = 0; /* Invalid -> default 1.8MHz */
|
||||
}
|
||||
if (cycles < 3 || cycles > 7)
|
||||
{
|
||||
cycles = 5; /* Valid range: 3~7, default 5 */
|
||||
}
|
||||
if (averaging == 0)
|
||||
{
|
||||
averaging = 1; /* Minimum 1 */
|
||||
}
|
||||
if (averaging > 1000)
|
||||
{
|
||||
averaging = 1000; /* Maximum 1000 */
|
||||
}
|
||||
freq_option = normalize_freq_option(freq_option);
|
||||
delay_us = clamp_measure_delay_us(delay_us);
|
||||
num_samples = clamp_measure_num_samples(num_samples);
|
||||
cycles = clamp_measure_cycles(cycles);
|
||||
averaging = clamp_measure_averaging(averaging);
|
||||
if (piezo_ch >= MAA_NUM_CHANNELS)
|
||||
{
|
||||
piezo_ch = 0; /* clamp channel range */
|
||||
@@ -821,26 +874,11 @@ dr_adc_err_t dr_adc_capture_channel_only(uint8_t freq_option, uint16_t delay_us,
|
||||
{
|
||||
return DR_ADC_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (num_samples == 0 || num_samples > MAA_SAMPLES_MAX)
|
||||
{
|
||||
return DR_ADC_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (freq_option > 3)
|
||||
{
|
||||
freq_option = 0;
|
||||
}
|
||||
if (cycles < 3 || cycles > 7)
|
||||
{
|
||||
cycles = 5;
|
||||
}
|
||||
if (averaging == 0)
|
||||
{
|
||||
averaging = 1;
|
||||
}
|
||||
if (averaging > 1000)
|
||||
{
|
||||
averaging = 1000;
|
||||
}
|
||||
freq_option = normalize_freq_option(freq_option);
|
||||
delay_us = clamp_measure_delay_us(delay_us);
|
||||
num_samples = clamp_measure_num_samples(num_samples);
|
||||
cycles = clamp_measure_cycles(cycles);
|
||||
averaging = clamp_measure_averaging(averaging);
|
||||
if (piezo_ch > (MAA_NUM_CHANNELS - 1))
|
||||
{
|
||||
piezo_ch = 0;
|
||||
@@ -893,6 +931,12 @@ dr_adc_err_t dr_adc_capture_channel_only(uint8_t freq_option, uint16_t delay_us,
|
||||
case 3:
|
||||
dr_piezo_burst_sw_17mhz(cycles);
|
||||
break;
|
||||
case 4:
|
||||
dr_piezo_burst_sw_22mhz(cycles);
|
||||
break;
|
||||
case 9:
|
||||
dr_piezo_burst_sw_19mhz(cycles);
|
||||
break;
|
||||
}
|
||||
|
||||
/* delay from TX burst to ADC start */
|
||||
@@ -1281,20 +1325,16 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us, uint16_t nu
|
||||
{
|
||||
return DR_ADC_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (num_samples == 0 || num_samples > DR_ADC_ECHO_SAMPLES_MAX)
|
||||
{
|
||||
return DR_ADC_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Clear BLE buffer to prevent stale data from previous measurement */
|
||||
memset(ble_buffer, 0, BLE_MTU_SIZE);
|
||||
|
||||
/* Initialize context */
|
||||
g_maa_ctx.freq_option = freq_option;
|
||||
g_maa_ctx.delay_us = delay_us;
|
||||
g_maa_ctx.num_samples = num_samples;
|
||||
g_maa_ctx.cycles = (cycles < 3 || cycles > 7) ? 5 : cycles;
|
||||
g_maa_ctx.averaging = (averaging == 0) ? 1 : ((averaging > 1000) ? 1000 : averaging);
|
||||
g_maa_ctx.freq_option = normalize_freq_option(freq_option);
|
||||
g_maa_ctx.delay_us = clamp_measure_delay_us(delay_us);
|
||||
g_maa_ctx.num_samples = clamp_measure_num_samples(num_samples);
|
||||
g_maa_ctx.cycles = clamp_measure_cycles(cycles);
|
||||
g_maa_ctx.averaging = clamp_measure_averaging(averaging);
|
||||
g_maa_ctx.ble_buffer = ble_buffer;
|
||||
g_maa_ctx.current_ch = 0;
|
||||
g_maa_ctx.current_pkt = 0;
|
||||
|
||||
Reference in New Issue
Block a user