use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto 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.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto in project open-smart-grid-platform by OSGP.
the class AbstractGetPowerQualityProfileHandler method getUnitType.
private DlmsUnitTypeDto getUnitType(final ScalerUnitInfo scalerUnitInfo) {
if (scalerUnitInfo.getScalerUnit() != null) {
final List<DataObject> dataObjects = scalerUnitInfo.getScalerUnit().getValue();
final int index = Integer.parseInt(dataObjects.get(1).getValue().toString());
final DlmsUnitTypeDto unitType = DlmsUnitTypeDto.getUnitType(index);
if (unitType != null) {
return unitType;
}
}
return DlmsUnitTypeDto.UNDEFINED;
}
Aggregations