Search in sources :

Example 61 with ProtocolAdapterException

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

the class GetConfigurationObjectServiceDsmr4 method getGprsOperationMode.

private Optional<GprsOperationModeTypeDto> getGprsOperationMode(final DataObject gprsMode) throws ProtocolAdapterException {
    if (gprsMode == null || !gprsMode.isNumber()) {
        final String message = String.format("Expected ConfigurationObject gprsOperationMode as Number, but got: %s", gprsMode);
        LOGGER.warn(message);
        throw new ProtocolAdapterException(message);
    }
    final Number number = gprsMode.getValue();
    return GprsOperationModeTypeDto.forNumber(number.intValue());
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 62 with ProtocolAdapterException

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

the class GetConfigurationObjectServiceDsmr4 method getConfigurationFlags.

private ConfigurationFlagsDto getConfigurationFlags(final DataObject flags) throws ProtocolAdapterException {
    if (flags == null || !flags.isBitString()) {
        final String message = String.format("Expected ConfigurationObject flags as BitString, but got: %s", flags);
        LOGGER.warn(message);
        throw new ProtocolAdapterException(message);
    }
    final BitString bitString = flags.getValue();
    final byte[] flagBytes = bitString.getBitString();
    final List<ConfigurationFlagDto> configurationFlags = this.toConfigurationFlags(flagBytes);
    return new ConfigurationFlagsDto(configurationFlags);
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) BitString(org.openmuc.jdlms.datatypes.BitString) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 63 with ProtocolAdapterException

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

the class GetConfigurationObjectServiceDsmr4 method getConfigurationObject.

@Override
ConfigurationObjectDto getConfigurationObject(final GetResult result) throws ProtocolAdapterException {
    final DataObject resultData = result.getResultData();
    if (resultData == null || !resultData.isComplex()) {
        final String message = String.format("Expected ConfigurationObject ResultData as Complex, but got: %s", resultData);
        LOGGER.warn(message);
        throw new ProtocolAdapterException(message);
    }
    return this.getConfigurationObject(resultData);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 64 with ProtocolAdapterException

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

the class GetConfigurationObjectServiceDsmr4 method getConfigurationObject.

private ConfigurationObjectDto getConfigurationObject(final DataObject resultData) throws ProtocolAdapterException {
    LOGGER.info("ConfigurationObject ResultData: {}", this.dlmsHelper.getDebugInfo(resultData));
    final List<DataObject> elements = resultData.getValue();
    if (elements == null || elements.size() != NUMBER_OF_CONFIGURATION_OBJECT_ELEMENTS) {
        final String message = String.format("Expected ConfigurationObject ResultData with %d elements, but got %s", NUMBER_OF_CONFIGURATION_OBJECT_ELEMENTS, elements == null ? "null" : elements.size());
        LOGGER.warn(message);
        throw new ProtocolAdapterException(message);
    }
    return this.getConfigurationObject(elements);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 65 with ProtocolAdapterException

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

the class ClearMBusStatusOnAllChannelsCommandExecutorTest method testExecuteObjectNotFound.

@Test
void testExecuteObjectNotFound() throws ProtocolAdapterException {
    when(this.dlmsObjectConfigService.getAttributeAddress(any(), any(), any())).thenThrow(new ProtocolAdapterException("Object not found"));
    final DlmsDevice dlmsDevice = new DlmsDevice();
    dlmsDevice.setProtocol("SMR", "5.0.0");
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
    });
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

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