Broadlink binding for RMx, A1, SPx and MP. Any interest?

I’ve had some time to pick up the dev work on the British General sockets, which look to extend the SP4b sockets.

I think I’ve got the payload sorted, but my java skills are weak and byte operations in java are weaker.

The Python here has the following code:

        checksum = sum(packet[0x08:], 0xC0AD) & 0xFFFF
        packet[0x06] = checksum & 0xFF
        packet[0x07] = checksum >> 8

I’ve seen in the existing binding code there’s some for loops for checksums, but I’m struggling to work out what the python is doing. It’s taking the byte array from the flag onwards and adding 0xc0ad but I don’t understand anything else.

My rudimentary, untested code for the encode function at the moment is as follows. I’m thinking I should move to using a ByteBuffer instead.

private void encodeMessage(int flag, String json) {
        int length = 12 + json.length();
        Byte[] packet = new Byte[14 + json.length()];
        packet[0x00] = (byte) (length & 0xFF);
        packet[0x01] = (byte) ((length >> 8) & 0xFF);
        packet[0x02] = (byte) (0xa5a5 & 0xFF);
        packet[0x03] = (byte) ((0xa5a5 >> 8) & 0xFF);
        packet[0x04] = 0x5a5a & 0xFF;
        packet[0x05] = ((0x5a5a >> 8) & 0xFF);
        packet[0x06] = 0x00;
        packet[0x07] = 0x00;
        packet[0x08] = (byte) flag;
        packet[0x09] = 0x0B;
        packet[0x0a] = (byte) (json.length() & 0xFF);
        packet[0x0b] = (byte) ((json.length() >> 8) & 0xFF);
        packet[0x0c] = (byte) ((json.length() >> 16) & 0xFF);
        packet[0x0d] = (byte) ((json.length() >> 24) & 0xFF);
        for (int i = 0; i < json.length(); i++) {            
            packet[i + 15] = (byte) json.charAt(i);
        }
}

Any help would be appreciated