I am editing the ble_app_uart example. Where is the nus_data_handler variable declared? I see the function void nus_data_handler(ble_nus_t * p....).
The function itself is declared and defined in main.c, but the function is used as a pointer, and the function pointer type is declared in ble_nus.h
typedef void (*ble_nus_data_handler_t) (ble_nus_t * p_nus, uint8_t * p_data, uint16_t length);
In ble_nus.h you have the following struct, and the data_handler
variable is of the above function pointer type. So, in ble_nus_init()
you actually assign this variable to point to the nus_data_handler()
function in main.c.
struct ble_nus_s
{
uint8_t uuid_type; /**< UUID type for Nordic UART Service Base UUID. */
uint16_t service_handle; /**< Handle of Nordic UART Service (as provided by the S110 SoftDevice). */
ble_gatts_char_handles_t tx_handles; /**< Handles related to the TX characteristic (as provided by the S110 SoftDevice). */
ble_gatts_char_handles_t rx_handles; /**< Handles related to the RX characteristic (as provided by the S110 SoftDevice). */
uint16_t conn_handle; /**< Handle of the current connection (as provided by the S110 SoftDevice). BLE_CONN_HANDLE_INVALID if not in a connection. */
bool is_notification_enabled; /**< Variable to indicate if the peer has enabled notification of the RX characteristic.*/
ble_nus_data_handler_t data_handler; /**< Event handler to be called for handling received data. */
};