Search in sources :

Example 6 with AlarmTypeDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.

the class AlarmRegisterMappingTest method testWithNonEmptySet.

// Test if mapping with a non-empty set succeeds
@Test
public void testWithNonEmptySet() {
    // build test data
    final Set<AlarmTypeDto> alarmTypes = new TreeSet<>();
    alarmTypes.add(AlarmTypeDto.CLOCK_INVALID);
    final AlarmRegisterResponseDto alarmRegisterDto = new AlarmRegisterResponseDto(alarmTypes);
    // actual mapping
    final AlarmRegister alarmRegister = this.monitoringMapper.map(alarmRegisterDto, AlarmRegister.class);
    // test mapping
    assertThat(alarmRegister).isNotNull();
    assertThat(alarmRegister.getAlarmTypes().size()).isEqualTo(alarmRegisterDto.getAlarmTypes().size());
    assertThat(alarmRegister.getAlarmTypes().contains(AlarmType.CLOCK_INVALID)).isTrue();
}
Also used : AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) TreeSet(java.util.TreeSet) AlarmRegister(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmRegister) AlarmRegisterResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmRegisterResponseDto) Test(org.junit.jupiter.api.Test)

Example 7 with AlarmTypeDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.

the class ReadAlarmRegisterCommandExecutor method execute.

@Override
public AlarmRegisterResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final ReadAlarmRegisterRequestDto object, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final AttributeAddress alarmRegister1AttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.ALARM_REGISTER_1, null);
    final Set<AlarmTypeDto> alarmList = this.readAlarmRegister(conn, alarmRegister1AttributeAddress, DlmsObjectType.ALARM_REGISTER_1);
    final Optional<AttributeAddress> alarmRegister2AttributeAddress = this.dlmsObjectConfigService.findAttributeAddress(device, DlmsObjectType.ALARM_REGISTER_2, null);
    if (alarmRegister2AttributeAddress.isPresent()) {
        alarmList.addAll(this.readAlarmRegister(conn, alarmRegister2AttributeAddress.get(), DlmsObjectType.ALARM_REGISTER_2));
    }
    return new AlarmRegisterResponseDto(alarmList);
}
Also used : AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) AlarmRegisterResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmRegisterResponseDto)

Example 8 with AlarmTypeDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.

the class SetAlarmNotificationsCommandExecutor method executeForAlarmFilter.

private AccessResultCode executeForAlarmFilter(final DlmsConnectionManager conn, final AttributeAddress alarmFilterAttributeAddress, final AlarmNotificationsDto alarmNotifications, final DlmsObjectType alarmRegisterDlmsObjectType) throws ProtocolAdapterException {
    try {
        final AlarmNotificationsDto alarmNotificationsOnDevice = this.retrieveCurrentAlarmNotifications(conn, alarmFilterAttributeAddress, alarmRegisterDlmsObjectType);
        LOGGER.info("Alarm Filter on device before setting notifications: {}", alarmNotificationsOnDevice);
        final Set<AlarmTypeDto> alarmTypesForRegister = this.alarmHelperService.alarmTypesForRegister(alarmRegisterDlmsObjectType);
        final Set<AlarmNotificationDto> alarmNotificationsSet = alarmNotifications.getAlarmNotificationsSet().stream().filter(alarmNotificationDto -> alarmTypesForRegister.contains(alarmNotificationDto.getAlarmType())).collect(Collectors.toSet());
        final long alarmFilterLongValueOnDevice = this.alarmFilterLongValue(alarmNotificationsOnDevice);
        final long updatedAlarmFilterLongValue = this.calculateAlarmFilterLongValue(alarmNotificationsOnDevice, alarmNotificationsSet);
        if (alarmFilterLongValueOnDevice == updatedAlarmFilterLongValue) {
            return AccessResultCode.SUCCESS;
        }
        LOGGER.info("Modified Alarm Filter long value for device: {}", updatedAlarmFilterLongValue);
        return this.writeUpdatedAlarmNotifications(conn, updatedAlarmFilterLongValue, alarmFilterAttributeAddress);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) GetResult(org.openmuc.jdlms.GetResult) LoggerFactory(org.slf4j.LoggerFactory) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) TreeSet(java.util.TreeSet) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) SetAlarmNotificationsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetAlarmNotificationsRequestDto) AccessResultCode(org.openmuc.jdlms.AccessResultCode) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) Logger(org.slf4j.Logger) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) SetParameter(org.openmuc.jdlms.SetParameter) AbstractCommandExecutor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor) Set(java.util.Set) DataObject(org.openmuc.jdlms.datatypes.DataObject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ActionRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionRequestDto) Component(org.springframework.stereotype.Component) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) Optional(java.util.Optional) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) BitSet(java.util.BitSet) JdlmsObjectToStringUtil(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.JdlmsObjectToStringUtil) AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) IOException(java.io.IOException) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 9 with AlarmTypeDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.

