Search in sources :

Example 21 with GetResult

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

the class GetPushSetupAlarmCommandExecutor method execute.

@Override
public PushSetupAlarmDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void useless, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    conn.getDlmsMessageListener().setDescription("GetPushSetupAlarm, retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_ADDRESSES));
    LOGGER.info("Retrieving Push Setup Alarm");
    final List<GetResult> getResultList = this.dlmsHelper.getWithList(conn, device, ATTRIBUTE_ADDRESSES);
    GetPushSetupCommandExecutor.checkResultList(getResultList, ATTRIBUTE_ADDRESSES);
    final PushSetupAlarmDto.Builder pushSetupAlarmBuilder = new PushSetupAlarmDto.Builder();
    pushSetupAlarmBuilder.withLogicalName(new CosemObisCodeDto(OBIS_CODE.bytes()));
    pushSetupAlarmBuilder.withPushObjectList(this.dlmsHelper.readListOfObjectDefinition(getResultList.get(INDEX_PUSH_OBJECT_LIST), "Push Object List"));
    pushSetupAlarmBuilder.withSendDestinationAndMethod(this.dlmsHelper.readSendDestinationAndMethod(getResultList.get(INDEX_SEND_DESTINATION_AND_METHOD), "Send Destination And Method"));
    pushSetupAlarmBuilder.withCommunicationWindow(this.dlmsHelper.readListOfWindowElement(getResultList.get(INDEX_COMMUNICATION_WINDOW), "Communication Window"));
    pushSetupAlarmBuilder.withRandomisationStartInterval(this.dlmsHelper.readLongNotNull(getResultList.get(INDEX_RANDOMISATION_START_INTERVAL), "Randomisation Start Interval").intValue());
    pushSetupAlarmBuilder.withNumberOfRetries(this.dlmsHelper.readLongNotNull(getResultList.get(INDEX_NUMBER_OF_RETRIES), "Number of Retries").intValue());
    pushSetupAlarmBuilder.withRepetitionDelay(this.dlmsHelper.readLongNotNull(getResultList.get(INDEX_REPETITION_DELAY), "Repetition Delay").intValue());
    return pushSetupAlarmBuilder.build();
}
Also used : GetResult(org.openmuc.jdlms.GetResult) PushSetupAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto) CosemObisCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemObisCodeDto)

Example 22 with GetResult

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

the class GetPushSetupSmsCommandExecutor method execute.

@Override
public PushSetupSmsDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void useless, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    conn.getDlmsMessageListener().setDescription("GetPushSetupSms, retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_ADDRESSES));
    LOGGER.info("Retrieving Push Setup SMS");
    final List<GetResult> getResultList = this.dlmsHelper.getWithList(conn, device, ATTRIBUTE_ADDRESSES);
    GetPushSetupCommandExecutor.checkResultList(getResultList, ATTRIBUTE_ADDRESSES);
    final PushSetupSmsDto.Builder pushSetupSmsBuilder = new PushSetupSmsDto.Builder();
    pushSetupSmsBuilder.withLogicalName(new CosemObisCodeDto(OBIS_CODE.bytes()));
    pushSetupSmsBuilder.withPushObjectList(this.dlmsHelper.readListOfObjectDefinition(getResultList.get(INDEX_PUSH_OBJECT_LIST), "Push Object List"));
    pushSetupSmsBuilder.withSendDestinationAndMethod(this.dlmsHelper.readSendDestinationAndMethod(getResultList.get(INDEX_SEND_DESTINATION_AND_METHOD), "Send Destination And Method"));
    pushSetupSmsBuilder.withCommunicationWindow(this.dlmsHelper.readListOfWindowElement(getResultList.get(INDEX_COMMUNICATION_WINDOW), "Communication Window"));
    pushSetupSmsBuilder.withRandomisationStartInterval(this.dlmsHelper.readLongNotNull(getResultList.get(INDEX_RANDOMISATION_START_INTERVAL), "Randomisation Start Interval").intValue());
    pushSetupSmsBuilder.withNumberOfRetries(this.dlmsHelper.readLongNotNull(getResultList.get(INDEX_NUMBER_OF_RETRIES), "Number of Retries").intValue());
    pushSetupSmsBuilder.withRepetitionDelay(this.dlmsHelper.readLongNotNull(getResultList.get(INDEX_REPETITION_DELAY), "Repetition Delay").intValue());
    return pushSetupSmsBuilder.build();
}
Also used : GetResult(org.openmuc.jdlms.GetResult) PushSetupSmsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupSmsDto) CosemObisCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemObisCodeDto)

Example 23 with GetResult

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

the class GetPeriodicMeterReadsCommandExecutor method execute.

