Hi..... I'm working with custom service and characteristic!!!
I succeeded in changing the characteristic length like bellow.
attr_char_value.init_len = 10;
attr_char_value.init_len = 10;
attr_char_value.init_offs = 0;
attr_char_value.max_len = 10;
uint8_t value[10] = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10 };
When I checked through my nRF Connect App, it worked fine. When I pressed Read, those values popped up as I wanted.
And now I am trying to use 'Notification' to change the data..
I wrote the codes for notification as below
in the main.c
--------------------------------------------------------
static void test_data_update(void)
{
uint8_t array[10] = { 0x10,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01 };
uint8_t darray = array;
ble_midi_data_io_value_update(&m_midi_service, darray);
nrf_delay_ms(2000);
}
------------------------------------------------------------
and in midi_service.c
-------------------------------------------------------------
uint32_t ble_midi_data_io_value_update(ble_midi_service_t * p_midi_service, uint8_t data_io_value)
{
if (p_midi_service == NULL)
{
return NRF_ERROR_NULL;
}
uint32_t err_code = NRF_SUCCESS;
ble_gatts_value_t gatts_value;
// Initialize value struct.
memset(&gatts_value, 0 , sizeof(gatts_value));
gatts_value.len = 10;
gatts_value.offset = 0;
gatts_value.p_value = &data_io_value;
// Update database.
err_code = sd_ble_gatts_value_set(p_midi_service->conn_handle,
p_midi_service->data_io_char_handles.value_handle,
&gatts_value);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Send value if connected and notifying.
if ((p_midi_service->conn_handle != BLE_CONN_HANDLE_INVALID))
{
ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = p_midi_service->data_io_char_handles.value_handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len = gatts_value.len;
hvx_params.p_data = gatts_value.p_value;
err_code = sd_ble_gatts_hvx(p_midi_service->conn_handle, &hvx_params);
NRF_LOG_INFO("sd_ble_gatts_hvx result: %x. \r\n", err_code);
}
----------------------------
However, by doing this, I'm getting weird values that I didn't intend.
Can someone help me where I should change in this code to get the intended values when I press notifications??
Thanks for all your support.