use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceByChannelCommandExecutor method execute.
@Override
public CoupleMbusDeviceByChannelResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final CoupleMbusDeviceByChannelRequestDataDto requestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
log.info("Retrieving values for mbus channel {} on device {}", requestDto.getChannel(), device.getDeviceIdentification());
final ChannelElementValuesDto channelElementValuesDto = this.deviceChannelsHelper.getChannelElementValues(conn, device, requestDto.getChannel());
/*
* Couple M-Bus device by channel is created to couple the M-Bus device
* in the platform based on a new M-Bus device discovered alarm for a
* particular channel. As such there is no write action to the M-Bus
* Client Setup involved, since the platform depends on the attributes
* on the gateway device to be able to determine which M-Bus device was
* actually involved when the alarm was triggered for the channel from
* the request.
*/
return new CoupleMbusDeviceByChannelResponseDto(channelElementValuesDto);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class DecoupleMBusDeviceCommandExecutor method execute.
@Override
public DecoupleMbusDeviceResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final DecoupleMbusDeviceDto decoupleMbusDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final Short channel = decoupleMbusDto.getChannel();
log.debug("Decouple channel {} on gateway device {}", channel, device.getDeviceIdentification());
final ObisCode obisCode = this.deviceChannelsHelper.getObisCode(device, channel);
// Get the current channel element values before resetting the channel
final ChannelElementValuesDto channelElementValues = this.deviceChannelsHelper.getChannelElementValues(conn, device, channel);
// Deinstall and reset channel
final CosemObjectAccessor mBusSetup = new CosemObjectAccessor(conn, obisCode, InterfaceClass.MBUS_CLIENT.id());
this.deviceChannelsHelper.deinstallSlave(conn, device, channel, mBusSetup);
this.deviceChannelsHelper.resetMBusClientAttributeValues(conn, device, channel, this.getClass().getSimpleName());
// return the channel element values as before decoupling
return new DecoupleMbusDeviceResponseDto(channelElementValues);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class DeviceChannelsHelper method findCandidateChannelsForDevice.
public List<ChannelElementValuesDto> findCandidateChannelsForDevice(final DlmsConnectionManager conn, final DlmsDevice device, final MbusChannelElementsDto requestDto) throws ProtocolAdapterException {
final List<ChannelElementValuesDto> channelElementValuesList = new ArrayList<>();
for (short channel = FIRST_CHANNEL; channel < FIRST_CHANNEL + NR_OF_CHANNELS; channel++) {
final ChannelElementValuesDto channelElementValues = this.getChannelElementValues(conn, device, channel);
channelElementValuesList.add(channelElementValues);
if (requestDto != null && FindMatchingChannelHelper.matches(requestDto, channelElementValues)) {
/*
* A complete match for all attributes from the request has been
* found. Stop retrieving M-Bus Client Setup attributes for
* other channels. Return a list returning the values retrieved
* so far and don't retrieve any additional M-Bus Client Setup
* data from the device.
*/
return channelElementValuesList;
}
}
/*
* A complete match for all attributes from the request has not been
* found. The best partial match that has no conflicting attribute
* values, or the first free channel has to be picked from this list.
*/
return channelElementValuesList;
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class FindMatchingChannelHelperTest method testAllFilled.
@Test
public void testAllFilled() {
/*
* All attributes for requestData and channelValues are defined and
* matching.
*/
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);
assertThat(FindMatchingChannelHelper.matches(requestData, channelValues)).withFailMessage(requestData + " should match " + channelValues).isTrue();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class FindMatchingChannelHelperTest method testNoAttributesInRequestAllInRetrievedValues.
@Test
public void testNoAttributesInRequestAllInRetrievedValues() {
final MbusChannelElementsDto requestData = new MbusChannelElementsDto(this.primaryAddress, this.deviceIdentification, this.noIdentificationNumber, this.noManufacturerIdentification, null, null);
final ChannelElementValuesDto channelValues = new ChannelElementValuesDto(this.channel, this.primaryAddress, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceTypeIdentification);
assertThat(FindMatchingChannelHelper.matches(requestData, channelValues)).withFailMessage(requestData + " should match " + channelValues).isTrue();
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();
}
Aggregations