Tizen D.I.T

NFC

D.I.T

#include "Commnucation/NFC.h"
#include "Interface/Log.h"
#include "dit.h"

void NFC_Send (char * tag, char * msg)
{
    NFC nfc = NewNFC ();
    //NFC 모듈 생성
    if ( nfc->isAccessible (nfc))
    { //NFC 장비 유무 확인
        if ( nfc->onConnect (nfc))
        { //NFC 장비 연결 / 초기화
            NDEF ndef = CreateNDEF (tag, msg); //NDEF 생성
            nfc->Send (nfc, ndef); //NFC 메세지 전송
            DeleteNDEF(&ndef);
        }
    }
    DestoryNFC (nfc);
    //NFC 모듈 삭제
}

void NFC_Recv ()
{
    NFC nfc = NewNFC ();
    if ( nfc->isAccessible (nfc))
    { //NFC 장비 유무 확인
        if ( nfc->onConnect (nfc))
        { //NFC 장비 연결 / 초기화
            NDEF msg = nfc->Recv (nfc); //NDEF 수신
            LOGINFO("DIT", "tag : %s, msg : %s", msg.tag, msg.msg);
            //데이터 출력
            DeleteNDEF(&msg);
        }
    }
    DestoryNFC (nfc);
    //NFC 모듈 삭제
}

Native

void NFC_Send (char * tag, char * msg)
{
    bool ret;
    system_info_get_platform_bool ("http://tizen.org/feature/network.nfc", &ret);

    if ( ret == true )
    {
        nfc_manager_set_tag_filter (NFC_TAG_FILTER_ALL_ENABLE);
    }
    //NFC 장비 유무 확인

    nfc_manager_initialize ();

    nfc_manager_is_supported ();

    nfc_manager_set_tag_filter (NFC_TAG_FILTER_ALL_ENABLE);

    bool flag = false;
    if ( nfc_manager_is_system_handler_enabled () != true )
    {
        if ( nfc_manager_set_system_handler_enable (true) == NFC_ERROR_NONE )
        {
            flag = true;
        }
    }
    else
    {
        flag = true;
    }
    //NFC 장비 연결 / 초기화

    if ( flag )
    {
        nfc_ndef_message_h ndef_message = NULL;
        nfc_ndef_message_create (&ndef_message);
        //NDEF 생성
        if ( strcmp (tag, "TEXT") == 0 )
        {
            nfc_ndef_record_create_text (&ndef_message, msg, "en-US", NFC_ENCODE_UTF_8);
        }
        else if ( strcmp (tag, "URI") == 0 )
        {
            nfc_ndef_record_create_uri (&ndef_message, msg);
        }
        else if ( strcmp (tag, "MIME") == 0 )
        {
            nfc_ndef_record_create_mime (&ndef_message, "image/jpeg", msg, sizeof (msg));
        }
        //NDEF 생성

        nfc_tag_h tag;
        nfc_tag_write_ndef (tag, ndef_message, NULL, NULL);
        //NFC 메세지 전송
        nfc_ndef_record_destroy (&ndef_message);
    }
}

void NFC_Recv ()
{
    bool ret;
    system_info_get_platform_bool ("http://tizen.org/feature/network.nfc", &ret);

    if ( ret == true )
    {
        nfc_manager_set_tag_filter (NFC_TAG_FILTER_ALL_ENABLE);
    }
    //NFC 장비 유무 확인

    nfc_manager_initialize ();

    nfc_manager_is_supported ();

    nfc_manager_set_tag_filter (NFC_TAG_FILTER_ALL_ENABLE);

    bool flag = false;
    if ( nfc_manager_is_system_handler_enabled () != true )
    {
        if ( nfc_manager_set_system_handler_enable (true) == NFC_ERROR_NONE )
        {
            flag = true;
        }
    }
    else
    {
        flag = true;
    }
    //NFC 장비 연결 / 초기화

    if ( flag )
    {
        nfc_tag_h tag;
        nfc_tag_read_ndef (tag, NULL, NULL);

        char tagChar[1000];
        int  tagLength;

        nfc_ndef_record_get_type (NULL, &tagChar, &tagLength);
        tag = (String)malloc (tagLength + 1);
        strcpy (tag, tagChar);

        char msgChar[1000];
        int  msgLength;

        nfc_ndef_record_get_type (NULL, &msgChar, &msgLength);
        msg = (String)malloc (msgLength + 1);
        strcpy (msg, msgChar);
        //NDEF 수신

        dlog_print (DLOG_INFO, "DIT", "tag : %s, msg : %s", tag, msg);
        //데이터 출력
    }
}