Search in sources :

Example 26 with GetResult

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

the class DeviceChannelsHelper method readIdentificationNumber.

private String readIdentificationNumber(final List<GetResult> resultList, final int index, final DlmsObject clientSetupObject, final String description) throws ProtocolAdapterException {
    final GetResult getResult = resultList.get(index);
    final DataObject resultData = getResult.getResultData();
    if (resultData == null) {
        return null;
    } else {
        final Long identification = this.dlmsHelper.readLong(resultData, description);
        final IdentificationNumber identificationNumber;
        if (this.identificationNumberStoredAsBcdOnDevice(clientSetupObject)) {
            identificationNumber = IdentificationNumber.fromBcdRepresentationAsLong(identification);
        } else {
            identificationNumber = IdentificationNumber.fromNumericalRepresentation(identification);
        }
        return identificationNumber.getTextualRepresentation();
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult)

Example 27 with GetResult

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

the class GetActualMeterReadsCommandExecutor method execute.

@Override
public MeterReadsResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActualMeterReadsQueryDto actualMeterReadsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    if (actualMeterReadsQuery != null && actualMeterReadsQuery.isMbusQuery()) {
        throw new IllegalArgumentException("ActualMeterReadsQuery object for energy reads should not be about gas.");
    }
    conn.getDlmsMessageListener().setDescription("GetActualMeterReads retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_ADDRESSES));
    LOGGER.info("Retrieving actual energy reads");
    final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "retrieve actual meter reads", ATTRIBUTE_ADDRESSES);
    final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(getResultList.get(INDEX_TIME), "Actual Energy Reads Time");
    final DateTime time = cosemDateTime.asDateTime();
    if (time == null) {
        throw new ProtocolAdapterException("Unexpected null/unspecified value for Actual Energy Reads Time");
    }
    final DlmsMeterValueDto activeEnergyImport = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_SCALER_UNIT), "Actual Energy Reads +A");
    final DlmsMeterValueDto activeEnergyExport = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_SCALER_UNIT), "Actual Energy Reads -A");
    final DlmsMeterValueDto activeEnergyImportRate1 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_1), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_1_SCALER_UNIT), "Actual Energy Reads +A rate 1");
    final DlmsMeterValueDto activeEnergyImportRate2 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_2), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_2_SCALER_UNIT), "Actual Energy Reads +A rate 2");
    final DlmsMeterValueDto activeEnergyExportRate1 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_1), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_1_SCALER_UNIT), "Actual Energy Reads -A rate 1");
    final DlmsMeterValueDto activeEnergyExportRate2 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_2), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_2_SCALER_UNIT), "Actual Energy Reads -A rate 2");
    return new MeterReadsResponseDto(time.toDate(), new ActiveEnergyValuesDto(activeEnergyImport, activeEnergyExport, activeEnergyImportRate1, activeEnergyImportRate2, activeEnergyExportRate1, activeEnergyExportRate2));
}
Also used : MeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsResponseDto) GetResult(org.openmuc.jdlms.GetResult) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ActiveEnergyValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActiveEnergyValuesDto) DateTime(org.joda.time.DateTime) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Example 28 with GetResult

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

the class JdlmsObjectToStringUtilTest method testDescribeGetResults.

@Test
public void testDescribeGetResults() {
    final GetResult getResult1 = new GetResultImpl(DataObject.newInteger32Data(100), AccessResultCode.SUCCESS);
    final GetResult getResult2 = new GetResultImpl(DataObject.newVisibleStringData("Test".getBytes()), AccessResultCode.OBJECT_UNDEFINED);
    final String description = JdlmsObjectToStringUtil.describeGetResults(Arrays.asList(getResult1, getResult2));
    assertThat(description).isEqualTo("{SUCCESS, DOUBLE_LONG Value: 100 - OBJECT_UNDEFINED, VISIBLE_STRING Value: Test}");
}
Also used : GetResult(org.openmuc.jdlms.GetResult) GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) Test(org.junit.jupiter.api.Test)

Example 29 with GetResult

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

the class JdlmsObjectToStringUtilTest method testDescribeGetResultWithSuccess.

@Test
public void testDescribeGetResultWithSuccess() {
    final GetResult getResult = new GetResultImpl(DataObject.newInteger32Data(100), AccessResultCode.SUCCESS);
    final String description = JdlmsObjectToStringUtil.describeGetResult(getResult);
    assertThat(description).isEqualTo("SUCCESS, DOUBLE_LONG Value: 100");
}
Also used : GetResult(org.openmuc.jdlms.GetResult) GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) Test(org.junit.jupiter.api.Test)

Example 30 with GetResult

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

the class ClearMBusStatusOnAllChannelsCommandExecutor method readStatus.

private long readStatus(final DlmsConnectionManager conn, final Integer channel, final AttributeAddress attributeAddress) throws IOException, ProtocolAdapterException {
    conn.getDlmsMessageListener().setDescription("ClearMBusStatusOnAllChannels-readStatus for channel" + channel + " - read status" + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
    log.info("Reading status for M-Bus channel {} with attributeAddress: {}.", channel, attributeAddress);
    final GetResult result = conn.getConnection().get(attributeAddress);
    if (result == null) {
        throw new ProtocolAdapterException("No GetResult received while reading status for M-Bus channel " + channel + ".");
    }
    return this.parseStatusFilter(result.getResultData(), channel);
}
Also used : GetResult(org.openmuc.jdlms.GetResult) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

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