Search in sources :

Example 1 with SclParseException

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

the class RtuSimulatorConfig method rtuSimulator.

@Bean
public RtuSimulator rtuSimulator(@Value("${rtu.icd:Pampus_v0.4.5.icd}") final String icdFilename, @Value("${rtu.port:60102}") final Integer port, @Value("${rtu.serverName:WAGO61850Server}") final String serverName, @Value("${rtu.stopGeneratingValues:false}") final Boolean stopGeneratingValues) throws IOException {
    final InputStream icdFile = resourceLoader.getResource("classpath:" + icdFilename).getInputStream();
    try {
        final RtuSimulator rtuSimulator = new RtuSimulator(port, icdFile, serverName);
        if (stopGeneratingValues) {
            rtuSimulator.ensurePeriodicDataGenerationIsStopped();
        }
        rtuSimulator.start();
        return rtuSimulator;
    } catch (final SclParseException e) {
        LOGGER.warn("Error parsing SCL/ICD file {}", e);
    } finally {
        icdFile.close();
    }
    return null;
}
Also used : InputStream(java.io.InputStream) SclParseException(org.openmuc.openiec61850.SclParseException) Bean(org.springframework.context.annotation.Bean)

Example 2 with SclParseException

use of com.beanit.openiec61850.SclParseException in project open-smart-grid-platform by OSGP.

the class RtuSimulatorConfig method rtuSimulator.

@Bean
@SuppressWarnings(// Large number of parameters is preferable over the alternatives.
"squid:S00107")
public RtuSimulator rtuSimulator(@Value("${rtu.icd}") final String icdFilename, @Value("${rtu.port}") final Integer port, @Value("${rtu.serverName}") final String serverName, @Value("${rtu.stopGeneratingValues}") final Boolean stopGeneratingValues, @Value("${rtu.updateValuesDelay}") final Long updateValuesDelay, @Value("${rtu.updateValuesPeriod}") final Long updateValuesPeriod, final ResourceLoader resourceLoader, final ServerSapEventProducer serverSapEventProducer) throws IOException {
    LOGGER.info("Start simulator with icdFilename={}, port={}, serverName={}, stopGeneratingValues={}, updateValuesDelay={}, updateValuesPeriod={}", icdFilename, port, serverName, stopGeneratingValues, updateValuesDelay, updateValuesPeriod);
    final InputStream icdInputStream;
    final File icdFile = new File(icdFilename);
    if (icdFile.exists()) {
        LOGGER.info("Simulator icd {} found as external file", icdFilename);
        icdInputStream = resourceLoader.getResource("file:" + icdFilename).getInputStream();
    } else {
        LOGGER.info("Simulator icd {} not found as external file, load it from the classpath", icdFilename);
        icdInputStream = resourceLoader.getResource("classpath:" + icdFilename).getInputStream();
    }
    LOGGER.info("Simulator icd file loaded");
    try {
        final RtuSimulator rtuSimulator = new RtuSimulator(port, icdInputStream, serverName, serverSapEventProducer, updateValuesDelay, updateValuesPeriod);
        if (Boolean.TRUE.equals(stopGeneratingValues)) {
            rtuSimulator.ensurePeriodicDataGenerationIsStopped();
        }
        rtuSimulator.start();
        return rtuSimulator;
    } catch (final SclParseException e) {
        LOGGER.warn("Error parsing SCL/ICD file", e);
    } finally {
        icdInputStream.close();
    }
    return null;
}
Also used : InputStream(java.io.InputStream) SclParseException(com.beanit.openiec61850.SclParseException) File(java.io.File) Bean(org.springframework.context.annotation.Bean)

Example 3 with SclParseException

use of com.beanit.openiec61850.SclParseException in project open-smart-grid-platform by OSGP.

the class Iec61850Client method readServerModelFromSclFile.

/**
 * Use an ICD file (model file) to read the device model.
 *
 * @param clientAssociation Instance of {@link ClientAssociation}
 * @param filePath "../sampleServer/sampleModel.icd"
 * @return Instance of {@link ServerModel}
 * @throws ProtocolAdapterException In case the file path is empty.
 */
public ServerModel readServerModelFromSclFile(final ClientAssociation clientAssociation, final String filePath) throws ProtocolAdapterException {
    if (StringUtils.isEmpty(filePath)) {
        throw new ProtocolAdapterException("File path is empty");
    }
    try {
        final ServerModel serverModel = SclParser.parse(filePath).get(0);
        clientAssociation.setServerModel(serverModel);
        return serverModel;
    } catch (final SclParseException e) {
        throw new ProtocolAdapterException("Error parsing SCL file: " + filePath, e);
    }
}
Also used : ServerModel(com.beanit.openiec61850.ServerModel) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) SclParseException(com.beanit.openiec61850.SclParseException)

Aggregations

SclParseException (com.beanit.openiec61850.SclParseException)2 InputStream (java.io.InputStream)2 Bean (org.springframework.context.annotation.Bean)2 ServerModel (com.beanit.openiec61850.ServerModel)1 File (java.io.File)1 SclParseException (org.openmuc.openiec61850.SclParseException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1