From 28b7f4df199dc9a4625cbfda78f2f2539e929283 Mon Sep 17 00:00:00 2001 From: Suvir Kumar Date: Fri, 22 Jan 2021 18:07:31 +0700 Subject: [PATCH] added repeater playing functionality --- client.go | 26 +++++++++++++------------- cmd/talkkonnect/main.go | 2 +- commandkeys.go | 20 +++++++++++++++++++- talkkonnect.go | 4 ++-- utils.go | 10 ++++++++++ xmlparser.go | 2 +- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/client.go b/client.go index 39915a7..e03f19c 100644 --- a/client.go +++ b/client.go @@ -68,7 +68,7 @@ var ( GPSLongitude float64 Streaming bool ServerHop bool - httpServRunning bool + HTTPServRunning bool message string isrepeattx bool = true NowStreaming bool @@ -119,7 +119,7 @@ type ChannelsListStruct struct { chanUsers int } -func PreInit0(file string, ServerIndex string) { +func Init(file string, ServerIndex string) { err := term.Init() if err != nil { log.Println("error: Cannot Initalize Terminal Error: ", err) @@ -208,10 +208,6 @@ func PreInit0(file string, ServerIndex string) { log.Printf("info: MQTT Server Subscription Diabled in Config") } - b.PreInit1(false) -} - -func (b *Talkkonnect) PreInit1(httpServRunning bool) { if len(b.Username) == 0 { buf := make([]byte, 6) _, err := rand.Read(buf) @@ -240,7 +236,7 @@ func (b *Talkkonnect) PreInit1(httpServRunning bool) { b.TLSConfig.Certificates = append(b.TLSConfig.Certificates, cert) } - if APIEnabled && !httpServRunning { + if APIEnabled && !HTTPServRunning { go func() { http.HandleFunc("/", b.httpAPI) @@ -251,7 +247,7 @@ func (b *Talkkonnect) PreInit1(httpServRunning bool) { }() } - b.Init() + b.ClientStart() IsConnected = false sigs := make(chan os.Signal, 1) @@ -263,12 +259,12 @@ func (b *Talkkonnect) PreInit1(httpServRunning bool) { os.Exit(exitStatus) } -func (b *Talkkonnect) Init() { +func (b *Talkkonnect) ClientStart() { f, err := os.OpenFile(LogFilenameAndPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) log.Println("info: Trying to Open File ", LogFilenameAndPath) if err != nil { log.Println("error: Problem opening talkkonnect.log file Error: ", err) - log.Fatal("Exiting talkkonnect! ...... bye!\n") + log.Fatal("Exiting talkkonnect! ...... Happy Talkkonnecting, Bye!\n") } if TargetBoard == "rpi" { @@ -511,6 +507,10 @@ keyPressListenerLoop: b.cmdConnNextServer() case term.KeyCtrlP: b.cmdPanicSimulation() + case term.KeyCtrlQ: + b.cmdPlayRepeaterTone() + time.Sleep(1 * time.Second) + b.cmdPlayRepeaterTone() case term.KeyCtrlR: b.cmdRepeatTxLoop() case term.KeyCtrlS: @@ -525,14 +525,14 @@ keyPressListenerLoop: b.cmdDumpXMLConfig() default: if ev.Ch != 0 { - log.Println("error: Invalid Keypress ASCII", ev.Ch) + log.Println("error: Invalid Keypress ASCII ", ev.Ch, "Press for Menu") } else { - log.Println("error: Key Not Mapped") + log.Println("error: Key Not Mapped, Press for menu") } } case term.EventError: log.Println("error: Terminal Error: ", ev.Err) - log.Fatal("Exiting talkkonnect! ...... bye!\n") + log.Fatal("Exiting talkkonnect!\n") } } diff --git a/cmd/talkkonnect/main.go b/cmd/talkkonnect/main.go index a882b4e..7b82873 100644 --- a/cmd/talkkonnect/main.go +++ b/cmd/talkkonnect/main.go @@ -75,7 +75,7 @@ func main() { f.Close() } - talkkonnect.PreInit0(*config, *serverindex) + talkkonnect.Init(*config, *serverindex) diff --git a/commandkeys.go b/commandkeys.go index b8167e5..dabc794 100644 --- a/commandkeys.go +++ b/commandkeys.go @@ -566,7 +566,7 @@ func (b *Talkkonnect) cmdPingServers() { func (b *Talkkonnect) cmdConnNextServer() { log.Println("debug: Ctrl-N Pressed") - log.Println("info: Next Server Requested") + log.Println("info: Next Server Requested Killing This Session, talkkonnect should be restarted by systemd") if TTSEnabled && TTSNextServer { err := PlayWavLocal(TTSNextServerFilenameAndPath, TTSVolumeLevel) @@ -821,3 +821,21 @@ func (b *Talkkonnect) cmdDumpXMLConfig() { printxmlconfig() } + +func (b *Talkkonnect) cmdPlayRepeaterTone() { + log.Println("debug: Ctrl-Q Pressed") + log.Println("info: Play Repeater Tone File into Stream") + + b.BackLightTimer() + + if b.IsTransmitting { + log.Println("alert: talkkonnect was already transmitting will now stop transmitting and start to play the repeater tone") + b.TransmitStop(false) + } + + go b.playIntoStream(RepeaterToneFilenameAndPath, RepeaterToneVolume) + + IsPlayStream = !IsPlayStream +// NowStreaming = IsPlayStream + +} diff --git a/talkkonnect.go b/talkkonnect.go index 29bfbb2..2e53ca7 100644 --- a/talkkonnect.go +++ b/talkkonnect.go @@ -96,7 +96,7 @@ func (b *Talkkonnect) talkkonnectMenu(backgroundcolor string) { log.Println("info: " + backgroundcolor + "│ Debug Stacktrace │ │" + backgroundreset) log.Println("info: " + backgroundcolor + "│ Send Email │ Conn Next Server │" + backgroundreset) log.Println("info: " + backgroundcolor + "│ Conn Previous Server│ Panic Simulation │" + backgroundreset) - log.Println("info: " + backgroundcolor + "│ Reserved │ Scan Channels │" + backgroundreset) + log.Println("info: " + backgroundcolor + "│ Send Repeater Tone │ Scan Channels │" + backgroundreset) log.Println("info: " + backgroundcolor + "│ Display Version │ Thanks/Acknowledgements│" + backgroundreset) log.Println("info: " + backgroundcolor + "├─────────────────────────────┼────────────────────────────────┤" + backgroundreset) log.Println("info: " + backgroundcolor + "│ Clear Screen │ Ping Servers │" + backgroundreset) @@ -111,7 +111,7 @@ func (b *Talkkonnect) talkkonnectMenu(backgroundcolor string) { log.Println("info: IP Address & Session Information") b.pingconnectedserver() localAddresses() - + log.Println("info: Internet WAN IP Is", GetOutboundIP()) origMuted, _ := volume.GetMuted(OutputDevice) if origMuted { log.Println("info: Speaker Currently Muted") diff --git a/utils.go b/utils.go index 44894e8..6ff2da4 100644 --- a/utils.go +++ b/utils.go @@ -36,6 +36,7 @@ import ( "errors" "flag" "fmt" + "github.com/glendc/go-external-ip" "github.com/kennygrant/sanitize" "github.com/talkkonnect/gumble/gumble" term "github.com/talkkonnect/termbox-go" @@ -556,3 +557,12 @@ func getMacAddr() ([]string, error) { } return as, nil } + +func GetOutboundIP() string { + consensus := externalip.DefaultConsensus(nil, nil) + ip, err := consensus.ExternalIP() + if err == nil { + return ip.String() + } + return "Could Not Get Public WAN IP" +} diff --git a/xmlparser.go b/xmlparser.go index f379801..7bf4c46 100644 --- a/xmlparser.go +++ b/xmlparser.go @@ -51,7 +51,7 @@ import ( //version and release date const ( - talkkonnectVersion string = "1.56.04" + talkkonnectVersion string = "1.56.05" talkkonnectReleased string = "January 22 2021" )