public class AsciiCommander extends java.lang.Object implements IAsciiCommandExecuting
Modifier and Type | Field and Description |
---|---|
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 |
abortSynchronousCommand()
Terminates the currently running synchronous command
|
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
|
static void |
createSharedInstance(android.content.Context context)
Create the shared instance of the AsciiCommander
Does nothing if instance already exists
|
void |
executeCommand(IAsciiCommand command)
Execute the given command
|
java.lang.String |
getCommanderId()
Identifier for the AsciiCommander instance that is unique for the life of the App
but not identical across App launches
|
java.lang.String |
getConnectedDeviceName()
A display name for the currently connected device
|
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() |
Reader |
getReader()
Gets the currently connected reader
|
java.lang.Iterable<IAsciiCommandResponder> |
getResponderChain()
Gets the chain of responders that handle responses to commands
|
boolean |
isConnected()
Gets a value indicating whether a reader is connected and ready for use
|
boolean |
isResponsive() |
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
|
IResponderChainErrorDelegate |
responderChainErrorDelegate()
The delegate to notify when there is an unhandled exception in the ResponderChain
|
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 |
setReader(Reader reader)
Set the reader being used
|
void |
setResponderChainErrorDelegate(IResponderChainErrorDelegate delegate)
Sets the responder chain error delegate
|
static AsciiCommander |
sharedInstance() |
public static final java.lang.String STATE_CHANGED_NOTIFICATION
public static final java.lang.String REASON_KEY
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 getCommanderId()
public java.lang.String getConnectedDeviceName()
public Reader getReader()
public void setReader(Reader reader)
reader
- the Reader to usepublic IResponderChainErrorDelegate responderChainErrorDelegate()
public void setResponderChainErrorDelegate(IResponderChainErrorDelegate delegate)
delegate
- teh delegatepublic static void createSharedInstance(android.content.Context context)
context
- the ApplicationContext for the AsciiCommanderpublic static AsciiCommander sharedInstance()
public final boolean isConnected()
public ConnectionState getConnectionState()
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 abortSynchronousCommand()