use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBusReaderSchedulerTest method createDP.
/**
* Convenience method creating a Datapoint
*
* @param dpt datapoint type
* @return a new CommandDP
* @throws KNXFormatException
*/
private Datapoint createDP(String dpt) throws KNXFormatException {
dpCount++;
int mainNumber = Integer.parseInt(dpt.substring(0, dpt.indexOf('.')));
return new CommandDP(new GroupAddress("1/1/" + dpCount), "test" + dpCount, mainNumber, dpt);
}
use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBinding method allBindingsChanged.
/*
* (non-Javadoc)
*
* @see org.openhab.core.binding.AbstractBinding#allBindingsChanged(org.openhab.core.binding.BindingProvider)
*/
@Override
public void allBindingsChanged(BindingProvider provider) {
logger.trace("allBindingsChanged() msg received.");
if (mKNXConnectionEstablished) {
logger.debug("Initializing readable DPs.");
if (provider instanceof KNXBindingProvider) {
KNXBindingProvider knxProvider = (KNXBindingProvider) provider;
mKNXBusReaderScheduler.clear();
for (Datapoint datapoint : knxProvider.getReadableDatapoints()) {
mKNXBusReaderScheduler.readOnce(datapoint);
int autoRefreshTimeInSecs = knxProvider.getAutoRefreshTime(datapoint);
if (autoRefreshTimeInSecs > 0) {
if (!mKNXBusReaderScheduler.scheduleRead(datapoint, knxProvider.getAutoRefreshTime(datapoint))) {
logger.warn("Couldn't add to KNX bus reader scheduler (allBindingsChanged, datapoint='{}')", datapoint);
}
}
}
}
}
}
use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBindingDatapointReaderTask method addToReadQueue.
/**
* Adds or re-adds a datapoint to readQueue,
* if datapoint is known in dpReadRetries, retries will be reduced.
* Otherwise it will be registered in dpReadRetries with retriesLimit.
*
* @param datapoint
*/
private void addToReadQueue(Datapoint datapoint) throws InterruptedException {
Integer r = dpReadRetries.remove(datapoint);
int retries = (r != null ? r : KNXConnection.getReadRetriesLimit()) - 1;
if (retries >= 0) {
sLogger.warn("Autorefresh: Remaining retries for address '{}' = '{}'", datapoint.getMainAddress().toString(), retries);
readQueue.put(datapoint);
dpReadRetries.put(datapoint, retries);
} else if (retries == -1) {
sLogger.warn("Autorefresh: Give up, could not read address '{}' after '{}' retries.", datapoint.getMainAddress().toString(), KNXConnection.getReadRetriesLimit());
}
}
use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBinding method readFromKNX.
/**
* Handles the given {@link ProcessEvent}. After finding the corresponding
* Item (by iterating through all known group addresses) this Item is updated.
* Each item is added to a special list to identify and avoid echo's in
* the <code>receiveUpdate</code> and <code>receiveCommand</code> methods.
*
* @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;
}
String[] itemList = getItemNames(destination);
if (itemList.length == 0) {
logger.debug("Received telegram for unknown group address {}", destination.toString());
}
for (String itemName : itemList) {
Iterable<Datapoint> datapoints = getDatapoints(itemName, destination);
if (datapoints != null) {
for (Datapoint datapoint : datapoints) {
Type type = getType(datapoint, asdu);
if (type != null) {
if (type instanceof Command && isStartStopEnabled(itemName, destination, datapoint)) {
if (isDimmerThreadRunning(itemName) && type == IncreaseDecreaseType.INCREASE) {
stopDimmerThread(itemName);
} else {
startDimmerThread(destination, itemName, (Command) type);
}
} else {
sendTypeToItemButNotToKnx(destination, itemName, type);
}
} 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() });
}
}
}
}
} catch (RuntimeException re) {
logger.error("Error while receiving event from KNX bus: " + re.toString());
}
}
use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBinding method writeToKNX.
private void writeToKNX(String itemName, Type value) {
Iterable<Datapoint> datapoints = getDatapoints(itemName, value.getClass());
if (datapoints != null) {
ProcessCommunicator pc = KNXConnection.getCommunicator();
if (pc != null) {
for (Datapoint datapoint : datapoints) {
try {
pc.write(datapoint, toDPTValue(value, datapoint.getDPT()));
logger.debug("Wrote value '{}' to datapoint '{}'", value, datapoint);
} catch (KNXException e) {
logger.warn("Value '{}' could not be sent to the KNX bus using datapoint '{}' - retrying one time: {}", new Object[] { value, datapoint, e.getMessage() });
try {
// do a second try, maybe the reconnection was successful
pc = KNXConnection.getCommunicator();
pc.write(datapoint, toDPTValue(value, datapoint.getDPT()));
logger.debug("Wrote value '{}' to datapoint '{}' on second try", value, datapoint);
} catch (KNXException e1) {
logger.error("Value '{}' could not be sent to the KNX bus using datapoint '{}' - giving up after second try: {}", new Object[] { value, datapoint, e1.getMessage() });
}
}
}
}
}
}
Aggregations