Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openhab.binding.haywardomnilogiclocal.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The type to request.
Expand Down Expand Up @@ -48,4 +49,13 @@ private HaywardMessageType(int msgInt) {
public int getMsgInt() {
return msgInt;
}

public static @Nullable HaywardMessageType fromMsgInt(int msgInt) {
for (HaywardMessageType type : values()) {
if (type.msgInt == msgInt) {
return type;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.zip.InflaterInputStream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.haywardomnilogiclocal.internal.HaywardMessageType;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.QNameMap;
Expand All @@ -37,10 +38,9 @@
*/
@NonNullByDefault
public class UdpClient {
private static final int MSG_TYPE_ACK = 1002;
private static final int MSG_ACK = 1002;
private static final int MSG_LEAD = 1998;
private static final int MSG_BLOCK = 1999;
private static final HaywardMessageType MSG_ACK = HaywardMessageType.ACK;
private static final HaywardMessageType MSG_LEAD = HaywardMessageType.MSP_LEADMESSAGE;
private static final HaywardMessageType MSG_BLOCK = HaywardMessageType.MSP_BLOCKMESSAGE;

private static final QNameMap QNAME_MAP;
private static final XStream XSTREAM;
Expand Down Expand Up @@ -88,12 +88,11 @@ public UdpResponse send(UdpRequest request) throws IOException {
int msgId = buffer.getInt();
buffer.getLong();
buffer.position(16);
int msgType = buffer.getInt();
@Nullable HaywardMessageType msgType = HaywardMessageType.fromMsgInt(buffer.getInt());

boolean thisCompressed = data[22] == 1;

if (msgType == MSG_LEAD || msgType == MSG_BLOCK
|| msgType == HaywardMessageType.MSP_TELEMETRY_UPDATE.getMsgInt()) {
if (msgType == MSG_LEAD || msgType == MSG_BLOCK || msgType == HaywardMessageType.MSP_TELEMETRY_UPDATE) {
sendAck(socket, msgId);
}

Expand All @@ -118,7 +117,7 @@ public UdpResponse send(UdpRequest request) throws IOException {
header.putInt(msgId);
header.putLong(System.currentTimeMillis());
header.put("1.22".getBytes(StandardCharsets.US_ASCII));
header.putInt(msgType);
header.putInt(msgType.getMsgInt());
header.put((byte) 1);
header.put(new byte[3]);
byte[] xmlBytes = (xml + '\0').getBytes(StandardCharsets.UTF_8);
Expand All @@ -128,7 +127,7 @@ public UdpResponse send(UdpRequest request) throws IOException {
response = UdpResponse.fromBytes(packetBytes, packetBytes.length);
break;
}
} else if (msgType == HaywardMessageType.ACK.getMsgInt()) {
} else if (msgType == HaywardMessageType.ACK) {
continue;
} else {
response = UdpResponse.fromBytes(data, data.length);
Expand All @@ -151,7 +150,7 @@ private void sendAck(DatagramSocket socket, int messageId) throws IOException {
header.putInt(messageId);
header.putLong(System.currentTimeMillis());
header.put("1.22".getBytes(StandardCharsets.US_ASCII));
header.putInt(MSG_TYPE_ACK);
header.putInt(MSG_ACK.getMsgInt());
header.put((byte) 1);
header.put(new byte[3]);

Expand All @@ -163,7 +162,7 @@ private void sendAck(DatagramSocket socket, int messageId) throws IOException {
DatagramPacket packet = new DatagramPacket(out, out.length, address, port);
socket.send(packet);

UdpRequest ack = new UdpRequest(MSG_ACK, "", messageId);
UdpRequest ack = new UdpRequest(MSG_ACK.getMsgInt(), "", messageId);
byte[] ackBytes = ack.toBytes();
DatagramPacket ackPacket = new DatagramPacket(ackBytes, ackBytes.length, address, port);
socket.send(ackPacket);
Expand Down