[New] Implemented implicit virtual connections and added verbose logging

This commit is contained in:
Robert von Burg 2020-02-05 22:59:48 +01:00
parent c83b387e7d
commit d0adc91e4b
10 changed files with 201 additions and 88 deletions

View File

@ -36,6 +36,7 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
private MapOfMaps<String, String, PlcAddress> plcTelegrams; private MapOfMaps<String, String, PlcAddress> plcTelegrams;
private Map<PlcAddress, String> addressesToResourceId; private Map<PlcAddress, String> addressesToResourceId;
private PlcListener globalListener; private PlcListener globalListener;
private boolean verbose;
public DefaultPlcHandler(ComponentContainer container, String componentName) { public DefaultPlcHandler(ComponentContainer container, String componentName) {
super(container, componentName); super(container, componentName);
@ -86,6 +87,7 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
this.plcAddresses = new MapOfMaps<>(); this.plcAddresses = new MapOfMaps<>();
this.plcTelegrams = new MapOfMaps<>(); this.plcTelegrams = new MapOfMaps<>();
this.addressesToResourceId = new HashMap<>(); this.addressesToResourceId = new HashMap<>();
this.verbose = configuration.getBoolean("verbose", false);
super.initialize(configuration); super.initialize(configuration);
} }
@ -136,6 +138,7 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
MapOfMaps<String, String, PlcAddress> plcTelegrams = new MapOfMaps<>(); MapOfMaps<String, String, PlcAddress> plcTelegrams = new MapOfMaps<>();
Map<PlcAddress, String> addressesToResourceId = new HashMap<>(); Map<PlcAddress, String> addressesToResourceId = new HashMap<>();
this.plc = configure(validateCtx(), plcAddresses, plcTelegrams, addressesToResourceId); this.plc = configure(validateCtx(), plcAddresses, plcTelegrams, addressesToResourceId);
this.plc.setVerbose(this.verbose);
this.plcAddresses = plcAddresses; this.plcAddresses = plcAddresses;
this.plcTelegrams = plcTelegrams; this.plcTelegrams = plcTelegrams;
this.addressesToResourceId = addressesToResourceId; this.addressesToResourceId = addressesToResourceId;
@ -199,7 +202,9 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
} }
private void updatePlcAddress(PlcAddress address, Object value) { private void updatePlcAddress(PlcAddress address, Object value) {
long s = nanoTime(); long s = 0L;
if (this.verbose)
s = nanoTime();
String addressId = this.addressesToResourceId.get(address); String addressId = this.addressesToResourceId.get(address);
if (addressId == null) { if (addressId == null) {
@ -213,13 +218,13 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
Resource addressRes = tx.getResourceBy(TYPE_PLC_ADDRESS, addressId, true); Resource addressRes = tx.getResourceBy(TYPE_PLC_ADDRESS, addressId, true);
// see if we need to invert a boolean flag // 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); value = !((boolean) value);
}
Parameter<?> valueP = addressRes.getParameter(PARAM_VALUE, true); Parameter<?> valueP = addressRes.getParameter(PARAM_VALUE, true);
logger.info("PlcAddress {}-{} has changed from {} to {}", address.resource, address.action, if (this.verbose)
valueP.getValue(), value); logger.info("PlcAddress {}-{} has changed from {} to {}", address.resource, address.action,
valueP.getValue(), value);
valueP.accept(new SetParameterValueVisitor(value)); valueP.accept(new SetParameterValueVisitor(value));
tx.update(addressRes); tx.update(addressRes);
@ -229,11 +234,14 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
logger.error("Failed to update PlcAddress " + addressId + " with new value " + value, e); logger.error("Failed to update PlcAddress " + addressId + " with new value " + value, e);
} }
logger.info("async update " + address.address + " took " + (formatNanoDuration(nanoTime() - s))); if (this.verbose)
logger.info("async update " + address.address + " took " + (formatNanoDuration(nanoTime() - s)));
} }
private void updateConnectionState(PlcConnection plcConnection) { private void updateConnectionState(PlcConnection plcConnection) {
long s = nanoTime(); long s = 0L;
if (this.verbose)
s = nanoTime();
try { try {
try (StrolchTransaction tx = openTx(validateCtx().getCertificate(), "updateConnectionState", false)) { try (StrolchTransaction tx = openTx(validateCtx().getCertificate(), "updateConnectionState", false)) {
@ -247,7 +255,8 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
logger.error("Failed to update state for connection " + plcConnection.getId(), e); logger.error("Failed to update state for connection " + plcConnection.getId(), e);
} }
logger.info("updateConnectionState took " + (formatNanoDuration(nanoTime() - s))); if (this.verbose)
logger.info("updateConnectionState took " + (formatNanoDuration(nanoTime() - s)));
} }
private PrivilegeContext validateCtx() { private PrivilegeContext validateCtx() {

View File

@ -22,6 +22,7 @@ public class DefaultPlc implements Plc {
private PlcListener globalListener; private PlcListener globalListener;
private MapOfLists<PlcAddress, PlcListener> listeners; private MapOfLists<PlcAddress, PlcListener> listeners;
private PlcConnectionStateChangeListener connectionStateChangeListener; private PlcConnectionStateChangeListener connectionStateChangeListener;
private boolean verbose;
public DefaultPlc() { public DefaultPlc() {
this.notificationMappings = new HashMap<>(); this.notificationMappings = new HashMap<>();
@ -30,6 +31,11 @@ public class DefaultPlc implements Plc {
this.connectionsByAddress = new HashMap<>(); this.connectionsByAddress = new HashMap<>();
} }
@Override
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
@Override @Override
public void setGlobalListener(PlcListener listener) { public void setGlobalListener(PlcListener listener) {
this.globalListener = listener; this.globalListener = listener;
@ -52,14 +58,15 @@ public class DefaultPlc implements Plc {
@Override @Override
public void notify(String address, Object value) { public void notify(String address, Object value) {
logger.info("Update for " + address + " with value " + value);
PlcAddress plcAddress = this.notificationMappings.get(address); PlcAddress plcAddress = this.notificationMappings.get(address);
if (plcAddress == null) { if (plcAddress == null) {
logger.warn("No mapping to PlcAddress for hwAddress " + address); logger.warn("No mapping to PlcAddress for hwAddress " + address);
return; return;
} }
logger.info("Update for {}-{} @ {} with value {}", plcAddress.resource, plcAddress.action, plcAddress.address,
value);
List<PlcListener> listeners = this.listeners.getList(plcAddress); List<PlcListener> listeners = this.listeners.getList(plcAddress);
if (listeners == null || listeners.isEmpty()) { if (listeners == null || listeners.isEmpty()) {
logger.warn("No listeners for key " + plcAddress); logger.warn("No listeners for key " + plcAddress);
@ -79,16 +86,19 @@ public class DefaultPlc implements Plc {
@Override @Override
public void send(PlcAddress plcAddress) { public void send(PlcAddress plcAddress) {
logger.info("Sending " + plcAddress.resource + "-" + plcAddress.action + ": " + plcAddress.defaultValue if (this.verbose)
+ " (default)"); logger.info("Sending {}-{}: {} (default)", plcAddress.resource, plcAddress.action, plcAddress.defaultValue);
validateConnection(plcAddress).send(plcAddress.address, plcAddress.defaultValue); if (!isVirtual(plcAddress))
validateConnection(plcAddress).send(plcAddress.address, plcAddress.defaultValue);
notify(plcAddress.address, plcAddress.defaultValue); notify(plcAddress.address, plcAddress.defaultValue);
} }
@Override @Override
public void send(PlcAddress plcAddress, Object value) { public void send(PlcAddress plcAddress, Object value) {
logger.info("Sending " + plcAddress.resource + "-" + plcAddress.action + ": " + value); if (this.verbose)
validateConnection(plcAddress).send(plcAddress.address, value); logger.info("Sending {}-{}: {}", plcAddress.resource, plcAddress.action, value);
if (!isVirtual(plcAddress))
validateConnection(plcAddress).send(plcAddress.address, value);
notify(plcAddress.address, value); notify(plcAddress.address, value);
} }
@ -154,18 +164,40 @@ public class DefaultPlc implements Plc {
@Override @Override
public void registerNotificationMapping(PlcAddress address) { 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( throw new IllegalStateException(
"There is no connection registered for address " + address.address + " for key " + address); "There is no connection registered for address " + address.address + " for key " + address);
logger.info("Registered address mapping for " + address);
if (address.type != PlcAddressType.Notification) if (address.type != PlcAddressType.Notification)
throw new IllegalArgumentException("Key must be of type " + PlcAddressType.Notification + ": " + address); throw new IllegalArgumentException("Key must be of type " + PlcAddressType.Notification + ": " + address);
PlcAddress replaced = this.notificationMappings.put(address.address, address); PlcAddress replaced = this.notificationMappings.put(address.address, address);
if (replaced != null) { if (replaced != null)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Replaced mapping for address " + address.address + " for key " + replaced + " with " + address); "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");
}
} }

View File

@ -31,4 +31,6 @@ public interface Plc {
void notifyConnectionStateChanged(PlcConnection connection); void notifyConnectionStateChanged(PlcConnection connection);
void setConnectionStateChangeListener(PlcConnectionStateChangeListener listener); void setConnectionStateChangeListener(PlcConnectionStateChangeListener listener);
void setVerbose(boolean verbose);
} }

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -139,6 +139,8 @@ public class PCF8574InputConnection extends PlcConnection {
if (gpioController.getProvisionedPins().stream().map(GpioPin::getPin).anyMatch(interruptPin::equals)) if (gpioController.getProvisionedPins().stream().map(GpioPin::getPin).anyMatch(interruptPin::equals))
throw new IllegalStateException("Pin " + interruptPin + " is already provisioned!"); throw new IllegalStateException("Pin " + interruptPin + " is already provisioned!");
this.interruptGpioPin = gpioController.provisionDigitalInputPin(interruptPin, this.interruptResistance); this.interruptGpioPin = gpioController.provisionDigitalInputPin(interruptPin, this.interruptResistance);
logger.info("Provisioned GPIO Input pin " + this.interruptGpioPin + " with PinPullResistance "
+ this.interruptResistance);
this.interruptGpioPin.removeAllListeners(); this.interruptGpioPin.removeAllListeners();
this.interruptGpioPin.addListener((GpioPinListenerDigital) this::handleInterrupt); this.interruptGpioPin.addListener((GpioPinListenerDigital) this::handleInterrupt);
@ -165,6 +167,7 @@ public class PCF8574InputConnection extends PlcConnection {
if (this.interruptGpioPin != null) { if (this.interruptGpioPin != null) {
this.interruptGpioPin.removeAllListeners(); this.interruptGpioPin.removeAllListeners();
PlcGpioController.getInstance().unprovisionPin(this.interruptGpioPin); PlcGpioController.getInstance().unprovisionPin(this.interruptGpioPin);
logger.info("Provisioned GPIO Input pin " + this.interruptGpioPin);
} }
this.inputDevices = null; this.inputDevices = null;
@ -193,6 +196,11 @@ public class PCF8574InputConnection extends PlcConnection {
for (int i = 0; i < this.inputDevices.length; i++) { for (int i = 0; i < this.inputDevices.length; i++) {
I2CDevice i2CDevice = this.inputDevices[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(); byte data = (byte) i2CDevice.read();
if (this.verbose) if (this.verbose)
@ -236,6 +244,7 @@ public class PCF8574InputConnection extends PlcConnection {
} }
} catch (Exception e) { } catch (Exception e) {
ok = false; ok = false;
this.inputDevices[i] = null;
logger.error("Failed to read initial state for address 0x" + toHexString((byte) i2CDevice.getAddress()), logger.error("Failed to read initial state for address 0x" + toHexString((byte) i2CDevice.getAddress()),
e); e);
} }

View File

@ -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.PARAM_VALUE;
import static li.strolch.plc.model.PlcConstants.TYPE_PLC_ADDRESS; 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; 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.privilege.model.Certificate;
import li.strolch.testbase.runtime.RuntimeMock; import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -29,7 +30,7 @@ public class PlcHandlerTest {
private static Certificate cert; private static Certificate cert;
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() {
runtimeMock = new RuntimeMock().mockRuntime(TARGET_PATH, SRC_RUNTIME); runtimeMock = new RuntimeMock().mockRuntime(TARGET_PATH, SRC_RUNTIME);
runtimeMock.startContainer(); runtimeMock.startContainer();
cert = runtimeMock.loginAdmin(); cert = runtimeMock.loginAdmin();
@ -47,33 +48,71 @@ public class PlcHandlerTest {
} }
@Test @Test
public void shouldStartPlcHandler() throws InterruptedException { public void shouldStartPlcHandler() {
PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class); PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class);
Assert.assertEquals(PlcState.Started, plcHandler.getPlcState()); assertEquals(PlcState.Started, plcHandler.getPlcState());
PlcConnection loggerOutput = plcHandler.getPlc().getConnection("loggerOutput"); PlcConnection loggerOutput = plcHandler.getPlc().getConnection("loggerOutput");
Assert.assertEquals(ConnectionState.Connected, loggerOutput.getState()); assertEquals(ConnectionState.Connected, loggerOutput.getState());
PlcConnection barcodeReader = plcHandler.getPlc().getConnection("barcodeReader"); PlcConnection barcodeReader = plcHandler.getPlc().getConnection("barcodeReader");
Assert.assertEquals(ConnectionState.Connected, barcodeReader.getState()); assertEquals(ConnectionState.Connected, barcodeReader.getState());
String plcAddressId = plcHandler.getPlcAddressId("PLC", "Started"); String plcAddressId = plcHandler.getPlcAddressId("PLC", "Started");
Assert.assertEquals("addrPlcStarted", plcAddressId); assertEquals("addrPlcStarted", plcAddressId);
try (StrolchTransaction tx = runtimeMock.openUserTx(cert, true)) { try (StrolchTransaction tx = runtimeMock.openUserTx(cert, true)) {
Resource plcStartedAddr = tx.getResourceBy(TYPE_PLC_ADDRESS, plcAddressId, true); Resource plcStartedAddr = tx.getResourceBy(TYPE_PLC_ADDRESS, plcAddressId, true);
BooleanParameter valueP = plcStartedAddr.getParameter(PARAM_VALUE, true); BooleanParameter valueP = plcStartedAddr.getParameter(PARAM_VALUE, true);
Assert.assertEquals(true, valueP.getValue()); assertEquals(true, valueP.getValue());
} }
} }
@Test @Test
public void shouldNotifyPlcService() throws InterruptedException { public void shouldNotifyPlcService() {
PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class); PlcHandler plcHandler = runtimeMock.getComponent(PlcHandler.class);
AtomicReference<String> value = new AtomicReference<>(""); AtomicReference<String> value = new AtomicReference<>("");
plcHandler.registerListener("BarcodeReader", "Barcode", (address, v) -> value.set((String) v)); plcHandler.registerListener("BarcodeReader", "Barcode", (address, v) -> value.set((String) v));
plcHandler.send("BarcodeReader", "ReadBarcode", "DoRead"); 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());
} }
} }

View File

@ -14,26 +14,6 @@
</ParameterBag> </ParameterBag>
</Resource> </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 Barcode reader connection, currently place holder with RandomString
--> -->
@ -98,20 +78,92 @@
</ParameterBag> </ParameterBag>
<ParameterBag Id="relations" Name="Relations" Type="Relations"> <ParameterBag Id="relations" Name="Relations" Type="Relations">
<Parameter Id="addresses" Name="Addresses" Type="StringList" Interpretation="Resource-Ref" Uom="PlcAddress" <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" <Parameter Id="telegrams" Name="Telegrams" Type="StringList" Interpretation="Resource-Ref" Uom="PlcTelegram"
Value=""/> Value="telPlcStarted, telPlcStopped, telPlcRunning, telPlcNotRunning, telServerConnected, telServerDisconnected"/>
</ParameterBag> </ParameterBag>
</Resource> </Resource>
<Resource Id="addrPlcStarted" Name="PLC - Started" Type="PlcAddress"> <Resource Id="addrPlcStarted" Name="PLC - Started" Type="PlcAddress">
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters"> <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="resource" Name="Resource ID for PlcAddress" Type="String" Value="PLC"/>
<Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Started"/> <Parameter Id="action" Name="Action ID for PlcAddress" Type="String" Value="Started"/>
<Parameter Id="value" Name="Value" Type="Boolean" Value="false"/> <Parameter Id="value" Name="Value" Type="Boolean" Value="false"/>
<Parameter Id="index" Name="Index" Type="Integer" Value="10"/> <Parameter Id="index" Name="Index" Type="Integer" Value="10"/>
</ParameterBag> </ParameterBag>
</Resource> </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 BarcodeReader

View File

@ -44,6 +44,8 @@ public class PlcGwClientHandler extends StrolchComponent {
private static final long RETRY_DELAY = 30; private static final long RETRY_DELAY = 30;
private static final int INITIAL_DELAY = 10; private static final int INITIAL_DELAY = 10;
private boolean verbose;
private String plcId; private String plcId;
private String gwUsername; private String gwUsername;
private String gwPassword; private String gwPassword;
@ -67,6 +69,7 @@ public class PlcGwClientHandler extends StrolchComponent {
@Override @Override
public void initialize(ComponentConfiguration configuration) throws Exception { public void initialize(ComponentConfiguration configuration) throws Exception {
this.verbose = configuration.getBoolean("verbose", false);
this.plcId = configuration.getString("plcId", null); this.plcId = configuration.getString("plcId", null);
this.gwUsername = configuration.getString("gwUsername", null); this.gwUsername = configuration.getString("gwUsername", null);
this.gwPassword = configuration.getString("gwPassword", null); this.gwPassword = configuration.getString("gwPassword", null);
@ -286,14 +289,15 @@ public class PlcGwClientHandler extends StrolchComponent {
try { try {
sendDataToClient(notificationJ); sendDataToClient(notificationJ);
logger.info("Sent notification for " + plcAddress.resource + "-" + plcAddress.action + " to server"); if (this.verbose)
logger.info("Sent notification for " + plcAddress.resource + "-" + plcAddress.action + " to server");
} catch (IOException e) { } catch (IOException e) {
logger.error("Failed to send notification to server", e); logger.error("Failed to send notification to server", e);
} }
} }
public void onWsMessage(Session session, String message) { 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(); JsonObject jsonObject = new JsonParser().parse(message).getAsJsonObject();
if (!jsonObject.has(PARAM_MESSAGE_TYPE)) { if (!jsonObject.has(PARAM_MESSAGE_TYPE)) {

View File

@ -204,7 +204,7 @@ public class PlcGwServerHandler extends StrolchComponent {
} }
public void onWsMessage(String message, Session session) { 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(); JsonObject jsonObject = new JsonParser().parse(message).getAsJsonObject();
if (!jsonObject.has(PARAM_MESSAGE_TYPE)) if (!jsonObject.has(PARAM_MESSAGE_TYPE))