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