the class PushNotificationAlarmMappingTest method testWithNonEmptyEnumSet.

// Test if mapping a PushNotificationAlarm object succeeds when the EnumSet
// is not empty
@Test
public void testWithNonEmptyEnumSet() {
    // build test data
    final String deviceId = "device1";
    final EnumSet<AlarmTypeDto> alarms = EnumSet.of(AlarmTypeDto.CLOCK_INVALID);
    final PushNotificationAlarmDto pushNotificationAlarmDto = new PushNotificationAlarmDto(deviceId, alarms, this.alarmBytes);
    // actual mapping
    final PushNotificationAlarm pushNotificationAlarm = this.mapperFactory.getMapperFacade().map(pushNotificationAlarmDto, PushNotificationAlarm.class);
    // test mapping
    assertThat(pushNotificationAlarm).isNotNull();
    assertThat(pushNotificationAlarm.getDeviceIdentification()).isEqualTo(deviceId);
    assertThat(pushNotificationAlarm.getAlarms().size()).isEqualTo(alarms.size());
    assertThat(pushNotificationAlarm.getAlarms().contains(AlarmType.CLOCK_INVALID)).isTrue();
    assertThat(this.alarmBytes).isEqualTo(pushNotificationAlarm.getAlarmBytes());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Test(org.junit.jupiter.api.Test)

Example 10 with AlarmTypeDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.

the class DlmsPushNotificationDecoderTest method decodeDsmr4AlarmsWithAlarmRegister.

@Test
public void decodeDsmr4AlarmsWithAlarmRegister() throws UnrecognizedMessageDataException {
    // SETUP
    this.decoder = new DlmsPushNotificationDecoder();
    final ByteBuf buffer = mock(ByteBuf.class);
    // Create alarm register with 3 alarms: replace battery and 2 mbus
    // alarms
    final byte[] alarmRegister = new byte[] { 0x00, 0x18, 0x00, 0x02 };
    final byte[] bytes = this.setupDsmr4Buffer(buffer, IDENTIFIER, alarmRegister);
    // CALL
    final List<Object> out = new ArrayList<>();
    this.decoder.decode(this.ctx, buffer, out);
    final Object pushNotificationObject = out.get(0);
    // VERIFY
    assertThat(pushNotificationObject instanceof DlmsPushNotification).isTrue();
    final DlmsPushNotification dlmsPushNotification = (DlmsPushNotification) pushNotificationObject;
    assertThat(dlmsPushNotification.getEquipmentIdentifier()).isEqualTo(IDENTIFIER);
    assertThat(dlmsPushNotification.getTriggerType()).isEqualTo(PUSH_ALARM_TRIGGER);
    assertThat(dlmsPushNotification.toByteArray()).isEqualTo(bytes);
    final Set<AlarmTypeDto> alarms = dlmsPushNotification.getAlarms();
    assertThat(alarms.size()).isEqualTo(3);
    assertThat(alarms.contains(REPLACE_BATTERY)).isTrue();
    assertThat(alarms.contains(COMMUNICATION_ERROR_M_BUS_CHANNEL_4)).isTrue();
    assertThat(alarms.contains(FRAUD_ATTEMPT_M_BUS_CHANNEL_1)).isTrue();
    this.verifyDsmr4BufferCalls(buffer, alarmRegister);
}
Also used : AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) ArrayList(java.util.ArrayList) DlmsPushNotification(org.opensmartgridplatform.dlms.DlmsPushNotification) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)11 Test (org.junit.jupiter.api.Test)7 TreeSet (java.util.TreeSet)4 PushNotificationAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm)3 AlarmNotificationDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto)3 AlarmRegisterResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmRegisterResponseDto)3 PushNotificationAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto)3 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 AccessResultCode (org.openmuc.jdlms.AccessResultCode)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 DlmsPushNotification (org.opensmartgridplatform.dlms.DlmsPushNotification)2 AlarmRegister (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmRegister)2 AlarmNotificationsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)2 IOException (java.io.IOException)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1