Bug fixes

Former-commit-id: e2dd5aecc8d9fd521d97bff04a9336f6c5008aad
This commit is contained in:
Ziver Koc 2016-01-05 02:11:03 +01:00
parent 060f784611
commit e08f1b4477
7 changed files with 65 additions and 24 deletions

View file

@ -30,7 +30,9 @@
<NATIVE>
<root url="file://$MODULE_DIR$/lib" />
</NATIVE>
<SOURCES />
<SOURCES>
<root url="jar://$USER_HOME$/.ideaLibSources/jSerialComm-1.3.10-sources.jar!/" />
</SOURCES>
<jarDirectory url="file://$MODULE_DIR$/lib" recursive="false" />
</library>
</orderEntry>

3
hal.conf.example Executable file
View file

@ -0,0 +1,3 @@
http_port=8080
sync_port=6666
tellstick.com_port=COM5

View file

@ -50,6 +50,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
/////////////////////////////// SENSORS ///////////////////////////////////
public void register(Sensor sensor) throws IllegalAccessException, InstantiationException {
logger.info("Registering new sensor(id: "+ sensor.getId() +"): "+ sensor.getSensorData().getClass());
Class<? extends HalSensorController> c = sensor.getController();
HalSensorController controller = getControllerInstance(c);
@ -59,6 +60,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
}
public void deregister(Sensor sensor){
logger.info("Deregistering sensor(id: "+ sensor.getId() +"): "+ sensor.getSensorData().getClass());
Class<? extends HalSensorController> c = sensor.getController();
HalSensorController controller = (HalSensorController) controllerMap.get(c);;
if (controller != null) {
@ -91,7 +93,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
if (sensor != null) {
PreparedStatement stmt =
db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, event_id, data) VALUES(?, ?, ?)");
db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES(?, ?, ?)");
stmt.setLong(1, sensorData.getTimestamp());
stmt.setLong(2, sensor.getId());
stmt.setDouble(3, sensorData.getData());
@ -112,6 +114,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
//////////////////////////////// EVENTS ///////////////////////////////////
public void register(Event event) throws IllegalAccessException, InstantiationException {
logger.info("Registering new event(id: "+ event.getId() +"): "+ event.getEventData().getClass());
Class<? extends HalEventController> c = event.getController();
HalEventController controller = getControllerInstance(c);
@ -121,6 +124,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
}
public void deregister(Event event){
logger.info("Deregistering event(id: "+ event.getId() +"): "+ event.getEventData().getClass());
Class<? extends HalEventController> c = event.getController();
HalEventController controller = (HalEventController) controllerMap.get(c);
if (controller != null) {
@ -179,7 +183,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
controller = controllerMap.get(c);
else {
// Instantiate controller
logger.fine("Instantiating new controller: " + c.getName());
logger.info("Instantiating new controller: " + c.getName());
try {
controller = c.newInstance();
if(controller instanceof HalSensorController) {
@ -209,7 +213,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
if(size < 0){
// Remove controller as it has no more registered sensors
logger.fine("Closing controller as it has no more registered sensors: "+controller.getClass().getName());
logger.info("Closing controller as it has no more registered objects: "+controller.getClass().getName());
controllerMap.remove(controller.getClass());
if(controller instanceof HalSensorController)

View file

@ -44,8 +44,6 @@ public class TellstickParser {
}
private TellstickProtocol previus;
public TellstickProtocol decode(String data) {
if (data.startsWith("+W")) {
data = data.substring(2);
@ -62,12 +60,10 @@ public class TellstickParser {
try {
TellstickProtocol protocol = protClass.newInstance();
String binData = map.get("data");
protocol.decode(Converter.hexToByte(binData));
if(!protocol.equals(previus)) {
previus = protocol;
logger.finest("Decoded: " + protocol);
return protocol;
}
logger.finest("Decoded: " + protocol);
return protocol;
} catch (Exception e) {
logger.log(Level.WARNING, null, e);
}

View file

@ -47,8 +47,8 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
private static final Logger logger = LogUtil.getLogger();
private SerialPort serial;
private BufferedReader in;
private BufferedWriter out;
private InputStream in;
private OutputStream out;
private TimedHashSet set; // To check for retransmissions
private TellstickParser parser;
@ -84,8 +84,8 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
serial.setComPortTimeouts(
SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
in = new BufferedReader(new InputStreamReader(new InputStreamLogger(serial.getInputStream()), "UTF-8"));
out = new BufferedWriter(new OutputStreamWriter(new OutputStreamLogger(serial.getOutputStream()), "UTF-8"));
in = new InputStreamLogger(serial.getInputStream());
out = new OutputStreamLogger(serial.getOutputStream());
Executors.newSingleThreadExecutor().execute(this);
}
@ -109,7 +109,8 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
public void run() {
try {
String data;
while (in != null && (data = in.readLine()) != null) {
while (in != null && (data = readLine()) != null) {
if ((data.startsWith("+S") || data.startsWith("+T"))) {
synchronized (this) {
this.notifyAll();
@ -118,14 +119,16 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
else {
if(!set.contains(data)) {
TellstickProtocol protocol = parser.decode(data);
if(protocol.getTimestamp() < 0)
protocol.setTimestamp(System.currentTimeMillis());
set.add(data);
if(protocol != null) {
if (protocol.getTimestamp() < 0)
protocol.setTimestamp(System.currentTimeMillis());
set.add(data);
if (sensorListener != null && protocol instanceof HalSensor)
sensorListener.reportReceived((HalSensor)protocol);
else if (eventListener != null && protocol instanceof HalEvent)
eventListener.reportReceived((HalEvent)protocol);
if (sensorListener != null && protocol instanceof HalSensor)
sensorListener.reportReceived((HalSensor) protocol);
else if (eventListener != null && protocol instanceof HalEvent)
eventListener.reportReceived((HalEvent) protocol);
}
}
}
}
@ -134,6 +137,26 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
}
}
/**
* There seems to be an issue with read(...) methods only read() is working
*/
private String readLine() throws IOException {
StringBuilder str = new StringBuilder(50);
char c = 0;
while((c = (char)in.read()) >= 0){
switch(c) {
case '\n':
case '\r':
if(str.length() > 0)
return str.toString();
break;
default:
str.append(c);
}
}
return str.toString();
}
@Override
public void send(HalEvent event) {

View file

@ -154,7 +154,7 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEvent {
public String toString(){
return "class:command;protocol:arctech;model:selflearning;" +
return "protocol:arctech;model:selflearning;" +
"house:"+house+
";group:"+group+
";unit:"+unit+

View file

@ -71,6 +71,19 @@ public class Oregon0x1A2D extends TellstickProtocol implements PowerConsumptionS
}
public boolean equals(Object obj){
if(! (obj instanceof Oregon0x1A2D))
return false;
return ((Oregon0x1A2D)obj).address == this.address;
}
public String toString(){
return "protocol:oregon;model:0x1A2D;" +
"address:"+address+
";temperature:"+temperature+
";humidity:"+humidity;
}
public double getTemperature(){
return temperature;