Search in sources :

Example 36 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class CosemObjectAccessor method writeAttribute.

public void writeAttribute(final AttributeClass attributeClass, final DataObject data) throws ProtocolAdapterException {
    final AttributeAddress attributeAddress = this.createAttributeAddress(attributeClass);
    final SetParameter setParameter = new SetParameter(attributeAddress, data);
    final AccessResultCode accessResultCode;
    try {
        accessResultCode = this.connector.getConnection().set(setParameter);
    } catch (final IOException e) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_WRITING_ATTRIBUTE, attributeClass, this.classId, this.obisCode), e);
    }
    if (accessResultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_ACCESS_RESULT_NOT_SUCCESS, accessResultCode.name(), attributeClass, this.classId, this.obisCode));
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SetParameter(org.openmuc.jdlms.SetParameter)

Example 37 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class DlmsHelper method checkResultCode.

private void checkResultCode(final GetResult getResult, final String description) throws ProtocolAdapterException {
    final AccessResultCode resultCode = getResult.getResultCode();
    LOGGER.debug("{} - AccessResultCode: {}", description, resultCode);
    if (resultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException("No success retrieving " + description + ": AccessResultCode = " + resultCode);
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 38 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class DlmsHelper method getAttributeValue.

/**
 * Gets a single result from a meter, and returns the result data if retrieval was successful
 * (resultCode of the GetResult equals AccessResultCode.SUCCESS).
 *
 * @return a result from trying to retrieve the value for the attribute identified by {@code
 *     attributeAddress}.
 */
public DataObject getAttributeValue(final DlmsConnectionManager conn, final AttributeAddress attributeAddress) throws FunctionalException {
    Objects.requireNonNull(conn, "conn must not be null");
    Objects.requireNonNull(attributeAddress, "attributeAddress must not be null");
    try {
        final GetResult getResult = conn.getConnection().get(attributeAddress);
        final AccessResultCode resultCode = getResult.getResultCode();
        if (AccessResultCode.SUCCESS == resultCode) {
            return getResult.getResultData();
        }
        final String errorMessage = String.format("Retrieving attribute value for { %d, %s, %d }. Result: resultCode(%d), with data: %s", attributeAddress.getClassId(), attributeAddress.getInstanceId().asShortObisCodeString(), attributeAddress.getId(), resultCode.getCode(), this.getDebugInfo(getResult.getResultData()));
        LOGGER.error(errorMessage);
        throw new FunctionalException(FunctionalExceptionType.ERROR_RETRIEVING_ATTRIBUTE_VALUE, ComponentType.PROTOCOL_DLMS, new OsgpException(ComponentType.PROTOCOL_DLMS, errorMessage));
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetResult(org.openmuc.jdlms.GetResult) AccessResultCode(org.openmuc.jdlms.AccessResultCode) BitString(org.openmuc.jdlms.datatypes.BitString) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) IOException(java.io.IOException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 39 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class SetPushSetupAlarmCommandExecutor method setSendDestinationAndMethod.

private AccessResultCode setSendDestinationAndMethod(final DlmsConnectionManager conn, final PushSetupAlarmDto pushSetupAlarm, final DlmsDevice device) throws ProtocolAdapterException {
    LOGGER.info("Setting Send destination and method of Push Setup Alarm: {}", pushSetupAlarm.getSendDestinationAndMethod());
    final SetParameter setParameterSendDestinationAndMethod = this.getSetParameterSendDestinationAndMethod(pushSetupAlarm, device);
    final AccessResultCode resultCode = this.doSetRequest("PushSetupAlarm, Send destination and method", conn, setParameterSendDestinationAndMethod);
    if (resultCode != null) {
        return resultCode;
    } else {
        throw new ProtocolAdapterException("Error setting Alarm push setup data (destination and method.");
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SetParameter(org.openmuc.jdlms.SetParameter)

Example 40 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class SetPushSetupAlarmCommandExecutor method setPushObjectList.

private AccessResultCode setPushObjectList(final DlmsConnectionManager conn, final PushSetupAlarmDto pushSetupAlarm) throws ProtocolAdapterException {
    LOGGER.info("Setting Push Object List of Push Setup Alarm: {}", pushSetupAlarm.getPushObjectList());
    // Before setting the push object list, verify if the objects in the list are really present in
    // the meter
    this.verifyPushObjects(pushSetupAlarm.getPushObjectList(), conn);
    final SetParameter setParameterPushObjectList = this.getSetParameterPushObjectList(pushSetupAlarm);
    final AccessResultCode resultCode = this.doSetRequest("PushSetupAlarm, push object list", conn, setParameterPushObjectList);
    if (resultCode != null) {
        return resultCode;
    } else {
        throw new ProtocolAdapterException("Error setting Alarm push setup data (push object list).");
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SetParameter(org.openmuc.jdlms.SetParameter)

Aggregations

AccessResultCode (org.openmuc.jdlms.AccessResultCode)44 Test (org.junit.jupiter.api.Test)17 SetParameter (org.openmuc.jdlms.SetParameter)16 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)15 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 AttributeAddress (org.openmuc.jdlms.AttributeAddress)11 AlarmNotificationDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto)8 IOException (java.io.IOException)4 ActivityCalendarDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto)4 AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)4 ConfigurationObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)4 PushSetupAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto)4 CsvSource (org.junit.jupiter.params.provider.CsvSource)3 BitString (org.openmuc.jdlms.datatypes.BitString)3 DataObject (org.openmuc.jdlms.datatypes.DataObject)3 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)3 CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)3 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)3 GprsOperationModeTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto)3