Fixed TC and initial implementation of Nexa group transmissions. issue 12

This commit is contained in:
Ziver Koc 2016-02-15 16:45:51 +01:00
parent b93c8bc124
commit cf646bb340
4 changed files with 29 additions and 11 deletions

View file

@ -65,4 +65,12 @@ public abstract class TellstickProtocol {
public abstract String encode(); public abstract String encode();
public abstract void decode(byte[] data); public abstract void decode(byte[] data);
/**
* Protocols should extend this method if it has group functionality.
* @return true if this object an the input is in the same group.
*/
public boolean equalsGroup(Object obj){
return false;
}
} }

View file

@ -34,7 +34,7 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
@Configurator.Configurable("House code") @Configurator.Configurable("House code")
private int house = 0; private int house = 0;
@Configurator.Configurable("Group code") @Configurator.Configurable("Group code")
private int group = 0; private boolean group = false;
@Configurator.Configurable("Unit code") @Configurator.Configurable("Unit code")
private int unit = 0; private int unit = 0;
@ -47,6 +47,8 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
public String encode(){ public String encode(){
// Binary 0 => "01"
// Binary 1 => "10"
StringBuilder enc = new StringBuilder(); StringBuilder enc = new StringBuilder();
enc.append(new char[]{'T', 127, 255, 24, 1}); enc.append(new char[]{'T', 127, 255, 24, 1});
@ -58,7 +60,10 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
m.append( (house & (1 << i)) == 0 ? "01" : "10" ); m.append( (house & (1 << i)) == 0 ? "01" : "10" );
} }
// Group // Group
m.append("01"); if (group)
m.append("10");
else
m.append("01");
// On or OFF // On or OFF
if (enable) if (enable)
@ -89,7 +94,6 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
} }
} }
enc.append("+"); enc.append("+");
return enc.toString(); return enc.toString();
} }
@ -110,13 +114,12 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
house |= (data[1] & 0xFF) << 2; house |= (data[1] & 0xFF) << 2;
house |= (data[0] & 0xC0) >>> 6; house |= (data[0] & 0xC0) >>> 6;
group = data[0] & 0x20; int tmpGroup = data[0] & 0x20; // >>> 5
group >>>= 5; group = tmpGroup != 0;
enable = (data[0] & 0x10) != 0; enable = (data[0] & 0x10) != 0;
unit = data[0] & 0x0F; unit = data[0] & 0x0F;
//unit++;
} }
@ -126,10 +129,10 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
public void setHouse(int house) { public void setHouse(int house) {
this.house = house; this.house = house;
} }
public int getGroup() { public boolean getGroup() {
return group; return group;
} }
public void setGroup(int group) { public void setGroup(boolean group) {
this.group = group; this.group = group;
} }
public int getUnit() { public int getUnit() {
@ -162,9 +165,16 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
public boolean equals(Object obj){ public boolean equals(Object obj){
if(obj instanceof NexaSelfLearning) if(obj instanceof NexaSelfLearning)
return ((NexaSelfLearning) obj).house == house && return ((NexaSelfLearning) obj).house == house &&
((NexaSelfLearning) obj).group == group &&
((NexaSelfLearning)obj).unit == unit; ((NexaSelfLearning)obj).unit == unit;
return false; return false;
} }
public boolean equalsGroup(Object obj){
if(obj instanceof NexaSelfLearning)
return ((NexaSelfLearning) obj).house == house &&
(((NexaSelfLearning) obj).group || group );
return false;
}
@Override @Override

View file

@ -20,7 +20,7 @@ public class TelstickSerialCommNexaOnOffTest {
NexaSelfLearning nexa = new NexaSelfLearning(); NexaSelfLearning nexa = new NexaSelfLearning();
//nexa.setHouse(11772006); //nexa.setHouse(11772006);
nexa.setHouse(14160770); nexa.setHouse(14160770);
nexa.setGroup(0); nexa.setGroup(false);
nexa.setUnit(1); nexa.setUnit(1);
System.out.println("Up and Running"); System.out.println("Up and Running");

View file

@ -51,7 +51,7 @@ public class NexaSelfLearningTest {
NexaSelfLearning nexa = decode("0x2CE81990"); NexaSelfLearning nexa = decode("0x2CE81990");
assertEquals("House Code", 11772006, nexa.getHouse()); assertEquals("House Code", 11772006, nexa.getHouse());
assertEquals("Unit Code", 1, nexa.getUnit()); assertEquals("Unit Code", 0, nexa.getUnit());
assertTrue("Enabled", nexa.isOn()); assertTrue("Enabled", nexa.isOn());
@ -61,7 +61,7 @@ public class NexaSelfLearningTest {
NexaSelfLearning nexa = decode("0x2CE81980"); NexaSelfLearning nexa = decode("0x2CE81980");
assertEquals("House Code", 11772006, nexa.getHouse()); assertEquals("House Code", 11772006, nexa.getHouse());
assertEquals("Unit Code", 1, nexa.getUnit()); assertEquals("Unit Code", 0, nexa.getUnit());
assertFalse("Enabled", nexa.isOn()); assertFalse("Enabled", nexa.isOn());
} }