use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto 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);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto 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));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto 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);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutor method convertToResponseItem.
private PeriodicMeterReadsResponseItemDto convertToResponseItem(final ConversionContext ctx, final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads) throws ProtocolAdapterException, BufferedDateTimeValidationException {
LOGGER.info("Converting bufferObject with value: {} ", ctx.bufferedObjects);
final Optional<Date> previousLogTime = this.getPreviousLogTime(periodicMeterReads);
final Date logTime = this.readClock(ctx, previousLogTime, this.dlmsHelper);
final AmrProfileStatusCodeDto status = this.readStatus(ctx.bufferedObjects, ctx.attributeAddressForProfile);
if (ctx.periodicMeterReadsQuery.getPeriodType() == PeriodTypeDto.INTERVAL) {
final DlmsMeterValueDto importValue = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_IMPORT, "positiveActiveEnergy");
final DlmsMeterValueDto exportValue = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_EXPORT, "negativeActiveEnergy");
LOGGER.info("Resulting values: LogTime: {}, status: {}, importValue {}, exportValue {} ", logTime, status, importValue, exportValue);
return new PeriodicMeterReadsResponseItemDto(logTime, importValue, exportValue, status);
} else {
final DlmsMeterValueDto importValueRate1 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_1, "positiveActiveEnergyTariff1");
final DlmsMeterValueDto importValueRate2 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_2, "positiveActiveEnergyTariff2");
final DlmsMeterValueDto exportValueRate1 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_1, "negativeActiveEnergyTariff1");
final DlmsMeterValueDto exportValueRate2 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_2, "negativeActiveEnergyTariff2");
LOGGER.info("Resulting values: LogTime: {}, status: {}, importRate1Value {}, importRate2Value {}, " + "exportRate1Value {}, exportRate2Value {} ", logTime, status, importValueRate1, importValueRate2, exportValueRate1, exportValueRate2);
return new PeriodicMeterReadsResponseItemDto(logTime, importValueRate1, importValueRate2, exportValueRate1, exportValueRate2, status);
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.
the class PeriodicMeterReadContainerMappingTest method mapsPeriodicMeterReadsResponseItemDto.
@Test
public void mapsPeriodicMeterReadsResponseItemDto() {
final Date logTime = new Date();
final ActiveEnergyValuesDto valuesDto = 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 AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(new HashSet<>(asList(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR, AmrProfileStatusCodeFlagDto.CLOCK_ADJUSTED)));
final PeriodicMeterReadsResponseItemDto source = new PeriodicMeterReadsResponseItemDto(logTime, valuesDto, amrProfileStatusCodeDto);
final PeriodicMeterReads readsResult = this.monitoringMapper.map(source, PeriodicMeterReads.class);
final ActiveEnergyValues expectedValues = 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 AmrProfileStatusCode amrProfileStatusCode = new AmrProfileStatusCode(new HashSet<>(asList(AmrProfileStatusCodeFlag.CRITICAL_ERROR, AmrProfileStatusCodeFlag.CLOCK_ADJUSTED)));
final PeriodicMeterReads expectedReads = new PeriodicMeterReads(logTime, expectedValues, amrProfileStatusCode);
assertThat(readsResult).usingRecursiveComparison().isEqualTo(expectedReads);
}
Aggregations