use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class BundleServiceTest method testException.
@Test
public void testException() {
final List<ActionDto> actionDtoList = this.makeActions();
final BundleMessagesRequestDto dto = new BundleMessagesRequestDto(actionDtoList);
this.getStub(FindEventsRequestDto.class).failWith(new ProtocolAdapterException("simulate error"));
final BundleMessagesRequestDto result = this.callExecutors(dto, this.messageMetadata);
this.assertResult(result);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetActualPowerQualityCommandExecutor method makeActualPowerQualityDataDto.
private ActualPowerQualityDataDto makeActualPowerQualityDataDto(final List<GetResult> resultList, final List<PowerQualityObjectMetadata> metadatas) throws ProtocolAdapterException {
final List<PowerQualityObjectDto> powerQualityObjects = new ArrayList<>();
final List<PowerQualityValueDto> powerQualityValues = new ArrayList<>();
int idx = 0;
for (final PowerQualityObjectMetadata metadata : metadatas) {
final PowerQualityObjectDto powerQualityObject;
final PowerQualityValueDto powerQualityValue;
if (metadata.getClassId() == CLASS_ID_CLOCK) {
final GetResult resultTime = resultList.get(idx++);
final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(resultTime, "Actual Power Quality - Time");
powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
powerQualityValue = new PowerQualityValueDto(cosemDateTime.asDateTime().toDate());
} else if (metadata.getClassId() == CLASS_ID_REGISTER) {
final GetResult resultValue = resultList.get(idx++);
final GetResult resultScalerUnit = resultList.get(idx++);
final DlmsMeterValueDto meterValue = this.dlmsHelper.getScaledMeterValue(resultValue, resultScalerUnit, "Actual Power Quality - " + metadata.getObisCode());
final BigDecimal value = meterValue != null ? meterValue.getValue() : null;
final String unit = meterValue != null ? meterValue.getDlmsUnit().getUnit() : null;
powerQualityValue = new PowerQualityValueDto(value);
powerQualityObject = new PowerQualityObjectDto(metadata.name(), unit);
} else if (metadata.getClassId() == CLASS_ID_DATA) {
final GetResult resultValue = resultList.get(idx++);
final Integer meterValue = this.dlmsHelper.readInteger(resultValue, "Actual Power Quality - " + metadata.getObisCode());
powerQualityValue = meterValue != null ? new PowerQualityValueDto(new BigDecimal(meterValue)) : null;
powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
} else {
throw new ProtocolAdapterException(String.format("Unsupported ClassId {} for logical name {}", metadata.getClassId(), metadata.obisCode));
}
powerQualityObjects.add(powerQualityObject);
powerQualityValues.add(powerQualityValue);
}
return new ActualPowerQualityDataDto(powerQualityObjects, powerQualityValues);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutor method readCaptureTime.
private Date readCaptureTime(final ConversionContext ctx, final Optional<Date> previousCaptureTime) throws ProtocolAdapterException, BufferedDateTimeValidationException {
final List<DataObject> bufferedObjects = ctx.bufferedObjects;
final AttributeAddressForProfile attributeAddressForProfile = ctx.attributeAddressForProfile;
final Integer captureTimeIndex = attributeAddressForProfile.getIndex(DlmsObjectType.MBUS_MASTER_VALUE, 5);
if (captureTimeIndex != null) {
final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(bufferedObjects.get(captureTimeIndex), "Clock from mbus interval extended register");
if (cosemDateTime != null) {
if (cosemDateTime.isDateTimeSpecified()) {
return cosemDateTime.asDateTime().toDate();
} else {
throw new ProtocolAdapterException(UNEXPECTED_VALUE);
}
} else {
return this.calculateIntervalTimeBasedOnPreviousValue(ctx.periodicMeterReadsQuery.getPeriodType(), previousCaptureTime, ctx.intervalTime);
}
}
return null;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutor method execute.
@Override
public List<EventDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final FindEventsRequestDto findEventsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final SelectiveAccessDescription selectiveAccessDescription = this.getSelectiveAccessDescription(device, findEventsQuery.getFrom(), findEventsQuery.getUntil());
final DlmsObject eventLogObject = this.dlmsObjectConfigService.getDlmsObject(device, EVENT_LOG_CATEGORY_OBISCODE_MAP.get(findEventsQuery.getEventLogCategory()));
final AttributeAddress eventLogBuffer = new AttributeAddress(eventLogObject.getClassId(), eventLogObject.getObisCode(), eventLogObject.getDefaultAttributeId(), selectiveAccessDescription);
conn.getDlmsMessageListener().setDescription("RetrieveEvents for " + findEventsQuery.getEventLogCategory() + " from " + findEventsQuery.getFrom() + " until " + findEventsQuery.getUntil() + ", retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(eventLogBuffer));
final GetResult getResult;
try {
getResult = conn.getConnection().get(eventLogBuffer);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (getResult == null) {
throw new ProtocolAdapterException("No GetResult received while retrieving event register " + findEventsQuery.getEventLogCategory());
}
if (!AccessResultCode.SUCCESS.equals(getResult.getResultCode())) {
LOGGER.info("Result of getting events for {} is {}", findEventsQuery.getEventLogCategory(), getResult.getResultCode());
throw new ProtocolAdapterException("Getting the events for " + findEventsQuery.getEventLogCategory() + " from the meter resulted in: " + getResult.getResultCode());
}
final DataObject resultData = getResult.getResultData();
return this.dataObjectToEventListConverter.convert(resultData, findEventsQuery.getEventLogCategory());
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetAssociationLnObjectsCommandExecutor method execute.
@Override
public AssociationLnListTypeDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void object, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final AttributeAddress attributeAddress = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
conn.getDlmsMessageListener().setDescription("GetAssociationLnObjects, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
LOGGER.debug("Retrieving Association LN objects for class id: {}, obis code: {}, attribute id: {}", CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "Association LN Objects", attributeAddress);
final DataObject resultData = getResultList.get(0).getResultData();
if (!resultData.isComplex()) {
throw new ProtocolAdapterException("Unexpected type of element");
}
final List<DataObject> associationLnListObjects = resultData.getValue();
final List<AssociationLnListElementDto> elements = this.convertAssociationLnList(associationLnListObjects);
return new AssociationLnListTypeDto(elements);
}
Aggregations