void MacAddressHandler::handleNfcHandoverCompletedEvent(nfc_target_t *target)
{
    unsigned int messageCount = 0;
    nfc_get_ndef_message_count(target, &messageCount);

    if (messageCount > 0) {
        nfc_ndef_message_t *ndefMessage = 0;
        nfc_get_ndef_message(target, 0, &ndefMessage);
        nfc_ndef_record_t *record = 0;
        nfc_get_ndef_record(ndefMessage, 0, &record);

        // The MAC address is in little-endian order
        char *macAddress = 0;

        nfc_get_handover_bluetooth_mac_address(record, &macAddress);
        m_macAddress.sprintf("%02x:%02x:%02x:%02x:%02x:%02x", (unsigned int) macAddress[5],
                                (unsigned int) macAddress[4], (unsigned int) macAddress[3],
                                (unsigned int) macAddress[2], (unsigned int) macAddress[1],
                                (unsigned int) macAddress[0]);
        emit macAddressChanged();
        qDebug() << "[INFO] MAC ADDRESS: " << m_macAddress;
    } else {
        qWarning() << "[ERRO] No NdefMessage's found";
    }
}
示例#2
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;
	}
}