Search in sources :

Example 26 with ObisCode

use of org.openmuc.jdlms.ObisCode 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 27 with ObisCode

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

the class GetPeriodicMeterReadsGasCommandExecutor method readScalerUnit.

private DataObject readScalerUnit(final List<GetResult> getResultList, final List<AttributeAddress> attributeAddresses, final AttributeAddressForProfile attributeAddressForProfile, final Integer channel) {
    final DlmsCaptureObject captureObject = attributeAddressForProfile.getCaptureObject(DlmsObjectType.MBUS_MASTER_VALUE);
    int index = 0;
    Integer scalerUnitIndex = null;
    for (final AttributeAddress address : attributeAddresses) {
        final String obisCode = captureObject.getRelatedObject().getObisCodeAsString().replace("<c>", channel.toString());
        if (address.getInstanceId().equals(new ObisCode(obisCode))) {
            scalerUnitIndex = index;
        }
        index++;
    }
    // and should be skipped. The first scaler unit is at index 1.
    if (scalerUnitIndex != null) {
        return getResultList.get(scalerUnitIndex + 1).getResultData();
    }
    return null;
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsCaptureObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject) ObisCode(org.openmuc.jdlms.ObisCode)

Example 28 with ObisCode

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

the class GetSpecificAttributeValueCommandExecutor method execute.

@Override
public String execute(final DlmsConnectionManager conn, final DlmsDevice device, final SpecificAttributeValueRequestDto requestData, final MessageMetadata messageMetadata) throws FunctionalException {
    final ObisCodeValuesDto obisCodeValues = requestData.getObisCode();
    final byte[] obisCodeBytes = { obisCodeValues.getA(), obisCodeValues.getB(), obisCodeValues.getC(), obisCodeValues.getD(), obisCodeValues.getE(), obisCodeValues.getF() };
    final ObisCode obisCode = new ObisCode(obisCodeBytes);
    LOGGER.debug("Get specific attribute value, class id: {}, obis code: {}, attribute id: {}", requestData.getClassId(), obisCode, requestData.getAttribute());
    final AttributeAddress attributeAddress = new AttributeAddress(requestData.getClassId(), obisCode, requestData.getAttribute());
    conn.getDlmsMessageListener().setDescription("GetSpecificAttributeValue, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
    final DataObject attributeValue = this.dlmsHelper.getAttributeValue(conn, attributeAddress);
    return this.dlmsHelper.getDebugInfo(attributeValue);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode) ObisCodeValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ObisCodeValuesDto)

Example 29 with ObisCode

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

the class GetPeriodicMeterReadsCommandExecutor method readScalerUnit.

private DataObject readScalerUnit(final List<GetResult> getResultList, final List<AttributeAddress> attributeAddresses, final AttributeAddressForProfile attributeAddressForProfile, final DlmsObjectType objectType) {
    final DlmsCaptureObject captureObject = attributeAddressForProfile.getCaptureObject(objectType);
    int index = 0;
    Integer scalerUnitIndex = null;
    for (final AttributeAddress address : attributeAddresses) {
        final ObisCode obisCode = captureObject.getRelatedObject().getObisCode();
        if (address.getInstanceId().equals(obisCode)) {
            scalerUnitIndex = index;
        }
        index++;
    }
    // and should be skipped. The first scaler unit is at index 1.
    if (scalerUnitIndex != null) {
        return getResultList.get(scalerUnitIndex + 1).getResultData();
    }
    return null;
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsCaptureObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject) ObisCode(org.openmuc.jdlms.ObisCode)

Example 30 with ObisCode

use of org.openmuc.jdlms.ObisCode 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)

Aggregations

ObisCode (org.openmuc.jdlms.ObisCode)46 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 Bean (org.springframework.context.annotation.Bean)9 BitString (org.openmuc.jdlms.datatypes.BitString)8 DataObject (org.openmuc.jdlms.datatypes.DataObject)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 OctetStringData (org.opensmartgridplatform.simulator.protocol.dlms.cosem.OctetStringData)6 Then (io.cucumber.java.en.Then)4 GetResult (org.openmuc.jdlms.GetResult)4 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)4 Given (io.cucumber.java.en.Given)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 CosemClass (org.openmuc.jdlms.CosemClass)3 ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)3 IOException (java.io.IOException)2 DlmsCaptureObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject)2 CosemObjectAccessor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor)2 DataObjectAttrExecutors (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors)2