All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.plc4x.java.abeth.readwrite.io.DF1RequestProtectedTypedLogicalReadIO Maven / Gradle / Ivy

Go to download

Implementation of a PLC4X driver able to speak using the Allen Bradley AB-ETH protocol.

There is a newer version: 0.12.0
Show newest version
/*
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
*/

package org.apache.plc4x.java.abeth.readwrite.io;

import org.apache.plc4x.java.abeth.readwrite.*;

import org.apache.plc4x.java.abeth.readwrite.types.*;
import org.apache.plc4x.java.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Supplier;

public class DF1RequestProtectedTypedLogicalReadIO {

    private static final Logger LOGGER = LoggerFactory.getLogger(DF1RequestProtectedTypedLogicalReadIO.class);

    public static DF1RequestProtectedTypedLogicalReadBuilder parse(ReadBuffer io) throws ParseException {
        int startPos = io.getPos();
        int curPos;

        // Simple Field (byteSize)
        short byteSize = io.readUnsignedShort(8);

        // Simple Field (fileNumber)
        short fileNumber = io.readUnsignedShort(8);

        // Simple Field (fileType)
        short fileType = io.readUnsignedShort(8);

        // Simple Field (elementNumber)
        short elementNumber = io.readUnsignedShort(8);

        // Simple Field (subElementNumber)
        short subElementNumber = io.readUnsignedShort(8);

        // Create the instance
        return new DF1RequestProtectedTypedLogicalReadBuilder(byteSize, fileNumber, fileType, elementNumber, subElementNumber);
    }

    public static void serialize(WriteBuffer io, DF1RequestProtectedTypedLogicalRead _value) throws ParseException {

        // Simple Field (byteSize)
        short byteSize = (short) _value.getByteSize();
        io.writeUnsignedShort(8, ((Number) (byteSize)).shortValue());

        // Simple Field (fileNumber)
        short fileNumber = (short) _value.getFileNumber();
        io.writeUnsignedShort(8, ((Number) (fileNumber)).shortValue());

        // Simple Field (fileType)
        short fileType = (short) _value.getFileType();
        io.writeUnsignedShort(8, ((Number) (fileType)).shortValue());

        // Simple Field (elementNumber)
        short elementNumber = (short) _value.getElementNumber();
        io.writeUnsignedShort(8, ((Number) (elementNumber)).shortValue());

        // Simple Field (subElementNumber)
        short subElementNumber = (short) _value.getSubElementNumber();
        io.writeUnsignedShort(8, ((Number) (subElementNumber)).shortValue());
    }

    private static int COUNT(Object obj) {
        if(obj.getClass().isArray()) {
            Object[] arr = (Object[]) obj;
            return arr.length;
        } else if(obj instanceof Collection) {
            Collection col = (Collection) obj;
            return col.size();
        }
        throw new RuntimeException("Unable to count object of type " + obj.getClass().getName());
    }

    private static  T CAST(Object obj, Class clazz) {
        try {
            return clazz.cast(obj);
        } catch(ClassCastException e) {
            throw new RuntimeException("Unable to cast object of type " + obj.getClass().getName() + " to " + clazz.getName());
        }
    }

    public static class DF1RequestProtectedTypedLogicalReadBuilder implements DF1RequestCommandIO.DF1RequestCommandBuilder {
        private final short byteSize;
        private final short fileNumber;
        private final short fileType;
        private final short elementNumber;
        private final short subElementNumber;

        public DF1RequestProtectedTypedLogicalReadBuilder(short byteSize, short fileNumber, short fileType, short elementNumber, short subElementNumber) {
            this.byteSize = byteSize;
            this.fileNumber = fileNumber;
            this.fileType = fileType;
            this.elementNumber = elementNumber;
            this.subElementNumber = subElementNumber;
        }

        public DF1RequestProtectedTypedLogicalRead build() {
            return new DF1RequestProtectedTypedLogicalRead(byteSize, fileNumber, fileType, elementNumber, subElementNumber);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy