use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method setUp.
@BeforeEach
public void setUp() {
this.setParametersReceived = new ArrayList<>();
this.device = new DlmsDevice("SuperAwesomeHeroicRockstarDevice");
this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
final DlmsObjectConfigConfiguration dlmsObjectConfigConfiguration = new DlmsObjectConfigConfiguration();
final DlmsObjectConfigService dlmsObjectConfigService = new DlmsObjectConfigService(new DlmsHelper(), dlmsObjectConfigConfiguration.getDlmsObjectConfigs()) {
@Override
public Optional<AttributeAddress> findAttributeAddress(final DlmsDevice device, final DlmsObjectType type, final Integer channel) {
switch(type) {
case ALARM_FILTER_1:
return Optional.of(new AttributeAddress(40, "0.0.97.98.10.255", 2));
case ALARM_FILTER_2:
return Optional.of(new AttributeAddress(40, "0.0.97.98.11.255", 2));
}
return Optional.empty();
}
};
this.executor = new SetAlarmNotificationsCommandExecutor(dlmsObjectConfigService);
final DlmsConnectionStub conn = new DlmsConnectionStub() {
@Override
public AccessResultCode set(final SetParameter setParameter) {
SetAlarmNotificationsCommandExecutorTest.this.setParametersReceived.add(setParameter);
return AccessResultCode.SUCCESS;
}
};
// Set the return value to 10 (0b1010):
// REPLACE_BATTERY enabled, AUXILIARY_EVENT enabled.
conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.10.255", 2), DataObject.newInteger32Data(10));
conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.11.255", 2), DataObject.newInteger32Data(0));
this.connMgr = new DlmsConnectionManagerStub(conn);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutor method getProfileBufferAddress.
private AttributeAddressForProfile getProfileBufferAddress(final PeriodTypeDto periodType, final ChannelDto channel, final DateTime beginDateTime, final DateTime endDateTime, final DlmsDevice device) throws ProtocolAdapterException {
final DlmsObjectType type = DlmsObjectType.getTypeForPeriodType(periodType);
// Add the attribute address for the profile
final AttributeAddressForProfile attributeAddressProfile = this.dlmsObjectConfigService.findAttributeAddressForProfile(device, type, channel.getChannelNumber(), beginDateTime, endDateTime, Medium.GAS).orElseThrow(() -> new ProtocolAdapterException("No address found for " + type));
LOGGER.info("Dlms object config service returned profile buffer address {} ", attributeAddressProfile);
return attributeAddressProfile;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutor method getProfileBufferAddress.
private AttributeAddressForProfile getProfileBufferAddress(final PeriodTypeDto periodType, final DateTime beginDateTime, final DateTime endDateTime, final DlmsDevice device) throws ProtocolAdapterException {
final DlmsObjectType type = DlmsObjectType.getTypeForPeriodType(periodType);
// Add the attribute address for the profile
final AttributeAddressForProfile attributeAddressProfile = this.dlmsObjectConfigService.findAttributeAddressForProfile(device, type, 0, beginDateTime, endDateTime, Medium.ELECTRICITY).orElseThrow(() -> new ProtocolAdapterException("No address found for " + type));
LOGGER.info("Dlms object config service returned profile buffer address {} ", attributeAddressProfile);
return attributeAddressProfile;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType 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);
}
}
Aggregations