pt.citar.diablu.nxt.protocol
Class NXTCommand

java.lang.Object
  extended by pt.citar.diablu.nxt.protocol.NXTCommand
Direct Known Subclasses:
NXTCommandGetBatteryLevel, NXTCommandGetInputValues, NXTCommandGetOutputState, NXTCommandLSRead, NXTCommandLSWrite, NXTCommandPlayTone, NXTCommandReceiveMsg, NXTCommandResetMotorPosition, NXTCommandSendMsg, NXTCommandSetInputMode, NXTCommandSetOutputState

public abstract class NXTCommand
extends Object

Represents a Command that can be sent to the NXTBrick. This class cannot be instantiated. Only subclasses which represent concrete Commands should be used. Commands can generate Responses if so required. Responses are encapsulated by NXTResponse subclasses. Subclasses should implement the sendCommand() method and any specific parameter setting methods.

Author:
Jorge Cardoso
See Also:
NXTResponse

Constructor Summary
NXTCommand()
          Constructs a new command object with no response requirement.
NXTCommand(boolean responseRequired)
          Constructs a new command object with a response requirement.
 
Method Summary
 int getPacketLength()
           
 boolean isResponseRequired()
          Returns the response requirements for the command.
 NXTResponse sendCommand(NXTCommChannel channel)
          Sends the command to the brick and returns the response (if required).
 void setResponseRequired(boolean responseRequired)
          Sets the requirement for a response to the command.
 String toString()
          Formats the command packet in hex form.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NXTCommand

public NXTCommand()
Constructs a new command object with no response requirement.


NXTCommand

public NXTCommand(boolean responseRequired)
Constructs a new command object with a response requirement.

Parameters:
responseRequired - The response requirement. false, no response required. true, response required.
Method Detail

sendCommand

public NXTResponse sendCommand(NXTCommChannel channel)
                        throws IOException
Sends the command to the brick and returns the response (if required).

Parameters:
is - The InputStream from which the response can be read.
os - The OutputStream to send the command.
Returns:
The NXTResponse response. This should be cast to the apropriate subclass.
Throws:
IOException

getPacketLength

public int getPacketLength()

isResponseRequired

public boolean isResponseRequired()
Returns the response requirements for the command.

Returns:
The response requirement.

setResponseRequired

public void setResponseRequired(boolean responseRequired)
Sets the requirement for a response to the command. If a response to a command is not strictly necessary that this should be set to false in order to achieve a faster communication.

Parameters:
responseRequired - true if a response is required, false if a response is not required.

toString

public String toString()
Formats the command packet in hex form.

Overrides:
toString in class Object
Returns:
The command packet in hex form.


Processing library NXTComm by Jorge C. S. Cardoso. (c) 2014