From 49f2a78dce4ebb51811f67c958baea18e24ac418 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 9 May 2024 20:37:15 +0800 Subject: [PATCH] update --- .vscode/c_cpp_properties.json | 40 +++++++------------- .vscode/settings.json | 3 +- app/main.c | 88 +++++++++---------------------------------- app/zble_nus_c.h | 3 +- 4 files changed, 36 insertions(+), 98 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 09c0cb3..121b48e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,18 +3,12 @@ { "name": "nrf52833_xxaa", "includePath": [ - "libznordic\\include", - "sdk/external/fatfs/src/", - "sdk/external/fatfs/src/", - "sdk/external/fatfs/port/", - "sdk/components/libraries/block_dev/sdc/", - "sdk/components/libraries/block_dev/", - "sdk\\config", - "app\\src", + "sdk\\modules\\nrfx\\mdk\\", + "app\\config", "sdk\\components", "sdk\\components\\ble\\ble_advertising", + "sdk\\components\\ble\\ble_db_discovery", "sdk\\components\\ble\\ble_dtm", - "sdk\\components\\ble\\ble_link_ctx_manager", "sdk\\components\\ble\\ble_racp", "sdk\\components\\ble\\ble_services\\ble_ancs_c", "sdk\\components\\ble\\ble_services\\ble_ans_c", @@ -41,12 +35,13 @@ "sdk\\components\\ble\\ble_services\\ble_tps", "sdk\\components\\ble\\common", "sdk\\components\\ble\\nrf_ble_gatt", + "sdk\\components\\ble\\nrf_ble_gq", "sdk\\components\\ble\\nrf_ble_qwr", + "sdk\\components\\ble\\nrf_ble_scan", "sdk\\components\\ble\\peer_manager", "sdk\\components\\boards", "sdk\\components\\libraries\\atomic", "sdk\\components\\libraries\\atomic_fifo", - "sdk\\components\\libraries\\atomic_flags", "sdk\\components\\libraries\\balloc", "sdk\\components\\libraries\\bootloader\\ble_dfu", "sdk\\components\\libraries\\bsp", @@ -130,8 +125,8 @@ "sdk\\components\\nfc\\t4t_parser\\hl_detection_procedure", "sdk\\components\\nfc\\t4t_parser\\tlv", "sdk\\components\\softdevice\\common", - "sdk\\components\\softdevice\\s140\\headers", - "sdk\\components\\softdevice\\s140\\headers\\nrf52", + "sdk\\components\\softdevice\\s122\\headers", + "sdk\\components\\softdevice\\s122\\headers\\nrf52", "sdk\\external\\fprintf", "sdk\\external\\segger_rtt", "sdk\\external\\utf_converter", @@ -140,31 +135,23 @@ "sdk\\modules\\nrfx", "sdk\\modules\\nrfx\\drivers\\include", "sdk\\modules\\nrfx\\hal", - "app\\config\\", - "app\\config", "app", "sdk\\modules\\nrfx\\soc", "sdk\\modules\\nrfx\\drivers\\src", - "sdk\\modules\\nrfx\\drivers\\src\\prs", - "sdk\\modules\\nrfx\\mdk\\", - "sdk\\components\\toolchain\\cmsis\\include\\", - "sdk\\components\\libraries\\bootloader\\" + "sdk\\modules\\nrfx\\drivers\\src\\prs" ], "defines": [ - "BL_SETTINGS_ACCESS_ONLY", - "NRF_DFU_SVCI_ENABLED", - "NRF_DFU_TRANSPORT_BLE=1", - "CONFIG_NFCT_PINS_AS_GPIOS", "APP_TIMER_V2", "APP_TIMER_V2_RTC1_ENABLED", - "BOARD_PCA10100", + "BOARD_QING_FENG_NRF52833", + "CONFIG_GPIO_AS_PINRESET", "FLOAT_ABI_HARD", "NRF52833_XXAA", - "NRF_SD_BLE_API_VERSION=7", - "S140", + "NRF_SD_BLE_API_VERSION=8", + "S122", "SOFTDEVICE_PRESENT", "__HEAP_SIZE=2048", - "__STACK_SIZE=4096", + "__STACK_SIZE=2048", "__CC_ARM", "__arm__", "__align(x)=", @@ -240,6 +227,7 @@ ], "intelliSenseMode": "${default}" } + ], "version": 4 } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 048c7b3..62d5a58 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -191,7 +191,8 @@ "heart_ware_sample_data_mgr.h": "c", "bsp.h": "c", "boards.h": "c", - "nrf_gpio.h": "c" + "nrf_gpio.h": "c", + "sdk_errors.h": "c" }, "files.encoding": "gbk" } \ No newline at end of file diff --git a/app/main.c b/app/main.c index 421092b..928dfbb 100644 --- a/app/main.c +++ b/app/main.c @@ -83,59 +83,30 @@ static uint16_t m_ble_nus_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - OPCODE_LENGT /**@brief NUS UUID. */ static ble_uuid_t const m_nus_uuid = {.uuid = BLE_UUID_NUS_SERVICE, .type = NUS_SERVICE_UUID_TYPE}; - -/**@brief Function for handling asserts in the SoftDevice. - * - * @details This function is called in case of an assert in the SoftDevice. - * - * @warning This handler is only an example and is not meant for the final product. You need to analyze - * how your product is supposed to react in case of assert. - * @warning On assert from the SoftDevice, the system can only recover on reset. - * - * @param[in] line_num Line number of the failing assert call. - * @param[in] p_file_name File name of the failing assert call. - */ -void assert_nrf_callback(uint16_t line_num, const uint8_t* p_file_name) { app_error_handler(0xDEADBEEF, line_num, p_file_name); } - -/**@brief Function for handling the Nordic UART Service Client errors. - * - * @param[in] nrf_error Error code containing information about what went wrong. - */ -static void nus_error_handler(uint32_t nrf_error) { APP_ERROR_HANDLER(nrf_error); } - -/**@brief Function to start scanning. */ -static void scan_start(void) { +void assert_nrf_callback(uint16_t line_num, const uint8_t* p_file_name) { app_error_handler(0xDEADBEEF, line_num, p_file_name); } +static void nus_error_handler(uint32_t nrf_error) { APP_ERROR_HANDLER(nrf_error); } +static void scan_start(void) { ret_code_t ret; - ret = nrf_ble_scan_start(&m_scan); APP_ERROR_CHECK(ret); - ret = bsp_indication_set(BSP_INDICATE_SCANNING); APP_ERROR_CHECK(ret); } - -/**@brief Function for handling Scanning Module events. - */ static void scan_evt_handler(scan_evt_t const* p_scan_evt) { ret_code_t err_code; - switch (p_scan_evt->scan_evt_id) { case NRF_BLE_SCAN_EVT_CONNECTING_ERROR: { err_code = p_scan_evt->params.connecting_err.err_code; APP_ERROR_CHECK(err_code); } break; - case NRF_BLE_SCAN_EVT_CONNECTED: { ble_gap_evt_connected_t const* p_connected = p_scan_evt->params.connected.p_connected; - // Scan is automatically stopped by the connection. NRF_LOG_INFO("Connecting to target %02x%02x%02x%02x%02x%02x", p_connected->peer_addr.addr[0], p_connected->peer_addr.addr[1], p_connected->peer_addr.addr[2], p_connected->peer_addr.addr[3], p_connected->peer_addr.addr[4], p_connected->peer_addr.addr[5]); } break; - case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT: { NRF_LOG_INFO("Scan timed out."); scan_start(); } break; - default: break; } @@ -148,7 +119,7 @@ static char m_target_periph_name1[20] = "M1001"; /**< Name of the device we tr static char m_target_periph_name2[20] = "iflytop"; /**< Name of the device we try to connect to. This name is searched in the scan report data*/ static char m_target_periph_name3[20] = "ADS1293"; /**< Name of the device we try to connect to. This name is searched in the scan report data*/ static char m_target_periph_name4[20] = "IFLYTOP"; /**< Name of the device we try to connect to. This name is searched in the scan report data*/ -static char m_target_periph_name5[20] = "M1003"; /**< Name of the device we try to connect to. This name is searched in the scan report data*/ +static char m_target_periph_name5[20] = "M1003"; /**< Name of the device we try to connect to. This name is searched in the scan report data*/ static void scan_init(void) { ret_code_t err_code; @@ -164,6 +135,7 @@ static void scan_init(void) { // err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid); // APP_ERROR_CHECK(err_code); + nrf_ble_scan_all_filter_remove(&m_scan); APP_ERROR_CHECK(nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name0)); APP_ERROR_CHECK(nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name1)); @@ -172,29 +144,11 @@ static void scan_init(void) { APP_ERROR_CHECK(nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name4)); APP_ERROR_CHECK(nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name5)); - // err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false); - // APP_ERROR_CHECK(err_code); - err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false); APP_ERROR_CHECK(err_code); } -/**@brief Function for handling database discovery events. - * - * @details This function is a callback function to handle events from the database discovery module. - * Depending on the UUIDs that are discovered, this function forwards the events - * to their respective services. - * - * @param[in] p_event Pointer to the database discovery event. - */ static void db_disc_handler(ble_db_discovery_evt_t* p_evt) { ble_nus_c_on_db_disc_evt(&m_ble_nus_c, p_evt); } - -/**@brief Function for handling characters received by the Nordic UART Service (NUS). - * - * @details This function takes a list of characters of length data_len and prints the characters out on UART. - * If @ref ECHOBACK_BLE_UART_DATA is set, the data is sent back to sender. - */ - static void app_uart_force_put(uint8_t data) { ret_code_t ret_val; do { @@ -266,18 +220,7 @@ void uart_event_handle(app_uart_evt_t* p_event) { case APP_UART_DATA_READY: UNUSED_VARIABLE(app_uart_get(&data_array[data_array_index])); data_array_index++; - - if (data_array_index >= (m_ble_nus_max_data_len)) { - NRF_LOG_DEBUG("Ready to send data over BLE NUS"); - NRF_LOG_HEXDUMP_DEBUG(data_array, data_array_index); - - do { - ret_val = ble_nus_c_string_send(&m_ble_nus_c, data_array, data_array_index); - if ((ret_val != NRF_ERROR_INVALID_STATE) && (ret_val != NRF_ERROR_RESOURCES)) { - APP_ERROR_CHECK(ret_val); - } - } while (ret_val == NRF_ERROR_RESOURCES); - + if (data_array_index > BLE_NUS_MAX_DATA_LEN) { data_array_index = 0; } break; @@ -602,16 +545,21 @@ static void idle_state_handle(void) { } APP_TIMER_DEF(m_uart_send_tmr); // ״̬»úÇý¶¯¶¨Ê±Æ÷ +static void process_uart_rx_packet(uint8_t* data, size_t len) { + ret_code_t ret_val; + + do { + ret_val = ble_nus_c_string_send(&m_ble_nus_c, data, len); + if ((ret_val != NRF_ERROR_INVALID_STATE) && (ret_val != NRF_ERROR_RESOURCES)) { + APP_ERROR_CHECK(ret_val); + } + } while (ret_val == NRF_ERROR_RESOURCES); +} + static void uart_send_tmr_cb(void* p_context) { // static uint32_t last_data_array_index; - ret_code_t ret_val; if (data_array_index != 0 && data_array_index == last_data_array_index) { - do { - ret_val = ble_nus_c_string_send(&m_ble_nus_c, data_array, data_array_index); - if ((ret_val != NRF_ERROR_INVALID_STATE) && (ret_val != NRF_ERROR_RESOURCES)) { - APP_ERROR_CHECK(ret_val); - } - } while (ret_val == NRF_ERROR_RESOURCES); + process_uart_rx_packet(data_array, data_array_index); data_array_index = 0; last_data_array_index = 0; } diff --git a/app/zble_nus_c.h b/app/zble_nus_c.h index 680845b..dcee5cd 100644 --- a/app/zble_nus_c.h +++ b/app/zble_nus_c.h @@ -261,4 +261,5 @@ uint32_t ble_nus_c_handles_assign(ble_nus_c_t* p_ble_nus_c, uint16_t conn_handle #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif +