use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project open-smart-grid-platform by OSGP.
the class Iec61850EnableReportingCommand method enableReportingOnDevice.
/**
* Enable reporting so the device can send reports.
*
* @throws NodeException In case writing or reading of data-attributes fails.
*/
public void enableReportingOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeException {
final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.BR);
// Only reading the sequence number for the report node, as the report
// node is not fully described by the ServerModel when using an ICD
// file. Since the report node differs from the ServerModel, a full read
// of the node and all data-attributes will fail. Therefore, only the
// needed data-attributes are read.
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.SEQUENCE_NUMBER.getDescription()));
final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
final short sqNum = reporting.getUnsignedByte(SubDataAttribute.SEQUENCE_NUMBER).getValue();
reportListener.setSqNum(sqNum);
reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
LOGGER.info("Allowing device {} to send reports containing events", deviceConnection.getDeviceIdentification());
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project open-smart-grid-platform by OSGP.
the class Iec61850DeviceConnectionService method connect.
public DeviceConnection connect(final DeviceConnectionParameters deviceConnectionParameters, final String organisationIdentification, final boolean cacheConnection) throws ConnectionFailureException {
final String deviceIdentification = deviceConnectionParameters.getDeviceIdentification();
final String serverName = deviceConnectionParameters.getServerName();
final IED ied = deviceConnectionParameters.getIed();
// an usable for the given deviceIdentification.
try {
if (cacheConnection && this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, serverName, deviceConnectionParameters.getLogicalDevice())) {
return new DeviceConnection(this.fetchIec61850Connection(deviceIdentification), deviceIdentification, organisationIdentification, serverName);
}
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
final InetAddress inetAddress = this.convertIpAddress(deviceConnectionParameters.getIpAddress());
// Connect to obtain ClientAssociation and ServerModel.
LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}", deviceIdentification, deviceConnectionParameters.getIpAddress(), this.responseTimeout);
final DateTime startTime = DateTime.now();
// Create instance of appropriate event listener.
Iec61850ClientBaseEventListener eventListener = null;
try {
eventListener = this.iec61850ClientEventListenerFactory.getEventListener(ied, deviceIdentification, organisationIdentification);
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
final Iec61850Device iec61850Device = this.iec61850DeviceRepository.findByDeviceIdentification(deviceIdentification);
final int port = this.determinePortForIec61850Device(ied, iec61850Device);
// Try to connect and receive the ClientAssociation.
final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850Client.connect(deviceIdentification, inetAddress, eventListener, port);
final ClientAssociation clientAssociation = iec61850ClientAssociation.getClientAssociation();
// Set response time-out.
clientAssociation.setResponseTimeout(this.responseTimeout);
// Read the ServerModel, either from the device or from a SCL file.
ServerModel serverModel;
try {
serverModel = this.readServerModel(clientAssociation, deviceIdentification, iec61850Device);
} catch (final ProtocolAdapterException e) {
LOGGER.error("ProtocolAdapterException: unable to read ServerModel for deviceIdentification {}", deviceIdentification, e);
throw new ConnectionFailureException(e.getMessage(), e);
}
// Cache the connection.
final Iec61850Connection iec61850Connection = new Iec61850Connection(iec61850ClientAssociation, serverModel, startTime, ied);
if (cacheConnection) {
this.cacheIec61850Connection(deviceIdentification, iec61850Connection);
}
final DeviceConnection connection = new DeviceConnection(iec61850Connection, deviceIdentification, organisationIdentification, serverName);
final DateTime endTime = DateTime.now();
LOGGER.info("Connected to device: {}, fetched server model. Start time: {}, end time: {}, total time in milliseconds: {}", deviceIdentification, startTime, endTime, endTime.minus(startTime.getMillis()).getMillis());
this.iec61850RtuDeviceReportingService.enableReportingForDevice(connection, deviceIdentification, serverName);
return connection;
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project open-smart-grid-platform by OSGP.
the class Iec61850EnableReportingCommand method enableBufferedReportingOnDeviceWithoutUsingSequenceNumber.
/**
* Enable reporting so the SSLD can send reports. This version of the function does not use the
* 'sequence number' to filter incoming reports. When using the {@link Iec61850ClearReportCommand}
* the 'sequence number' will always be reset to 0.
*
* @throws NodeException In case writing of data-attributes fails.
*/
public void enableBufferedReportingOnDeviceWithoutUsingSequenceNumber(final DeviceConnection deviceConnection) throws NodeException {
final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.BR);
final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
reportListener.setSqNum(0);
reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
LOGGER.info("Allowing device {} to send buffered reports containing events", deviceConnection.getDeviceIdentification());
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project open-smart-grid-platform by OSGP.
the class Iec61850EnableReportingCommand method enableUnbufferedReportingOnLightMeasurementDevice.
public void enableUnbufferedReportingOnLightMeasurementDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeException {
final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LD0, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.RCB_A, Fc.RP);
// Read the reporting enabled boolean.
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.ENABLE_REPORTING.getDescription()));
final boolean reportingEnabled = reporting.getBoolean(SubDataAttribute.ENABLE_REPORTING).getValue();
LOGGER.info("reportingEnabled for unbuffered reports: {}", reportingEnabled);
if (reportingEnabled) {
LOGGER.info("Unbuffered reporting is already enabled for device: {}", deviceConnection.getDeviceIdentification());
return;
}
// Only reading the sequence number for the report node, as the report
// node is not fully described by the ServerModel when using an ICD
// file. Since the report node differs from the ServerModel, a full read
// of the node and all data-attributes will fail. Therefore, only the
// needed data-attributes are read.
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.SEQUENCE_NUMBER.getDescription()));
final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
final short sqNum = reporting.getUnsignedByte(SubDataAttribute.SEQUENCE_NUMBER).getValue();
reportListener.setSqNum(sqNum);
final String dataSetReference = reporting.getString(SubDataAttribute.DATA_SET);
LOGGER.info("dataSetReference for unbuffered reporting: {}", dataSetReference);
if (StringUtils.isEmpty(dataSetReference)) {
// Set data set reference.
reporting.writeString(SubDataAttribute.DATA_SET, this.getDataSetReferenceForLightMeasurementDevice());
reporting.writeString(SubDataAttribute.REPORT_ID, "A");
}
// Enable reporting.
reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
LOGGER.info("Allowing light measurement device {} to send unbuffered reports containing events", deviceConnection.getDeviceIdentification());
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project open-smart-grid-platform by OSGP.
the class Iec61850EnableReportingCommand method enableUnbufferedReportingOnDeviceWithoutUsingSequenceNumber.
public void enableUnbufferedReportingOnDeviceWithoutUsingSequenceNumber(final DeviceConnection deviceConnection) throws NodeException {
final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.RP);
final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
reportListener.setSqNum(0);
reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
LOGGER.info("Allowing device {} to send unbuffered reports containing events", deviceConnection.getDeviceIdentification());
}
Aggregations