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;
}
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;
}
Aggregations