Search in sources :

Example 1 with DlmsServer

use of org.openmuc.jdlms.DlmsServer in project open-smart-grid-platform by OSGP.

the class DeviceServer method getDlmsServer.

public DlmsServer getDlmsServer(final String[] args) {
    final SpringApplication dlmsSimulator = new SpringApplication(DlmsServerConfig.class);
    dlmsSimulator.setWebApplicationType(WebApplicationType.NONE);
    final ApplicationContext ctx = dlmsSimulator.run(args);
    LOGGER.info("Starting server");
    // Retrieve bean so DlmsServer is created and started.
    final DlmsServer serverConnection = ctx.getBean(DlmsServer.class);
    LOGGER.info("Server is running", serverConnection);
    return serverConnection;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) DlmsServer(org.openmuc.jdlms.DlmsServer) SpringApplication(org.springframework.boot.SpringApplication)

Example 2 with DlmsServer

use of org.openmuc.jdlms.DlmsServer in project open-smart-grid-platform by OSGP.

the class SimulatorThread method run.

/**
 * Start running a thread that starts a device simulator, waits for three minutes and then closes
 * that simulator.
 */
@Override
public void run() {
    final String[] arguments = this.configureSimulatorArguments(this.port, this.logicalId);
    final DlmsServer dlmsServer = new DeviceServer().getDlmsServer(arguments);
    try {
        this.checkStartUp(this.port);
        Thread.sleep(SIMULATOR_DELAY);
    } catch (final InterruptedException e) {
        LOGGER.warn("SimulatorThread was interrupted.", e);
    }
    try {
        dlmsServer.close();
        if (this.unregisterPort(this.port)) {
            LOGGER.info("Successfully closed DlmsServer, port {} is free for future use.", this.port);
        }
    } catch (final IOException e) {
        LOGGER.warn("Failed to close DlmsServer on port {}", this.port, e);
    }
}
Also used : DlmsServer(org.openmuc.jdlms.DlmsServer) IOException(java.io.IOException) DeviceServer(org.opensmartgridplatform.simulator.protocol.dlms.server.DeviceServer)

Example 3 with DlmsServer

use of org.openmuc.jdlms.DlmsServer in project open-smart-grid-platform by OSGP.

the class DlmsServerConfig method dlmsServer.

@Bean
public DlmsServer dlmsServer(final OsgpServerConnectionListener osgpServerConnectionListener) throws IOException {
    final DlmsServer serverConnection;
    TcpServerBuilder serverBuilder = DlmsServer.tcpServerBuilder(this.port);
    if (this.useHdlc) {
        serverBuilder = serverBuilder.setSessionLayerFactory(ServerSessionLayerFactories.newHdlcSessionLayerFactory());
    }
    serverBuilder = serverBuilder.setConnectionListener(osgpServerConnectionListener);
    for (final Integer logicalDeviceId : LogicalDeviceIdsConverter.convert(this.logicalDeviceIds)) {
        LOGGER.info("preparing logical device {} on port {}", logicalDeviceId, this.port);
        final LogicalDevice logdev = this.buildDevice(logicalDeviceId).build();
        serverBuilder = serverBuilder.registerLogicalDevice(logdev).setReferencingMethod(ReferencingMethod.valueOf(this.referencingMethod.toUpperCase()));
    }
    serverConnection = serverBuilder.build();
    return serverConnection;
}
Also used : TcpServerBuilder(org.openmuc.jdlms.DlmsServer.TcpServerBuilder) DlmsServer(org.openmuc.jdlms.DlmsServer) LogicalDevice(org.openmuc.jdlms.LogicalDevice) Bean(org.springframework.context.annotation.Bean)

Aggregations

DlmsServer (org.openmuc.jdlms.DlmsServer)3 IOException (java.io.IOException)1 TcpServerBuilder (org.openmuc.jdlms.DlmsServer.TcpServerBuilder)1 LogicalDevice (org.openmuc.jdlms.LogicalDevice)1 DeviceServer (org.opensmartgridplatform.simulator.protocol.dlms.server.DeviceServer)1 SpringApplication (org.springframework.boot.SpringApplication)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1