From f046393b9d8a65769f7fa5f7233c689c2d40a450 Mon Sep 17 00:00:00 2001
From: jhChun <linea150028@gmail.com>
Date: Mon, 30 Mar 2026 15:22:59 +0900
Subject: [PATCH] =?UTF-8?q?BLE=20=EC=97=B0=EA=B2=B0=20=EC=8B=A4=ED=8C=A8?=
 =?UTF-8?q?=20=EB=B0=9C=EC=83=9D=20=EC=8B=9C=20=EC=B6=94=EC=A0=81=EC=9D=84?=
 =?UTF-8?q?=20=EC=9C=84=ED=95=9C=20RTT=20=EB=A1=9C=EA=B7=B8=20=EC=B6=94?=
 =?UTF-8?q?=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 0: IMU 값 송신(msp)- 1: 배터리 SAADC 시작- 2: 배터리 콜백 완료(battery_event_handler)- 3: 배터리 대기 루프 탈출- 4: IMU 읽기 완료- 5: Piezo RX/TX Active- 6: 온도 SAADC 시작- 7: 온도 콜백 완료(tmp235_voltage_handler)- 8: 온도 대기 루프 탈출- 9: rbb: 패킷 전송- 10: Piezo 캡처 시작(maa_async_start)- 11: 전체 종료(mbb)
---
 pc_firm/parser.c                                     | 12 +++++++++++-
 .../ble_app_bladder_patch/battery_saadc.c            |  1 +
 .../icm42670p/app_raw/app_raw.c                      |  5 +++--
 .../ble_peripheral/ble_app_bladder_patch/tmp235_q1.c |  1 +
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/pc_firm/parser.c b/pc_firm/parser.c
index ee1676b..6324fa7 100644
--- a/pc_firm/parser.c
+++ b/pc_firm/parser.c
@@ -26,6 +26,7 @@
 #include <string.h>
 
 #include "nrf_gpio.h"
+#include "debug_print.h"
 #include "nrf_delay.h"
 #include "dr_piezo.h"
 #include "dr_util.h"
@@ -1010,30 +1011,36 @@ static void all_sensors(void)
     info4 = true;  /* 센서값을 전역 변수에 저장 (BLE 전송 안 함) */
 
     /* 1. 배터리 전압 측정 → info_batt에 저장 */
+    DBG_PRINTF("1");
     battery_saadc_done = false;
     battery_level_meas();
     for (timeout_cnt = 0; !battery_saadc_done && timeout_cnt < 100; timeout_cnt++)
     {
         dr_sd_delay_ms(1);  /* 콜백 오면 즉시 탈출, 최대 100ms */
     }
+    DBG_PRINTF("3");
 
     /* 2. IMU 6축 단발 읽기 → info_imu[6]에 저장 */
     hw_i2c_init_once();
     imu_read_direct();
+    DBG_PRINTF("4");
 
     /* 3. 온도 측정 → info_temp에 저장 (TMP235는 Piezo TX/RX 전원 필요) */
     if (!dr_piezo_is_power_on())
     {
         dr_piezo_power_on();
     }
+    DBG_PRINTF("5");
 
+    DBG_PRINTF("6");
     tmp235_saadc_done = false;
     tmp235_voltage_level_meas();
-    
+
     for (timeout_cnt = 0; !tmp235_saadc_done && timeout_cnt < 100; timeout_cnt++)
     {
         dr_sd_delay_ms(1);  /* 콜백 오면 즉시 탈출, 최대 100ms, 타임아웃 시 이전 값 또는 쓰레기값.. */
     }
+    DBG_PRINTF("8");
 
     info4 = false;
 
@@ -1054,6 +1061,7 @@ static void all_sensors(void)
     buf[19] = (uint8_t)(info_temp >> 8);
     
     dr_binary_tx_safe(buf, 10);  /* 20바이트 = 10워드 */
+    DBG_PRINTF("9");
 
     /* 배터리, IMU, 온도 확인용 로그 */
     //if (g_plat.log) g_plat.log("-------------------------------------------------------------------------------------\r\n[Battery] %u\r\n[IMU] %d,%d,%d,%d,%d,%d\r\n[Temperature] %u\r\n\r\n", info_batt, (int16_t)info_imu[0], (int16_t)info_imu[1], (int16_t)info_imu[2],
