Search in sources :

Example 1 with FcModelNode

use of com.beanit.openiec61850.FcModelNode in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850ClientSSLDEventListener method newReport.

@Override
public void newReport(final Report report) {
    final DateTime timeOfEntry = this.getTimeOfEntry(report);
    final String reportDescription = this.getReportDescription(report, timeOfEntry);
    this.logger.info("newReport for {}", reportDescription);
    boolean skipRecordBecauseOfOldSqNum = false;
    if (report.isBufOvfl()) {
        this.logger.warn("Buffer Overflow reported for {} - entries within the buffer may have been lost.", reportDescription);
    }
    if (this.firstNewSqNum != null && report.getSqNum() != null && report.getSqNum() < this.firstNewSqNum) {
        skipRecordBecauseOfOldSqNum = true;
    }
    this.logReportDetails(report);
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        this.logger.warn("No DataSet available for {}", reportDescription);
        return;
    }
    final List<FcModelNode> members = dataSet.getMembers();
    if (members == null || members.isEmpty()) {
        this.logger.warn("No members in DataSet available for {}", reportDescription);
        return;
    } else {
        this.logger.debug("Handling {} DataSet members for {}", members.size(), reportDescription);
    }
    for (final FcModelNode member : members) {
        if (member == null) {
            this.logger.warn("Member == null in DataSet for {}", reportDescription);
            continue;
        }
        this.logger.info("Handle member {} for {}", member.getReference(), reportDescription);
        try {
            if (skipRecordBecauseOfOldSqNum) {
                this.logger.warn("Skipping report because SqNum: {} is less than what should be the first new value: {}", report.getSqNum(), this.firstNewSqNum);
            } else {
                this.addEventNotificationForReportedData(member, timeOfEntry, reportDescription);
            }
        } catch (final Exception e) {
            this.logger.error("Error adding event notification for member {} from {}", member.getReference(), reportDescription, e);
        }
    }
}
Also used : DataSet(org.openmuc.openiec61850.DataSet) FcModelNode(org.openmuc.openiec61850.FcModelNode) BdaVisibleString(org.openmuc.openiec61850.BdaVisibleString) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 2 with FcModelNode

use of com.beanit.openiec61850.FcModelNode in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850ClientSSLDEventListener method logReportDetails.

private void logReportDetails(final Report report) {
    final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification).append(System.lineSeparator());
    sb.append("\t             RptId:\t").append(report.getRptId()).append(System.lineSeparator());
    sb.append("\t        DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
    sb.append("\t           ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
    sb.append("\t           BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
    sb.append("\t           EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
    sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString())).append(System.lineSeparator());
    sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
    sb.append("\t             SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
    sb.append("\t          SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
    sb.append("\t       TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
    if (report.getTimeOfEntry() != null) {
        sb.append("\t                   \t(").append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET)).append(')').append(System.lineSeparator());
    }
    final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
    if (reasonCodes != null && !reasonCodes.isEmpty()) {
        sb.append("\t       ReasonCodes:").append(System.lineSeparator());
        for (final BdaReasonForInclusion reasonCode : reasonCodes) {
            sb.append("\t                   \t").append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue()) : reasonCode).append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo()).append(')').append(System.lineSeparator());
        }
    }
    sb.append("\t           optFlds:").append(report.getOptFlds()).append("\t(").append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')').append(System.lineSeparator());
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        sb.append("\t           DataSet:\tnull").append(System.lineSeparator());
    } else {
        sb.append("\t           DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
        final List<FcModelNode> members = dataSet.getMembers();
        if (members != null && !members.isEmpty()) {
            sb.append("\t   DataSet members:\t").append(members.size()).append(System.lineSeparator());
            for (final FcModelNode member : members) {
                sb.append("\t            member:\t").append(member).append(System.lineSeparator());
                if (member.getReference().toString().contains("CSLC.EvnRpn")) {
                    sb.append(this.evnRpnInfo("\t                   \t\t", member));
                }
            }
        }
    }
    this.logger.info(sb.append(System.lineSeparator()).toString());
}
Also used : BdaReasonForInclusion(org.openmuc.openiec61850.BdaReasonForInclusion) DataSet(org.openmuc.openiec61850.DataSet) FcModelNode(org.openmuc.openiec61850.FcModelNode) Iec61850BdaOptFldsHelper(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850BdaOptFldsHelper) DateTime(org.joda.time.DateTime)

