Search in sources :

Example 26 with Record

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

the class OpenmucParserServiceImplTest method deserializeTimestamp.

@Test
void deserializeTimestamp() {
    String inputString = "{\"timestamp\":1582722316,\"flag\":\"VALID\",\"value\":3.0}";
    Record recordDes = parserService.deserialize(inputString.getBytes(), new SerializationContainerTest(ValueType.DOUBLE));
    assertEquals(1582722316, recordDes.getTimestamp().longValue());
}
Also used : Record(org.openmuc.framework.data.Record) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord) Test(org.junit.jupiter.api.Test)

Example 27 with Record

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

the class OpenmucParserServiceImplTest method serializeByteArrayValue.

@Test
void serializeByteArrayValue() throws SerializationException {
    String controlString = "{\"timestamp\":1582722316,\"flag\":\"VALID\",\"value\":\"dGVzdA==\"}";
    Value byteArrayValue = new ByteArrayValue("test".getBytes());
    long timestamp = 1582722316;
    Flag flag = Flag.VALID;
    Record record = new Record(byteArrayValue, 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) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) Flag(org.openmuc.framework.data.Flag) Test(org.junit.jupiter.api.Test)

Example 28 with Record

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

the class DriverConnection method setRecords.

private boolean setRecords(List<ChannelRecordContainer> containers, MBusConnection mBusConnection, long timestamp, List<DataRecord> dataRecords, String[] dibvibs) throws ConnectionException {
    boolean selectForReadoutSet = false;
    for (ChannelRecordContainer container : containers) {
        String channelAddress = container.getChannelAddress();
        if (channelAddress.startsWith("X")) {
            String[] dibAndVib = channelAddress.split(":");
            if (dibAndVib.length != 2) {
                container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_ADDRESS_SYNTAX_INVALID));
            }
            List<DataRecord> dataRecordsToSelectForReadout = new ArrayList<>(1);
            selectForReadoutSet = true;
            try {
                mBusConnection.selectForReadout(mBusAddress, dataRecordsToSelectForReadout);
                sleep(delay);
            } catch (SerialPortTimeoutException e) {
                container.setRecord(new Record(Flag.DRIVER_ERROR_TIMEOUT));
                continue;
            } catch (IOException e) {
                connectionInterface.close();
                throw new ConnectionException(e);
            }
            VariableDataStructure variableDataStructure2 = null;
            try {
                variableDataStructure2 = mBusConnection.read(mBusAddress);
            } catch (SerialPortTimeoutException e1) {
                container.setRecord(new Record(Flag.DRIVER_ERROR_TIMEOUT));
                continue;
            } catch (IOException e1) {
                connectionInterface.close();
                throw new ConnectionException(e1);
            }
            DataRecord dataRecord = variableDataStructure2.getDataRecords().get(0);
            setContainersRecord(timestamp, container, dataRecord);
            continue;
        }
        int j = 0;
        for (DataRecord dataRecord : dataRecords) {
            if (dibvibs[j++].equalsIgnoreCase(channelAddress)) {
                setContainersRecord(timestamp, container, dataRecord);
                break;
            }
        }
        if (container.getRecord() == null) {
            container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND));
        }
    }
    return selectForReadoutSet;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) SerialPortTimeoutException(org.openmuc.jrxtx.SerialPortTimeoutException) DataRecord(org.openmuc.jmbus.DataRecord) Record(org.openmuc.framework.data.Record) DataRecord(org.openmuc.jmbus.DataRecord) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 29 with Record

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

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

the class RestChannel method write.

public void write(RestConnection connection) throws ConnectionException {
    Record record = getRecord();
    ToJson json = new ToJson();
    json.addRecord(record, getValueType());
    Flag flag = connection.put(uri, json.toString());
    setFlag(flag);
}
Also used : ToJson(org.openmuc.framework.lib.rest.ToJson) RestRecord(org.openmuc.framework.lib.rest.objects.RestRecord) Record(org.openmuc.framework.data.Record) Flag(org.openmuc.framework.data.Flag)

Aggregations

Record (org.openmuc.framework.data.Record)115 DoubleValue (org.openmuc.framework.data.DoubleValue)34 LoggingRecord (org.openmuc.framework.datalogger.spi.LoggingRecord)34 Value (org.openmuc.framework.data.Value)26 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)24 Test (org.junit.jupiter.api.Test)21 StringValue (org.openmuc.framework.data.StringValue)20 BooleanValue (org.openmuc.framework.data.BooleanValue)18 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)14 ArrayList (java.util.ArrayList)13 IntValue (org.openmuc.framework.data.IntValue)13 FloatValue (org.openmuc.framework.data.FloatValue)12 LongValue (org.openmuc.framework.data.LongValue)12 ShortValue (org.openmuc.framework.data.ShortValue)12 LogFileReader (org.openmuc.framework.datalogger.ascii.LogFileReader)12 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)12 ByteValue (org.openmuc.framework.data.ByteValue)10 Flag (org.openmuc.framework.data.Flag)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)7