diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c b/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c index 632361a..ee856e1 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c +++ b/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c @@ -49,6 +49,7 @@ static const CmdEntry m_cmd_table[] = { { "mec?", true, Cmd_mec }, { "maa?", true, Cmd_maa }, { "mbb?", true, Cmd_mbb }, + { "mab?", true, Cmd_mab }, // B-Mode Test { "mtb?", true, Cmd_mtb }, { "mcf?", true, Cmd_mcf }, { "mcs?", true, Cmd_mcs }, diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c index b479e63..6c1511e 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c +++ b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c @@ -16,12 +16,18 @@ #include "cmd_sensor.h" /* all_sensors() */ #include "dr_piezo.h" #include "dr_adc121s051.h" +#include "led_control.h" static void mtb_send_rim_after_piezo(void) { send_imu_rim_fifo(); } +static void mab_led_off_after_piezo(void) +{ + led_set_state(LED_STATE_OFF); +} + /*------------------------------------------------------------------------------ * Internal clamp helpers for persisted piezo configuration *----------------------------------------------------------------------------*/ @@ -414,6 +420,57 @@ int Cmd_mtb(const ParsedCmd *cmd) return 1; } +/*============================================================================== + * mab? -> reb:+raa: 6-channel asynchronous full capture + GR LED + * + * Request: [TAG 4B "mab?"] [CRC 2B] + * Response: per channel reb: [num_samples 2B] [raw_data...] + * final raa: [status 2B] + * Error: raa: + 0xFFFE (previous capture in progress) + * raa: + (0xFF00|err) (start failed) + * + * For B-Mode Test + *============================================================================*/ +int Cmd_mab(const ParsedCmd *cmd) +{ + dr_adc_err_t err; + (void)cmd; + + if (maa_async_is_busy()) + { + dr_ble_return_1("raa:", 0xFFFE); + return 1; + } + + led_set_state(LED_STATE_ALIGN_COMPLETE); + + err = maa_async_start( + m_config.piezo_freq_option, + m_config.piezo_delay_us, + m_config.piezo_num_samples, + m_config.piezo_cycles, + m_config.piezo_averaging, + ble_bin_buffer + ); + + if (err != DR_ADC_OK) + { + if (g_plat.log) + { + g_plat.log("[Cmd_mab] 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); + dr_piezo_power_off(); + led_set_state(LED_STATE_OFF); + return 1; + } + + maa_async_set_on_complete(mab_led_off_after_piezo); + + return 1; +} + /*============================================================================== * mcf? -> rcf: Read piezo parameters from FDS * diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.h b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.h index bca7bb9..85f33a2 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.h +++ b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.h @@ -12,6 +12,7 @@ int Cmd_mpc(const ParsedCmd *cmd); /* mpc? -> rpc: burst generation */ int Cmd_mec(const ParsedCmd *cmd); /* mec? -> reb:+raa: single-channel capture */ int Cmd_maa(const ParsedCmd *cmd); /* maa? -> reb:+raa: 6-channel async capture */ int Cmd_mbb(const ParsedCmd *cmd); /* mbb? -> rbb:+reb:+raa: sensors + capture */ +int Cmd_mab(const ParsedCmd *cmd); /* mab? -> reb:+raa: 6-channel async capture + green LED */ int Cmd_mtb(const ParsedCmd *cmd); /* mtb? -> reb:+raa:+rim: piezo + IMU FIFO (no rbb:) */ int Cmd_mcf(const ParsedCmd *cmd); /* mcf? -> rcf: read piezo parameters */ int Cmd_mcs(const ParsedCmd *cmd); /* mcs? -> rcs: write piezo parameters */