Search in sources :

Example 11 with DoubleValue

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

the class EdgeListener method handleGpioPinDigitalStateChangeEvent.

@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
    if (event.getPin() == pin && event.getEdge() == edge) {
        long samplingTime = System.currentTimeMillis();
        if (lastSamplingTime == null || samplingTime - lastSamplingTime > bounceTime) {
            synchronized (counter) {
                counter++;
                if (listener != null && channels.size() > 0) {
                    List<ChannelRecordContainer> containers = new LinkedList<ChannelRecordContainer>();
                    for (GpioChannel channel : channels) {
                        Value value = null;
                        if (channel.isDerivative()) {
                            if (lastSamplingTime != null) {
                                double counterDelta = 1.0 / channel.getImpulses();
                                double timeDelta = (samplingTime - lastSamplingTime) / channel.getDerivativeTime();
                                if (timeDelta > 0) {
                                    value = new DoubleValue(counterDelta / timeDelta);
                                }
                            }
                        } else {
                            value = new DoubleValue(counter / channel.getImpulses());
                        }
                        if (value != null) {
                            logger.debug("Registered {}. edge for {}: {}", counter, event.getPin().getName(), value);
                            channel.setRecord(new Record(value, samplingTime, Flag.VALID));
                        } else {
                            channel.setRecord(new Record(null, samplingTime, Flag.DRIVER_ERROR_CHANNEL_TEMPORARILY_NOT_ACCESSIBLE));
                        }
                        containers.add((ChannelRecordContainer) channel.getTaskContainer());
                    }
                    listener.newRecords(containers);
                }
                lastSamplingTime = samplingTime;
            }
        }
    }
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) GpioChannel(org.openmuc.framework.driver.rpi.gpio.GpioChannel) DoubleValue(org.openmuc.framework.data.DoubleValue) DoubleValue(org.openmuc.framework.data.DoubleValue) Value(org.openmuc.framework.data.Value) Record(org.openmuc.framework.data.Record) LinkedList(java.util.LinkedList)

Example 12 with DoubleValue

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

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

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

the class LoggerUtilsTest method getGroup.

private static LogIntervalContainerGroup getGroup(long timeStamp, int i) {
    LogIntervalContainerGroup group = new LogIntervalContainerGroup();
    LoggingRecord container1 = new LoggingRecord(ch01, new Record(new DoubleValue(i * 7 - 0.555), timeStamp));
    group.add(container1);
    return group;
}
Also used : DoubleValue(org.openmuc.framework.data.DoubleValue) LogIntervalContainerGroup(org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup) Record(org.openmuc.framework.data.Record) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord)

Example 15 with DoubleValue

use of org.openmuc.framework.data.DoubleValue 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

DoubleValue (org.openmuc.framework.data.DoubleValue)31 Record (org.openmuc.framework.data.Record)26 StringValue (org.openmuc.framework.data.StringValue)14 IntValue (org.openmuc.framework.data.IntValue)12 Value (org.openmuc.framework.data.Value)12 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)11 FloatValue (org.openmuc.framework.data.FloatValue)11 LongValue (org.openmuc.framework.data.LongValue)11 ShortValue (org.openmuc.framework.data.ShortValue)11 BooleanValue (org.openmuc.framework.data.BooleanValue)10 LoggingRecord (org.openmuc.framework.datalogger.spi.LoggingRecord)10 ByteValue (org.openmuc.framework.data.ByteValue)8 ArrayList (java.util.ArrayList)5 Flag (org.openmuc.framework.data.Flag)4 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 LogIntervalContainerGroup (org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup)3 Read (org.openmuc.framework.driver.annotation.Read)3 Calendar (java.util.Calendar)2 LinkedList (java.util.LinkedList)2