*
* @param e the {@link ProcessEvent} to handle.
*/
private void readFromKNX(ProcessEvent e) {
try {
GroupAddress destination = e.getDestination();
byte[] asdu = e.getASDU();
if (asdu.length==0) {
return;
}
for (String itemName : getItemNames(destination)) {
Iterable<Datapoint> datapoints = getDatapoints(itemName, destination);
if (datapoints != null) {
for (Datapoint datapoint : datapoints) {
Type type = getType(datapoint, asdu);
if (type!=null) {
// we need to make sure that we won't send out this event to
// the knx bus again, when receiving it on the openHAB bus
ignoreEventList.add(itemName + type.toString());
logger.trace("Added event (item='{}', type='{}') to the ignore event list", itemName, type.toString());
if (type instanceof Command && isCommandGA(destination)) {
eventPublisher.postCommand(itemName, (Command) type);
} else if (type instanceof State) {
eventPublisher.postUpdate(itemName, (State) type);
} else {
throw new IllegalClassException("Cannot process datapoint of type " + type.toString());
}
logger.trace("Processed event (item='{}', type='{}', destination='{}')", itemName, type.toString(), destination.toString());
return;
}
else {
final char[] hexCode = "0123456789ABCDEF".toCharArray();
StringBuilder sb = new StringBuilder(2+asdu.length * 2);
sb.append("0x");
for (byte b : asdu) {
sb.append(hexCode[(b >> 4) & 0xF]);
sb.append(hexCode[(b & 0xF)]);
}
logger.debug("Ignoring KNX bus data: couldn't transform to an openHAB type (not supported). Destination='{}', datapoint='{}', data='{}'",
new Object[] {destination.toString(), datapoint.toString(), sb.toString() });
return;
}
}
}
}
logger.debug("Received telegram for unknown group address {}", destination.toString());
} catch(RuntimeException re) {
logger.error("Error while receiving event from KNX bus: " + re.toString());
}
}