maa samples 140->100 변경, mec/maa 수신 시 Piezo 자동 Active/Sleep
- MAA_NUM_SAMPLES 140에서 100으로 변경 (DR_ADC_ECHO_SAMPLES_MAX 제한) - 단일(mec) 및 모든 채널(maa) 에코 캡처 명령 수신 시 Piezo 자동 Active, 응답 송신 후 Sleep - Cmd_mpa 중복 호출 정리 (dr_piezo_system_init 내부에 power_on 포함) - 채널별 디버그 로그 추가 - 코드 리뷰 주석 정리 및 기타 파일 업데이트 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -111,6 +111,7 @@ extern config_data_t m_config; /* 전체 설정 구조체 (FDS 저장 대
|
||||
/* 피에조 초음파 트랜스듀서 제어 함수 */
|
||||
extern void dr_piezo_power_on( void ); /* 피에조 회로 전원 ON (TX/RX 보드) */
|
||||
extern void dr_piezo_power_off( void ); /* 피에조 회로 전원 OFF */
|
||||
extern bool dr_piezo_is_power_on( void ); /* 피에조 전원 상태 확인 */
|
||||
extern void dr_piezo_burst_sw(uint8_t cycles); /* 2.1MHz 버스트 펄스 발생 (기본 주파수) */
|
||||
extern void dr_piezo_burst_sw_18mhz(uint8_t cycles); /* 1.8MHz 버스트 펄스 발생 */
|
||||
extern void dr_piezo_burst_sw_20mhz(uint8_t cycles); /* 2.0MHz 버스트 펄스 발생 */
|
||||
@@ -436,7 +437,7 @@ static CmdEntry g_cmd_table[] = {
|
||||
|
||||
/* D. 각종 센서 측정 */
|
||||
{ "msn?", true, Cmd_msn },
|
||||
{ "mso?", false, Cmd_mso },
|
||||
{ "mso?", true, Cmd_mso },
|
||||
{ "msp?", true, Cmd_msp },
|
||||
{ "msi?", true, Cmd_msi },
|
||||
|
||||
@@ -511,7 +512,7 @@ static int dr_cmd_dispatch(const ParsedCmd *cmd)
|
||||
int dr_cmd_parser(const uint8_t *buf, uint8_t len)
|
||||
{
|
||||
ParsedCmd cmd;
|
||||
g_plat.log("parser!!!!!!!!");
|
||||
g_plat.log("parser!!!!!!!!\r\n");
|
||||
|
||||
if (g_plat.log) g_plat.log("[PARSER] in len=%u crc=%u\r\n", len, g_plat.crc_check);
|
||||
|
||||
@@ -614,9 +615,7 @@ static int Cmd_msq(const ParsedCmd *cmd)
|
||||
{
|
||||
uint16_t val = 0;
|
||||
dr_get_u16(cmd, 0, &val);
|
||||
if (g_plat.log && g_log_enable) {
|
||||
g_plat.log("[Cmd_msq] Power off\r\n");
|
||||
}
|
||||
if (g_plat.log) g_plat.log("[Cmd_msq] Power off val=%u\r\n", val);
|
||||
single_format_data(ble_bin_buffer, "rsq:", val);
|
||||
dr_binary_tx_safe(ble_bin_buffer, 2);
|
||||
go_device_power_off = true; /* 메인 루프에서 전원 OFF 실행 예약 */
|
||||
@@ -637,9 +636,7 @@ static int Cmd_msr(const ParsedCmd *cmd)
|
||||
{
|
||||
uint16_t val = 0;
|
||||
dr_get_u16(cmd, 0, &val);
|
||||
if (g_plat.log && g_log_enable) {
|
||||
g_plat.log("[Cmd_msr] Bond delete + reset\r\n");
|
||||
}
|
||||
if (g_plat.log) g_plat.log("[Cmd_msr] Bond delete + reset val=%u\r\n", val);
|
||||
single_format_data(ble_bin_buffer, "rsr:", val);
|
||||
dr_binary_tx_safe(ble_bin_buffer, 2);
|
||||
|
||||
@@ -665,9 +662,7 @@ static int Cmd_mss(const ParsedCmd *cmd)
|
||||
{
|
||||
uint16_t val = 0;
|
||||
dr_get_u16(cmd, 0, &val);
|
||||
if (g_plat.log && g_log_enable) {
|
||||
g_plat.log("[Cmd_mss] Device reset\r\n");
|
||||
}
|
||||
if (g_plat.log) g_plat.log("[Cmd_mss] Device reset val=%u\r\n", val);
|
||||
single_format_data(ble_bin_buffer, "rss:", val);
|
||||
dr_binary_tx_safe(ble_bin_buffer, 2);
|
||||
|
||||
@@ -712,8 +707,7 @@ static int Cmd_mpa(const ParsedCmd *cmd)
|
||||
g_plat.log("[Cmd_mpa] Piezo Activation\n");
|
||||
}
|
||||
|
||||
dr_piezo_power_on(); /* 피에조 보드 전원 ON (LDO 활성화) */
|
||||
dr_piezo_system_init(); /* 피에조 시스템 초기화 (DAC/MUX/ADC 설정) */
|
||||
dr_piezo_system_init(); /* 내부에서 power_on + init 수행 */
|
||||
|
||||
if (g_plat.tx_bin) {
|
||||
single_format_data(ble_bin_buffer, "rpa:", 1);
|
||||
@@ -777,8 +771,8 @@ static int Cmd_mpc(const ParsedCmd *cmd)
|
||||
(void)dr_get_u16(cmd, 1, &freq_option); /* word 1: 주파수 옵션 */
|
||||
(void)dr_get_u16(cmd, 2, &piezo_ch); /* word 2: 피에조 채널 */
|
||||
|
||||
/* 채널 범위 검증: 0~7 유효, 초과 시 0으로 리셋 */
|
||||
if (piezo_ch > 7) piezo_ch = 0;
|
||||
/* 채널 범위 검증: 초과 시 0으로 리셋 */
|
||||
if (piezo_ch >= MAA_NUM_CHANNELS) piezo_ch = 0;
|
||||
|
||||
if (g_plat.log && g_log_enable) {
|
||||
const char *freq_str = (freq_option == 0) ? "1.8MHz" :
|
||||
@@ -851,6 +845,14 @@ static int Cmd_mec(const ParsedCmd *cmd)
|
||||
uint16_t averaging = 1; /* 기본 1 (평균화 없음), 최대 1000 */
|
||||
uint16_t piezo_ch = 0; /* 기본 채널 0 (유효: 0~7) */
|
||||
|
||||
/* 피에조 전원이 꺼져 있으면 자동으로 켜기 */
|
||||
bool auto_powered = false;
|
||||
if (!dr_piezo_is_power_on()) {
|
||||
if (g_plat.log) g_plat.log("[Cmd_mec] TX/RX Sleep -> Active\r\n");
|
||||
dr_piezo_system_init();
|
||||
auto_powered = true;
|
||||
}
|
||||
|
||||
/* 6개 파라미터 순서대로 추출 (데이터 부족 시 기본값 유지) */
|
||||
(void)dr_get_u16(cmd, 0, &freq_option); /* word 0: 주파수 옵션 */
|
||||
(void)dr_get_u16(cmd, 1, &delay_us); /* word 1: 버스트→ADC 딜레이 */
|
||||
@@ -863,8 +865,8 @@ static int Cmd_mec(const ParsedCmd *cmd)
|
||||
if (averaging == 0) averaging = 1;
|
||||
if (averaging > 1000) averaging = 1000;
|
||||
|
||||
/* 피에조 채널 범위 검증: 0~7 */
|
||||
if (piezo_ch > 7) piezo_ch = 0;
|
||||
/* 피에조 채널 범위 검증 */
|
||||
if (piezo_ch >= MAA_NUM_CHANNELS) piezo_ch = 0;
|
||||
|
||||
if (g_plat.log && g_log_enable) {
|
||||
const char *freq_str = (freq_option == 0) ? "1.8MHz" :
|
||||
@@ -877,18 +879,10 @@ static int Cmd_mec(const ParsedCmd *cmd)
|
||||
freq_option, freq_str, delay_us, num_samples, cycles, averaging, piezo_ch);
|
||||
}
|
||||
|
||||
/* 통합 버스트+캡처+전송 함수 호출
|
||||
* 내부 동작 순서:
|
||||
* 1. ADC 전원 ON
|
||||
* 2. MUX로 피에조 채널 선택 (0~7)
|
||||
* 3. 주파수별 버스트 펄스 발생 (freq_option에 따라)
|
||||
* 4. delay_us 후 ADC 캡처 (averaging 횟수만큼 반복)
|
||||
* 5. 캡처된 샘플 평균화 (노이즈 저감)
|
||||
* 6. BLE 멀티패킷 전송 (패킷 간 타이밍 자동 관리)
|
||||
*/
|
||||
/* 통합 버스트+캡처+전송 함수 호출 */
|
||||
dr_adc_err_t err = dr_adc_burst_capture_transmit(
|
||||
(uint8_t)freq_option, delay_us, num_samples, (uint8_t)cycles,
|
||||
(uint16_t)averaging, (uint8_t)piezo_ch, ble_bin_buffer, 0); /* 0=raa 태그로 전송 */
|
||||
(uint16_t)averaging, (uint8_t)piezo_ch, ble_bin_buffer, 0);
|
||||
|
||||
/* 에러 발생 시 에러 코드 + 요청 샘플 수 응답 */
|
||||
if (err != DR_ADC_OK) {
|
||||
@@ -899,6 +893,12 @@ static int Cmd_mec(const ParsedCmd *cmd)
|
||||
g_plat.log("[Cmd_mec] result=%d\r\n", err);
|
||||
}
|
||||
|
||||
/* 자동으로 켰으면 완료 후 전원 OFF */
|
||||
if (auto_powered) {
|
||||
if (g_plat.log) g_plat.log("[Cmd_mec] TX/RX Active -> Sleep\r\n");
|
||||
dr_piezo_power_off();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -981,7 +981,7 @@ static int Cmd_cmd(const ParsedCmd *cmd)
|
||||
*/
|
||||
#define MAA_FREQ_OPTION 1 /* 기본 2.1MHz */
|
||||
#define MAA_DELAY_US 10 /* 버스트 후 10us 딜레이 */
|
||||
#define MAA_NUM_SAMPLES 140 /* 140샘플 (약 25cm 거리) */
|
||||
#define MAA_NUM_SAMPLES 100 /* 140샘플 (약 25cm 거리) */
|
||||
#define MAA_CYCLES 7 /* 7사이클 버스트 */
|
||||
#define MAA_AVERAGING 5 /* 5회 평균화 */
|
||||
|
||||
@@ -1005,11 +1005,22 @@ static int Cmd_maa(const ParsedCmd *cmd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 피에조 전원이 꺼져 있으면 자동으로 켜기 */
|
||||
bool auto_powered = false;
|
||||
bool pwr = dr_piezo_is_power_on();
|
||||
if (g_plat.log) g_plat.log("[Cmd_maa] piezo_power=%u\r\n", pwr);
|
||||
if (!pwr) {
|
||||
if (g_plat.log) g_plat.log("[Cmd_maa] TX/RX Sleep -> Active\r\n");
|
||||
dr_piezo_system_init();
|
||||
auto_powered = true;
|
||||
}
|
||||
|
||||
/*=======================================================================
|
||||
* 비동기 4채널 캡처 시작
|
||||
* 비동기 6채널 캡처 시작
|
||||
* - maa_async_start(): CH0 캡처 실행 + 첫 헤더 패킷 전송
|
||||
* - 이후 패킷은 BLE_NUS_EVT_TX_RDY 콜백에서 자동 전송
|
||||
* - 블로킹 딜레이 없음 → SoftDevice 이벤트 정상 처리 가능
|
||||
* - auto_powered=true면 완료 후 자동 전원 OFF
|
||||
*=======================================================================*/
|
||||
err = maa_async_start(
|
||||
(uint8_t)MAA_FREQ_OPTION,
|
||||
@@ -1021,12 +1032,19 @@ static int Cmd_maa(const ParsedCmd *cmd)
|
||||
);
|
||||
|
||||
if (err != DR_ADC_OK) {
|
||||
/* 시작 실패 → maa_async_start 내부에서 에러 응답 이미 전송됨 */
|
||||
/* 시작 실패 → 에러 응답 전송 (앱 타임아웃 방지) */
|
||||
if (g_plat.log) g_plat.log("[Cmd_maa] start failed err=%d\r\n", err);
|
||||
single_format_data(ble_bin_buffer, "raa:", (uint16_t)(0xFF00 | err));
|
||||
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||
if (auto_powered) dr_piezo_power_off();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 자동 전원 플래그 설정 → 비동기 완료 시 자동 OFF */
|
||||
maa_async_set_auto_power(auto_powered);
|
||||
|
||||
/* 즉시 반환 → 비동기 전송 진행 중 */
|
||||
/* 전체 완료 시 상태 머신이 "raa:" 응답을 자동 전송 */
|
||||
/* 전체 완료 시 상태 머신이 "raa:" 응답 + 자동 power off 처리 */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1119,10 +1137,7 @@ static int Cmd_mrs(const ParsedCmd *cmd)
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
* 패스키 / 수명 카운터 (FDS)
|
||||
*
|
||||
* 패스키: BLE 페어링 시 사용하는 6자리 숫자 (예: "123456")
|
||||
* 수명 카운터: 디바이스 사용 횟수 추적 (uint32, 상위16+하위16으로 분할 전송)
|
||||
*============================================================================*/
|
||||
|
||||
/* mpz? - BLE 패스키 FDS에 쓰기
|
||||
@@ -1154,6 +1169,8 @@ static int Cmd_mqz(const ParsedCmd *cmd)
|
||||
(void)cmd;
|
||||
memcpy(m_static_passkey, m_config.static_passkey, 6);
|
||||
|
||||
if (g_plat.log) g_plat.log("[mqz] Passkey read: %.6s\r\n", m_static_passkey);
|
||||
|
||||
ascii_format_data(ble_bin_buffer, "rqz:", m_static_passkey, 6);
|
||||
dr_binary_tx_safe(ble_bin_buffer, 5);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user