Search in sources :

Example 76 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException 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)

Example 77 with ProtocolAdapterException

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

the class UpdateFirmwareCommandExecutor method addMac.

private FirmwareFile addMac(final MessageMetadata messageMetadata, final String deviceIdentification, final FirmwareFile firmwareFile) throws ProtocolAdapterException {
    log.debug("Adding MAC to firmware file for M-Bus device with deviceIdentification {}", deviceIdentification);
    final DlmsDevice mbusDevice = this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification);
    if (mbusDevice == null) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_DEVICE_NOT_AVAILABLE_IN_DATABASE, deviceIdentification));
    }
    final String identificationNumber = this.getIdentificationNumber(mbusDevice);
    log.debug("Original Firmware file header: {}", firmwareFile.getHeader());
    log.debug("Setting M-Bus Identification number: {}", identificationNumber);
    firmwareFile.setMbusDeviceIdentificationNumber(identificationNumber);
    final int mbusVersion = 80;
    log.debug("Setting M-Bus Version: {}", mbusVersion);
    firmwareFile.setMbusVersion(mbusVersion);
    log.debug("Modified Firmware file header: {}", firmwareFile.getHeader());
    final byte[] calculatedMac = this.macGenerationService.calculateMac(messageMetadata, mbusDevice.getDeviceIdentification(), firmwareFile);
    log.debug("Calculated MAC: {}", Hex.toHexString(calculatedMac));
    firmwareFile.setSecurityByteArray(calculatedMac);
    return firmwareFile;
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 78 with ProtocolAdapterException

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

the class DataObjectToEventListConverter method convert.

public List<EventDto> convert(final DataObject source, final EventLogCategoryDto eventLogCategory) throws ProtocolAdapterException {
    final List<EventDto> eventList = new ArrayList<>();
    if (source == null) {
        throw new ProtocolAdapterException("DataObject should not be null");
    }
    final List<DataObject> listOfEvents = source.getValue();
    for (final DataObject eventDataObject : listOfEvents) {
        eventList.add(this.getEvent(eventDataObject, eventLogCategory));
    }
    return eventList;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 79 with ProtocolAdapterException

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

the class DataObjectToEventListConverter method getEvent.

private EventDto getEvent(final DataObject eventDataObject, final EventLogCategoryDto eventLogCategory) throws ProtocolAdapterException {
    final List<DataObject> eventData = eventDataObject.getValue();
    if (eventData == null) {
        throw new ProtocolAdapterException("eventData DataObject should not be null");
    }
    final int numberOfEventElements = eventLogCategory.getDetailsType().getNumberOfEventElements();
    if (eventData.size() != numberOfEventElements) {
        throw new ProtocolAdapterException("eventData size should be " + numberOfEventElements);
    }
    // extract values from List<DataObject> eventData.
    final DateTime dateTime = this.extractDateTime(eventData);
    final Integer code = this.extractCode(eventData);
    final Integer eventCounter = this.extractEventCounter(eventLogCategory, eventData);
    final String eventLogCategoryName = eventLogCategory.name();
    log.info("Event time is {}, event code is {}, event category is {} and event counter is {}", dateTime, code, eventLogCategoryName, eventCounter);
    // build a new EventDto with those values.
    final EventDto event = new EventDto(dateTime, code, eventCounter, eventLogCategoryName);
    // add details
    event.addEventDetails(this.extractEventDetails(eventLogCategory, eventData));
    return event;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DateTime(org.joda.time.DateTime)

Example 80 with ProtocolAdapterException

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

the class DataObjectToOutageListConverter method getOutageDto.

private OutageDto getOutageDto(final DataObject outageDataObject) throws ProtocolAdapterException {
    final List<DataObject> outageData = outageDataObject.getValue();
    if (outageData == null) {
        throw new ProtocolAdapterException("outageData DataObject should not be null");
    }
    if (outageData.size() != NUMBER_OF_ELEMENTS) {
        throw new ProtocolAdapterException("outageData size should be " + NUMBER_OF_ELEMENTS);
    }
    final DateTime endTime = this.extractDateTime(outageData);
    final Long duration = this.extractEventDuration(outageData);
    final OutageDto outage = new OutageDto(endTime, duration);
    log.info("Converted dataObject to outage: {}", outage);
    return outage;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) OutageDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.OutageDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DateTime(org.joda.time.DateTime)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)95 DataObject (org.openmuc.jdlms.datatypes.DataObject)32 Test (org.junit.jupiter.api.Test)22 AccessResultCode (org.openmuc.jdlms.AccessResultCode)15 GetResult (org.openmuc.jdlms.GetResult)15 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)9 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)9 BitString (org.openmuc.jdlms.datatypes.BitString)7 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)7 ObisCode (org.openmuc.jdlms.ObisCode)6 SetParameter (org.openmuc.jdlms.SetParameter)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 DateTime (org.joda.time.DateTime)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)4 Date (java.util.Date)3 List (java.util.List)3