Search in sources :

Example 1 with ProtocolAdapterException

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();
    }
}
Also used : DeviceKeyProcessAlreadyRunningException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException) Instant(java.time.Instant) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 2 with ProtocolAdapterException

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);
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 3 with ProtocolAdapterException

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;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) GetResult(org.openmuc.jdlms.GetResult) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 4 with ProtocolAdapterException

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;
}
Also used : ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 5 with ProtocolAdapterException

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);
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto)

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