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

nrf5_calendar example callback function?

Hello,

I am using nrf52840 and SDK 16.0.0

I am doing some work with the calendar example and got some questions.

Q1.

Inside the main function in main.c file there is nrf_cal_set_callback(calendar_updated, 4); function. How it can be called multiple times even though it is defined before the while(true) loop? How does it work?

Q2.

I am integrating ble_app_template example with this calendar example. My beacon is broadcasting advertisement packets. If I wanna update manufacturer specific data(lets say a time stamp) every 1 second, is it possible to locate advertisement update function inside this call back function(nrf_cal_set_callback())?

Thank you.

Parents
  • To be more specific about Q2,

    Advertisement update function looks like below. I got the function from this thread.

    static void advertising_update_mfg_data(void)
    {
        ret_code_t             err_code;
    
        static ble_advdata_t new_data; // SDK 16.x.x implementation is similar to advertising_init
    
        // Variables used for manufacturer specific data
        ble_advdata_manuf_data_t p_manuf_specific_data;
        uint8_array_t            adv_manuf_data_array;
        uint8_t                  adv_manuf_data_data[1];
        
        // Configuration of manufacturer specific data
        adv_manuf_data_data[0] = nrf_cal_get_time()->tm_sec;   // Update second
        
        
        adv_manuf_data_array.p_data      = adv_manuf_data_data;
        adv_manuf_data_array.size        = sizeof(adv_manuf_data_data);
    
        p_manuf_specific_data.company_identifier = 0x0059;
        p_manuf_specific_data.data       = adv_manuf_data_array; 
          
        new_data.p_manuf_specific_data   = &p_manuf_specific_data;
    
        new_data.name_type               = BLE_ADVDATA_SHORT_NAME;
        new_data.short_name_len          = 5;
        new_data.include_appearance      = false;
        new_data.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        new_data.uuids_complete.uuid_cnt = 0;
        new_data.uuids_complete.p_uuids  = m_adv_uuids;
    
        //SDK16.x.x implementation will handle all buffering and encoding inside the update function
        err_code = ble_advertising_advdata_update(&m_advertising, &new_data, NULL);  
        APP_ERROR_CHECK(err_code);
    
    }

    Callback function and update function.

    void nrf_cal_set_callback(void (*callback)(void), uint32_t interval)
    {
        // Set the calendar callback, and set the callback interval in seconds
        cal_event_callback = callback;
        m_rtc_increment = interval;
        m_time += CAL_RTC->COUNTER / 8;
        CAL_RTC->TASKS_CLEAR = 1;
        CAL_RTC->CC[0] = interval * 8;  
        
        advertising_update_mfg_data(); // update function
    }

    Is there any other way to update this manufacturer data every 1 sec?

Reply
  • To be more specific about Q2,

    Advertisement update function looks like below. I got the function from this thread.

    static void advertising_update_mfg_data(void)
    {
        ret_code_t             err_code;
    
        static ble_advdata_t new_data; // SDK 16.x.x implementation is similar to advertising_init
    
        // Variables used for manufacturer specific data
        ble_advdata_manuf_data_t p_manuf_specific_data;
        uint8_array_t            adv_manuf_data_array;
        uint8_t                  adv_manuf_data_data[1];
        
        // Configuration of manufacturer specific data
        adv_manuf_data_data[0] = nrf_cal_get_time()->tm_sec;   // Update second
        
        
        adv_manuf_data_array.p_data      = adv_manuf_data_data;
        adv_manuf_data_array.size        = sizeof(adv_manuf_data_data);
    
        p_manuf_specific_data.company_identifier = 0x0059;
        p_manuf_specific_data.data       = adv_manuf_data_array; 
          
        new_data.p_manuf_specific_data   = &p_manuf_specific_data;
    
        new_data.name_type               = BLE_ADVDATA_SHORT_NAME;
        new_data.short_name_len          = 5;
        new_data.include_appearance      = false;
        new_data.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        new_data.uuids_complete.uuid_cnt = 0;
        new_data.uuids_complete.p_uuids  = m_adv_uuids;
    
        //SDK16.x.x implementation will handle all buffering and encoding inside the update function
        err_code = ble_advertising_advdata_update(&m_advertising, &new_data, NULL);  
        APP_ERROR_CHECK(err_code);
    
    }

    Callback function and update function.

    void nrf_cal_set_callback(void (*callback)(void), uint32_t interval)
    {
        // Set the calendar callback, and set the callback interval in seconds
        cal_event_callback = callback;
        m_rtc_increment = interval;
        m_time += CAL_RTC->COUNTER / 8;
        CAL_RTC->TASKS_CLEAR = 1;
        CAL_RTC->CC[0] = interval * 8;  
        
        advertising_update_mfg_data(); // update function
    }

    Is there any other way to update this manufacturer data every 1 sec?

Children
No Data
Related