Search in sources :

Example 1 with DataObjectAttrExecutors

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors in project open-smart-grid-platform by OSGP.

the class SetActivityCalendarCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActivityCalendarDto activityCalendar, final MessageMetadata messageMetadata) throws ProtocolAdapterException, FunctionalException {
    LOGGER.debug("SetActivityCalendarCommandExecutor.execute {} called", activityCalendar.getCalendarName());
    ActivityCalendarValidator.validate(activityCalendar);
    final List<SeasonProfileDto> seasonProfileList = activityCalendar.getSeasonProfileList();
    final Set<WeekProfileDto> weekProfileSet = this.getWeekProfileSet(seasonProfileList);
    final Set<DayProfileDto> dayProfileSet = this.getDayProfileSet(weekProfileSet);
    final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors("SetActivityCalendar").addExecutor(this.getCalendarNameExecutor(activityCalendar)).addExecutor(this.getSeasonProfileExecutor(seasonProfileList)).addExecutor(this.getWeekProfileTableExecutor(weekProfileSet)).addExecutor(this.getDayProfileTablePassiveExecutor(dayProfileSet));
    conn.getDlmsMessageListener().setDescription("SetActivityCalendar for calendar " + activityCalendar.getCalendarName() + ", set attributes: " + dataObjectExecutors.describeAttributes());
    dataObjectExecutors.execute(conn);
    LOGGER.info("Finished setting the passive activity calendar");
    // in the exception to throw
    try {
        this.setActivityCalendarCommandActivationExecutor.execute(conn, device, null, messageMetadata);
        LOGGER.info("Finished activating the passive to the active activity calendar");
    } catch (final ProtocolAdapterException e) {
        final StringBuilder message = new StringBuilder();
        for (final DataObjectAttrExecutor executor : dataObjectExecutors.getDataObjectAttrExecutorList()) {
            message.append(executor.createRequestAndResultCodeInfo());
        }
        throw new ProtocolAdapterException(e.getMessage() + message, e);
    }
    return AccessResultCode.SUCCESS;
}
Also used : DataObjectAttrExecutors(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SeasonProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto) WeekProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto) DayProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto) DataObjectAttrExecutor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutor)

Example 2 with DataObjectAttrExecutors

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors in project open-smart-grid-platform by OSGP.

the class DeviceChannelsHelper method writeUpdatedMbus.

protected ChannelElementValuesDto writeUpdatedMbus(final DlmsConnectionManager conn, final DlmsDevice device, final MbusChannelElementsDto requestDto, final short channel, final String executorName) throws ProtocolAdapterException {
    final DlmsObject mbusClientSetupObject = this.dlmsObjectConfigService.getDlmsObject(device, DlmsObjectType.MBUS_CLIENT_SETUP);
    final ObisCode obiscode = mbusClientSetupObject.getObisCodeWithChannel(channel);
    final int classId = mbusClientSetupObject.getClassId();
    final DataObject identificationNumberDataObject;
    if (this.identificationNumberStoredAsBcdOnDevice(mbusClientSetupObject)) {
        identificationNumberDataObject = IdentificationNumber.fromTextualRepresentation(requestDto.getMbusIdentificationNumber()).asDataObjectInBcdRepresentation();
    } else {
        identificationNumberDataObject = IdentificationNumber.fromTextualRepresentation(requestDto.getMbusIdentificationNumber()).asDataObject();
    }
    final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors(executorName).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.IDENTIFICATION_NUMBER, identificationNumberDataObject, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.MANUFACTURER_ID, ManufacturerId.fromIdentification(requestDto.getMbusManufacturerIdentification()).asDataObject(), obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.VERSION, DataObject.newUInteger8Data(requestDto.getMbusVersion()), obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.DEVICE_TYPE, DataObject.newUInteger8Data(requestDto.getMbusDeviceTypeIdentification()), obiscode, classId));
    if (requestDto.getPrimaryAddress() != null) {
        dataObjectExecutors.addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.PRIMARY_ADDRESS, DataObject.newUInteger8Data(requestDto.getPrimaryAddress()), obiscode, classId));
    }
    conn.getDlmsMessageListener().setDescription(String.format("Write updated MBus attributes to channel %d, set attributes: %s", channel, dataObjectExecutors.describeAttributes()));
    dataObjectExecutors.execute(conn);
    log.info("Finished coupling the mbus device to the gateway device");
    return new ChannelElementValuesDto(channel, requestDto.getPrimaryAddress(), requestDto.getMbusIdentificationNumber(), requestDto.getMbusManufacturerIdentification(), requestDto.getMbusVersion(), requestDto.getMbusDeviceTypeIdentification());
}
Also used : DataObjectAttrExecutors(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors) ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) ObisCode(org.openmuc.jdlms.ObisCode) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)

Example 3 with DataObjectAttrExecutors

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors in project open-smart-grid-platform by OSGP.

the class DeviceChannelsHelper method resetMBusClientAttributeValues.

protected void resetMBusClientAttributeValues(final DlmsConnectionManager conn, final DlmsDevice device, final short channel, final String executorName) throws ProtocolAdapterException {
    final DlmsObject mbusClientSetupObject = this.dlmsObjectConfigService.getDlmsObject(device, DlmsObjectType.MBUS_CLIENT_SETUP);
    final ObisCode obiscode = mbusClientSetupObject.getObisCodeWithChannel(channel);
    final int classId = mbusClientSetupObject.getClassId();
    final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors(executorName).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.IDENTIFICATION_NUMBER, UINT_32_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.MANUFACTURER_ID, UINT_16_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.VERSION, UINT_8_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.DEVICE_TYPE, UINT_8_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.PRIMARY_ADDRESS, UINT_8_ZERO, obiscode, classId));
    conn.getDlmsMessageListener().setDescription(String.format("Reset MBus attributes to channel %d", channel));
    dataObjectExecutors.execute(conn);
}
Also used : DataObjectAttrExecutors(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors) ObisCode(org.openmuc.jdlms.ObisCode) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)

Aggregations

DataObjectAttrExecutors (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors)3 ObisCode (org.openmuc.jdlms.ObisCode)2 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 DataObjectAttrExecutor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutor)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)1 DayProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto)1 SeasonProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto)1 WeekProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto)1