missing error handling added
This commit is contained in:
90
main.go
90
main.go
@@ -28,18 +28,17 @@ const (
|
||||
)
|
||||
|
||||
type TCPServer struct {
|
||||
Protocol chan string
|
||||
ToPactor *ByteFIFO // used for the TUI
|
||||
FromPactor *ByteFIFO // used for the TUI
|
||||
ToTRX *ByteFIFO // TRX remote control
|
||||
FromTRX *ByteFIFO // TRX remove control
|
||||
VARAMode bool
|
||||
DaemonMode bool
|
||||
GPSdMode bool
|
||||
NMEAPassthrough bool
|
||||
DeviceType string
|
||||
Status uint8
|
||||
Command struct {
|
||||
Protocol chan string
|
||||
ToPactor *ByteFIFO // used for the TUI
|
||||
FromPactor *ByteFIFO // used for the TUI
|
||||
ToTRX *ByteFIFO // TRX remote control
|
||||
FromTRX *ByteFIFO // TRX remove control
|
||||
Userconfig *Userconfig
|
||||
VARAMode bool
|
||||
DaemonMode bool
|
||||
DeviceType string
|
||||
Status uint8
|
||||
Command struct {
|
||||
Cmd *StringFIFO
|
||||
Response *StringFIFO
|
||||
}
|
||||
@@ -50,31 +49,6 @@ type TCPServer struct {
|
||||
GPSStream *StringFIFO // NMEA steam from PTC to gpsd server, see gpsd.go
|
||||
}
|
||||
|
||||
func NewTCPServer(varamode bool, daemonmode bool, gpsdmode bool, nmeapassthrough bool) *TCPServer {
|
||||
return &TCPServer{
|
||||
Protocol: make(chan string, 1024),
|
||||
ToPactor: NewByteFIFO(1024),
|
||||
FromPactor: NewByteFIFO(1024),
|
||||
ToTRX: NewByteFIFO(1024),
|
||||
FromTRX: NewByteFIFO(1024),
|
||||
VARAMode: varamode,
|
||||
DaemonMode: daemonmode,
|
||||
GPSdMode: gpsdmode,
|
||||
NMEAPassthrough: nmeapassthrough,
|
||||
DeviceType: "",
|
||||
Status: 0,
|
||||
Command: struct {
|
||||
Cmd *StringFIFO
|
||||
Response *StringFIFO
|
||||
}{Cmd: NewStringFIFO(), Response: NewStringFIFO()},
|
||||
Data: struct {
|
||||
Data *ByteFIFO
|
||||
Response *ByteFIFO
|
||||
}{Data: NewByteFIFO(10240), Response: NewByteFIFO(10240)},
|
||||
GPSStream: NewStringFIFO(),
|
||||
}
|
||||
}
|
||||
|
||||
type Userconfig struct {
|
||||
Device string `yaml:"device"`
|
||||
Baudrate int `yaml:"baudrate"`
|
||||
@@ -87,6 +61,30 @@ type Userconfig struct {
|
||||
StartwithVaraMode bool `yaml:"vara_mode"`
|
||||
}
|
||||
|
||||
func NewTCPServer(userconfig *Userconfig, daemonmode bool) *TCPServer {
|
||||
return &TCPServer{
|
||||
Protocol: make(chan string, 1024),
|
||||
ToPactor: NewByteFIFO(1024),
|
||||
FromPactor: NewByteFIFO(1024),
|
||||
ToTRX: NewByteFIFO(1024),
|
||||
FromTRX: NewByteFIFO(1024),
|
||||
Userconfig: userconfig,
|
||||
VARAMode: userconfig.StartwithVaraMode,
|
||||
DaemonMode: daemonmode,
|
||||
DeviceType: "",
|
||||
Status: 0,
|
||||
Command: struct {
|
||||
Cmd *StringFIFO
|
||||
Response *StringFIFO
|
||||
}{Cmd: NewStringFIFO(), Response: NewStringFIFO()},
|
||||
Data: struct {
|
||||
Data *ByteFIFO
|
||||
Response *ByteFIFO
|
||||
}{Data: NewByteFIFO(10240), Response: NewByteFIFO(10240)},
|
||||
GPSStream: NewStringFIFO(),
|
||||
}
|
||||
}
|
||||
|
||||
func configmanage(Config *Userconfig, path string) error {
|
||||
cf := store.GetApplicationDirPath() + string(os.PathSeparator) + path
|
||||
|
||||
@@ -151,7 +149,12 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
err := f.Close()
|
||||
if err != nil {
|
||||
writeDebug(err.Error(), 0)
|
||||
}
|
||||
}()
|
||||
|
||||
log.SetOutput(f)
|
||||
fmt.Println("logging to " + logfile)
|
||||
@@ -165,13 +168,18 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
s = NewTCPServer(Config.StartwithVaraMode, daemonMode, Config.GPSdAddress != "", Config.NMEAPassthrough)
|
||||
s = NewTCPServer(&Config, daemonMode)
|
||||
fmt.Println("Initializing PACTOR modem, please wait...")
|
||||
m, err := OpenModem(Config.Device, Config.Baudrate, Config.Mycall, "", Config.CmdLineInit)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
defer m.Close()
|
||||
defer func() {
|
||||
err := m.Close()
|
||||
if err != nil {
|
||||
writeDebug(err.Error(), 0)
|
||||
}
|
||||
}()
|
||||
|
||||
go tcpCmdServer(&Config)
|
||||
go tcpDataServer(&Config)
|
||||
@@ -203,7 +211,7 @@ func main() {
|
||||
log.Panicln(err)
|
||||
}
|
||||
// Start the main TUI loop
|
||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
|
||||
log.Panicln(err)
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user