[New] ReadState is now configurable with configuration parameter plcSupportsReadState
If this parameter is missing, it is considered true, as this is the previous behaviour
This commit is contained in:
parent
c3a7f6abea
commit
d9f6f9daca
|
@ -1,10 +1,15 @@
|
|||
package li.strolch.plc.gw.server;
|
||||
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.plc.model.PlcAddressKey;
|
||||
import li.strolch.plc.model.PlcAddressValueResponse;
|
||||
|
||||
import static li.strolch.plc.model.PlcConstants.PARAM_PLC_SUPPORTS_READ_STATE;
|
||||
|
||||
public abstract class ReadStatePlcGwService extends PlcGwService implements PlcConnectionStateListener {
|
||||
|
||||
protected boolean plcSupportsReadState;
|
||||
|
||||
public ReadStatePlcGwService(String plcId, PlcGwServerHandler plcHandler) {
|
||||
super(plcId, plcHandler);
|
||||
}
|
||||
|
@ -12,14 +17,28 @@ public abstract class ReadStatePlcGwService extends PlcGwService implements PlcC
|
|||
protected void handleGetState(PlcAddressValueResponse response) {
|
||||
PlcAddressKey addressKey = response.getPlcAddressKey();
|
||||
if (response.isFailed()) {
|
||||
logger.error("Failed to read value for address " + addressKey + ": " + response.getStateMsg());
|
||||
logger.error("Failed to read value for address {}: {}", addressKey, response.getStateMsg());
|
||||
} else {
|
||||
storeAddressState(addressKey, response.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
this.plcSupportsReadState = runReadOnlyTx((ctx, tx) -> {
|
||||
Resource configuration = tx.getConfiguration();
|
||||
return !configuration.hasParameter(PARAM_PLC_SUPPORTS_READ_STATE) || configuration.getBoolean(
|
||||
PARAM_PLC_SUPPORTS_READ_STATE);
|
||||
});
|
||||
super.register();
|
||||
}
|
||||
|
||||
protected void readState(String resource, String action) {
|
||||
this.plcHandler.asyncGetAddressState(keyFor(resource, action), this.plcId, this::handleGetState);
|
||||
if (!this.plcSupportsReadState)
|
||||
logger.warn("Not reading state for resource {}: {} as PLC does not support this feature!", resource,
|
||||
action);
|
||||
else
|
||||
this.plcHandler.asyncGetAddressState(keyFor(resource, action), this.plcId, this::handleGetState);
|
||||
}
|
||||
|
||||
protected abstract void storeAddressState(PlcAddressKey addressKey, Object value);
|
||||
|
|
|
@ -54,6 +54,8 @@ public class PlcConstants {
|
|||
public static final String PARAM_REALM = "realm";
|
||||
public static final String PARAM_SIMULATED = "simulated";
|
||||
|
||||
public static final String PARAM_PLC_SUPPORTS_READ_STATE = "plcSupportsReadState";
|
||||
|
||||
public static final String INTERPRETATION_NOTIFICATION = "Notification";
|
||||
public static final String INTERPRETATION_TELEGRAM = "Telegram";
|
||||
|
||||
|
|
Loading…
Reference in New Issue