Search in sources :

Example 66 with ProtocolAdapterException

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);
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 67 with ProtocolAdapterException

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);
}
Also used : ActualPowerQualityDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) PowerQualityObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto) PowerQualityValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Example 68 with ProtocolAdapterException

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;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Example 69 with ProtocolAdapterException

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());
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 70 with ProtocolAdapterException

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);
}
Also used : AssociationLnListElementDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AssociationLnListElementDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) AssociationLnListTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AssociationLnListTypeDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)95 DataObject (org.openmuc.jdlms.datatypes.DataObject)32 Test (org.junit.jupiter.api.Test)22 AccessResultCode (org.openmuc.jdlms.AccessResultCode)15 GetResult (org.openmuc.jdlms.GetResult)15 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)9 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)9 BitString (org.openmuc.jdlms.datatypes.BitString)7 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)7 ObisCode (org.openmuc.jdlms.ObisCode)6 SetParameter (org.openmuc.jdlms.SetParameter)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 DateTime (org.joda.time.DateTime)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)4 Date (java.util.Date)3 List (java.util.List)3