Search in sources :

Example 6 with StringValue

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

the class OpenmucParserServiceImplTest method serializeStringValue.

@Test
void serializeStringValue() throws SerializationException {
    String controlString = "{\"timestamp\":1582722316,\"flag\":\"VALID\",\"value\":\"test\"}";
    Value doubleValue = new StringValue("test");
    long timestamp = 1582722316;
    Flag flag = Flag.VALID;
    Record record = new Record(doubleValue, timestamp, flag);
    byte[] serializedRecord = parserService.serialize(record, new SerializationContainerTest());
    String serializedJson = new String(serializedRecord);
    assertEquals(controlString, serializedJson);
}
Also used : ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) DoubleValue(org.openmuc.framework.data.DoubleValue) StringValue(org.openmuc.framework.data.StringValue) Value(org.openmuc.framework.data.Value) Record(org.openmuc.framework.data.Record) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord) StringValue(org.openmuc.framework.data.StringValue) Flag(org.openmuc.framework.data.Flag) Test(org.junit.jupiter.api.Test)

Example 7 with StringValue

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

the class OpcChannel method decode.

public Record decode(DataValue data) {
    long timestamp = data.getServerTime().getJavaTime();
    Object value = data.getValue().getValue();
    switch(getValueType()) {
        case BOOLEAN:
            return new Record(new BooleanValue((Boolean) value), timestamp);
        case BYTE:
            return new Record(new ByteValue((Byte) value), timestamp);
        case SHORT:
            return new Record(new ShortValue((Short) value), timestamp);
        case INTEGER:
            return new Record(new IntValue((Integer) value), timestamp);
        case LONG:
            return new Record(new LongValue((Long) value), timestamp);
        case FLOAT:
            return new Record(new FloatValue((Float) value), timestamp);
        case DOUBLE:
            return new Record(new DoubleValue((Double) value), timestamp);
        default:
            return new Record(new StringValue((String) value), timestamp);
    }
}
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) 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 8 with StringValue

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

the class Iec62056Listener method newRecord.

private synchronized void newRecord(List<DataSet> dataSets, long time) {
    List<ChannelRecordContainer> newContainers = new ArrayList<>();
    for (ChannelRecordContainer container : containers) {
        for (DataSet dataSet : dataSets) {
            if (dataSet.getAddress().equals(container.getChannelAddress())) {
                String value = dataSet.getValue();
                if (value != null) {
                    try {
                        container.setRecord(new Record(new DoubleValue(Double.parseDouble(dataSet.getValue())), time));
                        newContainers.add(container);
                    } catch (NumberFormatException e) {
                        container.setRecord(new Record(new StringValue(dataSet.getValue()), time));
                    }
                }
                break;
            }
        }
    }
    listener.newRecords(newContainers);
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) DataSet(org.openmuc.j62056.DataSet) DoubleValue(org.openmuc.framework.data.DoubleValue) ArrayList(java.util.ArrayList) Record(org.openmuc.framework.data.Record) StringValue(org.openmuc.framework.data.StringValue)

Example 9 with StringValue

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

the class SmlConnection method extractValueOf.

private static ValueContainer extractValueOf(SmlListEntry entry) {
    double value = 0;
    ValueType valueType = ValueType.DOUBLE;
    ASNObject obj = entry.getValue().getChoice();
    if (obj.getClass().equals(Integer64.class)) {
        Integer64 val = (Integer64) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(Integer32.class)) {
        Integer32 val = (Integer32) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(Integer16.class)) {
        Integer16 val = (Integer16) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(Integer8.class)) {
        Integer8 val = (Integer8) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(Unsigned64.class)) {
        Unsigned64 val = (Unsigned64) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(Unsigned32.class)) {
        Unsigned32 val = (Unsigned32) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(Unsigned16.class)) {
        Unsigned16 val = (Unsigned16) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(Unsigned8.class)) {
        Unsigned8 val = (Unsigned8) obj;
        value = val.getVal();
    } else if (obj.getClass().equals(OctetString.class)) {
        OctetString val = (OctetString) obj;
        return new ValueContainer(new StringValue(new String(val.getValue())), ValueType.STRING);
    } else {
        return new ValueContainer(new DoubleValue(Double.NaN), valueType);
    }
    byte scaler = entry.getScaler().getVal();
    double scaledValue = value * Math.pow(10, scaler);
    return new ValueContainer(new DoubleValue(scaledValue), valueType);
}
Also used : OctetString(org.openmuc.jsml.structures.OctetString) ValueType(org.openmuc.framework.data.ValueType) OctetString(org.openmuc.jsml.structures.OctetString) Integer16(org.openmuc.jsml.structures.Integer16) Integer8(org.openmuc.jsml.structures.Integer8) Integer64(org.openmuc.jsml.structures.Integer64) Integer32(org.openmuc.jsml.structures.Integer32) Unsigned8(org.openmuc.jsml.structures.Unsigned8) Unsigned64(org.openmuc.jsml.structures.Unsigned64) Unsigned32(org.openmuc.jsml.structures.Unsigned32) DoubleValue(org.openmuc.framework.data.DoubleValue) ASNObject(org.openmuc.jsml.structures.ASNObject) Unsigned16(org.openmuc.jsml.structures.Unsigned16) StringValue(org.openmuc.framework.data.StringValue)

Example 10 with StringValue

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

the class DbAccess method queryRecords.

/**
 * Retrieves data from database and adds it to records
 */
public List<Record> queryRecords(StringBuilder sb, ValueType valuetype) {
    // retrieve numeric values from database and add them to the records list
    List<Record> records = new ArrayList<>();
    String sql = sb.toString();
    try (ResultSet resultSet = dbConnector.createStatementWithConnection().executeQuery(sql)) {
        while (resultSet.next()) {
            if (valuetype == ValueType.STRING) {
                Record rc = new Record(new StringValue(resultSet.getString(VALUE)), resultSet.getTimestamp("time").getTime(), Flag.VALID);
                records.add(rc);
            } else if (valuetype == ValueType.BYTE_ARRAY) {
                Record rc = new Record(new ByteArrayValue(resultSet.getBytes(VALUE)), resultSet.getTimestamp("time").getTime(), Flag.VALID);
                records.add(rc);
            } else if (valuetype == ValueType.BOOLEAN) {
                Record rc = new Record(new BooleanValue(resultSet.getBoolean(VALUE)), resultSet.getTimestamp("time").getTime(), Flag.VALID);
                records.add(rc);
            } else {
                Record rc = new Record(new DoubleValue(resultSet.getDouble(VALUE)), resultSet.getTimestamp("time").getTime(), Flag.VALID);
                records.add(rc);
            }
        }
    } catch (SQLException e) {
        logger.error(MessageFormat.format("Error executing SQL: \n{0}", sql), e.getMessage());
    }
    return records;
}
Also used : DoubleValue(org.openmuc.framework.data.DoubleValue) SQLException(java.sql.SQLException) BooleanValue(org.openmuc.framework.data.BooleanValue) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) Record(org.openmuc.framework.data.Record) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) 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