How to run into function tnep_svc_one_selected()?

As the title, in the project "ncs\v3.2.1\nrf\samples\nfc\tnep_tag", how to runt into  function tnep_svc_one_selected()?

I use the NFC tools, Send the hex data, want to select the servive, what hex data must be send? Is there a complete example or debugging method?

  • Hi

    The tnep_svc_one_selected() is triggered from the NFC_TNEP_TAG_SERVICE_DEF and the information from the brief there should cover how to use it:

     @brief Macro to define TNEP service.
     *
     * TNEP Service instance contains information about Services Parameter
     * and callback s for NDEF application. The Service Parameter contains
     * the Service Name URI of the Service and the TNEP parameters used to
     * communicate with the Service. The Reader/Writer will configure
     * the TNEP communication according to the announced parameter
     * in the Service Parameter record.

    Best regards,

    Simon

  • I know that tnep_svc_one_selected is defined by NFC_TNEP_TAG_SERVICE_DEF, but it just doesn't execute. When I read it with an NFC tag reader, the service can be detected. Now I'm using an NFC debugger and want to send hexadecimal data for interaction, aiming to read the specific content of the service, such as the “svc_one_msg” message here.

    Maybe I need an Android version of the verification software that matches this sample program.

  • Hi

    I'm sorry, but I don't understand what you mean here I'm afraid. Are you using a phone, Android or similar running an NFC debugger app of sorts or a dedicated NFC debugger device? I think the NFC TNEP polling device. 

    Is the issue here that you are not able to switch back to the svc_one service with a button press? If so, I think that is because the sample only lets you switch from 1 to 2 and not back with the same button press, so you need to change this in the source code.

    Or is the issue that you aren't able to change/poll the service from the phone? If so, I think you should look at how the TNEP poller sample does this and implement something like that on the NFC tools on your end.

    Best regards,

    Simon

  • It's like this: I plan to use TNEP for data exchange. What I imagine is being able to use tool software, like NFC TOOL, similar to a serial port debugging assistant, to send and receive hexadecimal data for manual debugging.

  • Hello,

    Sorry for the late reply. Simon is currently out of office, so I will look into your ticket. 

    So the question is "how to run the tnep_svc_one_selected()"? 

    Do you see tnep_svc_two_selected() being called?

    Currently, the button_pressed() callback is being used to set the svc_two_rec, and enabling it using nfc_ndef_msg_record_add() and nfc_tnep_tag_tx_msg_app_data(). So if you see the record being switched to svc_two_rec, then this is working. Try adding something like this:

    static void button_pressed(uint32_t button_state, uint32_t has_changed)
    {
    	int err;
    	uint32_t button = button_state & has_changed;
    	const char svc_two_msg[] = "Service e  = 2.71828182845904523536";
    
    	if (button & DK_BTN1_MSK) {
    		NFC_TNEP_TAG_APP_MSG_DEF(app_msg, 1);
    		NFC_NDEF_TEXT_RECORD_DESC_DEF(svc_two_rec, UTF_8, en_code,
    					      sizeof(en_code), svc_two_msg,
    					      strlen(svc_two_msg));
    
    		err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
    					      &NFC_NDEF_TEXT_RECORD_DESC(svc_two_rec));
    
    		err = nfc_tnep_tag_tx_msg_app_data(&NFC_NDEF_MSG(app_msg),
    						   NFC_TNEP_STATUS_SUCCESS);
    		if (err == -EACCES) {
    			printk("Service is not in selected state. App data cannot be set\n");
    		} else {
    			printk("Service app data set err: %d\n", err);
    		}
    	}
    	else if (button & DK_BTN2_MSK) {
    	    NFC_TNEP_TAG_APP_MSG_DEF(app_msg, 1);
    		NFC_NDEF_TEXT_RECORD_DESC_DEF(svc_one_rec, UTF_8, en_code,
    					      sizeof(en_code), svc_one_msg,
    					      strlen(svc_one_msg));
    
    		err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
    					      &NFC_NDEF_TEXT_RECORD_DESC(svc_one_rec));
    
    		err = nfc_tnep_tag_tx_msg_app_data(&NFC_NDEF_MSG(app_msg),
    						   NFC_TNEP_STATUS_SUCCESS);
    		if (err == -EACCES) {
    			printk("Service is not in selected state. App data cannot be set\n");
    		} else {
    			printk("Service app data set err: %d\n", err);
    		}
    	}
    }

    Best regards,

    Edvin

Related