Search in sources :

Example 6 with DataObject

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

Example 7 with DataObject

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

the class SynchronizeTimeCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final SynchronizeTimeRequestDto synchronizeTimeRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final DateTime dt = DateTime.now();
    final DataObject time = this.dlmsHelper.asDataObject(dt, synchronizeTimeRequestDto.getDeviation(), synchronizeTimeRequestDto.isDst());
    final SetParameter setParameter = new SetParameter(ATTRIBUTE_TIME, time);
    conn.getDlmsMessageListener().setDescription("SynchronizeTime to " + dt + ", set attribute: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_TIME));
    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) DateTime(org.joda.time.DateTime) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 8 with DataObject

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

the class DlmsObjectConfigService method getAccessDescription.

private SelectiveAccessDescription getAccessDescription(final AddressRequest addressRequest, final List<DlmsCaptureObject> selectedObjects) {
    final DlmsObject object = addressRequest.getDlmsObject();
    final DateTime from = addressRequest.getFrom();
    final DateTime to = addressRequest.getTo();
    if (!(object instanceof DlmsProfile) || from == null || to == null) {
        return null;
    } else {
        final int accessSelector = 1;
        final DataObject selectedValues = this.getSelectedValues(addressRequest, selectedObjects);
        final DataObject accessParameter = this.dlmsHelper.getAccessSelectionTimeRangeParameter(from, to, selectedValues);
        return new SelectiveAccessDescription(accessSelector, accessParameter);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) DateTime(org.joda.time.DateTime)

Example 9 with DataObject

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

the class DlmsObjectConfigService method getSelectedValues.

private DataObject getSelectedValues(final AddressRequest addressRequest, final List<DlmsCaptureObject> selectedObjects) {
    List<DataObject> objectDefinitions = new ArrayList<>();
    final DlmsObject object = addressRequest.getDlmsObject();
    final Protocol protocol = Protocol.forDevice(addressRequest.getDevice());
    if (object instanceof DlmsProfile && ((DlmsProfile) object).getCaptureObjects() != null) {
        final DlmsProfile profile = (DlmsProfile) object;
        objectDefinitions = this.getObjectDefinitions(addressRequest.getChannel(), addressRequest.getFilterMedium(), protocol, profile, selectedObjects);
    }
    return DataObject.newArrayData(objectDefinitions);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) ArrayList(java.util.ArrayList) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)

Example 10 with DataObject

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

the class SetRandomisationSettingsCommandExecutor method writeRandomisationSettings.

private void writeRandomisationSettings(final DlmsConnectionManager conn, final DlmsDevice device, final int randomisationStartWindow, final int multiplicationFactor, final int numberOfRetries) throws ProtocolAdapterException {
    final AttributeAddress randomisationSettingsAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.RANDOMISATION_SETTINGS, null);
    final DataObject randomisationStartWindowObject = DataObject.newUInteger32Data(randomisationStartWindow);
    final DataObject multiplicationFactorObject = DataObject.newUInteger16Data(multiplicationFactor);
    final DataObject numberOfRetriesObject = DataObject.newUInteger16Data(numberOfRetries);
    final DataObject randomisationSettingsObject = DataObject.newStructureData(randomisationStartWindowObject, multiplicationFactorObject, numberOfRetriesObject);
    final SetParameter setRandomisationSettings = new SetParameter(randomisationSettingsAddress, randomisationSettingsObject);
    this.writeAttribute(conn, setRandomisationSettings);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddress(org.openmuc.jdlms.AttributeAddress) SetParameter(org.openmuc.jdlms.SetParameter)

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