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());
}
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);
}
}
}
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;
}
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);
}
}
Aggregations