Search in sources :

Example 1 with CaptureObjectDefinitionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto in project open-smart-grid-platform by OSGP.

the class AbstractGetPowerQualityProfileHandler method handle.

protected GetPowerQualityProfileResponseDto handle(final DlmsConnectionManager conn, final DlmsDevice device, final GetPowerQualityProfileRequestDataDto getPowerQualityProfileRequestDataDto) throws ProtocolAdapterException {
    final String profileType = getPowerQualityProfileRequestDataDto.getProfileType();
    final List<Profile> profiles = this.determineProfileForDevice(profileType);
    final GetPowerQualityProfileResponseDto response = new GetPowerQualityProfileResponseDto();
    final List<PowerQualityProfileDataDto> responseDatas = new ArrayList<>();
    for (final Profile profile : profiles) {
        final ObisCode obisCode = this.makeObisCode(profile.getObisCodeValuesDto());
        final DateTime beginDateTime = new DateTime(getPowerQualityProfileRequestDataDto.getBeginDate());
        final DateTime endDateTime = new DateTime(getPowerQualityProfileRequestDataDto.getEndDate());
        // all value types that can be selected within this profile.
        final List<GetResult> captureObjects = this.retrieveCaptureObjects(conn, device, obisCode);
        // the values that are allowed to be retrieved from the meter, used
        // as filter either before (SMR 5.1+) or
        // after data retrieval
        final Map<Integer, CaptureObjectDefinitionDto> selectableCaptureObjects = this.createSelectableCaptureObjects(captureObjects, profile.getLogicalNames());
        // the units of measure for all Selectable Capture objects
        final List<ScalerUnitInfo> scalerUnitInfos = this.createScalerUnitInfos(conn, device, selectableCaptureObjects.values());
        final List<GetResult> bufferList = this.retrieveBuffer(conn, device, obisCode, beginDateTime, endDateTime, new ArrayList<>(selectableCaptureObjects.values()));
        final PowerQualityProfileDataDto responseDataDto = this.processData(profile, captureObjects, scalerUnitInfos, selectableCaptureObjects, bufferList);
        responseDatas.add(responseDataDto);
    }
    response.setPowerQualityProfileDatas(responseDatas);
    return response;
}
Also used : PowerQualityProfileDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityProfileDataDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) ObisCode(org.openmuc.jdlms.ObisCode) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) CaptureObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto) ScalerUnitInfo(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.ScalerUnitInfo) GetPowerQualityProfileResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto)

Example 2 with CaptureObjectDefinitionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto in project open-smart-grid-platform by OSGP.

the class AbstractGetPowerQualityProfileHandler method createScalerUnitInfos.

private List<ScalerUnitInfo> createScalerUnitInfos(final DlmsConnectionManager conn, final DlmsDevice device, final Collection<CaptureObjectDefinitionDto> values) throws ProtocolAdapterException {
    final List<ScalerUnitInfo> scalerUnitInfos = new ArrayList<>();
    for (final CaptureObjectDefinitionDto dto : values) {
        final ScalerUnitInfo newScalerUnitInfo = this.createScalerUnitInfo(conn, device, dto);
        scalerUnitInfos.add(newScalerUnitInfo);
    }
    return scalerUnitInfos;
}
Also used : ArrayList(java.util.ArrayList) ScalerUnitInfo(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.ScalerUnitInfo) CaptureObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto)

Example 3 with CaptureObjectDefinitionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto 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 4 with CaptureObjectDefinitionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto in project open-smart-grid-platform by OSGP.

the class ConfigureDefinableLoadProfileCommandExecutor method mapCaptureObjects.

private List<DataObject> mapCaptureObjects(final List<CaptureObjectDefinitionDto> captureObjects) {
    final List<DataObject> captureObjectsArray = new ArrayList<>();
    /*
     * Always make sure the capture object definition of the clock time is
     * included as first capture object in the list, and that the clock time
     * is not included anywhere else as part of the capture objects.
     */
    captureObjectsArray.add(CLOCK_TIME_DEFINITION);
    for (final CaptureObjectDefinitionDto captureObject : captureObjects) {
        if (!this.isClockTimeDefinition(captureObject)) {
            captureObjectsArray.add(this.configurationMapper.map(captureObject, DataObject.class));
        }
    }
    return captureObjectsArray;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) CaptureObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto)

Example 5 with CaptureObjectDefinitionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto in project open-smart-grid-platform by OSGP.

the class GetPowerQualityProfileSelectiveAccessHandler method convertSelectableCaptureObjects.

@Override
protected DataObject convertSelectableCaptureObjects(final List<CaptureObjectDefinitionDto> selectableCaptureObjects) {
    final List<DataObject> objectDefinitions = new ArrayList<>();
    if (!selectableCaptureObjects.isEmpty()) {
        // The captured clock is always included.
        objectDefinitions.add(this.dlmsHelper.getClockDefinition());
        for (final CaptureObjectDefinitionDto captureObjectDefinition : selectableCaptureObjects) {
            final int classId = captureObjectDefinition.getClassId();
            final byte[] obisBytes = captureObjectDefinition.getLogicalName().toByteArray();
            final byte attributeIndex = captureObjectDefinition.getAttributeIndex();
            final int dataIndex = captureObjectDefinition.getDataIndex() == null ? 0 : captureObjectDefinition.getDataIndex();
            objectDefinitions.add(DataObject.newStructureData(Arrays.asList(DataObject.newUInteger16Data(classId), DataObject.newOctetStringData(obisBytes), DataObject.newInteger8Data(attributeIndex), DataObject.newUInteger16Data(dataIndex))));
        }
    }
    return DataObject.newArrayData(objectDefinitions);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) CaptureObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto)

Aggregations

CaptureObjectDefinitionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto)5 ArrayList (java.util.ArrayList)4 DataObject (org.openmuc.jdlms.datatypes.DataObject)3 GetResult (org.openmuc.jdlms.GetResult)2 ScalerUnitInfo (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.ScalerUnitInfo)2 LocalDateTime (java.time.LocalDateTime)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 ObisCode (org.openmuc.jdlms.ObisCode)1 CosemObjectDefinitionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemObjectDefinitionDto)1 GetPowerQualityProfileResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto)1 ObisCodeValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ObisCodeValuesDto)1 PowerQualityProfileDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityProfileDataDto)1