- FDS 피에조 파라미터 구조체 변경 (pd_adc_cnt/pd_delay_us 삭제, piezo 5개 필드 추가)
- maa/mbb 앱 파라미터 수신 → FDS 저장 기능 추가 - magic_number 변경 (0x20260319), cycles 범위 3~7로 제한 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,7 @@ extern void dr_piezo_power_off(void);
|
||||
/*==============================================================================
|
||||
* DEBUG CONFIGURATION
|
||||
*============================================================================*/
|
||||
#define DEBUG_ADC
|
||||
#ifdef DEBUG_ADC
|
||||
#include "nrf_log.h"
|
||||
#define ADC_LOG(...) NRF_LOG_INFO(__VA_ARGS__)
|
||||
@@ -1330,7 +1331,7 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch)
|
||||
|
||||
if (g_plat.log) g_plat.log("[maa] capturing CH%u\r\n", ch);
|
||||
|
||||
return dr_adc_capture_channel_only(
|
||||
dr_adc_err_t err = dr_adc_capture_channel_only(
|
||||
g_maa_ctx.freq_option,
|
||||
g_maa_ctx.delay_us,
|
||||
g_maa_ctx.num_samples,
|
||||
@@ -1339,6 +1340,23 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch)
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1387,9 +1405,10 @@ static bool maa_async_send_data_packet(void)
|
||||
{
|
||||
dr_maa_channel_t *ch = &g_maa_ctx.channels[g_maa_ctx.current_ch];
|
||||
uint8_t *buf = g_maa_ctx.ble_buffer;
|
||||
|
||||
uint16_t total_data_bytes = ch->num_samples * 2;
|
||||
if (g_maa_ctx.data_offset >= total_data_bytes) {
|
||||
|
||||
if (g_maa_ctx.data_offset >= total_data_bytes)
|
||||
{
|
||||
return false; /* All data sent */
|
||||
}
|
||||
|
||||
@@ -1405,7 +1424,8 @@ static bool maa_async_send_data_packet(void)
|
||||
/* Copy sample data */
|
||||
uint16_t src_sample_idx = g_maa_ctx.data_offset / 2;
|
||||
uint16_t dst_idx = 6;
|
||||
for (uint16_t i = 0; i < chunk_size / 2 && src_sample_idx < ch->num_samples; i++, src_sample_idx++) {
|
||||
for (uint16_t i = 0; i < chunk_size / 2 && src_sample_idx < ch->num_samples; i++, src_sample_idx++)
|
||||
{
|
||||
uint16_t sample = ch->samples[src_sample_idx];
|
||||
buf[dst_idx++] = (uint8_t)(sample & 0xFF);
|
||||
buf[dst_idx++] = (uint8_t)(sample >> 8);
|
||||
@@ -1417,8 +1437,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);
|
||||
}
|
||||
@@ -1450,7 +1469,8 @@ static void maa_async_send_completion(uint16_t status)
|
||||
ADC_LOG("maa_async: complete, status=0x%04X", status);
|
||||
|
||||
/* 완료 콜백 호출 (mbb? 등에서 센서 측정 체인 트리거용) */
|
||||
if (g_maa_ctx.on_complete_cb) {
|
||||
if (g_maa_ctx.on_complete_cb)
|
||||
{
|
||||
void (*cb)(void) = g_maa_ctx.on_complete_cb;
|
||||
g_maa_ctx.on_complete_cb = NULL; /* 1회성: 재호출 방지 */
|
||||
cb();
|
||||
@@ -1465,7 +1485,8 @@ 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)
|
||||
{
|
||||
if (g_maa_ctx.state != MAA_ASYNC_IDLE) {
|
||||
if (g_maa_ctx.state != MAA_ASYNC_IDLE)
|
||||
{
|
||||
ADC_LOG("maa_async_start: busy");
|
||||
return DR_ADC_ERR_NOT_INIT; /* Already running */
|
||||
}
|
||||
@@ -1492,7 +1513,9 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
|
||||
/* Capture CH0 */
|
||||
g_maa_ctx.state = MAA_ASYNC_CAPTURING;
|
||||
dr_adc_err_t err = maa_async_capture_channel(0);
|
||||
if (err != DR_ADC_OK) {
|
||||
|
||||
if (err != DR_ADC_OK)
|
||||
{
|
||||
ADC_LOG("maa_async_start: CH0 capture failed (%d)", err);
|
||||
maa_async_send_completion(0xFFF0);
|
||||
return err;
|
||||
@@ -1506,26 +1529,34 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
|
||||
|
||||
bool maa_async_on_tx_ready(void)
|
||||
{
|
||||
if (g_maa_ctx.state == MAA_ASYNC_IDLE) {
|
||||
if (g_maa_ctx.state == MAA_ASYNC_IDLE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (g_maa_ctx.state) {
|
||||
case MAA_ASYNC_TX_DATA:
|
||||
/* Send next data packet */
|
||||
if (!maa_async_send_data_packet()) {
|
||||
if (!maa_async_send_data_packet())
|
||||
{
|
||||
/* Current channel done, move to next */
|
||||
g_maa_ctx.current_ch++;
|
||||
if (g_maa_ctx.current_ch >= MAA_NUM_CHANNELS) {
|
||||
|
||||
if (g_maa_ctx.current_ch >= MAA_NUM_CHANNELS)
|
||||
{
|
||||
/* All channels done */
|
||||
g_maa_ctx.state = MAA_ASYNC_COMPLETE;
|
||||
maa_async_send_completion(0x0000);
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Capture next channel */
|
||||
g_maa_ctx.state = MAA_ASYNC_CAPTURING;
|
||||
dr_adc_err_t err = maa_async_capture_channel(g_maa_ctx.current_ch);
|
||||
if (err != DR_ADC_OK) {
|
||||
|
||||
if (err != DR_ADC_OK)
|
||||
{
|
||||
ADC_LOG("maa_async: CH%u capture failed", g_maa_ctx.current_ch);
|
||||
maa_async_send_completion(0xFFF0 | g_maa_ctx.current_ch);
|
||||
return false;
|
||||
|
||||
@@ -976,17 +976,30 @@ static int Cmd_cmd(const ParsedCmd *cmd)
|
||||
|
||||
static int Cmd_maa(const ParsedCmd *cmd)
|
||||
{
|
||||
uint16_t mode = 0;
|
||||
dr_adc_err_t err;
|
||||
|
||||
/* mode 파라미터 추출 */
|
||||
(void)dr_get_u16(cmd, 0, &mode);
|
||||
/* 파라미터 5개 수신 시 FDS에 저장 — 디버그 중 비활성화
|
||||
if (cmd->data_len >= 10) {
|
||||
uint16_t freq, cycles, averaging, delay_us, num_samples;
|
||||
dr_get_u16(cmd, 0, &freq);
|
||||
dr_get_u16(cmd, 1, &cycles);
|
||||
dr_get_u16(cmd, 2, &averaging);
|
||||
dr_get_u16(cmd, 3, &delay_us);
|
||||
dr_get_u16(cmd, 4, &num_samples);
|
||||
|
||||
/* mode 검증 - mode 0(비동기 원시)만 지원 */
|
||||
if (mode > 0) {
|
||||
dr_ble_return_1("raa:", 0xFFFF); /* 미지원 모드 에러 */
|
||||
return 1;
|
||||
m_config.piezo_freq_option = (uint8_t)freq;
|
||||
m_config.piezo_cycles = (uint8_t)cycles;
|
||||
m_config.piezo_averaging = averaging;
|
||||
m_config.piezo_delay_us = delay_us;
|
||||
m_config.piezo_num_samples = num_samples;
|
||||
config_save();
|
||||
|
||||
if (g_plat.log) g_plat.log("[Cmd_maa] params updated: freq=%u cyc=%u avg=%u delay=%u samples=%u\r\n",
|
||||
m_config.piezo_freq_option, m_config.piezo_cycles,
|
||||
m_config.piezo_averaging, m_config.piezo_delay_us,
|
||||
m_config.piezo_num_samples);
|
||||
}
|
||||
*/
|
||||
|
||||
/* 이전 캡처가 진행 중인지 확인 (비동기이므로 중복 실행 방지) */
|
||||
if (maa_async_is_busy()) {
|
||||
@@ -1108,16 +1121,30 @@ static void all_sensors(void)
|
||||
*/
|
||||
static int Cmd_mbb(const ParsedCmd *cmd)
|
||||
{
|
||||
uint16_t mode = 0;
|
||||
dr_adc_err_t err;
|
||||
|
||||
(void)dr_get_u16(cmd, 0, &mode);
|
||||
/* 파라미터 5개 수신 시 FDS에 저장 — 디버그 중 비활성화
|
||||
if (cmd->data_len >= 10) {
|
||||
uint16_t freq, cycles, averaging, delay_us, num_samples;
|
||||
dr_get_u16(cmd, 0, &freq);
|
||||
dr_get_u16(cmd, 1, &cycles);
|
||||
dr_get_u16(cmd, 2, &averaging);
|
||||
dr_get_u16(cmd, 3, &delay_us);
|
||||
dr_get_u16(cmd, 4, &num_samples);
|
||||
|
||||
if (mode > 0)
|
||||
{
|
||||
dr_ble_return_1("raa:", 0xFFFF);
|
||||
return 1;
|
||||
m_config.piezo_freq_option = (uint8_t)freq;
|
||||
m_config.piezo_cycles = (uint8_t)cycles;
|
||||
m_config.piezo_averaging = averaging;
|
||||
m_config.piezo_delay_us = delay_us;
|
||||
m_config.piezo_num_samples = num_samples;
|
||||
config_save();
|
||||
|
||||
if (g_plat.log) g_plat.log("[Cmd_mbb] params updated: freq=%u cyc=%u avg=%u delay=%u samples=%u\r\n",
|
||||
m_config.piezo_freq_option, m_config.piezo_cycles,
|
||||
m_config.piezo_averaging, m_config.piezo_delay_us,
|
||||
m_config.piezo_num_samples);
|
||||
}
|
||||
*/
|
||||
|
||||
all_sensors();
|
||||
|
||||
@@ -1134,6 +1161,11 @@ static int Cmd_mbb(const ParsedCmd *cmd)
|
||||
dr_piezo_system_init();
|
||||
}
|
||||
|
||||
if (g_plat.log) g_plat.log("[Cmd_mbb] freq=%u cyc=%u avg=%u delay=%u samples=%u\r\n",
|
||||
m_config.piezo_freq_option, m_config.piezo_cycles,
|
||||
m_config.piezo_averaging, m_config.piezo_delay_us,
|
||||
m_config.piezo_num_samples);
|
||||
|
||||
/* 비동기 6채널 캡처 시작 (m_config 파라미터 사용) */
|
||||
err = maa_async_start(
|
||||
m_config.piezo_freq_option,
|
||||
|
||||
Reference in New Issue
Block a user