2020-10-16 17:13:46 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-16 19:25:02 +02:00
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
2020-10-16 17:13:46 +02:00
|
|
|
|
|
|
|
|
"github.com/nonoo/kappanhang/log"
|
|
|
|
|
)
|
|
|
|
|
|
2020-10-18 10:33:47 +02:00
|
|
|
var streams struct {
|
|
|
|
|
control controlStream
|
2020-10-20 23:26:05 +02:00
|
|
|
serial serialStream
|
2020-10-18 10:33:47 +02:00
|
|
|
audio audioStream
|
2020-10-17 23:53:33 +02:00
|
|
|
}
|
2020-10-16 17:13:46 +02:00
|
|
|
|
2020-10-18 11:15:31 +02:00
|
|
|
func exit(err error) {
|
2020-10-18 13:19:52 +02:00
|
|
|
if err != nil {
|
|
|
|
|
log.Error(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 15:42:59 +02:00
|
|
|
streams.audio.common.close()
|
|
|
|
|
streams.serial.common.close()
|
|
|
|
|
streams.control.common.close()
|
2020-10-21 09:26:21 +02:00
|
|
|
serialPort.deinit()
|
2020-10-20 15:23:12 +02:00
|
|
|
audio.deinit()
|
2020-10-20 08:47:42 +02:00
|
|
|
|
2020-10-19 09:53:49 +02:00
|
|
|
log.Print("exiting")
|
2020-10-18 11:15:31 +02:00
|
|
|
if err == nil {
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
} else {
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 19:25:02 +02:00
|
|
|
func setupCloseHandler() {
|
|
|
|
|
c := make(chan os.Signal)
|
|
|
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
go func() {
|
|
|
|
|
<-c
|
2020-10-18 11:15:31 +02:00
|
|
|
exit(nil)
|
2020-10-16 19:25:02 +02:00
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 17:13:46 +02:00
|
|
|
func main() {
|
|
|
|
|
log.Init()
|
2020-10-20 23:30:23 +02:00
|
|
|
log.Print("kappanhang by Norbert Varga HA2NON and Akos Marton ES1AKOS https://github.com/nonoo/kappanhang")
|
2020-10-16 17:13:46 +02:00
|
|
|
parseArgs()
|
2020-10-20 08:47:42 +02:00
|
|
|
|
2020-10-21 09:26:21 +02:00
|
|
|
serialPort.init()
|
2020-10-18 18:34:22 +02:00
|
|
|
streams.audio.init()
|
2020-10-20 23:26:05 +02:00
|
|
|
streams.serial.init()
|
2020-10-18 18:34:22 +02:00
|
|
|
streams.control.init()
|
|
|
|
|
|
2020-10-20 08:49:17 +02:00
|
|
|
setupCloseHandler()
|
|
|
|
|
|
2020-10-18 12:50:09 +02:00
|
|
|
streams.control.start()
|
2020-10-16 17:13:46 +02:00
|
|
|
}
|