Tappy Communication Messaging Protocol (TCMP) command family for
performing basic tag detection, reading, emulating, and writing operations.
Installation
Bower
bower install tappy-basicnfcfamily
NPM
npm install @taptrack/tappy-basicnfcfamily
Commands
Tag Detection Commands
var BasicNfc = require('tappy-basicnfcfamily');
var Commands = BasicNfc.Commands;
var scanTag = new Commands.ScanTag(timeout, BasicNfc.PollingModes.TYPE1);
var streamTags = new Commands.StreamTags(timeout);
var scanNdef = new Commands.ScanNdef(timeout, BasicNfc.PollingModes.GENERAL);
var streamNdef = new Commands.StreamNdef(timeout);
Tag Writing Commands
var writeCustom = new Commands.WriteNdefCustom(timeout, lockTag, ndefData);
var writeText = new Commands.WriteNdefText(timeout, lockTag, textData);
var writeUri = new Commands.WriteNdefUri(timeout, lockTag, uri, uriCode);
Tag Emulation Commands
var emulateCustom = new Commands.EmulateNdefCustom(timeout, maxScans, ndefData);
var emulateText = new Commands.EmulateNdefText(timeout, maxScans, textData);
var emulateUri = new Commands.EmulateNdefUri(timeout, maxScans, uri, uriCode);
Utility Commands
var stop = new Commands.Stop();
var getLibraryVersion = new Commands.GetLibraryVersion();
Responses
Note: You should only manually construct responses as below for testing
purposes. in practice, please use the resolver described later to convert
raw TCMP messages received from the tappy into their corresponding concrete
response types with the payloads parsed appropriately.
Utility Responses
var applicationError = new Responses.ApplicationError();
applicationError.getErrorCode();
applicationError.getInternalErrorCode();
applicationError.getReaderStatusCode();
applicationError.getErrorMessage();
var libVersion = new Responses.LibraryVersion();
libVersion.getMajorVersion();
libVersion.getMinorVersion();
Tag Detection Responses
var ndefFound = new Responses.NdefFound();
ndefFound.getTagType();
ndefFound.getTagCode();
ndefFound.getMessage();
var scanTimeout = new Responses.ScanTimeout();
var tagFound = new Responses.TagFound();
tagFound.getTagType();
tagFound.getTagCode();
Tag Writing Responses
var tagWritten = new Responses.TagWritten();
tagWritten.getTagType();
tagWritten.getTagCode();
Tag Emulation Responses
var emulationScanSuccess = new Responses.EmulationScanSuccess()
var emulationComplete = new Responses.EmulationComplete();
emulationComplete.getReasonCode();
emulationComplete.getScanCount();
Resolver
While you can manually resolve raw TCMP messages received from the Tappy using
getCommandFamily()
, getCommandCode()
, getPayload()
, and parsePayload()
, it is
much more convenient to use the built-in resolvers and isTypeOf()
.
var resolver = new BasicNfc.Resolver();
if(resolver.checkFamily(responseMsg)) {
var resolved = resolver.resolveResponse(responseMsg);
if(resolved !== null && BasicNfc.Responses.LibraryVersion.isTypeOf(resolved)) {
console.log("BasicNfc version v" + resolved.getMajorVersion() + "." +
resolved.getMinorVersion());
}
}
There is a corresponding resolveCommand
function for commands in case you are storing
commands in a raw form. Note that commands and responses have overlapping commandCode
space, so you'll need to keep track of whether the message was sent to the Tappy
or received from it, and use the appropriate resolution function.