2727import java .util .zip .InflaterInputStream ;
2828
2929import org .eclipse .jdt .annotation .NonNullByDefault ;
30+ import org .eclipse .jdt .annotation .Nullable ;
3031import org .openhab .binding .haywardomnilogiclocal .internal .HaywardMessageType ;
3132import com .thoughtworks .xstream .XStream ;
3233import com .thoughtworks .xstream .io .xml .QNameMap ;
3738 */
3839@ NonNullByDefault
3940public class UdpClient {
40- private static final int MSG_TYPE_ACK = 1002 ;
41- private static final int MSG_ACK = 1002 ;
42- private static final int MSG_LEAD = 1998 ;
43- private static final int MSG_BLOCK = 1999 ;
41+ private static final HaywardMessageType MSG_ACK = HaywardMessageType .ACK ;
42+ private static final HaywardMessageType MSG_LEAD = HaywardMessageType .MSP_LEADMESSAGE ;
43+ private static final HaywardMessageType MSG_BLOCK = HaywardMessageType .MSP_BLOCKMESSAGE ;
4444
4545 private static final QNameMap QNAME_MAP ;
4646 private static final XStream XSTREAM ;
@@ -88,12 +88,11 @@ public UdpResponse send(UdpRequest request) throws IOException {
8888 int msgId = buffer .getInt ();
8989 buffer .getLong ();
9090 buffer .position (16 );
91- int msgType = buffer .getInt ();
91+ @ Nullable HaywardMessageType msgType = HaywardMessageType . fromMsgInt ( buffer .getInt () );
9292
9393 boolean thisCompressed = data [22 ] == 1 ;
9494
95- if (msgType == MSG_LEAD || msgType == MSG_BLOCK
96- || msgType == HaywardMessageType .MSP_TELEMETRY_UPDATE .getMsgInt ()) {
95+ if (msgType == MSG_LEAD || msgType == MSG_BLOCK || msgType == HaywardMessageType .MSP_TELEMETRY_UPDATE ) {
9796 sendAck (socket , msgId );
9897 }
9998
@@ -118,7 +117,7 @@ public UdpResponse send(UdpRequest request) throws IOException {
118117 header .putInt (msgId );
119118 header .putLong (System .currentTimeMillis ());
120119 header .put ("1.22" .getBytes (StandardCharsets .US_ASCII ));
121- header .putInt (msgType );
120+ header .putInt (msgType . getMsgInt () );
122121 header .put ((byte ) 1 );
123122 header .put (new byte [3 ]);
124123 byte [] xmlBytes = (xml + '\0' ).getBytes (StandardCharsets .UTF_8 );
@@ -128,7 +127,7 @@ public UdpResponse send(UdpRequest request) throws IOException {
128127 response = UdpResponse .fromBytes (packetBytes , packetBytes .length );
129128 break ;
130129 }
131- } else if (msgType == HaywardMessageType .ACK . getMsgInt () ) {
130+ } else if (msgType == HaywardMessageType .ACK ) {
132131 continue ;
133132 } else {
134133 response = UdpResponse .fromBytes (data , data .length );
@@ -151,7 +150,7 @@ private void sendAck(DatagramSocket socket, int messageId) throws IOException {
151150 header .putInt (messageId );
152151 header .putLong (System .currentTimeMillis ());
153152 header .put ("1.22" .getBytes (StandardCharsets .US_ASCII ));
154- header .putInt (MSG_TYPE_ACK );
153+ header .putInt (MSG_ACK . getMsgInt () );
155154 header .put ((byte ) 1 );
156155 header .put (new byte [3 ]);
157156
@@ -163,7 +162,7 @@ private void sendAck(DatagramSocket socket, int messageId) throws IOException {
163162 DatagramPacket packet = new DatagramPacket (out , out .length , address , port );
164163 socket .send (packet );
165164
166- UdpRequest ack = new UdpRequest (MSG_ACK , "" , messageId );
165+ UdpRequest ack = new UdpRequest (MSG_ACK . getMsgInt () , "" , messageId );
167166 byte [] ackBytes = ack .toBytes ();
168167 DatagramPacket ackPacket = new DatagramPacket (ackBytes , ackBytes .length , address , port );
169168 socket .send (ackPacket );
0 commit comments