Skip to content

Commit

Permalink
Update SDK readme
Browse files Browse the repository at this point in the history
  • Loading branch information
afilini committed Mar 12, 2024
1 parent 7c6a8cc commit 47e90cf
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ The SDK is divided into a `CardManager`, which is not exposed to the final user

The user only needs to implement the code required to receive and send raw (byte arrays) messages from/to the NFC card. This could be done in many different ways depending on the specific platform: in this repo an example implementation uses libnfc, which should work on all common desktop platforms.

Afterwards, the user will need to spawn a thread* which repeatedly calls `sdk.wait()` in a loop: this method will return an `Option<NfcOut>`, which tells the user whether there's a command to send via NFC: The `Transceive` variant means that the user should send the message and expect a reply from the card (which he should then give to the sdk with `sdk.push_incoming(data)`). The `Send` variant means that the user should just send the data via NFC.
Afterwards, the user will need to spawn a task which repeatedly calls `sdk.poll()` in a loop: this method will return an `NfcOut` struct, which is composed of a byte array message and a numeric message id. The message should be sent via NFC and then the reply provided back to the library with `sdk.incoming_data()`.

Calling `wait()` repeatedly will drive the internal state machine and drive the communication with the NFC card, so it's very important to always keep doing that.

`PortalSdk` exposes methods to send commands to the card, like `get_status()` to get the device status, `generate_mnemonic(num_words)` to make the device generate a new mnemonic, etc. Since the `PortalSdk` structure is thread-safe, these calls could be made from any other thread, while the main loop keeps calling `wait()`.

\* Note that it's not actually strictly required to spawn a new thread, although it makes the code easier to manage. It's technically possible to interleave calls to `wait()` with calls to all the other methods of `PortalSdk` in the same thread.
`PortalSdk` exposes methods to send commands to the card, like `get_status()` to get the device status, `generate_mnemonic(num_words)` to make the device generate a new mnemonic, etc. Since the `PortalSdk` structure is thread-safe, these calls could be made from any other task or thread, while the main task keeps calling `poll()`.

## CLI

This crate also has a binary target that uses `libnfc` to connect to a supported NFC reader and talk to the portal. To try it out use the following command:

```
cargo run --features=libnfc --bin=cli
```
```

0 comments on commit 47e90cf

Please sign in to comment.