[New] Implemented implicit virtual connections and added verbose logging
This commit is contained in:
parent
c83b387e7d
commit
d0adc91e4b
|
@ -36,6 +36,7 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
|
|||
private MapOfMaps<String, String, PlcAddress> plcTelegrams;
|
||||
private Map<PlcAddress, String> addressesToResourceId;
|
||||
private PlcListener globalListener;
|
||||
private boolean verbose;
|
||||
|
||||
public DefaultPlcHandler(ComponentContainer container, String componentName) {
|
||||
super(container, componentName);
|
||||
|
@ -86,6 +87,7 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
|
|||
this.plcAddresses = new MapOfMaps<>();
|
||||
this.plcTelegrams = new MapOfMaps<>();
|
||||
this.addressesToResourceId = new HashMap<>();
|
||||
this.verbose = configuration.getBoolean("verbose", false);
|
||||
|
||||
super.initialize(configuration);
|
||||
}
|
||||
|
@ -136,6 +138,7 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
|
|||
MapOfMaps<String, String, PlcAddress> plcTelegrams = new MapOfMaps<>();
|
||||
Map<PlcAddress, String> addressesToResourceId = new HashMap<>();
|
||||
this.plc = configure(validateCtx(), plcAddresses, plcTelegrams, addressesToResourceId);
|
||||
this.plc.setVerbose(this.verbose);
|
||||
this.plcAddresses = plcAddresses;
|
||||
this.plcTelegrams = plcTelegrams;
|
||||
this.addressesToResourceId = addressesToResourceId;
|
||||
|
@ -199,7 +202,9 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
|
|||
}
|
||||
|
||||
private void updatePlcAddress(PlcAddress address, Object value) {
|
||||
long s = nanoTime();
|
||||
long s = 0L;
|
||||
if (this.verbose)
|
||||
s = nanoTime();
|
||||
|
||||
String addressId = this.addressesToResourceId.get(address);
|
||||
if (addressId == null) {
|
||||
|
@ -213,11 +218,11 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
|
|||
Resource addressRes = tx.getResourceBy(TYPE_PLC_ADDRESS, addressId, true);
|
||||
|
||||
// see if we need to invert a boolean flag
|
||||
if (address.valueType == StrolchValueType.BOOLEAN && address.inverted) {
|
||||
if (address.valueType == StrolchValueType.BOOLEAN && address.inverted)
|
||||
value = !((boolean) value);
|
||||
}
|
||||
|
||||
Parameter<?> valueP = addressRes.getParameter(PARAM_VALUE, true);
|
||||
if (this.verbose)
|
||||
logger.info("PlcAddress {}-{} has changed from {} to {}", address.resource, address.action,
|
||||
valueP.getValue(), value);
|
||||
|
||||
|
@ -229,11 +234,14 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
|
|||
logger.error("Failed to update PlcAddress " + addressId + " with new value " + value, e);
|
||||
}
|
||||
|
||||
if (this.verbose)
|
||||
logger.info("async update " + address.address + " took " + (formatNanoDuration(nanoTime() - s)));
|
||||
}
|
||||
|
||||
private void updateConnectionState(PlcConnection plcConnection) {
|
||||
long s = nanoTime();
|
||||
long s = 0L;
|
||||
if (this.verbose)
|
||||
s = nanoTime();
|
||||
|
||||
try {
|
||||
try (StrolchTransaction tx = openTx(validateCtx().getCertificate(), "updateConnectionState", false)) {
|
||||
|
@ -247,6 +255,7 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
|
|||
logger.error("Failed to update state for connection " + plcConnection.getId(), e);
|
||||
}
|
||||
|
||||
if (this.verbose)
|
||||
logger.info("updateConnectionState took " + (formatNanoDuration(nanoTime() - s)));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ public class DefaultPlc implements Plc {
|
|||
private PlcListener globalListener;
|
||||
private MapOfLists<PlcAddress, PlcListener> listeners;
|
||||
private PlcConnectionStateChangeListener connectionStateChangeListener;
|
||||
private boolean verbose;
|
||||
|
||||
public DefaultPlc() {
|
||||
this.notificationMappings = new HashMap<>();
|
||||
|
@ -30,6 +31,11 @@ public class DefaultPlc implements Plc {
|
|||
this.connectionsByAddress = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVerbose(boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGlobalListener(PlcListener listener) {
|
||||
this.globalListener = listener;
|
||||
|
@ -52,14 +58,15 @@ public class DefaultPlc implements Plc {
|
|||
|
||||
@Override
|
||||
public void notify(String address, Object value) {
|
||||
logger.info("Update for " + address + " with value " + value);
|
||||
|
||||
PlcAddress plcAddress = this.notificationMappings.get(address);
|
||||
if (plcAddress == null) {
|
||||
logger.warn("No mapping to PlcAddress for hwAddress " + address);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Update for {}-{} @ {} with value {}", plcAddress.resource, plcAddress.action, plcAddress.address,
|
||||
value);
|
||||
|
||||
List<PlcListener> listeners = this.listeners.getList(plcAddress);
|
||||
if (listeners == null || listeners.isEmpty()) {
|
||||
logger.warn("No listeners for key " + plcAddress);
|
||||
|
@ -79,15 +86,18 @@ public class DefaultPlc implements Plc {
|
|||
|
||||
@Override
|
||||
public void send(PlcAddress plcAddress) {
|
||||
logger.info("Sending " + plcAddress.resource + "-" + plcAddress.action + ": " + plcAddress.defaultValue
|
||||
+ " (default)");
|
||||
if (this.verbose)
|
||||
logger.info("Sending {}-{}: {} (default)", plcAddress.resource, plcAddress.action, plcAddress.defaultValue);
|
||||
if (!isVirtual(plcAddress))
|
||||
validateConnection(plcAddress).send(plcAddress.address, plcAddress.defaultValue);
|
||||
notify(plcAddress.address, plcAddress.defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(PlcAddress plcAddress, Object value) {
|
||||
logger.info("Sending " + plcAddress.resource + "-" + plcAddress.action + ": " + value);
|
||||
if (this.verbose)
|
||||
logger.info("Sending {}-{}: {}", plcAddress.resource, plcAddress.action, value);
|
||||
if (!isVirtual(plcAddress))
|
||||
validateConnection(plcAddress).send(plcAddress.address, value);
|
||||
notify(plcAddress.address, value);
|
||||
}
|
||||
|
@ -154,18 +164,40 @@ public class DefaultPlc implements Plc {
|
|||
|
||||
@Override
|
||||
public void registerNotificationMapping(PlcAddress address) {
|
||||
if (!this.connectionsByAddress.containsKey(address.address))
|
||||
|
||||
boolean virtual = isVirtual(address);
|
||||
if (virtual)
|
||||
validateVirtualAddress(address);
|
||||
else if (!this.connectionsByAddress.containsKey(address.address))
|
||||
throw new IllegalStateException(
|
||||
"There is no connection registered for address " + address.address + " for key " + address);
|
||||
logger.info("Registered address mapping for " + address);
|
||||
|
||||
if (address.type != PlcAddressType.Notification)
|
||||
throw new IllegalArgumentException("Key must be of type " + PlcAddressType.Notification + ": " + address);
|
||||
|
||||
PlcAddress replaced = this.notificationMappings.put(address.address, address);
|
||||
if (replaced != null) {
|
||||
if (replaced != null)
|
||||
throw new IllegalArgumentException(
|
||||
"Replaced mapping for address " + address.address + " for key " + replaced + " with " + address);
|
||||
|
||||
logger.info("Registered address mapping for " + address);
|
||||
}
|
||||
|
||||
private void validateVirtualAddress(PlcAddress address) {
|
||||
|
||||
if (address.address.equals("virtualBoolean") || address.address.equals("virtualBoolean.")) {
|
||||
throw new IllegalStateException(
|
||||
"Virtual address " + address.address + " is missing sub component for " + address);
|
||||
}
|
||||
|
||||
if (address.address.equals("virtualString") || address.address.equals("virtualString.")) {
|
||||
throw new IllegalStateException(
|
||||
"Virtual address " + address.address + " is missing sub component for " + address);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isVirtual(PlcAddress address) {
|
||||
return address.address.startsWith("virtualBoolean") //
|
||||
|| address.address.startsWith("virtualString");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,4 +31,6 @@ public interface Plc {
|
|||
void notifyConnectionStateChanged(PlcConnection connection);
|
||||
|
||||
void setConnectionStateChangeListener(PlcConnectionStateChangeListener listener);
|
||||
|
||||
void setVerbose(boolean verbose);
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package li.strolch.plc.core.hw.connections;
|
||||
|
||||
import li.strolch.plc.core.hw.Plc;
|
||||
|
||||
public class VirtualBooleanValueConnection extends SimplePlcConnection {
|
||||
|
||||
public VirtualBooleanValueConnection(Plc plc, String id) {
|
||||
super(plc, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String address, Object value) {
|
||||
boolean bool = (boolean) value;
|
||||
logger.info("Setting address " + this.id + " to " + bool);
|
||||
// this.plc.notify(this.id, bool);
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package li.strolch.plc.core.hw.connections;
|
||||
|
||||
import li.strolch.plc.core.hw.Plc;
|
||||
|
||||
public class VirtualStringValueConnection extends SimplePlcConnection {
|
||||
|
||||
public VirtualStringValueConnection(Plc plc, String id) {
|
||||
super(plc, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String address, Object value) {
|
||||
String string = (String) value;
|
||||
logger.info("Setting address " + this.id + " to " + string);
|
||||
// this.plc.notify(this.id, string);
|
||||
}
|
||||
}
|
|
@ -139,6 +139,8 @@ public class PCF8574InputConnection extends PlcConnection {
|
|||
if (gpioController.getProvisionedPins().stream().map(GpioPin::getPin).anyMatch(interruptPin::equals))
|
||||
throw new IllegalStateException("Pin " + interruptPin + " is already provisioned!");
|
||||
this.interruptGpioPin = gpioController.provisionDigitalInputPin(interruptPin, this.interruptResistance);
|
||||
logger.info("Provisioned GPIO Input pin " + this.interruptGpioPin + " with PinPullResistance "
|
||||
+ this.interruptResistance);
|
||||
this.interruptGpioPin.removeAllListeners();
|
||||
this.interruptGpioPin.addListener((GpioPinListenerDigital) this::handleInterrupt);
|
||||
|
||||
|
@ -165,6 +167,7 @@ public class PCF8574InputConnection extends PlcConnection {
|
|||
if (this.interruptGpioPin != null) {
|
||||
this.interruptGpioPin.removeAllListeners();
|
||||
PlcGpioController.getInstance().unprovisionPin(this.interruptGpioPin);
|
||||
logger.info("Provisioned GPIO Input pin " + this.interruptGpioPin);
|
||||
}
|
||||
|
||||
this.inputDevices = null;
|
||||
|
@ -193,6 +196,11 @@ public class PCF8574InputConnection extends PlcConnection {
|
|||
|
||||
for (int i = 0; i < this.inputDevices.length; i++) {
|
||||
I2CDevice i2CDevice = this.inputDevices[i];
|
||||
if (i2CDevice == null) {
|
||||
logger.warn("Ignoring invalid I2C Device 0x" + toHexString(this.addresses[i]));
|
||||
continue;
|
||||
}
|
||||
|
||||
byte data = (byte) i2CDevice.read();
|
||||
|
||||
if (this.verbose)
|
||||
|
@ -236,6 +244,7 @@ public class PCF8574InputConnection extends PlcConnection {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
ok = false;
|
||||
this.inputDevices[i] = null;
|
||||
logger.error("Failed to read initial state for address 0x" + toHexString((byte) i2CDevice.getAddress()),
|
||||
e);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package li.strolch.plc.core;
|
|||
|
||||
import static li.strolch.plc.model.PlcConstants.PARAM_VALUE;
|
||||
import static li.strolch.plc.model.PlcConstants.TYPE_PLC_ADDRESS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -14,7 +16,6 @@ import li.strolch.plc.model.PlcState;
|
|||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -29,7 +30,7 @@ public class PlcHandlerTest {
|
|||
private static Certificate cert;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
runtimeMock = new RuntimeMock().mockRuntime(TARGET_PATH, SRC_RUNTIME);
|
||||
runtimeMock.startContainer();
|
||||
cert = runtimeMock.loginAdmin();
|
||||
|
@ -47,33 +48,71 @@ public class PlcHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStartPlcHandler() throws InterruptedException {
|
||||
public void shouldStartPlcHandler() {
|
||||
|
||||
PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class);
|
||||
Assert.assertEquals(PlcState.Started, plcHandler.getPlcState());
|
||||
assertEquals(PlcState.Started, plcHandler.getPlcState());
|
||||
|
||||
PlcConnection loggerOutput = plcHandler.getPlc().getConnection("loggerOutput");
|
||||
Assert.assertEquals(ConnectionState.Connected, loggerOutput.getState());
|
||||
assertEquals(ConnectionState.Connected, loggerOutput.getState());
|
||||
|
||||
PlcConnection barcodeReader = plcHandler.getPlc().getConnection("barcodeReader");
|
||||
Assert.assertEquals(ConnectionState.Connected, barcodeReader.getState());
|
||||
assertEquals(ConnectionState.Connected, barcodeReader.getState());
|
||||
|
||||
String plcAddressId = plcHandler.getPlcAddressId("PLC", "Started");
|
||||
Assert.assertEquals("addrPlcStarted", plcAddressId);
|
||||
assertEquals("addrPlcStarted", plcAddressId);
|
||||
try (StrolchTransaction tx = runtimeMock.openUserTx(cert, true)) {
|
||||
Resource plcStartedAddr = tx.getResourceBy(TYPE_PLC_ADDRESS, plcAddressId, true);
|
||||
BooleanParameter valueP = plcStartedAddr.getParameter(PARAM_VALUE, true);
|
||||
Assert.assertEquals(true, valueP.getValue());
|
||||
assertEquals(true, valueP.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotifyPlcService() throws InterruptedException {
|
||||
public void shouldNotifyPlcService() {
|
||||
|
||||
PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class);
|
||||
AtomicReference<String> value = new AtomicReference<>("");
|
||||
plcHandler.registerListener("BarcodeReader", "Barcode", (address, v) -> value.set((String) v));
|
||||
plcHandler.send("BarcodeReader", "ReadBarcode", "DoRead");
|
||||
Assert.assertNotEquals("", value.get());
|
||||
assertNotEquals("", value.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendVirtualBoolean() {
|
||||
|
||||
PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class);
|
||||
String addressId = plcHandler.getPlcAddressId("PLC", "Running");
|
||||
AtomicReference<Boolean> value;
|
||||
try (StrolchTransaction tx = runtimeMock.openUserTx(cert, true)) {
|
||||
Resource address = tx.getResourceBy(TYPE_PLC_ADDRESS, addressId, true);
|
||||
value = new AtomicReference<>(address.getParameter(PARAM_VALUE, true).getValue());
|
||||
}
|
||||
assertEquals(false, value.get());
|
||||
|
||||
plcHandler.registerListener("PLC", "Running", (address, v) -> value.set((Boolean) v));
|
||||
plcHandler.send("PLC", "Running");
|
||||
assertEquals(true, value.get());
|
||||
plcHandler.send("PLC", "NotRunning");
|
||||
assertEquals(false, value.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendVirtualString() {
|
||||
|
||||
PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class);
|
||||
String addressId = plcHandler.getPlcAddressId("Server", "Connected");
|
||||
AtomicReference<String> value;
|
||||
try (StrolchTransaction tx = runtimeMock.openUserTx(cert, true)) {
|
||||
Resource address = tx.getResourceBy(TYPE_PLC_ADDRESS, addressId, true);
|
||||
value = new AtomicReference<>(address.getParameter(PARAM_VALUE, true).getValue());
|
||||
}
|
||||
assertEquals("Disconnected", value.get());
|
||||
|
||||
plcHandler.registerListener("Server", "Connected", (address, v) -> value.set((String) v));
|
||||
plcHandler.send("Server", "Connected", "Connected");
|
||||
assertEquals("Connected", value.get());
|
||||
plcHandler.send("Server", "Connected", "Disconnected");
|
||||
assertEquals("Disconnected", value.get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,26 +14,6 @@
|
|||
</ParameterBag>
|
||||
</Resource>
|
||||
|
||||
<!--
|
||||
Virtual connections
|
||||
-->
|
||||
<Resource Id="virtualString" Name="Virtual String PLC Connection" Type="PlcConnection">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="className" Name="Connection Class" Type="String" Value="li.strolch.plc.core.hw.connections.VirtualStringValueConnection"/>
|
||||
<Parameter Id="state" Name="Connection State" Type="String" Interpretation="Enumeration" Uom="ConnectionState" Value="Disconnected"/>
|
||||
<Parameter Id="stateMsg" Name="Connection State Msg" Type="String" Interpretation="Enumeration" Uom="ConnectionState"
|
||||
Value=""/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="virtualBoolean" Name="Virtual Boolean PLC Connection" Type="PlcConnection">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="className" Name="Connection Class" Type="String" Value="li.strolch.plc.core.hw.connections.VirtualBooleanValueConnection"/>
|
||||
<Parameter Id="state" Name="Connection State" Type="String" Interpretation="Enumeration" Uom="ConnectionState" Value="Disconnected"/>
|
||||
<Parameter Id="stateMsg" Name="Connection State Msg" Type="String" Interpretation="Enumeration" Uom="ConnectionState"
|
||||
Value=""/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
|
||||
<!--
|
||||
Barcode reader connection, currently place holder with RandomString
|
||||
-->
|
||||
|
@ -98,20 +78,92 @@
|
|||
</ParameterBag>
|
||||
<ParameterBag Id="relations" Name="Relations" Type="Relations">
|
||||
<Parameter Id="addresses" Name="Addresses" Type="StringList" Interpretation="Resource-Ref" Uom="PlcAddress"
|
||||
Value="addrPlcStarted"/>
|
||||
Value="addrPlcStarted, addrPlcRunning, addrServerConnected"/>
|
||||
<Parameter Id="telegrams" Name="Telegrams" Type="StringList" Interpretation="Resource-Ref" Uom="PlcTelegram"
|
||||
Value=""/>
|
||||
Value="telPlcStarted, telPlcStopped, telPlcRunning, telPlcNotRunning, telServerConnected, telServerDisconnected"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="addrPlcStarted" Name="PLC - Started" Type="PlcAddress">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean"/>
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.plcStarted"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="PLC"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Started"/>
|
||||
<Parameter Id="value" Name="Value" Type="Boolean" Value="false"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="telPlcStarted" Name="PLC - Started" Type="PlcTelegram">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.plcStarted"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="PLC"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Started"/>
|
||||
<Parameter Id="value" Name="Value" Type="Boolean" Value="true"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="telPlcStopped" Name="PLC - Stopped" Type="PlcTelegram">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.plcStarted"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="PLC"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Stopped"/>
|
||||
<Parameter Id="value" Name="Value" Type="Boolean" Value="false"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="addrPlcRunning" Name="PLC - Running" Type="PlcAddress">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.plcRunning"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="PLC"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Running"/>
|
||||
<Parameter Id="value" Name="Value" Type="Boolean" Value="false"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="telPlcRunning" Name="PLC - Running" Type="PlcTelegram">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.plcRunning"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="PLC"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Running"/>
|
||||
<Parameter Id="value" Name="Value" Type="Boolean" Value="true"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="telPlcNotRunning" Name="PLC - NotRunning" Type="PlcTelegram">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.plcRunning"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="PLC"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="NotRunning"/>
|
||||
<Parameter Id="value" Name="Value" Type="Boolean" Value="false"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="addrServerConnected" Name="Server - Connected" Type="PlcAddress">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.serverConnected"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="Server"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Connected"/>
|
||||
<Parameter Id="value" Name="Value" Type="String" Value="Disconnected"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="telServerConnected" Name="Server - Connected" Type="PlcTelegram">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.serverConnected"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="Server"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Connected"/>
|
||||
<Parameter Id="value" Name="Value" Type="String" Value="Connected"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Resource Id="telServerDisconnected" Name="Server - Disconnected" Type="PlcTelegram">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="address" Name="HW Address" Type="String" Interpretation="PlcConnection" Value="virtualBoolean.serverConnected"/>
|
||||
<Parameter Id="resource" Name="Resource ID for PlcAddress" Type="String" Value="Server"/>
|
||||
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Disconnected"/>
|
||||
<Parameter Id="value" Name="Value" Type="String" Value="Disconnected"/>
|
||||
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
|
||||
<!--
|
||||
BarcodeReader
|
||||
|
|
|
@ -44,6 +44,8 @@ public class PlcGwClientHandler extends StrolchComponent {
|
|||
private static final long RETRY_DELAY = 30;
|
||||
private static final int INITIAL_DELAY = 10;
|
||||
|
||||
private boolean verbose;
|
||||
|
||||
private String plcId;
|
||||
private String gwUsername;
|
||||
private String gwPassword;
|
||||
|
@ -67,6 +69,7 @@ public class PlcGwClientHandler extends StrolchComponent {
|
|||
@Override
|
||||
public void initialize(ComponentConfiguration configuration) throws Exception {
|
||||
|
||||
this.verbose = configuration.getBoolean("verbose", false);
|
||||
this.plcId = configuration.getString("plcId", null);
|
||||
this.gwUsername = configuration.getString("gwUsername", null);
|
||||
this.gwPassword = configuration.getString("gwPassword", null);
|
||||
|
@ -286,6 +289,7 @@ public class PlcGwClientHandler extends StrolchComponent {
|
|||
|
||||
try {
|
||||
sendDataToClient(notificationJ);
|
||||
if (this.verbose)
|
||||
logger.info("Sent notification for " + plcAddress.resource + "-" + plcAddress.action + " to server");
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to send notification to server", e);
|
||||
|
@ -293,7 +297,7 @@ public class PlcGwClientHandler extends StrolchComponent {
|
|||
}
|
||||
|
||||
public void onWsMessage(Session session, String message) {
|
||||
logger.info(session.getId() + ": Handling message");
|
||||
//logger.info(session.getId() + ": Handling message");
|
||||
|
||||
JsonObject jsonObject = new JsonParser().parse(message).getAsJsonObject();
|
||||
if (!jsonObject.has(PARAM_MESSAGE_TYPE)) {
|
||||
|
|
|
@ -204,7 +204,7 @@ public class PlcGwServerHandler extends StrolchComponent {
|
|||
}
|
||||
|
||||
public void onWsMessage(String message, Session session) {
|
||||
logger.info(session.getId() + ": Handling message");
|
||||
//logger.info(session.getId() + ": Handling message");
|
||||
|
||||
JsonObject jsonObject = new JsonParser().parse(message).getAsJsonObject();
|
||||
if (!jsonObject.has(PARAM_MESSAGE_TYPE))
|
||||
|
|
Loading…
Reference in New Issue