Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the invert funktion of Meter Siemens PAC 1600 and corrected production and consumption energy register #2823

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ public static final ElementToChannelConverter SCALE_FACTOR_MINUS_1_AND_INVERT_IF
// CHECKSTYLE:ON
return chain(SCALE_FACTOR_MINUS_1, INVERT_IF_TRUE(invert));
}

/**
* Applies {@link ElementToChannelConverter#SCALE_FACTOR_MINUS_2} and
* INVERT_IF_TRUE.
*
* @param invert input value for {@link #INVERT_IF_TRUE(boolean)}
* @return the {@link ElementToChannelConverter}
*/
// CHECKSTYLE:OFF
public static final ElementToChannelConverter SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(boolean invert) {
// CHECKSTYLE:ON
return chain(SCALE_FACTOR_MINUS_2, INVERT_IF_TRUE(invert));
}

private final Function<Object, Object> elementToChannel;
private final Function<Object, Object> channelToElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

@AttributeDefinition(name = "Modbus Unit-ID", description = "The Unit-ID of the Modbus device.")
int modbusUnitId() default 1;

@AttributeDefinition(name = "Invert Power", description = "Inverts all Power values, inverts current values, swaps production and consumption energy, i.e. Power is multiplied with -1.")
boolean invert() default false;

@AttributeDefinition(name = "Modbus target filter", description = "This is auto-generated by 'Modbus-ID'.")
String Modbus_target() default "(enabled=true)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class MeterSiemensPac1600Impl extends AbstractOpenemsModbusComponent
implements MeterSiemensPac1600, ElectricityMeter, ModbusComponent, OpenemsComponent, ModbusSlave {

private MeterType meterType = MeterType.GRID;
/** Invert power values. */
private boolean invert = false;

@Reference
protected ConfigurationAdmin cm;
Expand All @@ -63,6 +65,7 @@ protected void setModbus(BridgeModbus modbus) {
@Activate
private void activate(ComponentContext context, Config config) throws OpenemsException {
this.meterType = config.type();
this.invert = config.invert();

if (super.activate(context, config.id(), config.alias(), config.enabled(), config.modbusUnitId(), this.cm,
"Modbus", config.modbus_id())) {
Expand All @@ -82,7 +85,7 @@ public MeterType getMeterType() {

@Override
protected ModbusProtocol defineModbusProtocol() {
return new ModbusProtocol(this, //
var modbusProtocol = new ModbusProtocol(this, //
new FC3ReadRegistersTask(1, Priority.HIGH, //
m(ElectricityMeter.ChannelId.VOLTAGE_L1, new UnsignedDoublewordElement(1),
ElementToChannelConverter.SCALE_FACTOR_1),
Expand All @@ -105,19 +108,19 @@ protected ModbusProtocol defineModbusProtocol() {
m(MeterSiemensPac1600.ChannelId.VOLTAGE_L3L1, new UnsignedDoublewordElement(17),
ElementToChannelConverter.SCALE_FACTOR_1),

m(ElectricityMeter.ChannelId.ACTIVE_POWER_L1, new SignedDoublewordElement(19),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2),
m(ElectricityMeter.ChannelId.ACTIVE_POWER_L1, new SignedDoublewordElement(19),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert)),
m(ElectricityMeter.ChannelId.ACTIVE_POWER_L2, new SignedDoublewordElement(21),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert)),
m(ElectricityMeter.ChannelId.ACTIVE_POWER_L3, new SignedDoublewordElement(23),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert)),

m(ElectricityMeter.ChannelId.REACTIVE_POWER_L1, new SignedDoublewordElement(25),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert)),
m(ElectricityMeter.ChannelId.REACTIVE_POWER_L2, new SignedDoublewordElement(27),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert)),
m(ElectricityMeter.ChannelId.REACTIVE_POWER_L3, new SignedDoublewordElement(29),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2)),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert))),

new FC3ReadRegistersTask(49, Priority.HIGH, // DummyRegisterElement didn`t work here
m(ElectricityMeter.ChannelId.FREQUENCY, new SignedDoublewordElement(49),
Expand All @@ -128,47 +131,89 @@ protected ModbusProtocol defineModbusProtocol() {
ElementToChannelConverter.SCALE_FACTOR_1),
new DummyRegisterElement(55, 56), //
m(ElectricityMeter.ChannelId.ACTIVE_POWER, new SignedDoublewordElement(57),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert)),
m(ElectricityMeter.ChannelId.REACTIVE_POWER, new SignedDoublewordElement(59),
ElementToChannelConverter.SCALE_FACTOR_MINUS_2)),

new FC3ReadRegistersTask(6687, Priority.LOW,
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY, new UnsignedDoublewordElement(6687),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY, new UnsignedDoublewordElement(6689),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY,
new UnsignedDoublewordElement(6691), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY, new UnsignedDoublewordElement(6693),
ElementToChannelConverter.DIRECT_1_TO_1),
new DummyRegisterElement(6695, 6706),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L1, new UnsignedDoublewordElement(6707),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L1, new UnsignedDoublewordElement(6709),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L1,
new UnsignedDoublewordElement(6711), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L1,
new UnsignedDoublewordElement(6713), ElementToChannelConverter.DIRECT_1_TO_1)),

