Search in sources :

Example 11 with ChannelElementValuesDto

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

the class FindMatchingChannelHelperTest method testAllAttributesInRequestOnlySomeInRetrievedValues.

@Test
public void testAllAttributesInRequestOnlySomeInRetrievedValues() {
    final MbusChannelElementsDto requestData = new MbusChannelElementsDto(this.primaryAddress, this.deviceIdentification, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceTypeIdentification);
    final ChannelElementValuesDto channelValues = new ChannelElementValuesDto(this.channel, this.primaryAddress, this.identificationNumber, this.noManufacturerIdentification, this.noVersion, this.noDeviceTypeIdentification);
    assertThat(FindMatchingChannelHelper.matches(requestData, channelValues)).withFailMessage(requestData + " should not match " + channelValues).isFalse();
    assertThat(FindMatchingChannelHelper.matchesPartially(requestData, channelValues)).withFailMessage(requestData + " should match partially " + channelValues).isTrue();
    final List<ChannelElementValuesDto> channelValuesList = Arrays.asList(channelValues);
    assertThat(FindMatchingChannelHelper.bestMatch(requestData, channelValuesList)).withFailMessage(requestData + " should have a best match from " + channelValuesList).isNotNull();
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MbusChannelElementsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto) Test(org.junit.jupiter.api.Test)

Example 12 with ChannelElementValuesDto

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

the class FindMatchingChannelHelperTest method testAllAttributesInRequestOnlyPrimaryAddressInRetrievedValues.

@Test
public void testAllAttributesInRequestOnlyPrimaryAddressInRetrievedValues() {
    final MbusChannelElementsDto requestData = new MbusChannelElementsDto(this.primaryAddress, this.deviceIdentification, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceTypeIdentification);
    final ChannelElementValuesDto channelValues = new ChannelElementValuesDto(this.channel, this.primaryAddress, this.noIdentificationNumber, this.noManufacturerIdentification, this.noVersion, this.noDeviceTypeIdentification);
    assertThat(FindMatchingChannelHelper.matches(requestData, channelValues)).withFailMessage(requestData + " should not match " + channelValues).isFalse();
    assertThat(FindMatchingChannelHelper.matchesPartially(requestData, channelValues)).withFailMessage(requestData + " should match partially " + channelValues).isTrue();
    final List<ChannelElementValuesDto> channelValuesList = Arrays.asList(channelValues);
    assertThat(FindMatchingChannelHelper.bestMatch(requestData, channelValuesList)).withFailMessage(requestData + " should have a best match from " + channelValuesList).isNotNull();
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MbusChannelElementsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto) Test(org.junit.jupiter.api.Test)

Example 13 with ChannelElementValuesDto

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

the class ConfigurationService method getMbusKeyExchangeData.

public GMeterInfoDto getMbusKeyExchangeData(final DlmsConnectionManager conn, final DlmsDevice device, final SetMbusUserKeyByChannelRequestDataDto setMbusUserKeyByChannelRequestData, final MessageMetadata messageMetadata) throws OsgpException {
    final GetMBusDeviceOnChannelRequestDataDto mbusDeviceOnChannelRequest = new GetMBusDeviceOnChannelRequestDataDto(device.getDeviceIdentification(), setMbusUserKeyByChannelRequestData.getChannel());
    final ChannelElementValuesDto channelElementValues = this.getMBusDeviceOnChannelCommandExecutor.execute(conn, device, mbusDeviceOnChannelRequest, messageMetadata);
    final DlmsDevice mbusDevice = this.domainHelperService.findMbusDevice(channelElementValues.getIdentificationNumber(), channelElementValues.getManufacturerIdentification());
    return new GMeterInfoDto(setMbusUserKeyByChannelRequestData.getChannel(), mbusDevice.getDeviceIdentification());
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) GMeterInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) GetMBusDeviceOnChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)

Example 14 with ChannelElementValuesDto

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

the class DeviceChannelsHelper method writeUpdatedMbus.

