Search in sources :

Example 51 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class ImageTransfer method readImageBlockSize.

private int readImageBlockSize() throws ProtocolAdapterException {
    this.connector.getDlmsMessageListener().setDescription("ImageTransfer read image_block_size, read attribute: " + JdlmsObjectToStringUtil.describeAttributes(this.imageTransferCosem.createAttributeAddress(ImageTransferAttribute.IMAGE_BLOCK_SIZE)));
    final DataObject imageBlockSizeData = this.imageTransferCosem.readAttribute(ImageTransferAttribute.IMAGE_BLOCK_SIZE);
    if (imageBlockSizeData == null || !imageBlockSizeData.isNumber()) {
        throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_BLOCK_SIZE_NOT_READ);
    }
    final Long imageBlockSizeValue = imageBlockSizeData.getValue();
    this.imageBlockSize = imageBlockSizeValue.intValue();
    this.imageBlockSizeReadFlag = true;
    return this.imageBlockSize;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 52 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class ImageTransfer method getImageFirstNotTransferredBlockNumber.

private int getImageFirstNotTransferredBlockNumber() throws ProtocolAdapterException {
    this.connector.getDlmsMessageListener().setDescription("ImageTransfer read image_first_not_transferred_block_number, read attribute: " + JdlmsObjectToStringUtil.describeAttributes(this.imageTransferCosem.createAttributeAddress(ImageTransferAttribute.IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER)));
    final DataObject imageFirstNotReadBlockNumberData = this.imageTransferCosem.readAttribute(ImageTransferAttribute.IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER);
    if (imageFirstNotReadBlockNumberData == null || !imageFirstNotReadBlockNumberData.isNumber()) {
        throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER_NOT_READ);
    }
    final Long imageFirstNotReadBlockNumber = imageFirstNotReadBlockNumberData.getValue();
    return imageFirstNotReadBlockNumber.intValue();
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 53 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class ImageTransfer method verifyImage.

/**
 * The Image is verified. This is done by invoking the image_verify method by the client and
 * testing the image transfer status.
 */
public void verifyImage() throws OsgpException {
    final DataObject parameter = DataObject.newInteger8Data((byte) 0);
    this.setDescriptionForMethodCall(ImageTransferMethod.IMAGE_VERIFY, parameter);
    final MethodResultCode verified = this.imageTransferCosem.callMethod(ImageTransferMethod.IMAGE_VERIFY, parameter);
    if (verified == null) {
        throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_VERIFY_NOT_CALLED);
    }
    if (verified == MethodResultCode.SUCCESS) {
        return;
    }
    if (verified == MethodResultCode.TEMPORARY_FAILURE) {
        this.waitForImageVerification();
    }
    // If activation was triggered the device will not verify again.
    if (this.imageIsVerified()) {
        return;
    }
    final int status = this.getImageTransferStatus();
    throw new ImageTransferException(String.format(EXCEPTION_MSG_IMAGE_VERIFICATION_ERROR, ImageTransferStatus.getByValue(status).name(), verified.name()));
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ImageTransferException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)

Example 54 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest.

@Test
void processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest() throws OsgpException, JMSException {
    // arrange
    final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
    final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
    final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
    final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
    final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
    when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock);
    when(this.firmwareService.updateFirmware(same(this.dlmsConnectionManagerMock), same(this.dlmsDevice), same(firmwareFileDto), any(MessageMetadata.class))).thenThrow(new ProtocolAdapterException("Firmware file fw is not available."));
    // act
    this.getFirmwareFileResponseMessageProcessor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock);
    // assert
    verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture());
    final ResponseMessage capturedValue = responseMessageArgumentCaptor.getValue();
    assertThat(((UpdateFirmwareRequestDto) capturedValue.getDataObject()).getFirmwareIdentification()).isSameAs(firmwareFileDto.getFirmwareIdentification());
    assertThat(capturedValue.getResult()).isSameAs(ResponseMessageResultType.NOT_OK);
    assertThat(capturedValue.bypassRetry()).isFalse();
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 55 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class ConfigurationService method setAlarmNotifications.

public void setAlarmNotifications(final DlmsConnectionManager conn, final DlmsDevice device, final AlarmNotificationsDto alarmNotifications, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    LOGGER.info("Alarm Notifications to set on the device: {}", alarmNotifications);
    final AccessResultCode accessResultCode = this.setAlarmNotificationsCommandExecutor.execute(conn, device, alarmNotifications, messageMetadata);
    if (AccessResultCode.SUCCESS != accessResultCode) {
        throw new ProtocolAdapterException("AccessResultCode for set alarm notifications was not SUCCESS: " + accessResultCode);
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)95 DataObject (org.openmuc.jdlms.datatypes.DataObject)32 Test (org.junit.jupiter.api.Test)22 AccessResultCode (org.openmuc.jdlms.AccessResultCode)15 GetResult (org.openmuc.jdlms.GetResult)15 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)9 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)9 BitString (org.openmuc.jdlms.datatypes.BitString)7 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)7 ObisCode (org.openmuc.jdlms.ObisCode)6 SetParameter (org.openmuc.jdlms.SetParameter)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 DateTime (org.joda.time.DateTime)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)4 Date (java.util.Date)3 List (java.util.List)3