if (result) {
// Command - list
if (cmd[1].equals("list") || cmd[1].equals("l")) {
TreeSet<Integer> set = new TreeSet<Integer>( ports.keySet() );
RpSerialPort port;
for (Integer portnum: set) {
port = ports.get(portnum);
svcConsole.write(" " + portnum + ": " +port.getName() + "\n" );
}
} else
// Command - readstr
if (cmd[1].equals("readstr") || cmd[1].equals("rs")) {
RpSerialPort port = getPortForConsoleCommand(cmd);
svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ port.readAllString() +"\n" );
} else
// Command - readhex
if (cmd[1].equals("readhex") || cmd[1].equals("rh")) {
RpSerialPort port = getPortForConsoleCommand(cmd);
byte[] bin = new byte[2048];
int n = port.readBytes(bin);
byte[] bb = Arrays.copyOfRange(bin, 0, Math.abs(n));
svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ RpHyperstring.bytesToHexString(bb) +"\n" );
} else
// Command - write and read string
if (cmd[1].equals("str") || cmd[1].equals("s")) {
RpSerialPort port = getPortForConsoleCommand(cmd);
svcConsole.write(JRoboStrings.SVCSERIAL_WRITE_TO + port.getName()+": "+cmd[3]+"\n" );
port.writeString(cmd[3]+"\n");
Thread.sleep(500);
svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ port.readAllString() +"\n" );
} else
// Command - write and read hex
if (cmd[1].equals("hex") || cmd[1].equals("h")) {
RpSerialPort port = getPortForConsoleCommand(cmd);
byte[] bout = RpHyperstring.hexStringToBytes(cmd, 3);
svcConsole.write(JRoboStrings.SVCSERIAL_WRITE_TO + port.getName()+": "+ RpHyperstring.bytesToHexString(bout) +"\n" );
port.writeBytes(bout);
byte[] bin = new byte[2048];
int n = port.readBytes(bin);
byte[] bb = Arrays.copyOfRange(bin, 0, Math.abs(n));
svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ RpHyperstring.bytesToHexString(bb) +"\n" );
} else
// somebody else's command
result = false;
}