Search in sources :

Example 66 with DataObject

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

the class DlmsHelper method getAccessSelectionTimeRangeParameter.

public DataObject getAccessSelectionTimeRangeParameter(final DateTime from, final DateTime to, final DataObject selectedValues) {
    /*
     * Define the clock object {8,0-0:1.0.0.255,2,0} to be used as
     * restricting object in a range descriptor with a from value and to
     * value to determine which elements from the buffered array should be
     * retrieved.
     */
    final DataObject clockDefinition = this.getClockDefinition();
    final DataObject fromValue = this.asDataObject(from);
    final DataObject toValue = this.asDataObject(to);
    return DataObject.newStructureData(Arrays.asList(clockDefinition, fromValue, toValue, selectedValues));
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject)

Example 67 with DataObject

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

the class DlmsHelper method readObjectDefinition.

public CosemObjectDefinitionDto readObjectDefinition(final DataObject resultData, final String description) throws ProtocolAdapterException {
    final List<DataObject> objectDefinitionElements = this.readList(resultData, description);
    if (objectDefinitionElements == null) {
        return null;
    }
    if (objectDefinitionElements.size() != 4) {
        LOGGER.error("Unexpected ResultData for Object Definition value: {}", this.getDebugInfo(resultData));
        throw new ProtocolAdapterException("Expected list for Object Definition to contain 4 elements, got: " + objectDefinitionElements.size());
    }
    final Long classId = this.readLongNotNull(objectDefinitionElements.get(0), "Class ID from " + description);
    final CosemObisCodeDto logicalName = this.readLogicalName(objectDefinitionElements.get(1), "Logical Name from " + description);
    final Long attributeIndex = this.readLongNotNull(objectDefinitionElements.get(2), "Attribute Index from " + description);
    final Long dataIndex = this.readLongNotNull(objectDefinitionElements.get(3), "Data Index from " + description);
    return new CosemObjectDefinitionDto(classId.intValue(), logicalName, attributeIndex.intValue(), dataIndex.intValue());
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) CosemObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemObjectDefinitionDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) CosemObisCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemObisCodeDto)

Example 68 with DataObject

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

the class SetEncryptionKeyExchangeOnGMeterCommandExecutor method getTransferKeyMethodParameter.

private MethodParameter getTransferKeyMethodParameter(final String mbusDeviceIdentification, final int channel, final byte[] gMeterUserKey, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final DlmsDevice mbusDevice = this.dlmsDeviceRepository.findByDeviceIdentification(mbusDeviceIdentification);
    if (mbusDevice == null) {
        throw new ProtocolAdapterException("Unknown M-Bus device: " + mbusDeviceIdentification);
    }
    final byte[] mbusDefaultKey = this.secretManagementService.getKey(messageMetadata, mbusDeviceIdentification, G_METER_MASTER);
    final byte[] encryptedUserKey = this.encryptMbusUserKey(mbusDefaultKey, gMeterUserKey);
    final DataObject methodParameter = DataObject.newOctetStringData(encryptedUserKey);
    final MBusClientMethod method = MBusClientMethod.TRANSFER_KEY;
    return new MethodParameter(method.getInterfaceClass().id(), OBIS_HASHMAP.get(channel), method.getMethodId(), methodParameter);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MethodParameter(org.openmuc.jdlms.MethodParameter) MBusClientMethod(org.opensmartgridplatform.dlms.interfaceclass.method.MBusClientMethod)

Example 69 with DataObject

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

the class GetAllAttributeValuesCommandExecutor method execute.

@Override
public String execute(final DlmsConnectionManager conn, final DlmsDevice device, final DataObject object, final MessageMetadata messageMetadata) throws OsgpException {
    final AttributeAddress attributeAddress = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
    conn.getDlmsMessageListener().setDescription("RetrieveAllAttributeValues, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
    LOGGER.debug("Retrieving all attribute values for class id: {}, obis code: {}, attribute id: {}", CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
    final DataObject objectList = this.dlmsHelper.getAttributeValue(conn, attributeAddress);
    if (!objectList.isComplex()) {
        this.throwUnexpectedTypeProtocolAdapterException();
    }
    final List<DataObject> objectListElements = objectList.getValue();
    final List<ClassIdObisAttr> allObisCodes = this.getAllObisCodes(objectListElements);
    this.logAllObisCodes(allObisCodes);
    try {
        final String output = this.createOutput(conn, allObisCodes);
        LOGGER.debug("Total output is: {}", output);
        return output;
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 70 with DataObject

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

the class GetAllAttributeValuesCommandExecutor method getAllObisCodes.

private List<ClassIdObisAttr> getAllObisCodes(final List<DataObject> objectListElements) throws ProtocolAdapterException {
    final List<ClassIdObisAttr> allObisCodes = new ArrayList<>();
    for (final DataObject objectListElement : objectListElements) {
        final List<DataObject> objectListElementValues = objectListElement.getValue();
        final ClassIdObisAttr classIdObisAttr = new ClassIdObisAttr(this.getClassId(objectListElementValues.get(CLASS_ID_INDEX)), objectListElementValues.get(OBIS_CODE_INDEX), this.getNoOffAttributes(objectListElementValues));
        allObisCodes.add(classIdObisAttr);
    }
    return allObisCodes;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList)

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