Search in sources :

Example 1 with AdsSubscriptionHandle

use of org.apache.plc4x.java.ads.model.AdsSubscriptionHandle in project plc4x by apache.

the class AdsProtocolLogic method decode.

@Override
protected void decode(ConversationContext<AmsTCPPacket> context, AmsTCPPacket msg) throws Exception {
    if (msg.getUserdata().getData() instanceof AdsDeviceNotificationRequest) {
        AdsDeviceNotificationRequest notificationData = (AdsDeviceNotificationRequest) msg.getUserdata().getData();
        List<AdsStampHeader> stamps = notificationData.getAdsStampHeaders();
        for (AdsStampHeader stamp : stamps) {
            // convert Windows FILETIME format to unix epoch
            long unixEpochTimestamp = stamp.getTimestamp().divide(BigInteger.valueOf(10000L)).longValue() - 11644473600000L;
            List<AdsNotificationSample> samples = stamp.getAdsNotificationSamples();
            for (AdsNotificationSample sample : samples) {
                long handle = sample.getNotificationHandle();
                for (DefaultPlcConsumerRegistration registration : consumers.keySet()) {
                    for (PlcSubscriptionHandle subscriptionHandle : registration.getSubscriptionHandles()) {
                        if (subscriptionHandle instanceof AdsSubscriptionHandle) {
                            AdsSubscriptionHandle adsHandle = (AdsSubscriptionHandle) subscriptionHandle;
                            if (adsHandle.getNotificationHandle() == handle)
                                consumers.get(registration).accept(new DefaultPlcSubscriptionEvent(Instant.ofEpochMilli(unixEpochTimestamp), convertSampleToPlc4XResult(adsHandle, sample.getData())));
                        }
                    }
                }
            }
        }
    }
}
Also used : DefaultPlcConsumerRegistration(org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration) AdsSubscriptionHandle(org.apache.plc4x.java.ads.model.AdsSubscriptionHandle) PlcSubscriptionHandle(org.apache.plc4x.java.api.model.PlcSubscriptionHandle)

Aggregations

AdsSubscriptionHandle (org.apache.plc4x.java.ads.model.AdsSubscriptionHandle)1 PlcSubscriptionHandle (org.apache.plc4x.java.api.model.PlcSubscriptionHandle)1 DefaultPlcConsumerRegistration (org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration)1