use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class AbstractGetPowerQualityProfileHandler method createScalerUnitInfo.
private ScalerUnitInfo createScalerUnitInfo(final DlmsConnectionManager conn, final DlmsDevice device, final CaptureObjectDefinitionDto captureObjectDefinitionDto) throws ProtocolAdapterException {
final int classId = captureObjectDefinitionDto.getClassId();
final String logicalName = captureObjectDefinitionDto.getLogicalName().toString();
if (this.hasScalerUnit(classId)) {
final AttributeAddress addr = new AttributeAddress(classId, logicalName, SCALER_UNITS_MAP.get(classId));
final List<GetResult> scalerUnitResult = this.dlmsHelper.getAndCheck(conn, device, "retrieve scaler unit for capture object", addr);
final DataObject scalerUnitDataObject = scalerUnitResult.get(0).getResultData();
return new ScalerUnitInfo(logicalName, classId, scalerUnitDataObject);
} else {
return new ScalerUnitInfo(logicalName, classId, null);
}
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class AbstractGetPowerQualityProfileHandler method createSelectableCaptureObjects.
// the available CaptureObjects are filtered with the ones that can be
// selected
private List<CaptureObjectDto> createSelectableCaptureObjects(final List<GetResult> captureObjects, final List<ScalerUnitInfo> scalerUnitInfos, final List<CaptureObjectDefinitionDto> selectableCaptureObjects) throws ProtocolAdapterException {
final List<CaptureObjectDto> captureObjectDtos = new ArrayList<>();
for (final GetResult captureObjectResult : captureObjects) {
final DataObject dataObject = captureObjectResult.getResultData();
final List<DataObject> captureObjectList = dataObject.getValue();
for (final DataObject object : captureObjectList) {
final boolean addCaptureObject = this.isSelectableValue(selectableCaptureObjects, object);
if (addCaptureObject) {
captureObjectDtos.add(this.makeCaptureObjectDto(object, scalerUnitInfos.get(captureObjectDtos.size())));
}
}
}
return captureObjectDtos;
}
use of org.openmuc.jdlms.GetResult 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;
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class AbstractGetPowerQualityProfileHandler method createSelectableCaptureObjects.
private Map<Integer, CaptureObjectDefinitionDto> createSelectableCaptureObjects(final List<GetResult> captureObjects, final List<SelectableObisCode> logicalNames) throws ProtocolAdapterException {
final Map<Integer, CaptureObjectDefinitionDto> selectableCaptureObjects = new HashMap<>();
// there is always only one GetResult
for (final GetResult captureObjectResult : captureObjects) {
final List<DataObject> dataObjects = captureObjectResult.getResultData().getValue();
for (int positionInDataObjectsList = 0; positionInDataObjectsList < dataObjects.size(); positionInDataObjectsList++) {
final DataObject dataObject = dataObjects.get(positionInDataObjectsList);
final CosemObjectDefinitionDto cosemObjectDefinitionDto = this.dlmsHelper.readObjectDefinition(dataObject, CAPTURE_OBJECT);
final Optional<SelectableObisCode> logicalName = SelectableObisCode.getByObisCode(cosemObjectDefinitionDto.getLogicalName().toString());
if (logicalName.isPresent() && logicalNames.contains(logicalName.get())) {
selectableCaptureObjects.put(positionInDataObjectsList, new CaptureObjectDefinitionDto(cosemObjectDefinitionDto.getClassId(), new ObisCodeValuesDto(logicalName.get().obisCode), (byte) cosemObjectDefinitionDto.getAttributeIndex(), cosemObjectDefinitionDto.getDataIndex()));
}
}
}
return selectableCaptureObjects;
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutor method execute.
@Override
public PeriodicMeterReadGasResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final PeriodicMeterReadsRequestDto periodicMeterReadsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
if (periodicMeterReadsQuery == null) {
throw new IllegalArgumentException("PeriodicMeterReadsQuery should contain PeriodType, BeginDate and EndDate.");
}
final PeriodTypeDto queryPeriodType = periodicMeterReadsQuery.getPeriodType();
final DateTime from = new DateTime(periodicMeterReadsQuery.getBeginDate());
final DateTime to = new DateTime(periodicMeterReadsQuery.getEndDate());
final AttributeAddressForProfile profileBufferAddress = this.getProfileBufferAddress(queryPeriodType, periodicMeterReadsQuery.getChannel(), from, to, device);
final List<AttributeAddress> scalerUnitAddresses = this.getScalerUnitAddresses(periodicMeterReadsQuery.getChannel(), profileBufferAddress);
final Optional<ProfileCaptureTime> intervalTime = this.getProfileCaptureTime(device, this.dlmsObjectConfigService, Medium.GAS);
LOGGER.info("Retrieving current billing period and profiles for gas for period type: {}, from: " + "{}, to: {}", queryPeriodType, from, to);
/*
* workaround for a problem when using with_list and retrieving a profile
* buffer, this will be returned erroneously.
*/
final List<GetResult> getResultList = new ArrayList<>();
final List<AttributeAddress> allAttributeAddresses = new ArrayList<>();
allAttributeAddresses.add(profileBufferAddress.getAttributeAddress());
allAttributeAddresses.addAll(scalerUnitAddresses);
for (final AttributeAddress address : allAttributeAddresses) {
conn.getDlmsMessageListener().setDescription(String.format(FORMAT_DESCRIPTION, periodicMeterReadsQuery.getChannel(), queryPeriodType, from, to, JdlmsObjectToStringUtil.describeAttributes(address)));
getResultList.addAll(this.dlmsHelper.getAndCheck(conn, device, "retrieve periodic meter reads for " + queryPeriodType + ", channel " + periodicMeterReadsQuery.getChannel(), address));
}
LOGGER.info("Received getResult: {} ", getResultList);
final DataObject resultData = this.dlmsHelper.readDataObject(getResultList.get(0), PERIODIC_G_METER_READS);
final List<DataObject> bufferedObjectsList = resultData.getValue();
final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads = new ArrayList<>();
for (final DataObject bufferedObject : bufferedObjectsList) {
final List<DataObject> bufferedObjectValue = bufferedObject.getValue();
try {
periodicMeterReads.add(this.convertToResponseItem(new ConversionContext(periodicMeterReadsQuery, bufferedObjectValue, getResultList, profileBufferAddress, scalerUnitAddresses, intervalTime), periodicMeterReads));
} catch (final BufferedDateTimeValidationException e) {
LOGGER.warn(e.getMessage(), e);
}
}
LOGGER.info("Resulting periodicMeterReads: {} ", periodicMeterReads);
return new PeriodicMeterReadGasResponseDto(queryPeriodType, periodicMeterReads);
}
Aggregations