Search in sources :

Example 16 with ChannelElementValuesDto

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

the class CoupleMBusDeviceCommandExecutor method execute.

@Override
public MbusChannelElementsResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final MbusChannelElementsDto requestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    log.debug("retrieving mbus info on e-meter");
    final List<ChannelElementValuesDto> candidateChannelElementValues = this.deviceChannelsHelper.findCandidateChannelsForDevice(conn, device, requestDto);
    final ChannelElementValuesDto lastChannelElementValuesRetrieved = candidateChannelElementValues.get(candidateChannelElementValues.size() - 1);
    if (FindMatchingChannelHelper.matches(requestDto, lastChannelElementValuesRetrieved)) {
        /*
       * Match found, indicating device is already coupled on this
       * channel: return it.
       */
        return new MbusChannelElementsResponseDto(requestDto, lastChannelElementValuesRetrieved.getChannel(), candidateChannelElementValues);
    }
    final ChannelElementValuesDto bestMatch = FindMatchingChannelHelper.bestMatch(requestDto, candidateChannelElementValues);
    if (bestMatch != null) {
        /*
       * Good enough match found indicating a channel the device is
       * already coupled on: return it.
       */
        return new MbusChannelElementsResponseDto(requestDto, bestMatch.getChannel(), candidateChannelElementValues);
    }
    final ChannelElementValuesDto emptyChannelMatch = this.deviceChannelsHelper.findEmptyChannel(candidateChannelElementValues);
    if (emptyChannelMatch == null) {
        /*
       * No channel free, all are occupied by M-Bus devices not matching
       * the one to be coupled here. Return null for the channel.
       */
        return new MbusChannelElementsResponseDto(requestDto, null, candidateChannelElementValues);
    }
    /*
     * If a free channel is found, write the attribute values from the
     * request to the M-Bus Client Setup for this channel.
     *
     * Note that this will not work for wired M-Bus devices. In order to
     * properly couple a wired M-Bus device the M-Bus Client Setup
     * slave_install method needs to be invoked so a primary_address is set
     * and its value is transferred to the M-Bus slave device.
     */
    final ChannelElementValuesDto updatedChannelElementValues = this.deviceChannelsHelper.writeUpdatedMbus(conn, device, requestDto, emptyChannelMatch.getChannel(), "CoupleMBusDevice");
    /*
     * Also update the entry in the candidateChannelElementValues list. Take
     * into account that the candidateChannelElementsValues List is 0-based,
     * while the channel in emptyChannelMatch is not
     */
    candidateChannelElementValues.set(this.deviceChannelsHelper.correctFirstChannelOffset(emptyChannelMatch), updatedChannelElementValues);
    return new MbusChannelElementsResponseDto(requestDto, updatedChannelElementValues.getChannel(), candidateChannelElementValues);
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MbusChannelElementsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto)

Example 17 with ChannelElementValuesDto

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

the class FindMatchingChannelHelperTest method testAllAttributesInRequestNoneInRetrievedValues.

@Test
public void testAllAttributesInRequestNoneInRetrievedValues() {
    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.noPrimaryAddress, 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 not match partially " + channelValues).isFalse();
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MbusChannelElementsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto) Test(org.junit.jupiter.api.Test)

Example 18 with ChannelElementValuesDto

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

the class FindMatchingChannelHelperTest method testValuesBestMatchingToRequestShouldBePicked.

@Test
public void testValuesBestMatchingToRequestShouldBePicked() {
    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.manufacturerIdentification, this.version, this.deviceTypeIdentification);
    final ChannelElementValuesDto otherChannelValues = new ChannelElementValuesDto(this.otherChannel, this.otherPrimaryAddress, this.otherIdentificationNumber, this.otherManufacturerIdentification, this.otherVersion, this.otherDeviceTypeIdentification);
    final ChannelElementValuesDto partiallyMatchingChannelValues = new ChannelElementValuesDto((short) 3, (short) 3, this.noIdentificationNumber, this.manufacturerIdentification, this.version, this.deviceTypeIdentification);
    assertThat(FindMatchingChannelHelper.matches(requestData, channelValues)).withFailMessage(requestData + " should match " + channelValues).isTrue();
    assertThat(FindMatchingChannelHelper.matches(requestData, otherChannelValues)).withFailMessage(requestData + " should not match " + otherChannelValues).isFalse();
    assertThat(FindMatchingChannelHelper.matches(requestData, partiallyMatchingChannelValues)).withFailMessage(requestData + " should not match " + partiallyMatchingChannelValues).isFalse();
    assertThat(FindMatchingChannelHelper.matchesPartially(requestData, channelValues)).withFailMessage(requestData + " should match partially " + channelValues).isTrue();
    assertThat(FindMatchingChannelHelper.matchesPartially(requestData, otherChannelValues)).withFailMessage(requestData + " should not match partially " + otherChannelValues).isFalse();
    assertThat(FindMatchingChannelHelper.matchesPartially(requestData, partiallyMatchingChannelValues)).withFailMessage(requestData + " should match partially " + partiallyMatchingChannelValues).isTrue();
    final List<ChannelElementValuesDto> channelValuesList = Arrays.asList(partiallyMatchingChannelValues, otherChannelValues, channelValues);
    final ChannelElementValuesDto bestMatch = FindMatchingChannelHelper.bestMatch(requestData, channelValuesList);
    assertThat(bestMatch).withFailMessage(requestData + " should have a best match from " + channelValuesList).isNotNull();
    assertThat(bestMatch.getChannel()).withFailMessage("Channel for best match").isEqualTo(channelValues.getChannel());
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MbusChannelElementsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto) Test(org.junit.jupiter.api.Test)

Example 19 with ChannelElementValuesDto

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

the class DeviceChannelsHelperTest method testGetChannelElementValuesDsmr4.

@Test
void testGetChannelElementValuesDsmr4() throws Exception {
    final List<GetResult> resultList = new ArrayList<>(Arrays.asList(this.primaryAddress, this.identificationNumberInBcd, this.manufacturerIdentification, this.version, this.deviceType));
    when(this.device.isWithListSupported()).thenReturn(true);
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.get(anyList())).thenReturn(resultList);
    when(this.device.getProtocolName()).thenReturn("DSMR");
    when(this.device.getProtocolVersion()).thenReturn("4.2.2");
    final ChannelElementValuesDto values = this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, (short) 1);
    assertThat(values.getPrimaryAddress()).isEqualTo(PRIMARY_ADDRESS);
    assertThat(values.getIdentificationNumber()).isEqualTo(IDENTIFICATION_NUMBER_AS_STRING);
    assertThat(values.getManufacturerIdentification()).isEqualTo(MANUFACTURER_IDENTIFICATION_AS_TEXT);
    assertThat(values.getVersion()).isEqualTo(VERSION);
    assertThat(values.getDeviceTypeIdentification()).isEqualTo(DEVICE_TYPE);
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 20 with ChannelElementValuesDto

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

the class DeviceChannelsHelperTest method testFindEmptyChannel.

@Test
public void testFindEmptyChannel() {
    final ChannelElementValuesDto emptyChannel = new ChannelElementValuesDto((short) 1, (short) 0, "00000000", null, (short) 0, (short) 0);
    final ChannelElementValuesDto nonEmptyChannel = new ChannelElementValuesDto((short) 2, (short) 0, "12345678", null, (short) 0, (short) 0);
    final ChannelElementValuesDto result = this.deviceChannelsHelper.findEmptyChannel(Arrays.asList(nonEmptyChannel, emptyChannel));
    assertThat(result).isEqualTo(emptyChannel);
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) Test(org.junit.jupiter.api.Test)

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