use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class InstallationService method addMeter.
public void addMeter(final MessageMetadata messageMetadata, final SmartMeteringDeviceDto smartMeteringDevice) throws FunctionalException {
if (smartMeteringDevice.getDeviceIdentification() == null) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_DLMS, new IllegalArgumentException("Provided device does not contain device identification"));
}
this.storeAndActivateKeys(messageMetadata, smartMeteringDevice);
final DlmsDevice dlmsDevice = this.installationMapper.map(smartMeteringDevice, DlmsDevice.class);
this.dlmsDeviceRepository.save(dlmsDevice);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigService method getDlmsObjectForCommunicationMethod.
public DlmsObject getDlmsObjectForCommunicationMethod(final DlmsDevice device, final DlmsObjectType type) throws ProtocolAdapterException {
final Protocol protocol = Protocol.forDevice(device);
final CommunicationMethod method = CommunicationMethod.getCommunicationMethod(device.getCommunicationMethod());
return this.dlmsObjectConfigs.stream().filter(config -> config.contains(protocol)).findAny().flatMap(dlmsObjectConfig -> dlmsObjectConfig.findObjectForCommunicationMethod(type, method)).orElseThrow(() -> new ProtocolAdapterException("Did not find " + type.name() + " object with communication method " + method.getMethodName() + " for device " + device.getDeviceId()));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class RecoverKeyProcess method run.
@Override
public void run() {
final DlmsDevice device = this.findDeviceAndCheckState();
log.info("[{}] Attempting key recovery for device {}", this.messageMetadata.getCorrelationUid(), this.deviceIdentification);
try {
// The process started in this try-catch block should only be stopped in the
// ThrottlingPermitDeniedException catch block. If a DeviceKeyProcessAlreadyRunningException
// is thrown the process was already started and should not be stopped. This method below
// could also throw a RecoverKeyException in this case the process wasn't started either
// The next try-catch block has a finally block to ensure stopping the process started here.
this.startProcessing(device);
if (!this.canConnectUsingNewKeys(device)) {
log.warn("[{}] Could not recover keys: could not connect to device {} using New keys", this.messageMetadata.getCorrelationUid(), this.deviceIdentification);
return;
}
} catch (final ThrottlingPermitDeniedException e) {
log.warn("RecoverKeyProcess could not connect to the device due to throttling constraints", e);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
RecoverKeyProcess.this.run();
}
}, this.throttlingClientConfig.permitRejectedDelay().toMillis());
this.deviceKeyProcessingService.stopProcessing(this.deviceIdentification);
return;
} catch (final DeviceKeyProcessAlreadyRunningException e) {
log.info("RecoverKeyProcess could not be started while other key changing process is already running.");
new Timer().schedule(new TimerTask() {
@Override
public void run() {
RecoverKeyProcess.this.run();
}
}, this.deviceKeyProcessingService.getDeviceKeyProcessingTimeout().toMillis());
return;
}
try {
this.secretManagementService.activateNewKeys(this.messageMetadata, this.deviceIdentification, Arrays.asList(E_METER_ENCRYPTION, E_METER_AUTHENTICATION));
} catch (final Exception e) {
throw new RecoverKeyException(e);
} finally {
this.deviceKeyProcessingService.stopProcessing(this.deviceIdentification);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutorTest method createDevice.
private DlmsDevice createDevice(final Protocol protocol) {
final DlmsDevice device = new DlmsDevice();
device.setProtocol(protocol);
return device;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method testExecute.
private void testExecute(final Protocol protocol, final PeriodTypeDto type, final boolean useNullData) throws Exception {
// SETUP
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
// Reset stub
this.connectionStub.clearRequestedAttributeAddresses();
// Create device with requested protocol version
final DlmsDevice device = this.createDlmsDevice(protocol);
// Create request object
final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(type, this.timeFrom, this.timeTo);
// Get expected values
final AttributeAddress expectedAddressProfile = this.createAttributeAddress(protocol, type, this.timeFrom, this.timeTo);
final List<AttributeAddress> expectedScalerUnitAddresses = this.getScalerUnitAttributeAddresses(type);
final int expectedTotalNumberOfAttributeAddresses = expectedScalerUnitAddresses.size() + 1;
// Set response in stub
this.setResponseForProfile(expectedAddressProfile, protocol, type, useNullData);
this.setResponsesForScalerUnit(expectedScalerUnitAddresses);
// CALL
final PeriodicMeterReadsResponseDto response = this.executor.execute(this.connectionManagerStub, device, request, messageMetadata);
// VERIFY
// Get resulting requests from connection stub
final List<AttributeAddress> requestedAttributeAddresses = this.connectionStub.getRequestedAttributeAddresses();
assertThat(requestedAttributeAddresses.size()).isEqualTo(expectedTotalNumberOfAttributeAddresses);
// There should be 1 request to the buffer (id = 2) of a profile
// (class-id = 7)
final AttributeAddress actualAttributeAddressProfile = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_PROFILE).collect(Collectors.toList()).get(0);
AttributeAddressAssert.is(actualAttributeAddressProfile, expectedAddressProfile);
// Check the amount of requests to the scaler_units of the meter values
// in the registers
final List<AttributeAddress> attributeAddressesScalerUnit = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_REGISTER && a.getId() == this.ATTR_ID_SCALER_UNIT).collect(Collectors.toList());
assertThat(attributeAddressesScalerUnit.size()).isEqualTo(expectedScalerUnitAddresses.size());
// Check response
assertThat(response.getPeriodType()).isEqualTo(type);
final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads = response.getPeriodicMeterReads();
assertThat(periodicMeterReads.size()).isEqualTo(this.AMOUNT_OF_PERIODS);
this.checkClockValues(periodicMeterReads, type, useNullData);
this.checkValues(periodicMeterReads, type);
}
Aggregations