Search in sources :

Example 11 with FloatValue

use of org.openmuc.framework.data.FloatValue in project OpenMUC by isc-konstanz.

the class Options method parseValue.

public static Value parseValue(ValueType type, String valueStr) throws ArgumentSyntaxException {
    Value value;
    switch(type) {
        case DOUBLE:
            value = new DoubleValue(Double.valueOf(valueStr));
            break;
        case FLOAT:
            value = new FloatValue(Float.valueOf(valueStr));
            break;
        case INTEGER:
            value = new IntValue(Integer.valueOf(valueStr));
            break;
        case LONG:
            value = new LongValue(Long.valueOf(valueStr));
            break;
        case SHORT:
            value = new ShortValue(Short.valueOf(valueStr));
            break;
        case BYTE:
            value = new ByteValue(Byte.valueOf(valueStr));
            break;
        case BOOLEAN:
            value = new BooleanValue(Boolean.valueOf(valueStr));
            break;
        case BYTE_ARRAY:
            byte[] arr;
            if (!valueStr.startsWith("0x")) {
                arr = valueStr.getBytes(StandardCharsets.US_ASCII);
            } else {
                try {
                    arr = OptionValue.hexToBytes(valueStr.substring(2).trim());
                } catch (IllegalArgumentException e) {
                    throw new ArgumentSyntaxException("Unable to parse value as byte array: " + valueStr);
                }
            }
            value = new ByteArrayValue(arr);
            break;
        case STRING:
            value = new StringValue(valueStr);
            break;
        default:
            throw new ArgumentSyntaxException("Parameter value type not configured: " + type.name().toLowerCase());
    }
    return value;
}
Also used : ByteValue(org.openmuc.framework.data.ByteValue) ShortValue(org.openmuc.framework.data.ShortValue) DoubleValue(org.openmuc.framework.data.DoubleValue) BooleanValue(org.openmuc.framework.data.BooleanValue) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) StringValue(org.openmuc.framework.data.StringValue) Value(org.openmuc.framework.data.Value) FloatValue(org.openmuc.framework.data.FloatValue) DoubleValue(org.openmuc.framework.data.DoubleValue) ByteValue(org.openmuc.framework.data.ByteValue) ShortValue(org.openmuc.framework.data.ShortValue) BooleanValue(org.openmuc.framework.data.BooleanValue) LongValue(org.openmuc.framework.data.LongValue) IntValue(org.openmuc.framework.data.IntValue) LongValue(org.openmuc.framework.data.LongValue) FloatValue(org.openmuc.framework.data.FloatValue) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) StringValue(org.openmuc.framework.data.StringValue) IntValue(org.openmuc.framework.data.IntValue) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 12 with FloatValue

use of org.openmuc.framework.data.FloatValue in project OpenMUC by isc-konstanz.

the class ModbusDriverUtil method getValueFromByteArray.

@SuppressWarnings("deprecation")
public static Value getValueFromByteArray(byte[] registerAsByteArray, DataType datatype) {
    Value registerValue = null;
    switch(datatype) {
        // break;
        case SHORT:
        case INT16:
            registerValue = new ShortValue(ModbusUtil.registerToShort(registerAsByteArray));
            break;
        case INT32:
            registerValue = new IntValue(ModbusUtil.registersToInt(registerAsByteArray));
            break;
        // break;
        case UINT16:
            // TODO might need both: big/little endian support in settings
            // int uint16 = DatatypeConversion.bytes_To_UnsignedInt16(registerAsByteArray,
            // EndianInput.BYTES_ARE_BIG_ENDIAN);
            // registerValue = new IntValue(uint16);
            registerValue = new IntValue(ModbusUtil.registerToUnsignedShort(registerAsByteArray));
            break;
        case UINT32:
            // TODO might need both: big/little endian support in settings
            long uint32 = DataTypeConverter.bytesToUnsignedInt32(registerAsByteArray, EndianInput.BYTES_ARE_BIG_ENDIAN);
            registerValue = new LongValue(uint32);
            break;
        case FLOAT:
            registerValue = new FloatValue(ModbusUtil.registersToFloat(registerAsByteArray));
            break;
        case DOUBLE:
            registerValue = new DoubleValue(ModbusUtil.registersToDouble(registerAsByteArray));
            break;
        case LONG:
            registerValue = new LongValue(ModbusUtil.registersToLong(registerAsByteArray));
            break;
        case BYTEARRAY:
            registerValue = new ByteArrayValue(registerAsByteArray);
            break;
        case BYTEARRAYLONG:
            registerValue = new LongValue(DataTypeConverter.bytesToSignedInt64(registerAsByteArray, EndianInput.BYTES_ARE_LITTLE_ENDIAN));
            break;
        // break;
        default:
            throw new RuntimeException("Datatype " + datatype.toString() + " not supported yet");
    }
    return registerValue;
}
Also used : ShortValue(org.openmuc.framework.data.ShortValue) DoubleValue(org.openmuc.framework.data.DoubleValue) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) DoubleValue(org.openmuc.framework.data.DoubleValue) ShortValue(org.openmuc.framework.data.ShortValue) Value(org.openmuc.framework.data.Value) BooleanValue(org.openmuc.framework.data.BooleanValue) LongValue(org.openmuc.framework.data.LongValue) FloatValue(org.openmuc.framework.data.FloatValue) IntValue(org.openmuc.framework.data.IntValue) LongValue(org.openmuc.framework.data.LongValue) FloatValue(org.openmuc.framework.data.FloatValue) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) IntValue(org.openmuc.framework.data.IntValue)

Aggregations

FloatValue (org.openmuc.framework.data.FloatValue)12 DoubleValue (org.openmuc.framework.data.DoubleValue)11 IntValue (org.openmuc.framework.data.IntValue)11 LongValue (org.openmuc.framework.data.LongValue)11 ShortValue (org.openmuc.framework.data.ShortValue)11 BooleanValue (org.openmuc.framework.data.BooleanValue)10 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)8 ByteValue (org.openmuc.framework.data.ByteValue)8 StringValue (org.openmuc.framework.data.StringValue)8 Record (org.openmuc.framework.data.Record)7 Value (org.openmuc.framework.data.Value)5 ArrayList (java.util.ArrayList)2 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 ServerModel (com.beanit.iec61850bean.ServerModel)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)1 Test (org.junit.jupiter.api.Test)1 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)1 ParseException (org.openmuc.framework.config.ParseException)1