#include <nfc_internal.h>
#define BUFFER_LEN 10
-#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
-#define TC_PRT(format, args...) PRT(format"\n", ##args)
+#define PRT(format, args...) printf("%s:%d() " format, __FUNCTION__, __LINE__, ##args)
+#define TC_PRT(format, args...) PRT(format "\n", ##args)
GMainLoop *main_loop = NULL;
-typedef struct {
+typedef struct
+{
const char *tc_name;
int tc_code;
} tc_table_t;
{"NFC Configure discovery (CE only) Test", 2},
{"NFC Configure discovery (Tag only) Test", 3},
{"NFC Tag NDEF Read", 4},
- {"NFC Tag NDEF Write", 5},
- {"NFC Deinitialize Test", 6},
- {"NFC Configure discovery (ALL enable) Test", 7},
- {"NFC Configure discovery (ALL disable) Test", 8},
+ {"NFC Test Mode ON", 5},
+ {"NFC Test Mode OFF", 6},
+ {"NFC Deinitialize Test", 7},
+ {"NFC Configure discovery (ALL enable) Test", 8},
+ {"NFC Configure discovery (ALL disable) Test", 9},
/* -----------*/
- {"Finish" , 0x00ff},
- {NULL , 0x0000},
+ {"Finish", 0x00ff},
+ {NULL, 0x0000},
};
void tc_usage_print(void)
{
int i = 0;
- while (tc_table[i].tc_name) {
+ while (tc_table[i].tc_name)
+ {
if (tc_table[i].tc_code != 0x00ff)
TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name);
else
void __tag_read_completed(nfc_error_e result, nfc_ndef_message_h message, void *user_data)
{
- if (result == NFC_ERROR_NONE) {
+ if (result == NFC_ERROR_NONE)
+ {
int count = 0;
nfc_ndef_message_get_record_count(message, &count);
TC_PRT("tag read successful");
TC_PRT("record count : %d", count);
- if (count > 0) {
+ if (count > 0)
+ {
nfc_ndef_record_h record = NULL;
int ret = nfc_ndef_message_get_record(message, 0, &record);
- if (ret != NFC_ERROR_NONE) {
+ if (ret != NFC_ERROR_NONE)
+ {
TC_PRT("fail to get record from ndef message: %d", ret);
return;
}
- if (record != NULL) {
+ if (record != NULL)
+ {
char *lang_code = NULL;
int id_size = 0;
int type_size = 0;
nfc_ndef_record_get_type(record, &type, &type_size);
TC_PRT("3. type : %s, type_size : %d", type, type_size);
- if (strcmp((const char *)type, "T") == 0) {
- char* text = NULL;
+ if (strcmp((const char *)type, "T") == 0)
+ {
+ char *text = NULL;
nfc_ndef_record_get_text(record, &text);
TC_PRT("3. This record is Text record.");
TC_PRT("----* record 0 information end *----");
}
}
- } else {
+ }
+ else
+ {
TC_PRT("tag read error : %d", result);
}
}
void __tag_discovered(nfc_discovered_type_e type, nfc_tag_h tag, void *user_data)
{
- if (type == NFC_DISCOVERED_TYPE_ATTACHED) {
+ if (type == NFC_DISCOVERED_TYPE_ATTACHED)
+ {
nfc_tag_type_e tag_type = NFC_UNKNOWN_TARGET;
bool is_support_ndef = false;
nfc_tag_is_support_ndef(tag, &is_support_ndef);
TC_PRT("NDEF is supported? : %d", is_support_ndef);
-
- } else if (type == NFC_DISCOVERED_TYPE_DETACHED) {
+ }
+ else if (type == NFC_DISCOVERED_TYPE_DETACHED)
+ {
TC_PRT("tag detached!!!");
}
}
-char* nfc_util_itoa(char* fmt, ...)
+char *nfc_util_itoa(char *fmt, ...)
{
char str[128];
va_list arguments;
nfc_ndef_message_h msg = NULL;
nfc_ndef_record_h ndef_name_record = NULL;
unsigned int seed = time(NULL);
- char* time_str = nfc_util_itoa("The random text : %d", rand_r(&seed));
+ char *time_str = nfc_util_itoa("The random text : %d", rand_r(&seed));
nfc_ndef_message_create(&msg);
nfc_ndef_record_create_text(&ndef_name_record, time_str, "en-US", NFC_ENCODE_UTF_8);
int ret = 0;
long test_id = (long)data;
- switch (test_id) {
+ switch (test_id)
+ {
case 0x00ff:
TC_PRT("Finished");
g_main_loop_quit(main_loop);
break;
case 1:
- {
- TC_PRT("nfc initialize start");
- ret = nfc_manager_initialize();
- if (ret == NFC_ERROR_NONE)
- TC_PRT("NFC Initialize successful");
- else
- TC_PRT("NFC Error occur : %d", ret);
-
- nfc_manager_set_tag_discovered_cb(__tag_discovered, NULL);
- TC_PRT("nfc initialize end");
- }
- break;
+ {
+ TC_PRT("nfc initialize start");
+ ret = nfc_manager_initialize();
+ if (ret == NFC_ERROR_NONE)
+ TC_PRT("NFC Initialize successful");
+ else
+ TC_PRT("NFC Error occur : %d", ret);
+
+ nfc_manager_set_tag_discovered_cb(__tag_discovered, NULL);
+ TC_PRT("nfc initialize end");
+ }
+ break;
case 2:
- {
- TC_PRT("nfc configure discovery : CE only start");
- ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_CONFIG_LISTENING);
- TC_PRT("nfc configure discovery : CE only end : %d", ret);
- }
- break;
+ {
+ TC_PRT("nfc configure discovery : CE only start");
+ ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_CONFIG_LISTENING);
+ TC_PRT("nfc configure discovery : CE only end : %d", ret);
+ }
+ break;
case 3:
- {
- TC_PRT("nfc configure discovery : Tag only start");
- ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_CONFIG_POLLING);
- TC_PRT("nfc configure discovery : Tag only end : %d", ret);
- }
- break;
+ {
+ TC_PRT("nfc configure discovery : Tag only start");
+ ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_CONFIG_POLLING);
+ TC_PRT("nfc configure discovery : Tag only end : %d", ret);
+ }
+ break;
case 4:
- {
- TC_PRT("Tag read start");
- nfc_tag_h current_tag = NULL;
- nfc_manager_get_connected_tag(¤t_tag);
+ {
+ TC_PRT("Tag read start");
+ nfc_tag_h current_tag = NULL;
+ nfc_manager_get_connected_tag(¤t_tag);
- if (current_tag != NULL)
- ret = nfc_tag_read_ndef(current_tag, __tag_read_completed, NULL);
- else
- TC_PRT("Tag Not Connected");
+ if (current_tag != NULL)
+ ret = nfc_tag_read_ndef(current_tag, __tag_read_completed, NULL);
+ else
+ TC_PRT("Tag Not Connected");
- TC_PRT("Tag read end");
- }
- break;
+ TC_PRT("Tag read end");
+ }
+ break;
case 5:
- {
- TC_PRT("Tag write start");
-
- nfc_tag_h current_tag = NULL;
- nfc_manager_get_connected_tag(¤t_tag);
- nfc_ndef_message_h msg = __create_ndef_message();
-
- if (msg != NULL) {
- if (current_tag != NULL)
- ret = nfc_tag_write_ndef(current_tag, msg, __tag_write_completed, NULL);
- else
- TC_PRT("Tag Not Connected.");
- } else {
- TC_PRT("NDEF Message create is failed.");
- }
-
- TC_PRT("Tag write end");
- }
- break;
+ {
+ TC_PRT("Test Mode ON");
+ nfc_manager_test_mode_on();
+ }
+ break;
case 6:
- {
- TC_PRT("nfc deinitialize start");
+ {
+ TC_PRT("Test Mode OFF");
+ nfc_manager_test_mode_off();
+ }
+ break;
+ case 7:
+ {
+ TC_PRT("nfc deinitialize start");
- ret = nfc_manager_deinitialize();
- if (ret == NFC_ERROR_NONE)
- TC_PRT("NFC Deinitialize successful");
- else
- TC_PRT("NFC Error occur : %d", ret);
+ ret = nfc_manager_deinitialize();
+ if (ret == NFC_ERROR_NONE)
+ TC_PRT("NFC Deinitialize successful");
+ else
+ TC_PRT("NFC Error occur : %d", ret);
- TC_PRT("nfc deinitialize end");
- }
- break;
- case 7:
- {
- TC_PRT("nfc configure discovery : All enable start");
- ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_RESUME);
- TC_PRT("nfc configure discovery : All enable end : %d", ret);
- }
- break;
+ TC_PRT("nfc deinitialize end");
+ }
+ break;
case 8:
- {
- TC_PRT("nfc configure discovery : All disable start");
- ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_STOP);
- TC_PRT("nfc configure discovery : All enable end : %d", ret);
- }
- break;
+ {
+ TC_PRT("nfc configure discovery : All enable start");
+ ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_RESUME);
+ TC_PRT("nfc configure discovery : All enable end : %d", ret);
+ }
+ break;
+ case 9:
+ {
+ TC_PRT("nfc configure discovery : All disable start");
+ ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_STOP);
+ TC_PRT("nfc configure discovery : All enable end : %d", ret);
+ }
+ break;
default:
tc_usage_print();
break;
}
static gboolean key_event_cb(GIOChannel *chan,
- GIOCondition cond,
- gpointer data)
+ GIOCondition cond,
+ gpointer data)
{
- char buf[BUFFER_LEN] = { 0 };
+ char buf[BUFFER_LEN] = {0};
gsize len = 0;
long test_id;
return TRUE;
}
-
-int main(int argc, char ** argv)
+int main(int argc, char **argv)
{
GIOChannel *key_io;
g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- key_event_cb, NULL);
+ key_event_cb, NULL);
g_io_channel_unref(key_io);