Search in sources :

Example 6 with CosemDateTimeDto

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

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

the class DlmsHelperTest method testFromByteArrayWinterTime.

@Test
public void testFromByteArrayWinterTime() throws Exception {
    final CosemDateTimeDto cosemDateTime = this.dlmsHelper.fromDateTimeValue(this.byteArrayWinterTime());
    assertThat(cosemDateTime.isDateTimeSpecified()).isTrue();
    final DateTime dateInWinterTime = cosemDateTime.asDateTime();
    assertThat(ISODateTimeFormat.dateTime().print(dateInWinterTime)).isEqualTo("2015-02-21T14:53:07.230+01:00");
}
Also used : DateTime(org.joda.time.DateTime) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) Test(org.junit.jupiter.api.Test)

Example 8 with CosemDateTimeDto

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

the class GetActualPowerQualityCommandExecutor method makeActualPowerQualityDataDto.

private ActualPowerQualityDataDto makeActualPowerQualityDataDto(final List<GetResult> resultList, final List<PowerQualityObjectMetadata> metadatas) throws ProtocolAdapterException {
    final List<PowerQualityObjectDto> powerQualityObjects = new ArrayList<>();
    final List<PowerQualityValueDto> powerQualityValues = new ArrayList<>();
    int idx = 0;
    for (final PowerQualityObjectMetadata metadata : metadatas) {
        final PowerQualityObjectDto powerQualityObject;
        final PowerQualityValueDto powerQualityValue;
        if (metadata.getClassId() == CLASS_ID_CLOCK) {
            final GetResult resultTime = resultList.get(idx++);
            final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(resultTime, "Actual Power Quality - Time");
            powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
            powerQualityValue = new PowerQualityValueDto(cosemDateTime.asDateTime().toDate());
        } else if (metadata.getClassId() == CLASS_ID_REGISTER) {
            final GetResult resultValue = resultList.get(idx++);
            final GetResult resultScalerUnit = resultList.get(idx++);
            final DlmsMeterValueDto meterValue = this.dlmsHelper.getScaledMeterValue(resultValue, resultScalerUnit, "Actual Power Quality - " + metadata.getObisCode());
            final BigDecimal value = meterValue != null ? meterValue.getValue() : null;
            final String unit = meterValue != null ? meterValue.getDlmsUnit().getUnit() : null;
            powerQualityValue = new PowerQualityValueDto(value);
            powerQualityObject = new PowerQualityObjectDto(metadata.name(), unit);
        } else if (metadata.getClassId() == CLASS_ID_DATA) {
            final GetResult resultValue = resultList.get(idx++);
            final Integer meterValue = this.dlmsHelper.readInteger(resultValue, "Actual Power Quality - " + metadata.getObisCode());
            powerQualityValue = meterValue != null ? new PowerQualityValueDto(new BigDecimal(meterValue)) : null;
            powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
        } else {
            throw new ProtocolAdapterException(String.format("Unsupported ClassId {} for logical name {}", metadata.getClassId(), metadata.obisCode));
        }
        powerQualityObjects.add(powerQualityObject);
        powerQualityValues.add(powerQualityValue);
    }
    return new ActualPowerQualityDataDto(powerQualityObjects, powerQualityValues);
}
Also used : ActualPowerQualityDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) PowerQualityObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto) PowerQualityValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Example 9 with CosemDateTimeDto

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

the class AbstractGetPowerQualityProfileHandler method makeDateProfileEntryValueDto.

private ProfileEntryValueDto makeDateProfileEntryValueDto(final DataObject dataObject, final ProfileEntryDto previousProfileEntryDto, final int timeInterval) {
    final CosemDateTimeDto cosemDateTime = this.dlmsHelper.convertDataObjectToDateTime(dataObject);
    if (cosemDateTime == null) {
        // in case of null date, we calculate the date based on the always
        // existing previous value plus interval
        final Date previousDate = (Date) previousProfileEntryDto.getProfileEntryValues().get(0).getValue();
        final LocalDateTime newLocalDateTime = Instant.ofEpochMilli(previousDate.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime().plusMinutes(timeInterval);
        return new ProfileEntryValueDto(Date.from(newLocalDateTime.atZone(ZoneId.systemDefault()).toInstant()));
    } else {
        return new ProfileEntryValueDto(cosemDateTime.asDateTime().toDate());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ProfileEntryValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ProfileEntryValueDto) Date(java.util.Date) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Example 10 with CosemDateTimeDto

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

the class AbstractPeriodicMeterReadsCommandExecutor method readClock.

/**
 * Calculates/derives the date of the read buffered DataObject.
 *
 * @param ctx context elements for the buffered object conversion
 * @param previousLogTime the log time of the previous meter read
 * @param dlmsHelper dlms helper object
 * @return the date of the buffered {@link DataObject} or null if it cannot be determined
 * @throws ProtocolAdapterException
 * @throws BufferedDateTimeValidationException in case the date is invalid or null
 */
Date readClock(final ConversionContext ctx, final Optional<Date> previousLogTime, final DlmsHelper dlmsHelper) throws ProtocolAdapterException, BufferedDateTimeValidationException {
    final Date logTime;
    final PeriodTypeDto queryPeriodType = ctx.periodicMeterReadsQuery.getPeriodType();
    final DateTime from = new DateTime(ctx.periodicMeterReadsQuery.getBeginDate());
    final DateTime to = new DateTime(ctx.periodicMeterReadsQuery.getEndDate());
    final Integer clockIndex = ctx.attributeAddressForProfile.getIndex(DlmsObjectType.CLOCK, null);
    CosemDateTimeDto cosemDateTime = null;
    if (clockIndex != null) {
        cosemDateTime = dlmsHelper.readDateTime(ctx.bufferedObjects.get(clockIndex), "Clock from " + queryPeriodType + " buffer");
    }
    final DateTime bufferedDateTime = cosemDateTime == null ? null : cosemDateTime.asDateTime();
    if (bufferedDateTime != null) {
        dlmsHelper.validateBufferedDateTime(bufferedDateTime, from, to);
        logTime = bufferedDateTime.toDate();
    } else {
        logTime = this.calculateIntervalTimeBasedOnPreviousValue(ctx.periodicMeterReadsQuery.getPeriodType(), previousLogTime, ctx.intervalTime);
    }
    if (logTime == null) {
        throw new BufferedDateTimeValidationException("Unable to calculate logTime");
    }
    return logTime;
}
Also used : BufferedDateTimeValidationException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) Date(java.util.Date) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Aggregations

CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)17 DateTime (org.joda.time.DateTime)6 GetResult (org.openmuc.jdlms.GetResult)6 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)6 Date (java.util.Date)5 Test (org.junit.jupiter.api.Test)5 AttributeAddress (org.openmuc.jdlms.AttributeAddress)4 DataObject (org.openmuc.jdlms.datatypes.DataObject)4 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)4 ArrayList (java.util.ArrayList)3 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)3 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)3 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)3 LocalDateTime (java.time.LocalDateTime)2 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)2 DlmsCaptureObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject)2 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)2 DlmsClock (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock)2 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)2 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)2