View Source LibNFC.Mock (LibNFC v0.1.0)

NFC device emulation for testing purposes without physical interaction with a NFC device.

This module allows to emulate the presence of NFC targets in range of a "mock" device. LibNFC.Mock is a GenServer (to be spawned within a supervision tree) that holds the status of NFC targets in range. Functions on LibNFC accepting a :mock parameter instead of the NFC device reference will fetch data from this server instead of actually talking to libnfc.

Summary

Types

Link to this type

modulation()

View Source (since 0.1.0)
@type modulation() :: atom()
Link to this type

server_options()

View Source (since 0.1.0)
@type server_options() :: [
  nif_delay: non_neg_integer() | false,
  nif_delay_jitter: non_neg_integer()
]

Server options

  • nif_delay emulates delay of NIF calls (default: 400)
  • nif_delay_jitter jitter factor for delay (default: 0.5)
Link to this type

target()

View Source (since 0.1.0)
@type target() :: %{modulation: modulation(), target_info: target_info()}
Link to this type

target_info()

View Source (since 0.1.0)
@type target_info() :: %{required(String.t()) => binary()}

Functions

Link to this function

clear_target()

View Source (since 0.1.0)
@spec clear_target() :: :ok

Removes the NFC target.

Link to this function

put_target(target_info \\ %{"uid" => :rand.bytes(4)}, modulation \\ :iso14443a)

View Source (since 0.1.0)
@spec put_target(target_info(), modulation()) :: :ok

Puts a NFC target in range.

Link to this function

start_link(opts \\ [])

View Source (since 0.1.0)
@spec start_link(server_options()) :: GenServer.on_start()

Starts the mock process.