Search in sources :

Example 1 with DlmsUnitTypeDto

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);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsUnitTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) BigDecimal(java.math.BigDecimal) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Example 2 with DlmsUnitTypeDto

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;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsUnitTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto)

Aggregations

DataObject (org.openmuc.jdlms.datatypes.DataObject)2 DlmsUnitTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto)2 BigDecimal (java.math.BigDecimal)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)1