Example 3 with FcModelNode

use of com.beanit.openiec61850.FcModelNode in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850ClientRTUEventListener method logReportDetails.

private void logReportDetails(final Report report) {
    final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification).append(System.lineSeparator());
    sb.append("\t             RptId:\t").append(report.getRptId()).append(System.lineSeparator());
    sb.append("\t        DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
    sb.append("\t           ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
    sb.append("\t           BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
    sb.append("\t           EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
    sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString())).append(System.lineSeparator());
    sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
    sb.append("\t             SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
    sb.append("\t          SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
    sb.append("\t       TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
    if (report.getTimeOfEntry() != null) {
        sb.append("\t                   \t(").append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET)).append(')').append(System.lineSeparator());
    }
    final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
    if ((reasonCodes != null) && !reasonCodes.isEmpty()) {
        sb.append("\t       ReasonCodes:").append(System.lineSeparator());
        for (final BdaReasonForInclusion reasonCode : reasonCodes) {
            sb.append("\t                   \t").append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue()) : reasonCode).append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo()).append(')').append(System.lineSeparator());
        }
    }
    sb.append("\t           optFlds:").append(report.getOptFlds()).append("\t(").append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')').append(System.lineSeparator());
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        sb.append("\t           DataSet:\tnull").append(System.lineSeparator());
    } else {
        sb.append("\t           DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
        final List<FcModelNode> members = dataSet.getMembers();
        if ((members != null) && !members.isEmpty()) {
            sb.append("\t   DataSet members:\t").append(members.size()).append(System.lineSeparator());
            for (final FcModelNode member : members) {
                sb.append("\t            member:\t").append(member).append(System.lineSeparator());
                sb.append("\t                   \t\t").append(member);
            }
        }
    }
    this.logger.info(sb.append(System.lineSeparator()).toString());
}
Also used : BdaReasonForInclusion(org.openmuc.openiec61850.BdaReasonForInclusion) DataSet(org.openmuc.openiec61850.DataSet) FcModelNode(org.openmuc.openiec61850.FcModelNode) Iec61850BdaOptFldsHelper(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850BdaOptFldsHelper) DateTime(org.joda.time.DateTime)

Example 4 with FcModelNode

use of com.beanit.openiec61850.FcModelNode in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850ClientRTUEventListener method processReport.

private void processReport(final Report report, final String reportDescription, final Iec61850ReportHandler reportHandler) throws ProtocolAdapterException {
    if (report.getDataSet() == null) {
        this.logger.warn("No DataSet available for {}", reportDescription);
        return;
    }
    final List<FcModelNode> members = report.getDataSet().getMembers();
    if ((members == null) || members.isEmpty()) {
        this.logger.warn("No members in DataSet available for {}", reportDescription);
        return;
    }
    final List<MeasurementDto> measurements = new ArrayList<>();
    for (final FcModelNode member : members) {
        if (member == null) {
            this.logger.warn("Member == null in DataSet for {}", reportDescription);
            continue;
        }
        this.logger.info("Handle member {} for {}", member.getReference(), reportDescription);
        try {
            final MeasurementDto dto = reportHandler.handleMember(new ReadOnlyNodeContainer(this.deviceIdentification, member));
            if (dto != null) {
                measurements.add(dto);
            } else {
                this.logger.warn("Unsupprted member {}, skipping", member.getName());
            }
        } catch (final Exception e) {
            this.logger.error("Error adding event notification for member {} from {}", member.getReference(), reportDescription, e);
        }
    }
    final GetDataSystemIdentifierDto systemResult = reportHandler.createResult(measurements);
    final List<GetDataSystemIdentifierDto> systems = new ArrayList<>();
    systems.add(systemResult);
    final ReportDto reportDto = new ReportDto(report.getSqNum(), new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET), report.getRptId());
    this.deviceManagementService.sendMeasurements(this.deviceIdentification, new GetDataResponseDto(systems, reportDto));
}
Also used : GetDataResponseDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto) GetDataSystemIdentifierDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataSystemIdentifierDto) ArrayList(java.util.ArrayList) FcModelNode(org.openmuc.openiec61850.FcModelNode) ReportDto(com.alliander.osgp.dto.valueobjects.microgrids.ReportDto) ReadOnlyNodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.ReadOnlyNodeContainer) MeasurementDto(com.alliander.osgp.dto.valueobjects.microgrids.MeasurementDto) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) DateTime(org.joda.time.DateTime)

