Search in sources :

Example 1 with ImageTransferException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException 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 2 with ImageTransferException

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

the class ImageTransfer method waitForImageInitiation.

private void waitForImageInitiation() throws OsgpException {
    final Future<Integer> newStatus = EXECUTOR_SERVICE.submit(new ImageTransferStatusChangeWatcher(ImageTransferStatus.NOT_INITIATED, this.properties.getInitiationStatusCheckInterval(), this.properties.getInitiationStatusCheckTimeout()));
    final int status;
    try {
        status = newStatus.get();
    } catch (final InterruptedException | ExecutionException e) {
        throw new ProtocolAdapterException("", e);
    }
    if (status != ImageTransferStatus.INITIATED.getValue()) {
        throw new ImageTransferException(EXCEPTION_MSG_IMAGE_TRANSFER_NOT_INITIATED);
    }
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ExecutionException(java.util.concurrent.ExecutionException) ImageTransferException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)

Example 3 with ImageTransferException

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

the class ImageTransfer method waitForImageVerification.

private void waitForImageVerification() throws OsgpException {
    final Future<Integer> newStatus = EXECUTOR_SERVICE.submit(new ImageTransferStatusChangeWatcher(ImageTransferStatus.VERIFICATION_INITIATED, this.properties.getVerificationStatusCheckInterval(), this.properties.getVerificationStatusCheckTimeout()));
    final int status;
    try {
        status = newStatus.get();
    } catch (final InterruptedException | ExecutionException e) {
        throw new ProtocolAdapterException("", e);
    }
    if (status == ImageTransferStatus.VERIFICATION_FAILED.getValue()) {
        throw new ImageTransferException(EXCEPTION_MSG_IMAGE_NOT_VERIFIED);
    }
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ExecutionException(java.util.concurrent.ExecutionException) ImageTransferException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)

Example 4 with ImageTransferException

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

the class UpdateFirmwareCommandExecutor method execute.

@Override
public UpdateFirmwareResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final UpdateFirmwareRequestDto updateFirmwareRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
    final String firmwareIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
    final FirmwareFile firmwareFile = this.getFirmwareFile(updateFirmwareRequestDto, messageMetadata);
    final ImageTransfer transfer = new ImageTransfer(conn, this.imageTransferProperties, this.getImageIdentifier(firmwareIdentification, firmwareFile), firmwareFile.getByteArray());
    try {
        this.prepare(transfer);
        this.transfer(transfer);
        if (!firmwareFile.isMbusFirmware()) {
            this.verify(transfer);
            this.activate(transfer);
        } else {
            this.activateWithoutVerification(transfer);
        }
        return new UpdateFirmwareResponseDto(firmwareIdentification);
    } catch (final ImageTransferException | ProtocolAdapterException e) {
        throw new ProtocolAdapterException(EXCEPTION_MSG_UPDATE_FAILED, e);
    }
}
Also used : UpdateFirmwareResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile) ImageTransferException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)

Aggregations

ImageTransferException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)4 ExecutionException (java.util.concurrent.ExecutionException)2 MethodResultCode (org.openmuc.jdlms.MethodResultCode)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 FirmwareFile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile)1 UpdateFirmwareResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto)1