Geräteerkennung ohne Datenverbindungen

This commit is contained in:
Dieter Lang 2026-08-11 13:26:05 +02:00
parent 084ca66c7b
commit a33546fbed
2 changed files with 55 additions and 28 deletions

View file

@ -1,12 +1,9 @@
/*
Package main implements the rs2322tcp server application.
The server will provide the network endpoint for rs2322tcp clients
and connect incoming connections to configured physical RS232
interfaces.
At this stage the application only provides the basic program
structure and version information.
The server provides the network endpoint for rs2322tcp clients
and connects incoming data connections to configured physical
RS232 interfaces.
Project: rs2322tcp
Module: git.lang-dieter.de/rs2322tcp
@ -14,11 +11,56 @@ Module: git.lang-dieter.de/rs2322tcp
package main
import (
"flag"
"fmt"
"log"
"git.lang-dieter.de/rs2322tcp/internal/config"
"git.lang-dieter.de/rs2322tcp/internal/server"
"git.lang-dieter.de/rs2322tcp/internal/version"
)
func main() {
fmt.Printf("rs2322tcp-server %s\n", version.Version)
configFile := flag.String(
"config",
"./configs/server.json",
"Pfad zur Server-Konfigurationsdatei",
)
flag.Parse()
cfg, err := config.LoadServer(*configFile)
if err != nil {
log.Fatalf("Server-Konfiguration laden: %v", err)
}
controlServer, err := server.NewControlServer(cfg)
if err != nil {
log.Fatalf("Control-Server erstellen: %v", err)
}
if err := controlServer.Listen(); err != nil {
log.Fatalf("Control-Server starten: %v", err)
}
defer controlServer.Close()
fmt.Printf(
"rs2322tcp-server %s\n",
version.Version,
)
fmt.Printf(
"Control-Server gestartet auf %s\n",
controlServer.Addr(),
)
fmt.Printf(
"Geräte: %d\n",
len(cfg.Devices),
)
if err := controlServer.Serve(); err != nil {
log.Fatalf("Control-Server beendet: %v", err)
}
}

View file

@ -94,14 +94,14 @@ func NewApplication(configFile string) (*Application, error) {
// Start
///////////////////////////////////////////////////////////////////////////////
// Start loads the client configuration, connects to the server and starts
// the client Runtime.
// Start loads the client configuration and connects to the server.
//
// Start is intended for the initial application startup. An already running
// application must be stopped first by calling Close or Reconnect.
//
// The Runtime runs asynchronously because it waits for the configured
// bridges while the GUI must remain responsive.
// The server device list is retrieved during startup. The client Runtime is
// not started here; data connections are established separately when the
// runtime is explicitly started.
func (a *Application) Start() error {
if a == nil {
return fmt.Errorf("application is nil")
@ -140,32 +140,17 @@ func (a *Application) Start() error {
return fmt.Errorf("get remote devices: %w", err)
}
manager := NewVirtualPortManager(cfg.VirtualPortRange)
runtime, err := NewRuntime(client, manager)
if err != nil {
_ = client.Close()
return fmt.Errorf("create client runtime: %w", err)
}
runtimeDone := make(chan error, 1)
a.mu.Lock()
a.config = cfg
a.client = client
a.runtime = runtime
a.runtime = nil
a.devices = append(
[]transport.RemoteDeviceInfo(nil),
devices...,
)
a.runtimeDone = runtimeDone
a.runtimeDone = nil
a.mu.Unlock()
go func() {
runtimeDone <- runtime.Run(*cfg)
}()
return nil
}