use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelper method readList.
private List<DataObject> readList(final DataObject resultData, final String description) throws ProtocolAdapterException {
this.logDebugResultData(resultData, description);
if (resultData == null || resultData.isNull()) {
return Collections.emptyList();
}
final Object resultValue = resultData.getValue();
if (!resultData.isComplex() || !(resultValue instanceof List)) {
this.logAndThrowExceptionForUnexpectedResultData(resultData, "List");
}
return (List<DataObject>) resultValue;
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelper method getScaledMeterValue.
public DlmsMeterValueDto getScaledMeterValue(final DataObject value, final DataObject scalerUnitObject, final String description) throws ProtocolAdapterException {
LOGGER.debug(this.getDebugInfo(value));
LOGGER.debug(this.getDebugInfo(scalerUnitObject));
final Long rawValue = this.readLong(value, description);
if (rawValue == null) {
return null;
}
if (!scalerUnitObject.isComplex()) {
throw new ProtocolAdapterException("complex data (structure) expected while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
}
final List<DataObject> dataObjects = scalerUnitObject.getValue();
if (dataObjects.size() != 2) {
throw new ProtocolAdapterException("expected 2 values while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
}
final int scaler = this.readLongNotNull(dataObjects.get(0), description).intValue();
final DlmsUnitTypeDto unit = DlmsUnitTypeDto.getUnitType(this.readLongNotNull(dataObjects.get(1), description).intValue());
// determine value
BigDecimal scaledValue = BigDecimal.valueOf(rawValue);
if (scaler != 0) {
scaledValue = scaledValue.multiply(BigDecimal.valueOf(Math.pow(10, scaler)));
}
return new DlmsMeterValueDto(scaledValue, unit);
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelper method readNumber.
private Number readNumber(final DataObject resultData, final String description, final String interpretation) throws ProtocolAdapterException {
this.logDebugResultData(resultData, description);
if (resultData == null || resultData.isNull()) {
return null;
}
final Object resultValue = resultData.getValue();
if (!resultData.isNumber() || !(resultValue instanceof Number)) {
this.logAndThrowExceptionForUnexpectedResultData(resultData, interpretation);
}
return (Number) resultValue;
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelper method readByteArray.
private byte[] readByteArray(final DataObject resultData, final String description, final String interpretation) throws ProtocolAdapterException {
this.logDebugResultData(resultData, description);
if (resultData == null || resultData.isNull()) {
return new byte[0];
}
final Object resultValue = resultData.getValue();
if (!resultData.isByteArray() || !(resultValue instanceof byte[])) {
this.logAndThrowExceptionForUnexpectedResultData(resultData, "byte array to be interpreted as " + interpretation);
}
return (byte[]) resultValue;
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelper method readListOfWindowElement.
public List<WindowElementDto> readListOfWindowElement(final DataObject resultData, final String description) throws ProtocolAdapterException {
final List<DataObject> listOfWindowElement = this.readList(resultData, description);
if (listOfWindowElement == null) {
return Collections.emptyList();
}
final List<WindowElementDto> windowElementList = new ArrayList<>();
for (final DataObject windowElementObject : listOfWindowElement) {
windowElementList.add(this.readWindowElement(windowElementObject, "Window Element from " + description));
}
return windowElementList;
}
Aggregations