@Override
public PeriodicMeterReadsResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final PeriodicMeterReadsRequestDto periodicMeterReadsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    if (periodicMeterReadsQuery == null) {
        throw new IllegalArgumentException("PeriodicMeterReadsQuery should contain PeriodType, BeginDate and EndDate.");
    }
    final PeriodTypeDto queryPeriodType = periodicMeterReadsQuery.getPeriodType();
    final DateTime from = new DateTime(periodicMeterReadsQuery.getBeginDate());
    final DateTime to = new DateTime(periodicMeterReadsQuery.getEndDate());
    final AttributeAddressForProfile profileBufferAddress = this.getProfileBufferAddress(queryPeriodType, from, to, device);
    final List<AttributeAddress> scalerUnitAddresses = this.getScalerUnitAddresses(profileBufferAddress);
    final Optional<ProfileCaptureTime> intervalTime = this.getProfileCaptureTime(device, this.dlmsObjectConfigService, Medium.ELECTRICITY);
    LOGGER.debug("Retrieving current billing period and profiles for period type: {}, from: {}, to: {}", queryPeriodType, from, to);
    // Get results one by one because getWithList does not work for all devices
    final List<GetResult> getResultList = new ArrayList<>();
    final List<AttributeAddress> allAttributeAddresses = new ArrayList<>();
    allAttributeAddresses.add(profileBufferAddress.getAttributeAddress());
    allAttributeAddresses.addAll(scalerUnitAddresses);
    for (final AttributeAddress address : allAttributeAddresses) {
        conn.getDlmsMessageListener().setDescription(String.format(FORMAT_DESCRIPTION, queryPeriodType, from, to, JdlmsObjectToStringUtil.describeAttributes(address)));
        getResultList.addAll(this.dlmsHelper.getAndCheck(conn, device, "retrieve periodic meter reads for " + queryPeriodType, address));
    }
    LOGGER.info("Received getResult: {} ", getResultList);
    final DataObject resultData = this.dlmsHelper.readDataObject(getResultList.get(0), PERIODIC_E_METER_READS);
    final List<DataObject> bufferedObjectsList = resultData.getValue();
    final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads = new ArrayList<>();
    for (final DataObject bufferedObject : bufferedObjectsList) {
        final List<DataObject> bufferedObjectValue = bufferedObject.getValue();
        try {
            periodicMeterReads.add(this.convertToResponseItem(new ConversionContext(periodicMeterReadsQuery, bufferedObjectValue, getResultList, profileBufferAddress, scalerUnitAddresses, intervalTime), periodicMeterReads));
        } catch (final BufferedDateTimeValidationException e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
    return new PeriodicMeterReadsResponseDto(queryPeriodType, periodicMeterReads);
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ArrayList(java.util.ArrayList) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto) DateTime(org.joda.time.DateTime) BufferedDateTimeValidationException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException) ProfileCaptureTime(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.ProfileCaptureTime) DataObject(org.openmuc.jdlms.datatypes.DataObject)

Example 24 with GetResult

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

the class GetActualMeterReadsGasCommandExecutor method execute.

@Override
public MeterReadsGasResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActualMeterReadsQueryDto actualMeterReadsRequest, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final ObisCode obisCodeMbusMasterValue = this.masterValueForChannel(actualMeterReadsRequest.getChannel());
    LOGGER.debug("Retrieving current MBUS master value for ObisCode: {}", obisCodeMbusMasterValue);
    final AttributeAddress mbusValue = new AttributeAddress(CLASS_ID_MBUS, this.masterValueForChannel(actualMeterReadsRequest.getChannel()), ATTRIBUTE_ID_VALUE);
    LOGGER.debug("Retrieving current MBUS master capture time for ObisCode: {}", obisCodeMbusMasterValue);
    final AttributeAddress mbusTime = new AttributeAddress(CLASS_ID_MBUS, obisCodeMbusMasterValue, ATTRIBUTE_ID_TIME);
    final AttributeAddress scalerUnit = new AttributeAddress(CLASS_ID_MBUS, this.masterValueForChannel(actualMeterReadsRequest.getChannel()), ATTRIBUTE_ID_SCALER_UNIT);
    conn.getDlmsMessageListener().setDescription("GetActualMeterReadsGas for channel " + actualMeterReadsRequest.getChannel() + ", retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(mbusValue, mbusTime, scalerUnit));
    final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "retrieve actual meter reads for mbus " + actualMeterReadsRequest.getChannel(), mbusValue, mbusTime, scalerUnit);
    final DlmsMeterValueDto consumption = this.dlmsHelper.getScaledMeterValue(getResultList.get(0), getResultList.get(2), "retrieve scaled value for mbus " + actualMeterReadsRequest.getChannel());
    final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(getResultList.get(1), "captureTime gas");
    final Date captureTime;
    if (cosemDateTime.isDateTimeSpecified()) {
        captureTime = cosemDateTime.asDateTime().toDate();
    } else {
        throw new ProtocolAdapterException("Unexpected null/unspecified value for M-Bus Capture Time");
    }
    return new MeterReadsGasResponseDto(new Date(), consumption, captureTime);
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto) Date(java.util.Date) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Example 25 with GetResult

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

the class DeviceChannelsHelper method getChannelElementValues.

protected ChannelElementValuesDto getChannelElementValues(final DlmsConnectionManager conn, final DlmsDevice device, final short channel) throws ProtocolAdapterException {
    final DlmsObject clientSetupObject = this.dlmsObjectConfigService.getDlmsObject(device, DlmsObjectType.MBUS_CLIENT_SETUP);
    final AttributeAddress[] attrAddresses = this.makeAttributeAddresses(clientSetupObject, channel);
    final List<GetResult> resultList = this.getMBusClientAttributeValues(conn, device, attrAddresses);
    return this.makeChannelElementValues(channel, resultList, clientSetupObject);
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)

Aggregations

GetResult (org.openmuc.jdlms.GetResult)47 DataObject (org.openmuc.jdlms.datatypes.DataObject)23 ArrayList (java.util.ArrayList)16 AttributeAddress (org.openmuc.jdlms.AttributeAddress)16 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)14 Test (org.junit.jupiter.api.Test)13 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)11 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)8 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)8 DateTime (org.joda.time.DateTime)6 ObisCode (org.openmuc.jdlms.ObisCode)6 IOException (java.io.IOException)5 Date (java.util.Date)5 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)4 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)4 AccessResultCode (org.openmuc.jdlms.AccessResultCode)3 BufferedDateTimeValidationException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException)3