use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method invocationCounterUpdateSuccesfull.
@Test
void invocationCounterUpdateSuccesfull() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("SMR").withInvocationCounter(123L).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
final ConnectionException exception = new ConnectionException("Error creating connection for device E0051004228715518 with Ip address:62.133.88.34 Port:null " + "UseHdlc:false UseSn:false Message:Socket was closed by remote host.");
// First try throw exception, second time no exception
doThrow(exception).doNothing().when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, null, this.task);
verify(this.invocationCounterManager).initializeInvocationCounter(this.messageMetadata, device);
verify(this.connectionFactory, times(2)).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class SetRandomisationSettingsCommandExecutor method writeAttribute.
private void writeAttribute(final DlmsConnectionManager conn, final SetParameter parameter) throws ProtocolAdapterException {
try {
final AccessResultCode result = conn.getConnection().set(parameter);
this.checkResult(result, "setRandomisationSettings");
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutor method executeForAlarmFilter.
private AccessResultCode executeForAlarmFilter(final DlmsConnectionManager conn, final AttributeAddress alarmFilterAttributeAddress, final AlarmNotificationsDto alarmNotifications, final DlmsObjectType alarmRegisterDlmsObjectType) throws ProtocolAdapterException {
try {
final AlarmNotificationsDto alarmNotificationsOnDevice = this.retrieveCurrentAlarmNotifications(conn, alarmFilterAttributeAddress, alarmRegisterDlmsObjectType);
LOGGER.info("Alarm Filter on device before setting notifications: {}", alarmNotificationsOnDevice);
final Set<AlarmTypeDto> alarmTypesForRegister = this.alarmHelperService.alarmTypesForRegister(alarmRegisterDlmsObjectType);
final Set<AlarmNotificationDto> alarmNotificationsSet = alarmNotifications.getAlarmNotificationsSet().stream().filter(alarmNotificationDto -> alarmTypesForRegister.contains(alarmNotificationDto.getAlarmType())).collect(Collectors.toSet());
final long alarmFilterLongValueOnDevice = this.alarmFilterLongValue(alarmNotificationsOnDevice);
final long updatedAlarmFilterLongValue = this.calculateAlarmFilterLongValue(alarmNotificationsOnDevice, alarmNotificationsSet);
if (alarmFilterLongValueOnDevice == updatedAlarmFilterLongValue) {
return AccessResultCode.SUCCESS;
}
LOGGER.info("Modified Alarm Filter long value for device: {}", updatedAlarmFilterLongValue);
return this.writeUpdatedAlarmNotifications(conn, updatedAlarmFilterLongValue, alarmFilterAttributeAddress);
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutor method execute.
@Override
public List<EventDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final FindEventsRequestDto findEventsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final SelectiveAccessDescription selectiveAccessDescription = this.getSelectiveAccessDescription(device, findEventsQuery.getFrom(), findEventsQuery.getUntil());
final DlmsObject eventLogObject = this.dlmsObjectConfigService.getDlmsObject(device, EVENT_LOG_CATEGORY_OBISCODE_MAP.get(findEventsQuery.getEventLogCategory()));
final AttributeAddress eventLogBuffer = new AttributeAddress(eventLogObject.getClassId(), eventLogObject.getObisCode(), eventLogObject.getDefaultAttributeId(), selectiveAccessDescription);
conn.getDlmsMessageListener().setDescription("RetrieveEvents for " + findEventsQuery.getEventLogCategory() + " from " + findEventsQuery.getFrom() + " until " + findEventsQuery.getUntil() + ", retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(eventLogBuffer));
final GetResult getResult;
try {
getResult = conn.getConnection().get(eventLogBuffer);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (getResult == null) {
throw new ProtocolAdapterException("No GetResult received while retrieving event register " + findEventsQuery.getEventLogCategory());
}
if (!AccessResultCode.SUCCESS.equals(getResult.getResultCode())) {
LOGGER.info("Result of getting events for {} is {}", findEventsQuery.getEventLogCategory(), getResult.getResultCode());
throw new ProtocolAdapterException("Getting the events for " + findEventsQuery.getEventLogCategory() + " from the meter resulted in: " + getResult.getResultCode());
}
final DataObject resultData = getResult.getResultData();
return this.dataObjectToEventListConverter.convert(resultData, findEventsQuery.getEventLogCategory());
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForIskraDevice.
@Test
void initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForIskraDevice() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("SMR").withInvocationCounter(123L).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
final ConnectionException exception = new ConnectionException("Error creating connection for device E0033006878667817 with Ip address:62.133.86.119 Port:4059 " + "UseHdlc:false UseSn:false Message:UNKNOWN: Received an association response (AARE) with an" + " error message. Result name REJECTED_PERMANENT. Assumed fault: user.");
doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
assertThrows(ConnectionException.class, () -> this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, null, this.task));
verify(this.invocationCounterManager).initializeInvocationCounter(this.messageMetadata, device);
verify(this.connectionFactory, times(2)).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
}
Aggregations