use of org.apache.plc4x.java.spi.values.PlcStruct in project plc4x by apache.
the class KnxNetIpProtocolLogic method processCemiData.
protected void processCemiData(KnxAddress sourceAddress, byte[] destinationGroupAddress, byte firstByte, byte[] restBytes) throws ParseException {
// The first byte is actually just 6 bit long, but we'll treat it as a full one.
// So here we create a byte array containing the first and all the following bytes.
byte[] payload = new byte[1 + restBytes.length];
payload[0] = firstByte;
System.arraycopy(restBytes, 0, payload, 1, restBytes.length);
// Decode the group address depending on the project settings.
ReadBuffer addressBuffer = new ReadBufferByteBased(destinationGroupAddress);
final KnxGroupAddress knxGroupAddress = KnxGroupAddress.staticParse(addressBuffer, knxNetIpDriverContext.getGroupAddressType());
final String destinationAddress = toString(knxGroupAddress);
// If there is an ETS5 model provided, continue decoding the payload.
if (knxNetIpDriverContext.getEts5Model() != null) {
final Ets5Model ets5Model = knxNetIpDriverContext.getEts5Model();
final GroupAddress groupAddress = ets5Model.getGroupAddresses().get(destinationAddress);
final String areaName = ets5Model.getTopologyName(destinationAddress.substring(0, destinationAddress.indexOf('/')));
final String lineName = ets5Model.getTopologyName(destinationAddress.substring(0, destinationAddress.indexOf('/', destinationAddress.indexOf('/') + 1)));
if ((groupAddress != null) && (groupAddress.getType() != null)) {
LOGGER.trace(String.format("Message from: '%s' to: '%s'", toString(sourceAddress), destinationAddress));
// Parse the payload depending on the type of the group-address.
ReadBuffer rawDataReader = new ReadBufferByteBased(payload);
final PlcValue value = KnxDatapoint.staticParse(rawDataReader, groupAddress.getType());
// Assemble the plc4x return data-structure.
Map<String, PlcValue> dataPointMap = new HashMap<>();
dataPointMap.put("sourceAddress", new PlcSTRING(toString(sourceAddress)));
dataPointMap.put("targetAddress", new PlcSTRING(groupAddress.getGroupAddress()));
if (groupAddress.getFunction() != null) {
dataPointMap.put("location", new PlcSTRING(groupAddress.getFunction().getSpaceName()));
dataPointMap.put("function", new PlcSTRING(groupAddress.getFunction().getName()));
} else {
dataPointMap.put("location", null);
dataPointMap.put("function", null);
}
if (areaName != null) {
dataPointMap.put("area", new PlcSTRING(areaName));
}
if (lineName != null) {
dataPointMap.put("line", new PlcSTRING(lineName));
}
dataPointMap.put("description", new PlcSTRING(groupAddress.getName()));
dataPointMap.put("unitOfMeasurement", new PlcSTRING(groupAddress.getType().getName()));
dataPointMap.put("value", value);
final PlcStruct dataPoint = new PlcStruct(dataPointMap);
// Send the data-structure.
publishEvent(groupAddress, dataPoint);
} else {
LOGGER.warn(String.format("Message from: '%s' to unknown group address: '%s'%n payload: '%s'", toString(sourceAddress), destinationAddress, Hex.encodeHexString(payload)));
}
} else // Else just output the raw payload.
{
LOGGER.info(String.format("Raw Message: '%s' to: '%s'%n payload: '%s'", KnxNetIpProtocolLogic.toString(sourceAddress), destinationAddress, Hex.encodeHexString(payload)));
}
}
use of org.apache.plc4x.java.spi.values.PlcStruct in project plc4x by apache.
the class DefaultPlcReadResponse method getAsPlcValue.
@Override
@JsonIgnore
public PlcValue getAsPlcValue() {
Map<String, PlcValue> structMap = new HashMap<>();
for (String fieldName : request.getFieldNames()) {
PlcValue plcValue = getPlcValue(fieldName);
structMap.put(fieldName, plcValue);
}
return new PlcStruct(structMap);
}
use of org.apache.plc4x.java.spi.values.PlcStruct in project plc4x by apache.
the class PassiveBacNetIpDriverManual method main.
public static void main(String[] args) throws Exception {
final BacNetIpDriver driver = new BacNetIpDriver();
final PlcConnection connection = driver.getConnection("bacnet-ip:pcap:///Users/christofer.dutz/Projects/Apache/PLC4X-Documents/BacNET/Merck/Captures/BACnet.pcapng?ede-directory-path=/Users/christofer.dutz/Projects/Apache/PLC4X-Documents/BacNET/Merck/EDE-Files");
connection.connect();
final PlcSubscriptionResponse subscriptionResponse = connection.subscriptionRequestBuilder().addEventField("Hurz", "*/*/*").build().execute().get();
subscriptionResponse.getSubscriptionHandle("Hurz").register(plcSubscriptionEvent -> {
PlcStruct plcStruct = (PlcStruct) ((DefaultPlcSubscriptionEvent) plcSubscriptionEvent).getValues().get("event").getValue();
System.out.println(plcStruct);
});
}
use of org.apache.plc4x.java.spi.values.PlcStruct in project plc4x by apache.
the class PassiveBacNetIpDriver2Manual method main.
public static void main(String[] args) throws Exception {
String tempDirectory = FileUtils.getTempDirectoryPath();
File pcapFile = FileSystems.getDefault().getPath(tempDirectory, "bacnet-stack-services.cap").toFile();
if (!pcapFile.exists())
FileUtils.copyURLToFile(new URL("https://wiki.wireshark.org/Protocols/bacnet?action=AttachFile&do=get&target=bacnet-stack-services.cap"), pcapFile);
final BacNetIpDriver driver = new BacNetIpDriver();
final PlcConnection connection = driver.getConnection("bacnet-ip:pcap://" + pcapFile.getAbsolutePath());
connection.connect();
final PlcSubscriptionResponse subscriptionResponse = connection.subscriptionRequestBuilder().addEventField("Hurz", "*/*/*").build().execute().get();
subscriptionResponse.getSubscriptionHandle("Hurz").register(plcSubscriptionEvent -> {
PlcStruct plcStruct = (PlcStruct) ((DefaultPlcSubscriptionEvent) plcSubscriptionEvent).getValues().get("event").getValue();
System.out.println(plcStruct);
});
}
use of org.apache.plc4x.java.spi.values.PlcStruct in project plc4x by apache.
the class PassiveBacNetIpDriver3Manual method main.
public static void main(String[] args) throws Exception {
String tempDirectory = FileUtils.getTempDirectoryPath();
File pcapFile = FileSystems.getDefault().getPath(tempDirectory, "bo_command_failure_original.pcap").toFile();
if (!pcapFile.exists())
FileUtils.copyURLToFile(new URL("http://kargs.net/captures/bo_command_failure_original.pcap"), pcapFile);
final BacNetIpDriver driver = new BacNetIpDriver();
try (final PlcConnection connection = driver.getConnection("bacnet-ip:pcap://" + pcapFile.getAbsolutePath() + "?filter=udp%20port%2047808")) {
connection.connect();
final PlcSubscriptionResponse subscriptionResponse = connection.subscriptionRequestBuilder().addEventField("Hurz", "*/*/*").build().execute().get();
subscriptionResponse.getSubscriptionHandle("Hurz").register(plcSubscriptionEvent -> {
PlcStruct plcStruct = (PlcStruct) ((DefaultPlcSubscriptionEvent) plcSubscriptionEvent).getValues().get("event").getValue();
System.out.println(plcStruct);
});
TimeUnit.SECONDS.sleep(3);
}
}
Aggregations