How to realize >>poll<< cycle as described in AN4910 in swift UIKit?
Hi all,
My aim is to develop an iPhone app with UIKit in
Xcode using CoreNFC to communicate to a ISO/IEC 15693
tag. In particular, to communicate to a ST25DV64K type 5 tag.
The data exchange between iPhone and tag is done by using
ST25DV64K its fast transfer mode mailbox.
In RF, mailbox is read and written via a dedicated (Fast) Read/
Write Message commands.
Infrastructure:
MacBook Air M1 2020 macOS Sonoma 14.0
iPhone 14 Pro Max iOs 17.0.3
Xcode 15.0
Under UIKit I am able to use the CoreNFC framework and the
customCommand() function to read and write the ST25 tag - its
working well. But I have two basic questions:
1)
I try to establish a handshake procedure to exchange data
between the iPhone and the NFC tag.
This procedure is well described in ST-AN4910:
1. RF put message
2. Host detect event
3. Host get message
4. RF poll for message being read by host
5. Repeat from step 1 until all data are transmitted
1, 2 and 3 are easy done and are already implemented
successful. Currently I struggle with 4, especially with the
„poll“. I know I have to read the MB_CTRL_Dyn register using
custom command 0xAD. This is already implemented and
working well. But if the response says: „host didn’t read
message yet“, or if an error occurred, I need to repeat the
command -> poll. I need to implement a kind of loop until the
response is as expected („host read message“). Between the
custom commands/between the loops probably a short delay
(a few milliseconds) might be needed on top.
My questions:
1a) Has the entire sequence 1, 4 and 5, including the potential
loops, as described above, to be done in: session.connect(to:
tags.first!) {here?}
1b) Embedding the custom command 0xAD, to see if the
message was read by RF, into a while loop causes errors:
45[NFCTagReaderSession
transceive:tagUpdate:error:]:888 Error
Domain=NFCError Code=100 "Tag connection lost"
UserInfo={NSLocalizedDescription=Tag connection lost}
Therefore, I guess there is another way of doing the poll?
2)
In case 1a) is answered with „yes“, it would be helpful to
outsource some code to avoid session.connect() is becoming
too large in size and is not readable anymore. I was thinking to
use some functions but I don’t know if this is a good idea?
self.readMailbox(tag: iso15693Tag, session:
session)
self.writeMailbox(tag: iso15693Tag, session:
session)
This would mean I make a copy of session and I can’t believe
it’s a good idea. I was thinking of making a reference to session
by using „&“ operator but the compiler don’t allow it. I assume
some basic understanding is missing. Could you please help
me to find a way to avoid methods and functions are becoming
too large and therefore are difficult to read and to understand?
Every hint is welcome!
