diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/dbn_ble_srv.c b/BLE/DLD154Pro_Peripheral_28K/APP/dbn_ble_srv.c index 473c0c8..3580f71 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/dbn_ble_srv.c +++ b/BLE/DLD154Pro_Peripheral_28K/APP/dbn_ble_srv.c @@ -429,6 +429,8 @@ static void unpack_pkg_set_cjq_param(uint8_t *pkg, uint8_t len) g_loop_cng_unit.direction_mode = pkg[i++]; g_function_mode = (g_loop_cng_unit.direction_mode >> 4) & 0x0F; + g_fm_700bs_disable = g_function_mode & 0x01; + g_fm_radar_input_disable = (g_function_mode >> 1) & 0x01; g_hold_time = g_loop_cng_unit.exist_mode * 20 * 5; g_freq_sens = (g_loop_cng_unit.sensitvity > 0) ? (g_loop_cng_unit.sensitvity - 1) : 0; @@ -637,6 +639,42 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len) set_response_buf(&g_buf_ble_response, MAGIC_BYTE_DBN_DEFAULT, _cmd, tmp_ble_buf, i); // PRINT("\nGet_Cjq_param\n"); } break; + case CMD_DBN_RW_UART_BAUD:{ // 读写波特率 + uint8_t _rw = pkg[4]; + uint32_t _baud = 0; + i = 0; + tmp_ble_buf[i++] = _rw; + tmp_ble_buf[i++] = 0x0; //status + + if(_rw == 0){// read baud + tmp_ble_buf[i++] = g_max_counter_bt_min; // 表示空闲蓝牙超时关闭时间 + tmp_ble_buf[i++] = (uint8_t)g_storage_uart_baud; //1 为485串口,g_storage_uart_baud;2 为TTL串口g_storage_uart_baud_2 + tmp_ble_buf[i++] = (uint8_t)(g_storage_uart_baud >> 8); + tmp_ble_buf[i++] = (uint8_t)(g_storage_uart_baud >> 16); + tmp_ble_buf[i++] = g_rs485_id; + tmp_ble_buf[i++] = 0; + tmp_ble_buf[i++] = 0; + tmp_ble_buf[i++] = 0; + // 4BYte Reserved + + } + else { // write baud + g_max_counter_bt_min = pkg[5]; + g_storage_uart_baud = pkg[6]; + g_storage_uart_baud |= (uint16_t)(pkg[7] << 8) & 0xFF00; + g_storage_uart_baud |= (uint32_t)(pkg[8] << 16) & 0xFF0000; + g_rs485_id = pkg[9]; + + tmp_ble_buf[i++] = g_max_counter_bt_min; + tmp_ble_buf[i++] = (uint8_t)g_storage_uart_baud; + tmp_ble_buf[i++] = (uint8_t)(g_storage_uart_baud >> 8); + tmp_ble_buf[i++] = (uint8_t)(g_storage_uart_baud >> 16); + tmp_ble_buf[i++] = g_rs485_id; tmp_ble_buf[i++] = 0x00; tmp_ble_buf[i++] = 0x00; tmp_ble_buf[i++] = 0x00; // 3BYte Reserved + + write_cfg_to_store(ADDR_BT_Close_TIMEOUT_Offset, &tmp_ble_buf[2], 5); + } + set_response_buf(&g_buf_ble_response, MAGIC_BYTE_DBN_DEFAULT, _cmd, tmp_ble_buf, i); + } break; // case CMD_DBN_LOOP_SAMPLE_PARAM:{ // // 获取/设置 地感采样参数 //// PRINT("SAMPLE_CNG: %02X\n", pkg[4]); diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/include/cmcng.h b/BLE/DLD154Pro_Peripheral_28K/APP/include/cmcng.h index 43424f3..cda9c9c 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/include/cmcng.h +++ b/BLE/DLD154Pro_Peripheral_28K/APP/include/cmcng.h @@ -41,11 +41,19 @@ extern uint32_t g_loop_cut_amount; extern uint8_t g_loop_power_up_state; extern uint8_t g_function_mode; +extern uint8_t g_fm_700bs_disable ; //0: 700bs protocol; 1 Modbus protocol +extern uint8_t g_fm_radar_input_disable; //0: radar input enable; 1 reset /* 新算法状�? (DLD154V4B 移植) */ extern uint8_t g_loop_stable; // 稳定期结束标�? (0=收敛�?, 1=稳定) extern uint8_t g_env_activity; // 环境活跃�? (BLE condition 字段来源) +extern uint8_t g_storage_uart_num; +extern uint32_t g_storage_uart_baud; +extern uint8_t g_max_counter_bt_min; +extern uint32_t g_max_counter_bt_timeout; +extern uint8_t g_rs485_id; + uint32_t mstick(void); #endif /* INCLUDE_CMCNG_H_ */ diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/include/dbn_ble_srv.h b/BLE/DLD154Pro_Peripheral_28K/APP/include/dbn_ble_srv.h index 804edf5..bca2461 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/include/dbn_ble_srv.h +++ b/BLE/DLD154Pro_Peripheral_28K/APP/include/dbn_ble_srv.h @@ -52,6 +52,8 @@ // #define CMD_SET_RELAY 0xC4 #define CMD_SENS_ACS_ENABLE 0xC5 // 设备主动上报 使能 +#define CMD_DBN_RW_UART_BAUD 0x31 + diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/include/storage.h b/BLE/DLD154Pro_Peripheral_28K/APP/include/storage.h index 57f9ecf..ef61e3c 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/include/storage.h +++ b/BLE/DLD154Pro_Peripheral_28K/APP/include/storage.h @@ -26,12 +26,20 @@ // #define Addr_Release_Rate_Weight 0x1E // #define Addr_Release_Rate_Mode 0x1F +#define ADDR_BT_Close_TIMEOUT_Offset 0x10 +#define Addr_RS485_Baud_Offset 0x11 // 3 byte +#define Addr_RS485_ID_Offset 0x14 // 1 byte + + #define Addr_Loop_Sens_List_Offset 0x20 #define Addr_Sens_Array_In 0x20 #define Addr_Sens_Array_Out 0x30 +#define RS_BAUD_DEFAULT 9600 + + #define MAX_LOOP_SENS_AMOUNT 3 // 4 // 5 #pragma pack(1) diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/peripheral_main.c b/BLE/DLD154Pro_Peripheral_28K/APP/peripheral_main.c index 0210004..f7788a2 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/peripheral_main.c +++ b/BLE/DLD154Pro_Peripheral_28K/APP/peripheral_main.c @@ -33,7 +33,16 @@ uint8_t g_flag_bt_state = 0; // 0 蓝牙没有连接,1 有蓝牙连接 uint8_t g_function_mode = 0; +uint8_t g_fm_700bs_disable = 0; //0: 700bs protocol; 1 Modbus protocol +uint8_t g_fm_radar_input_disable = 0; //0: radar input enable; 1 reset uint32_t g_sys_freq = 0; +uint8_t g_storage_uart_num = 0; +uint32_t g_storage_uart_baud = 19200;//9600; +uint8_t g_max_counter_bt_min = 0; +uint32_t g_max_counter_bt_timeout = 0; //BT_DISABLE_IDLE_TIMEOUT * 60 * 1000; // ms unit + +uint8_t g_rs485_id = 0; + /*=========================================================================== * IO 宏定义 -- DLD154Pro 硬件资源 @@ -277,6 +286,11 @@ void factory_dev(void){ i = 4; memcpy(&rBuf[i], &g_loop_cng_unit.sensitvity, 7); i += 7; + rBuf[Addr_RS485_ID_Offset] = 1; + rBuf[Addr_RS485_Baud_Offset] = RS_BAUD_DEFAULT & 0xFF; + rBuf[Addr_RS485_Baud_Offset + 1] = (RS_BAUD_DEFAULT >> 8) & 0xFF; + rBuf[Addr_RS485_Baud_Offset + 2] = (RS_BAUD_DEFAULT >> 16) & 0xFF; + rBuf[ADDR_BT_Close_TIMEOUT_Offset] = 0; i = Addr_Loop_Sens_List_Offset; if(g_loop_sens_list.total > MAX_LOOP_SENS_AMOUNT) @@ -313,11 +327,19 @@ void para_store_init(void) memcpy(&g_loop_cng_unit, &rBuf[4], sizeof(g_loop_cng_unit)); memcpy(&g_loop_sens_list, &rBuf[Addr_Loop_Sens_List_Offset], sizeof(g_loop_sens_list)); + g_rs485_id = rBuf[Addr_RS485_ID_Offset]; + g_storage_uart_baud = rBuf[Addr_RS485_Baud_Offset] | (rBuf[Addr_RS485_Baud_Offset + 1] << 8) | (rBuf[Addr_RS485_Baud_Offset + 2] << 16); + g_max_counter_bt_min = rBuf[ADDR_BT_Close_TIMEOUT_Offset]; // unit: minute + g_max_counter_bt_timeout = g_max_counter_bt_min * 60 * 1000; // unit: ms + + g_loop_out_delay = g_loop_cng_unit.delay_time * 2; // 定时器以 50ms 为单位, 延时以100ms为单位 g_hold_time = g_loop_cng_unit.exist_mode * 20 * 5; //50ms/per, period: 5s g_safe_max_cnt = g_loop_cng_unit.loopSafe_Timeout * 10 * (1000 / 50); g_freq_level = g_loop_cng_unit.loopFreq_Level - 1; g_function_mode = g_loop_cng_unit.direction_mode >> 4; + g_fm_700bs_disable = g_function_mode & 0x01; + g_fm_radar_input_disable = (g_function_mode >> 1) & 0x01; g_freq_sens = (g_loop_cng_unit.sensitvity > 0) ? (g_loop_cng_unit.sensitvity - 1) : 0; #ifdef DEBUG