Skip to content

Commit

Permalink
added channel up and down to sa818
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Jan 29, 2022
1 parent eb5107d commit b98f15a
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 46 deletions.
9 changes: 7 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ func (b *Talkkonnect) ClientStart() {
if !(Config.Global.Hardware.Radio.Sa818.Enabled && Config.Global.Hardware.Radio.Sa818.Serial.Enabled) {
log.Println("error: Radio Module Not Configured Properly")
} else {
createEnabledRadioChannels()
go radioSetup()
}
}
Expand Down Expand Up @@ -572,10 +573,12 @@ keyPressListenerLoop:
b.cmdAudioMicTrafficRecord()
case term.KeyCtrlL:
b.cmdClearScreen()
case term.KeyCtrlM:
b.cmdRadioChannelMove("Up")
case term.KeyCtrlN:
b.cmdRadioChannelMove("Down")
case term.KeyCtrlO:
b.cmdPingServers()
case term.KeyCtrlN:
b.cmdConnNextServer()
case term.KeyCtrlP:
b.cmdPanicSimulation()
case term.KeyCtrlG:
Expand All @@ -592,6 +595,8 @@ keyPressListenerLoop:
b.cmdDisplayVersion()
case term.KeyCtrlX:
b.cmdDumpXMLConfig()
case term.KeyCtrlZ:
b.cmdConnNextServer()
default:
if _, ok := TTYKeyMap[ev.Ch]; ok {
switch strings.ToLower(TTYKeyMap[ev.Ch].Command) {
Expand Down
18 changes: 18 additions & 0 deletions commandkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,24 @@ func (b *Talkkonnect) cmdClearScreen() {
}
}

func (b *Talkkonnect) cmdRadioChannelMove(command string) {
log.Printf("debug: Ctrl-M Radio Channel %v\n", command)
if Config.Global.Hardware.TargetBoard == "rpi" {
if Config.Global.Hardware.Radio.Enabled {
if !(Config.Global.Hardware.Radio.Sa818.Enabled && Config.Global.Hardware.Radio.Sa818.Serial.Enabled) {
log.Println("error: Radio Module Not Configured Properly")
} else {
if command == "Up" {
go radioChannelChange("up")
}
if command == "Down" {
go radioChannelChange("down")
}
}
}
}
}

func (b *Talkkonnect) cmdPingServers() {
log.Printf("debug: Ctrl-O Pressed \n")
log.Println("info: Ping Servers")
Expand Down
95 changes: 80 additions & 15 deletions radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import (
"github.com/talkkonnect/sa818"
)

var CurrentChannelIndex = 0
var MoveChannelIndex = 0
var EnabledChannelCounter = 0

func radioSetup() {
DMOSetup.SerialOptions.PortName = Config.Global.Hardware.Radio.Sa818.Serial.Port
DMOSetup.SerialOptions.BaudRate = Config.Global.Hardware.Radio.Sa818.Serial.Baud
Expand All @@ -46,8 +50,63 @@ func radioSetup() {
RadioModuleSA818Channel(Config.Global.Hardware.Radio.ConnectChannelID)
}

func radioChannelChange(command string) {
DMOSetup.SerialOptions.PortName = Config.Global.Hardware.Radio.Sa818.Serial.Port
DMOSetup.SerialOptions.BaudRate = Config.Global.Hardware.Radio.Sa818.Serial.Baud
DMOSetup.SerialOptions.DataBits = Config.Global.Hardware.Radio.Sa818.Serial.Databits
DMOSetup.SerialOptions.StopBits = Config.Global.Hardware.Radio.Sa818.Serial.Stopbits
DMOSetup.SerialOptions.MinimumReadSize = 2
DMOSetup.SerialOptions.InterCharacterTimeout = 200

if command == "up" {
if len(radioChannels)-1 < CurrentChannelIndex+1 {
MoveChannelIndex = 0
CurrentChannelIndex = 0
log.Printf("info: Moving %v To Channel ID %v Name %v\n", command, radioChannels[MoveChannelIndex].ID, radioChannels[MoveChannelIndex].Name)
RadioModuleSA818Channel(radioChannels[MoveChannelIndex].ID)
return
}
if len(radioChannels)-1 >= CurrentChannelIndex+1 {
MoveChannelIndex = CurrentChannelIndex + 1
CurrentChannelIndex++
log.Printf("info: Moving %v To Channel ID %v Name %v\n", command, radioChannels[MoveChannelIndex].ID, radioChannels[MoveChannelIndex].Name)
RadioModuleSA818Channel(radioChannels[MoveChannelIndex].ID)
return
}
}

if command == "down" {
if CurrentChannelIndex-1 < 0 {
MoveChannelIndex = len(radioChannels) - 1
CurrentChannelIndex = len(radioChannels) - 1
log.Printf("info: Moving %v To Channel ID %v Name %v\n", command, radioChannels[MoveChannelIndex].ID, radioChannels[MoveChannelIndex].Name)
RadioModuleSA818Channel(radioChannels[MoveChannelIndex].ID)
return
}
if CurrentChannelIndex-1 >= 0 {
MoveChannelIndex = CurrentChannelIndex - 1
CurrentChannelIndex--
log.Printf("info: Moving %v To Channel ID %v Name %v\n", command, radioChannels[MoveChannelIndex].ID, radioChannels[MoveChannelIndex].Name)
RadioModuleSA818Channel(radioChannels[MoveChannelIndex].ID)
return
}
}
}

func createEnabledRadioChannels() {
for _, channel := range Config.Global.Hardware.Radio.Sa818.Channels.Channel {
if channel.Enabled {
EnabledChannelCounter++
if channel.ID == Config.Global.Hardware.Radio.ConnectChannelID {
CurrentChannelIndex = EnabledChannelCounter - 1
}
radioChannels = append(radioChannels, radioChannelsStruct{channel.ID, channel.Name, channel.ItemInList, channel.Bandwidth, channel.Rxfreq, channel.Txfreq, channel.Squelch, channel.Ctcsstone, channel.Dcstone, channel.Predeemph, channel.Highpass, channel.Lowpass, channel.Volume})
}
}
}

func RadioModuleSA818Channel(useChannelID string) {
found, name := findChannelByID(useChannelID)
found, name := findChannelNameByID(useChannelID)
if found {
log.Printf("info: Found Channel ID %v Name %v\n", useChannelID, name)
setFrequency()
Expand All @@ -56,20 +115,25 @@ func RadioModuleSA818Channel(useChannelID string) {
}
}

func findChannelByID(findChannelID string) (bool, string) {
for _, channel := range Config.Global.Hardware.Radio.Sa818.Channels.Channel {
if channel.ID == findChannelID && channel.Enabled {
DMOSetup.Band = channel.Bandwidth
DMOSetup.Rxfreq = channel.Rxfreq
DMOSetup.Txfreq = channel.Txfreq
DMOSetup.Ctsstone = channel.Ctcsstone
DMOSetup.Squelch = channel.Squelch
DMOSetup.Dcstone = channel.Dcstone
DMOSetup.Predeemph = channel.Predeemph
DMOSetup.Highpass = channel.Highpass
DMOSetup.Lowpass = channel.Lowpass
DMOSetup.Volume = channel.Volume
return true, channel.Name
func findChannelNameByID(findChannelID string) (bool, string) {
var EnabledItemInList int = 0
for Item, channel := range Config.Global.Hardware.Radio.Sa818.Channels.Channel {
if channel.Enabled {
EnabledItemInList++
Config.Global.Hardware.Radio.Sa818.Channels.Channel[Item].ItemInList = EnabledItemInList
if channel.ID == findChannelID {
DMOSetup.Band = channel.Bandwidth
DMOSetup.Rxfreq = channel.Rxfreq
DMOSetup.Txfreq = channel.Txfreq
DMOSetup.Ctsstone = channel.Ctcsstone
DMOSetup.Squelch = channel.Squelch
DMOSetup.Dcstone = channel.Dcstone
DMOSetup.Predeemph = channel.Predeemph
DMOSetup.Highpass = channel.Highpass
DMOSetup.Lowpass = channel.Lowpass
DMOSetup.Volume = channel.Volume
return true, channel.Name
}
}
}
return false, "not found channel"
Expand All @@ -87,6 +151,7 @@ func checkRSSI() {

func setFrequency() {
err := sa818.Callsa818("DMOSetupGroup", DMOSetup)
log.Printf("debug: actual data sent to module %#v", DMOSetup)
if err != nil {
log.Println("info: SAModule Set Frequecy Error ", err)
} else {
Expand Down
24 changes: 11 additions & 13 deletions talkkonnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,22 @@ func (b *Talkkonnect) talkkonnectMenu(backgroundcolor string) {
log.Println("info: " + backgroundcolor + "│ <F9> Stop Transmitting │ <F10> List Online Users │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│ <F11> Playback/Stop Stream │ <F12> For GPS Position │" + backgroundreset)
log.Println("info: " + backgroundcolor + "├─────────────────────────────┼────────────────────────────────┤" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-B> Reload XML Config │ <Ctrl-D> Debug Stacktrace │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-H> Check XML Config │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-B> Reload XML Config │ <Ctrl-C> Stop Talkkonnect │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-D> Debug Stacktrace │ <Ctrl-E> Send Email │" + backgroundreset)
log.Println("info: " + backgroundcolor + "├─────────────────────────────┼────────────────────────────────┤" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-E> Send Email │<Ctrl-N> Conn Next Server │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-F> Conn Previous Server│<Ctrl-P> Panic Simulation │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-G> Send Repeater Tone │<Ctrl-S> Scan Channels │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-V> Display Version │<Ctrl-T> Thanks/Acknowledgements│" + backgroundreset)
log.Println("info: " + backgroundcolor + "├─────────────────────────────┼────────────────────────────────┤" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-L> Clear Screen │<Ctrl-O> Ping Servers │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-R> Repeat TX Loop Test │<Ctrl-X> Dump XML Config │" + backgroundreset)
log.Println("info: " + backgroundcolor + "├─────────────────────────────┼────────────────────────────────┤" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-I> Traffic Record │<Ctrl-J> Mic Record │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-K> Traffic & Mic Record│<Ctrl-U> Show Uptime │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-F> Conn Previous Server│<Ctrl-G> Send Repeater Tone │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-H> XML Config Checker │<Ctrl-I> Traffic Record │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-J> Mic Record │<Ctrl-K> Traffic & Mic Record │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-L> Clear Screen │<Ctrl-M> Radio Channel (+) │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-N> Next Server │<Ctrl-O> Ping Servers │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-P> Panic Simulation │<Ctrl-R> Repeat TX Loop Test │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-S> Scan Channels │<Ctrl-T> Thanks/Acknowledgements│" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-U> Show Uptime │<Ctrl-V> Display Version │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│<Ctrl-X> Dump XML Config │ │" + backgroundreset)
log.Println("info: " + backgroundcolor + "├─────────────────────────────┼────────────────────────────────┤" + backgroundreset)
log.Println("info: " + backgroundcolor + "│ Visit us at www.talkkonnect.com and github.com/talkkonnect │" + backgroundreset)
log.Println("info: " + backgroundcolor + "│ Thanks to Global Coders Co., Ltd. for their sponsorship │" + backgroundreset)
log.Println("info: " + backgroundcolor + "└──────────────────────────────────────────────────────────────┘" + backgroundreset)

log.Println("info: IP Address & Session Information")
b.pingconnectedserver()
localAddresses()
Expand Down
6 changes: 3 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
package talkkonnect

const (
talkkonnectVersion string = "2.09.04"
talkkonnectReleased string = "Jan 28 2022"
talkkonnectVersion string = "2.09.05"
talkkonnectReleased string = "Jan 29 2022"
)

/* Release Notes
1. Fixed Broken Implementation of SA818 Causing talkkonnect not to compile
1. Added Channel Up and Down to SA818 from talkkonnect
*/
44 changes: 31 additions & 13 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,19 +477,20 @@ type ConfigStruct struct {
} `xml:"serial"`
Channels struct {
Channel []struct {
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
Enabled bool `xml:"enabled,attr"`
Bandwidth int `xml:"bandwidth"`
Rxfreq float32 `xml:"rxfreq"`
Txfreq float32 `xml:"txfreq"`
Squelch int `xml:"squelch"`
Ctcsstone int `xml:"ctcsstone"`
Dcstone int `xml:"dcstone"`
Predeemph int `xml:"predeemph"`
Highpass int `xml:"highpass"`
Lowpass int `xml:"lowpass"`
Volume int `xml:"volume"`
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
Enabled bool `xml:"enabled,attr"`
ItemInList int `xml:""`
Bandwidth int `xml:"bandwidth"`
Rxfreq float32 `xml:"rxfreq"`
Txfreq float32 `xml:"txfreq"`
Squelch int `xml:"squelch"`
Ctcsstone int `xml:"ctcsstone"`
Dcstone int `xml:"dcstone"`
Predeemph int `xml:"predeemph"`
Highpass int `xml:"highpass"`
Lowpass int `xml:"lowpass"`
Volume int `xml:"volume"`
} `xml:"channel"`
} `xml:"channels"`
} `xml:"sa818"`
Expand Down Expand Up @@ -595,9 +596,26 @@ type mqttPubButtonStruct struct {
Enabled bool
}

type radioChannelsStruct struct {
ID string
Name string
ItemInList int
Bandwidth int
Rxfreq float32
Txfreq float32
Squelch int
Ctcsstone int
Dcstone int
Predeemph int
Highpass int
Lowpass int
Volume int
}

// Generic Global Config Variables
var Config ConfigStruct
var ConfigXMLFile string
var radioChannels []radioChannelsStruct

// Generic Global State Variables
var (
Expand Down

0 comments on commit b98f15a

Please sign in to comment.