Search in sources :

Example 11 with AttributeAddress

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

the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method getScalerUnitAttributeAddresses.

private List<AttributeAddress> getScalerUnitAttributeAddresses(final PeriodTypeDto type) throws Exception {
    final List<AttributeAddress> attributeAddresses = new ArrayList<>();
    switch(type) {
        case MONTHLY:
        case DAILY:
            attributeAddresses.add(new AttributeAddress(this.CLASS_ID_REGISTER, this.OBIS_ACTIVE_ENERGY_IMPORT_RATE_1, this.ATTR_ID_SCALER_UNIT, null));
            attributeAddresses.add(new AttributeAddress(this.CLASS_ID_REGISTER, this.OBIS_ACTIVE_ENERGY_IMPORT_RATE_2, this.ATTR_ID_SCALER_UNIT, null));
            attributeAddresses.add(new AttributeAddress(this.CLASS_ID_REGISTER, this.OBIS_ACTIVE_ENERGY_EXPORT_RATE_1, this.ATTR_ID_SCALER_UNIT, null));
            attributeAddresses.add(new AttributeAddress(this.CLASS_ID_REGISTER, this.OBIS_ACTIVE_ENERGY_EXPORT_RATE_2, this.ATTR_ID_SCALER_UNIT, null));
            break;
        case INTERVAL:
            attributeAddresses.add(new AttributeAddress(this.CLASS_ID_REGISTER, this.OBIS_ACTIVE_ENERGY_IMPORT, this.ATTR_ID_SCALER_UNIT, null));
            attributeAddresses.add(new AttributeAddress(this.CLASS_ID_REGISTER, this.OBIS_ACTIVE_ENERGY_EXPORT, this.ATTR_ID_SCALER_UNIT, null));
            break;
        default:
            throw new Exception("Unexpected period type " + type);
    }
    return attributeAddresses;
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) ArrayList(java.util.ArrayList)

Example 12 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress 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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) DlmsConnectionManagerStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub) Date(java.util.Date) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ArrayList(java.util.ArrayList) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) AttributeAddress(org.openmuc.jdlms.AttributeAddress) Calendar(java.util.Calendar) ObisCode(org.openmuc.jdlms.ObisCode) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DlmsConnectionStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) AttributeAddressAssert(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.AttributeAddressAssert) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) GregorianCalendar(java.util.GregorianCalendar) TimeZone(java.util.TimeZone) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DateTime(org.joda.time.DateTime) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsObjectConfigConfiguration(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration) AmrProfileStatusCodeHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.AmrProfileStatusCodeHelper) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) List(java.util.List) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Collections(java.util.Collections) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto)

Example 13 with AttributeAddress

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

the class GetPeriodicMeterReadsGasCommandExecutorIntegrationTest method setResponsesForScalerUnit.

private void setResponsesForScalerUnit(final List<AttributeAddress> attributeAddressesForScalerUnit) {
    final int DLMS_ENUM_VALUE_M3 = 14;
    final DataObject responseDataObject = DataObject.newStructureData(DataObject.newInteger8Data((byte) 0), DataObject.newEnumerateData(DLMS_ENUM_VALUE_M3));
    for (final AttributeAddress attributeAddress : attributeAddressesForScalerUnit) {
        this.connectionStub.addReturnValue(attributeAddress, responseDataObject);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddress(org.openmuc.jdlms.AttributeAddress)

Example 14 with AttributeAddress

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

the class DlmsObjectConfigServiceTest method testProfileWithOneMedium.

@Test
void testProfileWithOneMedium() {
    // SETUP
    final Integer channel = null;
    final Medium filterMedium = Medium.ELECTRICITY;
    final DataObject selectedValues = DataObject.newArrayData(Collections.emptyList());
    final DataObject accessParams = this.getAccessParams(selectedValues);
    final SelectiveAccessDescription access = new SelectiveAccessDescription(1, accessParams);
    final AttributeAddress expectedAddress = new AttributeAddress(this.profileE.getClassId(), this.profileE.getObisCodeAsString(), this.profileE.getDefaultAttributeId(), access);
    // CALL
    final Optional<AttributeAddressForProfile> attributeAddressForProfile = this.service.findAttributeAddressForProfile(this.device422, DlmsObjectType.INTERVAL_VALUES, channel, this.from, this.to, filterMedium);
    // VERIFY
    assertThat(attributeAddressForProfile).isPresent();
    AttributeAddressAssert.is(attributeAddressForProfile.get().getAttributeAddress(), expectedAddress);
    assertThat(attributeAddressForProfile.get().getSelectedObjects()).isEqualTo(this.captureObjectsE);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) Medium(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium) AttributeAddress(org.openmuc.jdlms.AttributeAddress) Test(org.junit.jupiter.api.Test)

Example 15 with AttributeAddress

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

the class DlmsObjectConfigServiceTest method testProfileWithMediumCombinedAndNoFilterMedium.

@Test
void testProfileWithMediumCombinedAndNoFilterMedium() {
    // SETUP
    final Integer channel = 1;
    final Medium filterMedium = null;
    final DataObject selectedValues = DataObject.newArrayData(Collections.emptyList());
    final DataObject accessParams = this.getAccessParams(selectedValues);
    final SelectiveAccessDescription access = new SelectiveAccessDescription(1, accessParams);
    final AttributeAddress expectedAddress = new AttributeAddress(this.profileCombined.getClassId(), this.profileCombined.getObisCodeAsString(), this.profileCombined.getDefaultAttributeId(), access);
    // CALL
    final Optional<AttributeAddressForProfile> attributeAddressForProfile = this.service.findAttributeAddressForProfile(this.device422, DlmsObjectType.DAILY_LOAD_PROFILE, channel, this.from, this.to, filterMedium);
    // VERIFY
    assertThat(attributeAddressForProfile).isPresent();
    AttributeAddressAssert.is(attributeAddressForProfile.get().getAttributeAddress(), expectedAddress);
    assertThat(attributeAddressForProfile.get().getSelectedObjects()).isEqualTo(this.captureObjectsCombined);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) Medium(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium) AttributeAddress(org.openmuc.jdlms.AttributeAddress) Test(org.junit.jupiter.api.Test)

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