Search in sources :

Example 11 with ProtocolAdapterException

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

the class DomainHelperService method getDeviceIpAddressFromSessionProvider.

public String getDeviceIpAddressFromSessionProvider(final DlmsDevice dlmsDevice) throws OsgpException {
    final SessionProvider sessionProvider = this.sessionProviderService.getSessionProvider(dlmsDevice.getCommunicationProvider());
    String deviceIpAddress;
    try {
        deviceIpAddress = sessionProvider.getIpAddress(dlmsDevice.getIccId());
        if (deviceIpAddress != null) {
            return deviceIpAddress;
        }
        // If the result is null then the meter is not in session (not
        // awake).
        // So wake up the meter and start polling for the session
        this.jasperWirelessSmsClient.sendWakeUpSMS(dlmsDevice.getIccId());
        deviceIpAddress = this.pollForSession(sessionProvider, dlmsDevice);
    } catch (final SessionProviderException e) {
        LOGGER.error("IccId is probably not supported in this session provider", e);
        throw new FunctionalException(FunctionalExceptionType.INVALID_ICCID, ComponentType.PROTOCOL_DLMS, e);
    }
    if ((deviceIpAddress == null) || "".equals(deviceIpAddress)) {
        throw new ProtocolAdapterException("Session provider: " + dlmsDevice.getCommunicationProvider() + " did not return an IP address for device: " + dlmsDevice.getDeviceIdentification() + " and iccId: " + dlmsDevice.getIccId());
    }
    return deviceIpAddress;
}
Also used : FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SessionProvider(org.opensmartgridplatform.adapter.protocol.jasper.sessionproviders.SessionProvider) SessionProviderException(org.opensmartgridplatform.adapter.protocol.jasper.sessionproviders.exceptions.SessionProviderException)

Example 12 with ProtocolAdapterException

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

the class ClearMBusStatusOnAllChannelsCommandExecutor method clearStatusMaskForChannel.

private void clearStatusMaskForChannel(final DlmsConnectionManager conn, final int channel, final DlmsDevice device) throws IOException, ProtocolAdapterException {
    final AttributeAddress readMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.READ_MBUS_STATUS, channel);
    final AttributeAddress clearMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLEAR_MBUS_STATUS, channel);
    final AttributeAddress clientSetupMbus = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLIENT_SETUP_MBUS, channel);
    final long statusMask = this.readStatus(conn, channel, readMBusStatusAttributeAddress);
    if (statusMask == 0L) {
        return;
    }
    final AccessResultCode resultCode = this.setClearStatusMask(statusMask, conn, channel, clearMBusStatusAttributeAddress);
    if (resultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException("Unable to set clear status mask for M-Bus channel " + channel + ", AccessResultCode=" + resultCode + ".");
    }
    final MethodResult methodResult = this.resetAlarm(conn, channel, clientSetupMbus.getInstanceId());
    if (methodResult.getResultCode() != MethodResultCode.SUCCESS) {
        throw new ProtocolAdapterException("Call for RESET_ALARM was unsuccessful for M-Bus channel " + channel + ", MethodResultCode=" + methodResult.getResultCode() + ".");
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MethodResult(org.openmuc.jdlms.MethodResult)

Example 13 with ProtocolAdapterException

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

the class SetAlarmNotificationsCommandExecutor method retrieveCurrentAlarmNotifications.

private AlarmNotificationsDto retrieveCurrentAlarmNotifications(final DlmsConnectionManager conn, final AttributeAddress alarmFilterValue, final DlmsObjectType alarmRegisterDlmsObjectType) throws IOException, ProtocolAdapterException {
    conn.getDlmsMessageListener().setDescription("SetAlarmNotifications retrieve current value, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(alarmFilterValue));
    LOGGER.info("Retrieving current alarm filter by issuing get request for for address: {}", alarmFilterValue);
    final GetResult getResult = conn.getConnection().get(alarmFilterValue);
    if (getResult == null) {
        throw new ProtocolAdapterException("No GetResult received while retrieving current alarm filter.");
    }
    return this.alarmNotifications(getResult.getResultData(), alarmRegisterDlmsObjectType);
}
Also used : GetResult(org.openmuc.jdlms.GetResult) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 14 with ProtocolAdapterException

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

the class GetConfigurationObjectServiceDsmr4 method getConfigurationObject.

private ConfigurationObjectDto getConfigurationObject(final List<DataObject> elements) throws ProtocolAdapterException {
    final Optional<GprsOperationModeTypeDto> gprsMode = this.getGprsOperationMode(elements.get(INDEX_OF_GPRS_OPERATION_MODE));
    final ConfigurationFlagsDto flags = this.getConfigurationFlags(elements.get(INDEX_OF_CONFIGURATION_FLAGS));
    return gprsMode.map(c -> new ConfigurationObjectDto(c, flags)).orElseGet(() -> new ConfigurationObjectDto(flags));
}
Also used : GetResult(org.openmuc.jdlms.GetResult) Logger(org.slf4j.Logger) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) LoggerFactory(org.slf4j.LoggerFactory) DataObject(org.openmuc.jdlms.datatypes.DataObject) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) BitString(org.openmuc.jdlms.datatypes.BitString) List(java.util.List) Component(org.springframework.stereotype.Component) ConfigurationFlagTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagTypeDto) Optional(java.util.Optional) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)

Example 15 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException 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)

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