Search in sources :

Example 21 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.

the class DlmsHelperTest method testGetWithListWorkaround.

@Test
public void testGetWithListWorkaround() throws ProtocolAdapterException, IOException {
    final DlmsConnection dlmsConnection = mock(DlmsConnection.class);
    final DlmsConnectionManager connectionManager = mock(DlmsConnectionManager.class);
    final DlmsDevice dlmsDevice = mock(DlmsDevice.class);
    when(connectionManager.getConnection()).thenReturn(dlmsConnection);
    final AttributeAddress[] attrAddresses = new AttributeAddress[1];
    attrAddresses[0] = mock(AttributeAddress.class);
    when(dlmsDevice.isWithListSupported()).thenReturn(false);
    this.dlmsHelper.getWithList(connectionManager, dlmsDevice, attrAddresses);
    verify(dlmsConnection).get(attrAddresses[0]);
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsConnection(org.openmuc.jdlms.DlmsConnection) Test(org.junit.jupiter.api.Test)

Example 22 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress 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);
}
Also used : SetRandomisationSettingsRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetRandomisationSettingsRequestDataDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ObisCode(org.openmuc.jdlms.ObisCode) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) SetParameter(org.openmuc.jdlms.SetParameter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress 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 24 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress 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 25 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutorTest method setupAlarmRegister1.

void setupAlarmRegister1(final DlmsDevice dlmsDevice) throws ProtocolAdapterException, IOException {
    dlmsDevice.setProtocol("SMR", "5.2");
    when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice, DlmsObjectType.ALARM_REGISTER_1, null)).thenReturn(new AttributeAddress(InterfaceClass.DATA.id(), OBIS_CODE_ALARM_REGISTER_1, DataAttribute.VALUE.attributeId()));
    when(this.connectionManager.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.connectionManager.getConnection()).thenReturn(this.dlmsConnection);
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress)

Aggregations

AttributeAddress (org.openmuc.jdlms.AttributeAddress)77 DataObject (org.openmuc.jdlms.datatypes.DataObject)38 ObisCode (org.openmuc.jdlms.ObisCode)18 Test (org.junit.jupiter.api.Test)16 GetResult (org.openmuc.jdlms.GetResult)16 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)16 SetParameter (org.openmuc.jdlms.SetParameter)15 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)14 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)8 DateTime (org.joda.time.DateTime)7 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)6 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)6 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)6 Collectors (java.util.stream.Collectors)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5