Package lejos.remote.nxt
Class LCPResponder
- java.lang.Object
-
- java.lang.Thread
-
- lejos.remote.nxt.LCPResponder
-
- All Implemented Interfaces:
java.lang.Runnable
public class LCPResponder extends java.lang.ThreadSupport for LCP commands- Author:
- Lawrie Griffiths/Andy Shaw
-
-
Field Summary
Fields Modifier and Type Field Description protected NXTConnectionconnprotected NXTCommConnectorconnectorprotected booleanrunning
-
Constructor Summary
Constructors Constructor Description LCPResponder(NXTCommConnector connector)Create a Responder using the provided connector The connector is used to create the listening connection used to accept remote commands.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intcommand(byte[] inMsg, int len, byte[] reply)Process the actual command Default action is to call the LCP object to emulate the commandprotected voiddisconnect()Method called to disconnect the responder connect.booleanisConnected()Checks whether there is an active connectionprotected voidpostCommand(byte[] inMsg, int inLen, byte[] replyMsg, int replyLen)protected intpreCommand(byte[] inMsg, int len)Method called with a newly read command, before it is processed.voidrun()voidshutdown()Terminate the responder.protected voidwaitConnect()Method called when the responder is waiting for a new connection.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
connector
protected NXTCommConnector connector
-
conn
protected NXTConnection conn
-
running
protected boolean running
-
-
Constructor Detail
-
LCPResponder
public LCPResponder(NXTCommConnector connector)
Create a Responder using the provided connector The connector is used to create the listening connection used to accept remote commands.- Parameters:
connector-
-
-
Method Detail
-
waitConnect
protected void waitConnect()
Method called when the responder is waiting for a new connection. Default action is to wait for the new connection and return.
-
disconnect
protected void disconnect()
Method called to disconnect the responder connect. Default action is to close the underlying connection object.
-
preCommand
protected int preCommand(byte[] inMsg, int len)Method called with a newly read command, before it is processed. Default action is to detect invalid commands and if detected to drop the connection.- Parameters:
inMsg- Newly read commandlen- length of the command- Returns:
- the length of the command
-
command
protected int command(byte[] inMsg, int len, byte[] reply)Process the actual command Default action is to call the LCP object to emulate the command- Parameters:
inMsg- The command byteslen- length of the commandreply- bytes to send back in response to the command- Returns:
- length of the reply
-
postCommand
protected void postCommand(byte[] inMsg, int inLen, byte[] replyMsg, int replyLen)
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
shutdown
public void shutdown()
Terminate the responder. Abort any listening operation and close any open connections (this will also abort any current read requests).
-
isConnected
public boolean isConnected()
Checks whether there is an active connection- Returns:
- true iff the responder is connected
-
-