use of org.openhab.binding.nibeheatpump.internal.NibeHeatPumpException in project openhab1-addons by openhab.
the class NibeHeatPumpUDPConnector method receiveDatagram.
@Override
public byte[] receiveDatagram() throws NibeHeatPumpException {
final int PACKETSIZE = 255;
try {
if (socket == null) {
socket = new DatagramSocket(port);
}
// Create a packet
DatagramPacket packet = new DatagramPacket(new byte[PACKETSIZE], PACKETSIZE);
// Receive a packet (blocking)
socket.receive(packet);
return Arrays.copyOfRange(packet.getData(), 0, packet.getLength());
} catch (SocketException e) {
throw new NibeHeatPumpException(e);
} catch (IOException e) {
throw new NibeHeatPumpException(e);
}
}
use of org.openhab.binding.nibeheatpump.internal.NibeHeatPumpException in project openhab1-addons by openhab.
the class NibeHeatPumpDataParser method ParseData.
public static Hashtable<Integer, Short> ParseData(byte[] data) throws NibeHeatPumpException {
if (data[0] == (byte) 0x5C && data[1] == (byte) 0x00 && data[2] == (byte) 0x20 && data[3] == (byte) 0x68 && data[4] >= (byte) 0x50) {
int datalen = data[4];
int msglen = 5 + datalen;
byte checksum = 0;
// calculate XOR checksum
for (int i = 2; i < msglen; i++) {
checksum ^= data[i];
}
byte msgChecksum = data[msglen];
if (checksum == msgChecksum || (checksum == (byte) 0x5C && msgChecksum == (byte) 0xC5)) {
if (datalen > 0x50) {
// let's remove doubles
for (int i = 1; i < msglen; i++) {
if (data[i] == (byte) 0x5C) {
data = ArrayUtils.remove(data, i);
msglen--;
}
}
}
// parse data to hash table
Hashtable<Integer, Short> values = new Hashtable<Integer, Short>();
try {
for (int i = 5; i < (msglen - 1); i += 4) {
int id = ((data[i + 1] & 0xFF) << 8 | (data[i + 0] & 0xFF));
short value = (short) ((data[i + 3] & 0xFF) << 8 | (data[i + 2] & 0xFF));
if (id != 0xFFFF) {
values.put(id, value);
}
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new NibeHeatPumpException("Error occured during data parsing", e);
}
return values;
} else {
throw new NibeHeatPumpException("Checksum does not match");
}
} else {
return null;
}
}
use of org.openhab.binding.nibeheatpump.internal.NibeHeatPumpException in project openhab1-addons by openhab.
the class NibeHeatPumpSimulator method receiveDatagram.
@Override
public byte[] receiveDatagram() throws NibeHeatPumpException {
try {
Thread.sleep(10000);
final byte[] testdata = new byte[] { (byte) 0x5C, (byte) 0x00, (byte) 0x20, (byte) 0x68, (byte) 0x50, (byte) 0x01, (byte) 0xA8, (byte) 0x1F, (byte) 0x01, (byte) 0x00, (byte) 0xA8, (byte) 0x64, (byte) 0x00, (byte) 0xFD, (byte) 0xA7, (byte) 0xD0, (byte) 0x03, (byte) 0x44, (byte) 0x9C, (byte) 0x1E, (byte) 0x00, (byte) 0x4F, (byte) 0x9C, (byte) 0xA0, (byte) 0x00, (byte) 0x50, (byte) 0x9C, (byte) 0x78, (byte) 0x00, (byte) 0x51, (byte) 0x9C, (byte) 0x03, (byte) 0x01, (byte) 0x52, (byte) 0x9C, (byte) 0x1B, (byte) 0x01, (byte) 0x87, (byte) 0x9C, (byte) 0x14, (byte) 0x01, (byte) 0x4E, (byte) 0x9C, (byte) 0xC6, (byte) 0x01, (byte) 0x47, (byte) 0x9C, (byte) 0x01, (byte) 0x01, (byte) 0x15, (byte) 0xB9, (byte) 0xB0, (byte) 0xFF, (byte) 0x3A, (byte) 0xB9, (byte) 0x4B, (byte) 0x00, (byte) 0xC9, (byte) 0xAF, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x9C, (byte) 0x0D, (byte) 0x01, (byte) 0x4C, (byte) 0x9C, (byte) 0xE7, (byte) 0x00, (byte) 0x4B, (byte) 0x9C, (byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x45 };
return testdata;
} catch (InterruptedException e) {
throw new NibeHeatPumpException(e);
}
}
Aggregations