Search in sources :

Example 76 with DataObject

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

the class AbstractGetPowerQualityProfileHandler method createSelectableCaptureObjects.

// the available CaptureObjects are filtered with the ones that can be
// selected
private List<CaptureObjectDto> createSelectableCaptureObjects(final List<GetResult> captureObjects, final List<ScalerUnitInfo> scalerUnitInfos, final List<CaptureObjectDefinitionDto> selectableCaptureObjects) throws ProtocolAdapterException {
    final List<CaptureObjectDto> captureObjectDtos = new ArrayList<>();
    for (final GetResult captureObjectResult : captureObjects) {
        final DataObject dataObject = captureObjectResult.getResultData();
        final List<DataObject> captureObjectList = dataObject.getValue();
        for (final DataObject object : captureObjectList) {
            final boolean addCaptureObject = this.isSelectableValue(selectableCaptureObjects, object);
            if (addCaptureObject) {
                captureObjectDtos.add(this.makeCaptureObjectDto(object, scalerUnitInfos.get(captureObjectDtos.size())));
            }
        }
    }
    return captureObjectDtos;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) CaptureObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDto)

Example 77 with DataObject

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

the class AbstractGetPowerQualityProfileHandler method getUnitType.

private DlmsUnitTypeDto getUnitType(final ScalerUnitInfo scalerUnitInfo) {
    if (scalerUnitInfo.getScalerUnit() != null) {
        final List<DataObject> dataObjects = scalerUnitInfo.getScalerUnit().getValue();
        final int index = Integer.parseInt(dataObjects.get(1).getValue().toString());
        final DlmsUnitTypeDto unitType = DlmsUnitTypeDto.getUnitType(index);
        if (unitType != null) {
            return unitType;
        }
    }
    return DlmsUnitTypeDto.UNDEFINED;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsUnitTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto)

Example 78 with DataObject

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

the class AbstractGetPowerQualityProfileHandler method createSelectableCaptureObjects.

private Map<Integer, CaptureObjectDefinitionDto> createSelectableCaptureObjects(final List<GetResult> captureObjects, final List<SelectableObisCode> logicalNames) throws ProtocolAdapterException {
    final Map<Integer, CaptureObjectDefinitionDto> selectableCaptureObjects = new HashMap<>();
    // there is always only one GetResult
    for (final GetResult captureObjectResult : captureObjects) {
        final List<DataObject> dataObjects = captureObjectResult.getResultData().getValue();
        for (int positionInDataObjectsList = 0; positionInDataObjectsList < dataObjects.size(); positionInDataObjectsList++) {
            final DataObject dataObject = dataObjects.get(positionInDataObjectsList);
            final CosemObjectDefinitionDto cosemObjectDefinitionDto = this.dlmsHelper.readObjectDefinition(dataObject, CAPTURE_OBJECT);
            final Optional<SelectableObisCode> logicalName = SelectableObisCode.getByObisCode(cosemObjectDefinitionDto.getLogicalName().toString());
            if (logicalName.isPresent() && logicalNames.contains(logicalName.get())) {
                selectableCaptureObjects.put(positionInDataObjectsList, new CaptureObjectDefinitionDto(cosemObjectDefinitionDto.getClassId(), new ObisCodeValuesDto(logicalName.get().obisCode), (byte) cosemObjectDefinitionDto.getAttributeIndex(), cosemObjectDefinitionDto.getDataIndex()));
            }
        }
    }
    return selectableCaptureObjects;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) HashMap(java.util.HashMap) CosemObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemObjectDefinitionDto) ObisCodeValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ObisCodeValuesDto) CaptureObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto)

Example 79 with DataObject

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

the class GetPowerQualityProfileNoSelectiveAccessHandler method createProfileEntryValueDto.

@Override
protected List<ProfileEntryValueDto> createProfileEntryValueDto(final DataObject profileEntryDataObject, final List<ScalerUnitInfo> scalerUnitInfos, final ProfileEntryDto previousProfileEntryDto, final Map<Integer, CaptureObjectDefinitionDto> selectableCaptureObjects, final int timeInterval) {
    final List<ProfileEntryValueDto> result = new ArrayList<>();
    final List<DataObject> dataObjects = profileEntryDataObject.getValue();
    for (int i = 0; i < dataObjects.size(); i++) {
        if (selectableCaptureObjects.containsKey(i)) {
            final ProfileEntryValueDto currentProfileEntryValueDto = this.makeProfileEntryValueDto(dataObjects.get(i), scalerUnitInfos.get(result.size()), previousProfileEntryDto, timeInterval);
            result.add(currentProfileEntryValueDto);
        }
    }
    return result;
}
Also used : ProfileEntryValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ProfileEntryValueDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList)

Example 80 with DataObject

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

the class GetPeriodicMeterReadsGasCommandExecutor method execute.

@Override
public PeriodicMeterReadGasResponseDto 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, periodicMeterReadsQuery.getChannel(), from, to, device);
    final List<AttributeAddress> scalerUnitAddresses = this.getScalerUnitAddresses(periodicMeterReadsQuery.getChannel(), profileBufferAddress);
    final Optional<ProfileCaptureTime> intervalTime = this.getProfileCaptureTime(device, this.dlmsObjectConfigService, Medium.GAS);
    LOGGER.info("Retrieving current billing period and profiles for gas for period type: {}, from: " + "{}, to: {}", queryPeriodType, from, to);
    /*
     * workaround for a problem when using with_list and retrieving a profile
     * buffer, this will be returned erroneously.
     */
    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, periodicMeterReadsQuery.getChannel(), queryPeriodType, from, to, JdlmsObjectToStringUtil.describeAttributes(address)));
        getResultList.addAll(this.dlmsHelper.getAndCheck(conn, device, "retrieve periodic meter reads for " + queryPeriodType + ", channel " + periodicMeterReadsQuery.getChannel(), address));
    }
    LOGGER.info("Received getResult: {} ", getResultList);
    final DataObject resultData = this.dlmsHelper.readDataObject(getResultList.get(0), PERIODIC_G_METER_READS);
    final List<DataObject> bufferedObjectsList = resultData.getValue();
    final List<PeriodicMeterReadsGasResponseItemDto> 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);
        }
    }
    LOGGER.info("Resulting periodicMeterReads: {} ", periodicMeterReads);
    return new PeriodicMeterReadGasResponseDto(queryPeriodType, periodicMeterReads);
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) GetResult(org.openmuc.jdlms.GetResult) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ArrayList(java.util.ArrayList) 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) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto)

Aggregations

DataObject (org.openmuc.jdlms.datatypes.DataObject)176 ArrayList (java.util.ArrayList)46 AttributeAddress (org.openmuc.jdlms.AttributeAddress)36 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)34 Test (org.junit.jupiter.api.Test)31 GetResult (org.openmuc.jdlms.GetResult)23 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)16 DateTime (org.joda.time.DateTime)15 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)14 SetParameter (org.openmuc.jdlms.SetParameter)12 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)11 BitString (org.openmuc.jdlms.datatypes.BitString)10 ObisCode (org.openmuc.jdlms.ObisCode)9 IOException (java.io.IOException)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)7 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)6 List (java.util.List)5 MethodResultCode (org.openmuc.jdlms.MethodResultCode)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)5 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)5