use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectCommandExecutor method execute.
@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final ConfigurationObjectDto configurationToSet, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final Protocol protocol = Protocol.forDevice(device);
final GetConfigurationObjectService getService = this.protocolServiceLookup.lookupGetService(protocol);
final ConfigurationObjectDto configurationOnDevice = getService.getConfigurationObject(conn);
final SetConfigurationObjectService setService = this.protocolServiceLookup.lookupSetService(protocol);
return setService.setConfigurationObject(conn, configurationToSet, configurationOnDevice);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigService method getDlmsObjectForCommunicationMethod.
public DlmsObject getDlmsObjectForCommunicationMethod(final DlmsDevice device, final DlmsObjectType type) throws ProtocolAdapterException {
final Protocol protocol = Protocol.forDevice(device);
final CommunicationMethod method = CommunicationMethod.getCommunicationMethod(device.getCommunicationMethod());
return this.dlmsObjectConfigs.stream().filter(config -> config.contains(protocol)).findAny().flatMap(dlmsObjectConfig -> dlmsObjectConfig.findObjectForCommunicationMethod(type, method)).orElseThrow(() -> new ProtocolAdapterException("Did not find " + type.name() + " object with communication method " + method.getMethodName() + " for device " + device.getDeviceId()));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigService method getSelectedValues.
private DataObject getSelectedValues(final AddressRequest addressRequest, final List<DlmsCaptureObject> selectedObjects) {
List<DataObject> objectDefinitions = new ArrayList<>();
final DlmsObject object = addressRequest.getDlmsObject();
final Protocol protocol = Protocol.forDevice(addressRequest.getDevice());
if (object instanceof DlmsProfile && ((DlmsProfile) object).getCaptureObjects() != null) {
final DlmsProfile profile = (DlmsProfile) object;
objectDefinitions = this.getObjectDefinitions(addressRequest.getChannel(), addressRequest.getFilterMedium(), protocol, profile, selectedObjects);
}
return DataObject.newArrayData(objectDefinitions);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method testExecute.
private void testExecute(final Protocol protocol, final PeriodTypeDto type, final boolean useNullData) throws Exception {
// SETUP
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
// Reset stub
this.connectionStub.clearRequestedAttributeAddresses();
// Create device with requested protocol version
final DlmsDevice device = this.createDlmsDevice(protocol);
// Create request object
final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(type, this.timeFrom, this.timeTo);
// Get expected values
final AttributeAddress expectedAddressProfile = this.createAttributeAddress(protocol, type, this.timeFrom, this.timeTo);
final List<AttributeAddress> expectedScalerUnitAddresses = this.getScalerUnitAttributeAddresses(type);
final int expectedTotalNumberOfAttributeAddresses = expectedScalerUnitAddresses.size() + 1;
// Set response in stub
this.setResponseForProfile(expectedAddressProfile, protocol, type, useNullData);
this.setResponsesForScalerUnit(expectedScalerUnitAddresses);
// CALL
final PeriodicMeterReadsResponseDto response = this.executor.execute(this.connectionManagerStub, device, request, messageMetadata);
// VERIFY
// Get resulting requests from connection stub
final List<AttributeAddress> requestedAttributeAddresses = this.connectionStub.getRequestedAttributeAddresses();
assertThat(requestedAttributeAddresses.size()).isEqualTo(expectedTotalNumberOfAttributeAddresses);
// There should be 1 request to the buffer (id = 2) of a profile
// (class-id = 7)
final AttributeAddress actualAttributeAddressProfile = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_PROFILE).collect(Collectors.toList()).get(0);
AttributeAddressAssert.is(actualAttributeAddressProfile, expectedAddressProfile);
// Check the amount of requests to the scaler_units of the meter values
// in the registers
final List<AttributeAddress> attributeAddressesScalerUnit = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_REGISTER && a.getId() == this.ATTR_ID_SCALER_UNIT).collect(Collectors.toList());
assertThat(attributeAddressesScalerUnit.size()).isEqualTo(expectedScalerUnitAddresses.size());
// Check response
assertThat(response.getPeriodType()).isEqualTo(type);
final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads = response.getPeriodicMeterReads();
assertThat(periodicMeterReads.size()).isEqualTo(this.AMOUNT_OF_PERIODS);
this.checkClockValues(periodicMeterReads, type, useNullData);
this.checkValues(periodicMeterReads, type);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class SetRandomisationSettingsCommandExecutorTest method init.
@BeforeEach
public void init() throws ProtocolAdapterException, IOException {
// SETUP
final Protocol smr51 = Protocol.SMR_5_1;
this.device = this.createDlmsDevice(smr51);
this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
final AttributeAddress address = new AttributeAddress(1, new ObisCode("0.1.94.31.12.255"), 1);
this.dataDto = new SetRandomisationSettingsRequestDataDto(0, 1, 1, 1);
final ConfigurationFlagsDto currentConfigurationFlagsDto = new ConfigurationFlagsDto(this.getFlags());
final ConfigurationObjectDto currentConfigurationObjectDto = new ConfigurationObjectDto(currentConfigurationFlagsDto);
when(this.protocolServiceLookup.lookupGetService(smr51)).thenReturn(this.getConfigurationObjectService);
when(this.protocolServiceLookup.lookupSetService(smr51)).thenReturn(this.setConfigurationObjectService);
when(this.getConfigurationObjectService.getConfigurationObject(this.dlmsConnectionManager)).thenReturn(currentConfigurationObjectDto);
when(this.setConfigurationObjectService.setConfigurationObject(any(DlmsConnectionManager.class), any(ConfigurationObjectDto.class), any(ConfigurationObjectDto.class))).thenReturn(AccessResultCode.SUCCESS);
when(this.dlmsObjectConfigService.getAttributeAddress(this.device, DlmsObjectType.RANDOMISATION_SETTINGS, null)).thenReturn(address);
when(this.dlmsConnectionManager.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
}
Aggregations