]> git.basschouten.com Git - openhab-addons.git/blob
bb6086031bed03cfa7820f7f4c7dc97bab69a4fb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.pentair.internal;
14
15 /**
16  * Pentair Intellichlor specialation of a PentairPacket. Includes public variables for many of the reverse engineered
17  * packet content. Note, Intellichlor packet is of a different format and all helper functions in the base PentairPacket
18  * may not apply.
19  *
20  * This packet can be a 3 or 4 data byte packet.
21  *
22  * 10 02 50 00 00 62 10 03
23  * 10 02 00 01 00 00 13 10 03
24  *
25  * @author Jeff James - initial contribution
26  *
27  */
28 public class PentairPacketIntellichlor extends PentairPacket { // 29 byte packet format
29     protected static final int CMD = 3; // not sure what this is, needs to be 11 for SALT_OUTPUT or SALINITY to be valid
30
31     // 3 Length command
32     protected static final int SALTOUTPUT = 4;
33
34     // 4 Length command
35     protected static final int SALINITY = 4;
36
37     /** length of the packet - 3 or 4 data bytes */
38     protected int length;
39     /** for a saltoutput packet, represents the salt output percent */
40     public int saltoutput;
41     /** for a salinity packet, is value of salinity. Must be multiplied by 50 to get the actual salinity value. */
42     public int salinity;
43
44     /**
45      * Constructor for Intellichlor packet. Does not call super constructure since the Intellichlor packet is structure
46      * so differently
47      *
48      * @param buf
49      * @param length
50      */
51     public PentairPacketIntellichlor(byte[] buf, int length) {
52         this.buf = buf;
53         this.length = length;
54
55         if (length == 3) {
56             saltoutput = buf[SALTOUTPUT];
57         } else if (length == 4) {
58             salinity = buf[SALINITY] & 0xFF; // make sure it is positive
59         }
60     }
61
62     /**
63      * Constructor for empty Intellichlor packet
64      */
65     public PentairPacketIntellichlor() {
66         super();
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see org.openhab.binding.pentair.PentairPacket#getLength()
73      */
74     @Override
75     public int getLength() {
76         return length;
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see org.openhab.binding.pentair.PentairPacket#setLength(int)
83      */
84     @Override
85     public void setLength(int length) {
86         if (length != this.length) {
87             buf = new byte[length + 2];
88         }
89         this.length = length;
90     }
91
92     /**
93      * Gets the command byte for this packet
94      *
95      * @return command
96      */
97     public int getCmd() {
98         return buf[CMD];
99     }
100
101     @Override
102     public String toString() {
103         return bytesToHex(buf, length + 5);
104     }
105 }