Skip to content

Commit 3b6d3b2

Browse files
committed
Finally managed to figure out the issues with the RM3 mini. This should fix them.
Signed-off-by: AntonJansen <gradius@fmf.nl>
1 parent 9abcc3c commit 3b6d3b2

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/internal/handler/BroadlinkRemoteHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void dispose() {
9292
return sendCommand(commandByte, new byte[0], purpose);
9393
}
9494

95-
private byte @Nullable [] sendCommand(byte commandByte, byte[] codeBytes, String purpose) {
95+
protected byte @Nullable [] sendCommand(byte commandByte, byte[] codeBytes, String purpose) {
9696
try {
9797
ByteArrayOutputStream outputStream = buildCommandMessage(commandByte, codeBytes);
9898
byte[] padded = Utils.padTo(outputStream.toByteArray(), 16);
@@ -183,7 +183,7 @@ private void handleIRCommand(String irCommand, boolean replacement) {
183183
}
184184
}
185185
} catch (IOException e) {
186-
logger.warn("Exception while attempting to check learnt code: {}", e.getMessage());
186+
logger.warn("Exception while attempting to check learnt code: {}", e.getMessage(), e);
187187
updateState(BroadlinkBindingConstants.LEARNING_CONTROL_CHANNEL, new StringType("NULL"));
188188
}
189189
}

bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/internal/handler/BroadlinkRemoteModel3V44057Handler.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.jdt.annotation.Nullable;
2020
import org.openhab.binding.broadlink.internal.BroadlinkBindingConstants;
2121
import org.openhab.binding.broadlink.internal.BroadlinkRemoteDynamicCommandDescriptionProvider;
22+
import org.openhab.binding.broadlink.internal.Utils;
2223
import org.openhab.core.library.types.StringType;
2324
import org.openhab.core.storage.StorageService;
2425
import org.openhab.core.thing.Thing;
@@ -40,20 +41,16 @@ public BroadlinkRemoteModel3V44057Handler(Thing thing,
4041
@Override
4142
protected byte @Nullable [] sendCommand(byte commandByte, byte[] codeBytes, String purpose) {
4243
try {
43-
// Little Endian len(codeBytes)+4, unsigned short (2 bytes) + command, unsigned int (4 bytes)
44-
int length = codeBytes.length + 4;
45-
length = length & 0xffff; // truncate
46-
4744
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
48-
outputStream.write((byte) (length & 0xFF));
49-
outputStream.write((byte) ((length >> 8) & 0xFF));
50-
51-
outputStream.write(commandByte);
52-
outputStream.write(0x00);
53-
outputStream.write(0x00);
54-
outputStream.write(0x00);
55-
byte[] message = buildMessage((byte) 0x6a, outputStream.toByteArray());
56-
logger.debug("Sending byte[]: {}", message);
45+
// We start using an unsigned int (2 bytes) that indicates the size of the command (4 bytes) and the length
46+
// of the codeBytes
47+
int length = codeBytes.length + 4;
48+
length = length & 0xffff; // truncate, ensure we have an unsigned short int value
49+
outputStream.write((byte) (length & 0xFF)); // We have an unsigned int with little Endian
50+
outputStream.write((byte) ((length >> 8) & 0xFF)); // So the larger part goes later
51+
buildCommandMessage(commandByte, codeBytes).writeTo(outputStream);
52+
byte[] padded = Utils.padTo(outputStream.toByteArray(), 16);
53+
byte[] message = buildMessage((byte) 0x6a, padded);
5754
return sendAndReceiveDatagram(message, purpose);
5855
} catch (IOException e) {
5956
updateState(BroadlinkBindingConstants.LEARNING_CONTROL_CHANNEL,
@@ -63,4 +60,12 @@ public BroadlinkRemoteModel3V44057Handler(Thing thing,
6360

6461
return null;
6562
}
63+
64+
@Override
65+
protected byte[] extractResponsePayload(byte[] responseBytes) throws IOException {
66+
byte decryptedResponse[] = decodeDevicePacket(responseBytes);
67+
// Interesting stuff begins at the sixth byte, as we now have the extra short unsigned int in the response
68+
// as compared to the "standard" devices
69+
return Utils.slice(decryptedResponse, 6, decryptedResponse.length);
70+
}
6671
}

0 commit comments

Comments
 (0)