|
jAER project on SourceForge | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.jaer.util.RemoteControl
public class RemoteControl
Remote control via a datagram connection. Listeners add themselves with a command string and list of arguments. Remote control builds a parser and returns calls the appropriate listener. The listener can access the arguments by name. A remote client can connect to the UDP port and obtain a list of commands with the help command. Using, for example, netcat (or nc.exe on Windows), a session might look as follows (the -u means use UDP connection)
>nc -u localhost 8995 > ? ? is unknown command - type help for help > help Available commands are setifoll bitvalue - Set the bitValue of IPot foll setidiffoff bitvalue - Set the bitValue of IPot diffOff seticas bitvalue - Set the bitValue of IPot cas setidiffon bitvalue - Set the bitValue of IPot diffOn setirefr bitvalue - Set the bitValue of IPot refr setipux bitvalue - Set the bitValue of IPot puX setipuy bitvalue - Set the bitValue of IPot puY setireqpd bitvalue - Set the bitValue of IPot reqPd setireq bitvalue - Set the bitValue of IPot req setiinjgnd bitvalue - Set the bitValue of IPot injGnd setidiff bitvalue - Set the bitValue of IPot diff setipr bitvalue - Set the bitValue of IPot Pr >Commands are added to an object as shown next; getRemoteControl accesses in this example the Chip's built-in RemoteControl. This object implements RemoteControlled. It adds a single command "setbufferbias".
if (getRemoteControl() != null) {
getRemoteControl().addCommandListener(this, "setbufferbias bitvalue", "Sets the buffer bias value");
}
This RemoteControlled implements the processCommand method like this; processCommand returns a String which contains the results.
public String processCommand(RemoteControlCommand command, String input) {
String[] tok = input.split("\\s");
if (tok.length < 2) {
return "bufferbias " + getValue()+"\n";
} else {
try {
int val = Integer.parseInt(tok[1]);
setValue(val);
} catch (NumberFormatException e) {
return "?\n";
}
}
return "bufferbias " + getValue()+"\n";
}
| Field Summary | |
|---|---|
static int |
PORT_DEFAULT
The default UDP local port for the default constructor. |
| Constructor Summary | |
|---|---|
RemoteControl()
Makes a new RemoteControl on the default port |
|
RemoteControl(int port)
Creates a new instance. |
|
| Method Summary | |
|---|---|
void |
addCommandListener(RemoteControlled remoteControlled,
java.lang.String cmd,
java.lang.String description)
Objects that want to receive commands should add themselves here with a command string and command description (for showing help). |
void |
close()
|
static void |
main(java.lang.String[] args)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int PORT_DEFAULT
| Constructor Detail |
|---|
public RemoteControl()
throws java.net.SocketException
java.net.SocketException
public RemoteControl(int port)
throws java.net.SocketException
port - the UDP port number this RemoteControl listens on.
java.net.SocketException| Method Detail |
|---|
public void close()
public void addCommandListener(RemoteControlled remoteControlled,
java.lang.String cmd,
java.lang.String description)
remoteControlled - the remote controlled object.cmd - a string such as "setipr bitvalue". "setipr" is the command and the RemoteControlled is responsible for parsing the rest of the line.description - for showing help.
public static void main(java.lang.String[] args)
throws java.net.SocketException
java.net.SocketException
|
jAER project on SourceForge | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||