Search in sources :

Example 16 with ObisCode

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

the class SetPushSetupAlarmCommandExecutor method verifyPushObject.

private void verifyPushObject(final CosemObjectDefinitionDto pushObject, final DlmsConnectionManager conn) throws ProtocolAdapterException {
    final int dataIndex = pushObject.getDataIndex();
    if (dataIndex != 0) {
        throw new ProtocolAdapterException("PushObject contains non-zero data index: " + dataIndex + ". Using data index is not implemented.");
    }
    final ObisCode obisCode = new ObisCode(pushObject.getLogicalName().toByteArray());
    final AttributeAddress attributeAddress = new AttributeAddress(pushObject.getClassId(), obisCode, pushObject.getAttributeIndex());
    try {
        this.dlmsHelper.getAttributeValue(conn, attributeAddress);
    } catch (final FunctionalException e) {
        throw new ProtocolAdapterException("Verification of push object failed. Object " + obisCode.asDecimalString() + " could not be retrieved using a get request.", e);
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ObisCode(org.openmuc.jdlms.ObisCode) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 17 with ObisCode

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

the class SetEncryptionKeyExchangeOnGMeterCommandExecutor method execute.

@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final GMeterInfoDto gMeterInfo, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    try {
        LOGGER.debug("SetEncryptionKeyExchangeOnGMeterCommandExecutor.execute called");
        final String mbusDeviceIdentification = gMeterInfo.getDeviceIdentification();
        final int channel = gMeterInfo.getChannel();
        final ObisCode obisCode = OBIS_HASHMAP.get(channel);
        final byte[] gMeterEncryptionKey = this.secretManagementService.generate128BitsKeyAndStoreAsNewKey(messageMetadata, mbusDeviceIdentification, G_METER_ENCRYPTION);
        MethodResult methodResultCode = this.transferKey(conn, mbusDeviceIdentification, channel, gMeterEncryptionKey, messageMetadata);
        this.checkMethodResultCode(methodResultCode, "M-Bus Setup transfer_key", obisCode);
        methodResultCode = this.setEncryptionKey(conn, channel, gMeterEncryptionKey);
        this.checkMethodResultCode(methodResultCode, "M-Bus Setup set_encryption_key", obisCode);
        this.secretManagementService.activateNewKey(messageMetadata, mbusDeviceIdentification, G_METER_ENCRYPTION);
        return MethodResultCode.SUCCESS;
    } catch (final IOException e) {
        throw new ConnectionException(e);
    } catch (final EncrypterException e) {
        throw new ProtocolAdapterException("Unexpected exception during decryption of security keys, reason = " + e.getMessage(), e);
    }
}
Also used : EncrypterException(org.opensmartgridplatform.shared.exceptionhandling.EncrypterException) ObisCode(org.openmuc.jdlms.ObisCode) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) MethodResult(org.openmuc.jdlms.MethodResult)

Example 18 with ObisCode

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

the class DlmsObjectConfigService method getAttributeAddressForProfile.

private AttributeAddressForProfile getAttributeAddressForProfile(final AddressRequest addressRequest) {
    final List<DlmsCaptureObject> selectedObjects = new ArrayList<>();
    final SelectiveAccessDescription access = this.getAccessDescription(addressRequest, selectedObjects);
    final DlmsObject dlmsObject = addressRequest.getDlmsObject();
    final ObisCode obisCode = this.replaceChannel(dlmsObject.getObisCodeAsString(), addressRequest.getChannel());
    return new AttributeAddressForProfile(new AttributeAddress(dlmsObject.getClassId(), obisCode, dlmsObject.getDefaultAttributeId(), access), selectedObjects);
}
Also used : SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)

Example 19 with ObisCode

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

the class DeviceChannelsHelper method makeAttributeAddresses.

private AttributeAddress[] makeAttributeAddresses(final DlmsObject mbusClientSetupObject, final int channel) {
    final AttributeAddress[] attrAddresses = new AttributeAddress[NUMBER_OF_ATTRIBUTES_MBUS_CLIENT];
    final ObisCode obiscode = mbusClientSetupObject.getObisCodeWithChannel(channel);
    final int classId = mbusClientSetupObject.getClassId();
    attrAddresses[INDEX_PRIMARY_ADDRESS] = new AttributeAddress(classId, obiscode, MbusClientAttribute.PRIMARY_ADDRESS.attributeId());
    attrAddresses[INDEX_IDENTIFICATION_NUMBER] = new AttributeAddress(classId, obiscode, MbusClientAttribute.IDENTIFICATION_NUMBER.attributeId());
    attrAddresses[INDEX_MANUFACTURER_ID] = new AttributeAddress(classId, obiscode, MbusClientAttribute.MANUFACTURER_ID.attributeId());
    attrAddresses[INDEX_VERSION] = new AttributeAddress(classId, obiscode, MbusClientAttribute.VERSION.attributeId());
    attrAddresses[INDEX_DEVICE_TYPE] = new AttributeAddress(classId, obiscode, MbusClientAttribute.DEVICE_TYPE.attributeId());
    return attrAddresses;
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode)

Example 20 with ObisCode

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

the class DecoupleMBusDeviceCommandExecutor method execute.

@Override
public DecoupleMbusDeviceResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final DecoupleMbusDeviceDto decoupleMbusDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final Short channel = decoupleMbusDto.getChannel();
    log.debug("Decouple channel {} on gateway device {}", channel, device.getDeviceIdentification());
    final ObisCode obisCode = this.deviceChannelsHelper.getObisCode(device, channel);
    // Get the current channel element values before resetting the channel
    final ChannelElementValuesDto channelElementValues = this.deviceChannelsHelper.getChannelElementValues(conn, device, channel);
    // Deinstall and reset channel
    final CosemObjectAccessor mBusSetup = new CosemObjectAccessor(conn, obisCode, InterfaceClass.MBUS_CLIENT.id());
    this.deviceChannelsHelper.deinstallSlave(conn, device, channel, mBusSetup);
    this.deviceChannelsHelper.resetMBusClientAttributeValues(conn, device, channel, this.getClass().getSimpleName());
    // return the channel element values as before decoupling
    return new DecoupleMbusDeviceResponseDto(channelElementValues);
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) CosemObjectAccessor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor) DecoupleMbusDeviceResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto) ObisCode(org.openmuc.jdlms.ObisCode)

Aggregations

ObisCode (org.openmuc.jdlms.ObisCode)46 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 Bean (org.springframework.context.annotation.Bean)9 BitString (org.openmuc.jdlms.datatypes.BitString)8 DataObject (org.openmuc.jdlms.datatypes.DataObject)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 OctetStringData (org.opensmartgridplatform.simulator.protocol.dlms.cosem.OctetStringData)6 Then (io.cucumber.java.en.Then)4 GetResult (org.openmuc.jdlms.GetResult)4 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)4 Given (io.cucumber.java.en.Given)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 CosemClass (org.openmuc.jdlms.CosemClass)3 ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)3 IOException (java.io.IOException)2 DlmsCaptureObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject)2 CosemObjectAccessor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor)2 DataObjectAttrExecutors (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors)2