public class AsciiCommander extends java.lang.Object implements IAsciiCommandExecuting, java.util.Observer
Modifier and Type | Class and Description |
---|---|
static class |
AsciiCommander.ConnectionState
The connection states for AsciiCommander
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONNECT_FAILED_PREFIX |
static java.lang.String |
CONNECTED_MESSAGE_PREFIX |
static java.lang.String |
CONNECTING_MESSAGE_PREFIX |
static java.lang.String |
DISCONNECTED_MESSAGE_PREFIX |
static java.lang.String |
REASON_KEY |
static java.lang.String |
STATE_CHANGED_NOTIFICATION |
static java.lang.String |
USER_DISCONNECTED_MESSAGE_PREFIX |
Constructor and Description |
---|
AsciiCommander(android.content.Context context)
Initializes a new instance of the AsciiCommander class
|
Modifier and Type | Method and Description |
---|---|
void |
addResponder(IAsciiCommandResponder responder)
Add a responder to the responder chain
|
void |
addSynchronousResponder()
Add the synchronous responder into the chain
|
void |
clearResponders()
Clear all responders from the responder chain
|
void |
connect(android.bluetooth.BluetoothDevice reader)
Connect the AsciiCommander to the given reader
This is an asynchronous operation.
|
void |
disconnect()
Disconnects from the current device
|
void |
executeCommand(IAsciiCommand command)
Execute the given command
|
java.lang.String |
getConnectedDeviceName() |
AsciiCommander.ConnectionState |
getConnectionState()
Query the AsciiCommander's connection state
|
DeviceProperties |
getDeviceProperties() |
boolean |
getHasSynchronousResponder()
Gets a value indicating whether the chain has a synchronous responder
|
java.util.Date |
getLastActivityTime() |
java.lang.String |
getLastCommandLine() |
java.lang.Iterable<IAsciiCommandResponder> |
getResponderChain()
Gets the chain of responders that handle responses to commands
|
boolean |
hasConnectedSuccessfully()
Query for a previously successful connection to a device
|
boolean |
isConnected()
Gets a value indicating whether a reader is connected
|
boolean |
isResponsive() |
void |
permanentlyDisconnect()
Sends the signal to the accessory to permanently disconnect
Once issued this will require waking and reconnecting to the reader to use it again.
|
protected void |
processReceivedLine(java.lang.String line,
int lineNumber,
boolean moreAvailable)
Called from ProcessReceivedLines to process each line received from the reader
|
protected void |
processReceivedLines(java.util.Collection<java.lang.String> receivedLines)
This should be called when new data is received from the reader
|
void |
removeResponder(IAsciiCommandResponder responder)
Remove a responder from the responder chain
|
void |
removeSynchronousResponder()
Remove the synchronous responder from the chain
|
void |
send(java.lang.String line)
Send the given string as a CrLf terminated string, to the reader.
|
protected void |
setLastActivityTime(java.util.Date value) |
void |
update(java.util.Observable arg0,
java.lang.Object arg1) |
public static final java.lang.String STATE_CHANGED_NOTIFICATION
public static final java.lang.String REASON_KEY
public static final java.lang.String CONNECT_FAILED_PREFIX
public static final java.lang.String CONNECTING_MESSAGE_PREFIX
public static final java.lang.String CONNECTED_MESSAGE_PREFIX
public static final java.lang.String USER_DISCONNECTED_MESSAGE_PREFIX
public static final java.lang.String DISCONNECTED_MESSAGE_PREFIX
public AsciiCommander(android.content.Context context)
public final DeviceProperties getDeviceProperties()
public java.lang.String getConnectedDeviceName()
public final boolean hasConnectedSuccessfully()
public final boolean isConnected()
public AsciiCommander.ConnectionState getConnectionState()
public final void connect(android.bluetooth.BluetoothDevice reader)
reader
- The UHF Reader that supports the TSL ASCII 2.0 protocolpublic final void disconnect()
public final void permanentlyDisconnect()
public void send(java.lang.String line)
line
- line The ASCII string to send to the devicejava.lang.UnsupportedOperationException
- if no device is connectedpublic final boolean isResponsive()
public final java.util.Date getLastActivityTime()
protected final void setLastActivityTime(java.util.Date value)
public final java.lang.String getLastCommandLine()
public final java.lang.Iterable<IAsciiCommandResponder> getResponderChain()
getResponderChain
in interface IAsciiCommandExecuting
public final boolean getHasSynchronousResponder()
public void executeCommand(IAsciiCommand command)
executeCommand
in interface IAsciiCommandExecuting
command
- The command to execute
For synchronous commands the responder's delegate is set to this object
Otherwise does nothing
Derived classes should always call the inherited implementation.public final void addResponder(IAsciiCommandResponder responder)
addResponder
in interface IAsciiCommandExecuting
responder
- The responder to addpublic final void removeResponder(IAsciiCommandResponder responder)
removeResponder
in interface IAsciiCommandExecuting
responder
- The responder to removepublic final void addSynchronousResponder()
addSynchronousResponder
in interface IAsciiCommandExecuting
public final void removeSynchronousResponder()
removeSynchronousResponder
in interface IAsciiCommandExecuting
public final void clearResponders()
clearResponders
in interface IAsciiCommandExecuting
protected void processReceivedLines(java.util.Collection<java.lang.String> receivedLines) throws java.lang.Exception
receivedLines
- A number of complete lines received from the readerjava.lang.Exception
protected void processReceivedLine(java.lang.String line, int lineNumber, boolean moreAvailable) throws java.lang.Exception
line
- The received linelineNumber
- The line number in the set of lines being processedmoreAvailable
- True if not the last line in the setjava.lang.Exception
public void update(java.util.Observable arg0, java.lang.Object arg1)
update
in interface java.util.Observer