use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class GetSpecificAttributeValueCommandExecutor method execute.
@Override
public String execute(final DlmsConnectionManager conn, final DlmsDevice device, final SpecificAttributeValueRequestDto requestData, final MessageMetadata messageMetadata) throws FunctionalException {
final ObisCodeValuesDto obisCodeValues = requestData.getObisCode();
final byte[] obisCodeBytes = { obisCodeValues.getA(), obisCodeValues.getB(), obisCodeValues.getC(), obisCodeValues.getD(), obisCodeValues.getE(), obisCodeValues.getF() };
final ObisCode obisCode = new ObisCode(obisCodeBytes);
LOGGER.debug("Get specific attribute value, class id: {}, obis code: {}, attribute id: {}", requestData.getClassId(), obisCode, requestData.getAttribute());
final AttributeAddress attributeAddress = new AttributeAddress(requestData.getClassId(), obisCode, requestData.getAttribute());
conn.getDlmsMessageListener().setDescription("GetSpecificAttributeValue, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
final DataObject attributeValue = this.dlmsHelper.getAttributeValue(conn, attributeAddress);
return this.dlmsHelper.getDebugInfo(attributeValue);
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class GetPowerQualityProfileSelectiveAccessHandler method createProfileEntryValueDto.
@Override
protected List<ProfileEntryValueDto> createProfileEntryValueDto(final DataObject profileEntryDataObject, final List<ScalerUnitInfo> scalerUnitInfos, final ProfileEntryDto previousProfileEntryDto, final Map<Integer, CaptureObjectDefinitionDto> selectableCaptureObjects, final int timeInterval) {
final List<ProfileEntryValueDto> result = new ArrayList<>();
final List<DataObject> dataObjects = profileEntryDataObject.getValue();
for (int i = 0; i < dataObjects.size(); i++) {
final ProfileEntryValueDto currentProfileEntryValueDto = super.makeProfileEntryValueDto(dataObjects.get(i), scalerUnitInfos.get(i), previousProfileEntryDto, timeInterval);
result.add(currentProfileEntryValueDto);
}
return result;
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutor method execute.
@Override
public PeriodicMeterReadsResponseDto 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, from, to, device);
final List<AttributeAddress> scalerUnitAddresses = this.getScalerUnitAddresses(profileBufferAddress);
final Optional<ProfileCaptureTime> intervalTime = this.getProfileCaptureTime(device, this.dlmsObjectConfigService, Medium.ELECTRICITY);
LOGGER.debug("Retrieving current billing period and profiles for period type: {}, from: {}, to: {}", queryPeriodType, from, to);
// Get results one by one because getWithList does not work for all devices
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, queryPeriodType, from, to, JdlmsObjectToStringUtil.describeAttributes(address)));
getResultList.addAll(this.dlmsHelper.getAndCheck(conn, device, "retrieve periodic meter reads for " + queryPeriodType, address));
}
LOGGER.info("Received getResult: {} ", getResultList);
final DataObject resultData = this.dlmsHelper.readDataObject(getResultList.get(0), PERIODIC_E_METER_READS);
final List<DataObject> bufferedObjectsList = resultData.getValue();
final List<PeriodicMeterReadsResponseItemDto> 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);
}
}
return new PeriodicMeterReadsResponseDto(queryPeriodType, periodicMeterReads);
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutor method getSelectiveAccessDescription.
private SelectiveAccessDescription getSelectiveAccessDescription(final DlmsDevice device, final DateTime beginDateTime, final DateTime endDateTime) throws ProtocolAdapterException {
/*
* Define the clock object {8,0-0:1.0.0.255,2,0} to be used as
* restricting object in a range descriptor with a from value and to
* value to determine which elements from the buffered array should be
* retrieved.
*/
final DlmsObject clockObject = this.dlmsObjectConfigService.getDlmsObject(device, DlmsObjectType.CLOCK);
final DataObject clockDefinition = DataObject.newStructureData(Arrays.asList(DataObject.newUInteger16Data(clockObject.getClassId()), DataObject.newOctetStringData(clockObject.getObisCode().bytes()), DataObject.newInteger8Data((byte) clockObject.getDefaultAttributeId()), DataObject.newUInteger16Data(0)));
final DataObject fromValue = this.dlmsHelper.asDataObject(beginDateTime);
final DataObject toValue = this.dlmsHelper.asDataObject(endDateTime);
/*
* Retrieve all captured objects by setting selectedValues to an empty
* array.
*/
final DataObject selectedValues = DataObject.newArrayData(Collections.emptyList());
final DataObject accessParameter = DataObject.newStructureData(Arrays.asList(clockDefinition, fromValue, toValue, selectedValues));
return new SelectiveAccessDescription(ACCESS_SELECTOR_RANGE_DESCRIPTOR, accessParameter);
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class GetAdministrativeStatusCommandExecutor method execute.
@Override
public AdministrativeStatusTypeDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void useless, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final AttributeAddress getParameter = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
conn.getDlmsMessageListener().setDescription("GetAdministrativeStatus, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(getParameter));
LOGGER.info("Retrieving current administrative status by issuing get request for class id: {}, obis code: {}, " + "attribute id: {}", CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
final DataObject dataObject = this.getValidatedResultData(conn, getParameter);
return this.configurationMapper.map(dataObject.getValue(), AdministrativeStatusTypeDto.class);
}
Aggregations