Reputation: 10552
Hey all I am having an issue with trying to figure out why this code does not work. it never errors - it just doesn't do anything. I checked with my Onkyo iPhone app and it works and I'm using the same config as it is.
Here is the main code that sets up the command:
public StringBuilder getEiscpMessage(String command) {
StringBuilder sb = new StringBuilder();
int eiscpDataSize = 2 + command.length() + 1; // this is the eISCP data size
sb.append("ISCP");
// the following are all in HEX representing one char
// 4 char Big Endian Header
sb.append((char) 0x00);
sb.append((char) 0x00);
sb.append((char) 0x00);
sb.append((char) 0x10);
// 4 char Big Endian data size
sb.append((char) ((eiscpDataSize >> 24) & 0xFF));
sb.append((char) ((eiscpDataSize >> 16) & 0xFF));
sb.append((char) ((eiscpDataSize >> 8) & 0xFF));
sb.append((char) (eiscpDataSize & 0xFF));
// eiscp_version = "01";
sb.append((char) 0x01);
// 3 chars reserved = "00"+"00"+"00";
sb.append((char) 0x00);
sb.append((char) 0x00);
sb.append((char) 0x00);
// eISCP data
// Start Character
sb.append("!");
// eISCP data - unittype char '1' is receiver
sb.append("1");
// eISCP data - 3 char command and param ie PWR01
sb.append(command);
// msg end - EOF
//sb.append((char) Integer.parseInt("0D", 16));
sb.append((char) 0x0D);
System.out.println("eISCP data size: " + eiscpDataSize + "(0x" + Integer.toHexString(eiscpDataSize) + ") chars");
System.out.println("eISCP msg size: " + sb.length() + "(0x" + Integer.toHexString(sb.length()) + ") chars");
return sb;
}
public void sendCommand(String command, boolean closeSocket) {
StringBuilder sb = getEiscpMessage(command);
if (connectSocket()) {
try {
System.out.println("sending " + sb.length() + " chars: ");
convertStringToHex(sb.toString(), true);
out_.writeBytes(sb.toString());
out_.flush();
System.out.println("sent!");
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
if (closeSocket) closeSocket();
}
public static String convertStringToHex(String str, boolean dumpOut) {
char[] chars = str.toCharArray();
String out_put = "";
if (dumpOut) System.out.println("Ascii: " + str);
if (dumpOut) System.out.print("Hex: ");
StringBuffer hex = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
out_put = Integer.toHexString((int) chars[i]);
if (out_put.length() == 1) hex.append("0");
hex.append(out_put);
if (dumpOut)
System.out.print("0x" + (out_put.length() == 1 ? "0" : "") + out_put + " ");
}
if (dumpOut) System.out.println("");
return hex.toString();
}
The output its sending looks like this:
ISCP������������������!1QSTN
And according to the documentation it looks right to me?
And the rest of the System.out.printLn is this:
eISCP data size: 7(0x7) chars
eISCP msg size: 23(0x17) chars
Connected to 192.168.1.33 on port 60128
out_Init
inInit
sending 23 chars:
Ascii: ISCP??????????????????!1PWRQSTN
Hex: 0x49 0x53 0x43 0x50 0x00 0x00 0x00 0x10 0x00 0x00 0x00 0x07 0x01 0x00 0x00 0x00 0x21 0x31 0x51 0x53 0x54 0x4e 0x0d
sent!
Here is the full source code to the java app.
It would be great if someone who knows java sockets and byte code better than I jump in and help me out! Maybe there's just something I am missing or incorrectly inserting? :o)
Upvotes: 0
Views: 46