Search in sources :

Example 1 with Type

use of org.openmuc.jdlms.datatypes.DataObject.Type in project OpenMUC by isc-konstanz.

the class WriteHandle method createSetParamsFor.

private static List<SetParameter> createSetParamsFor(List<ChannelValueContainer> writeList) throws ConnectionException {
    List<SetParameter> setParams = new ArrayList<>(writeList.size());
    for (ChannelValueContainer channelContainer : writeList) {
        try {
            ChannelAddress channelAddress = new ChannelAddress(channelContainer.getChannelAddress());
            Type type = channelAddress.getType();
            if (type == null) {
                String msg = MessageFormat.format("Can not set attribute with address {0} where the type is unknown.", channelAddress);
                throw new ConnectionException(msg);
            }
            DataObject newValue = createDoFor(channelContainer, type);
            AttributeAddress address = channelAddress.getAttributeAddress();
            SetParameter setParameter = new SetParameter(address, newValue);
            setParams.add(setParameter);
        } catch (ArgumentSyntaxException e) {
            throw new ConnectionException(e);
        }
    }
    return setParams;
}
Also used : Type(org.openmuc.jdlms.datatypes.DataObject.Type) DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ChannelAddress(org.openmuc.framework.driver.dlms.settings.ChannelAddress) SetParameter(org.openmuc.jdlms.SetParameter) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 2 with Type

use of org.openmuc.jdlms.datatypes.DataObject.Type in project OpenMUC by isc-konstanz.

the class ReadHandle method getType.

@SuppressWarnings("unused")
private static ValueType getType(DataObject dataObject) {
    final ValueType valueType;
    final Type type = dataObject.getType();
    switch(type) {
        case BOOLEAN:
            valueType = ValueType.BOOLEAN;
            break;
        case FLOAT32:
            valueType = ValueType.FLOAT;
            break;
        case FLOAT64:
            valueType = ValueType.DOUBLE;
            break;
        case BCD:
        case INTEGER:
            valueType = ValueType.BYTE;
            break;
        case LONG_INTEGER:
        case UNSIGNED:
            valueType = ValueType.SHORT;
            break;
        case ENUMERATE:
        case DOUBLE_LONG:
        case LONG_UNSIGNED:
            valueType = ValueType.INTEGER;
            break;
        case DOUBLE_LONG_UNSIGNED:
        case LONG64:
        case // Long is to small for Long unsigned
        LONG64_UNSIGNED:
            valueType = ValueType.LONG;
            break;
        case OCTET_STRING:
            valueType = ValueType.BYTE_ARRAY;
            break;
        case VISIBLE_STRING:
            valueType = ValueType.STRING;
            break;
        case NULL_DATA:
            // TODO
            valueType = null;
            break;
        case ARRAY:
        case BIT_STRING:
        case COMPACT_ARRAY:
        case DONT_CARE:
        case DATE:
        case DATE_TIME:
        case STRUCTURE:
        case TIME:
        default:
            valueType = null;
            break;
    }
    return valueType;
}
Also used : Type(org.openmuc.jdlms.datatypes.DataObject.Type) ValueType(org.openmuc.framework.data.ValueType) ValueType(org.openmuc.framework.data.ValueType)

Aggregations

Type (org.openmuc.jdlms.datatypes.DataObject.Type)2 ArrayList (java.util.ArrayList)1 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 ValueType (org.openmuc.framework.data.ValueType)1 ChannelAddress (org.openmuc.framework.driver.dlms.settings.ChannelAddress)1 ChannelValueContainer (org.openmuc.framework.driver.spi.ChannelValueContainer)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 SetParameter (org.openmuc.jdlms.SetParameter)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1