hii,
i am working on ble project where i would want to read the name and address of a slave.The example i am looking at is "nrf51_sdk_v6_1_0_b2ec2e6\nrf51822\Board\nrf6310\s120\ble_app_multilink_central". In the main() you can see function definition for "on_ble_evt". On going through the example i found out that we get the target device name in adv_data.p_data( adv_data.p_data =p_ble_evt->evt.gap_evt.params.adv_report.data;). Then i edited the code like
ble_gap_evt_adv_report_t x;///added extra
adv_data.p_data =x.data;////instead of adv_data.p_data =p_ble_evt->evt.gap_evt.params.adv_report.data;///
it also points to the same location as before the code was edited,but i don't get the target device name now as expected in adv_data.p_data.The edited code is pasted below .why does this happen,ie, i can't access the device name even though i point to the same memory location 'data' using 'x',instead of 'p_ble_evt' (i realise that p_ble_evt is a passed parameter for the function).
please help
static void on_ble_evt(ble_evt_t * p_ble_evt) {
uint8_t *p;
uint32_t err_code;
ble_gap_evt_adv_report_t x;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_ADV_REPORT:
{
data_t adv_data;
data_t type_data;
ble_gap_evt_adv_report_t x;
// Initialize advertisement report for parsing.
adv_data.p_data =x.data;//p_ble_evt->evt.gap_evt.params.adv_report.data;
adv_data.data_len = p_ble_evt->evt.gap_evt.params.adv_report.dlen;
err_code = adv_report_parse(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME,
&adv_data,
&type_data);
if (err_code != NRF_SUCCESS)
{
// Compare short local name in case complete name does not match.
err_code = adv_report_parse(BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME,
&adv_data,
&type_data);
}
// Verify if short or complete name matches target.
if ((err_code == NRF_SUCCESS) &&
(0 == memcmp(TARGET_DEV_NAME,type_data.p_data,type_data.data_len)))
{
err_code = sd_ble_gap_scan_stop();
if (err_code != NRF_SUCCESS)
{
APPL_LOG("[APPL]: Scan stop failed, reason %d\r\n", err_code);
}
err_code = sd_ble_gap_connect(&gs_hb_peripheral_address[0],
&m_scan_param,
&m_connection_param);
/* err_code = sd_ble_gap_connect(&p_ble_evt->evt.gap_evt.params.adv_report.\
peer_addr,
&m_scan_param,
&m_connection_param);*/
if (err_code != NRF_SUCCESS)
{
APPL_LOG("[APPL]: Connection Request Failed, reason %d\r\n", err_code);
}
}
break;
}
default:
break;
}
}