From aa8d8f698f43e20ede1bc4c8acb0f6b8d1d6dd85 Mon Sep 17 00:00:00 2001 From: jhchun Date: Mon, 1 Jun 2026 12:45:13 +0900 Subject: [PATCH] =?UTF-8?q?ADC=20raw=20data=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=ED=8C=A8=ED=82=B7(reb:)=20=EC=B1=84=EB=84=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [ch info 2B] = [ch session 1B] + [ch num 1B] - 동일한 ch session을 가진 reb: 패킷들을 하나의 측정 세트로 판단 - ch num 값으로 채널별 ADC raw data 구분 - session 불일치 또는 중복 채널 수신 시 해당 세트는 무효 처리 가능 --- .../measurement/adc121s051/dr_adc121s051.c | 26 ++++++++++++++----- .../measurement/adc121s051/dr_adc121s051.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.c b/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.c index e45d8b0..304348b 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.c +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.c @@ -152,6 +152,8 @@ static uint16_t clamp_measure_delay_us(uint16_t delay_us) #define BLE_RDB_HEADER_LEN 8 /* "rdb:" tag(4) + num_samples(2) + compressed_size(2) */ #define BLE_REB_DATA_LEN (BLE_MTU_SIZE - BLE_REB_HEADER_LEN) /* 238 bytes = 119 samples */ #define BLE_RED_DATA_LEN (BLE_MTU_SIZE - BLE_RED_HEADER_LEN) /* 238 bytes = 119 samples */ +#define MAA_REB_HEADER_LEN 8 /* "reb:" tag(4) + ch_info(2) + num_samples(2) */ +#define MAA_REB_DATA_LEN (BLE_MTU_SIZE - MAA_REB_HEADER_LEN) /* 236 bytes = 118 samples */ #define BLE_PACKET_DELAY_MS 100 /* Inter-packet delay - allow BLE TX buffer to drain */ /* maa_async: inter-packet busy-wait (0 = rely on BLE_NUS_EVT_TX_RDY only). */ #define MAA_ASYNC_POST_REB_MS 0U @@ -1162,6 +1164,7 @@ dr_adc_err_t dr_adc_transmit_channel_delta(const dr_maa_channel_t *ch_data, uint /* Global async context */ static maa_async_ctx_t g_maa_ctx = { .state = MAA_ASYNC_IDLE }; +static uint8_t g_maa_ch_session = 0; /* (reb+red merged protocol) */ @@ -1202,7 +1205,8 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch) /** * @brief Send reb: header + data merged for current channel * - * reb: tag(4) + num_samples(2) + data(up to 238 bytes) + * reb: tag(4) + ch_info(2) + num_samples(2) + data(up to 236 bytes) + * ch_info: session(1) + channel(1) * If <= 100 samples (200B), the channel completes in this single packet */ static bool maa_async_send_header(void) @@ -1212,16 +1216,23 @@ static bool maa_async_send_header(void) uint32_t tx_err; uint16_t total_data_bytes = ch->num_samples * 2; + uint16_t ch_info = ((uint16_t)g_maa_ctx.ch_session << 8) | g_maa_ctx.current_ch; - /* reb: header + data merged (Big-Endian) */ + /* reb: header + channel info + data merged (Big-Endian) */ buf[0] = 'r'; buf[1] = 'e'; buf[2] = 'b'; buf[3] = ':'; - buf[4] = (uint8_t)(ch->num_samples >> 8); - buf[5] = (uint8_t)(ch->num_samples & 0xFF); + buf[4] = (uint8_t)(ch_info >> 8); + buf[5] = (uint8_t)(ch_info & 0xFF); + buf[6] = (uint8_t)(ch->num_samples >> 8); + buf[7] = (uint8_t)(ch->num_samples & 0xFF); + ADC_LOG("reb ch_info: session=%u, ch=%u, value=0x%04X", + g_maa_ctx.ch_session, + g_maa_ctx.current_ch, + ch_info); - uint16_t dst_idx = BLE_REB_HEADER_LEN; - uint16_t first_chunk = (total_data_bytes > BLE_REB_DATA_LEN) ? BLE_REB_DATA_LEN : total_data_bytes; + uint16_t dst_idx = MAA_REB_HEADER_LEN; + uint16_t first_chunk = (total_data_bytes > MAA_REB_DATA_LEN) ? MAA_REB_DATA_LEN : total_data_bytes; uint16_t src_idx = 0; - while (src_idx < ch->num_samples && (dst_idx - BLE_REB_HEADER_LEN) < first_chunk) + while (src_idx < ch->num_samples && (dst_idx - MAA_REB_HEADER_LEN) < first_chunk) { uint16_t sample = ch->samples[src_idx++]; buf[dst_idx++] = (uint8_t)(sample >> 8); @@ -1376,6 +1387,7 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us, uint16_t nu g_maa_ctx.ble_buffer = ble_buffer; g_maa_ctx.current_ch = 0; g_maa_ctx.current_pkt = 0; + g_maa_ctx.ch_session = g_maa_ch_session++; g_maa_ctx.data_offset = 0; g_maa_ctx.on_complete_cb = NULL; /* default: no callback (maa?) */ diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h b/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h index ef31687..dddfe80 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h @@ -434,6 +434,7 @@ typedef struct { maa_async_state_t state; /**< Current state */ uint8_t current_ch; /**< Current channel (0~7) */ uint8_t current_pkt; /**< Current packet index */ + uint8_t ch_session; /**< reb: channel session id for one measurement set */ uint16_t data_offset; /**< Bytes sent so far for current channel */ uint8_t freq_option; /**< Frequency option */ uint16_t delay_us; /**< Capture delay */