Search in sources :

Example 61 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.

the class DlmsHelper method readList.

private List<DataObject> readList(final DataObject resultData, final String description) throws ProtocolAdapterException {
    this.logDebugResultData(resultData, description);
    if (resultData == null || resultData.isNull()) {
        return Collections.emptyList();
    }
    final Object resultValue = resultData.getValue();
    if (!resultData.isComplex() || !(resultValue instanceof List)) {
        this.logAndThrowExceptionForUnexpectedResultData(resultData, "List");
    }
    return (List<DataObject>) resultValue;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) List(java.util.List) ArrayList(java.util.ArrayList)

Example 62 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.

the class DlmsHelper method getScaledMeterValue.

public DlmsMeterValueDto getScaledMeterValue(final DataObject value, final DataObject scalerUnitObject, final String description) throws ProtocolAdapterException {
    LOGGER.debug(this.getDebugInfo(value));
    LOGGER.debug(this.getDebugInfo(scalerUnitObject));
    final Long rawValue = this.readLong(value, description);
    if (rawValue == null) {
        return null;
    }
    if (!scalerUnitObject.isComplex()) {
        throw new ProtocolAdapterException("complex data (structure) expected while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
    }
    final List<DataObject> dataObjects = scalerUnitObject.getValue();
    if (dataObjects.size() != 2) {
        throw new ProtocolAdapterException("expected 2 values while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
    }
    final int scaler = this.readLongNotNull(dataObjects.get(0), description).intValue();
    final DlmsUnitTypeDto unit = DlmsUnitTypeDto.getUnitType(this.readLongNotNull(dataObjects.get(1), description).intValue());
    // determine value
    BigDecimal scaledValue = BigDecimal.valueOf(rawValue);
    if (scaler != 0) {
        scaledValue = scaledValue.multiply(BigDecimal.valueOf(Math.pow(10, scaler)));
    }
    return new DlmsMeterValueDto(scaledValue, unit);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsUnitTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) BigDecimal(java.math.BigDecimal) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Example 63 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.

the class DlmsHelper method readNumber.

private Number readNumber(final DataObject resultData, final String description, final String interpretation) throws ProtocolAdapterException {
    this.logDebugResultData(resultData, description);
    if (resultData == null || resultData.isNull()) {
        return null;
    }
    final Object resultValue = resultData.getValue();
    if (!resultData.isNumber() || !(resultValue instanceof Number)) {
        this.logAndThrowExceptionForUnexpectedResultData(resultData, interpretation);
    }
    return (Number) resultValue;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject)

Example 64 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.

the class DlmsHelper method readByteArray.

private byte[] readByteArray(final DataObject resultData, final String description, final String interpretation) throws ProtocolAdapterException {
    this.logDebugResultData(resultData, description);
    if (resultData == null || resultData.isNull()) {
        return new byte[0];
    }
    final Object resultValue = resultData.getValue();
    if (!resultData.isByteArray() || !(resultValue instanceof byte[])) {
        this.logAndThrowExceptionForUnexpectedResultData(resultData, "byte array to be interpreted as " + interpretation);
    }
    return (byte[]) resultValue;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject)

Example 65 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.

the class DlmsHelper method readListOfWindowElement.

public List<WindowElementDto> readListOfWindowElement(final DataObject resultData, final String description) throws ProtocolAdapterException {
    final List<DataObject> listOfWindowElement = this.readList(resultData, description);
    if (listOfWindowElement == null) {
        return Collections.emptyList();
    }
    final List<WindowElementDto> windowElementList = new ArrayList<>();
    for (final DataObject windowElementObject : listOfWindowElement) {
        windowElementList.add(this.readWindowElement(windowElementObject, "Window Element from " + description));
    }
    return windowElementList;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) WindowElementDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WindowElementDto) ArrayList(java.util.ArrayList)

Aggregations

DataObject (org.openmuc.jdlms.datatypes.DataObject)176 ArrayList (java.util.ArrayList)46 AttributeAddress (org.openmuc.jdlms.AttributeAddress)36 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)34 Test (org.junit.jupiter.api.Test)31 GetResult (org.openmuc.jdlms.GetResult)23 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)16 DateTime (org.joda.time.DateTime)15 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)14 SetParameter (org.openmuc.jdlms.SetParameter)12 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)11 BitString (org.openmuc.jdlms.datatypes.BitString)10 ObisCode (org.openmuc.jdlms.ObisCode)9 IOException (java.io.IOException)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)7 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)6 List (java.util.List)5 MethodResultCode (org.openmuc.jdlms.MethodResultCode)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)5 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)5