Search in sources :

Example 11 with StringValue

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

the class SnmpDevice method readChannelGroup.

/**
 * Read all the channels of the device at once.
 *
 * @param device
 * @param containers
 * @param timeout
 * @return Object
 * @throws ConnectionException
 */
private Object readChannelGroup(List<ChannelRecordContainer> containers, int timeout) throws ConnectionException {
    new Date().getTime();
    List<String> oids = new ArrayList<>();
    for (ChannelRecordContainer container : containers) {
        if (getDeviceAddress().equalsIgnoreCase(container.getChannel().getDeviceAddress())) {
            oids.add(container.getChannelAddress());
        }
    }
    Map<String, String> values;
    try {
        values = getRequestsList(oids);
        long receiveTime = System.currentTimeMillis();
        for (ChannelRecordContainer container : containers) {
            // make sure the value exists for corresponding channel
            if (values.get(container.getChannelAddress()) != null) {
                logger.debug("{}: value = '{}'", container.getChannelAddress(), values.get(container.getChannelAddress()));
                container.setRecord(new Record(new StringValue(values.get(container.getChannelAddress())), receiveTime));
            }
        }
    } catch (SnmpTimeoutException e) {
        for (ChannelRecordContainer container : containers) {
            container.setRecord(new Record(Flag.TIMEOUT));
        }
    }
    return null;
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) ArrayList(java.util.ArrayList) Record(org.openmuc.framework.data.Record) OctetString(org.snmp4j.smi.OctetString) StringValue(org.openmuc.framework.data.StringValue) Date(java.util.Date)

Example 12 with StringValue

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

the class OpcChannel method setValue.

@Override
public void setValue(AttributeContext context, VariableNode node, DataValue value) throws UaException {
    Variant variant = value.getValue();
    Record record = null;
    switch(getValueType()) {
        case BOOLEAN:
            record = new Record(new BooleanValue((Boolean) variant.getValue()), value.getServerTime().getUtcTime());
            break;
        case BYTE:
            record = new Record(new ByteValue((Byte) variant.getValue()), value.getServerTime().getUtcTime());
            break;
        case SHORT:
            record = new Record(new ShortValue((Short) variant.getValue()), value.getServerTime().getUtcTime());
            break;
        case INTEGER:
            record = new Record(new IntValue((Integer) variant.getValue()), value.getServerTime().getUtcTime());
            break;
        case LONG:
            record = new Record(new LongValue((Long) variant.getValue()), value.getServerTime().getUtcTime());
            break;
        case FLOAT:
            record = new Record(new FloatValue((Float) variant.getValue()), value.getServerTime().getUtcTime());
            break;
        case DOUBLE:
            record = new Record(new DoubleValue((Double) variant.getValue()), value.getServerTime().getUtcTime());
            break;
        default:
            record = new Record(new StringValue((String) variant.getValue()), value.getServerTime().getUtcTime());
            break;
    }
    setRecord(record);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ByteValue(org.openmuc.framework.data.ByteValue) ShortValue(org.openmuc.framework.data.ShortValue) DoubleValue(org.openmuc.framework.data.DoubleValue) BooleanValue(org.openmuc.framework.data.BooleanValue) LongValue(org.openmuc.framework.data.LongValue) Record(org.openmuc.framework.data.Record) FloatValue(org.openmuc.framework.data.FloatValue) StringValue(org.openmuc.framework.data.StringValue) IntValue(org.openmuc.framework.data.IntValue)

Example 13 with StringValue

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

the class SmlConnection method convertEntryToScanInfo.

private static ChannelScanInfo convertEntryToScanInfo(SmlListEntry entry) {
    String channelAddress = convertBytesToHexString(entry.getObjName().getValue());
    ValueContainer valueContainer = extractValueOf(entry);
    Value value = valueContainer.value;
    String description = MessageFormat.format("Current value: {0} {1}", value, entry.getUnit());
    ValueType valueType = valueContainer.valueType;
    Integer valueTypeLength = null;
    if (value != null) {
        if (valueType == ValueType.STRING) {
            String stringValue = value.asString();
            valueTypeLength = stringValue.length();
        } else if (valueType == ValueType.BYTE_ARRAY) {
            byte[] byteValue = value.asByteArray();
            valueTypeLength = byteValue.length;
        }
    }
    boolean readable = true;
    boolean writable = false;
    return new ChannelScanInfo(channelAddress, description, valueType, valueTypeLength, readable, writable);
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ValueType(org.openmuc.framework.data.ValueType) StringValue(org.openmuc.framework.data.StringValue) Value(org.openmuc.framework.data.Value) DoubleValue(org.openmuc.framework.data.DoubleValue) OctetString(org.openmuc.jsml.structures.OctetString)

Example 14 with StringValue

use of org.openmuc.framework.data.StringValue 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 15 with StringValue

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

the class SimpleDemoApp method updateEvStatusChannel.

/**
 * Checks if the electric vehicle is charging (Demonstrates how to access a value from a channel and how to set a
 * value/record)
 */
private void updateEvStatusChannel() {
    double evPower;
    String status = "idle";
    // get current value of the electric vehicle power channel
    Record lastRecord = chPowerElecticVehicle.getLatestRecord();
    if (lastRecord != null) {
        Value value = lastRecord.getValue();
        if (value != null) {
            evPower = chPowerElecticVehicle.getLatestRecord().getValue().asDouble();
            if (evPower > STANDBY_POWER_CHARGING_STATION) {
                status = "charging";
            }
            // set value for virtual channel
            Record newRecord = new Record(new StringValue(status), System.currentTimeMillis(), Flag.VALID);
            chEvStatus.setLatestRecord(newRecord);
        }
    }
}
Also used : DoubleValue(org.openmuc.framework.data.DoubleValue) StringValue(org.openmuc.framework.data.StringValue) Value(org.openmuc.framework.data.Value) Record(org.openmuc.framework.data.Record) StringValue(org.openmuc.framework.data.StringValue)

Aggregations

StringValue (org.openmuc.framework.data.StringValue)15 DoubleValue (org.openmuc.framework.data.DoubleValue)13 Record (org.openmuc.framework.data.Record)10 BooleanValue (org.openmuc.framework.data.BooleanValue)8 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)8 ByteValue (org.openmuc.framework.data.ByteValue)7 FloatValue (org.openmuc.framework.data.FloatValue)7 IntValue (org.openmuc.framework.data.IntValue)7 LongValue (org.openmuc.framework.data.LongValue)7 ShortValue (org.openmuc.framework.data.ShortValue)7 Value (org.openmuc.framework.data.Value)5 ArrayList (java.util.ArrayList)3 ValueType (org.openmuc.framework.data.ValueType)2 LoggingRecord (org.openmuc.framework.datalogger.spi.LoggingRecord)2 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 OctetString (org.openmuc.jsml.structures.OctetString)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)1