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