Search in sources :

Example 1 with DlmsObjectType

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);
}
Also used : DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DlmsObjectConfigConfiguration(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) DlmsConnectionManagerStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SetParameter(org.openmuc.jdlms.SetParameter) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with DlmsObjectType

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;
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)

Example 3 with DlmsObjectType

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;
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)

Example 4 with DlmsObjectType

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

Aggregations

DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)3 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 SetParameter (org.openmuc.jdlms.SetParameter)2 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)2 DlmsObjectConfigService (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 IOException (java.io.IOException)1 BitSet (java.util.BitSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Collectors (java.util.stream.Collectors)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 AccessResultCode (org.openmuc.jdlms.AccessResultCode)1 GetResult (org.openmuc.jdlms.GetResult)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 AbstractCommandExecutor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor)1 DlmsObjectConfigConfiguration (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration)1 DlmsConnectionManagerStub (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub)1