Search in sources :

Example 11 with SelectiveAccessDescription

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

the class AbstractGetPowerQualityProfileHandler method retrieveBuffer.

private List<GetResult> retrieveBuffer(final DlmsConnectionManager conn, final DlmsDevice device, final ObisCode obisCode, final DateTime beginDateTime, final DateTime endDateTime, final List<CaptureObjectDefinitionDto> selectableCaptureObjects) throws ProtocolAdapterException {
    final DataObject selectableValues = this.convertSelectableCaptureObjects(selectableCaptureObjects);
    final SelectiveAccessDescription selectiveAccessDescription = this.getSelectiveAccessDescription(beginDateTime, endDateTime, selectableValues);
    final AttributeAddress bufferAttributeAddress = new AttributeAddress(InterfaceClass.PROFILE_GENERIC.id(), obisCode, ProfileGenericAttribute.BUFFER.attributeId(), selectiveAccessDescription);
    return this.dlmsHelper.getAndCheck(conn, device, "retrieve profile generic buffer", bufferAttributeAddress);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) AttributeAddress(org.openmuc.jdlms.AttributeAddress)

Example 12 with SelectiveAccessDescription

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

the class FindEventsCommandExecutor method execute.

@Override
public List<EventDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final FindEventsRequestDto findEventsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final SelectiveAccessDescription selectiveAccessDescription = this.getSelectiveAccessDescription(device, findEventsQuery.getFrom(), findEventsQuery.getUntil());
    final DlmsObject eventLogObject = this.dlmsObjectConfigService.getDlmsObject(device, EVENT_LOG_CATEGORY_OBISCODE_MAP.get(findEventsQuery.getEventLogCategory()));
    final AttributeAddress eventLogBuffer = new AttributeAddress(eventLogObject.getClassId(), eventLogObject.getObisCode(), eventLogObject.getDefaultAttributeId(), selectiveAccessDescription);
    conn.getDlmsMessageListener().setDescription("RetrieveEvents for " + findEventsQuery.getEventLogCategory() + " from " + findEventsQuery.getFrom() + " until " + findEventsQuery.getUntil() + ", retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(eventLogBuffer));
    final GetResult getResult;
    try {
        getResult = conn.getConnection().get(eventLogBuffer);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
    if (getResult == null) {
        throw new ProtocolAdapterException("No GetResult received while retrieving event register " + findEventsQuery.getEventLogCategory());
    }
    if (!AccessResultCode.SUCCESS.equals(getResult.getResultCode())) {
        LOGGER.info("Result of getting events for {} is {}", findEventsQuery.getEventLogCategory(), getResult.getResultCode());
        throw new ProtocolAdapterException("Getting the events for  " + findEventsQuery.getEventLogCategory() + " from the meter resulted in: " + getResult.getResultCode());
    }
    final DataObject resultData = getResult.getResultData();
    return this.dataObjectToEventListConverter.convert(resultData, findEventsQuery.getEventLogCategory());
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 13 with SelectiveAccessDescription

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

the class DlmsObjectConfigServiceTest method testProfileWithMediumCombinedAndFilterMedium.

@Test
void testProfileWithMediumCombinedAndFilterMedium() {
    // SETUP
    final Integer channel = null;
    final Medium filterMedium = Medium.ELECTRICITY;
    final List<DlmsCaptureObject> expectedSelectedObjects = this.captureObjectsCombined.stream().filter(c -> !(c.getRelatedObject() instanceof DlmsRegister) || ((DlmsRegister) c.getRelatedObject()).getMedium() == filterMedium).collect(Collectors.toList());
    final DataObject selectedValues = DataObject.newArrayData(expectedSelectedObjects.stream().map(o -> this.getDataObject(o.getRelatedObject())).collect(Collectors.toList()));
    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(expectedSelectedObjects);
}
Also used : Strictness(org.mockito.quality.Strictness) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) Fail.fail(org.assertj.core.api.Fail.fail) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegister) ObisCode(org.openmuc.jdlms.ObisCode) DlmsClock(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Medium(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium) ProfileCaptureTime(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.ProfileCaptureTime) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) 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) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DateTime(org.joda.time.DateTime) DataObject(org.openmuc.jdlms.datatypes.DataObject) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) CommunicationMethod(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.CommunicationMethod) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) Optional(java.util.Optional) RegisterUnit(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.RegisterUnit) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Collections(java.util.Collections) DlmsGsmDiagnostic(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsGsmDiagnostic) DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegister) 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 14 with SelectiveAccessDescription

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

the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method createSelectiveAccessDescriptionSmr5.

private SelectiveAccessDescription createSelectiveAccessDescriptionSmr5(final DataObject from, final DataObject to) {
    final DataObject selectedValues = DataObject.newArrayData(Collections.emptyList());
    final DataObject expectedAccessParam = DataObject.newStructureData(Arrays.asList(this.CLOCK, from, to, selectedValues));
    return new SelectiveAccessDescription(1, expectedAccessParam);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription)

Example 15 with SelectiveAccessDescription

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

the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method createSelectiveAccessDescriptionDsmr4Monthly.

private SelectiveAccessDescription createSelectiveAccessDescriptionDsmr4Monthly(final DataObject from, final DataObject to) {
    final DataObject selectedValues = DataObject.newArrayData(Arrays.asList(this.CLOCK, this.ACTIVE_ENERGY_IMPORT_RATE_1, this.ACTIVE_ENERGY_IMPORT_RATE_2, this.ACTIVE_ENERGY_EXPORT_RATE_1, this.ACTIVE_ENERGY_EXPORT_RATE_2));
    final DataObject expectedAccessParam = DataObject.newStructureData(Arrays.asList(this.CLOCK, from, to, selectedValues));
    return new SelectiveAccessDescription(1, expectedAccessParam);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription)

Aggregations

SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)17 DataObject (org.openmuc.jdlms.datatypes.DataObject)16 AttributeAddress (org.openmuc.jdlms.AttributeAddress)6 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)5 Test (org.junit.jupiter.api.Test)3 Medium (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium)3 DateTime (org.joda.time.DateTime)2 ObisCode (org.openmuc.jdlms.ObisCode)2 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)2 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)1 Fail.fail (org.assertj.core.api.Fail.fail)1