use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DeviceKeyProcessingService method startProcessing.
public void startProcessing(final String deviceIdentification) throws DeviceKeyProcessAlreadyRunningException, FunctionalException {
final DlmsDevice dlmsDevice = this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification);
if (dlmsDevice == null) {
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.PROTOCOL_DLMS, new ProtocolAdapterException("Unable to start key changing process with unknown device: " + deviceIdentification));
}
final Instant oldestStartTimeNotConsiderTimedOut = Instant.now().minus(this.deviceKeyProcessingTimeout);
final int updatedRecords = this.dlmsDeviceRepository.setProcessingStartTime(dlmsDevice.getDeviceIdentification(), oldestStartTimeNotConsiderTimedOut);
if (updatedRecords == 0) {
throw new DeviceKeyProcessAlreadyRunningException();
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class FirmwareService method updateFirmware.
public UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionManager conn, final DlmsDevice device, final FirmwareFileDto firmwareFileDto, final MessageMetadata messageMetadata) throws OsgpException {
LOGGER.info("Updating firmware of device {} to firmware with identification {} using included firmware file", device, firmwareFileDto.getFirmwareIdentification());
if (ArrayUtils.isEmpty(firmwareFileDto.getFirmwareFile())) {
throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_FIRMWARE_FILE_NOT_AVAILABLE, firmwareFileDto.getFirmwareIdentification()));
}
this.firmwareRepository.store(firmwareFileDto.getFirmwareIdentification(), firmwareFileDto.getFirmwareFile());
this.imageIdentifierRepository.store(firmwareFileDto.getFirmwareIdentification(), firmwareFileDto.getImageIdentifier());
return this.executeFirmwareUpdate(conn, device, new UpdateFirmwareRequestDto(firmwareFileDto.getFirmwareIdentification(), firmwareFileDto.getDeviceIdentification()), messageMetadata);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class AbstractCommandExecutor method getValidatedResultData.
/**
* Retrieves connection, gets result data and validates it before returning.
*
* @param conn holds connection
* @param getParameter for attribute to retrieve result data from
* @return dataObject
*/
public DataObject getValidatedResultData(final DlmsConnectionManager conn, final AttributeAddress getParameter) throws ProtocolAdapterException {
final GetResult getResult;
try {
getResult = conn.getConnection().get(getParameter);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (getResult == null) {
throw new ProtocolAdapterException("No GetResult received while retrieving M-Bus encryption key status.");
}
final DataObject dataObject = getResult.getResultData();
if (!dataObject.isNumber()) {
throw new ProtocolAdapterException("Received unexpected result data.");
}
return dataObject;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class AbstractCommandExecutor method executeBundleAction.
@Override
public ActionResponseDto executeBundleAction(final DlmsConnectionManager conn, final DlmsDevice device, final ActionRequestDto actionRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
if (this.bundleExecutorMapKey == null) {
throw new ProtocolAdapterException("Execution of " + this.getClass().getName() + " is not supported in a bundle context.");
}
final T commandInput = this.fromBundleRequestInput(actionRequestDto);
LOGGER.debug("Translated {} from bundle to {} for call to CommandExecutor.", this.className(actionRequestDto), this.className(commandInput));
final R executionResult = this.execute(conn, device, commandInput, messageMetadata);
final ActionResponseDto bundleResponse = this.asBundleResponse(executionResult);
LOGGER.debug("Translated {} to {} for bundle response after call to CommandExecutor.", this.className(executionResult), this.className(bundleResponse));
return bundleResponse;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class ConfigurationService method setSpecialDays.
public void setSpecialDays(final DlmsConnectionManager conn, final DlmsDevice device, final SpecialDaysRequestDto specialDaysRequest, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
// The Special days towards the Smart Meter
final SpecialDaysRequestDataDto specialDaysRequestData = specialDaysRequest.getSpecialDaysRequestData();
LOGGER.info(VISUAL_SEPARATOR);
LOGGER.info("********** Set Special Days: 0-0:11.0.0.255 **********");
LOGGER.info(VISUAL_SEPARATOR);
final List<SpecialDayDto> specialDays = specialDaysRequestData.getSpecialDays();
for (final SpecialDayDto specialDay : specialDays) {
LOGGER.info("Date :{}, dayId : {} ", specialDay.getSpecialDayDate(), specialDay.getDayId());
}
LOGGER.info(VISUAL_SEPARATOR);
final AccessResultCode accessResultCode = this.setSpecialDaysCommandExecutor.execute(conn, device, specialDays, messageMetadata);
if (!AccessResultCode.SUCCESS.equals(accessResultCode)) {
throw new ProtocolAdapterException("Set special days reported result is: " + accessResultCode);
}
}
Aggregations