I have a message
static int[] message = {
0x01, 0x10, 0x00,
0x01, // port addres 01 - 08
0x00, 0x01, 0x02,
0x06, 0x00,
0xA4, 0x21
};
I know the data are right, as of I’m writing them to COM port with RXTX, and I got right HW reaction
I know that 0x01 is 1 value, and sent really like 01 (which is two bits, quarter byte long)
When I need to adjust the message, is generating values like this right?
message[index] = 1 & 0xff
I see the output of this snippet, and it looks properly
for (int i = 0; i < 255; i++) {
System.out.println(i & 0xff);
}
Is there any sheet you’d recommend me to read?
Is storing these numbers in int right, as we cannot use byte (-128, +127) for values up to <0x00, 0xFF> range
You probably want to use a
ByteBufferfor what you need, and wrap it under a class.I don’t know your exact message format, but let’s say for a moment this is 3 bytes of data and 1 byte of a port:
You can even use ByteBuffer’s hashCode() and equals() to compare messages, if you only ever use absolute get/put methods (otherwise quite a bit of gymnastic is in order).
I used this technique to read/write NRPE packets.