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