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