Search in sources :

Example 41 with ProtocolAdapterException

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

the class GetPeriodicMeterReadsGasCommandExecutor method getProfileBufferAddress.

private AttributeAddressForProfile getProfileBufferAddress(final PeriodTypeDto periodType, final ChannelDto channel, final DateTime beginDateTime, final DateTime endDateTime, final DlmsDevice device) throws ProtocolAdapterException {
    final DlmsObjectType type = DlmsObjectType.getTypeForPeriodType(periodType);
    // Add the attribute address for the profile
    final AttributeAddressForProfile attributeAddressProfile = this.dlmsObjectConfigService.findAttributeAddressForProfile(device, type, channel.getChannelNumber(), beginDateTime, endDateTime, Medium.GAS).orElseThrow(() -> new ProtocolAdapterException("No address found for " + type));
    LOGGER.info("Dlms object config service returned profile buffer address {} ", attributeAddressProfile);
    return attributeAddressProfile;
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)

Example 42 with ProtocolAdapterException

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

the class AbstractReplaceKeyCommandExecutor method sendToDevice.

/**
 * Send the key to the device.
 *
 * @param conn jDLMS connection.
 * @param deviceIdentification Device identification
 * @param keyWrapper Key data
 * @param messageMetadata
 */
private void sendToDevice(final DlmsConnectionManager conn, final String deviceIdentification, final ReplaceKeyInput keyWrapper, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    try {
        final byte[] decryptedKey = keyWrapper.getBytes();
        final byte[] decryptedMasterKey = this.secretManagementService.getKey(messageMetadata, deviceIdentification, SecurityKeyType.E_METER_MASTER);
        final MethodParameter methodParameterAuth = SecurityUtils.keyChangeMethodParamFor(decryptedMasterKey, decryptedKey, keyWrapper.getKeyId());
        conn.getDlmsMessageListener().setDescription("ReplaceKey for " + keyWrapper.getSecurityKeyType() + " " + keyWrapper.getKeyId() + ", call method: " + JdlmsObjectToStringUtil.describeMethod(methodParameterAuth));
        final MethodResultCode methodResultCode = conn.getConnection().action(methodParameterAuth).getResultCode();
        if (!MethodResultCode.SUCCESS.equals(methodResultCode)) {
            throw new ProtocolAdapterException("AccessResultCode for replace keys was not SUCCESS: " + methodResultCode);
        }
        if (keyWrapper.getSecurityKeyType() == SecurityKeyType.E_METER_AUTHENTICATION) {
            conn.getConnection().changeClientGlobalAuthenticationKey(decryptedKey);
        } else if (keyWrapper.getSecurityKeyType() == SecurityKeyType.E_METER_ENCRYPTION) {
            conn.getConnection().changeClientGlobalEncryptionKey(decryptedKey);
        }
    } catch (final IOException e) {
        throw new ConnectionException(e);
    } catch (final EncrypterException e) {
        throw new ProtocolAdapterException("Unexpected exception during decryption of security keys, reason = " + e.getMessage(), e);
    }
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) EncrypterException(org.opensmartgridplatform.shared.exceptionhandling.EncrypterException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) IOException(java.io.IOException) MethodParameter(org.openmuc.jdlms.MethodParameter) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 43 with ProtocolAdapterException

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

the class GetPeriodicMeterReadsCommandExecutor method getProfileBufferAddress.

private AttributeAddressForProfile getProfileBufferAddress(final PeriodTypeDto periodType, final DateTime beginDateTime, final DateTime endDateTime, final DlmsDevice device) throws ProtocolAdapterException {
    final DlmsObjectType type = DlmsObjectType.getTypeForPeriodType(periodType);
    // Add the attribute address for the profile
    final AttributeAddressForProfile attributeAddressProfile = this.dlmsObjectConfigService.findAttributeAddressForProfile(device, type, 0, beginDateTime, endDateTime, Medium.ELECTRICITY).orElseThrow(() -> new ProtocolAdapterException("No address found for " + type));
    LOGGER.info("Dlms object config service returned profile buffer address {} ", attributeAddressProfile);
    return attributeAddressProfile;
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)

Example 44 with ProtocolAdapterException

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

the class GetActualMeterReadsGasCommandExecutor method execute.

@Override
public MeterReadsGasResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActualMeterReadsQueryDto actualMeterReadsRequest, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final ObisCode obisCodeMbusMasterValue = this.masterValueForChannel(actualMeterReadsRequest.getChannel());
    LOGGER.debug("Retrieving current MBUS master value for ObisCode: {}", obisCodeMbusMasterValue);
    final AttributeAddress mbusValue = new AttributeAddress(CLASS_ID_MBUS, this.masterValueForChannel(actualMeterReadsRequest.getChannel()), ATTRIBUTE_ID_VALUE);
    LOGGER.debug("Retrieving current MBUS master capture time for ObisCode: {}", obisCodeMbusMasterValue);
    final AttributeAddress mbusTime = new AttributeAddress(CLASS_ID_MBUS, obisCodeMbusMasterValue, ATTRIBUTE_ID_TIME);
    final AttributeAddress scalerUnit = new AttributeAddress(CLASS_ID_MBUS, this.masterValueForChannel(actualMeterReadsRequest.getChannel()), ATTRIBUTE_ID_SCALER_UNIT);
    conn.getDlmsMessageListener().setDescription("GetActualMeterReadsGas for channel " + actualMeterReadsRequest.getChannel() + ", retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(mbusValue, mbusTime, scalerUnit));
    final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "retrieve actual meter reads for mbus " + actualMeterReadsRequest.getChannel(), mbusValue, mbusTime, scalerUnit);
    final DlmsMeterValueDto consumption = this.dlmsHelper.getScaledMeterValue(getResultList.get(0), getResultList.get(2), "retrieve scaled value for mbus " + actualMeterReadsRequest.getChannel());
    final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(getResultList.get(1), "captureTime gas");
    final Date captureTime;
    if (cosemDateTime.isDateTimeSpecified()) {
        captureTime = cosemDateTime.asDateTime().toDate();
    } else {
        throw new ProtocolAdapterException("Unexpected null/unspecified value for M-Bus Capture Time");
    }
    return new MeterReadsGasResponseDto(new Date(), consumption, captureTime);
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto) Date(java.util.Date) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Example 45 with ProtocolAdapterException

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

the class SetPushSetupAlarmCommandExecutor method verifyPushObject.

private void verifyPushObject(final CosemObjectDefinitionDto pushObject, final DlmsConnectionManager conn) throws ProtocolAdapterException {
    final int dataIndex = pushObject.getDataIndex();
    if (dataIndex != 0) {
        throw new ProtocolAdapterException("PushObject contains non-zero data index: " + dataIndex + ". Using data index is not implemented.");
    }
    final ObisCode obisCode = new ObisCode(pushObject.getLogicalName().toByteArray());
    final AttributeAddress attributeAddress = new AttributeAddress(pushObject.getClassId(), obisCode, pushObject.getAttributeIndex());
    try {
        this.dlmsHelper.getAttributeValue(conn, attributeAddress);
    } catch (final FunctionalException e) {
        throw new ProtocolAdapterException("Verification of push object failed. Object " + obisCode.asDecimalString() + " could not be retrieved using a get request.", e);
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ObisCode(org.openmuc.jdlms.ObisCode) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

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