Search in sources :

Example 1 with DataObject

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

the class AbstractCommandExecutor method getValidatedResultData.

/**
 * Retrieves connection, gets result data and validates it before returning.
 *
 * @param conn holds connection
 * @param getParameter for attribute to retrieve result data from
 * @return dataObject
 */
public DataObject getValidatedResultData(final DlmsConnectionManager conn, final AttributeAddress getParameter) throws ProtocolAdapterException {
    final GetResult getResult;
    try {
        getResult = conn.getConnection().get(getParameter);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
    if (getResult == null) {
        throw new ProtocolAdapterException("No GetResult received while retrieving M-Bus encryption key status.");
    }
    final DataObject dataObject = getResult.getResultData();
    if (!dataObject.isNumber()) {
        throw new ProtocolAdapterException("Received unexpected result data.");
    }
    return dataObject;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 2 with DataObject

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

the class ClearAlarmRegisterCommandExecutor method executeForAlarmRegister.

public AccessResultCode executeForAlarmRegister(final DlmsConnectionManager conn, final AttributeAddress alarmRegisterAttributeAddress) {
    log.info("Clear alarm register {}", JdlmsObjectToStringUtil.describeAttributes(alarmRegisterAttributeAddress));
    final DataObject data = DataObject.newUInteger32Data(ALARM_CODE);
    final SetParameter setParameter = new SetParameter(alarmRegisterAttributeAddress, data);
    conn.getDlmsMessageListener().setDescription("ClearAlarmRegister, with alarm code = " + ALARM_CODE + JdlmsObjectToStringUtil.describeAttributes(alarmRegisterAttributeAddress));
    try {
        return conn.getConnection().set(setParameter);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) IOException(java.io.IOException) SetParameter(org.openmuc.jdlms.SetParameter) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 3 with DataObject

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

the class GetConfigurationObjectServiceDsmr4 method getConfigurationObject.

private ConfigurationObjectDto getConfigurationObject(final List<DataObject> elements) throws ProtocolAdapterException {
    final Optional<GprsOperationModeTypeDto> gprsMode = this.getGprsOperationMode(elements.get(INDEX_OF_GPRS_OPERATION_MODE));
    final ConfigurationFlagsDto flags = this.getConfigurationFlags(elements.get(INDEX_OF_CONFIGURATION_FLAGS));
    return gprsMode.map(c -> new ConfigurationObjectDto(c, flags)).orElseGet(() -> new ConfigurationObjectDto(flags));
}
Also used : GetResult(org.openmuc.jdlms.GetResult) Logger(org.slf4j.Logger) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) LoggerFactory(org.slf4j.LoggerFactory) DataObject(org.openmuc.jdlms.datatypes.DataObject) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) BitString(org.openmuc.jdlms.datatypes.BitString) List(java.util.List) Component(org.springframework.stereotype.Component) ConfigurationFlagTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagTypeDto) Optional(java.util.Optional) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)

Example 4 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject 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 5 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject 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)

Aggregations

DataObject (org.openmuc.jdlms.datatypes.DataObject)176 ArrayList (java.util.ArrayList)46 AttributeAddress (org.openmuc.jdlms.AttributeAddress)36 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)34 Test (org.junit.jupiter.api.Test)31 GetResult (org.openmuc.jdlms.GetResult)23 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)16 DateTime (org.joda.time.DateTime)15 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)14 SetParameter (org.openmuc.jdlms.SetParameter)12 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)11 BitString (org.openmuc.jdlms.datatypes.BitString)10 ObisCode (org.openmuc.jdlms.ObisCode)9 IOException (java.io.IOException)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)7 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)6 List (java.util.List)5 MethodResultCode (org.openmuc.jdlms.MethodResultCode)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)5 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)5