-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ST25TB poller refining + write support #3239
ST25TB poller refining + write support #3239
Conversation
7922e3c
to
0578c3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @augustozanellato , thanks for PR!
First of all - everything works fine. However there are some things I want to discuss.
It would be nice if all pollers in NFC library looks similarly. That would help to maintain NFC subsystem a lot. I left some suggestions in code review.
Also I want to discuss poller states. Since your poller becomes bigger and you already added write capabilities in sync API, I suggest expanding poller itself. I would make these states in poller:
- Idle - reset St25tbPoller instance
- Select - selects card, emit "Ready" event with card type in event data
- Request mode - emit "RequestMode" event and receive mode in event data. Modes are St25tbPollerModeRead and St25tbPollerModeWrite
- Read - reads tag and switches to Fail or Success states
- Write - emits "RequestBlockData" event and receive block and block number in event data. Performs write command and switches to Fail or Success states.
- Fail - emits "Fail" event with error code in event data. Ends with furi_delay_ms(100) to switch context and switches to Idle state.
- Success - emits "Success" event with error code in event data. Ends with furi_delay_ms(100) to switch context and switches to Idle state.
In this case your sync API would be easy to write and we will have easier way to implement "write" in NFC application. You can see how it's done in mf classic poller for example.
Please, let me know what you think about this. We can do this step by step: merge this PR first and then refactore st25tb poller in future
Also please don't forget to lint sources :) |
I usually have format on save enabled, I'll figure out why it didn't work this time.
The thing that made me architect this poller different from the other ones was that this one is kinda an exception from the standard poller in the sense that it doesn't have either a parent or any children protocols, but has to implement both "low level" (anticollision, selection etc) and "high level" (data reading and writing). |
I think we should just iterate on this pr until we get to a decent shape without breaking API even more times :) |
It took less time than expected.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done, thank you! I think poller looks much better now
Thanks for your suggestions :) |
No problems with that. Usually I add Idle state to set all variables in poller instance to default values. Since there are not so many variables in this poller, Idle state is useless. If the poller will grow, we can add this state if necessary.
I was thinking about different Write mode behavior - to call "RequestBlockData" event, write blocks until upper layer provides data. When upper layer stops providing data poller switches to Success state. This is quite flexible behavior which allows you to write not only one block after anticollision, but perform multiple write operations in one communication session. |
Yeah that makes sense.
I didn't think about that, but that could be solved by having |
Yes, that's actually a good solution. Will you do that in this PR? |
Done, I was just waiting for some feedback :) |
Perfect, thanks! |
The failing unit test is subghz related, I don't think that could be directly related to this pr 🤔 |
Yes, the problem is not this PR |
Looks like extra - read specific card type - st25tb is now broken, I'll hook up a debugger and figure out why. |
* type wasn't properly set on ready event * sending NfcCustomEventPollerFailure on St25tbPollerEventTypeFailure caused poller to being freed and ultimately resulted in a thread crash
Bug fixed, while investigating that one I also found another one, more details in commit message. |
What's new
This PR should be ~same to #3185 but based on the improved NFC APIs
Verification
Checklist (For Reviewer)