nfcip-initiator.c

Go to the documentation of this file.
00001 /*-
00002  * Public platform independent Near Field Communication (NFC) library
00003  * 
00004  * Copyright (C) 2009, Roel Verdult
00005  * 
00006  * This program is free software: you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by the
00008  * Free Software Foundation, either version 3 of the License, or (at your
00009  * option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00014  * more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00025 #ifdef HAVE_CONFIG_H
00026   #include "config.h"
00027 #endif // HAVE_CONFIG_H
00028 
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <nfc/nfc.h>
00032 
00033 #define MAX_FRAME_LEN 264
00034 
00035 int main(int argc, const char *argv[])
00036 {
00037   nfc_device_t *pnd;
00038   nfc_target_info_t ti;
00039   byte_t abtRecv[MAX_FRAME_LEN];
00040   size_t szRecvBits;
00041   byte_t send[] = "Hello World!";
00042 
00043   pnd = nfc_connect(NULL);
00044   if (!pnd || !nfc_initiator_init(pnd)
00045       || !nfc_initiator_select_dep_target(pnd, NM_PASSIVE_DEP, NULL, 0,
00046             NULL, 0, NULL, 0, &ti)) {
00047     printf
00048   ("unable to connect, initialize, or select the target\n");
00049     return 1;
00050   }
00051 
00052   printf("Sending : %s\n", send);
00053   if (!nfc_initiator_transceive_dep_bytes(pnd,
00054             send,
00055             strlen((char*)send), abtRecv,
00056             &szRecvBits)) {
00057     printf("unable to send data\n");
00058     return 1;
00059   }
00060 
00061   abtRecv[szRecvBits] = 0;
00062   printf("Received: %s\n", abtRecv);
00063 
00064   nfc_initiator_deselect_tag(pnd);
00065   nfc_disconnect(pnd);
00066   return 0;
00067 }
Generated by  doxygen 1.6.2-20100208