apply latest local changes
This commit is contained in:
@@ -365,6 +365,7 @@ dr_adc_err_t dr_adc_analyze_echo(const uint16_t *buffer, uint16_t num_samples,
|
||||
|
||||
/* Convert to voltage and time */
|
||||
echo->peak_mv = dr_adc_raw_to_mv(echo->peak_raw);
|
||||
|
||||
/* peak_time_us: sample_index * 0.116us (8.6MHz sample rate) */
|
||||
echo->peak_time_us = (uint32_t)((float)echo->peak_index * DR_ADC_SAMPLE_INTERVAL_US);
|
||||
echo->num_samples = num_samples;
|
||||
@@ -505,6 +506,9 @@ void dr_adc_print_buffer(const uint16_t *buffer, uint16_t num_samples)
|
||||
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||
extern void dr_sd_delay_ms(uint32_t ms);
|
||||
|
||||
/* Platform interface (log function) */
|
||||
#include "parser.h"
|
||||
|
||||
/*==============================================================================
|
||||
* INTEGRATED BURST + CAPTURE + TRANSMIT
|
||||
*============================================================================*/
|
||||
@@ -649,7 +653,7 @@ dr_adc_err_t dr_adc_burst_capture_transmit(uint8_t freq_option, uint16_t delay_u
|
||||
dr_adc_err_t err = dr_adc_capture_echo(m_echo_buffer, num_samples);
|
||||
if (err != DR_ADC_OK) return err;
|
||||
|
||||
ADC_LOG("mec: single measurement (no averaging)");
|
||||
//ADC_LOG("mec: single measurement (no averaging)");
|
||||
}
|
||||
else {
|
||||
/*=== MULTIPLE MEASUREMENTS (with averaging) ===*/
|
||||
@@ -795,7 +799,7 @@ dr_adc_err_t dr_adc_burst_capture_transmit(uint8_t freq_option, uint16_t delay_u
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
* 4-CHANNEL CAPTURE FUNCTIONS (maa? command support)
|
||||
* CHANNEL CAPTURE FUNCTIONS (maa? command support)
|
||||
*============================================================================*/
|
||||
|
||||
dr_adc_err_t dr_adc_capture_channel_only(uint8_t freq_option, uint16_t delay_us,
|
||||
@@ -816,31 +820,28 @@ dr_adc_err_t dr_adc_capture_channel_only(uint8_t freq_option, uint16_t delay_us,
|
||||
static uint32_t accum_buffer[MAA_SAMPLES_MAX];
|
||||
memset(accum_buffer, 0, num_samples * sizeof(uint32_t));
|
||||
|
||||
if (!m_initialized) {
|
||||
if (!m_initialized)
|
||||
{
|
||||
dr_adc_err_t init_err = dr_adc_init();
|
||||
if (init_err != DR_ADC_OK) return init_err;
|
||||
}
|
||||
nrf_delay_us(100);
|
||||
|
||||
/* Select piezo channel */
|
||||
//nrf_delay_us(100);
|
||||
|
||||
/* 채널 선택(MUX) : 1.3ms */
|
||||
dr_piezo_select_channel(piezo_ch);
|
||||
|
||||
/* Capture with averaging */
|
||||
for (uint16_t avg_iter = 0; avg_iter < averaging; avg_iter++) {
|
||||
if (avg_iter > 0) {
|
||||
//nrf_delay_us(500); /* Echo decay time */
|
||||
}
|
||||
|
||||
//dr_piezo_select_channel(piezo_ch);
|
||||
|
||||
/* Execute piezo burst */
|
||||
/* 채널당 반복 측정 횟수만큼 */
|
||||
for (uint16_t avg_iter = 0; avg_iter < averaging; avg_iter++)
|
||||
{
|
||||
/* TX 펄스 출력(Burst) */
|
||||
switch (freq_option) {
|
||||
case 0:
|
||||
default:
|
||||
dr_piezo_burst_sw_18mhz(cycles);
|
||||
break;
|
||||
case 1:
|
||||
dr_piezo_burst_sw(cycles);
|
||||
dr_piezo_burst_sw(cycles); /* 2.1MHz */
|
||||
break;
|
||||
case 2:
|
||||
dr_piezo_burst_sw_20mhz(cycles);
|
||||
@@ -850,24 +851,30 @@ dr_adc_err_t dr_adc_capture_channel_only(uint8_t freq_option, uint16_t delay_us,
|
||||
break;
|
||||
}
|
||||
|
||||
if (delay_us > 0) {
|
||||
/* TX 펄스 출력 후 ADC 시작 시까지 대기 시간 */
|
||||
if (delay_us > 0)
|
||||
{
|
||||
nrf_delay_us(delay_us);
|
||||
}
|
||||
|
||||
/* Capture to internal buffer */
|
||||
/* 측정 ADC 샘플 수만큼 캡처 */
|
||||
dr_adc_err_t err = dr_adc_capture_echo(m_echo_buffer, num_samples);
|
||||
|
||||
if (err != DR_ADC_OK) return err;
|
||||
|
||||
/* Accumulate */
|
||||
for (uint16_t i = 0; i < num_samples; i++) {
|
||||
for (uint16_t i = 0; i < num_samples; i++)
|
||||
{
|
||||
accum_buffer[i] += m_echo_buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate average and copy to output */
|
||||
for (uint16_t i = 0; i < num_samples; i++) {
|
||||
for (uint16_t i = 0; i < num_samples; i++)
|
||||
{
|
||||
out_channel->samples[i] = (uint16_t)(accum_buffer[i] / averaging);
|
||||
}
|
||||
|
||||
out_channel->num_samples = num_samples;
|
||||
|
||||
/* Analyze echo data */
|
||||
@@ -877,8 +884,8 @@ dr_adc_err_t dr_adc_capture_channel_only(uint8_t freq_option, uint16_t delay_us,
|
||||
out_channel->peak_index = echo.peak_index;
|
||||
out_channel->baseline_raw = echo.baseline_raw;
|
||||
|
||||
ADC_LOG("maa capture CH%u: peak=%u idx=%u baseline=%u",
|
||||
piezo_ch, out_channel->peak_raw, out_channel->peak_index, out_channel->baseline_raw);
|
||||
/* peak, index, baseline 확인용 로그 */
|
||||
//if (g_plat.log) g_plat.log("CH%u: peak=%u index=%u baseline=%u\r\n", piezo_ch, out_channel->peak_raw, out_channel->peak_index, out_channel->baseline_raw);
|
||||
|
||||
return DR_ADC_OK;
|
||||
}
|
||||
@@ -1059,7 +1066,8 @@ dr_adc_err_t dr_adc_transmit_channel_delta(const dr_maa_channel_t *ch_data,
|
||||
|
||||
/* Data packets (rdd:) */
|
||||
uint16_t src_idx = 0;
|
||||
for (uint16_t pkt = 0; pkt < data_packets; pkt++) {
|
||||
for (uint16_t pkt = 0; pkt < data_packets; pkt++)
|
||||
{
|
||||
ble_buffer[0] = 'r';
|
||||
ble_buffer[1] = 'd';
|
||||
ble_buffer[2] = 'd';
|
||||
@@ -1069,13 +1077,15 @@ dr_adc_err_t dr_adc_transmit_channel_delta(const dr_maa_channel_t *ch_data,
|
||||
|
||||
uint16_t dst_idx = 6;
|
||||
uint16_t bytes_this_pkt = 0;
|
||||
while (src_idx < compressed_size && bytes_this_pkt < cont_pkt_data_cap) {
|
||||
while (src_idx < compressed_size && bytes_this_pkt < cont_pkt_data_cap)
|
||||
{
|
||||
ble_buffer[dst_idx++] = delta_buffer[src_idx++];
|
||||
bytes_this_pkt++;
|
||||
}
|
||||
|
||||
/* Pad to word boundary if needed */
|
||||
if (dst_idx & 1) {
|
||||
if (dst_idx & 1)
|
||||
{
|
||||
ble_buffer[dst_idx++] = 0;
|
||||
}
|
||||
|
||||
@@ -1117,8 +1127,6 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch)
|
||||
{
|
||||
if (ch > (MAA_NUM_CHANNELS - 1)) return DR_ADC_ERR_INVALID_PARAM;
|
||||
|
||||
if (g_plat.log) g_plat.log("[maa] capturing CH%u\r\n", ch);
|
||||
|
||||
dr_adc_err_t err = dr_adc_capture_channel_only(
|
||||
g_maa_ctx.freq_option,
|
||||
g_maa_ctx.delay_us,
|
||||
@@ -1129,21 +1137,6 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch)
|
||||
&g_maa_ctx.channels[ch]
|
||||
);
|
||||
|
||||
/* 캡처 성공 시 원시 데이터 덤프 (10진수) */
|
||||
if (err == DR_ADC_OK && g_plat.log)
|
||||
{
|
||||
dr_maa_channel_t *c = &g_maa_ctx.channels[ch];
|
||||
g_plat.log("[maa] CH%u raw (%u samples):\r\n", ch, c->num_samples);
|
||||
|
||||
for (uint16_t i = 0; i < c->num_samples; i++)
|
||||
{
|
||||
g_plat.log("%u ", c->samples[i]);
|
||||
if ((i + 1) % 16 == 0) g_plat.log("\r\n");
|
||||
}
|
||||
|
||||
if (c->num_samples % 16 != 0) g_plat.log("\r\n");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1176,13 +1169,25 @@ static void maa_async_send_header(void)
|
||||
buf[13] = (uint8_t)(ch->num_samples >> 8);
|
||||
|
||||
dr_binary_tx_safe(buf, 7); /* 14 bytes = 7 words */
|
||||
|
||||
/* 50ms BLE 대기 시간을 활용하여 raw 덤프 로그 (캡처 시간에 영향 없음)
|
||||
if (g_plat.log)
|
||||
{
|
||||
if (g_maa_ctx.current_ch > 0) g_plat.log("\r\n");
|
||||
g_plat.log("CH%u raw (%u samples):\r\n", g_maa_ctx.current_ch, ch->num_samples);
|
||||
for (uint16_t i = 0; i < ch->num_samples; i++)
|
||||
{
|
||||
g_plat.log("%u ", ch->samples[i]);
|
||||
if ((i + 1) % 16 == 0) g_plat.log("\r\n");
|
||||
}
|
||||
if (ch->num_samples % 16 != 0) g_plat.log("\r\n");
|
||||
}*/
|
||||
|
||||
dr_sd_delay_ms(50); /* Allow BLE stack to process TX */
|
||||
|
||||
g_maa_ctx.current_pkt = 0;
|
||||
g_maa_ctx.data_offset = 0;
|
||||
g_maa_ctx.state = MAA_ASYNC_TX_DATA;
|
||||
|
||||
ADC_LOG("maa_async: CH%u reb: sent (pkts=%u)", g_maa_ctx.current_ch, g_maa_ctx.total_packets);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1225,7 +1230,7 @@ static bool maa_async_send_data_packet(void)
|
||||
g_maa_ctx.data_offset += chunk_size;
|
||||
g_maa_ctx.current_pkt++;
|
||||
|
||||
ADC_LOG("maa_async: CH%u red:%u (%u/%u bytes)", g_maa_ctx.current_ch, pkt_idx, g_maa_ctx.data_offset, total_data_bytes);
|
||||
//ADC_LOG("maa_async: CH%u red:%u (%u/%u bytes)", g_maa_ctx.current_ch, pkt_idx, g_maa_ctx.data_offset, total_data_bytes);
|
||||
|
||||
return (g_maa_ctx.data_offset < total_data_bytes);
|
||||
}
|
||||
@@ -1246,15 +1251,13 @@ static void maa_async_send_completion(uint16_t status)
|
||||
|
||||
dr_binary_tx_safe(buf, 3);
|
||||
|
||||
/* 자동으로 켰으면 완료 후 전원 OFF */
|
||||
if (g_maa_ctx.auto_powered) {
|
||||
if (g_plat.log) g_plat.log("[Cmd_maa] TX/RX Active -> Sleep\r\n");
|
||||
dr_piezo_power_off();
|
||||
g_maa_ctx.auto_powered = false;
|
||||
}
|
||||
//if (g_plat.log) g_plat.log("-------------------------------------------------------------------------------------\r\n");
|
||||
|
||||
/* 캡처 완료 → Piezo TX/RX 전원 OFF */
|
||||
dr_piezo_power_off();
|
||||
|
||||
g_maa_ctx.state = MAA_ASYNC_IDLE;
|
||||
ADC_LOG("maa_async: complete, status=0x%04X", status);
|
||||
//ADC_LOG("maa_async: complete, status=0x%04X", status);
|
||||
|
||||
/* 완료 콜백 호출 (mbb? 등에서 센서 측정 체인 트리거용) */
|
||||
if (g_maa_ctx.on_complete_cb)
|
||||
@@ -1269,9 +1272,7 @@ static void maa_async_send_completion(uint16_t status)
|
||||
* PUBLIC ASYNC API
|
||||
*============================================================================*/
|
||||
|
||||
dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
|
||||
uint16_t num_samples, uint8_t cycles,
|
||||
uint16_t averaging, uint8_t *ble_buffer)
|
||||
dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us, uint16_t num_samples, uint8_t cycles, uint16_t averaging, uint8_t *ble_buffer)
|
||||
{
|
||||
dr_adc_err_t err;
|
||||
uint8_t ch;
|
||||
@@ -1298,28 +1299,25 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
|
||||
g_maa_ctx.data_offset = 0;
|
||||
g_maa_ctx.on_complete_cb = NULL; /* 기본: 콜백 없음 (maa?) */
|
||||
|
||||
ADC_LOG("maa_async_start: freq=%u delay=%u samples=%u cycles=%u avg=%u",
|
||||
freq_option, delay_us, num_samples, g_maa_ctx.cycles, g_maa_ctx.averaging);
|
||||
|
||||
/* 전채널 캡처: BLE 전송 없이 6채널 전부 캡처 완료 후 TX 시작 */
|
||||
g_maa_ctx.state = MAA_ASYNC_CAPTURING;
|
||||
|
||||
for (ch = 0; ch < MAA_NUM_CHANNELS; ch++)
|
||||
{
|
||||
err = maa_async_capture_channel(ch);
|
||||
if (err != DR_ADC_OK)
|
||||
{
|
||||
//ADC_LOG("maa_async_start: CH%u capture failed (%d)", ch, err);
|
||||
if (g_plat.log) g_plat.log("[maa] maa_async_start: CH%u capture failed (%d)", ch, err);
|
||||
maa_async_send_completion(0xFFF0 | ch);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
//ADC_LOG("maa_async_start: all channels captured, starting TX");
|
||||
if (g_plat.log) g_plat.log("[maa] maa_async_start: all channels captured, starting TX");
|
||||
|
||||
/* 캡처 완료 → 피에조 전원 OFF (BLE 전송 중 불필요) */
|
||||
/* peak 로그와 raw 덤프 사이 구분 */
|
||||
//if (g_plat.log) g_plat.log("\r\n");
|
||||
|
||||
/* 캡처 완료 → Piezo TX/RX 전원 OFF (BLE 전송 중 불필요) */
|
||||
dr_piezo_power_off();
|
||||
g_maa_ctx.auto_powered = false; /* 이미 껐으므로 완료 후 중복 OFF 방지 */
|
||||
|
||||
/* Send CH0 header - this will trigger TX_RDY for subsequent packets */
|
||||
maa_async_send_header();
|
||||
@@ -1398,11 +1396,6 @@ void maa_async_abort(void)
|
||||
}
|
||||
}
|
||||
|
||||
void maa_async_set_auto_power(bool on)
|
||||
{
|
||||
g_maa_ctx.auto_powered = on;
|
||||
}
|
||||
|
||||
void maa_async_set_on_complete(void (*cb)(void))
|
||||
{
|
||||
g_maa_ctx.on_complete_cb = cb;
|
||||
|
||||
@@ -454,7 +454,6 @@ typedef struct {
|
||||
dr_maa_channel_t channels[MAA_NUM_CHANNELS]; /**< Captured data for each channel */
|
||||
uint16_t total_packets; /**< Total packets for current channel */
|
||||
uint16_t data_packets; /**< Data packets for current channel */
|
||||
bool auto_powered; /**< true: 자동 전원 ON → 완료 후 OFF */
|
||||
bool pre_capture_all; /**< true: 전채널 캡처 완료 후 일괄 전송 (mbb용) */
|
||||
void (*on_complete_cb)(void); /**< 비동기 캡처 완료 후 호출될 콜백 (NULL이면 미사용) */
|
||||
} maa_async_ctx_t;
|
||||
|
||||
Reference in New Issue
Block a user