Example 5 with FcModelNode

use of com.beanit.openiec61850.FcModelNode in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850DeviceConnectionService method testIfConnectionIsCachedAndAlive.

private boolean testIfConnectionIsCachedAndAlive(final String deviceIdentification, final IED ied, final String serverName, final String logicalDevice) throws ProtocolAdapterException {
    try {
        LOGGER.info("Trying to find connection in cache for deviceIdentification: {}", deviceIdentification);
        final Iec61850Connection iec61850Connection = this.fetchIec61850Connection(deviceIdentification);
        if (iec61850Connection != null) {
            // Already connected, check if connection is still usable.
            LOGGER.info("Connection found for deviceIdentification: {}", deviceIdentification);
            // requires manual reads of remote data.
            if (ied != null && logicalDevice != null) {
                final String description = this.getActualServerName(ied, serverName);
                LOGGER.info("Testing if connection is alive using {}{}/{}.{} for deviceIdentification: {}", description, logicalDevice, LogicalNode.LOGICAL_NODE_ZERO.getDescription(), DataAttribute.NAME_PLATE.getDescription(), deviceIdentification);
                final FcModelNode modelNode = this.getModelNode(logicalDevice, iec61850Connection, description);
                this.iec61850Client.readNodeDataValues(iec61850Connection.getClientAssociation(), modelNode);
            } else {
                // Read all data values, which is much slower, but requires
                // no manual reads of remote data.
                LOGGER.info("Testing if connection is alive using readAllDataValues() for deviceIdentification: {}", deviceIdentification);
                this.iec61850Client.readAllDataValues(iec61850Connection.getClientAssociation());
            }
            LOGGER.info("Connection is still active for deviceIdentification: {}", deviceIdentification);
            return true;
        }
    } catch (final NodeReadException e) {
        LOGGER.error("Connection is no longer active, removing connection from cache for deviceIdentification: " + deviceIdentification, e);
        this.removeIec61850Connection(deviceIdentification);
    }
    return false;
}
Also used : Iec61850Connection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection) NodeReadException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException) FcModelNode(org.openmuc.openiec61850.FcModelNode)

Aggregations

FcModelNode (com.beanit.openiec61850.FcModelNode)13 DateTime (org.joda.time.DateTime)9 BdaVisibleString (com.beanit.openiec61850.BdaVisibleString)8 FcModelNode (org.openmuc.openiec61850.FcModelNode)7 BdaInt8U (com.beanit.openiec61850.BdaInt8U)6 ArrayList (java.util.ArrayList)5 BdaBoolean (com.beanit.openiec61850.BdaBoolean)4 BdaTimestamp (com.beanit.openiec61850.BdaTimestamp)4 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 DataSet (org.openmuc.openiec61850.DataSet)3 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)3 DataSampleDto (org.opensmartgridplatform.dto.da.iec61850.DataSampleDto)3 Iec61850BdaOptFldsHelper (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850BdaOptFldsHelper)2 BdaFloat32 (com.beanit.openiec61850.BdaFloat32)2 ObjectReference (com.beanit.openiec61850.ObjectReference)2 BigDecimal (java.math.BigDecimal)2 MathContext (java.math.MathContext)2 HashSet (java.util.HashSet)2