Search in sources :

Example 1 with LightMeasurementDevice

use of org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method addEventNotifications.

/**
 * Send an event notification to OSGP Core.
 *
 * @param deviceIdentification The identification of the device.
 * @param eventNotifications The event notifications.
 * @throws ProtocolAdapterException In case the device can not be found in the database.
 */
@Transactional(value = "iec61850OsgpCoreDbApiTransactionManager", readOnly = true)
public void addEventNotifications(final String deviceIdentification, final List<EventNotificationDto> eventNotifications) throws ProtocolAdapterException {
    final Ssld ssldDevice = this.ssldDataRepository.findByDeviceIdentification(deviceIdentification);
    if (ssldDevice == null) {
        final LightMeasurementDevice lmd = this.lmdDataRepository.findByDeviceIdentification(deviceIdentification);
        if (lmd == null) {
            throw new ProtocolAdapterException("Unable to find device using deviceIdentification: " + deviceIdentification);
        }
    }
    LOGGER.info("addEventNotifications called for device {}: {}", deviceIdentification, eventNotifications);
    final RequestMessage requestMessage = new RequestMessage(NO_CORRELATION_UID, NO_ORGANISATION, deviceIdentification, new ArrayList<>(eventNotifications));
    this.osgpRequestMessageSender.send(requestMessage, MessageType.EVENT_NOTIFICATION.name());
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) Ssld(org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LightMeasurementDevice

use of org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class Iec61850ClientLMDEventListener 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);
    if (Boolean.TRUE.equals(report.getBufOvfl())) {
        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) {
        this.logger.warn("report.getSqNum() < this.firstNewSqNum, report.getSqNum() = {}, this.firstNewSqNum = {}", report.getSqNum(), this.firstNewSqNum);
    }
    this.logReportDetails(report);
    if (CollectionUtils.isEmpty(report.getValues())) {
        this.logger.warn("No dataSet members available for {}", reportDescription);
        return;
    }
    final Map<LightMeasurementDevice, FcModelNode> reportMemberPerDevice = this.processReportedDataForLightMeasurementDevices(report.getValues());
    for (final LightMeasurementDevice lmd : reportMemberPerDevice.keySet()) {
        final String deviceIdentification = lmd.getDeviceIdentification();
        final Short index = lmd.getDigitalInput();
        final FcModelNode member = reportMemberPerDevice.get(lmd);
        final EventNotificationDto eventNotification = this.getEventNotificationForReportedData(member, timeOfEntry, reportDescription, deviceIdentification, index.intValue());
        try {
            this.deviceManagementService.addEventNotifications(deviceIdentification, Arrays.asList(eventNotification));
        } catch (final ProtocolAdapterException pae) {
            this.logger.error("Error adding device notifications for device: " + deviceIdentification, pae);
        }
    }
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice) FcModelNode(com.beanit.openiec61850.FcModelNode) EventNotificationDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) DateTime(org.joda.time.DateTime)

Example 3 with LightMeasurementDevice

use of org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class Iec61850ClientLMDEventListener method processReportedDataForLightMeasurementDevices.

private Map<LightMeasurementDevice, FcModelNode> processReportedDataForLightMeasurementDevices(final List<FcModelNode> dataSetMembers) {
    final Map<LightMeasurementDevice, FcModelNode> result = new HashMap<>();
    this.logger.info("Trying to find light measurement devices...");
    final List<LightMeasurementDevice> lmds = this.deviceManagementService.findRealLightMeasurementDevices();
    this.logger.info("Found {} light measurement devices.", lmds == null ? "null" : lmds.size());
    for (final LightMeasurementDevice lmd : lmds) {
        final String nodeName = LogicalNode.getSpggioByIndex(lmd.getDigitalInput()).getDescription().concat(".");
        for (final FcModelNode member : dataSetMembers) {
            if (member.getReference().toString().contains(nodeName)) {
                result.put(lmd, member);
            }
        }
    }
    this.logger.info("Returning {} results.", result.size());
    return result;
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice) HashMap(java.util.HashMap) FcModelNode(com.beanit.openiec61850.FcModelNode)

Example 4 with LightMeasurementDevice

use of org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class Iec61850LmdDeviceService method getLightSensorStatus.

@Override
public void getLightSensorStatus(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection devCon = null;
    try {
        final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);
        devCon = deviceConnection;
        final LightMeasurementDevice lmd = this.lmdDataService.findDevice(deviceRequest.getDeviceIdentification());
        LOGGER.info("Iec61850LmdDeviceService.getLightSensorStatus() called for LMD: {}", lmd);
        final LightSensorStatusDto lightSensorStatus = new Iec61850GetLightSensorStatusCommand(this.deviceMessageLoggingService).getStatusFromDevice(this.iec61850Client, deviceConnection, lmd);
        final GetLightSensorStatusResponse lightSensorStatusResponse = new GetLightSensorStatusResponse(deviceRequest, lightSensorStatus);
        deviceResponseHandler.handleResponse(lightSensorStatusResponse);
        this.enableReporting(deviceConnection, deviceRequest);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
        this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
        this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
    }
}
Also used : Iec61850GetLightSensorStatusCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetLightSensorStatusCommand) LightMeasurementDevice(org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice) GetLightSensorStatusResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.lmd.GetLightSensorStatusResponse) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) LightSensorStatusDto(org.opensmartgridplatform.dto.valueobjects.LightSensorStatusDto) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) JMSException(javax.jms.JMSException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)

Aggregations

LightMeasurementDevice (org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice)4 FcModelNode (com.beanit.openiec61850.FcModelNode)2 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 HashMap (java.util.HashMap)1 JMSException (javax.jms.JMSException)1 DateTime (org.joda.time.DateTime)1 GetLightSensorStatusResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.lmd.GetLightSensorStatusResponse)1 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)1 Iec61850GetLightSensorStatusCommand (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetLightSensorStatusCommand)1 Ssld (org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld)1 EventNotificationDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationDto)1 LightSensorStatusDto (org.opensmartgridplatform.dto.valueobjects.LightSensorStatusDto)1 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)1 Transactional (org.springframework.transaction.annotation.Transactional)1