|
|
|
|
@@ -212,20 +212,21 @@ static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /* C
|
|
|
|
|
static uint16_t m_ble_nus_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - 3; /* NUS max data length (MTU - overhead) */
|
|
|
|
|
static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}}; /* UUIDs included in advertising */
|
|
|
|
|
|
|
|
|
|
static uint8_t m_tx_buffer[BLE_NUS_MAX_DATA_LEN]; /* ASCII text transmission buffer */
|
|
|
|
|
static uint8_t m_tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0}; /* ASCII text transmission buffer */
|
|
|
|
|
static uint16_t m_tx_len = 0; /* Data length to transmit */
|
|
|
|
|
static volatile bool m_tx_in_progress = false; /* TX in progress flag */
|
|
|
|
|
static volatile bool m_tx_complete_pending = false; /* TX completion pending flag */
|
|
|
|
|
static uint8_t c_addr[6]; /* Connected peer BLE address */
|
|
|
|
|
static uint8_t c_addr[6] = {0}; /* Connected peer BLE address */
|
|
|
|
|
|
|
|
|
|
static char * roles_str[] = {"INVALID_ROLE", "CENTRAL", "PERIPHERAL"};
|
|
|
|
|
|
|
|
|
|
/*==============================================================================
|
|
|
|
|
* Global Variables
|
|
|
|
|
* IEC 62304 §5.5.3: all global buffers zero-initialized for deterministic startup
|
|
|
|
|
*============================================================================*/
|
|
|
|
|
uint8_t m_encrypted_text[AES_BLOCK_SIZE]; /* AES encryption result buffer */
|
|
|
|
|
uint8_t m_encrypted_text2[AES_BLOCK_SIZE]; /* AES encryption result buffer 2 */
|
|
|
|
|
uint8_t m_decrypted_text[AES_BLOCK_SIZE]; /* AES decryption result buffer */
|
|
|
|
|
uint8_t m_encrypted_text[AES_BLOCK_SIZE] = {0}; /* AES encryption result buffer */
|
|
|
|
|
uint8_t m_encrypted_text2[AES_BLOCK_SIZE] = {0}; /* AES encryption result buffer 2 */
|
|
|
|
|
uint8_t m_decrypted_text[AES_BLOCK_SIZE] = {0}; /* AES decryption result buffer */
|
|
|
|
|
|
|
|
|
|
volatile uint8_t Sj_type; /* Command type identifier */
|
|
|
|
|
volatile bool processing; /* Sensor data processing flag (prevents duplicate commands) */
|
|
|
|
|
@@ -244,9 +245,9 @@ extern uint8_t add_cycle; /* Additional measurement cycle counter *
|
|
|
|
|
extern bool motion_raw_data_enabled; /* Motion raw data streaming enabled */
|
|
|
|
|
|
|
|
|
|
uint16_t cnt_s; /* Power button polling counter (5ms units, 150=0.75s) */
|
|
|
|
|
char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN]; /* BLE text transmission buffer */
|
|
|
|
|
uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN]; /* BLE binary response buffer (2026-03-17: moved from cmd_parse.c) */
|
|
|
|
|
uint16_t ble_bin_buff[BLE_NUS_MAX_DATA_LEN/2]; /* BLE binary transmission buffer (word units) */
|
|
|
|
|
char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0}; /* BLE text transmission buffer */
|
|
|
|
|
uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] = {0}; /* BLE binary response buffer */
|
|
|
|
|
uint16_t ble_bin_buff[BLE_NUS_MAX_DATA_LEN/2] = {0}; /* BLE binary transmission buffer (word units) */
|
|
|
|
|
which_cmd_t cmd_type_t; /* Current command source (CMD_BLE or CMD_UART) */
|
|
|
|
|
|
|
|
|
|
bool device_status = false; /* Device active state (true=running) */
|
|
|
|
|
@@ -261,13 +262,13 @@ volatile bool data_tx_in_progress = false; /* Binary TX in progress flag
|
|
|
|
|
|
|
|
|
|
/* -- BLE TX async retry state -- */
|
|
|
|
|
static volatile bool s_tx_pending = false; /* TX retry pending */
|
|
|
|
|
static uint8_t s_tx_pending_buf[BLE_NUS_MAX_DATA_LEN]; /* Pending packet (with CRC) */
|
|
|
|
|
static uint8_t s_tx_pending_buf[BLE_NUS_MAX_DATA_LEN] = {0}; /* Pending packet (with CRC) */
|
|
|
|
|
static uint16_t s_tx_pending_len = 0; /* Pending packet length */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char m_static_passkey[PASSKEY_LENGTH] = DEFAULT_PASSKEY; /* Static passkey (6 digits, loaded from FDS) */
|
|
|
|
|
char SERIAL_NO[SERIAL_NO_LENGTH]; /* Serial number (used as BLE device name) */
|
|
|
|
|
char HW_NO[HW_NO_LENGTH]; /* Hardware number (FDS stored/read) */
|
|
|
|
|
char SERIAL_NO[SERIAL_NO_LENGTH] = {0}; /* Serial number (used as BLE device name) */
|
|
|
|
|
char HW_NO[HW_NO_LENGTH] = {0}; /* Hardware number (FDS stored/read) */
|
|
|
|
|
bool bond_data_delete; /* Bond data delete request flag */
|
|
|
|
|
uint32_t m_life_cycle; /* Device life cycle counter */
|
|
|
|
|
uint8_t resetCount = 0; /* Communication timeout counter (reset detection) */
|
|
|
|
|
@@ -592,7 +593,7 @@ extern bool maa_async_is_busy(void);
|
|
|
|
|
extern void maa_async_abort(void);
|
|
|
|
|
|
|
|
|
|
/* 2026-03-17: Prevent blocking in BLE callback -- buffer command for main loop processing */
|
|
|
|
|
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN];
|
|
|
|
|
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN] = {0};
|
|
|
|
|
static volatile uint8_t pending_cmd_len = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|