use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class DeviceChannelsHelper method readIdentificationNumber.
private String readIdentificationNumber(final List<GetResult> resultList, final int index, final DlmsObject clientSetupObject, final String description) throws ProtocolAdapterException {
final GetResult getResult = resultList.get(index);
final DataObject resultData = getResult.getResultData();
if (resultData == null) {
return null;
} else {
final Long identification = this.dlmsHelper.readLong(resultData, description);
final IdentificationNumber identificationNumber;
if (this.identificationNumberStoredAsBcdOnDevice(clientSetupObject)) {
identificationNumber = IdentificationNumber.fromBcdRepresentationAsLong(identification);
} else {
identificationNumber = IdentificationNumber.fromNumericalRepresentation(identification);
}
return identificationNumber.getTextualRepresentation();
}
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class GetActualMeterReadsCommandExecutor method execute.
@Override
public MeterReadsResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActualMeterReadsQueryDto actualMeterReadsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
if (actualMeterReadsQuery != null && actualMeterReadsQuery.isMbusQuery()) {
throw new IllegalArgumentException("ActualMeterReadsQuery object for energy reads should not be about gas.");
}
conn.getDlmsMessageListener().setDescription("GetActualMeterReads retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_ADDRESSES));
LOGGER.info("Retrieving actual energy reads");
final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "retrieve actual meter reads", ATTRIBUTE_ADDRESSES);
final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(getResultList.get(INDEX_TIME), "Actual Energy Reads Time");
final DateTime time = cosemDateTime.asDateTime();
if (time == null) {
throw new ProtocolAdapterException("Unexpected null/unspecified value for Actual Energy Reads Time");
}
final DlmsMeterValueDto activeEnergyImport = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_SCALER_UNIT), "Actual Energy Reads +A");
final DlmsMeterValueDto activeEnergyExport = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_SCALER_UNIT), "Actual Energy Reads -A");
final DlmsMeterValueDto activeEnergyImportRate1 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_1), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_1_SCALER_UNIT), "Actual Energy Reads +A rate 1");
final DlmsMeterValueDto activeEnergyImportRate2 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_2), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_2_SCALER_UNIT), "Actual Energy Reads +A rate 2");
final DlmsMeterValueDto activeEnergyExportRate1 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_1), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_1_SCALER_UNIT), "Actual Energy Reads -A rate 1");
final DlmsMeterValueDto activeEnergyExportRate2 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_2), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_2_SCALER_UNIT), "Actual Energy Reads -A rate 2");
return new MeterReadsResponseDto(time.toDate(), new ActiveEnergyValuesDto(activeEnergyImport, activeEnergyExport, activeEnergyImportRate1, activeEnergyImportRate2, activeEnergyExportRate1, activeEnergyExportRate2));
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class JdlmsObjectToStringUtilTest method testDescribeGetResults.
@Test
public void testDescribeGetResults() {
final GetResult getResult1 = new GetResultImpl(DataObject.newInteger32Data(100), AccessResultCode.SUCCESS);
final GetResult getResult2 = new GetResultImpl(DataObject.newVisibleStringData("Test".getBytes()), AccessResultCode.OBJECT_UNDEFINED);
final String description = JdlmsObjectToStringUtil.describeGetResults(Arrays.asList(getResult1, getResult2));
assertThat(description).isEqualTo("{SUCCESS, DOUBLE_LONG Value: 100 - OBJECT_UNDEFINED, VISIBLE_STRING Value: Test}");
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class JdlmsObjectToStringUtilTest method testDescribeGetResultWithSuccess.
@Test
public void testDescribeGetResultWithSuccess() {
final GetResult getResult = new GetResultImpl(DataObject.newInteger32Data(100), AccessResultCode.SUCCESS);
final String description = JdlmsObjectToStringUtil.describeGetResult(getResult);
assertThat(description).isEqualTo("SUCCESS, DOUBLE_LONG Value: 100");
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class ClearMBusStatusOnAllChannelsCommandExecutor method readStatus.
private long readStatus(final DlmsConnectionManager conn, final Integer channel, final AttributeAddress attributeAddress) throws IOException, ProtocolAdapterException {
conn.getDlmsMessageListener().setDescription("ClearMBusStatusOnAllChannels-readStatus for channel" + channel + " - read status" + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
log.info("Reading status for M-Bus channel {} with attributeAddress: {}.", channel, attributeAddress);
final GetResult result = conn.getConnection().get(attributeAddress);
if (result == null) {
throw new ProtocolAdapterException("No GetResult received while reading status for M-Bus channel " + channel + ".");
}
return this.parseStatusFilter(result.getResultData(), channel);
}
Aggregations