diff --git a/io.openems.edge.battery.api/src/io/openems/edge/battery/protection/BatteryProtection.java b/io.openems.edge.battery.api/src/io/openems/edge/battery/protection/BatteryProtection.java index 5689735a78..63d13b66c2 100644 --- a/io.openems.edge.battery.api/src/io/openems/edge/battery/protection/BatteryProtection.java +++ b/io.openems.edge.battery.api/src/io/openems/edge/battery/protection/BatteryProtection.java @@ -300,6 +300,9 @@ protected BatteryProtection(Battery battery, ChargeMaxCurrentHandler chargeMaxCu this.battery = battery; this.chargeMaxCurrentHandler = chargeMaxCurrentHandler; this.dischargeMaxCurrentHandler = dischargeMaxCurrentHandler; + + this.battery.getChargeMaxCurrentChannel().setReadSource("Battery-Protection"); + this.battery.getDischargeMaxCurrentChannel().setReadSource("Battery-Protection"); } /** diff --git a/io.openems.edge.battery.soltaro/src/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImpl.java b/io.openems.edge.battery.soltaro/src/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImpl.java index dacf2bf9ff..0315fc653c 100644 --- a/io.openems.edge.battery.soltaro/src/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImpl.java +++ b/io.openems.edge.battery.soltaro/src/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImpl.java @@ -1,8 +1,8 @@ package io.openems.edge.battery.soltaro.cluster.versionc; -import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.atomic.AtomicReference; import org.osgi.service.cm.ConfigurationAdmin; @@ -31,8 +31,8 @@ import io.openems.edge.battery.soltaro.cluster.versionc.statemachine.Context; import io.openems.edge.battery.soltaro.cluster.versionc.statemachine.StateMachine; import io.openems.edge.battery.soltaro.cluster.versionc.statemachine.StateMachine.State; -import io.openems.edge.battery.soltaro.common.batteryprotection.BatteryProtectionDefinitionSoltaro3500Wh; import io.openems.edge.battery.soltaro.common.batteryprotection.BatteryProtectionDefinitionSoltaro3000Wh; +import io.openems.edge.battery.soltaro.common.batteryprotection.BatteryProtectionDefinitionSoltaro3500Wh; import io.openems.edge.battery.soltaro.common.enums.ModuleType; import io.openems.edge.battery.soltaro.single.versionc.enums.PreChargeControl; import io.openems.edge.battery.soltaro.versionc.SoltaroBatteryVersionC; @@ -89,7 +89,7 @@ public class ClusterVersionCImpl extends AbstractOpenemsModbusComponent implemen private final StateMachine stateMachine = new StateMachine(State.UNDEFINED); private Config config; - private Set racks = new HashSet<>(); + private TreeSet racks = new TreeSet<>(); private BatteryProtection batteryProtection = null; public ClusterVersionCImpl() { @@ -381,18 +381,7 @@ protected ModbusProtocol defineModbusProtocol() throws OpenemsException { // getModbusProtocol, and it is using racks... for (Rack r : this.racks) { protocol.addTasks(// - // Single Cluster Control Registers (running without Master BMS) - new FC6WriteRegisterTask(r.offset + 0x0010, // - m(this.rack(r, RackChannel.PRE_CHARGE_CONTROL), new UnsignedWordElement(r.offset + 0x0010)) // - ), // - new FC16WriteRegistersTask(r.offset + 0x000B, // - m(this.rack(r, RackChannel.EMS_ADDRESS), new UnsignedWordElement(r.offset + 0x000B)), // - m(this.rack(r, RackChannel.EMS_BAUDRATE), new UnsignedWordElement(r.offset + 0x000C)) // - ), // - new FC6WriteRegisterTask(r.offset + 0x00F4, // - m(this.rack(r, RackChannel.EMS_COMMUNICATION_TIMEOUT), - new UnsignedWordElement(r.offset + 0x00F4)) // - ), // + new FC3ReadRegistersTask(r.offset + 0x000B, Priority.LOW, // m(this.rack(r, RackChannel.EMS_ADDRESS), new UnsignedWordElement(r.offset + 0x000B)), // m(this.rack(r, RackChannel.EMS_BAUDRATE), new UnsignedWordElement(r.offset + 0x000C)), // @@ -407,6 +396,19 @@ protected ModbusProtocol defineModbusProtocol() throws OpenemsException { new UnsignedWordElement(r.offset + 0x00F4)) // ), + // Single Cluster Control Registers (running without Master BMS) + new FC6WriteRegisterTask(r.offset + 0x0010, // + m(this.rack(r, RackChannel.PRE_CHARGE_CONTROL), new UnsignedWordElement(r.offset + 0x0010)) // + ), // + new FC6WriteRegisterTask(r.offset + 0x00F4, // + m(this.rack(r, RackChannel.EMS_COMMUNICATION_TIMEOUT), + new UnsignedWordElement(r.offset + 0x00F4)) // + ), // + new FC16WriteRegistersTask(r.offset + 0x000B, // + m(this.rack(r, RackChannel.EMS_ADDRESS), new UnsignedWordElement(r.offset + 0x000B)), // + m(this.rack(r, RackChannel.EMS_BAUDRATE), new UnsignedWordElement(r.offset + 0x000C)) // + ), // + // Single Cluster Control Registers (General) new FC6WriteRegisterTask(r.offset + 0x00CC, // m(this.rack(r, RackChannel.SYSTEM_TOTAL_CAPACITY), @@ -732,11 +734,8 @@ protected ModbusProtocol defineModbusProtocol() throws OpenemsException { new UnsignedWordElement(r.offset + 0x400)), // m(this.rack(r, RackChannel.LEVEL2_CELL_OVER_VOLTAGE_RECOVER), new UnsignedWordElement(r.offset + 0x401)), // - m(new UnsignedWordElement(r.offset + 0x402)) // - .m(this.rack(r, RackChannel.LEVEL2_SYSTEM_OVER_VOLTAGE_PROTECTION), - ElementToChannelConverter.SCALE_FACTOR_2) // [mV] - .m(Battery.ChannelId.CHARGE_MAX_VOLTAGE, ElementToChannelConverter.SCALE_FACTOR_MINUS_1) // [V] - .build(), // + m(this.rack(r, RackChannel.LEVEL2_SYSTEM_OVER_VOLTAGE_PROTECTION), + new UnsignedWordElement(r.offset + 0x402)), // m(this.rack(r, RackChannel.LEVEL2_SYSTEM_OVER_VOLTAGE_RECOVER), new UnsignedWordElement(r.offset + 0x403), ElementToChannelConverter.SCALE_FACTOR_2), // m(this.rack(r, RackChannel.LEVEL2_SYSTEM_CHARGE_OVER_CURRENT_PROTECTION), diff --git a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionb/ClusterVersionBTest.java b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionb/ClusterVersionBTest.java index f23129080e..cbb1adaa66 100644 --- a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionb/ClusterVersionBTest.java +++ b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionb/ClusterVersionBTest.java @@ -1,9 +1,7 @@ package io.openems.edge.battery.soltaro.cluster.versionb; -import org.junit.Before; import org.junit.Test; -import io.openems.edge.battery.soltaro.cluster.versionc.ResetChannelSources; import io.openems.edge.battery.soltaro.common.enums.BatteryState; import io.openems.edge.battery.soltaro.common.enums.ModuleType; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; @@ -15,11 +13,6 @@ public class ClusterVersionBTest { private static final String BATTERY_ID = "battery0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new ClusterVersionB()) // diff --git a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImplTest.java b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImplTest.java index 28e762f829..75bcef0675 100644 --- a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImplTest.java +++ b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionc/ClusterVersionCImplTest.java @@ -1,6 +1,5 @@ package io.openems.edge.battery.soltaro.cluster.versionc; -import org.junit.Before; import org.junit.Test; import io.openems.edge.battery.soltaro.common.enums.ModuleType; @@ -14,11 +13,6 @@ public class ClusterVersionCImplTest { private static final String BATTERY_ID = "battery0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new ClusterVersionCImpl()) // @@ -30,9 +24,9 @@ public void test() throws Exception { .setModuleType(ModuleType.MODULE_3_5_KWH) // .setStartStop(StartStopConfig.AUTO) // .setNumberOfSlaves(0) // - .setRack1Used(false) // - .setRack2Used(false) // - .setRack3Used(false) // + .setRack1Used(true) // + .setRack2Used(true) // + .setRack3Used(true) // .setRack4Used(false) // .setRack5Used(false) // .build()) // diff --git a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionc/ResetChannelSources.java b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionc/ResetChannelSources.java deleted file mode 100644 index 503a70540d..0000000000 --- a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/cluster/versionc/ResetChannelSources.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.openems.edge.battery.soltaro.cluster.versionc; - -import io.openems.edge.battery.api.Battery; -import io.openems.edge.battery.protection.BatteryProtection; -import io.openems.edge.battery.soltaro.cluster.SoltaroCluster; -import io.openems.edge.common.channel.ChannelId; - -/** - * Reset Channel sources to avoid 'Unable to add Modbus mapping' errors on - * running all tests at once. - */ -public class ResetChannelSources { - - public static void run() { - resetChannelSources(Battery.ChannelId.values()); - resetChannelSources(BatteryProtection.ChannelId.values()); - resetChannelSources(SoltaroCluster.ChannelId.values()); - } - - private static void resetChannelSources(ChannelId[] channelIds) { - for (ChannelId channelId : channelIds) { - channelId.doc().source(null); - } - } - -} diff --git a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versiona/SingleRackTest.java b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versiona/SingleRackTest.java index d41c4898c7..1cb9c66f72 100644 --- a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versiona/SingleRackTest.java +++ b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versiona/SingleRackTest.java @@ -1,9 +1,7 @@ package io.openems.edge.battery.soltaro.single.versiona; -import org.junit.Before; import org.junit.Test; -import io.openems.edge.battery.soltaro.cluster.versionc.ResetChannelSources; import io.openems.edge.battery.soltaro.common.enums.BatteryState; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; import io.openems.edge.common.test.ComponentTest; @@ -14,11 +12,6 @@ public class SingleRackTest { private static final String BATTERY_ID = "battery0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new SingleRack()) // diff --git a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionb/SingleRackVersionBImplTest.java b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionb/SingleRackVersionBImplTest.java index 6725532fb1..092cc01973 100644 --- a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionb/SingleRackVersionBImplTest.java +++ b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionb/SingleRackVersionBImplTest.java @@ -1,9 +1,7 @@ package io.openems.edge.battery.soltaro.single.versionb; -import org.junit.Before; import org.junit.Test; -import io.openems.edge.battery.soltaro.cluster.versionc.ResetChannelSources; import io.openems.edge.battery.soltaro.common.enums.ModuleType; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; import io.openems.edge.common.startstop.StartStopConfig; @@ -16,11 +14,6 @@ public class SingleRackVersionBImplTest { private static final String BATTERY_ID = "battery0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new SingleRackVersionBImpl()) // diff --git a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionc/SingleRackVersionCImplTest.java b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionc/SingleRackVersionCImplTest.java index c907e4dc1a..3ab3252ded 100644 --- a/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionc/SingleRackVersionCImplTest.java +++ b/io.openems.edge.battery.soltaro/test/io/openems/edge/battery/soltaro/single/versionc/SingleRackVersionCImplTest.java @@ -1,9 +1,7 @@ package io.openems.edge.battery.soltaro.single.versionc; -import org.junit.Before; import org.junit.Test; -import io.openems.edge.battery.soltaro.cluster.versionc.ResetChannelSources; import io.openems.edge.battery.soltaro.common.enums.ModuleType; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; import io.openems.edge.common.startstop.StartStopConfig; @@ -15,11 +13,6 @@ public class SingleRackVersionCImplTest { private static final String BATTERY_ID = "battery0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new SingleRackVersionCImpl()) // diff --git a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/AbstractOpenemsModbusComponent.java b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/AbstractOpenemsModbusComponent.java index 3be71e6858..cf3e7e98c5 100644 --- a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/AbstractOpenemsModbusComponent.java +++ b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/AbstractOpenemsModbusComponent.java @@ -266,6 +266,11 @@ public ChannelMapper(T element) { public ChannelMapper m(io.openems.edge.common.channel.ChannelId channelId, ElementToChannelConverter converter) { Channel channel = channel(channelId); + if (channel instanceof WriteChannel) { + ((WriteChannel) channel).setWriteTarget(new ModbusChannelMetaInfo(element.getStartAddress())); + } else { + channel.setReadSource(new ModbusChannelMetaInfo(element.getStartAddress())); + } this.channelMaps.put(channel, converter); return this; } @@ -363,7 +368,7 @@ public T build() { * Creates a ChannelMapper that can be used with builder pattern inside the * protocol definition. * - * @param the type of the {@link AbstractModbusElement}d + * @param the type of the {@link AbstractModbusElement}d * @param element the ModbusElement * @return a {@link ChannelMapper} */ @@ -398,46 +403,17 @@ protected final > T m(io.openems.edge.common. * Maps the given element to the Channel identified by channelId, applying the * given @link{ElementToChannelConverter}. * - * @param the type of the {@link AbstractModbusElement}d - * @param channelId the Channel-ID - * @param element the ModbusElement - * @param converter the ElementToChannelConverter - * @param ignoreDuplicatedSource set to - * {@link ModbusChannelSource#IGNORE_DUPLICATED_SOURCE} - * to ignore the check for channels with multiple - * mapped modbus registers - * @return the element parameter - */ - protected final > T m(io.openems.edge.common.channel.ChannelId channelId, - T element, ElementToChannelConverter converter, - ModbusChannelSource.IgnoreDuplicatedSource ignoreDuplicatedSource) { - if (ignoreDuplicatedSource != null) { - try { - channelId.doc().source(new ModbusChannelSource(element.getStartAddress())); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException( - "Unable to add Modbus mapping for [" + channelId.id() + "]: " + e.getMessage()); - } - } - - return new ChannelMapper(element) // - .m(channelId, converter) // - .build(); - } - - /** - * Maps the given element to the Channel identified by channelId, applying the - * given @link{ElementToChannelConverter}. - * - * @param the type of the {@link AbstractModbusElement} + * @param the type of the {@link AbstractModbusElement}d * @param channelId the Channel-ID * @param element the ModbusElement - * @param converter the {@link ElementToChannelConverter} + * @param converter the ElementToChannelConverter * @return the element parameter */ protected final > T m(io.openems.edge.common.channel.ChannelId channelId, T element, ElementToChannelConverter converter) { - return this.m(channelId, element, converter, null); + return new ChannelMapper(element) // + .m(channelId, converter) // + .build(); } public enum BitConverter { diff --git a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ModbusChannelSource.java b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ModbusChannelMetaInfo.java similarity index 67% rename from io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ModbusChannelSource.java rename to io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ModbusChannelMetaInfo.java index 309bd8c9e5..d3c692fcad 100644 --- a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ModbusChannelSource.java +++ b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ModbusChannelMetaInfo.java @@ -2,16 +2,7 @@ import java.util.Objects; -public class ModbusChannelSource { - - /** - * This can be used in {@link AbstractOpenemsModbusComponent} to ignore the - * check for duplicated source mappings. - */ - public static final IgnoreDuplicatedSource IGNORE_DUPLICATED_SOURCE = new IgnoreDuplicatedSource(); - - protected static class IgnoreDuplicatedSource { - } +public class ModbusChannelMetaInfo { /** * Holds the Start-Address of the Modbus Register. @@ -23,12 +14,12 @@ protected static class IgnoreDuplicatedSource { */ private final int bit; - public ModbusChannelSource(int address) { + public ModbusChannelMetaInfo(int address) { this.address = address; this.bit = -1; } - public ModbusChannelSource(int address, int bit) { + public ModbusChannelMetaInfo(int address, int bit) { this.address = address; this.bit = bit; } @@ -59,7 +50,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - ModbusChannelSource other = (ModbusChannelSource) obj; + ModbusChannelMetaInfo other = (ModbusChannelMetaInfo) obj; return this.address == other.address && this.bit == other.bit; } diff --git a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/element/BitsWordElement.java b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/element/BitsWordElement.java index f1fe282994..c27001e6a0 100644 --- a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/element/BitsWordElement.java +++ b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/element/BitsWordElement.java @@ -19,7 +19,7 @@ import io.openems.common.types.OpenemsType; import io.openems.edge.bridge.modbus.api.AbstractOpenemsModbusComponent; import io.openems.edge.bridge.modbus.api.AbstractOpenemsModbusComponent.BitConverter; -import io.openems.edge.bridge.modbus.api.ModbusChannelSource; +import io.openems.edge.bridge.modbus.api.ModbusChannelMetaInfo; import io.openems.edge.common.channel.Channel; import io.openems.edge.common.channel.ChannelId; import io.openems.edge.common.channel.WriteChannel; @@ -69,17 +69,19 @@ public BitsWordElement bit(int bitIndex, ChannelId channelId, BitConverter conve @SuppressWarnings("unchecked") Channel booleanChannel = (Channel) channel; - // Add Modbus Address and Bit-Index to Channel Source - channelId.doc().source(new ModbusChannelSource(this.getStartAddress(), bitIndex)); - - // Handle Writes to Bit-Channels ChannelWrapper channelWrapper = new ChannelWrapper(booleanChannel, converter); + + // Add Modbus Address and Bit-Index to Channel Source if (channel instanceof WriteChannel) { + // Handle Writes to Bit-Channels WriteChannel booleanWriteChannel = (WriteChannel) booleanChannel; booleanWriteChannel.onSetNextWrite(value -> { // Listen on Writes to the BooleanChannel and store the value channelWrapper.setWriteValue(value); }); + booleanWriteChannel.setWriteTarget(new ModbusChannelMetaInfo(this.getStartAddress(), bitIndex)); + } else { + channel.setReadSource(new ModbusChannelMetaInfo(this.getStartAddress(), bitIndex)); } this.channels[bitIndex] = channelWrapper; diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/BooleanWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/BooleanWriteChannel.java index ed1251aa39..b98afa6da1 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/BooleanWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/BooleanWriteChannel.java @@ -75,4 +75,20 @@ public void onSetNextWrite(ThrowingConsumer call this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/Channel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/Channel.java index a87c8e6a81..760497bcfc 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/Channel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/Channel.java @@ -207,4 +207,23 @@ public default void setNextValue(Object value) { */ public void deactivate(); + /** + * Sets an object that holds information about the read source of this Channel, + * i.e. a Modbus Register or REST-Api endpoint address. Defaults to null. + * + * @param the type of the source attachment + * @param source the source object + * @throws IllegalArgumentException if there is already a source registered with + * the Channel + */ + public void setReadSource(SOURCE source) throws IllegalArgumentException; + + /** + * Gets the read source information object. Defaults to empty String. + * + * @param the type of the source attachment + * @return the source information object + */ + public SOURCE getReadSource(); + } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/Doc.java b/io.openems.edge.common/src/io/openems/edge/common/channel/Doc.java index 47842f9734..3dcbbfe9c6 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/Doc.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/Doc.java @@ -135,26 +135,6 @@ public static StateChannelDoc of(Level level) { */ public String getText(); - /** - * Sets an object that holds information about the source of this Channel, i.e. - * a Modbus Register or REST-Api endpoint address. Defaults to null. - * - * @param the type of the source attachment - * @param source the source object - * @return myself - * @throws IllegalArgumentException if there is already a source registered with - * the Channel - */ - public Doc source(SOURCE source) throws IllegalArgumentException; - - /** - * Gets the source information object. Defaults to empty String. - * - * @param the type of the source attachment - * @return the soure information object - */ - public SOURCE getSource(); - /** * Is the more verbose debug mode activated?. * diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/DoubleWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/DoubleWriteChannel.java index 9704f4b217..1b5c386042 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/DoubleWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/DoubleWriteChannel.java @@ -44,4 +44,20 @@ public void onSetNextWrite(ThrowingConsumer callb this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/EnumWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/EnumWriteChannel.java index ae9212559f..c61b85a406 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/EnumWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/EnumWriteChannel.java @@ -8,9 +8,9 @@ import org.slf4j.LoggerFactory; import io.openems.common.exceptions.OpenemsError.OpenemsNamedException; +import io.openems.common.exceptions.OpenemsException; import io.openems.common.function.ThrowingConsumer; import io.openems.common.types.OptionsEnum; -import io.openems.common.exceptions.OpenemsException; import io.openems.edge.common.component.OpenemsComponent; public class EnumWriteChannel extends EnumReadChannel implements WriteChannel { @@ -101,4 +101,20 @@ public void onSetNextWrite(ThrowingConsumer call this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/FloatWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/FloatWriteChannel.java index a944d8e8aa..2c18ce6bbc 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/FloatWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/FloatWriteChannel.java @@ -73,4 +73,20 @@ public void onSetNextWrite(ThrowingConsumer callba this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/IntegerWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/IntegerWriteChannel.java index deeac9cd24..d679603271 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/IntegerWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/IntegerWriteChannel.java @@ -73,4 +73,20 @@ public void onSetNextWrite(ThrowingConsumer call this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/LongWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/LongWriteChannel.java index 0327b43fcc..ad39cd3fd0 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/LongWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/LongWriteChannel.java @@ -73,4 +73,20 @@ public void onSetNextWrite(ThrowingConsumer callbac this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/ShortWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/ShortWriteChannel.java index 9fa89ae685..3165d9e86d 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/ShortWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/ShortWriteChannel.java @@ -73,4 +73,20 @@ public void onSetNextWrite(ThrowingConsumer callba this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/StringWriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/StringWriteChannel.java index db5feabfce..35b28e2113 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/StringWriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/StringWriteChannel.java @@ -30,7 +30,7 @@ public void accept(Channel channel) { + "] is not an StringWriteChannel! Unable to register \"onSetNextWrite\"-Listener!"); return; } - + // on each setNextWrite to the channel -> store the value in the DEBUG-channel ((StringWriteChannel) channel).onSetNextWrite(value -> { channel.getComponent().channel(this.targetChannelId).setNextValue(value); @@ -73,4 +73,20 @@ public void onSetNextWrite(ThrowingConsumer callb this.getOnSetNextWrites().add(callback); } + /** + * An object that holds information about the write target of this Channel, i.e. + * a Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object writeTarget = null; + + @Override + public void setWriteTarget(WRITE_TARGET writeTarget) throws IllegalArgumentException { + this.writeTarget = WriteChannel.checkWriteTarget(this, writeTarget, writeTarget); + } + + @Override + @SuppressWarnings("unchecked") + public WRITE_TARGET getWriteTarget() { + return (WRITE_TARGET) this.writeTarget; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/WriteChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/WriteChannel.java index 1184c697d1..efc3b023f8 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/WriteChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/WriteChannel.java @@ -1,6 +1,7 @@ package io.openems.edge.common.channel; import java.util.List; +import java.util.Objects; import java.util.Optional; import io.openems.common.exceptions.OpenemsError.OpenemsNamedException; @@ -93,4 +94,44 @@ public default Optional getNextWriteValueAndReset() { public List> getOnSetNextWrites(); + /** + * Sets an object that holds information about the write target of this Channel, + * i.e. a Modbus Register or REST-Api endpoint address. Defaults to null. + * + * @param the type of the target attachment + * @param target the target object + * @return myself + * @throws IllegalArgumentException if there is already a target registered with + * the Channel + */ + public void setWriteTarget(WRITE_TARGET target) throws IllegalArgumentException; + + /** + * Gets the write target information object. Defaults to empty String. + * + * @param the type of the target attachment + * @return the target information object + */ + public WRITE_TARGET getWriteTarget(); + + /** + * Static helper method to be used within {@link #setWriteTarget(Object)}. + * + * @param the type of the target attachment + * @param channel the {@link WriteChannel} + * @param existingValue the existing value, or null + * @param newValue the new value + * @return the new value + * @throws IllegalArgumentException if the Channel already has a different + * Write-Target set + */ + public static WRITE_TARGET checkWriteTarget(WriteChannel channel, WRITE_TARGET existingValue, + WRITE_TARGET newValue) throws IllegalArgumentException { + if (existingValue != null && newValue != null && !Objects.equals(existingValue, newValue)) { + throw new IllegalArgumentException("Unable to set write target [" + newValue.toString() + "]." // + + " Channel [" + channel.address() + "] already has a write target [" + existingValue.toString() + + "]"); + } + return newValue; + } } diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractDoc.java b/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractDoc.java index ca557567a4..44be47af9d 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractDoc.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractDoc.java @@ -1,7 +1,6 @@ package io.openems.edge.common.channel.internal; import java.util.List; -import java.util.Objects; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; @@ -129,28 +128,6 @@ public String getText() { return this.text; } - /** - * An object that holds information about the source of this Channel, i.e. a - * Modbus Register or REST-Api endpoint address. Defaults to null. - */ - private Object source = null; - - @Override - public AbstractDoc source(SOURCE source) throws IllegalArgumentException { - if (this.source != null && source != null && !Objects.equals(this.source, source)) { - throw new IllegalArgumentException("Unable to set source [" + source.toString() - + "]. Channel already has a source [" + this.source.toString() + "]"); - } - this.source = source; - return this.self(); - } - - @Override - @SuppressWarnings("unchecked") - public SOURCE getSource() { - return (SOURCE) this.source; - } - @Override public Unit getUnit() { return Unit.NONE; diff --git a/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractReadChannel.java b/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractReadChannel.java index 707e02eaf0..27d981f827 100644 --- a/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractReadChannel.java +++ b/io.openems.edge.common/src/io/openems/edge/common/channel/internal/AbstractReadChannel.java @@ -259,4 +259,26 @@ private boolean validateType(OpenemsType expected, OpenemsType actual) { public CircularTreeMap> getPastValues() { return this.pastValues; } + + /** + * An object that holds information about the source of this Channel, i.e. a + * Modbus Register or REST-Api endpoint address. Defaults to null. + */ + private Object readSource = null; + + @Override + public void setReadSource(READ_SOURCE readSource) throws IllegalArgumentException { + if (this.readSource != null && readSource != null && !Objects.equals(this.readSource, readSource)) { + throw new IllegalArgumentException("Unable to set read source [" + readSource.toString() + "]." // + + " Channel [" + this.address() + "] already has a read source [" + this.readSource.toString() + + "]"); + } + this.readSource = readSource; + } + + @Override + @SuppressWarnings("unchecked") + public READ_SOURCE getReadSource() { + return (READ_SOURCE) this.readSource; + } } diff --git a/io.openems.edge.core/src/io/openems/edge/core/componentmanager/jsonrpc/ChannelExportXlsxResponse.java b/io.openems.edge.core/src/io/openems/edge/core/componentmanager/jsonrpc/ChannelExportXlsxResponse.java index e2df52623d..44ef74ee04 100644 --- a/io.openems.edge.core/src/io/openems/edge/core/componentmanager/jsonrpc/ChannelExportXlsxResponse.java +++ b/io.openems.edge.core/src/io/openems/edge/core/componentmanager/jsonrpc/ChannelExportXlsxResponse.java @@ -24,6 +24,7 @@ import io.openems.edge.common.channel.Channel; import io.openems.edge.common.channel.EnumReadChannel; import io.openems.edge.common.channel.StateChannel; +import io.openems.edge.common.channel.WriteChannel; import io.openems.edge.common.channel.internal.StateCollectorChannel; import io.openems.edge.common.component.OpenemsComponent; @@ -50,8 +51,9 @@ public class ChannelExportXlsxResponse extends Base64PayloadResponse { private static final int COL_VALUE = 1; private static final int COL_UNIT = 2; private static final int COL_DESCRIPTION = 3; - private static final int COL_ACCESS = 5; - private static final int COL_SOURCE = 4; + private static final int COL_READ_SOURCE = 4; + private static final int COL_WRITE_TARGET = 5; + private static final int COL_ACCESS = 6; public ChannelExportXlsxResponse(UUID id, OpenemsComponent component) throws OpenemsException { super(id, generatePayload(component)); @@ -118,12 +120,29 @@ protected static byte[] generatePayload(OpenemsComponent component) throws Opene ws.value(row, COL_UNIT, channel.channelDoc().getUnit().getSymbol()); ws.value(row, COL_DESCRIPTION, description); ws.value(row, COL_ACCESS, channel.channelDoc().getAccessMode().getAbbreviation()); - row++; - Object source = channel.channelDoc().getSource(); - if (source != null) { - ws.value(row, COL_SOURCE, source.toString()); + // Read Source + { + final Object readSource = channel.getReadSource(); + if (readSource != null) { + ws.value(row, COL_READ_SOURCE, readSource.toString()); + } + } + + // Write Target + { + final Object writeTarget; + if (channel instanceof WriteChannel) { + writeTarget = ((WriteChannel) channel).getWriteTarget(); + } else { + writeTarget = null; + } + if (writeTarget != null) { + ws.value(row, COL_WRITE_TARGET, writeTarget.toString()); + } } + + row++; } } finally { if (wb != null) { @@ -172,8 +191,9 @@ private static int addSheetHeader(Workbook wb, Worksheet ws, OpenemsComponent co addTableHeader(wb, ws, row, COL_VALUE, "Value", 35); addTableHeader(wb, ws, row, COL_UNIT, "Unit", 20); addTableHeader(wb, ws, row, COL_DESCRIPTION, "Description", 25); + addTableHeader(wb, ws, row, COL_READ_SOURCE, "Read Source", 20); + addTableHeader(wb, ws, row, COL_WRITE_TARGET, "Write Target", 20); addTableHeader(wb, ws, row, COL_ACCESS, "Access", 10); - addTableHeader(wb, ws, row, COL_SOURCE, "Source", 20); return ++row; } diff --git a/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/ResetChannelSources.java b/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/ResetChannelSources.java deleted file mode 100644 index 96491ae6e8..0000000000 --- a/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/ResetChannelSources.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.openems.edge.fenecon.dess; - -import io.openems.edge.common.channel.ChannelId; -import io.openems.edge.meter.api.AsymmetricMeter; -import io.openems.edge.meter.api.SymmetricMeter; - -/** - * Reset Channel sources to avoid 'Unable to add Modbus mapping' errors on - * running all tests at once. - */ -public class ResetChannelSources { - - public static void run() { - resetChannelSources(SymmetricMeter.ChannelId.values()); - resetChannelSources(AsymmetricMeter.ChannelId.values()); - } - - private static void resetChannelSources(ChannelId[] channelIds) { - for (ChannelId channelId : channelIds) { - channelId.doc().source(null); - } - } - -} diff --git a/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/gridmeter/FeneconDessGridMeterTest.java b/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/gridmeter/FeneconDessGridMeterTest.java index a3445cf187..4b5739d5c2 100644 --- a/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/gridmeter/FeneconDessGridMeterTest.java +++ b/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/gridmeter/FeneconDessGridMeterTest.java @@ -1,23 +1,16 @@ package io.openems.edge.fenecon.dess.gridmeter; -import org.junit.Before; import org.junit.Test; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; import io.openems.edge.common.test.ComponentTest; import io.openems.edge.common.test.DummyConfigurationAdmin; -import io.openems.edge.fenecon.dess.ResetChannelSources; public class FeneconDessGridMeterTest { private static final String METER_ID = "meter0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new FeneconDessGridMeterImpl()) // diff --git a/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/pvmeter/FeneconDessPvMeterTest.java b/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/pvmeter/FeneconDessPvMeterTest.java index c2b525b208..6ea702965b 100644 --- a/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/pvmeter/FeneconDessPvMeterTest.java +++ b/io.openems.edge.fenecon.dess/test/io/openems/edge/fenecon/dess/pvmeter/FeneconDessPvMeterTest.java @@ -1,23 +1,16 @@ package io.openems.edge.fenecon.dess.pvmeter; -import org.junit.Before; import org.junit.Test; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; import io.openems.edge.common.test.ComponentTest; import io.openems.edge.common.test.DummyConfigurationAdmin; -import io.openems.edge.fenecon.dess.ResetChannelSources; public class FeneconDessPvMeterTest { private static final String METER_ID = "meter0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new FeneconDessPvMeterImpl()) // diff --git a/io.openems.edge.fenecon.mini/src/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImpl.java b/io.openems.edge.fenecon.mini/src/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImpl.java index ad918ab564..2a187a828b 100644 --- a/io.openems.edge.fenecon.mini/src/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImpl.java +++ b/io.openems.edge.fenecon.mini/src/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImpl.java @@ -27,7 +27,6 @@ import io.openems.edge.bridge.modbus.api.BridgeModbus; import io.openems.edge.bridge.modbus.api.ElementToChannelConverter; import io.openems.edge.bridge.modbus.api.ElementToChannelOffsetConverter; -import io.openems.edge.bridge.modbus.api.ModbusChannelSource; import io.openems.edge.bridge.modbus.api.ModbusProtocol; import io.openems.edge.bridge.modbus.api.element.BitsWordElement; import io.openems.edge.bridge.modbus.api.element.DummyRegisterElement; @@ -456,10 +455,9 @@ protected ModbusProtocol defineModbusProtocol() throws OpenemsException { m(FeneconMiniEss.ChannelId.RTC_SECOND, new UnsignedWordElement(9019))), // new FC16WriteRegistersTask(30526, // m(FeneconMiniEss.ChannelId.GRID_MAX_CHARGE_CURRENT, new UnsignedWordElement(30526), - ElementToChannelConverter.SCALE_FACTOR_2, ModbusChannelSource.IGNORE_DUPLICATED_SOURCE), // + ElementToChannelConverter.SCALE_FACTOR_2), // m(FeneconMiniEss.ChannelId.GRID_MAX_DISCHARGE_CURRENT, new UnsignedWordElement(30527), - ElementToChannelConverter.SCALE_FACTOR_2, - ModbusChannelSource.IGNORE_DUPLICATED_SOURCE)), // + ElementToChannelConverter.SCALE_FACTOR_2)), // new FC16WriteRegistersTask(30558, // m(FeneconMiniEss.ChannelId.SETUP_MODE, new UnsignedWordElement(30558))), // new FC16WriteRegistersTask(30559, // diff --git a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/ResetChannelSources.java b/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/ResetChannelSources.java deleted file mode 100644 index 19cd761747..0000000000 --- a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/ResetChannelSources.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.openems.edge.fenecon.mini; - -import io.openems.edge.common.channel.ChannelId; -import io.openems.edge.meter.api.AsymmetricMeter; -import io.openems.edge.meter.api.SymmetricMeter; - -/** - * Reset Channel sources to avoid 'Unable to add Modbus mapping' errors on - * running all tests at once. - */ -public class ResetChannelSources { - - public static void run() { - resetChannelSources(SymmetricMeter.ChannelId.values()); - resetChannelSources(AsymmetricMeter.ChannelId.values()); - } - - private static void resetChannelSources(ChannelId[] channelIds) { - for (ChannelId channelId : channelIds) { - channelId.doc().source(null); - } - } - -} diff --git a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImplTest.java b/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImplTest.java index 83c7da9f0b..5e56a0c884 100644 --- a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImplTest.java +++ b/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/ess/FeneconMiniEssImplTest.java @@ -1,6 +1,5 @@ package io.openems.edge.fenecon.mini.ess; -import org.junit.Before; import org.junit.Test; import io.openems.common.types.ChannelAddress; @@ -10,7 +9,6 @@ import io.openems.edge.ess.api.SinglePhase; import io.openems.edge.ess.test.DummyPower; import io.openems.edge.ess.test.ManagedSymmetricEssTest; -import io.openems.edge.fenecon.mini.ResetChannelSources; import io.openems.edge.fenecon.mini.ess.statemachine.StateMachine.State; public class FeneconMiniEssImplTest { @@ -23,11 +21,6 @@ public class FeneconMiniEssImplTest { private static final ChannelAddress ESS_PCS_MODE = new ChannelAddress(ESS_ID, "PcsMode"); private static final ChannelAddress ESS_SETUP_MODE = new ChannelAddress(ESS_ID, "SetupMode"); - @Before - public void before() { - ResetChannelSources.run(); - } - /** * Tests activating write-mode when it was not activated before. * diff --git a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/gridmeter/FeneconMiniGridMeterTest.java b/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/gridmeter/FeneconMiniGridMeterTest.java index 1a99eeaf70..123a45c403 100644 --- a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/gridmeter/FeneconMiniGridMeterTest.java +++ b/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/gridmeter/FeneconMiniGridMeterTest.java @@ -1,23 +1,16 @@ package io.openems.edge.fenecon.mini.gridmeter; -import org.junit.Before; import org.junit.Test; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; import io.openems.edge.common.test.ComponentTest; import io.openems.edge.common.test.DummyConfigurationAdmin; -import io.openems.edge.fenecon.mini.ResetChannelSources; public class FeneconMiniGridMeterTest { private static final String METER_ID = "meter0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new FeneconMiniGridMeterImpl()) // diff --git a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/pvmeter/FeneconMiniPvMeterTest.java b/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/pvmeter/FeneconMiniPvMeterTest.java index ee8abe2505..69141cef2a 100644 --- a/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/pvmeter/FeneconMiniPvMeterTest.java +++ b/io.openems.edge.fenecon.mini/test/io/openems/edge/fenecon/mini/pvmeter/FeneconMiniPvMeterTest.java @@ -1,23 +1,16 @@ package io.openems.edge.fenecon.mini.pvmeter; -import org.junit.Before; import org.junit.Test; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; import io.openems.edge.common.test.ComponentTest; import io.openems.edge.common.test.DummyConfigurationAdmin; -import io.openems.edge.fenecon.mini.ResetChannelSources; public class FeneconMiniPvMeterTest { private static final String METER_ID = "meter0"; private static final String MODBUS_ID = "modbus0"; - @Before - public void before() { - ResetChannelSources.run(); - } - @Test public void test() throws Exception { new ComponentTest(new FeneconMiniPvMeterImpl()) // diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/AbstractGoodWeEtCharger.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/AbstractGoodWeEtCharger.java index ba74ffbc1f..30621c534b 100644 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/AbstractGoodWeEtCharger.java +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/AbstractGoodWeEtCharger.java @@ -18,7 +18,7 @@ import io.openems.edge.timedata.api.utils.CalculateEnergyFromPower; public abstract class AbstractGoodWeEtCharger extends AbstractOpenemsModbusComponent - implements EssDcCharger, OpenemsComponent, TimedataProvider, EventHandler { + implements GoodWeEtCharger, EssDcCharger, OpenemsComponent, TimedataProvider, EventHandler { private final CalculateEnergyFromPower calculateActualEnergy = new CalculateEnergyFromPower(this, EssDcCharger.ChannelId.ACTUAL_ENERGY); @@ -27,7 +27,7 @@ protected AbstractGoodWeEtCharger() { super(// OpenemsComponent.ChannelId.values(), // EssDcCharger.ChannelId.values(), // - PvChannelId.values() // + GoodWeEtCharger.ChannelId.values() // ); } @@ -36,9 +36,9 @@ protected ModbusProtocol defineModbusProtocol() throws OpenemsException { int startAddress = this.getStartAddress(); return new ModbusProtocol(this, // new FC3ReadRegistersTask(startAddress, Priority.LOW, // - m(PvChannelId.V, new UnsignedWordElement(startAddress), // + m(GoodWeEtCharger.ChannelId.V, new UnsignedWordElement(startAddress), // ElementToChannelConverter.SCALE_FACTOR_MINUS_1), // - m(PvChannelId.I, new UnsignedWordElement(startAddress + 1), + m(GoodWeEtCharger.ChannelId.I, new UnsignedWordElement(startAddress + 1), ElementToChannelConverter.SCALE_FACTOR_MINUS_1)), new FC3ReadRegistersTask(startAddress + 2, Priority.HIGH, // m(EssDcCharger.ChannelId.ACTUAL_POWER, new UnsignedDoublewordElement(startAddress + 2)))); diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger.java new file mode 100644 index 0000000000..a71bc429c4 --- /dev/null +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger.java @@ -0,0 +1,29 @@ +package io.openems.edge.goodwe.charger; + +import io.openems.common.channel.AccessMode; +import io.openems.common.channel.Unit; +import io.openems.common.types.OpenemsType; +import io.openems.edge.common.channel.Doc; + +public interface GoodWeEtCharger { + + public enum ChannelId implements io.openems.edge.common.channel.ChannelId { + + V(Doc.of(OpenemsType.INTEGER) // + .unit(Unit.VOLT).accessMode(AccessMode.READ_ONLY)), + I(Doc.of(OpenemsType.INTEGER) // + .unit(Unit.AMPERE).accessMode(AccessMode.READ_ONLY)); + + private final Doc doc; + + private ChannelId(Doc doc) { + this.doc = doc; + } + + @Override + public Doc doc() { + return this.doc; + } + + } +} \ No newline at end of file diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeChargerPv1.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger1.java similarity index 94% rename from io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeChargerPv1.java rename to io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger1.java index f3fbbbd5ee..7fe337112e 100644 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeChargerPv1.java +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger1.java @@ -31,8 +31,8 @@ property = { // EventConstants.EVENT_TOPIC + "=" + EdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE // }) -public class GoodWeChargerPv1 extends AbstractGoodWeEtCharger - implements EssDcCharger, OpenemsComponent, EventHandler, TimedataProvider { +public class GoodWeEtCharger1 extends AbstractGoodWeEtCharger + implements GoodWeEtCharger, EssDcCharger, OpenemsComponent, EventHandler, TimedataProvider { @Reference protected ConfigurationAdmin cm; @@ -48,7 +48,7 @@ protected void setModbus(BridgeModbus modbus) { super.setModbus(modbus); } - public GoodWeChargerPv1() { + public GoodWeEtCharger1() { super(); } diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeChargerPv2.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger2.java similarity index 94% rename from io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeChargerPv2.java rename to io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger2.java index 007cc71b4d..4f95ecbec7 100644 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeChargerPv2.java +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/GoodWeEtCharger2.java @@ -31,8 +31,8 @@ property = { // EventConstants.EVENT_TOPIC + "=" + EdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE // }) -public class GoodWeChargerPv2 extends AbstractGoodWeEtCharger - implements EssDcCharger, OpenemsComponent, EventHandler, TimedataProvider { +public class GoodWeEtCharger2 extends AbstractGoodWeEtCharger + implements GoodWeEtCharger, EssDcCharger, OpenemsComponent, EventHandler, TimedataProvider { @Reference protected ConfigurationAdmin cm; @@ -48,7 +48,7 @@ protected void setModbus(BridgeModbus modbus) { super.setModbus(modbus); } - public GoodWeChargerPv2() { + public GoodWeEtCharger2() { super(); } diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/PvChannelId.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/PvChannelId.java deleted file mode 100644 index a036d2419a..0000000000 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/charger/PvChannelId.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.openems.edge.goodwe.charger; - -import io.openems.common.channel.AccessMode; -import io.openems.common.channel.Unit; -import io.openems.common.types.OpenemsType; -import io.openems.edge.common.channel.ChannelId; -import io.openems.edge.common.channel.Doc; - -public enum PvChannelId implements ChannelId { - V(Doc.of(OpenemsType.INTEGER) // - .unit(Unit.VOLT).accessMode(AccessMode.READ_ONLY)), - I(Doc.of(OpenemsType.INTEGER) // - .unit(Unit.AMPERE).accessMode(AccessMode.READ_ONLY)); - - private final Doc doc; - - private PvChannelId(Doc doc) { - this.doc = doc; - } - - @Override - public Doc doc() { - return this.doc; - } -} \ No newline at end of file diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/GoodWe.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/GoodWe.java index 976037ced2..e00f776188 100644 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/GoodWe.java +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/GoodWe.java @@ -9,8 +9,8 @@ import io.openems.edge.common.channel.value.Value; import io.openems.edge.common.component.OpenemsComponent; import io.openems.edge.goodwe.charger.AbstractGoodWeEtCharger; -import io.openems.edge.goodwe.charger.GoodWeChargerPv1; -import io.openems.edge.goodwe.charger.GoodWeChargerPv2; +import io.openems.edge.goodwe.charger.GoodWeEtCharger1; +import io.openems.edge.goodwe.charger.GoodWeEtCharger2; import io.openems.edge.goodwe.common.enums.AppModeIndex; import io.openems.edge.goodwe.common.enums.BatteryMode; import io.openems.edge.goodwe.common.enums.EmsPowerMode; @@ -29,14 +29,14 @@ public interface GoodWe extends OpenemsComponent { /** * Registers a GoodWe Charger. * - * @param charger either {@link GoodWeChargerPv1} or {@link GoodWeChargerPv2} + * @param charger either {@link GoodWeEtCharger1} or {@link GoodWeEtCharger2} */ public void addCharger(AbstractGoodWeEtCharger charger); /** * Unregisters a GoodWe Charger. * - * @param charger either {@link GoodWeChargerPv1} or {@link GoodWeChargerPv2} + * @param charger either {@link GoodWeEtCharger1} or {@link GoodWeEtCharger2} */ public void removeCharger(AbstractGoodWeEtCharger charger); diff --git a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImplTest.java b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImplTest.java index f108c9c727..8d6e7232e7 100644 --- a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImplTest.java +++ b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImplTest.java @@ -7,7 +7,7 @@ import io.openems.edge.common.test.DummyConfigurationAdmin; import io.openems.edge.ess.test.DummyPower; import io.openems.edge.goodwe.GoodWeConstants; -import io.openems.edge.goodwe.charger.GoodWeChargerPv1; +import io.openems.edge.goodwe.charger.GoodWeEtCharger1; public class GoodWeBatteryInverterImplTest { @@ -19,7 +19,7 @@ public class GoodWeBatteryInverterImplTest { @Test public void testEt() throws Exception { - GoodWeChargerPv1 charger = new GoodWeChargerPv1(); + GoodWeEtCharger1 charger = new GoodWeEtCharger1(); new ComponentTest(charger) // .addReference("cm", new DummyConfigurationAdmin()) // .addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) // diff --git a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv1Test.java b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv1Test.java index 107afa69ad..6010779de3 100644 --- a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv1Test.java +++ b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv1Test.java @@ -14,7 +14,7 @@ public class GoodWeChargerPv1Test { @Test public void test() throws Exception { - new ComponentTest(new GoodWeChargerPv1()) // + new ComponentTest(new GoodWeEtCharger1()) // .addReference("cm", new DummyConfigurationAdmin()) // .addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) // .activate(MyConfig.create() // diff --git a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv2Test.java b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv2Test.java index ca32d10a7f..cfda586dc1 100644 --- a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv2Test.java +++ b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/charger/GoodWeChargerPv2Test.java @@ -14,7 +14,7 @@ public class GoodWeChargerPv2Test { @Test public void test() throws Exception { - new ComponentTest(new GoodWeChargerPv2()) // + new ComponentTest(new GoodWeEtCharger2()) // .addReference("cm", new DummyConfigurationAdmin()) // .addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) // .activate(MyConfig.create() // diff --git a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/ess/GoodWeEssImplTest.java b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/ess/GoodWeEssImplTest.java index 94953cd7d2..c2f46097ef 100644 --- a/io.openems.edge.goodwe/test/io/openems/edge/goodwe/ess/GoodWeEssImplTest.java +++ b/io.openems.edge.goodwe/test/io/openems/edge/goodwe/ess/GoodWeEssImplTest.java @@ -8,7 +8,7 @@ import io.openems.edge.ess.test.DummyPower; import io.openems.edge.ess.test.ManagedSymmetricEssTest; import io.openems.edge.goodwe.GoodWeConstants; -import io.openems.edge.goodwe.charger.GoodWeChargerPv1; +import io.openems.edge.goodwe.charger.GoodWeEtCharger1; public class GoodWeEssImplTest { @@ -18,7 +18,7 @@ public class GoodWeEssImplTest { @Test public void testEt() throws Exception { - GoodWeChargerPv1 charger = new GoodWeChargerPv1(); + GoodWeEtCharger1 charger = new GoodWeEtCharger1(); new ComponentTest(charger) // .addReference("cm", new DummyConfigurationAdmin()) // .addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) // diff --git a/io.openems.edge.kaco.blueplanet.hybrid10/bin_test/.gitignore b/io.openems.edge.kaco.blueplanet.hybrid10/bin_test/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/io.openems.edge.kaco.blueplanet.hybrid10/generated/buildfiles b/io.openems.edge.kaco.blueplanet.hybrid10/generated/buildfiles new file mode 100644 index 0000000000..c0fff74831 --- /dev/null +++ b/io.openems.edge.kaco.blueplanet.hybrid10/generated/buildfiles @@ -0,0 +1 @@ +C:/Users/stefan.feilmeier/fems/fems/io.openems.edge.kaco.blueplanet.hybrid10/generated/io.openems.edge.kaco.blueplanet.hybrid10.jar diff --git a/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/singlephase/SocomecMeterSinglephaseImplTest.java b/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/singlephase/SocomecMeterSinglephaseImplTest.java index 71a8506536..7967b80ee0 100644 --- a/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/singlephase/SocomecMeterSinglephaseImplTest.java +++ b/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/singlephase/SocomecMeterSinglephaseImplTest.java @@ -1,5 +1,6 @@ package io.openems.edge.meter.socomec.singlephase; +import org.junit.Before; import org.junit.Test; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; @@ -13,9 +14,11 @@ public class SocomecMeterSinglephaseImplTest { private static final String METER_ID = "meter0"; private static final String MODBUS_ID = "modbus0"; - @Test - public void test() throws Exception { - SocomecMeterSinglephaseImpl meter = new SocomecMeterSinglephaseImpl(); + private static SocomecMeterSinglephaseImpl meter; + + @Before + public void setup() throws Exception { + meter = new SocomecMeterSinglephaseImpl(); new ComponentTest(meter) // .addReference("cm", new DummyConfigurationAdmin()) // .addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) // @@ -26,12 +29,35 @@ public void test() throws Exception { .setInvert(false) // .setPhase(SinglePhase.L1) // .build()); // + } + @Test + public void testCountisE14() throws Exception { meter.identifiedCountisE14(); + } + + @Test + public void testCountisE23_E24_E27_E28() throws Exception { meter.identifiedCountisE23_E24_E27_E28(); + } + + @Test + public void testCountisE34_E44() throws Exception { meter.identifiedCountisE34_E44(); + } + + @Test + public void testDirisA10() throws Exception { meter.identifiedDirisA10(); + } + + @Test + public void testDirisA14() throws Exception { meter.identifiedDirisA14(); + } + + @Test + public void testDirisB30() throws Exception { meter.identifiedDirisB30(); } diff --git a/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/threephase/SocomecMeterThreephaseImplTest.java b/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/threephase/SocomecMeterThreephaseImplTest.java index edb86611ae..01b0592aa6 100644 --- a/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/threephase/SocomecMeterThreephaseImplTest.java +++ b/io.openems.edge.meter.socomec/test/io/openems/edge/meter/socomec/threephase/SocomecMeterThreephaseImplTest.java @@ -1,5 +1,6 @@ package io.openems.edge.meter.socomec.threephase; +import org.junit.Before; import org.junit.Test; import io.openems.edge.bridge.modbus.test.DummyModbusBridge; @@ -12,9 +13,11 @@ public class SocomecMeterThreephaseImplTest { private static final String METER_ID = "meter0"; private static final String MODBUS_ID = "modbus0"; - @Test - public void test() throws Exception { - SocomecMeterThreephaseImpl meter = new SocomecMeterThreephaseImpl(); + private static SocomecMeterThreephaseImpl meter; + + @Before + public void setup() throws Exception { + meter = new SocomecMeterThreephaseImpl(); new ComponentTest(meter) // .addReference("cm", new DummyConfigurationAdmin()) // .addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) // @@ -24,12 +27,35 @@ public void test() throws Exception { .setType(MeterType.GRID) // .setInvert(false) // .build()); // + } + @Test + public void testCountisE14() throws Exception { meter.identifiedCountisE14(); + } + + @Test + public void testCountisE23_E24_E27_E28() throws Exception { meter.identifiedCountisE23_E24_E27_E28(); + } + + @Test + public void testCountisE34_E44() throws Exception { meter.identifiedCountisE34_E44(); + } + + @Test + public void testDirisA10() throws Exception { meter.identifiedDirisA10(); + } + + @Test + public void testDirisA14() throws Exception { meter.identifiedDirisA14(); + } + + @Test + public void testDirisB30() throws Exception { meter.identifiedDirisB30(); } diff --git a/io.openems.edge.meter.weidmueller/src/io/openems/edge/meter/weidmueller/MeterWeidmueller525.java b/io.openems.edge.meter.weidmueller/src/io/openems/edge/meter/weidmueller/MeterWeidmueller525.java index 369a57319b..b4a51b2b2f 100644 --- a/io.openems.edge.meter.weidmueller/src/io/openems/edge/meter/weidmueller/MeterWeidmueller525.java +++ b/io.openems.edge.meter.weidmueller/src/io/openems/edge/meter/weidmueller/MeterWeidmueller525.java @@ -138,7 +138,7 @@ protected ModbusProtocol defineModbusProtocol() throws OpenemsException { m(WeidmuellerChannelId.HARMONIC_THD_VOLT_L2N, new FloatDoublewordElement(19112)), // m(WeidmuellerChannelId.HARMONIC_THD_VOLT_L3N, new FloatDoublewordElement(19114)), // m(WeidmuellerChannelId.HARMONIC_THD_CURRENT_L1N, new FloatDoublewordElement(19116)), // - m(WeidmuellerChannelId.HARMONIC_THD_VOLT_L2N, new FloatDoublewordElement(19118)), // + m(WeidmuellerChannelId.HARMONIC_THD_CURRENT_L2N, new FloatDoublewordElement(19118)), // m(WeidmuellerChannelId.HARMONIC_THD_CURRENT_L3N, new FloatDoublewordElement(19120)))); }