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