Search in sources :

Example 1 with ConnectionException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.

the class AbstractCommandExecutor method getValidatedResultData.

/**
 * Retrieves connection, gets result data and validates it before returning.
 *
 * @param conn holds connection
 * @param getParameter for attribute to retrieve result data from
 * @return dataObject
 */
public DataObject getValidatedResultData(final DlmsConnectionManager conn, final AttributeAddress getParameter) throws ProtocolAdapterException {
    final GetResult getResult;
    try {
        getResult = conn.getConnection().get(getParameter);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
    if (getResult == null) {
        throw new ProtocolAdapterException("No GetResult received while retrieving M-Bus encryption key status.");
    }
    final DataObject dataObject = getResult.getResultData();
    if (!dataObject.isNumber()) {
        throw new ProtocolAdapterException("Received unexpected result data.");
    }
    return dataObject;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 2 with ConnectionException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutor method executeForAlarmRegister.

public AccessResultCode executeForAlarmRegister(final DlmsConnectionManager conn, final AttributeAddress alarmRegisterAttributeAddress) {
    log.info("Clear alarm register {}", JdlmsObjectToStringUtil.describeAttributes(alarmRegisterAttributeAddress));
    final DataObject data = DataObject.newUInteger32Data(ALARM_CODE);
    final SetParameter setParameter = new SetParameter(alarmRegisterAttributeAddress, data);
    conn.getDlmsMessageListener().setDescription("ClearAlarmRegister, with alarm code = " + ALARM_CODE + JdlmsObjectToStringUtil.describeAttributes(alarmRegisterAttributeAddress));
    try {
        return conn.getConnection().set(setParameter);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) IOException(java.io.IOException) SetParameter(org.openmuc.jdlms.SetParameter) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 3 with ConnectionException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.

the class SetActivityCalendarCommandActivationExecutor method execute.

@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void v, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    LOGGER.info("ACTIVATING PASSIVE CALENDAR");
    final MethodParameter method = new MethodParameter(CLASS_ID, OBIS_CODE, METHOD_ID_ACTIVATE_PASSIVE_CALENDAR, DataObject.newInteger32Data(0));
    conn.getDlmsMessageListener().setDescription("SetActivityCalendarActivation, call method: " + JdlmsObjectToStringUtil.describeMethod(method));
    final MethodResult methodResultCode;
    try {
        methodResultCode = conn.getConnection().action(method);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
    if (!MethodResultCode.SUCCESS.equals(methodResultCode.getResultCode())) {
        throw new ProtocolAdapterException("Activating the activity calendar failed. MethodResult is: " + methodResultCode.getResultCode() + " ClassId: " + CLASS_ID + " obisCode: " + OBIS_CODE + " method id: " + METHOD_ID_ACTIVATE_PASSIVE_CALENDAR);
    }
    return MethodResultCode.SUCCESS;
}
Also used : IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MethodParameter(org.openmuc.jdlms.MethodParameter) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) MethodResult(org.openmuc.jdlms.MethodResult)

Example 4 with ConnectionException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.

the class SetSpecialDaysCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final List<SpecialDayDto> specialDays, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final StringBuilder specialDayData = new StringBuilder();
    final List<DataObject> specialDayEntries = new ArrayList<>();
    int i = 0;
    for (final SpecialDayDto specialDay : specialDays) {
        specialDayData.append(", ").append(specialDay.getDayId()).append(" => ").append(specialDay.getSpecialDayDate());
        final List<DataObject> specDayEntry = new ArrayList<>();
        specDayEntry.add(DataObject.newUInteger16Data(i));
        specDayEntry.add(this.dlmsHelper.asDataObject(specialDay.getSpecialDayDate()));
        specDayEntry.add(DataObject.newUInteger8Data((short) specialDay.getDayId()));
        final DataObject dayStruct = DataObject.newStructureData(specDayEntry);
        specialDayEntries.add(dayStruct);
        i += 1;
    }
    final AttributeAddress specialDaysTableEntries = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
    final DataObject entries = DataObject.newArrayData(specialDayEntries);
    final SetParameter request = new SetParameter(specialDaysTableEntries, entries);
    final String specialDayValues;
    if (specialDayData.length() == 0) {
        specialDayValues = "";
    } else {
        specialDayValues = ", values [" + specialDayData.substring(2) + "]";
    }
    conn.getDlmsMessageListener().setDescription("SetSpecialDays" + specialDayValues + ", set attribute: " + JdlmsObjectToStringUtil.describeAttributes(specialDaysTableEntries));
    try {
        return conn.getConnection().set(request);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) SetParameter(org.openmuc.jdlms.SetParameter) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 5 with ConnectionException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.

the class SynchronizeTimeCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final SynchronizeTimeRequestDto synchronizeTimeRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final DateTime dt = DateTime.now();
    final DataObject time = this.dlmsHelper.asDataObject(dt, synchronizeTimeRequestDto.getDeviation(), synchronizeTimeRequestDto.isDst());
    final SetParameter setParameter = new SetParameter(ATTRIBUTE_TIME, time);
    conn.getDlmsMessageListener().setDescription("SynchronizeTime to " + dt + ", set attribute: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_TIME));
    try {
        return conn.getConnection().set(setParameter);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) IOException(java.io.IOException) SetParameter(org.openmuc.jdlms.SetParameter) DateTime(org.joda.time.DateTime) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Aggregations

ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)25 IOException (java.io.IOException)18 DataObject (org.openmuc.jdlms.datatypes.DataObject)9 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)8 AttributeAddress (org.openmuc.jdlms.AttributeAddress)7 GetResult (org.openmuc.jdlms.GetResult)6 Test (org.junit.jupiter.api.Test)5 SetParameter (org.openmuc.jdlms.SetParameter)5 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)5 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)4 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)4 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)4 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)4 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)4 UnknownHostException (java.net.UnknownHostException)3 AccessResultCode (org.openmuc.jdlms.AccessResultCode)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 ArrayList (java.util.ArrayList)2 MethodParameter (org.openmuc.jdlms.MethodParameter)2