Search in sources :

Example 6 with Datapoint

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);
}
Also used : CommandDP(tuwien.auto.calimero.datapoint.CommandDP) GroupAddress(tuwien.auto.calimero.GroupAddress) Datapoint(tuwien.auto.calimero.datapoint.Datapoint)

Example 7 with Datapoint

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);
                    }
                }
            }
        }
    }
}
Also used : Datapoint(tuwien.auto.calimero.datapoint.Datapoint) KNXBindingProvider(org.openhab.binding.knx.config.KNXBindingProvider) Datapoint(tuwien.auto.calimero.datapoint.Datapoint)

Example 8 with 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());
    }
}
Also used : Datapoint(tuwien.auto.calimero.datapoint.Datapoint)

Example 9 with Datapoint

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());
    }
}
Also used : Datapoint(tuwien.auto.calimero.datapoint.Datapoint) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) Type(org.openhab.core.types.Type) Command(org.openhab.core.types.Command) GroupAddress(tuwien.auto.calimero.GroupAddress)

Example 10 with Datapoint

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() });
                    }
                }
            }
        }
    }
}
Also used : Datapoint(tuwien.auto.calimero.datapoint.Datapoint) KNXException(tuwien.auto.calimero.exception.KNXException) ProcessCommunicator(tuwien.auto.calimero.process.ProcessCommunicator)

Aggregations

Datapoint (tuwien.auto.calimero.datapoint.Datapoint)13 GroupAddress (tuwien.auto.calimero.GroupAddress)3 Test (org.junit.Test)2 KNXBindingProvider (org.openhab.binding.knx.config.KNXBindingProvider)2 CommandDP (tuwien.auto.calimero.datapoint.CommandDP)2 KNXException (tuwien.auto.calimero.exception.KNXException)2 KNXFormatException (tuwien.auto.calimero.exception.KNXFormatException)2 Color (java.awt.Color)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 DecimalType (org.openhab.core.library.types.DecimalType)1 HSBType (org.openhab.core.library.types.HSBType)1 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)1 Command (org.openhab.core.types.Command)1 Type (org.openhab.core.types.Type)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1 StateDP (tuwien.auto.calimero.datapoint.StateDP)1 DPTXlator (tuwien.auto.calimero.dptxlator.DPTXlator)1