Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.

Communicating Without Services

Luke Van Oort edited this page Jun 8, 2017 · 8 revisions

Overview

Communicating via either the SimpleTappyManager or a custom Tappy manager interfacing to a TappyBleCommunicationsService is not always the best choice for a given application. Developers who would prefer not to use either of these built-in services can instead work with the TappyBleCommunicator class directly.

Gradle Dependency

compile "com.taptrack.tcmptappy:commlink-ble:${latestVersion}"

Usage

TappyBleCommunicator communicator = 
    new TappyBleCommunicator(context,deviceDefinition);
//prepare to connect
communicator.initialize();
//connect to the tappy
communicator.connect();

// work with tappy

// disconnect from the tappy
communicator.disconnect();
// close the connection
// this cancels the connection and removes all listeners
communicator.close();

In order to listen to the status changes of the Tappy connection and any messages the Tappy sends, register a CommunicatorStatusChangedListener (see note on status values) and a TcmpMessageListener respectively. If you wish to also be notified of malformed unparsable packets being received, register an UnparsablePacketListener. One the communicator notified that it has entered a state of TappyBleDeviceStatus.READY, it is ready to communicate with the Tappy. Any TCMP messages you attempt to send while the Tappy is not ready will be queued up for sending once the connection is fully established. Additionally, the communicator will not attempt to reconnect if a connection is lost, if you wish to autoreconnect, you will have to listen for a change to TappyBleDeviceStatus.DISCONNECTED and reconnect (by calling connect()) yourself.

The TappyBleCommunicator is thread-safe so feel free to interact with it from whatever threads are convenient.