1919import org .eclipse .jdt .annotation .Nullable ;
2020import org .openhab .binding .broadlink .internal .BroadlinkBindingConstants ;
2121import org .openhab .binding .broadlink .internal .BroadlinkRemoteDynamicCommandDescriptionProvider ;
22+ import org .openhab .binding .broadlink .internal .Utils ;
2223import org .openhab .core .library .types .StringType ;
2324import org .openhab .core .storage .StorageService ;
2425import 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