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 ();
if ( nfc->isAccessible (nfc))
{
if ( nfc->onConnect (nfc))
{
NDEF ndef = CreateNDEF (tag, msg);
nfc->Send (nfc, ndef);
DeleteNDEF(&ndef);
}
}
DestoryNFC (nfc);
}
void NFC_Recv ()
{
NFC nfc = NewNFC ();
if ( nfc->isAccessible (nfc))
{
if ( nfc->onConnect (nfc))
{
NDEF msg = nfc->Recv (nfc);
LOGINFO("DIT", "tag : %s, msg : %s", msg.tag, msg.msg);
DeleteNDEF(&msg);
}
}
DestoryNFC (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_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;
}
if ( flag )
{
nfc_ndef_message_h ndef_message = NULL;
nfc_ndef_message_create (&ndef_message);
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));
}
nfc_tag_h tag;
nfc_tag_write_ndef (tag, ndef_message, NULL, NULL);
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_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;
}
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);
dlog_print (DLOG_INFO, "DIT", "tag : %s, msg : %s", tag, msg);
}
}