Skip to content

Commit

Permalink
api for voicetargets
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Aug 20, 2021
1 parent c80b7d2 commit 86466f5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 36 deletions.
92 changes: 58 additions & 34 deletions httpapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,208 +33,232 @@ import (
"fmt"
"log"
"net/http"
"strconv"
"strings"
)

func (b *Talkkonnect) httpAPI(w http.ResponseWriter, r *http.Request) {
commands, ok := r.URL.Query()["command"]
if !ok || len(commands[0]) < 1 {
log.Println("error: URL Param 'command' is missing example http api commands should be of the format http://a.b.c.d/?command=StartTransmitting")
fmt.Fprintf(w, "error: API should be of the format http://a.b.c.d:"+APIListenPort+"/?command=StartTransmitting\n")
Commands, ok := r.URL.Query()["command"]
if !ok || len(Commands) < 1 {
log.Println("error: URL Param 'command' is missing example http api commands should be of the format http://a.b.c.d/?command=starttransmitting")
fmt.Fprintf(w, "error: API should be of the format http://a.b.c.d:"+APIListenPort+"/?command=StartTransmitting or of the format http://a.b.c.d:"+APIListenPort+"?command=setvoicetarget&id=0\n")
return
}

command := commands[0]
log.Println("debug: http command " + string(command))
var Command string
var ID int
var err error

for key, values := range r.URL.Query() {
if strings.ToLower(key) == "command" {
Command = values[0]
}
if strings.ToLower(key) == "id" {
ID, err = strconv.Atoi(values[0])
if err != nil {
log.Println("error: Target ID is not Number")
fmt.Fprintf(w, "API VoiceTarget ID is not Number\n")
return
}
}
}

log.Println("debug: http command " + string(Command))
log.Println("debug: http parameters ", ID)

b.BackLightTimer()

switch string(command) {
case "DisplayMenu":
switch string(strings.ToLower(Command)) {
case "displaymenu":
if APIDisplayMenu {
b.cmdDisplayMenu()
fmt.Fprintf(w, "API Display Menu Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Display Menu Request Denied\n")
}
case "ChannelUp":
case "channelup":
if APIChannelUp {
b.cmdChannelUp()
fmt.Fprintf(w, "API Channel Up Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Channel Up Request Denied\n")
}
case "ChannelDown":
case "channeldown":
if APIChannelDown {
b.cmdChannelDown()
fmt.Fprintf(w, "API Channel Down Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Channel Down Request Denied\n")
}
case "Mute-Toggle":
case "mute-toggle":
if APIMute {
b.cmdMuteUnmute("toggle")
fmt.Fprintf(w, "API Mute/UnMute Speaker Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Mute/Unmute Speaker Request Denied\n")
}
case "Mute":
case "mute":
if APIMute {
b.cmdMuteUnmute("mute")
fmt.Fprintf(w, "API Mute/UnMute Speaker Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Mute/Unmute Speaker Request Denied\n")
}
case "Unmute":
case "unmute":
if APIMute {
b.cmdMuteUnmute("unmute")
fmt.Fprintf(w, "API Mute/UnMute Speaker Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Mute/Unmute Speaker Request Denied\n")
}
case "CurrentVolume":
case "currentvolume":
if APICurrentVolumeLevel {
b.cmdCurrentVolume()
fmt.Fprintf(w, "API Current Volume Level Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Current Volume Level Request Denied\n")
}
case "VolumeUp":
case "volumeup":
if APIDigitalVolumeUp {
b.cmdVolumeUp()
fmt.Fprintf(w, "API Digital Volume Up Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Digital Volume Up Request Denied\n")
}
case "VolumeDown":
case "volumedown":
if APIDigitalVolumeDown {
b.cmdVolumeDown()
fmt.Fprintf(w, "API Digital Volume Down Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Digital Volume Down Request Denied\n")
}
case "ListChannels":
case "listchannels":
if APIListServerChannels {
b.cmdListServerChannels()
fmt.Fprintf(w, "API List Server Channels Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API List Server Channels Request Denied\n")
}
case "StartTransmitting":
case "starttransmitting":
if APIStartTransmitting {
b.cmdStartTransmitting()
fmt.Fprintf(w, "API Start Transmitting Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Start Transmitting Request Denied\n")
}
case "StopTransmitting":
case "stoptransmitting":
if APIStopTransmitting {
b.cmdStopTransmitting()
fmt.Fprintf(w, "API Stop Transmitting Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Stop Transmitting Request Denied\n")
}
case "ListOnlineUsers":
case "listonlineusers":
if APIListOnlineUsers {
b.cmdListOnlineUsers()
fmt.Fprintf(w, "API List Online Users Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API List Online Users Request Denied\n")
}
case "Stream-Toggle":
case "stream-toggle":
if APIPlayStream {
b.cmdPlayback()
fmt.Fprintf(w, "API Play/Stop Stream Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Play/Stop Stream Request Denied\n")
}
case "GPSPosition":
case "gpsposition":
if APIRequestGpsPosition {
b.cmdGPSPosition()
fmt.Fprintf(w, "API Request GPS Position Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request GPS Position Denied\n")
}

case "SendEmail":
case "sendemail":
if APIEmailEnabled {
b.cmdSendEmail()
fmt.Fprintf(w, "API Send Email Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Send Email Config Denied\n")
}
case "ConnPreviousServer":
case "connpreviousserver":
if APINextServer {
b.cmdConnPreviousServer()
fmt.Fprintf(w, "API Previous Server Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Previous Server Denied\n")
}
case "ConnNextServer":
case "connnextserver":
if APINextServer {
b.cmdConnNextServer()
fmt.Fprintf(w, "API Next Server Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Next Server Denied\n")
}

case "ClearScreen":
case "clearscreen":
if APIClearScreen {
b.cmdClearScreen()
fmt.Fprintf(w, "API Clear Screen Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Clear Screen Denied\n")
}
case "PingServers":
case "pingservers":
if APIEmailEnabled {
b.cmdPingServers()
fmt.Fprintf(w, "API Ping Servers Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Ping Servers Denied\n")
}
case "PanicSimulation":
case "panicsimulation":
if APIPanicSimulation {
b.cmdPanicSimulation()
fmt.Fprintf(w, "API Request Panic Simulation Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Panic Simulation Denied\n")
}
case "RepeatTxLoop":
case "repeattxloop":
if APIRepeatTxLoopTest {
b.cmdRepeatTxLoop()
fmt.Fprintf(w, "API Request Repeat Tx Loop Test Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Repeat Tx Loop Test Denied\n")
}
case "ScanChannels":
case "scanchannels":
if APIScanChannels {
b.cmdScanChannels()
fmt.Fprintf(w, "API Request Scan Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Scan Denied\n")
}
case "Thanks":
case "thanks":
if true {
b.cmdThanks()
fmt.Fprintf(w, "API Request Show Acknowledgements Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Show Acknowledgements Denied\n")
}
case "ShowUptime":
case "showuptime":
if APIDisplayVersion {
b.cmdShowUptime()
fmt.Fprintf(w, "API Request Current Version Successfully\n")
} else {
fmt.Fprintf(w, "API Request Current Version Denied\n")
}
case "DumpXMLConfig":
case "dumpxmlconfig":
if APIPrintXmlConfig {
b.cmdDumpXMLConfig()
fmt.Fprintf(w, "API Print XML Config Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Print XML Congfig Denied\n")
}
case "PlayRepeaterTone":
case "playrepeatertone":
b.cmdPlayRepeaterTone()
fmt.Fprintf(w, "API Play Repeater Tone Processed Successfully\n")
case "setvoicetarget":
fmt.Fprintf(w, "API Set Voice Target to ID %v Processed Successfully\n", ID)
b.cmdSendVoiceTargets(uint32(ID))
default:
fmt.Fprintf(w, "API Command Not Defined\n")
}
Expand Down
4 changes: 2 additions & 2 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import (

//version and release date
const (
talkkonnectVersion string = "1.67.06"
talkkonnectReleased string = "Aug 19 2021"
talkkonnectVersion string = "1.67.07"
talkkonnectReleased string = "Aug 20 2021"
)

// Generic Global Variables
Expand Down

0 comments on commit 86466f5

Please sign in to comment.