Skip to content
Snippets Groups Projects
Commit 2821c3dc authored by jkerdreu's avatar jkerdreu
Browse files

Added xAAL config file parser

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Java/branches/0.7@2604 b32b6428-25c9-4566-ad07-03861ab6144f
parent 33781d4f
Branches
No related tags found
No related merge requests found
package org.imta.xaal.lib;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.logging.Logger;
public class Config {
private final static Logger LOGGER = Logger.getLogger(Device.class.getName());
private Properties cfg = null;
public Config() {
String fileName = getFileName();
LOGGER.info("Loading config" + fileName);
cfg = new Properties();
try {
FileInputStream in = new FileInputStream(fileName);
cfg.load(in);
}
catch (FileNotFoundException ex) {
LOGGER.warning("Unable to open xALL config file");
}
catch (IOException ex) {
LOGGER.warning("Unable to parse xAAL confif file");
}
}
public String getFileName() {
var path = Paths.get(System.getProperty("user.home"),".xaal", "xaal.ini");
return path.toString();
}
private Object getValue(String key,Object def) {
if (cfg==null) return null;
Object value = cfg.get(key);
if (value==null) return def;
return value;
}
public String getAddress() {
return (String) getValue("address", "224.0.29.200");
}
public Integer getPort() {
return (Integer) getValue("poirt", 1236);
}
public Integer getHops() {
return (Integer) getValue("hops", 10);
}
public Integer getAliveTimer() {
return (Integer) getValue("alive_timer", 300);
}
public String getKey() {
return (String) getValue("key", null);
}
}
......@@ -27,10 +27,10 @@ public class Engine extends Thread {
private ConcurrentLinkedQueue<Attribute> attrChgQueue = new ConcurrentLinkedQueue<Attribute>();
private boolean pause = false;
public Engine(byte[] key) throws IOException {
// TODO : put network config somewhere else..
networkConnector = new NetworkConnector("224.0.29.200", 1236, 10);
public Engine(Config cfg) throws IOException {
networkConnector = new NetworkConnector(cfg.getAddress(), cfg.getPort(), cfg.getHops());
networkConnector.setOUTFifo(fifoIN);
byte[] key = BinTools.unhexlify(cfg.getKey());
factory = new MessageFactory(key);
}
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.imta.xaal.lib;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Properties;
import java.util.UUID;
import com.upokecenter.cbor.CBORObject;
......@@ -16,15 +13,12 @@ import com.upokecenter.cbor.CBORObject;
* @author jkx
*/
public class Test {
static String xaal_key = "13af792910d83072e46f8d5f13fd5e41a8ae4e86755bf56d3ae200f2af06ec0b";
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
var key = BinTools.unhexlify(xaal_key);
Engine eng = new Engine(key);
Engine eng = new Engine(new Config());
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"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment