Search in sources :

Example 76 with AttributeAddress

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

the class CosemObjectAccessor method writeAttribute.

public void writeAttribute(final AttributeClass attributeClass, final DataObject data) throws ProtocolAdapterException {
    final AttributeAddress attributeAddress = this.createAttributeAddress(attributeClass);
    final SetParameter setParameter = new SetParameter(attributeAddress, data);
    final AccessResultCode accessResultCode;
    try {
        accessResultCode = this.connector.getConnection().set(setParameter);
    } catch (final IOException e) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_WRITING_ATTRIBUTE, attributeClass, this.classId, this.obisCode), e);
    }
    if (accessResultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_ACCESS_RESULT_NOT_SUCCESS, accessResultCode.name(), attributeClass, this.classId, this.obisCode));
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SetParameter(org.openmuc.jdlms.SetParameter)

Example 77 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress 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)

Aggregations

AttributeAddress (org.openmuc.jdlms.AttributeAddress)77 DataObject (org.openmuc.jdlms.datatypes.DataObject)38 ObisCode (org.openmuc.jdlms.ObisCode)18 Test (org.junit.jupiter.api.Test)16 GetResult (org.openmuc.jdlms.GetResult)16 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)16 SetParameter (org.openmuc.jdlms.SetParameter)15 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)14 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)8 DateTime (org.joda.time.DateTime)7 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)6 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)6 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)6 Collectors (java.util.stream.Collectors)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5