@@ -1077,6 +1085,7 @@ static int Cmd_mbb(const ParsedCmd *cmd)
     dr_adc_err_t err;
 
     all_sensors();  /* 배터리, IMU, 온도 센서 먼저 측정 */
+    DBG_PRINTF("10");
 
     if (maa_async_is_busy())
     {
@@ -1111,6 +1120,7 @@ static int Cmd_mbb(const ParsedCmd *cmd)
         dr_piezo_power_off();
         return 1;
     }
+    DBG_PRINTF("11\n");
 
     return 1;
 }
diff --git a/project/ble_peripheral/ble_app_bladder_patch/battery_saadc.c b/project/ble_peripheral/ble_app_bladder_patch/battery_saadc.c
index 4107fc6..22c6250 100644
--- a/project/ble_peripheral/ble_app_bladder_patch/battery_saadc.c
+++ b/project/ble_peripheral/ble_app_bladder_patch/battery_saadc.c
@@ -143,6 +143,7 @@ void battery_event_handler( nrf_drv_saadc_evt_t const * p_event )
 		nrf_drv_saadc_uninit();
 
 		/* 콜백 완료 알림 (all_sensors 대기 해제용) */
+		if (info4) DBG_PRINTF("2");
 		battery_saadc_done = true;
 
 		/* ADC값 → mV 변환 (매크로: ADC x 600/1023 x 6) */
diff --git a/project/ble_peripheral/ble_app_bladder_patch/icm42670p/app_raw/app_raw.c b/project/ble_peripheral/ble_app_bladder_patch/icm42670p/app_raw/app_raw.c
index 29fbb4d..08985f4 100644
--- a/project/ble_peripheral/ble_app_bladder_patch/icm42670p/app_raw/app_raw.c
+++ b/project/ble_peripheral/ble_app_bladder_patch/icm42670p/app_raw/app_raw.c
@@ -381,7 +381,7 @@ void imu_callback(inv_imu_sensor_event_t *event)
 
 		/* UART 모드: "Tp" 접두사로 6축 데이터를 텍스트 형식으로 출력 */
 		else if(cmd_type_t == CMD_UART) {
-			DBG_PRINTF("Tp%d,%d,%d,%d,%d,%d\r\n\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2]);
+			//DBG_PRINTF("Tp%d,%d,%d,%d,%d,%d\r\n\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2]);
 		}
 
 		/*
@@ -399,7 +399,7 @@ void imu_callback(inv_imu_sensor_event_t *event)
 			ssp_data[5] = (uint16_t)gyro[2];
 
 			format_data(imu_bin_buffer, "rsp:", ssp_data,12);
-			DBG_PRINTF("Tp%d,%d,%d,%d,%d,%d\r\n\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2]);
+			//DBG_PRINTF("Tp%d,%d,%d,%d,%d,%d\r\n\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2]);
 			dr_binary_tx_safe(imu_bin_buffer,8);
 
 			if(custom_add_data==true) {
@@ -569,6 +569,7 @@ int imu_read_direct(void)
 		/* 일반 모드: "rsp:" 태그로 BLE 즉시 전송 */
 		format_data(imu_bin_buffer, "rsp:", ssp_data, 12);
 		dr_binary_tx_safe(imu_bin_buffer, 8);
+		DBG_PRINTF("0");
 	}
 
 	/* IMU 슬립 모드: PWR_MGMT0 = 0x00 → 가속도/자이로 모두 OFF (전력 절감) */
diff --git a/project/ble_peripheral/ble_app_bladder_patch/tmp235_q1.c b/project/ble_peripheral/ble_app_bladder_patch/tmp235_q1.c
index ae6f286..b6bc40d 100644
--- a/project/ble_peripheral/ble_app_bladder_patch/tmp235_q1.c
+++ b/project/ble_peripheral/ble_app_bladder_patch/tmp235_q1.c
@@ -164,6 +164,7 @@ void tmp235_voltage_handler(nrf_drv_saadc_evt_t const * p_event)	/* TMP325 Vout
 //			data_tx_handler(ble_tx_buffer);
 		}
 
+		DBG_PRINTF("7");
 		tmp235_saadc_done = true;
     }
 
