Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        INFCNdefTag GetNdefTag(INFCTag tag)
        {
            if (tag == null || !tag.Available)
            {
                return(null);
            }

            INFCNdefTag ndef;

            if (tag.GetNFCMiFareTag() != null)
            {
                ndef = tag.GetNFCMiFareTag();
            }
            else if (tag.GetNFCIso7816Tag() != null)
            {
                ndef = tag.GetNFCIso7816Tag();
            }
            else if (tag.GetNFCFeliCaTag() != null)
            {
                ndef = tag.GetNFCFeliCaTag();
            }
            else
            {
                ndef = null;
            }

            return(ndef);
        }
Пример #2
0
        public static INFCNdefTag GetNdefTag(INFCTag tag)
        {
            if (tag == null /*|| !tag.Available*/)
            {
                return(null);
            }
            NFCTagType tp = (NFCTagType)tag.Type;

            INFCNdefTag ndef;

            if (tag.GetNFCMiFareTag() != null)
            {
                ndef = tag.GetNFCMiFareTag();
            }
            else if (tag.GetNFCIso7816Tag() != null)
            {
                ndef = tag.GetNFCIso7816Tag();
            }
            else if (tag.GetNFCFeliCaTag() != null)
            {
                ndef = tag.GetNFCFeliCaTag();
            }
            else
            {
                ndef = null;
            }

            return(ndef);
        }
Пример #3
0
        protected override async Task OnTagDetected(NFCTagReaderSession session, INFCTag tag)
        {
            if (SelectedAmiibo == null)
            {
                session.AlertMessage = "Select an amiibo to clone.";
                return;
            }

            if (SelectedAmiibo != null)
            {
                session.AlertMessage = $"Writing {SelectedAmiibo.Metadata.Name} to this tag...";

                await WriteAmiibo(session, tag.GetNFCMiFareTag(), SelectedAmiibo);

                return;
            }
        }
Пример #4
0
        public async Task <byte[]> ReadTagData(
            NFCTagReaderSession session, INFCTag tag)
        {
            await session.ConnectToAsync(tag);

            var mifare = tag.GetNFCMiFareTag();

            if (mifare is null)
            {
                return(new byte[0]); // not a mifare tag
            }
            var tagData =
                await mifare.DoFastRead(
                    from : 0x0, to : 0x86,
                    batchSize : 0x43
                    );

            Debug.WriteLine(
                "Tag Data:\r\n" +
                Utils.HexDump(tagData, 8));

            return(tagData);
        }
Пример #5
0
        public async Task <DetectedAmiibo> TryReadAmiibo(NFCTagReaderSession session, INFCTag tag)
        {
            // dump tag data
            Debug.WriteLine($"Found a tag: {tag}");

            // get mifare representation
            var mifareTag  = tag.GetNFCMiFareTag();
            var identifier = mifareTag.Identifier.ToArray();

            // connect w h y
            await session.ConnectToAsync(tag);

            // read entire tag contents
            var tagData =
                await mifareTag.DoFastRead(
                    from : 0x0, to : 0x86,
                    batchSize : 0x20
                    );

            // dump tag data
            Debug.WriteLine($"== Raw tag data ==\r\n" +
                            $"{Utils.HexDump(tagData, 16)}");

            // extract character identifiers
            var identificationHeader = tagData.Slice(0x15 * 4, 0x2 * 4);

            var uid       = identifier.String();
            var game      = identificationHeader.SliceStr(0, 4);
            var character = identificationHeader.SliceStr(4, 4);

            // print identifiers
            Debug.WriteLine(
                $"== Identifiers ==\r\n" +
                $"Nfc Uid: {uid}\r\n" +
                $"Game Id: {game}\r\n" +
                $"Char Id: {character}\r\n");

            // get metadata from amiibo api
            session.AlertMessage = $"Looking up Amiibo...";

            var lookup = await AmiiboApi.GetAmiibo(game, character);

            var metadata = lookup.Amiibo.FirstOrDefault();

            // dump metadata
            Debug.WriteLine(
                $"== Metadata : https://www.amiiboapi.com/api/ ==\r\n" +
                metadata.ToJson());

            // we did it!
            session.AlertMessage = $"It's {metadata.Name}!";

            var imageData = await new HttpClient().GetByteArrayAsync(metadata.Image);

            return(new DetectedAmiibo
            {
                UID = uid,
                CharacterId = $"{game}-{character}",
                Metadata = metadata,
                TagData = tagData,
                ImageData = imageData,
            });
        }