use of org.openmuc.jdlms.ObisCode 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);
}
}
use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class SetEncryptionKeyExchangeOnGMeterCommandExecutor method execute.
@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final GMeterInfoDto gMeterInfo, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
try {
LOGGER.debug("SetEncryptionKeyExchangeOnGMeterCommandExecutor.execute called");
final String mbusDeviceIdentification = gMeterInfo.getDeviceIdentification();
final int channel = gMeterInfo.getChannel();
final ObisCode obisCode = OBIS_HASHMAP.get(channel);
final byte[] gMeterEncryptionKey = this.secretManagementService.generate128BitsKeyAndStoreAsNewKey(messageMetadata, mbusDeviceIdentification, G_METER_ENCRYPTION);
MethodResult methodResultCode = this.transferKey(conn, mbusDeviceIdentification, channel, gMeterEncryptionKey, messageMetadata);
this.checkMethodResultCode(methodResultCode, "M-Bus Setup transfer_key", obisCode);
methodResultCode = this.setEncryptionKey(conn, channel, gMeterEncryptionKey);
this.checkMethodResultCode(methodResultCode, "M-Bus Setup set_encryption_key", obisCode);
this.secretManagementService.activateNewKey(messageMetadata, mbusDeviceIdentification, G_METER_ENCRYPTION);
return MethodResultCode.SUCCESS;
} 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.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigService method getAttributeAddressForProfile.
private AttributeAddressForProfile getAttributeAddressForProfile(final AddressRequest addressRequest) {
final List<DlmsCaptureObject> selectedObjects = new ArrayList<>();
final SelectiveAccessDescription access = this.getAccessDescription(addressRequest, selectedObjects);
final DlmsObject dlmsObject = addressRequest.getDlmsObject();
final ObisCode obisCode = this.replaceChannel(dlmsObject.getObisCodeAsString(), addressRequest.getChannel());
return new AttributeAddressForProfile(new AttributeAddress(dlmsObject.getClassId(), obisCode, dlmsObject.getDefaultAttributeId(), access), selectedObjects);
}
use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class DeviceChannelsHelper method makeAttributeAddresses.
private AttributeAddress[] makeAttributeAddresses(final DlmsObject mbusClientSetupObject, final int channel) {
final AttributeAddress[] attrAddresses = new AttributeAddress[NUMBER_OF_ATTRIBUTES_MBUS_CLIENT];
final ObisCode obiscode = mbusClientSetupObject.getObisCodeWithChannel(channel);
final int classId = mbusClientSetupObject.getClassId();
attrAddresses[INDEX_PRIMARY_ADDRESS] = new AttributeAddress(classId, obiscode, MbusClientAttribute.PRIMARY_ADDRESS.attributeId());
attrAddresses[INDEX_IDENTIFICATION_NUMBER] = new AttributeAddress(classId, obiscode, MbusClientAttribute.IDENTIFICATION_NUMBER.attributeId());
attrAddresses[INDEX_MANUFACTURER_ID] = new AttributeAddress(classId, obiscode, MbusClientAttribute.MANUFACTURER_ID.attributeId());
attrAddresses[INDEX_VERSION] = new AttributeAddress(classId, obiscode, MbusClientAttribute.VERSION.attributeId());
attrAddresses[INDEX_DEVICE_TYPE] = new AttributeAddress(classId, obiscode, MbusClientAttribute.DEVICE_TYPE.attributeId());
return attrAddresses;
}
use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class DecoupleMBusDeviceCommandExecutor method execute.
@Override
public DecoupleMbusDeviceResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final DecoupleMbusDeviceDto decoupleMbusDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final Short channel = decoupleMbusDto.getChannel();
log.debug("Decouple channel {} on gateway device {}", channel, device.getDeviceIdentification());
final ObisCode obisCode = this.deviceChannelsHelper.getObisCode(device, channel);
// Get the current channel element values before resetting the channel
final ChannelElementValuesDto channelElementValues = this.deviceChannelsHelper.getChannelElementValues(conn, device, channel);
// Deinstall and reset channel
final CosemObjectAccessor mBusSetup = new CosemObjectAccessor(conn, obisCode, InterfaceClass.MBUS_CLIENT.id());
this.deviceChannelsHelper.deinstallSlave(conn, device, channel, mBusSetup);
this.deviceChannelsHelper.resetMBusClientAttributeValues(conn, device, channel, this.getClass().getSimpleName());
// return the channel element values as before decoupling
return new DecoupleMbusDeviceResponseDto(channelElementValues);
}
Aggregations