new FC3ReadRegistersTask(6727, Priority.LOW, // DummyRegisterElement didn`t work here
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L2, new UnsignedDoublewordElement(6727),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L2, new UnsignedDoublewordElement(6729),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L2,
new UnsignedDoublewordElement(6731), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L2,
new UnsignedDoublewordElement(6733), ElementToChannelConverter.DIRECT_1_TO_1),
new DummyRegisterElement(6735, 6746),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L3, new UnsignedDoublewordElement(6747),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L3, new UnsignedDoublewordElement(6749),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L3,
new UnsignedDoublewordElement(6751), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L3,
new UnsignedDoublewordElement(6753), ElementToChannelConverter.DIRECT_1_TO_1)));
ElementToChannelConverter.SCALE_FACTOR_MINUS_2_AND_INVERT_IF_TRUE(this.invert))));
if (this.invert) {
modbusProtocol.addTask(new FC3ReadRegistersTask(6687, Priority.LOW,
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY, new UnsignedDoublewordElement(6687),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY, new UnsignedDoublewordElement(6689),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY,
new UnsignedDoublewordElement(6691), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY, new UnsignedDoublewordElement(6693),
ElementToChannelConverter.DIRECT_1_TO_1),
new DummyRegisterElement(6695, 6706),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L1, new UnsignedDoublewordElement(6707),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L1, new UnsignedDoublewordElement(6709),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L1,
new UnsignedDoublewordElement(6711), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L1,
new UnsignedDoublewordElement(6713), ElementToChannelConverter.DIRECT_1_TO_1)));

modbusProtocol.addTask(new FC3ReadRegistersTask(6727, Priority.LOW, // DummyRegisterElement didn`t work here
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L2, new UnsignedDoublewordElement(6727),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L2, new UnsignedDoublewordElement(6729),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L2,
new UnsignedDoublewordElement(6731), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L2,
new UnsignedDoublewordElement(6733), ElementToChannelConverter.DIRECT_1_TO_1),
new DummyRegisterElement(6735, 6746),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L3, new UnsignedDoublewordElement(6747),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L3, new UnsignedDoublewordElement(6749),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L3,
new UnsignedDoublewordElement(6751), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L3,
new UnsignedDoublewordElement(6753), ElementToChannelConverter.DIRECT_1_TO_1)));
} else {
modbusProtocol.addTask(new FC3ReadRegistersTask(6687, Priority.LOW,
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY, new UnsignedDoublewordElement(6687),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY, new UnsignedDoublewordElement(6689),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY,
new UnsignedDoublewordElement(6691), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY, new UnsignedDoublewordElement(6693),
ElementToChannelConverter.DIRECT_1_TO_1),
new DummyRegisterElement(6695, 6706),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L1, new UnsignedDoublewordElement(6707),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L1, new UnsignedDoublewordElement(6709),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L1,
new UnsignedDoublewordElement(6711), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L1,
new UnsignedDoublewordElement(6713), ElementToChannelConverter.DIRECT_1_TO_1)));

modbusProtocol.addTask(new FC3ReadRegistersTask(6727, Priority.LOW, // DummyRegisterElement didn`t work here
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L2, new UnsignedDoublewordElement(6727),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L2, new UnsignedDoublewordElement(6729),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L2,
new UnsignedDoublewordElement(6731), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L2,
new UnsignedDoublewordElement(6733), ElementToChannelConverter.DIRECT_1_TO_1),
new DummyRegisterElement(6735, 6746),
m(ElectricityMeter.ChannelId.ACTIVE_PRODUCTION_ENERGY_L3, new UnsignedDoublewordElement(6747),
ElementToChannelConverter.DIRECT_1_TO_1),
m(ElectricityMeter.ChannelId.ACTIVE_CONSUMPTION_ENERGY_L3, new UnsignedDoublewordElement(6749),
ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_PRODUCTION_ENERGY_L3,
new UnsignedDoublewordElement(6751), ElementToChannelConverter.DIRECT_1_TO_1),
m(MeterSiemensPac1600.ChannelId.REACTIVE_CONSUMPTION_ENERGY_L3,
new UnsignedDoublewordElement(6753), ElementToChannelConverter.DIRECT_1_TO_1)));
}


return modbusProtocol;
}

@Override
Expand All @@ -182,4 +227,4 @@ public ModbusSlaveTable getModbusSlaveTable(AccessMode accessMode) {
OpenemsComponent.getModbusSlaveNatureTable(accessMode), //
ElectricityMeter.getModbusSlaveNatureTable(accessMode));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void test() throws Exception {
.setId(METER_ID) //
.setModbusId(MODBUS_ID) //
.setType(MeterType.GRID) //
.setInvert(false) //
.build()) //
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ protected static class Builder {
private String modbusId;
private int modbusUnitId;
private MeterType type;
private boolean invert;

private Builder() {
}
Expand All @@ -30,6 +31,11 @@ public Builder setType(MeterType type) {
this.type = type;
return this;
}

public Builder setInvert(boolean invert) {
this.invert = invert;
return this;
}

public MyConfig build() {
return new MyConfig(this);
Expand Down Expand Up @@ -72,4 +78,9 @@ public MeterType type() {
return this.builder.type;
}

@Override
public boolean invert() {
return this.builder.invert;
}

}