Search in sources :

Example 91 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class DlmsHelper method buildWindowElementFromDataObjects.

private WindowElementDto buildWindowElementFromDataObjects(final List<DataObject> elements, final String description) throws ProtocolAdapterException {
    if (elements.size() != 2) {
        LOGGER.error("Unexpected number of ResultData elements for WindowElement value: {}", elements.size());
        throw new ProtocolAdapterException("Expected list for WindowElement to contain 2 elements, got: " + elements.size());
    }
    final CosemDateTimeDto startTime = this.readDateTime(elements.get(0), "Start Time from " + description);
    final CosemDateTimeDto endTime = this.readDateTime(elements.get(1), "End Time from " + description);
    return new WindowElementDto(startTime, endTime);
}
Also used : WindowElementDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WindowElementDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Example 92 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class DlmsHelper method readTransportServiceType.

public TransportServiceTypeDto readTransportServiceType(final DataObject resultData, final String description) throws ProtocolAdapterException {
    final Number number = this.readNumber(resultData, description, "Enum");
    if (number == null) {
        return null;
    }
    final int enumValue = number.intValue();
    final TransportServiceTypeDto transportService = this.getTransportServiceTypeForEnumValue(enumValue);
    if (transportService == null) {
        LOGGER.error("Unexpected Enum value for TransportServiceType: {}", enumValue);
        throw new ProtocolAdapterException("Unknown Enum value for TransportServiceType: " + enumValue);
    }
    return transportService;
}
Also used : TransportServiceTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.TransportServiceTypeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 93 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException 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 94 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class DlmsHelper method readMessageType.

public MessageTypeDto readMessageType(final DataObject resultData, final String description) throws ProtocolAdapterException {
    final Number number = this.readNumber(resultData, description, "Enum");
    if (number == null) {
        return null;
    }
    final MessageTypeDto message;
    final int enumValue = number.intValue();
    switch(enumValue) {
        case 0:
            message = MessageTypeDto.A_XDR_ENCODED_X_DLMS_APDU;
            break;
        case 1:
            message = MessageTypeDto.XML_ENCODED_X_DLMS_APDU;
            break;
        default:
            if (enumValue < 128 || enumValue > 255) {
                LOGGER.error("Unexpected Enum value for MessageType: {}", enumValue);
                throw new ProtocolAdapterException("Unknown Enum value for MessageType: " + enumValue);
            }
            message = MessageTypeDto.MANUFACTURER_SPECIFIC;
    }
    return message;
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MessageTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MessageTypeDto)

Example 95 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class DlmsHelper method checkResultCode.

private void checkResultCode(final GetResult getResult, final String description) throws ProtocolAdapterException {
    final AccessResultCode resultCode = getResult.getResultCode();
    LOGGER.debug("{} - AccessResultCode: {}", description, resultCode);
    if (resultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException("No success retrieving " + description + ": AccessResultCode = " + resultCode);
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)95 DataObject (org.openmuc.jdlms.datatypes.DataObject)32 Test (org.junit.jupiter.api.Test)22 AccessResultCode (org.openmuc.jdlms.AccessResultCode)15 GetResult (org.openmuc.jdlms.GetResult)15 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)9 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)9 BitString (org.openmuc.jdlms.datatypes.BitString)7 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)7 ObisCode (org.openmuc.jdlms.ObisCode)6 SetParameter (org.openmuc.jdlms.SetParameter)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 DateTime (org.joda.time.DateTime)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)4 Date (java.util.Date)3 List (java.util.List)3