Ejemplo n.º 1
0
/*
 * This method processed an NFC Event when we're intending to Write a Uri Tag
 */
void NfcWorker::handleNfcWriteUriTagEvent(bps_event_t *event) {
	uint16_t code = bps_event_get_code(event);
	qDebug() << "XXXX NfcWorker::handleWriteUriTagEvent - processing event code " << code;

	nfc_event_t *nfcEvent;
	nfc_target_t* target;
	nfc_ndef_record_t* myNdefRecord;
	nfc_ndef_message_t* myNdefMessage;

	if (NFC_TAG_READWRITE_EVENT == code) {
		qDebug() << "XXXX NfcWorker::handleWriteUriTagEvent - Target Read Write Event";

		CHECK(nfc_get_nfc_event(event, &nfcEvent));
		CHECK(nfc_get_target(nfcEvent, &target));

		qDebug() << "XXXX NfcWorker::handleWriteUriTagEvent - Preparing to write URI: " << _ndefUri;
		myNdefRecord = makeUriRecord(Settings::NfcRtdUriPrefixNone, _ndefUri);

		CHECK(nfc_create_ndef_message(&myNdefMessage));
		CHECK(nfc_add_ndef_record(myNdefMessage, myNdefRecord));
		CHECK(nfc_write_ndef_message_to_tag(target, myNdefMessage, false));
		CHECK(nfc_delete_ndef_message(myNdefMessage, true));
		CHECK(nfc_destroy_target(target));
		emit message(QString("Tag Type Written URI: %1").arg(_ndefUri));
	} else {
		qDebug() << "XXXX NfcWorker::handleWriteUriTagEvent - NFC BPS event that we didn't register for: " << code;
	}
}
Ejemplo n.º 2
0
void NfcWorker::handleNfcWriteCustomTagEvent(bps_event_t *event) {
	uint16_t code = bps_event_get_code(event);
	qDebug() << "XXXX NfcWorker::handleNfcWriteCustomTagEvent - processing event code " << code;

	nfc_event_t *nfcEvent;
	nfc_target_t* target;
	nfc_ndef_record_t* myNdefRecord;
	nfc_ndef_message_t* myNdefMessage;

	if (NFC_TAG_READWRITE_EVENT == code) {
		qDebug() << "XXXX NfcWorker::handleNfcWriteCustomTagEvent - Target Read Write Event";
		CHECK(nfc_get_nfc_event(event, &nfcEvent));
		CHECK(nfc_get_target(nfcEvent, &target));
		qDebug() << "XXXX NfcWorker::handleWriteCustomTagEvent - Preparing to write Custom: DOMAIN=" << _ndefDomain << ", TYPE=" << _ndefType;
		myNdefRecord = makeCustomRecord(_ndefDomain, _ndefType, _ndefPayload);
		CHECK(nfc_create_ndef_message(&myNdefMessage));
		CHECK(nfc_add_ndef_record(myNdefMessage, myNdefRecord));
		CHECK(nfc_write_ndef_message_to_tag(target, myNdefMessage, false));
		CHECK(nfc_delete_ndef_message(myNdefMessage, true));
		CHECK(nfc_destroy_target(target));
		emit message(QString("Custom Tag Written"));
	} else {
		qDebug() << "XXXX NfcWorker::handleNfcWriteCustomTagEvent - NFC BPS event that we didn't register for< " << code;
	}

	qDebug() << "XXXX Write Custom Tag written";
	emit message(QString("Custom tag written OK"));

}
Ejemplo n.º 3
0
/*
 * This method processed an NFC Event when we're intending to Write an Sp Tag
 */
