use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceCommandExecutorTest method testNoMatchAndNoEmptyChannel.
@Test
public void testNoMatchAndNoEmptyChannel() throws ProtocolAdapterException {
final MbusChannelElementsDto mbusChannelElementsDto = new MbusChannelElementsDto((short) -1, "noMatch", "noMatch", "noMatch", (short) -1, (short) -1);
when(this.deviceChannelsHelper.findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class))).thenReturn(this.candidateChannelElementValues);
final MbusChannelElementsResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, mbusChannelElementsDto, this.messageMetadata);
assertThat(responseDto.getChannel()).isNull();
assertThat(responseDto.getRetrievedChannelElements().get(0).getDeviceTypeIdentification()).isEqualTo(this.deviceTypeIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getIdentificationNumber()).isEqualTo(this.identificationNumber);
assertThat(responseDto.getRetrievedChannelElements().get(0).getManufacturerIdentification()).isEqualTo(this.manufacturerIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getPrimaryAddress()).isEqualTo(this.primaryAddress);
assertThat(responseDto.getRetrievedChannelElements().get(0).getVersion()).isEqualTo(this.version);
verify(this.deviceChannelsHelper, times(1)).findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceCommandExecutorTest method testExactMatch.
@Test
public void testExactMatch() throws ProtocolAdapterException {
final MbusChannelElementsDto mbusChannelElementsDto = new MbusChannelElementsDto(this.primaryAddress, this.mbusDeviceIdentification, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceTypeIdentification);
when(this.deviceChannelsHelper.findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class))).thenReturn(this.candidateChannelElementValues);
final MbusChannelElementsResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, mbusChannelElementsDto, this.messageMetadata);
assertThat(responseDto.getChannel()).isEqualTo(this.channel);
assertThat(responseDto.getRetrievedChannelElements().get(0).getDeviceTypeIdentification()).isEqualTo(this.deviceTypeIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getIdentificationNumber()).isEqualTo(this.identificationNumber);
assertThat(responseDto.getRetrievedChannelElements().get(0).getManufacturerIdentification()).isEqualTo(this.manufacturerIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getPrimaryAddress()).isEqualTo(this.primaryAddress);
assertThat(responseDto.getRetrievedChannelElements().get(0).getVersion()).isEqualTo(this.version);
verify(this.deviceChannelsHelper, times(1)).findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto 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);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceCommandExecutorTest method testNoMatchButEmptyChannel.
@Test
public void testNoMatchButEmptyChannel() throws ProtocolAdapterException {
// Add empty channel to the list of candidate channels
final ChannelElementValuesDto emptyChannel = new ChannelElementValuesDto((short) 2, (short) 0, "00000000", null, (short) 0, (short) 0);
final List<ChannelElementValuesDto> candidateChannelElementValuesWithEmptyChannel = Arrays.asList(this.candidateChannelElementValues.get(0), emptyChannel);
final MbusChannelElementsDto mbusChannelElementsDto = new MbusChannelElementsDto((short) -1, "noMatch", "noMatch", "noMatch", (short) -1, (short) -1);
when(this.deviceChannelsHelper.findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class))).thenReturn(candidateChannelElementValuesWithEmptyChannel);
when(this.deviceChannelsHelper.findEmptyChannel(candidateChannelElementValuesWithEmptyChannel)).thenReturn(emptyChannel);
when(this.deviceChannelsHelper.writeUpdatedMbus(eq(this.conn), eq(this.device), eq(mbusChannelElementsDto), eq(emptyChannel.getChannel()), any(String.class))).thenReturn(new ChannelElementValuesDto(emptyChannel.getChannel(), mbusChannelElementsDto.getPrimaryAddress(), mbusChannelElementsDto.getMbusIdentificationNumber(), mbusChannelElementsDto.getMbusManufacturerIdentification(), mbusChannelElementsDto.getMbusVersion(), mbusChannelElementsDto.getMbusDeviceTypeIdentification()));
when(this.deviceChannelsHelper.correctFirstChannelOffset(any(ChannelElementValuesDto.class))).thenReturn((short) (emptyChannel.getChannel() - 1));
final MbusChannelElementsResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, mbusChannelElementsDto, this.messageMetadata);
assertThat(responseDto.getChannel()).isEqualTo((short) 2);
assertThat(responseDto.getRetrievedChannelElements().get(0).getDeviceTypeIdentification()).isEqualTo(this.deviceTypeIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getIdentificationNumber()).isEqualTo(this.identificationNumber);
assertThat(responseDto.getRetrievedChannelElements().get(0).getManufacturerIdentification()).isEqualTo(this.manufacturerIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getPrimaryAddress()).isEqualTo(this.primaryAddress);
assertThat(responseDto.getRetrievedChannelElements().get(0).getVersion()).isEqualTo(this.version);
verify(this.deviceChannelsHelper, times(1)).findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceCommandExecutorTest method testBestMatch.
@Test
public void testBestMatch() throws ProtocolAdapterException {
final MbusChannelElementsDto mbusChannelElementsDto = new MbusChannelElementsDto((short) 8, this.mbusDeviceIdentification, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceTypeIdentification);
when(this.deviceChannelsHelper.findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class))).thenReturn(this.candidateChannelElementValues);
final MbusChannelElementsResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, mbusChannelElementsDto, this.messageMetadata);
assertThat(responseDto.getChannel()).isEqualTo(this.channel);
assertThat(responseDto.getRetrievedChannelElements().get(0).getDeviceTypeIdentification()).isEqualTo(this.deviceTypeIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getIdentificationNumber()).isEqualTo(this.identificationNumber);
assertThat(responseDto.getRetrievedChannelElements().get(0).getManufacturerIdentification()).isEqualTo(this.manufacturerIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getPrimaryAddress()).isEqualTo(this.primaryAddress);
assertThat(responseDto.getRetrievedChannelElements().get(0).getVersion()).isEqualTo(this.version);
verify(this.deviceChannelsHelper, times(1)).findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class));
}
Aggregations