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()));
}
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);
}
}
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);
}
}
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);
}
}
Aggregations