Search in sources :

Example 1 with MeterReadsResponseDto

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

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

the class ActualMeterReadsResponseMessageProcessor method handleMessage.

@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage, final OsgpException osgpException) {
    if (responseMessage.getDataObject() instanceof MeterReadsResponseDto) {
        final MeterReadsResponseDto actualMeterReadsDto = (MeterReadsResponseDto) responseMessage.getDataObject();
        this.monitoringService.handleActualMeterReadsResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, actualMeterReadsDto);
    } else if (responseMessage.getDataObject() instanceof MeterReadsGasResponseDto) {
        final MeterReadsGasResponseDto meterReadsGas = (MeterReadsGasResponseDto) responseMessage.getDataObject();
        this.monitoringService.handleActualMeterReadsResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, meterReadsGas);
    }
}
Also used : MeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsResponseDto) MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto)

Example 3 with MeterReadsResponseDto

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

the class MonitoringMapperTest method convertsMeterReadsResponseDtoToMeterReads.

@Test
public void convertsMeterReadsResponseDtoToMeterReads() {
    final Date logTime = new Date(123L * 24 * 60 * 60 * 1000);
    final ActiveEnergyValuesDto activeEnergyValuesDto = new ActiveEnergyValuesDto(new DlmsMeterValueDto(new BigDecimal("12.34"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.35"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.36"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.37"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.38"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.39"), DlmsUnitTypeDto.M3));
    final MeterReadsResponseDto source = new MeterReadsResponseDto(logTime, activeEnergyValuesDto);
    final MeterReads result = this.mapper.map(source, MeterReads.class);
    final ActiveEnergyValues activeEnergyValues = new ActiveEnergyValues(new OsgpMeterValue(new BigDecimal("12.340"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.350"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.360"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.370"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.380"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.390"), OsgpUnit.M3));
    final MeterReads expected = new MeterReads(logTime, activeEnergyValues);
    assertThat(result).usingRecursiveComparison().isEqualTo(expected);
}
Also used : MeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsResponseDto) MeterReads(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.MeterReads) ActiveEnergyValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActiveEnergyValuesDto) ActiveEnergyValues(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActiveEnergyValues) Date(java.util.Date) BigDecimal(java.math.BigDecimal) OsgpMeterValue(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Aggregations

MeterReadsResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsResponseDto)3 ActiveEnergyValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActiveEnergyValuesDto)2 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.jupiter.api.Test)1 GetResult (org.openmuc.jdlms.GetResult)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 ActiveEnergyValues (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActiveEnergyValues)1 MeterReads (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.MeterReads)1 OsgpMeterValue (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1 MeterReadsGasResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto)1