Search in sources :

Example 6 with AccessResultCode

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

the class ConfigurationService method setPushSetupSms.

public void setPushSetupSms(final DlmsConnectionManager conn, final DlmsDevice device, final PushSetupSmsDto pushSetupSms, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    LOGGER.info("Push Setup Sms to set on the device: {}", pushSetupSms);
    final AccessResultCode accessResultCode = this.setPushSetupSmsCommandExecutor.execute(conn, device, pushSetupSms, messageMetadata);
    if (AccessResultCode.SUCCESS != accessResultCode) {
        throw new ProtocolAdapterException("AccessResultCode for set push setup sms was not SUCCESS: " + accessResultCode);
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 7 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode 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 8 with AccessResultCode

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

the class SetAlarmNotificationsCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final AlarmNotificationsDto alarmNotifications, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final AttributeAddress alarmFilter1AttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.ALARM_FILTER_1, null);
    final AccessResultCode resultCodeAlarmFilter1 = this.setAlarmNotifications(conn, alarmNotifications, alarmFilter1AttributeAddress, DlmsObjectType.ALARM_REGISTER_1);
    final Optional<AttributeAddress> alarmFilter2AttributeAddress = this.dlmsObjectConfigService.findAttributeAddress(device, DlmsObjectType.ALARM_FILTER_2, null);
    if (!alarmFilter2AttributeAddress.isPresent()) {
        return resultCodeAlarmFilter1;
    } else {
        return this.setAlarmNotifications(conn, alarmNotifications, alarmFilter2AttributeAddress.get(), DlmsObjectType.ALARM_REGISTER_2);
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode)

Example 9 with AccessResultCode

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

the class SetPushSetupSmsCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final PushSetupSmsDto pushSetupSms, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final SetParameter setParameterSendDestinationAndMethod = this.getSetParameter(pushSetupSms, device);
    final AccessResultCode resultCode = this.doSetRequest("PushSetupSms, Send destination and method", conn, setParameterSendDestinationAndMethod);
    if (resultCode != null) {
        return resultCode;
    } else {
        throw new ProtocolAdapterException("Error setting Sms push setup data.");
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SetParameter(org.openmuc.jdlms.SetParameter)

Example 10 with AccessResultCode

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

the class SetPushSetupAlarmCommandExecutorTest method testSetSendDestinationAndMethod.

@ParameterizedTest
@EnumSource(Protocol.class)
void testSetSendDestinationAndMethod(final Protocol protocol) throws ProtocolAdapterException, IOException {
    // SETUP
    final DlmsDevice device = this.createDlmsDevice(protocol);
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
    final PushSetupAlarmDto pushSetupAlarmDto = new PushSetupAlarmDto.Builder().withSendDestinationAndMethod(SEND_DESTINATION_AND_METHOD).build();
    // CALL
    final AccessResultCode resultCode = this.executor.execute(this.conn, device, pushSetupAlarmDto, this.messageMetadata);
    // VERIFY
    assertThat(resultCode).isEqualTo(AccessResultCode.SUCCESS);
    verify(this.dlmsConnection, times(1)).set(this.setParameterArgumentCaptor.capture());
    final List<SetParameter> setParameters = this.setParameterArgumentCaptor.getAllValues();
    this.verifySendDestinationAndMethodParameter(setParameters.get(0), protocol);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) PushSetupAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto) SetParameter(org.openmuc.jdlms.SetParameter) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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