Search in sources :

Example 6 with Bridge

use of io.openems.api.bridge.Bridge in project openems by OpenEMS.

the class Scheduler method forever.

@Override
protected void forever() {
    cycleStartTime = System.currentTimeMillis();
    for (BeforeControllerExecutedListener listener : this.beforeControllerExecutedListener) {
        listener.beforeControllerExecuted();
    }
    execute();
    for (AfterControllerExecutedListener listener : this.afterControllerExecutedListener) {
        listener.afterControllerExecuted();
    }
    for (WriteChannel<?> channel : thingRepository.getWriteChannels()) {
        channel.shadowCopyAndReset();
    }
    for (Bridge bridge : thingRepository.getBridges()) {
        bridge.triggerWrite();
    }
    requiredTime = System.currentTimeMillis() - cycleStartTime;
    long maxTime = 0;
    for (Bridge bridge : thingRepository.getBridges()) {
        if (bridge.getRequiredCycleTime() > maxTime) {
            maxTime = bridge.getRequiredCycleTime();
        }
    }
    maxTime = (maxTime + 100) / 100 * 100;
    if (maxTime > cycleTime.valueOptional().orElse(500)) {
        // prevent cycleTime to get too big otherwise stuck bridge stops whole framework
        if (maxTime > cycleTime.valueOptional().orElse(500) * 3) {
            actualCycleTime = cycleTime.valueOptional().orElse(500) * 3;
        } else {
            actualCycleTime = (int) maxTime;
        }
    } else {
        actualCycleTime = cycleTime.valueOptional().orElse(500);
    }
    requiredCycleTime.setValue(System.currentTimeMillis() - cycleStartTime);
}
Also used : Bridge(io.openems.api.bridge.Bridge)

Aggregations

Bridge (io.openems.api.bridge.Bridge)6 Device (io.openems.api.device.Device)5 JsonObject (com.google.gson.JsonObject)4 JsonArray (com.google.gson.JsonArray)3 Controller (io.openems.api.controller.Controller)3 Persistence (io.openems.api.persistence.Persistence)3 Scheduler (io.openems.api.scheduler.Scheduler)3 JsonElement (com.google.gson.JsonElement)2 ConfigChannel (io.openems.api.channel.ConfigChannel)2 DeviceNature (io.openems.api.device.nature.DeviceNature)2 QueryablePersistence (io.openems.api.persistence.QueryablePersistence)2 Thing (io.openems.api.thing.Thing)2 OpenemsException (io.openems.common.exceptions.OpenemsException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BiMap (com.google.common.collect.BiMap)1 HashBasedTable (com.google.common.collect.HashBasedTable)1 HashBiMap (com.google.common.collect.HashBiMap)1 HashMultimap (com.google.common.collect.HashMultimap)1 Table (com.google.common.collect.Table)1