Search in sources :

Example 1 with Flag

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

the class FromJson method convertRecord.

public static Record convertRecord(RestRecord rrc, ValueType type) throws ClassCastException {
    Object value = rrc.getValue();
    Flag flag = rrc.getFlag();
    Value retValue = null;
    if (value != null) {
        retValue = convertValue(value, type);
    }
    if (flag == null) {
        return new Record(retValue, rrc.getTimestamp());
    } else {
        return new Record(retValue, rrc.getTimestamp(), rrc.getFlag());
    }
}
Also used : 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) RestValue(org.openmuc.framework.lib.rest.objects.RestValue) BooleanValue(org.openmuc.framework.data.BooleanValue) LongValue(org.openmuc.framework.data.LongValue) IntValue(org.openmuc.framework.data.IntValue) JsonObject(com.google.gson.JsonObject) RestRecord(org.openmuc.framework.lib.rest.objects.RestRecord) Record(org.openmuc.framework.data.Record) Flag(org.openmuc.framework.data.Flag)

Example 2 with Flag

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

the class OpenmucParserServiceImplTest method serializeDoubleValue.

@Test
void serializeDoubleValue() throws SerializationException {
    String controlString = "{\"timestamp\":1582722316,\"flag\":\"VALID\",\"value\":3.0}";
    Value doubleValue = new DoubleValue(3.0);
    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 : DoubleValue(org.openmuc.framework.data.DoubleValue) 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) Flag(org.openmuc.framework.data.Flag) Test(org.junit.jupiter.api.Test)

Example 3 with Flag

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

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

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

the class DriverConnectionTest method testReadThrowsIOException.

@Test
public void testReadThrowsIOException() throws Exception {
    MBusConnection con = mock(MBusConnection.class);
    VariableDataStructure vds = new VariableDataStructure(NZR_ANSWER, 6, NZR_ANSWER.length - 6, null, null);
    vds.decode();
    when(con.read(anyInt())).thenThrow(new IOException());
    ConnectionInterface serialIntervace = new ConnectionInterface(con, "/dev/ttyS100:5", delay, interfaces);
    serialIntervace.increaseConnectionCounter();
    String[] deviceAddressTokens = { "/dev/ttyS100", "5" };
    int address = Integer.parseInt(deviceAddressTokens[1]);
    DriverConnection driverCon = new DriverConnection(serialIntervace, address, null, delay);
    List<ChannelRecordContainer> records = Arrays.asList(newChannelRecordContainer("04:03"));
    driverCon.read(records, null, null);
    Flag actualFlag = records.get(0).getRecord().getFlag();
    assertEquals(Flag.DRIVER_ERROR_TIMEOUT, actualFlag);
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) IOException(java.io.IOException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) Flag(org.openmuc.framework.data.Flag) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Flag (org.openmuc.framework.data.Flag)15 Value (org.openmuc.framework.data.Value)11 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)8 Record (org.openmuc.framework.data.Record)8 DoubleValue (org.openmuc.framework.data.DoubleValue)7 StringValue (org.openmuc.framework.data.StringValue)7 Test (org.junit.jupiter.api.Test)4 LoggingRecord (org.openmuc.framework.datalogger.spi.LoggingRecord)4 BooleanValue (org.openmuc.framework.data.BooleanValue)3 RestRecord (org.openmuc.framework.lib.rest.objects.RestRecord)3 IOException (java.io.IOException)2 IntValue (org.openmuc.framework.data.IntValue)2 TypeConversionException (org.openmuc.framework.data.TypeConversionException)2 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 ConfigurationException (javax.naming.ConfigurationException)1 Test (org.junit.Test)1 ByteValue (org.openmuc.framework.data.ByteValue)1