use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectCommandExecutorSmr5IT method execute.
@Test
public void execute() throws IOException, ProtocolAdapterException {
// SETUP
// configurationToSet: ------1---10101-
// GPRS operation mode is not part of the ConfigurationObject in SMR5
final GprsOperationModeTypeDto gprsMode = null;
final ConfigurationObjectDto configurationToSet = this.createConfigurationObjectDto(gprsMode, this.createFlagDto(ConfigurationFlagTypeDto.HLS_5_ON_P_3_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.DIRECT_ATTACH_AT_POWER_ON, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_6_ON_P3_ENABLE, false), this.createFlagDto(ConfigurationFlagTypeDto.HLS_7_ON_P3_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_6_ON_P0_ENABLE, false), this.createFlagDto(ConfigurationFlagTypeDto.HLS_7_ON_P0_ENABLE, true));
// flagsOnDevice: 0000000001110100
final byte[] flagsOnDevice = this.createFlagBytes(ConfigurationFlagTypeDto.HLS_5_ON_PO_ENABLE, ConfigurationFlagTypeDto.DIRECT_ATTACH_AT_POWER_ON, ConfigurationFlagTypeDto.HLS_6_ON_P3_ENABLE, ConfigurationFlagTypeDto.HLS_6_ON_P0_ENABLE);
// result of merging configurationToSet and flagsOnDevice
final byte firstExpectedByte = this.asByte("00000010");
final byte secondExpectedByte = this.asByte("01101010");
final DataObject deviceData = this.createBitStringData(flagsOnDevice);
when(this.getResult.getResultData()).thenReturn(deviceData);
final DlmsDevice device = new DlmsDevice();
device.setProtocol(Protocol.SMR_5_0_0);
// CALL
final AccessResultCode result = this.instance.execute(this.conn, device, configurationToSet, this.messageMetadata);
// VERIFY
assertThat(result).isEqualTo(AccessResultCode.SUCCESS);
final BitString configurationFlags = this.captureSetParameterBitStringData();
final byte[] flagsSentToDevice = configurationFlags.getBitString();
assertThat(flagsSentToDevice[0]).isEqualTo(firstExpectedByte);
assertThat(flagsSentToDevice[1]).isEqualTo(secondExpectedByte);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class SetRandomisationSettingsCommandExecutorTest method createDlmsDevice.
private DlmsDevice createDlmsDevice(final Protocol protocol) {
final DlmsDevice device = new DlmsDevice();
device.setProtocol(protocol);
device.setSelectiveAccessSupported(true);
return device;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class ClearMBusStatusOnAllChannelsCommandExecutorTest method shouldExecuteForProtocol_SMR_5_1.
@Test
void shouldExecuteForProtocol_SMR_5_1() throws ProtocolAdapterException, IOException {
final DlmsDevice dlmsDevice_5_1 = new DlmsDevice("SMR 5.1 device");
dlmsDevice_5_1.setProtocol("SMR", "5.1");
for (int channel = 1; channel <= 4; channel++) {
when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice_5_1, DlmsObjectType.READ_MBUS_STATUS, channel)).thenReturn(new AttributeAddress(InterfaceClass.EXTENDED_REGISTER.id(), OBIS_CODE_TEMPLATE_READ_STATUS.replaceAll("<c>", Integer.toString(channel)), ExtendedRegisterAttribute.VALUE.attributeId()));
when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice_5_1, DlmsObjectType.CLEAR_MBUS_STATUS, channel)).thenReturn(new AttributeAddress(InterfaceClass.DATA.id(), OBIS_CODE_TEMPLATE_CLEAR_STATUS.replaceAll("<c>", Integer.toString(channel)), DataAttribute.VALUE.attributeId()));
when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice_5_1, DlmsObjectType.CLIENT_SETUP_MBUS, channel)).thenReturn(new AttributeAddress(InterfaceClass.MBUS_CLIENT.id(), OBIS_CODE_TEMPLATE_MBUS_CLIENT_SETUP.replaceAll("<c>", Integer.toString(channel)), DataAttribute.VALUE.attributeId()));
}
when(this.connectionManager.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.connectionManager.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.get(this.attributeAddressArgumentCaptor.capture())).thenReturn(this.getResult);
when(this.getResult.getResultData()).thenReturn(DataObject.newUInteger32Data(STATUS_MASK));
when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(AccessResultCode.SUCCESS);
when(this.methodResult.getResultCode()).thenReturn(MethodResultCode.SUCCESS);
when(this.dlmsConnection.action(this.methodParameterArgumentCaptor.capture())).thenReturn(this.methodResult);
this.executor.execute(this.connectionManager, dlmsDevice_5_1, this.dto, this.messageMetadata);
this.assertCurrentStatusAttributeAddresses(this.attributeAddressArgumentCaptor.getAllValues());
this.assertClearStatus(this.setParameterArgumentCaptor.getAllValues());
this.assertMethodResetAlarm(this.methodParameterArgumentCaptor.getAllValues());
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class ClearMBusStatusOnAllChannelsCommandExecutorTest method shouldSkipIfStatusIsZero.
@Test
void shouldSkipIfStatusIsZero() throws ProtocolAdapterException, IOException {
final DlmsDevice dlmsDevice_5_1 = new DlmsDevice("SMR 5.1 device");
dlmsDevice_5_1.setProtocol("SMR", "5.1");
for (int channel = 1; channel <= 4; channel++) {
when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice_5_1, DlmsObjectType.READ_MBUS_STATUS, channel)).thenReturn(new AttributeAddress(InterfaceClass.EXTENDED_REGISTER.id(), OBIS_CODE_TEMPLATE_READ_STATUS.replaceAll("<c>", Integer.toString(channel)), ExtendedRegisterAttribute.VALUE.attributeId()));
when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice_5_1, DlmsObjectType.CLEAR_MBUS_STATUS, channel)).thenReturn(new AttributeAddress(InterfaceClass.DATA.id(), OBIS_CODE_TEMPLATE_CLEAR_STATUS.replaceAll("<c>", Integer.toString(channel)), DataAttribute.VALUE.attributeId()));
when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice_5_1, DlmsObjectType.CLIENT_SETUP_MBUS, channel)).thenReturn(new AttributeAddress(InterfaceClass.MBUS_CLIENT.id(), OBIS_CODE_TEMPLATE_MBUS_CLIENT_SETUP.replaceAll("<c>", Integer.toString(channel)), DataAttribute.VALUE.attributeId()));
}
when(this.connectionManager.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.connectionManager.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.get(this.attributeAddressArgumentCaptor.capture())).thenReturn(this.getResult);
when(this.getResult.getResultData()).thenReturn(DataObject.newUInteger32Data(0L));
this.executor.execute(this.connectionManager, dlmsDevice_5_1, this.dto, this.messageMetadata);
this.assertCurrentStatusAttributeAddresses(this.attributeAddressArgumentCaptor.getAllValues());
verify(this.dlmsConnection, never()).set(any(SetParameter.class));
verify(this.dlmsConnection, never()).action(any(MethodParameter.class));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectCommandExecutorTest method execute.
@Test
public void execute() throws ProtocolAdapterException {
// SETUP
final DlmsDevice device = new DlmsDevice();
final Protocol protocol = Protocol.DSMR_4_2_2;
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
device.setProtocol(protocol);
when(this.protocolServiceLookup.lookupGetService(protocol)).thenReturn(this.getService);
when(this.getService.getConfigurationObject(this.conn)).thenReturn(this.configurationObjectDto);
// CALL
final ConfigurationObjectDto result = this.instance.execute(this.conn, device, null, messageMetadata);
// VERIFY
assertThat(result).isSameAs(this.configurationObjectDto);
}
Aggregations