diff --git a/src/main/java/com/github/mob41/blapi/BLDevice.java b/src/main/java/com/github/mob41/blapi/BLDevice.java index da60a5f..195be8e 100644 --- a/src/main/java/com/github/mob41/blapi/BLDevice.java +++ b/src/main/java/com/github/mob41/blapi/BLDevice.java @@ -939,14 +939,16 @@ protected byte[] decryptFromDeviceMessage(byte[] encData) throws Exception { * The ending position to be picked * @return The bytes array picked with length (end - start) */ - public static byte[] subbytes(byte[] data, int start, int end) { - byte[] out = new byte[end - start]; - - int outi = 0; - for (int i = start; i < end; i++, outi++) { - out[outi] = data[i]; - } - + public static byte[] subbytes(byte[] data, int start, int end) { + byte[] out = null; + if ((end-start)>0) { + out = new byte[end - start]; + + int outi = 0; + for (int i = start; i < end; i++, outi++) { + out[outi] = data[i]; + } + } return out; } diff --git a/src/main/java/com/github/mob41/blapi/dev/hysen/AdvancedStatusInfo.java b/src/main/java/com/github/mob41/blapi/dev/hysen/AdvancedStatusInfo.java index fca37d7..e2b686c 100644 --- a/src/main/java/com/github/mob41/blapi/dev/hysen/AdvancedStatusInfo.java +++ b/src/main/java/com/github/mob41/blapi/dev/hysen/AdvancedStatusInfo.java @@ -27,23 +27,34 @@ public class AdvancedStatusInfo extends BaseStatusInfo { protected AdvancedStatusInfo(byte[] payload) { super(payload); + if ((payload[19]>=0)&&(payload[19]<24)) + this.hour = payload[19]; + else + this.hour = 0; + if ((payload[20]>=0)&&(payload[20]<60)) + this.min = payload[20]; + else + this.min = 0; + if ((payload[21]>=0)&&(payload[21]<60)) + this.sec = payload[21]; + else + this.sec = 0; + if ((payload[22]>0)&&(payload[22]<=7)) + this.dayofweek = payload[22]; + else + this.dayofweek = 1; + for (int i = 0; i < 6; i++) { + this.periods[i] = new Period(i, payload); + this.weekday[i] = this.periods[i]; - this.hour = payload[19]; - this.min = payload[20]; - this.sec = payload[21]; - this.dayofweek = payload[22]; - if (payload.length>=46) { - for (int i = 0; i < 6; i++) { - this.periods[i] = new Period(i, payload); - this.weekday[i] = this.periods[i]; - - } - - for (int i = 6; i <= 7; i++) { - this.periods[i] = new Period(i, payload); - this.weekend[i - 6] = this.periods[i]; - } } + + for (int i = 6; i <= 7; i++) { + this.periods[i] = new Period(i, payload); + this.weekend[i - 6] = this.periods[i]; + + } + } public short getHour() { @@ -76,7 +87,7 @@ public Period[] getPeriods() { @Override public String toString() { - return "StatusInfo [remote lock=" + remoteLock + ",\n power=" + power + ",\n active=" + active + return "StatusInfo [remote lock=" + remoteLock + ",\n power=" + power + ",\n active=" + active + ",\n rtd_open=" + rtdOpen + ",\n manual temperature=" + manualTemp + ",\n room temp=" + roomTemp + ",\n thermostat temp=" + thermostatTemp + ",\n auto_mode=" + autoMode + ",\n loop_mode=" + loopMode + ",\n SensorControl=" + sensorControl + ",\n osv=" + osv + ",\n dif=" + dif + ",\n svh=" + svh + ",\n svl=" + svl diff --git a/src/main/java/com/github/mob41/blapi/dev/hysen/BaseStatusInfo.java b/src/main/java/com/github/mob41/blapi/dev/hysen/BaseStatusInfo.java index c8e5188..efe4a0f 100644 --- a/src/main/java/com/github/mob41/blapi/dev/hysen/BaseStatusInfo.java +++ b/src/main/java/com/github/mob41/blapi/dev/hysen/BaseStatusInfo.java @@ -19,6 +19,7 @@ public class BaseStatusInfo { protected final boolean remoteLock; protected final boolean power; protected final boolean active; + protected final boolean rtdOpen; // temp_manual protected final boolean manualTemp; // room_temp @@ -51,6 +52,16 @@ public class BaseStatusInfo { // external_temp protected final double externalTemp; + private String bytesToHex(byte[] hashInBytes) { + + StringBuilder sb = new StringBuilder(); + for (byte b : hashInBytes) { + sb.append(String.format("%02x", b)); + } + return sb.toString(); + + } + private static String bytesToString(byte[] hashInBytes) { StringBuilder sb = new StringBuilder(); @@ -61,11 +72,19 @@ private static String bytesToString(byte[] hashInBytes) { } - protected BaseStatusInfo(byte[] payload) { + private static byte[] toIndexArray(byte[] array) { + byte index[] = new byte[array.length]; + for(byte i = 0;i> 4) & 1)); + this.rtdOpen = byteToBool((byte) ((payload[4] >> 5) & 1)); this.manualTemp = byteToBool((byte) ((payload[4] >> 6) & 1)); this.roomTemp = (payload[5] & 0xff) / 2.0; this.thermostatTemp = (payload[6] & 0xff) / 2.0; @@ -81,7 +100,6 @@ protected BaseStatusInfo(byte[] payload) { tempAdj = (32767 - tempAdj); } this.roomTempAdjustment = tempAdj; - this.antiFreezing = AntiFreezing.fromValue(payload[15]); this.powerOnMemory = PowerOnMemory.fromValue(payload[16]); this.fac = payload[17]; @@ -99,6 +117,10 @@ public boolean getPower() { public boolean getActive() { return active; } + + public boolean getRtdOpen() { + return rtdOpen; + } public boolean getManualTemp() { return manualTemp; @@ -261,7 +283,7 @@ public double getExternalTemp() { @Override public String toString() { - return "BaseStatusInfo [\nremote lock=" + remoteLock + ",\n power=" + power + ",\n active=" + active + return "BaseStatusInfo [\nremote lock=" + remoteLock + ",\n power=" + power + ",\n active=" + active + ",\n rtd_open=" + rtdOpen + ",\n manual temp=" + manualTemp + ",\n room temp=" + roomTemp + ",\n thermostat temp=" + thermostatTemp + ",\n auto_mode=" + autoMode + ",\n loop_mode=" + loopMode + ",\n sensor=" + sensorControl + ",\n osv=" + osv + ",\n dif=" + dif + ",\n svh=" + svh + ",\n svl=" + svl diff --git a/src/main/java/com/github/mob41/blapi/dev/hysen/Period.java b/src/main/java/com/github/mob41/blapi/dev/hysen/Period.java index 157566a..4e047ef 100644 --- a/src/main/java/com/github/mob41/blapi/dev/hysen/Period.java +++ b/src/main/java/com/github/mob41/blapi/dev/hysen/Period.java @@ -13,9 +13,19 @@ public class Period { private final double temp; protected Period(int offset, byte[] payload) { - this.startHour = payload[2 * offset + 23]; - this.startMinute = payload[2 * offset + 24]; - this.temp = payload[offset + 39] / 2.0; + int iStartHour = 2 * offset + 23; + int iStartMin = 2 * offset + 24; + int iTemp = offset + 39; + if ((iStartHour34) { + log.debug(this.getClass().getSimpleName() + " received encrypted bytes: " + + DatatypeConverter.printHexBinary(data)); + + int err = data[0x22] | (data[0x23] << 8); + + if (err == 0) { + byte[] pl = device.decryptFromDeviceMessage(data); + log.debug(this.getClass().getSimpleName() + " received bytes (decrypted): " + + DatatypeConverter.printHexBinary(pl)); + return Arrays.copyOfRange(pl, 2, pl.length); + } else { + log.warn(this.getClass().getSimpleName() + " received an error: " + Integer.toHexString(err) + " / " + err); + } } return null; }