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