Search in sources :

Example 1 with ValueType

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

the class LogFileHeader method appendChannelSpecificComment.

/**
 * Appends channel specific comments to a StringBuilder
 *
 * @param sb
 * @param logChannel
 * @param colNumber
 */
private static void appendChannelSpecificComment(StringBuilder sb, LogChannel logChannel, int colNumber) {
    String unit = logChannel.getUnit();
    if (unit.equals("")) {
        unit = "0";
    }
    ValueType vType = logChannel.getValueType();
    String valueType = vType.toString();
    int valueTypeLength = 0;
    if (vType.equals(ValueType.BYTE_ARRAY) || vType.equals(ValueType.STRING)) {
        valueTypeLength = logChannel.getValueTypeLength();
    } else {
        valueTypeLength = LoggerUtils.getLengthOfValueType(vType);
    }
    String description = logChannel.getDescription();
    if (description.equals("")) {
        description = "-";
    }
    createRow(sb, String.format("%03d", colNumber), logChannel.getId(), FALSE_STRING, TRUE_STRING, unit, OTHER_STRING, valueType, valueTypeLength, description);
}
Also used : ValueType(org.openmuc.framework.data.ValueType)

Example 2 with ValueType

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

the class LogFileWriter method getDataTypeSize.

/**
 * Returns the size of a DataType / ValueType.
 *
 * @param logChannel
 * @param iterator
 * @return size of DataType / ValueType.
 */
private int getDataTypeSize(LogChannel logChannel, int iterator) {
    int size;
    if (logChannel != null) {
        boolean isByteArray = logChannel.getValueType().equals(ValueType.BYTE_ARRAY);
        boolean isString = logChannel.getValueType().equals(ValueType.STRING);
        if (isString) {
            // get length from channel for String / ByteArray
            size = logChannel.getValueTypeLength();
        } else if (isByteArray) {
            size = Const.HEXADECIMAL.length() + logChannel.getValueTypeLength() * 2;
        } else {
            // get length from channel for simple value types
            size = LoggerUtils.getLengthOfValueType(logChannel.getValueType());
        }
    } else {
        // get length from file
        ValueType vt = LoggerUtils.identifyValueType(iterator + Const.NUM_OF_TIME_TYPES_IN_HEADER + 1, actualFile);
        size = LoggerUtils.getLengthOfValueType(vt);
        if ((vt.equals(ValueType.BYTE_ARRAY) || (vt.equals(ValueType.STRING))) && size <= Const.VALUE_SIZE_MINIMAL) {
            size = LoggerUtils.getValueTypeLengthFromFile(iterator + Const.NUM_OF_TIME_TYPES_IN_HEADER + 1, actualFile);
        }
    }
    return size;
}
Also used : ValueType(org.openmuc.framework.data.ValueType)

Example 3 with ValueType

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

the class DriverConnection method fillDataRecordInChannelScanInfo.

private void fillDataRecordInChannelScanInfo(List<ChannelScanInfo> channelScanInfo, DataRecord dataRecord) {
    String vib = Helper.bytesToHex(dataRecord.getVib());
    String dib = Helper.bytesToHex(dataRecord.getDib());
    ValueType valueType;
    Integer valueLength;
    switch(dataRecord.getDataValueType()) {
        case STRING:
            valueType = ValueType.STRING;
            valueLength = 25;
            break;
        case LONG:
            if (dataRecord.getMultiplierExponent() == 0) {
                valueType = ValueType.LONG;
            } else {
                valueType = ValueType.DOUBLE;
            }
            valueLength = null;
            break;
        case DOUBLE:
        case DATE:
            valueType = ValueType.DOUBLE;
            valueLength = null;
            break;
        case BCD:
            if (dataRecord.getMultiplierExponent() == 0) {
                valueType = ValueType.DOUBLE;
            } else {
                valueType = ValueType.LONG;
            }
            valueLength = null;
            break;
        case NONE:
        default:
            valueType = ValueType.BYTE_ARRAY;
            valueLength = 100;
            break;
    }
    String unit = "";
    if (dataRecord.getUnit() != null) {
        unit = dataRecord.getUnit().getUnit();
    }
    channelScanInfo.add(new ChannelScanInfo(dib + ':' + vib, getDescription(dataRecord), valueType, valueLength, true, true, "", unit));
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) DataValueType(org.openmuc.jmbus.DataRecord.DataValueType) ValueType(org.openmuc.framework.data.ValueType)

Example 4 with ValueType

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

the class IecConnection method scanForChannels.

@Override
public List<ChannelScanInfo> scanForChannels(int timeout) {
    List<ChannelScanInfo> channelInfos = new LinkedList<>();
    logger.debug("scanning channels");
    try {
        byte[] frame = receiver.receiveMessage(timeout);
        ModeDMessage message = ModeDMessage.parse(frame);
        List<String> dataSets = message.getDataSets();
        for (String data : dataSets) {
            DataSet dataSet = new DataSet(data);
            String channelAddress = dataSet.getAddress();
            String description = "Current value: " + dataSet.parseValueAsDouble() + dataSet.getUnit();
            ValueType valueType = ValueType.DOUBLE;
            Integer valueTypeLength = null;
            Boolean readable = true;
            Boolean writable = false;
            ChannelScanInfo channelInfo = new ChannelScanInfo(channelAddress, description, valueType, valueTypeLength, readable, writable);
            channelInfos.add(channelInfo);
        }
    } catch (ParseException | IOException e) {
        logger.warn("read failed", e);
    }
    return channelInfos;
}
Also used : DataSet(org.openmuc.framework.driver.ehz.iec62056_21.DataSet) ValueType(org.openmuc.framework.data.ValueType) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ParseException(java.text.ParseException) ModeDMessage(org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage)

Example 5 with ValueType

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

Aggregations

ValueType (org.openmuc.framework.data.ValueType)13 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)6 DoubleValue (org.openmuc.framework.data.DoubleValue)2 Record (org.openmuc.framework.data.Record)2 StringValue (org.openmuc.framework.data.StringValue)2 Value (org.openmuc.framework.data.Value)2 OctetString (org.openmuc.jsml.structures.OctetString)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1