Search in sources :

Example 26 with DlmsDevice

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);
}
Also used : GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test)

Example 27 with DlmsDevice

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;
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

Example 28 with DlmsDevice

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());
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 29 with DlmsDevice

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));
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SetParameter(org.openmuc.jdlms.SetParameter) MethodParameter(org.openmuc.jdlms.MethodParameter) Test(org.junit.jupiter.api.Test)

Example 30 with DlmsDevice

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);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) Test(org.junit.jupiter.api.Test)

Aggregations

DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)103 Test (org.junit.jupiter.api.Test)58 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)24 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)17 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)17 AttributeAddress (org.openmuc.jdlms.AttributeAddress)15 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)13 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)10 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)10 Then (io.cucumber.java.en.Then)9 DataObject (org.openmuc.jdlms.datatypes.DataObject)7 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Instant (java.time.Instant)5 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)5 IOException (java.io.IOException)4 Date (java.util.Date)4 List (java.util.List)4 ThrowableAssert.catchThrowable (org.assertj.core.api.ThrowableAssert.catchThrowable)4 SetParameter (org.openmuc.jdlms.SetParameter)4