Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload and rtdOpen #28

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions src/main/java/com/github/mob41/blapi/BLDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -939,14 +939,16 @@ protected byte[] decryptFromDeviceMessage(byte[] encData) throws Exception {
* The ending position to be picked
* @return The bytes array picked with length (<code>end - start</code>)
*/
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/com/github/mob41/blapi/dev/hysen/BaseStatusInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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<array.length;i++)
index[i]=i;
return index;
}

protected BaseStatusInfo(byte[] payload) {
log.debug("payload: {}",bytesToString(payload));
this.remoteLock = byteToBool((byte) (payload[3] & 0x1));
this.power = byteToBool((byte) (payload[4] & 1));
this.active = byteToBool((byte) ((payload[4] >> 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;
Expand All @@ -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];
Expand All @@ -99,6 +117,10 @@ public boolean getPower() {
public boolean getActive() {
return active;
}

public boolean getRtdOpen() {
return rtdOpen;
}

public boolean getManualTemp() {
return manualTemp;
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/github/mob41/blapi/dev/hysen/Period.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ((iStartHour<payload.length)&&(iStartMin<payload.length)&&(iTemp<payload.length)){
this.startHour = payload[iStartHour];
this.startMinute = payload[iStartMin];
this.temp = payload[iTemp] / 2.0;
}
else {
this.startHour = 0;
this.startMinute = 0;
this.temp = 0.0;
}
}

public short getStartHour() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ public byte[] execute(BaseHysenDevice device) throws Exception {
DatagramPacket packet = device.sendCmdPkt(this);

byte[] data = packet.getData();

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);
if (data != null && data.length>34) {
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;
}
Expand Down