Skip to content

NFC APIs Design Specification #7426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Sep 2, 2018
Merged

NFC APIs Design Specification #7426

merged 28 commits into from
Sep 2, 2018

Conversation

donatieng
Copy link
Contributor

@donatieng donatieng commented Jul 5, 2018

Description

This pull request includes the design specification for adding NFC APIs in mbed OS, with a support for card emulation and NFC EEPROMs and NDEF encoding/decoding.

The design document for review can be found here: Design Document

It follows guidelines defined in this PR: #7561.

Pull request type

[ ] Fix
[ ] Refactor
[ ] New target
[x] Feature
[ ] Breaking change

@donatieng donatieng requested a review from a team July 5, 2018 15:28
@cmonr cmonr requested a review from kjbracey July 5, 2018 15:53
@donatieng donatieng changed the title NFC Design Specification NFC APIs Design Specification Jul 5, 2018
```
These methods called when a remote initiator (the local controller is acting as a target) or a remote target (the local controller is acting as an initiator) is detected.

Shared pointers are used so that the user does not have to maintain the lifetime of these objects. The `NFCController` instance will release its reference when the endpoint is lost (see below).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these objects are copyable then it might be better to pass them by value or const/reference and let the user code handle the copy if it is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I need to check if this is achievable but if so it makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on that one ?


```cpp
bool is_ndef_supported();
size_t nfc_tag_type();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a size_t here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point will switch to an enum

bool is_ndef_supported();
size_t nfc_tag_type();

void set_ndef_message(const NDEFMessage& message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is mismatch with the diagram for set_ndef_message, clear_ndef_message, get_ndef_message.
Does it returns nfc_err_t ?

virtual void on_deselected();
```

Some phones/readers 'park' a target and re-select it later - these events let the user know if the what state the local target is being put in.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: if the what

Some phones/readers 'park' a target and re-select it later - these events let the user know if the what state the local target is being put in.

```cpp
virtual void on_before_ndef_read();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the naming on_ndef_read_request and on_ndef_written would be more appropriate. I also wonder if the word message shouldn't be added to be more consistent with other delegates (see NFCTargetDelegate) What do you think ?

A NDEF Message is made of multiple NDEF Records which is reflected by the API:

```cpp
bool parse(const uint8_t* buffer, size_t sz)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the parse function ? Does it parse or does it validate then copy an NDEFMessage from a byte stream ?

All arrays are passed by reference (no copy made).

```cpp
static bool parse(const uint8_t* buffer, size_t max_sz)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it parse or validate ?

static bool parse(const uint8_t* buffer, size_t max_sz)
ssize_t build(const uint8_t* buffer, size_t max_sz)

uint8_t tnf()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is tnf ?


The following events must be called to signal completion of long operations:
```cpp
void on_backend_has_read_bytes(bool success, const uint8_t* bytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do better naming wise. I'm not sure that the on_backend prefix is required there.
Also I think it can be valuable to get a more descriptive error code.

Note: Shouldn't we get the size of the bytes read in the callback ?

# Dependencies
* Event Queue

There are currently at least four event queues (Plaftorm, BLE, USB, IP) in mbed OS and NFC will also require an event queing mechanism. We should aim at reusing one of these existing queues with the long term goal of unifying these code bases.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be solved by not instantiating the event queue inside the NFC stack but rather let the application provide it.
Dependency injection delegate the layout of the program to the application writer. Ble already does that for this reason.

@pan-
Copy link
Member

pan- commented Jul 19, 2018

One think I forgot to mention is naming consistency towards event handler classes. Should it be ClassNameDelegate, ClassNameEventHandler, ClassName::EventHandler ?

It would be nice to pick one and stick with it at the OS scale. So it become a recognizable pattern.

@cmonr
Copy link
Contributor

cmonr commented Aug 14, 2018

@donatieng Making sure, is the idea that once this is done with review, that it will be merged into Mbed OS' master branch, closed, with code changes coming, or should this go into its own feature branch?

@donatieng
Copy link
Contributor Author

donatieng commented Aug 14, 2018

@cmonr This one should land on master and will be followed by a subsequent PR for the implementation (targeting master as well). Aiming at having this one finalized by end of week.

@adbridge
Copy link
Contributor

@pan- Please confirm if you are happy with this now ?

@cmonr cmonr removed the risk: G label Aug 29, 2018
@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

@donatieng Please take a look and address @AnotherButler's comments.

@donatieng
Copy link
Contributor Author

@AnotherButler thanks for the review, comments addressed.
This PR is up to date and ready to go from our standpoint.

@cmonr
Copy link
Contributor

cmonr commented Sep 1, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Sep 1, 2018

Build : FAILURE

Build number : 2979
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7426/

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 1, 2018

Known failure, will be restarted once Connectivity drivers are in

@cmonr
Copy link
Contributor

cmonr commented Sep 1, 2018

It's in!
/morph build

@mbed-ci
Copy link

mbed-ci commented Sep 2, 2018

Build : SUCCESS

Build number : 2984
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7426/

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Sep 2, 2018

@mbed-ci
Copy link

mbed-ci commented Sep 2, 2018

@0xc0170 0xc0170 merged commit c6e18f9 into ARMmbed:master Sep 2, 2018
@cmonr cmonr removed the risk: G label Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants