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);
}
Aggregations