use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class ClearAlarmRegisterCommandExecutorTest method nullResultAlarmRegister1.
@Test
void nullResultAlarmRegister1() throws ProtocolAdapterException, IOException {
when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(null);
final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
this.setupAlarmRegister1(dlmsDevice);
final Throwable actual = catchThrowable(() -> this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata));
assertThat(actual).isInstanceOf(ProtocolAdapterException.class);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class ClearAlarmRegisterCommandExecutorTest method failureRegister1AndResultAlarmRegister2.
@Test
void failureRegister1AndResultAlarmRegister2() throws ProtocolAdapterException, IOException {
when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(AccessResultCode.OTHER_REASON).thenReturn(AccessResultCode.SUCCESS);
final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
this.setupAlarmRegister1(dlmsDevice);
final AccessResultCode accessResultCode = this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
assertThat(accessResultCode).isEqualTo(AccessResultCode.OTHER_REASON);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method setUp.
@BeforeEach
public void setUp() {
this.setParametersReceived = new ArrayList<>();
this.device = new DlmsDevice("SuperAwesomeHeroicRockstarDevice");
this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
final DlmsObjectConfigConfiguration dlmsObjectConfigConfiguration = new DlmsObjectConfigConfiguration();
final DlmsObjectConfigService dlmsObjectConfigService = new DlmsObjectConfigService(new DlmsHelper(), dlmsObjectConfigConfiguration.getDlmsObjectConfigs()) {
@Override
public Optional<AttributeAddress> findAttributeAddress(final DlmsDevice device, final DlmsObjectType type, final Integer channel) {
switch(type) {
case ALARM_FILTER_1:
return Optional.of(new AttributeAddress(40, "0.0.97.98.10.255", 2));
case ALARM_FILTER_2:
return Optional.of(new AttributeAddress(40, "0.0.97.98.11.255", 2));
}
return Optional.empty();
}
};
this.executor = new SetAlarmNotificationsCommandExecutor(dlmsObjectConfigService);
final DlmsConnectionStub conn = new DlmsConnectionStub() {
@Override
public AccessResultCode set(final SetParameter setParameter) {
SetAlarmNotificationsCommandExecutorTest.this.setParametersReceived.add(setParameter);
return AccessResultCode.SUCCESS;
}
};
// Set the return value to 10 (0b1010):
// REPLACE_BATTERY enabled, AUXILIARY_EVENT enabled.
conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.10.255", 2), DataObject.newInteger32Data(10));
conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.11.255", 2), DataObject.newInteger32Data(0));
this.connMgr = new DlmsConnectionManagerStub(conn);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class SessionProviderSimulator method getIpAddress.
/**
* This implementation depends on the iccId having the same value as the device identification (in
* order to be able to look up some data with the device for calling the simulator starting web
* service, like the port number and logicalId of a simulated device).
*
* @throws SessionProviderException when no dlmsDevice can be found with a deviceId equal to the
* given iccId, or the simulator was not successfully started.
*/
@Override
public String getIpAddress(final String iccId) throws SessionProviderException {
DlmsDevice dlmsDevice;
try {
dlmsDevice = this.domainHelperService.findDlmsDevice(iccId);
this.simulatorTriggerClient.sendTrigger(dlmsDevice);
} catch (final FunctionalException e) {
throw new SessionProviderException("Unable to find dlmsDevice. ", e);
} catch (final SimulatorTriggerClientException e) {
throw new SessionProviderException("Unable to successfully start a simulator. ", e);
}
return this.ipAddress;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class OsgpResponseMessageProcessor method processMessageTask.
// SilentException cannot be caught since
@SuppressWarnings("squid:S1193")
private // it does not extend Exception.
void processMessageTask(final Serializable messageObject, final MessageMetadata messageMetadata, final DlmsConnectionManager conn) throws OsgpException {
try {
final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
LOGGER.info("{} called for device: {} for organisation: {}", messageMetadata.getMessageType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification());
if (this.usesDeviceConnection()) {
this.handleMessage(conn, this.domainHelperService.findDlmsDevice(messageMetadata), messageObject);
} else {
this.handleMessage(device, messageObject);
}
} catch (final Exception exception) {
// Return original request + exception
if (!(exception instanceof SilentException)) {
LOGGER.error("Unexpected exception during {}", this.messageType.name(), exception);
}
this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, exception, this.responseMessageSender, messageObject);
} finally {
final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
this.doConnectionPostProcessing(device, conn, messageMetadata);
}
}
Aggregations