lejos.nxt.comm
Class LCPResponder

java.lang.Object
  extended by java.lang.Thread
      extended by lejos.nxt.comm.LCPResponder
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
LCPBTResponder

public class LCPResponder
extends Thread

Support for LCP commands

Author:
Lawrie Griffiths/Andy Shaw

Field Summary
protected  NXTConnection conn
           
protected  NXTCommConnector connector
           
protected  boolean running
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
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
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
protected  void disconnect()
          Method called to disconnect the responder connect.
protected  void postCommand(byte[] inMsg, int inLen, byte[] replyMsg, int replyLen)
           
protected  int preCommand(byte[] inMsg, int len)
          Method called with a newly read command, before it is processed.
 void run()
          When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
 void shutdown()
          Terminate the responder.
protected  void waitConnect()
          Method called when the responder is waiting for a new connection.
 
Methods inherited from class java.lang.Thread
currentThread, getName, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setName, setPriority, sleep, start, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 command
len - 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 bytes
len - length of the command
reply - 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()
Description copied from interface: Runnable
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Specified by:
run in interface Runnable
Overrides:
run in class 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).