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();
}
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);
}
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);
}
}
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());
}
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);
}
Aggregations