Search in sources :

Example 6 with ConfigurationFlagsDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceSmr5 method getConfigurationObject.

@Override
ConfigurationObjectDto getConfigurationObject(final GetResult result) throws ProtocolAdapterException {
    final DataObject resultData = result.getResultData();
    if (resultData == null || !resultData.isBitString()) {
        LOGGER.warn("Configuration object result data is not a BitString: {}", resultData);
        throw new ProtocolAdapterException("Expected bit-string data as Configuration object result data, but got: " + (resultData == null ? "null" : resultData.getType()));
    }
    LOGGER.info("SMR5 Configuration object current BitString: {}", this.dlmsHelper.getDebugInfo(resultData));
    final BitString bitString = resultData.getValue();
    final byte[] flagByteArray = bitString.getBitString();
    final List<ConfigurationFlagDto> configurationFlagDtos = this.toConfigurationFlags(flagByteArray);
    final ConfigurationFlagsDto configurationFlagsDto = new ConfigurationFlagsDto(configurationFlagDtos);
    return new ConfigurationObjectDto(configurationFlagsDto);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 7 with ConfigurationFlagsDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto 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 8 with ConfigurationFlagsDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectRequestMappingTest method checkSetConfigurationObjectRequestData.

// method to check values of all objects that are mapped when a
// SetConfigurationObjectRequest is mapped.
private void checkSetConfigurationObjectRequestData(final GprsOperationModeType gprsOperationModeType, final ConfigurationFlagType configurationFlagType, final ConfigurationFlags configurationFlags, final SetConfigurationObjectRequestDto setConfigurationObjectRequestDto) {
    // check if SetConfigurationObjectRequesDataDto object is present
    final SetConfigurationObjectRequestDataDto setConfigurationObjectRequestDataDto = setConfigurationObjectRequestDto.getSetConfigurationObjectRequestData();
    assertThat(setConfigurationObjectRequestDto).isNotNull();
    // check if ConfigurationObjectDto object is present
    final ConfigurationObjectDto configurationObjectDto = setConfigurationObjectRequestDataDto.getConfigurationObject();
    assertThat(configurationObjectDto).isNotNull();
    // check the GprsOperationModeTypeDto value
    final GprsOperationModeTypeDto gprsOperationModeTypeDto = configurationObjectDto.getGprsOperationMode();
    assertThat(gprsOperationModeTypeDto.name()).isEqualTo(gprsOperationModeType.name());
    // check if ConfigurationFlagsDto object is present, and if its List is
    // of an equal size.
    final ConfigurationFlagsDto configurationFlagsDto = configurationObjectDto.getConfigurationFlags();
    assertThat(configurationFlagsDto).isNotNull();
    assertThat(configurationFlagsDto.getFlags().size()).isEqualTo(configurationFlags.getFlags().size());
    // check ConfigurationObjectFlagTypeDto value.
    final ConfigurationFlagDto configurationFlagDto = configurationFlagsDto.getFlags().get(0);
    final ConfigurationFlagTypeDto configurationFlagTypeDto = configurationFlagDto.getConfigurationFlagType();
    assertThat(configurationFlagTypeDto.name()).isEqualTo(configurationFlagType.name());
}
Also used : GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) ConfigurationFlagTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagTypeDto) SetConfigurationObjectRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetConfigurationObjectRequestDataDto)

Example 9 with ConfigurationFlagsDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectResponseMappingTest method makeConfigurationObjectDto.

private ConfigurationObjectDto makeConfigurationObjectDto() {
    final List<ConfigurationFlagDto> configurationFlags = new ArrayList<>();
    configurationFlags.add(this.makeConfigurationFlagDto());
    final ConfigurationFlagsDto flags = new ConfigurationFlagsDto(configurationFlags);
    final ConfigurationObjectDto configObjectDto = new ConfigurationObjectDto(GprsOperationModeTypeDto.ALWAYS_ON, flags);
    return configObjectDto;
}
Also used : ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ArrayList(java.util.ArrayList) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)

Example 10 with ConfigurationFlagsDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectServiceTest method getFlagsCannotFindBitPosition.

@Test
void getFlagsCannotFindBitPosition() {
    // SETUP
    final ArrayList<ConfigurationFlagDto> flags = new ArrayList<>();
    flags.add(new ConfigurationFlagDto(ConfigurationFlagTypeDto.PO_ENABLE, true));
    final ConfigurationFlagsDto flagsToSet = new ConfigurationFlagsDto(flags);
    when(this.configurationToSet.getConfigurationFlags()).thenReturn(flagsToSet);
    when(this.configurationOnDevice.getConfigurationFlags()).thenReturn(this.emptyFlags());
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        // CALL
        this.instance.getFlags(this.configurationToSet, this.configurationOnDevice);
    });
}
Also used : ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ArrayList(java.util.ArrayList) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)10 ConfigurationFlagDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto)8 ConfigurationObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)8 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)5 ArrayList (java.util.ArrayList)4 BitString (org.openmuc.jdlms.datatypes.BitString)3 GprsOperationModeTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto)3 DataObject (org.openmuc.jdlms.datatypes.DataObject)2 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)2 ConfigurationFlagTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagTypeDto)2 List (java.util.List)1 Optional (java.util.Optional)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 AccessResultCode (org.openmuc.jdlms.AccessResultCode)1 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 GetResult (org.openmuc.jdlms.GetResult)1 ObisCode (org.openmuc.jdlms.ObisCode)1 SetParameter (org.openmuc.jdlms.SetParameter)1 DlmsHelper (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper)1