Search in sources :

Example 6 with FirmwareFile

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.

the class MacGenerationServiceTest method calculateMac.

void calculateMac(final byte[] byteArray, final String deviceIdentification, final byte[] firmwareUpdateAuthenticationKey, final String expectedMac) throws IOException, ProtocolAdapterException {
    when(this.secretManagementService.getKey(messageMetadata, deviceIdentification, SecurityKeyType.G_METER_FIRMWARE_UPDATE_AUTHENTICATION)).thenReturn(firmwareUpdateAuthenticationKey);
    final String mbusDeviceIdentificationNumber = deviceIdentification.substring(7, 15);
    final FirmwareFile firmwareFile = this.createFirmwareFile(byteArray, mbusDeviceIdentificationNumber);
    final byte[] calculatedMac = this.macGenerationService.calculateMac(messageMetadata, deviceIdentification, firmwareFile);
    assertThat(Hex.toHexString(calculatedMac)).isEqualTo(expectedMac);
}
Also used : FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile)

Example 7 with FirmwareFile

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.

the class MacGenerationServiceTest method testIV.

public void testIV(final byte[] byteArray, final String expectedIv, final String mbusDeviceIdentificationNumber) throws IOException, ProtocolAdapterException {
    final FirmwareFile firmwareFile = this.createFirmwareFile(byteArray, mbusDeviceIdentificationNumber);
    final byte[] iv = this.macGenerationService.createIV(firmwareFile);
    assertThat(Hex.toHexString(iv)).isEqualTo(expectedIv);
}
Also used : FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile)

Example 8 with FirmwareFile

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile 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

FirmwareFile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile)8 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)4 IOException (java.io.IOException)2 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1 ImageTransferException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)1 UpdateFirmwareResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1