Skip to content
Snippets Groups Projects
Commit 481286fe authored by jkerdreu's avatar jkerdreu
Browse files

API change for Device()

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Java/branches/0.7@2608 b32b6428-25c9-4566-ad07-03861ab6144f
parent 4127124f
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ public abstract class Device {
protected UUID groupID = null;
protected UUID address = null;
protected String devType = null;
protected String devType = "basic.basic";
protected Engine engine = null;
private List<String> unsupportedMethods = new ArrayList<String>();
private List<String> unsupportedAttributes = new ArrayList<String>();
......@@ -37,8 +37,7 @@ public abstract class Device {
private int alivePeriod = Config.getInstance().getAliveTimer();
private long aliveTimeOut = 0;
public Device(String devType, UUID address) {
setDevType(devType);
public Device(UUID address) {
setAddress(address);
}
......
......@@ -32,6 +32,7 @@ public class Engine extends Thread {
networkConnector.setOUTFifo(fifoIN);
byte[] key = BinTools.unhexlify(cfg.getKey());
factory = new MessageFactory(key);
init();
}
public NetworkConnector getNetworkConnector() {
......
......@@ -13,8 +13,9 @@ public class Lamp extends Device {
Attribute brightness = new Attribute("brightness", 100);
public Lamp(String devType, UUID address) throws URISyntaxException{
super(devType, address);
public Lamp(UUID address) throws URISyntaxException{
super(address);
setDevType("lamp.dimmer");
setVendorID("Jkx Industries");
setVersion("35 rev2");
setProductID("Dummy Java Lamp");
......@@ -23,7 +24,6 @@ public class Lamp extends Device {
setSchema( new URI("http://foobar.com"));
setUrl(new URI("http://dev.foobar.org"));
registerAttributes(Arrays.asList(light,brightness));
setGroupID(UUID.randomUUID());
}
public void toggle() {
......@@ -42,6 +42,12 @@ public class Lamp extends Device {
light.setValue(false);
}
public void setBrightness(Integer target) {
if (target<=0) turn_off();
else turn_on();
brightness.setValue(target);
}
@Override
public Message handleRequest(Message msg) {
switch (msg.getAction()) {
......@@ -56,9 +62,8 @@ public class Lamp extends Device {
break;
case "dim":
Integer target = msg.getBodyAsMap().get("target").AsInt32();
if (target<=0) turn_off();
else turn_on();
brightness.setValue(target);
setBrightness(target);
break;
}
return null;
}
......
......@@ -15,14 +15,17 @@ public class Test {
*/
public static void main(String[] args) throws Exception{
Engine eng = new Engine(Config.getInstance());
eng.init();
Lamp l1 = new Lamp("lamp.dimmer", UUID.fromString("6265eb30-8c59-11e9-98b1-b827ebe99201"));
Lamp l2 = new Lamp("lamp.dimmer", UUID.fromString("6265eb30-8c59-11e9-98b1-b827ebe99202"));
eng.registerDevices(Arrays.asList(l1,l2));
Lamp l1 = new Lamp(UUID.fromString("6265eb30-8c59-11e9-98b1-b827ebe99201"));
Lamp l2 = new Lamp(UUID.fromString("6265eb30-8c59-11e9-98b1-b827ebe99202"));
UUID grp = UUID.randomUUID();
l1.setGroupID(grp);
l2.setGroupID(grp);
eng.registerDevices(Arrays.asList(l1,l2));
eng.start();
l1.toggle();
l1.toggle();
l2.setBrightness(50);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment