This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can i use the pstorage_store in BLE_GAP_EVT_ADV_REPORT ?

Hi,

I'm trying to use the pstorage on a central device.
An event of BLE_GAP_EVT_ADV_REPORT is called by discovering some ble devices while a central device is scanning.
Now, when this event was occured, i call a pstorage_store method in it.
But, this way is not working as expected.

Below, this is my code:

・ Initialize pstorage

static void my_pstorage_init(void) {
    uint32_t                err_code;
    pstorage_module_param_t param;

    // Initialize pstorage
    err_code = pstorage_init();
    APP_ERROR_CHECK(err_code);

    param.block_size  = 16;
    param.block_count = 10;
    param.cb          = pstorage_cb_handler;
    err_code = pstorage_register(&param, &pstorage_handle);
    APP_ERROR_CHECK(err_code);

    pstorage_wait_flag = 1;
    pstorage_wait_handle = pstorage_handle.block_id;

    pstorage_block_identifier_get(&pstorage_handle, 0, &pstorage_block_handle);
    pstorage_clear(&pstorage_block_handle, 16);
    while(pstorage_wait_flag) {
        power_manage();
    }
}

・ Test saving data method

static void test_pstorage(void) {
    uint8_t                 source_data[16]   = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
    uint8_t                 dest_data[16] = {0};
    
    pstorage_block_identifier_get(&pstorage_handle, 0, &pstorage_block_handle);
    pstorage_wait_flag = 1;
    pstorage_wait_handle = pstorage_block_handle.block_id;
    pstorage_clear(&pstorage_block_handle, 16);
    while(pstorage_wait_flag) {
        power_manage();
    }
    
    pstorage_block_identifier_get(&pstorage_handle, 0, &pstorage_block_handle);
    pstorage_wait_flag = 1;
    pstorage_wait_handle = pstorage_block_handle.block_id;
    pstorage_store(&pstorage_block_handle, source_data, 16, 0);
    while(pstorage_wait_flag) {
        power_manage();
    }
    
    pstorage_block_identifier_get(&pstorage_handle, 0, &pstorage_block_handle);
    pstorage_wait_flag = 1;
    pstorage_wait_handle = pstorage_block_handle.block_id;
    pstorage_load(dest_data, &pstorage_block_handle, 16, 0);
    printf("dest_data size : %d \r\n", sizeof(dest_data));
    uint16_t i;
    for (i = 0; i < sizeof(dest_data); i++) {
        printf("%02x ", dest_data[i]);
    }
    printf("\r\n");
}

・ Call the test_pstorage method in ble eventing

static void on_ble_central_evt(ble_evt_t * p_ble_evt) {
    uint32_t                err_code;
    const ble_gap_evt_t   * p_gap_evt = &p_ble_evt->evt.gap_evt;

    switch (p_ble_evt->header.evt_id) {
    case BLE_GAP_EVT_ADV_REPORT: {
             // Initialize advertisement report for parsing.
            ble_gap_addr_t pa = p_gap_evt->params.adv_report.peer_addr;
            int8_t rssi = p_gap_evt->params.adv_report.rssi;
            test_pstorage();
        }
    case BLE_GAP_EVT_TIMEOUT:
       // ...
    case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
       / ...
    case BLE_GAP_EVT_DISCONNECTED:
       / ...
    default:
        break;
    }
}
  • My environment version
    • nRF51 SDK 9.0.0 (using softdevice : s130)
    • keil v5.15
    • nRFgo Studio 1.21.0.2

Actually, i want to a output "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f", but don't show results in console at all.
However the test_pstorage method is called in main method at once only, and it was success.

So, my questions are

  • How can i store the some data to pstorage while doing ble events ?
  • Why will be success calling the method at once only ?

I thank you for reading it through.

// yoshi

Related