Search in sources :

Example 46 with GetResult

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

the class DlmsHelper method getWithList.

public List<GetResult> getWithList(final DlmsConnectionManager conn, final DlmsDevice device, final AttributeAddress... params) throws ProtocolAdapterException {
    try {
        if (device.isWithListSupported()) {
            // Getting a too large list of attribute addresses in one get
            // from the DlmsConnection
            // might result in a SCOPE_OF_ACCESS_VIOLATED error
            final List<GetResult> getResults = new ArrayList<>();
            final List<AttributeAddress[]> maximizedSubsetsOfParams = this.getMaximizedSubsetsOfParams(params);
            for (final AttributeAddress[] maximizedSubsetOfParams : maximizedSubsetsOfParams) {
                getResults.addAll(conn.getConnection().get(Arrays.asList(maximizedSubsetOfParams)));
            }
            return getResults;
        } else {
            return this.getWithListWorkaround(conn, params);
        }
    } catch (final IOException | NullPointerException e) {
        // JDlmsException).
        throw new ConnectionException("Connection error retrieving values with-list for device: " + device.getDeviceIdentification(), e);
    } catch (final Exception e) {
        throw new ProtocolAdapterException("Error retrieving values with-list for device: " + device.getDeviceIdentification() + ", with-list: " + (device.isWithListSupported() ? "supported" : "not supported"), e);
    }
}
Also used : GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) BufferedDateTimeValidationException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException)

Example 47 with GetResult

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

the class DlmsHelper method getAttributeValue.

/**
 * Gets a single result from a meter, and returns the result data if retrieval was successful
 * (resultCode of the GetResult equals AccessResultCode.SUCCESS).
 *
 * @return a result from trying to retrieve the value for the attribute identified by {@code
 *     attributeAddress}.
 */
public DataObject getAttributeValue(final DlmsConnectionManager conn, final AttributeAddress attributeAddress) throws FunctionalException {
    Objects.requireNonNull(conn, "conn must not be null");
    Objects.requireNonNull(attributeAddress, "attributeAddress must not be null");
    try {
        final GetResult getResult = conn.getConnection().get(attributeAddress);
        final AccessResultCode resultCode = getResult.getResultCode();
        if (AccessResultCode.SUCCESS == resultCode) {
            return getResult.getResultData();
        }
        final String errorMessage = String.format("Retrieving attribute value for { %d, %s, %d }. Result: resultCode(%d), with data: %s", attributeAddress.getClassId(), attributeAddress.getInstanceId().asShortObisCodeString(), attributeAddress.getId(), resultCode.getCode(), this.getDebugInfo(getResult.getResultData()));
        LOGGER.error(errorMessage);
        throw new FunctionalException(FunctionalExceptionType.ERROR_RETRIEVING_ATTRIBUTE_VALUE, ComponentType.PROTOCOL_DLMS, new OsgpException(ComponentType.PROTOCOL_DLMS, errorMessage));
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetResult(org.openmuc.jdlms.GetResult) AccessResultCode(org.openmuc.jdlms.AccessResultCode) BitString(org.openmuc.jdlms.datatypes.BitString) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) IOException(java.io.IOException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Aggregations

GetResult (org.openmuc.jdlms.GetResult)47 DataObject (org.openmuc.jdlms.datatypes.DataObject)23 ArrayList (java.util.ArrayList)16 AttributeAddress (org.openmuc.jdlms.AttributeAddress)16 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)14 Test (org.junit.jupiter.api.Test)13 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)11 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)8 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)8 DateTime (org.joda.time.DateTime)6 ObisCode (org.openmuc.jdlms.ObisCode)6 IOException (java.io.IOException)5 Date (java.util.Date)5 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)4 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)4 AccessResultCode (org.openmuc.jdlms.AccessResultCode)3 BufferedDateTimeValidationException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException)3