Search in sources :

Example 11 with Datapoint

use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.

the class KNXBinding method connectionEstablished.

/*
     * (non-Javadoc)
     *
     * @see org.openhab.binding.knx.internal.connection.KNXConnectionListener#connectionEstablished()
     */
@Override
public void connectionEstablished() {
    logger.trace("connectionEstablished() msg received. Initializing readable DPs.");
    mKNXConnectionEstablished = true;
    for (KNXBindingProvider knxProvider : providers) {
        for (Datapoint datapoint : knxProvider.getReadableDatapoints()) {
            mKNXBusReaderScheduler.readOnce(datapoint);
            int autoRefreshTimeInSecs = knxProvider.getAutoRefreshTime(datapoint);
            if (autoRefreshTimeInSecs > 0) {
                if (!mKNXBusReaderScheduler.scheduleRead(datapoint, autoRefreshTimeInSecs)) {
                    logger.warn("Couldn't add to KNX bus reader scheduler (connectionEstablished, datapoint='{}')", datapoint);
                }
            }
        }
    }
}
Also used : Datapoint(tuwien.auto.calimero.datapoint.Datapoint) KNXBindingProvider(org.openhab.binding.knx.config.KNXBindingProvider) Datapoint(tuwien.auto.calimero.datapoint.Datapoint)

Example 12 with Datapoint

use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.

the class KNXBusReaderScheduler method scheduleRead.

/**
     * Schedules a <code>Datapoint</code> to be cyclicly read. When parameter
     * <code>autoRefreshTimeInSecs</code> is 0 then calling ths method is equal
     * to calling <link>readOnce</link>. This function will return true if the <code>Datapoint</code>
     * was added or if it was already scheduled with an identical <code>autoRefreshTimeInSecs</code>.
     * 
     * @param datapoint
     *            the <code>Datapoint</code> to be read
     * @param autoRefreshTimeInSecs
     *            time in seconds specifying the reading cycle. 0 is equal to
     *            calling <link>readOnce</link>
     * @return true if the Datapoint was scheduled for reading, false in all
     *         other cases
     */
public synchronized boolean scheduleRead(Datapoint datapoint, int autoRefreshTimeInSecs) {
    if (datapoint == null) {
        sLogger.error("Argument datapoint cannot be null");
        return false;
    }
    if (autoRefreshTimeInSecs < 0) {
        sLogger.error("AutoRefreshTimeInSecs must be >= 0 for datapoint '{}'", datapoint.getName());
        return false;
    }
    if (autoRefreshTimeInSecs == 0) {
        return readOnce(datapoint);
    }
    if (mReadQueue.size() > KNXConnection.getMaxRefreshQueueEntries()) {
        sLogger.error("Maximum number of permissible reading queue entries reached ('{}'). Ignoring new entries.", KNXConnection.getMaxRefreshQueueEntries());
        return false;
    }
    // Check if datapoint is already present in another list and if so, remove it
    int oldListNumber = getAutoRefreshTimeInSecs(datapoint);
    if (oldListNumber > 0) {
        if (oldListNumber == autoRefreshTimeInSecs) {
            sLogger.debug("Datapoint '{}' was already in auto refresh list {}", datapoint.getName(), autoRefreshTimeInSecs);
            return true;
        }
        List<Datapoint> oldList = mScheduleMap.get(oldListNumber);
        synchronized (oldList) {
            sLogger.debug("Datapoint '{}' already present in different list: {}, removing", datapoint.getName(), oldListNumber);
            for (Iterator<Datapoint> iterator = oldList.iterator(); iterator.hasNext(); ) {
                Datapoint dp = iterator.next();
                if (dp.toString().equals(datapoint.toString())) {
                    iterator.remove();
                }
            }
        }
    }
    // Check if we have a list for autoRefreshTimeInSecs. If not create it.
    if (!mScheduleMap.containsKey(autoRefreshTimeInSecs)) {
        sLogger.debug("Creating auto refresh list: {}.", autoRefreshTimeInSecs);
        mScheduleMap.put(autoRefreshTimeInSecs, new LinkedList<Datapoint>());
        if (mIsRunning) {
            // Start scheduled task for the new time
            sLogger.debug("Starting auto refresh cycle {}", autoRefreshTimeInSecs);
            mScheduledExecutorService.scheduleAtFixedRate(new AutoRefreshTask(autoRefreshTimeInSecs), autoRefreshTimeInSecs, autoRefreshTimeInSecs, TimeUnit.SECONDS);
        }
    }
    // Add the datapoint to the list
    List<Datapoint> dpList = mScheduleMap.get(autoRefreshTimeInSecs);
    synchronized (dpList) {
        sLogger.debug("Adding datapoint '{}' to auto refresh list {}.", datapoint.getName(), autoRefreshTimeInSecs);
        return dpList.add(datapoint);
    }
}
Also used : Datapoint(tuwien.auto.calimero.datapoint.Datapoint) Datapoint(tuwien.auto.calimero.datapoint.Datapoint)

Example 13 with Datapoint

use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.

the class KNXBusReaderSchedulerTest method testLargeNumberOfDPs.

@Test
public void testLargeNumberOfDPs() throws KNXFormatException {
    kNXBindingAutoRefreshScheduler.start();
    assertTrue(kNXBindingAutoRefreshScheduler.isRunning());
    Datapoint datapoint = createDP("1.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
    datapoint = createDP("1.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
    datapoint = createDP("1.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
    datapoint = createDP("1.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 10));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 11));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 12));
    datapoint = createDP("2.001");
    assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 13));
    try {
        Thread.sleep(15000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    kNXBindingAutoRefreshScheduler.clear();
    kNXBindingAutoRefreshScheduler.stop();
    assertFalse(kNXBindingAutoRefreshScheduler.isRunning());
}
Also used : Datapoint(tuwien.auto.calimero.datapoint.Datapoint) Test(org.junit.Test)

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