Search in sources :

Example 1 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 init.

@BeforeAll
public static void init() throws IOException, ProtocolAdapterException {
    byteArray1 = Files.readAllBytes(new ClassPathResource(fwFilename1).getFile().toPath());
    // Same firmware file but now with wildcarded mbusversion (Florian firmware)
    final FirmwareFile firmwareFile2 = new FirmwareFile(byteArray1);
    firmwareFile2.setMbusVersion(255);
    byteArray2 = firmwareFile2.getByteArray();
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 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 createFirmwareFile.

private FirmwareFile createFirmwareFile(final byte[] byteArray, final String mbusDeviceIdentificationNumber) throws ProtocolAdapterException {
    final FirmwareFile firmwareFile = new FirmwareFile(byteArray.clone());
    System.out.println(firmwareFile.getHeader());
    firmwareFile.setMbusDeviceIdentificationNumber(mbusDeviceIdentificationNumber);
    firmwareFile.setMbusVersion(80);
    System.out.println(firmwareFile.getHeader());
    return firmwareFile;
}
Also used : FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile)

Example 3 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 assertExceptionContainsMessageOnCalculateMac.

private void assertExceptionContainsMessageOnCalculateMac(final Class<? extends Exception> exceptionClass, final byte[] malformedFirmwareFile, final String partOfExceptionMessage, final String deviceIdentification) throws ProtocolAdapterException {
    final FirmwareFile firmwareFile = new FirmwareFile(malformedFirmwareFile);
    firmwareFile.setMbusDeviceIdentificationNumber(deviceIdentification.substring(7, 15));
    final Exception exception = assertThrows(exceptionClass, () -> {
        this.macGenerationService.calculateMac(messageMetadata, deviceIdentification, firmwareFile);
    });
    assertThat(exception).hasMessageContaining(partOfExceptionMessage);
}
Also used : FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 4 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 testNoKey.

@Test
void testNoKey() throws IOException, ProtocolAdapterException {
    when(this.secretManagementService.getKey(messageMetadata, this.deviceIdentification1, SecurityKeyType.G_METER_FIRMWARE_UPDATE_AUTHENTICATION)).thenReturn(null);
    final FirmwareFile firmwareFile = this.createFirmwareFile(byteArray1, this.deviceIdentification1.substring(7, 15));
    final Exception exception = assertThrows(ProtocolAdapterException.class, () -> {
        this.macGenerationService.calculateMac(messageMetadata, this.deviceIdentification1, firmwareFile);
    });
    assertThat(exception).hasMessageContaining("No key of type G_METER_FIRMWARE_UPDATE_AUTHENTICATION found for device");
}
Also used : FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 5 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 getFirmwareFile.

private FirmwareFile getFirmwareFile(final UpdateFirmwareRequestDto updateFirmwareRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    log.debug("Getting firmware file from caching repository for firmware {}", updateFirmwareRequestDto.getFirmwareIdentification());
    final byte[] firmwareFileByteArray = this.firmwareFileCachingRepository.retrieve(updateFirmwareRequestDto.getFirmwareIdentification());
    if (firmwareFileByteArray == null) {
        throw new ProtocolAdapterException(EXCEPTION_MSG_FIRMWARE_FILE_NOT_AVAILABLE);
    }
    final FirmwareFile firmwareFile = new FirmwareFile(firmwareFileByteArray);
    if (firmwareFile.isMbusFirmware()) {
        firmwareFile.checkLengths();
        this.addMac(messageMetadata, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile);
    }
    return firmwareFile;
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile)

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