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

how to decrement fds token(fds_find_token_t)?

Hi,

I am saving temp data along with timestamps in the internal memory and sending it through ble.

if during transfer the queue becomes full (NRF_ERROR_RESOURCES), I am waiting for the BLE_GATTS_EVT_HVN_TX_COMPLETE event and send it again.

i am not getting the data for which I get the NRF_ERROR_RESOURCES.

to avoid this I have to decrement the token used for searching in FDS. 

 

/**@brief   A token to keep information about the progress of @ref fds_record_find,
 *          @ref fds_record_find_by_key, and @ref fds_record_find_in_file.
 *
 * @note    Always zero-initialize the token before using it for the first time.
 * @note    Never reuse the same token to search for different records.
 */
typedef struct
{
    uint32_t const * p_addr;
    uint16_t         page;
} fds_find_token_t;

I want to know how the token structure is working and how can I decrement the same to start it with the previous record?

Thanx

  • Hi,

    I do not understand why you want to do this. Can you explain more about how you use FDS and what you want to do? If you iterate through some records and something prevents you from processing a record, then surely you need to remember the current record, and not the previous one.

    If you really want to go back to (just) the previous token then you can achieve this most easily by simply maintaining a copy of the previous state of the fds_find_token_t instance you pass to fds_record_iterate() or similar. If you need to go back one step, just pick the old copy.

  • then surely you need to remember the current record, and not the previous one.

    Yes, you are right. when a queue full error (NRF_ERROR_RESOURCES) occurs it does not send the current record and iterate to the next one. I tried to save the current record in a temporary token and tried to update it before the next iteration but it is not working. my code is as follows

    fds_find_token_t  tok  = {0};
    fds_find_token_t  temp_tok  = {0};     // to store current token during transfer of log data
    
    //function to send fds log data
    static void send_notification(void)
    {	
    			uint32_t err_code;
    			uint8_t tlog_data_send_value[data_length];
    			while(fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok)== NRF_SUCCESS)
    				{
    					
    					err_code = fds_record_open(&desc, &config);
    					if ( err_code != NRF_SUCCESS)
    							{
    								APP_ERROR_CHECK(err_code);
    							}
    			
    					memcpy(tlog_data_send_value,config.p_data,data_length);
    							
    					err_code = ble_tlog_custom_value_update(&m_tlog, &data_length, tlog_data_send_value);
    					
    							if (err_code == NRF_ERROR_RESOURCES )
    							{
    									//temp_tok =tok;
    									memcpy(&tok,&temp_tok,sizeof(tok));
    									NRF_LOG_INFO("Resource full");
    									break;
    							}	
    							
    					err_code = fds_record_close(&desc);
    						if (err_code != NRF_SUCCESS)
    						{
    							APP_ERROR_CHECK(err_code);
    						}
    				
    				}						
    }
    
    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
       
        switch (p_ble_evt->header.evt_id)
        {
            // when queue become full, wait for BLE_GATTS_EVT_HVN_TX_COMPLETE and send data again.
            case BLE_GATTS_EVT_HVN_TX_COMPLETE:
    			//reset token
    			//tok = temp_tok;
    			memcpy(&temp_tok,&tok,sizeof(tok));
    			send_notification();
    			break;
        }
    }
    
     

  • Hi,

    You have wrong order in your memcpy statements. The first parameter is destination and the second is source, not the other way around.

Related