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