Search in sources :

Example 1 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.

the class ClearMBusStatusOnAllChannelsCommandExecutor method clearStatusMaskForChannel.

private void clearStatusMaskForChannel(final DlmsConnectionManager conn, final int channel, final DlmsDevice device) throws IOException, ProtocolAdapterException {
    final AttributeAddress readMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.READ_MBUS_STATUS, channel);
    final AttributeAddress clearMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLEAR_MBUS_STATUS, channel);
    final AttributeAddress clientSetupMbus = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLIENT_SETUP_MBUS, channel);
    final long statusMask = this.readStatus(conn, channel, readMBusStatusAttributeAddress);
    if (statusMask == 0L) {
        return;
    }
    final AccessResultCode resultCode = this.setClearStatusMask(statusMask, conn, channel, clearMBusStatusAttributeAddress);
    if (resultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException("Unable to set clear status mask for M-Bus channel " + channel + ", AccessResultCode=" + resultCode + ".");
    }
    final MethodResult methodResult = this.resetAlarm(conn, channel, clientSetupMbus.getInstanceId());
    if (methodResult.getResultCode() != MethodResultCode.SUCCESS) {
        throw new ProtocolAdapterException("Call for RESET_ALARM was unsuccessful for M-Bus channel " + channel + ", MethodResultCode=" + methodResult.getResultCode() + ".");
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MethodResult(org.openmuc.jdlms.MethodResult)

Example 2 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.

the class SetAlarmNotificationsCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final AlarmNotificationsDto alarmNotifications, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final AttributeAddress alarmFilter1AttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.ALARM_FILTER_1, null);
    final AccessResultCode resultCodeAlarmFilter1 = this.setAlarmNotifications(conn, alarmNotifications, alarmFilter1AttributeAddress, DlmsObjectType.ALARM_REGISTER_1);
    final Optional<AttributeAddress> alarmFilter2AttributeAddress = this.dlmsObjectConfigService.findAttributeAddress(device, DlmsObjectType.ALARM_FILTER_2, null);
    if (!alarmFilter2AttributeAddress.isPresent()) {
        return resultCodeAlarmFilter1;
    } else {
        return this.setAlarmNotifications(conn, alarmNotifications, alarmFilter2AttributeAddress.get(), DlmsObjectType.ALARM_REGISTER_2);
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode)

Example 3 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectService method setConfigurationObject.

public AccessResultCode setConfigurationObject(final DlmsConnectionManager conn, final ConfigurationObjectDto configurationToSet, final ConfigurationObjectDto configurationOnDevice) throws ProtocolAdapterException {
    final DataObject dataObject = this.buildSetParameterData(configurationToSet, configurationOnDevice);
    LOGGER.info("ConfigurationObject SetParameter Data : {}", this.dlmsHelper.getDebugInfo(dataObject));
    final AttributeAddress attributeAddress = AttributeAddressFactory.getConfigurationObjectAddress();
    final SetParameter setParameter = new SetParameter(attributeAddress, dataObject);
    conn.getDlmsMessageListener().setDescription("SetConfigurationObject AttributeAddress: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
    return this.getAccessResultCode(conn, setParameter);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddress(org.openmuc.jdlms.AttributeAddress) SetParameter(org.openmuc.jdlms.SetParameter)

Example 4 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.

the class SetActivityCalendarCommandExecutor method getWeekProfileTableExecutor.

private DataObjectAttrExecutor getWeekProfileTableExecutor(final Set<WeekProfileDto> weekProfileSet) {
    final AttributeAddress weekProfileTablePassive = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID_WEEK_PROFILE_TABLE_PASSIVE);
    final DataObject weekArray = DataObject.newArrayData(this.configurationMapper.mapAsList(weekProfileSet, DataObject.class));
    LOGGER.info("WeekProfileTablePassive to set is: {}", this.dlmsHelper.getDebugInfo(weekArray));
    return new DataObjectAttrExecutor("WEEKS", weekProfileTablePassive, weekArray, CLASS_ID, OBIS_CODE, ATTRIBUTE_ID_WEEK_PROFILE_TABLE_PASSIVE);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DataObjectAttrExecutor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutor)

Example 5 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.

the class SetSpecialDaysCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final List<SpecialDayDto> specialDays, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final StringBuilder specialDayData = new StringBuilder();
    final List<DataObject> specialDayEntries = new ArrayList<>();
    int i = 0;
    for (final SpecialDayDto specialDay : specialDays) {
        specialDayData.append(", ").append(specialDay.getDayId()).append(" => ").append(specialDay.getSpecialDayDate());
        final List<DataObject> specDayEntry = new ArrayList<>();
        specDayEntry.add(DataObject.newUInteger16Data(i));
        specDayEntry.add(this.dlmsHelper.asDataObject(specialDay.getSpecialDayDate()));
        specDayEntry.add(DataObject.newUInteger8Data((short) specialDay.getDayId()));
        final DataObject dayStruct = DataObject.newStructureData(specDayEntry);
        specialDayEntries.add(dayStruct);
        i += 1;
    }
    final AttributeAddress specialDaysTableEntries = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
    final DataObject entries = DataObject.newArrayData(specialDayEntries);
    final SetParameter request = new SetParameter(specialDaysTableEntries, entries);
    final String specialDayValues;
    if (specialDayData.length() == 0) {
        specialDayValues = "";
    } else {
        specialDayValues = ", values [" + specialDayData.substring(2) + "]";
    }
    conn.getDlmsMessageListener().setDescription("SetSpecialDays" + specialDayValues + ", set attribute: " + JdlmsObjectToStringUtil.describeAttributes(specialDaysTableEntries));
    try {
        return conn.getConnection().set(request);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) SetParameter(org.openmuc.jdlms.SetParameter) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Aggregations

AttributeAddress (org.openmuc.jdlms.AttributeAddress)77 DataObject (org.openmuc.jdlms.datatypes.DataObject)38 ObisCode (org.openmuc.jdlms.ObisCode)18 Test (org.junit.jupiter.api.Test)16 GetResult (org.openmuc.jdlms.GetResult)16 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)16 SetParameter (org.openmuc.jdlms.SetParameter)15 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)14 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)8 DateTime (org.joda.time.DateTime)7 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)6 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)6 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)6 Collectors (java.util.stream.Collectors)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5