protected ChannelElementValuesDto writeUpdatedMbus(final DlmsConnectionManager conn, final DlmsDevice device, final MbusChannelElementsDto requestDto, final short channel, final String executorName) throws ProtocolAdapterException {
    final DlmsObject mbusClientSetupObject = this.dlmsObjectConfigService.getDlmsObject(device, DlmsObjectType.MBUS_CLIENT_SETUP);
    final ObisCode obiscode = mbusClientSetupObject.getObisCodeWithChannel(channel);
    final int classId = mbusClientSetupObject.getClassId();
    final DataObject identificationNumberDataObject;
    if (this.identificationNumberStoredAsBcdOnDevice(mbusClientSetupObject)) {
        identificationNumberDataObject = IdentificationNumber.fromTextualRepresentation(requestDto.getMbusIdentificationNumber()).asDataObjectInBcdRepresentation();
    } else {
        identificationNumberDataObject = IdentificationNumber.fromTextualRepresentation(requestDto.getMbusIdentificationNumber()).asDataObject();
    }
    final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors(executorName).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.IDENTIFICATION_NUMBER, identificationNumberDataObject, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.MANUFACTURER_ID, ManufacturerId.fromIdentification(requestDto.getMbusManufacturerIdentification()).asDataObject(), obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.VERSION, DataObject.newUInteger8Data(requestDto.getMbusVersion()), obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.DEVICE_TYPE, DataObject.newUInteger8Data(requestDto.getMbusDeviceTypeIdentification()), obiscode, classId));
    if (requestDto.getPrimaryAddress() != null) {
        dataObjectExecutors.addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.PRIMARY_ADDRESS, DataObject.newUInteger8Data(requestDto.getPrimaryAddress()), obiscode, classId));
    }
    conn.getDlmsMessageListener().setDescription(String.format("Write updated MBus attributes to channel %d, set attributes: %s", channel, dataObjectExecutors.describeAttributes()));
    dataObjectExecutors.execute(conn);
    log.info("Finished coupling the mbus device to the gateway device");
    return new ChannelElementValuesDto(channel, requestDto.getPrimaryAddress(), requestDto.getMbusIdentificationNumber(), requestDto.getMbusManufacturerIdentification(), requestDto.getMbusVersion(), requestDto.getMbusDeviceTypeIdentification());
}
Also used : DataObjectAttrExecutors(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors) ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) ObisCode(org.openmuc.jdlms.ObisCode) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)

Example 15 with ChannelElementValuesDto

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

the class GetMbusEncryptionKeyStatusByChannelCommandExecutor method execute.

@Override
public GetMbusEncryptionKeyStatusByChannelResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetMbusEncryptionKeyStatusByChannelRequestDataDto request, final MessageMetadata messageMetadata) throws OsgpException {
    final GetMBusDeviceOnChannelRequestDataDto mbusDeviceOnChannelRequest = new GetMBusDeviceOnChannelRequestDataDto(device.getDeviceIdentification(), request.getChannel());
    final ChannelElementValuesDto channelElementValues = this.getMBusDeviceOnChannelCommandExecutor.execute(conn, device, mbusDeviceOnChannelRequest, messageMetadata);
    if (!channelElementValues.hasChannel() || !channelElementValues.hasDeviceTypeIdentification() || !channelElementValues.hasManufacturerIdentification()) {
        throw new FunctionalException(FunctionalExceptionType.NO_DEVICE_FOUND_ON_CHANNEL, ComponentType.DOMAIN_SMART_METERING);
    }
    final EncryptionKeyStatusTypeDto encryptionKeyStatusType = this.getMbusEncryptionKeyStatusCommandExecutor.getEncryptionKeyStatusTypeDto(request.getChannel(), conn);
    return new GetMbusEncryptionKeyStatusByChannelResponseDto(device.getDeviceIdentification(), encryptionKeyStatusType, request.getChannel());
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) EncryptionKeyStatusTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EncryptionKeyStatusTypeDto) GetMbusEncryptionKeyStatusByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMbusEncryptionKeyStatusByChannelResponseDto) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) GetMBusDeviceOnChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)

Aggregations

ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)23 Test (org.junit.jupiter.api.Test)14 MbusChannelElementsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto)7 ArrayList (java.util.ArrayList)4 GetResult (org.openmuc.jdlms.GetResult)3 ObisCode (org.openmuc.jdlms.ObisCode)3 GetMBusDeviceOnChannelRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)3 CosemObjectAccessor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 CoupleMbusDeviceByChannelResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto)2 DecoupleMbusDeviceResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto)2 MbusChannelElementsResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)1 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)1 DataObjectAttrExecutors (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors)1 EncryptionKeyStatusTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EncryptionKeyStatusTypeDto)1 GMeterInfoDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto)1