2009-10-12 16:52:26 +02:00
|
|
|
/**
|
|
|
|
* Public platform independent Near Field Communication (NFC) library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Roel Verdult
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @file nfcip-initiator.c
|
|
|
|
* @brief
|
|
|
|
*/
|
|
|
|
|
2009-09-03 15:47:26 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-11-04 11:14:17 +01:00
|
|
|
#include <nfc.h>
|
2009-09-03 15:47:26 +02:00
|
|
|
|
|
|
|
int main(int argc, const char *argv[])
|
|
|
|
{
|
2009-11-09 12:23:33 +01:00
|
|
|
nfc_device_t *pnd;
|
2009-09-03 15:47:26 +02:00
|
|
|
tag_info ti;
|
|
|
|
byte_t abtRecv[MAX_FRAME_LEN];
|
2009-10-02 11:52:02 +02:00
|
|
|
size_t szRecvBits;
|
2009-09-03 15:47:26 +02:00
|
|
|
byte_t send[] = "Hello World!";
|
|
|
|
|
2009-11-09 12:23:33 +01:00
|
|
|
pnd = nfc_connect(NULL);
|
|
|
|
if (!pnd || !nfc_initiator_init(pnd)
|
|
|
|
|| !nfc_initiator_select_dep_target(pnd, IM_PASSIVE_DEP, NULL, 0,
|
2009-09-03 15:47:26 +02:00
|
|
|
NULL, 0, NULL, 0, &ti)) {
|
|
|
|
printf
|
|
|
|
("unable to connect, initialize, or select the target\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Sending : %s\n", send);
|
2009-11-09 12:23:33 +01:00
|
|
|
if (!nfc_initiator_transceive_dep_bytes(pnd,
|
2009-09-03 15:47:26 +02:00
|
|
|
send,
|
2009-10-05 11:12:48 +02:00
|
|
|
strlen((char*)send), abtRecv,
|
2009-10-02 11:52:02 +02:00
|
|
|
&szRecvBits)) {
|
2009-09-03 15:47:26 +02:00
|
|
|
printf("unable to send data\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-10-02 11:52:02 +02:00
|
|
|
abtRecv[szRecvBits] = 0;
|
2009-09-03 15:47:26 +02:00
|
|
|
printf("Received: %s\n", abtRecv);
|
|
|
|
|
2009-11-09 12:23:33 +01:00
|
|
|
nfc_initiator_deselect_tag(pnd);
|
|
|
|
nfc_disconnect(pnd);
|
2009-09-03 15:47:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|