use of io.openems.api.exception.WriteChannelException in project openems by OpenEMS.
the class WriteChannel method checkIntervalBoundaries.
@SuppressWarnings("unchecked")
public void checkIntervalBoundaries(T value) throws WriteChannelException {
Optional<T> max = writeMax();
Optional<T> min = writeMin();
Optional<T> write = this.writeValue;
if (!(value instanceof Comparable)) {
return;
} else if (write.isPresent() && write.get() instanceof Comparable && ((Comparable<T>) write.get()).compareTo(value) != 0) {
throw new WriteChannelException("Value [" + value + "] for [" + address() + "] is out of boundaries. Different fixed value [" + write.get() + "] had already been set");
} else if (max.isPresent() && max.get() instanceof Comparable && ((Comparable<T>) max.get()).compareTo(value) < 0) {
throw new WriteChannelException("Value [" + value + "] for [" + address() + "] is out of boundaries. Max value [" + max.get() + "] had already been set");
} else if (min.isPresent() && min.get() instanceof Comparable && ((Comparable<T>) min.get()).compareTo(value) > 0) {
throw new WriteChannelException("Value [" + value + "] for [" + address() + "] is out of boundaries. Min value [" + min.get() + "] had already been set");
}
}
use of io.openems.api.exception.WriteChannelException in project openems by OpenEMS.
the class SymmetricPowerImpl method writePower.
@Override
protected void writePower() {
super.writePower();
if (dynamicLimitations.size() > 0) {
Point p = reduceToZero();
Coordinate c = p.getCoordinate();
try {
setGeometry(p);
} catch (PowerException e1) {
}
double activePowerDelta = c.x - lastActivePower;
double reactivePowerDelta = c.y - lastReactivePower;
lastActivePower += activePowerDelta / 2;
lastReactivePower += reactivePowerDelta / 2;
try {
this.setActivePower.pushWrite((long) lastActivePower);
this.setReactivePower.pushWrite((long) lastReactivePower);
setActivePower.shadowCopyAndReset();
setReactivePower.shadowCopyAndReset();
} catch (WriteChannelException e) {
log.error("failed to write Power.", e);
}
}
}
use of io.openems.api.exception.WriteChannelException in project openems by OpenEMS.
the class ClockSyncController method run.
/*
* Methods
*/
@Override
public void run() {
if (isDateSet) {
// Set time only once in the beginning
return;
}
if (rtc.valueOptional().isPresent()) {
RealTimeClock r = rtc.valueOptional().get();
Optional<Long> rtcYear = r.year.valueOptional();
Optional<Long> rtcMonth = r.month.valueOptional();
Optional<Long> rtcDay = r.day.valueOptional();
Optional<Long> rtcHour = r.hour.valueOptional();
Optional<Long> rtcMinute = r.hour.valueOptional();
Optional<Long> rtcSecond = r.second.valueOptional();
if (rtcYear.isPresent() && rtcMonth.isPresent() && rtcDay.isPresent() && rtcHour.isPresent() && rtcMinute.isPresent() && rtcSecond.isPresent()) {
Calendar systemNow = Calendar.getInstance();
int year = systemNow.get(Calendar.YEAR);
if (year < 2016) {
// System date is wrong -> set system date from RTC
log.info("Setting system time from RTC: " + rtc.id() + ": " + rtcYear.get() + "-" + rtcMonth.get() + "-" + rtcDay.get() + " " + rtcHour.get() + ":" + rtcMinute.get() + ":" + rtcSecond.get());
try {
Runtime.getRuntime().exec(new String[] { "/usr/bin/timedatectl", "set-time", "2016-10-11 13:13:16" });
// process is running in a separate process from now...
} catch (IOException e) {
log.error("Error while setting system time: ", e);
}
} else {
// System date is correct -> set RTC from system date
log.info("Setting RTC from system time: " + rtc.id() + ": " + systemNow.get(Calendar.YEAR) + "-" + systemNow.get(Calendar.MONTH) + "-" + systemNow.get(Calendar.DAY_OF_MONTH) + " " + systemNow.get(Calendar.HOUR_OF_DAY) + ":" + systemNow.get(Calendar.MINUTE) + ":" + systemNow.get(Calendar.SECOND));
try {
r.year.pushWrite(Long.valueOf(systemNow.get(Calendar.YEAR)));
r.month.pushWrite(Long.valueOf(systemNow.get(Calendar.MONTH)));
r.day.pushWrite(Long.valueOf(systemNow.get(Calendar.DAY_OF_MONTH)));
r.hour.pushWrite(Long.valueOf(systemNow.get(Calendar.HOUR_OF_DAY)));
r.minute.pushWrite(Long.valueOf(systemNow.get(Calendar.MINUTE)));
r.second.pushWrite(Long.valueOf(systemNow.get(Calendar.SECOND)));
} catch (WriteChannelException e) {
log.error("Error while setting RTC time: ", e);
}
}
isDateSet = true;
}
}
}
use of io.openems.api.exception.WriteChannelException in project openems by OpenEMS.
the class RiedmannController method run.
@Override
public void run() {
// Check if all parameters are available
Ess ess;
Custom sps;
try {
ess = this.ess.value();
sps = this.sps.value();
} catch (InvalidValueException | NullPointerException e) {
log.error("TimelineChargeController error: " + e.getMessage());
return;
}
// Watchdog
try {
if (watchdogState) {
sps.watchdog.pushWrite(0L);
watchdogState = false;
} else {
sps.watchdog.pushWrite(1L);
watchdogState = true;
}
} catch (WriteChannelException e) {
log.error("Failed to set Watchdog: " + e.getMessage());
}
// Water level
if (updateWaterLevelBorehole1Off) {
try {
sps.setWaterLevelBorehole1Off.pushWrite(setWaterLevelBorehole1Off.value());
updateWaterLevelBorehole1Off = false;
} catch (InvalidValueException | WriteChannelException e) {
log.error("Failed to set WaterLevelBorehole1Off!", e);
}
}
if (updateWaterLevelBorehole1On) {
try {
sps.setWaterLevelBorehole1On.pushWrite(setWaterLevelBorehole1On.value());
updateWaterLevelBorehole1On = false;
} catch (InvalidValueException | WriteChannelException e) {
log.error("Failed to set WaterLevelBorehole1On!", e);
}
}
if (updateWaterLevelBorehole2Off) {
try {
sps.setWaterLevelBorehole2Off.pushWrite(setWaterLevelBorehole2Off.value());
updateWaterLevelBorehole2Off = false;
} catch (InvalidValueException | WriteChannelException e) {
log.error("Failed to set WaterLevelBorehole2Off!", e);
}
}
if (updateWaterLevelBorehole2On) {
try {
sps.setWaterLevelBorehole2On.pushWrite(setWaterLevelBorehole2On.value());
updateWaterLevelBorehole2On = false;
} catch (InvalidValueException | WriteChannelException e) {
log.error("Failed to set WaterLevelBorehole2On!", e);
}
}
if (updateWaterLevelBorehole3Off) {
try {
sps.setWaterLevelBorehole3Off.pushWrite(setWaterLevelBorehole3Off.value());
updateWaterLevelBorehole3Off = false;
} catch (InvalidValueException | WriteChannelException e) {
log.error("Failed to set WaterLevelBorehole3Off!", e);
}
}
if (updateWaterLevelBorehole3On) {
try {
sps.setWaterLevelBorehole3On.pushWrite(setWaterLevelBorehole3On.value());
updateWaterLevelBorehole3On = false;
} catch (InvalidValueException | WriteChannelException e) {
log.error("Failed to set WaterLevelBorehole3On!", e);
}
}
/*
* Load switching
*/
// Check if all parameters are available
long essSoc;
long socHysteresis;
long socLoad1Off;
long socLoad2Off;
long socLoad3Off;
long socLoad4Off;
try {
essSoc = ess.soc.value();
socHysteresis = this.socHysteresis.value();
socLoad1Off = this.socLoad1Off.value();
socLoad2Off = this.socLoad2Off.value();
socLoad3Off = this.socLoad3Off.value();
socLoad4Off = this.socLoad4Off.value();
} catch (InvalidValueException | NullPointerException e) {
log.error("TimelineChargeController error: " + e.getMessage());
return;
}
// Load1
try {
if (essSoc >= socLoad1Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
load1On = true;
} else if (essSoc <= socLoad1Off) {
load1On = false;
}
if (load1On) {
sps.setClima1On.pushWrite(1L);
sps.setClima2On.pushWrite(1L);
} else {
sps.setClima1On.pushWrite(0L);
sps.setClima2On.pushWrite(0L);
}
} catch (WriteChannelException e) {
log.error("Failed to connect/disconnect Load 1: " + e.getMessage());
}
// Load2
try {
if (essSoc >= socLoad2Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
load2On = true;
} else if (essSoc <= socLoad2Off) {
load2On = false;
}
if (load2On) {
sps.setPivotOn.pushWrite(1L);
} else {
sps.setPivotOn.pushWrite(0L);
}
} catch (WriteChannelException e) {
log.error("Failed to connect/disconnect Load 2: " + e.getMessage());
}
// Load3
try {
if (essSoc >= socLoad3Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
load3On = true;
} else if (essSoc <= socLoad3Off) {
load3On = false;
}
if (load3On) {
sps.setBorehole1On.pushWrite(1L);
sps.setBorehole2On.pushWrite(1L);
sps.setBorehole3On.pushWrite(1L);
} else {
sps.setBorehole1On.pushWrite(0L);
sps.setBorehole2On.pushWrite(0L);
sps.setBorehole3On.pushWrite(0L);
}
} catch (WriteChannelException e) {
log.error("Failed to connect/disconnect Load 3: " + e.getMessage());
}
// Load4
try {
if (essSoc >= socLoad4Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
load4On = true;
} else if (essSoc <= socLoad4Off) {
load4On = false;
}
if (load4On) {
sps.setOfficeOn.pushWrite(1L);
sps.setTraineeCenterOn.pushWrite(1L);
} else {
sps.setOfficeOn.pushWrite(0L);
sps.setTraineeCenterOn.pushWrite(0L);
}
} catch (WriteChannelException e) {
log.error("Failed to connect/disconnect Load 4: " + e.getMessage());
}
}
Aggregations