Geräteerkennung ohne Datenverbindungen
This commit is contained in:
parent
084ca66c7b
commit
a33546fbed
2 changed files with 55 additions and 28 deletions
|
|
@ -1,12 +1,9 @@
|
||||||
/*
|
/*
|
||||||
Package main implements the rs2322tcp server application.
|
Package main implements the rs2322tcp server application.
|
||||||
|
|
||||||
The server will provide the network endpoint for rs2322tcp clients
|
The server provides the network endpoint for rs2322tcp clients
|
||||||
and connect incoming connections to configured physical RS232
|
and connects incoming data connections to configured physical
|
||||||
interfaces.
|
RS232 interfaces.
|
||||||
|
|
||||||
At this stage the application only provides the basic program
|
|
||||||
structure and version information.
|
|
||||||
|
|
||||||
Project: rs2322tcp
|
Project: rs2322tcp
|
||||||
Module: git.lang-dieter.de/rs2322tcp
|
Module: git.lang-dieter.de/rs2322tcp
|
||||||
|
|
@ -14,11 +11,56 @@ Module: git.lang-dieter.de/rs2322tcp
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"git.lang-dieter.de/rs2322tcp/internal/config"
|
||||||
|
"git.lang-dieter.de/rs2322tcp/internal/server"
|
||||||
"git.lang-dieter.de/rs2322tcp/internal/version"
|
"git.lang-dieter.de/rs2322tcp/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,14 +94,14 @@ func NewApplication(configFile string) (*Application, error) {
|
||||||
// Start
|
// Start
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Start loads the client configuration, connects to the server and starts
|
// Start loads the client configuration and connects to the server.
|
||||||
// the client Runtime.
|
|
||||||
//
|
//
|
||||||
// Start is intended for the initial application startup. An already running
|
// Start is intended for the initial application startup. An already running
|
||||||
// application must be stopped first by calling Close or Reconnect.
|
// application must be stopped first by calling Close or Reconnect.
|
||||||
//
|
//
|
||||||
// The Runtime runs asynchronously because it waits for the configured
|
// The server device list is retrieved during startup. The client Runtime is
|
||||||
// bridges while the GUI must remain responsive.
|
// not started here; data connections are established separately when the
|
||||||
|
// runtime is explicitly started.
|
||||||
func (a *Application) Start() error {
|
func (a *Application) Start() error {
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return fmt.Errorf("application is nil")
|
return fmt.Errorf("application is nil")
|
||||||
|
|
@ -140,32 +140,17 @@ func (a *Application) Start() error {
|
||||||
return fmt.Errorf("get remote devices: %w", err)
|
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.mu.Lock()
|
||||||
a.config = cfg
|
a.config = cfg
|
||||||
a.client = client
|
a.client = client
|
||||||
a.runtime = runtime
|
a.runtime = nil
|
||||||
a.devices = append(
|
a.devices = append(
|
||||||
[]transport.RemoteDeviceInfo(nil),
|
[]transport.RemoteDeviceInfo(nil),
|
||||||
devices...,
|
devices...,
|
||||||
)
|
)
|
||||||
a.runtimeDone = runtimeDone
|
a.runtimeDone = nil
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
|
|
||||||
go func() {
|
|
||||||
runtimeDone <- runtime.Run(*cfg)
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue