| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include <stdint.h>
- #include <stdio.h>
- #include <string.h>
- #include "ble_gap.h"
- #include "app_uart.h"
- #include "app_util_platform.h"
- #include "bsp.h"
- #include "uart.h"
- #define UART_TX_BUF_SIZE 256
- #define UART_RX_BUF_SIZE 256
- #define BLE_DATA_LEN 32
- static uint8_t uart_data[BLE_DATA_LEN];
- static uint8_t uart_len = 0;
- void uart_process_data(void)
- {
-
- }
- /**@brief Function for handling app_uart events.
- *
- * @details This function will receive a single character from the app_uart module and append it to
- * a string. The string will be be sent over BLE when the last character received was a
- * 'new line' i.e '\n' (hex 0x0D) or if the string has reached a length of
- * @ref NUS_MAX_DATA_LENGTH.
- */
- /**@snippet [Handling the data received over UART] */
- void uart_event_handle(app_uart_evt_t * p_event)
- {
- switch (p_event->evt_type)
- {
- case APP_UART_DATA_READY:
- UNUSED_VARIABLE(app_uart_get(&uart_data[uart_len]));
- uart_len++;
- if ((uart_data[uart_len - 1] == '\n') || (uart_len >= (BLE_DATA_LEN)))
- {
- printf("uart:%s", uart_data);
- uart_data[uart_len - 1] = '\0';
- uart_data[uart_len - 2] = '\0';
- uart_process_data();
- memset(uart_data, 0, BLE_DATA_LEN);
- uart_len = 0;
- }
- break;
- case APP_UART_COMMUNICATION_ERROR:
- APP_ERROR_HANDLER(p_event->data.error_communication);
- break;
- case APP_UART_FIFO_ERROR:
- APP_ERROR_HANDLER(p_event->data.error_code);
- break;
- default:
- break;
- }
- }
- void uart_init(void)
- {
- uint32_t err_code;
- const app_uart_comm_params_t comm_params =
- {
- RX_PIN_NUMBER,
- TX_PIN_NUMBER,
- RTS_PIN_NUMBER,
- CTS_PIN_NUMBER,
- //APP_UART_FLOW_CONTROL_ENABLED,
- APP_UART_FLOW_CONTROL_DISABLED,
- false,
- UART_BAUDRATE_BAUDRATE_Baud115200
- };
- APP_UART_FIFO_INIT( &comm_params,
- UART_RX_BUF_SIZE,
- UART_TX_BUF_SIZE,
- uart_event_handle,
- APP_IRQ_PRIORITY_LOW,
- err_code);
- APP_ERROR_CHECK(err_code);
- }
|