Search in sources :

Example 21 with ObisCode

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

the class SetRandomisationSettingsCommandExecutorTest method init.

@BeforeEach
public void init() throws ProtocolAdapterException, IOException {
    // SETUP
    final Protocol smr51 = Protocol.SMR_5_1;
    this.device = this.createDlmsDevice(smr51);
    this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    final AttributeAddress address = new AttributeAddress(1, new ObisCode("0.1.94.31.12.255"), 1);
    this.dataDto = new SetRandomisationSettingsRequestDataDto(0, 1, 1, 1);
    final ConfigurationFlagsDto currentConfigurationFlagsDto = new ConfigurationFlagsDto(this.getFlags());
    final ConfigurationObjectDto currentConfigurationObjectDto = new ConfigurationObjectDto(currentConfigurationFlagsDto);
    when(this.protocolServiceLookup.lookupGetService(smr51)).thenReturn(this.getConfigurationObjectService);
    when(this.protocolServiceLookup.lookupSetService(smr51)).thenReturn(this.setConfigurationObjectService);
    when(this.getConfigurationObjectService.getConfigurationObject(this.dlmsConnectionManager)).thenReturn(currentConfigurationObjectDto);
    when(this.setConfigurationObjectService.setConfigurationObject(any(DlmsConnectionManager.class), any(ConfigurationObjectDto.class), any(ConfigurationObjectDto.class))).thenReturn(AccessResultCode.SUCCESS);
    when(this.dlmsObjectConfigService.getAttributeAddress(this.device, DlmsObjectType.RANDOMISATION_SETTINGS, null)).thenReturn(address);
    when(this.dlmsConnectionManager.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
}
Also used : SetRandomisationSettingsRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetRandomisationSettingsRequestDataDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ObisCode(org.openmuc.jdlms.ObisCode) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) SetParameter(org.openmuc.jdlms.SetParameter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 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 23 with ObisCode

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

the class GetAllAttributeValuesCommandExecutor method getAllDataFromAttribute.

private String getAllDataFromAttribute(final DlmsConnectionManager conn, final int classNumber, final DataObject obisCode, final int attributeValue) throws ProtocolAdapterException, IOException {
    if (!obisCode.isByteArray()) {
        this.throwUnexpectedTypeProtocolAdapterException();
    }
    final byte[] obisCodeByteArray = obisCode.getValue();
    if (obisCodeByteArray.length != OBIS_CODE_BYTE_ARRAY_LENGTH) {
        this.throwUnexpectedTypeProtocolAdapterException();
    }
    final AttributeAddress attributeAddress = new AttributeAddress(classNumber, new ObisCode(obisCodeByteArray), attributeValue);
    conn.getDlmsMessageListener().setDescription("RetrieveAllAttributeValues, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
    LOGGER.debug("Retrieving configuration objects data for class id: {}, obis code: {}, attribute id: {}", classNumber, obisCodeByteArray, attributeValue);
    final GetResult getResult = conn.getConnection().get(attributeAddress);
    LOGGER.debug("ResultCode: {}", getResult.getResultCode());
    return this.dlmsHelper.getDebugInfo(getResult.getResultData());
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode)

Example 24 with ObisCode

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

the class GetGsmDiagnosticCommandExecutor method createAttributeAddresses.

private AttributeAddress[] createAttributeAddresses(final DlmsObject dlmsObject) {
    final int classId = dlmsObject.getClassId();
    final ObisCode obisCode = dlmsObject.getObisCode();
    return new AttributeAddress[] { new AttributeAddress(classId, obisCode, OPERATOR.attributeId()), new AttributeAddress(classId, obisCode, MODEM_REGISTRATION_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CIRCUIT_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, PACKET_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CELL_INFO.attributeId()), new AttributeAddress(classId, obisCode, ADJACENT_CELLS.attributeId()) // Reading of capture_time is disabled for now, because the jDLMS library appears to handle
    // the COSEM date-time in the response incorrectly. Also see comment in getCaptureTime.
    // new AttributeAddress(classId, obisCode, CAPTURE_TIME.attributeId())
    };
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode)

Example 25 with ObisCode

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

the class GetOutagesCommandExecutor method execute.

@Override
public List<OutageDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetOutagesRequestDto getOutagesRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final AttributeAddress eventLogBuffer = new AttributeAddress(CLASS_ID, new ObisCode(OBIS_CODE), ATTRIBUTE_ID);
    conn.getDlmsMessageListener().setDescription("RetrieveOutages, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(eventLogBuffer));
    final GetResult getResult;
    try {
        getResult = conn.getConnection().get(eventLogBuffer);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
    if (getResult == null) {
        throw new ProtocolAdapterException("No GetResult received while retrieving event register POWER_FAILURE_EVENT_LOG");
    }
    if (!AccessResultCode.SUCCESS.equals(getResult.getResultCode())) {
        log.info("Result of getting events for POWER_FAILURE_EVENT_LOG is {}", getResult.getResultCode());
        throw new ProtocolAdapterException("Getting the outages from POWER_FAILURE_EVENT_LOG from the meter resulted in: " + getResult.getResultCode());
    }
    final DataObject resultData = getResult.getResultData();
    return this.dataObjectToOutageListConverter.convert(resultData);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) 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)

Aggregations

ObisCode (org.openmuc.jdlms.ObisCode)45 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)7 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