Implementation of group events done. issue 12

This commit is contained in:
Ziver Koc 2016-02-17 10:11:54 +01:00
parent cf646bb340
commit 75d60d7f40

View file

@ -85,10 +85,10 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
serial.setComPortTimeouts( serial.setComPortTimeouts(
SerialPort.TIMEOUT_READ_BLOCKING, 0, 0); SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
//in = serial.getInputStream(); in = serial.getInputStream();
//out = serial.getOutputStream(); out = serial.getOutputStream();
in = new InputStreamLogger(serial.getInputStream()); //in = new InputStreamLogger(serial.getInputStream());
out = new OutputStreamLogger(serial.getOutputStream()); //out = new OutputStreamLogger(serial.getOutputStream());
Executors.newSingleThreadExecutor().execute(this); Executors.newSingleThreadExecutor().execute(this);
@ -130,10 +130,13 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
if(registered && !set.contains(data) || // check for duplicates transmissions of registered devices if(registered && !set.contains(data) || // check for duplicates transmissions of registered devices
!registered && set.contains(data)) { // required duplicate transmissions before reporting unregistered devices !registered && set.contains(data)) { // required duplicate transmissions before reporting unregistered devices
if (sensorListener != null && protocol instanceof HalSensorData) //Check for registered device that are in the same group
sensorListener.reportReceived((HalSensorData) protocol); for (TellstickProtocol childProtocol : registeredDevices){
else if (eventListener != null && protocol instanceof HalEventData) if (protocol.equalsGroup(childProtocol) && !protocol.equals(childProtocol))
eventListener.reportReceived((HalEventData) protocol); reportEvent(protocol);
}
// Report source event
reportEvent(protocol);
} }
set.add(data); set.add(data);
} }
@ -143,6 +146,12 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
logger.log(Level.SEVERE, null, e); logger.log(Level.SEVERE, null, e);
} }
} }
private void reportEvent(TellstickProtocol protocol){
if (sensorListener != null && protocol instanceof HalSensorData)
sensorListener.reportReceived((HalSensorData) protocol);
else if (eventListener != null && protocol instanceof HalEventData)
eventListener.reportReceived((HalEventData) protocol);
}
/** /**
* There seems to be an issue with read(...) methods only read() is working * There seems to be an issue with read(...) methods only read() is working