void NfcWorker::handleNfcWriteSpTagEvent(bps_event_t *event) {
	uint16_t code = bps_event_get_code(event);
	qDebug() << "XXXX NfcWorker::handleNfcWriteSpTagEvent - processing event code " << code;

	nfc_event_t *nfcEvent;
	nfc_target_t* target;
	nfc_ndef_record_t* spNdefRecord;
	nfc_ndef_message_t* myNdefMessage;

	if (NFC_TAG_READWRITE_EVENT == code) {
		qDebug() << "XXXX NfcWorker::handleNfcWriteSpTagEvent - Target Read Write Event";
		CHECK(nfc_get_nfc_event(event, &nfcEvent));
		CHECK(nfc_get_target(nfcEvent, &target));

		qDebug() << "XXXX NfcWorker::handleWriteSpTagEvent - Preparing to write Sp: URI=" << _ndefSpUri << ", Text=" << _ndefSpText;
		spNdefRecord = makeSpRecord();
		CHECK(nfc_create_ndef_message(&myNdefMessage));
		CHECK(nfc_set_sp_uri(spNdefRecord, _ndefSpUri.toUtf8().constData()));
		CHECK( nfc_add_sp_title(spNdefRecord, Settings::LANG_EN, _ndefSpText.toUtf8().constData()));
		CHECK(nfc_add_ndef_record(myNdefMessage, spNdefRecord));
		CHECK(nfc_write_ndef_message_to_tag(target, myNdefMessage, false));
		CHECK(nfc_delete_ndef_message(myNdefMessage, true));
		CHECK(nfc_destroy_target(target));
		emit message(QString("Tag Type Sp Written: %1 %2").arg(_ndefSpUri).arg(_ndefSpText));
	} else {
		qDebug() << "XXXX NfcWorker::handleNfcWriteSpTagEvent - NFC BPS event that we didn't register for: " << code;
	}

	qDebug() << "XXXX Write Sp Tag written";
	emit message(QString("Smart Poster tag written OK"));

}
void MacAddressHandler::event(bps_event_t *event)
{
    uint16_t code = bps_event_get_code(event);
    nfc_event_t *nfc_event = 0;

    if (nfc_get_nfc_event(event, &nfc_event) != BPS_SUCCESS) {
        qDebug() << "[ERRO] Get NFC event: BPS_FAILURE" << endl;
    }

    nfc_target_t *target = 0;
    nfc_get_target(nfc_event, &target);

    switch(code) {
        case NFC_HANDOVER_DETECTED_EVENT: {
            qDebug() << "[INFO] Received NFC_HANDOVER_DETECTED_EVENT" << endl;
            handleNfcHandoverDetectedEvent(target);
        }
        break;
        case NFC_HANDOVER_COMPLETE_EVENT: {
            handleNfcHandoverCompletedEvent(target);
            qDebug() << "[INFO] Received NFC_HANDOVER_COMPLETE_EVENT" << endl;
        }
        break;
        default: {
            qDebug() << "[WARN] Event not handled: " << code << endl;
        }
        break;
    }

    nfc_destroy_target(target);
}
Ejemplo n.º 5
0
void NfcWorker::handleSendVcardEvent(bps_event_t *event) {
	uint16_t code = bps_event_get_code(event);
	qDebug() << "XXXX NfcWorker::handleSendVcardEvent - processing event code " << code;

	nfc_event_t *nfcEvent;
	nfc_target_t* target;
	nfc_ndef_record_t* myNdefRecord;
	nfc_ndef_message_t* myNdefMessage;

	if (NFC_SNEP_CONNECTION_EVENT == code) {

		QString mimeType = QString("text/x-vCard");
		QString vCard = QString("BEGIN:VCARD\n").append("VERSION:3.0\n").append("N:").append(_last_name).append(";").append(_first_name).append("\n").append(
				"FN:").append(_first_name).append(" ").append(_last_name).append("\n").append("ADR;TYPE=WORK:").append(_address).append("\n").append(
				"TEL;TYPE=CELL:").append(_mobile).append("\n").append("EMAIL;TYPE=INTERNET:").append(_email).append("\n").append("END:VCARD");

		CHECK(nfc_get_nfc_event(event, &nfcEvent));
		CHECK(nfc_get_target(nfcEvent, &target));

		qDebug() << "XXXX NfcWorker::handleSendVcardEvent - Preparing to send vCard: FIRST NAME=" << _first_name << ", LAST NAME=" << _last_name << ", ADDRESS="
				<< _address << ", EMAIL=" << _email << ", MOBILE=" << _mobile;
		qDebug() << "XXXX make a media record";
		myNdefRecord = makeMediaRecord(mimeType, vCard);

		qDebug() << "XXXX Create NDEF message";
		CHECK(nfc_create_ndef_message(&myNdefMessage));

		qDebug() << "XXXX Add ndef media record";
		CHECK(nfc_add_ndef_record(myNdefMessage, myNdefRecord));

		qDebug() << "XXXX Write NDEF message";
		CHECK(nfc_push_ndef_message(target, myNdefMessage));

		qDebug() << "XXXX Delete NDEF Message";
		CHECK(nfc_delete_ndef_message(myNdefMessage, true));

		qDebug() << "XXXX Destroy NFC Target";
		CHECK(nfc_destroy_target(target));

		emit message(QString("vCard sent OK"));
	} else {
		qDebug() << "XXXX NfcWorker::handleSendVcardEvent - NFC BPS event that we didn't register for: " << code;
	}

	qDebug() << "XXXX SendVcard done";
}
Ejemplo n.º 6
0
/*
 * This method processed an NFC Event when we're intending to read an NDEF Tag
*/
void NfcWorker::handleNfcReadNdefTagEvent(bps_event_t *event) {
	uint16_t code = bps_event_get_code(event);
	nfc_event_t *nfcEvent;

	qDebug()
			<< "XXXX NfcWorker::handleNfcReadNdefTagEvent - processing event code "
			<< code;

	if (NFC_TAG_READWRITE_EVENT == code) {
		qDebug()
				<< "XXXX NfcWorker::handleNfcReadNdefTagEvent - NDEF read event";

		CHECK(nfc_get_nfc_event(event, &nfcEvent));
		qDebug()
				<< "XXXX NfcWorker::handleNfcReadNdefTagEvent - got NFC event object";

		nfc_target_t* target;
		CHECK(nfc_get_target(nfcEvent, &target));
		qDebug() << "XXXX NfcWorker::handleNfcReadNdefTagEvent - got target";

		int ndefMsgCount = 0;
		CHECK(nfc_get_ndef_message_count(target, &ndefMsgCount));
		qDebug()
				<< "XXXX NfcWorker::handleNfcReadNdefTagEvent - target message count="
				<< ndefMsgCount;

		for (int ndefMsgIndex = 0; ndefMsgIndex < ndefMsgCount;
				++ndefMsgIndex) {

			// Now processing an an NDEF message

		//	qDebug() << "XXXX Processing NDEF Message index: " << ndefMsgIndex;

		//	nfc_ndef_message_t *ndefMessage;
		//	CHECK(nfc_get_ndef_message(target, ndefMsgIndex, &ndefMessage));

			//TODO
			// Parse the ndef message!!
			CHECK(nfc_destroy_target(target));
		}
	} else {
		qDebug()
				<< "XXXX NfcWorker::handleNfcReadNdefTagEvent - NFC BPS event that we didn't register for: "
				<< code;
	}
}
Ejemplo n.º 7
0
void NfcWorker::handleNfcWriteUriTagEvent(bps_event_t *event) {
	uint16_t code = bps_event_get_code(event);
	qDebug()
			<< "XXXX NfcWorker::handleWriteUriTagEvent - processing event code "
			<< code;

	nfc_event_t *nfcEvent;
	nfc_target_t* target;
	nfc_ndef_message_t* myNdefMessage;

	if (NFC_TAG_READWRITE_EVENT == code) {
		qDebug()
				<< "XXXX NfcWorker::handleWriteUriTagEvent - Target Read Write Event";

		CHECK(nfc_get_nfc_event(event, &nfcEvent));
		CHECK(nfc_get_target(nfcEvent, &target));

		qDebug()
				<< "XXXX NfcWorker::handleWriteUriTagEvent - Preparing to write URI: ";

//--------- Try using C APIs----------------------------
		QString uri("www.google.ca");
		nfc_ndef_record_t* record = 0;
		int len = uri.length();
		uchar_t payload[len + 1];
		memcpy(&payload[0], uri.toUtf8().constData(), len);
		CHECK(nfc_create_ndef_record(NDEF_TNF_WELL_KNOWN, "U", payload, len + 1, 0, &record));
		CHECK(nfc_create_ndef_message(&myNdefMessage));
		CHECK(nfc_add_ndef_record(myNdefMessage,record));
		qDebug() << "Before Writing";

		bool status;
		status = true;
		CHECK(nfc_tag_is_writable(target,&status));

		CHECK(nfc_write_ndef_message_to_tag(target,myNdefMessage, true));
		qDebug() << "After Writing";
		CHECK(nfc_delete_ndef_message(myNdefMessage, true));
		CHECK(nfc_destroy_target(target));
	} else {
		qDebug()
				<< "XXXX NfcWorker::handleWriteUriTagEvent - NFC BPS event that we didn't register for: "
				<< code;
	}
}
Ejemplo n.º 8
0
//! [1]
void NfcSender::event(bps_event_t *event)
{
    uint16_t code = bps_event_get_code(event);
    nfc_event_t *nfc_event = 0;

    if (nfc_get_nfc_event(event, &nfc_event) != BPS_SUCCESS) {
        qDebug() << "[ERRO] Get NFC event: BPS_FAILURE" << endl;
    }

    nfc_target_t *target = 0;
    nfc_get_target(nfc_event, &target);

    switch (code) {
        case NFC_SNEP_CONNECTION_EVENT: {
            qDebug() << "[INFO] Received NFC_NDEF_PUSH_EVENT" << endl;
            handleSnepPush(target);
        }
        break;
        case NFC_NDEF_PUSH_SUCCEED_EVENT: {
            qDebug() << "[INFO] Received NFC_NDEF_PUSH_SUCCEED_EVENT" << endl;
        }
        break;
        case NFC_NDEF_PUSH_FAILURE_MSG_OVER_SIZE_EVENT: {
            qDebug() << "[ERRO] Received NFC_NDEF_PUSH_FAILURE_MSG_OVER_SIZE_EVENT" << endl;
        }
        break;
        case NFC_NDEF_PUSH_FAILURE_REJECTED_EVENT: {
            qDebug() << "[ERRO] Received NFC_NDEF_PUSH_FAILURE_REJECTED_EVENT" << endl;
        }
        break;
        case NFC_NDEF_PUSH_FAILURE_IO_ERROR_EVENT: {
            qDebug() << "[ERRO] Received NFC_NDEF_PUSH_FAILURE_IO_ERROR_EVENT" << endl;
        }
        break;
        default: {
            qDebug() << "[WARN] Event not handled: " << code << endl;
        }
        break;
    }

    nfc_destroy_target(target);
}