Search in sources :

Example 1 with MethodResult

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

the class ClearMBusStatusOnAllChannelsCommandExecutor method clearStatusMaskForChannel.

private void clearStatusMaskForChannel(final DlmsConnectionManager conn, final int channel, final DlmsDevice device) throws IOException, ProtocolAdapterException {
    final AttributeAddress readMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.READ_MBUS_STATUS, channel);
    final AttributeAddress clearMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLEAR_MBUS_STATUS, channel);
    final AttributeAddress clientSetupMbus = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLIENT_SETUP_MBUS, channel);
    final long statusMask = this.readStatus(conn, channel, readMBusStatusAttributeAddress);
    if (statusMask == 0L) {
        return;
    }
    final AccessResultCode resultCode = this.setClearStatusMask(statusMask, conn, channel, clearMBusStatusAttributeAddress);
    if (resultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException("Unable to set clear status mask for M-Bus channel " + channel + ", AccessResultCode=" + resultCode + ".");
    }
    final MethodResult methodResult = this.resetAlarm(conn, channel, clientSetupMbus.getInstanceId());
    if (methodResult.getResultCode() != MethodResultCode.SUCCESS) {
        throw new ProtocolAdapterException("Call for RESET_ALARM was unsuccessful for M-Bus channel " + channel + ", MethodResultCode=" + methodResult.getResultCode() + ".");
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MethodResult(org.openmuc.jdlms.MethodResult)

Example 2 with MethodResult

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

the class SetActivityCalendarCommandActivationExecutor method execute.

@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void v, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    LOGGER.info("ACTIVATING PASSIVE CALENDAR");
    final MethodParameter method = new MethodParameter(CLASS_ID, OBIS_CODE, METHOD_ID_ACTIVATE_PASSIVE_CALENDAR, DataObject.newInteger32Data(0));
    conn.getDlmsMessageListener().setDescription("SetActivityCalendarActivation, call method: " + JdlmsObjectToStringUtil.describeMethod(method));
    final MethodResult methodResultCode;
    try {
        methodResultCode = conn.getConnection().action(method);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
    if (!MethodResultCode.SUCCESS.equals(methodResultCode.getResultCode())) {
        throw new ProtocolAdapterException("Activating the activity calendar failed. MethodResult is: " + methodResultCode.getResultCode() + " ClassId: " + CLASS_ID + " obisCode: " + OBIS_CODE + " method id: " + METHOD_ID_ACTIVATE_PASSIVE_CALENDAR);
    }
    return MethodResultCode.SUCCESS;
}
Also used : IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MethodParameter(org.openmuc.jdlms.MethodParameter) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) MethodResult(org.openmuc.jdlms.MethodResult)

Example 3 with MethodResult

use of org.openmuc.jdlms.MethodResult 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 4 with MethodResult

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

the class UpdateFirmwareCommandExecutorIntegrationTest method setUp.

@BeforeEach
void setUp() {
    this.connectionStub = new DlmsConnectionStub();
    this.connectionManagerStub = new DlmsConnectionManagerStub(this.connectionStub);
    this.connectionStub.setDefaultReturnValue(DataObject.newArrayData(Collections.emptyList()));
    this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_TRANSFER_ENABLED), DataObject.newBoolData(true));
    this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_TRANSFER_STATUS), DataObject.newInteger32Data(1), 5);
    this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_TRANSFER_STATUS), DataObject.newInteger32Data(6));
    this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_BLOCK_SIZE), DataObject.newUInteger32Data(100));
    this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER), DataObject.newUInteger32Data(100));
    this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    final MethodResult methodResult = mock(MethodResult.class);
    when(methodResult.getResultCode()).thenReturn(MethodResultCode.SUCCESS);
    final ImageTransferProperties imageTransferProperties = new ImageTransfer.ImageTransferProperties();
    imageTransferProperties.setVerificationStatusCheckInterval(this.verificationStatusCheckInterval);
    imageTransferProperties.setVerificationStatusCheckTimeout(this.verificationStatusCheckTimeout);
    imageTransferProperties.setInitiationStatusCheckInterval(this.initiationStatusCheckInterval);
    imageTransferProperties.setInitiationStatusCheckTimeout(this.initiationStatusCheckTimeout);
    this.connectionStub.setDefaultMethodResult(methodResult);
    this.commandExecutor = new UpdateFirmwareCommandExecutor(this.dlmsDeviceRepository, this.firmwareFileCachingRepository, this.firmwareImageIdentifierCachingRepository, this.macGenerationService, imageTransferProperties);
}
Also used : DlmsConnectionManagerStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub) DlmsConnectionStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub) ImageTransferProperties(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.ImageTransfer.ImageTransferProperties) MethodResult(org.openmuc.jdlms.MethodResult) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MethodResult (org.openmuc.jdlms.MethodResult)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)3 IOException (java.io.IOException)2 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 AccessResultCode (org.openmuc.jdlms.AccessResultCode)1 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 MethodParameter (org.openmuc.jdlms.MethodParameter)1 ObisCode (org.openmuc.jdlms.ObisCode)1 ImageTransferProperties (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.ImageTransfer.ImageTransferProperties)1 DlmsConnectionManagerStub (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub)1 DlmsConnectionStub (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub)1 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)1