Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Jul 22, 2021
1 parent 87fbbee commit 7dc8204
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 741 deletions.
8 changes: 4 additions & 4 deletions autoprovision.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func autoProvision() error {
log.Println("info: Trying to Autoprovision with URL: ", fileURL)
err := downloadFile(SaveFilePath, SaveFilename, fileURL)
if err != nil {
return fmt.Errorf("error: DownloadFile Module Returned an Error: ", err.Error())
return fmt.Errorf("error: DownloadFile Module Returned an Error: %q", err.Error())
}

return nil
Expand All @@ -90,19 +90,19 @@ func downloadFile(SaveFilePath string, SaveFilename string, URL string) error {
if resp.StatusCode == 200 {
log.Println("debug: HTTP Provisioning Server Responded With Status 200 OK ")
} else {
return fmt.Errorf("error: HTTP Provisioning Server Returned Status ", resp.StatusCode, " ", http.StatusText(resp.StatusCode))
return fmt.Errorf("error: HTTP Provisioning Server Returned Status %q %q", resp.StatusCode, http.StatusText(resp.StatusCode))

}

out, err := os.Create(SaveFilePath + SaveFilename)
if err != nil {
return fmt.Errorf("error: Cannot Create File Error: ", err.Error())
return fmt.Errorf("error: Cannot Create File Error: %q", err.Error())
}
defer out.Close()

_, err = io.Copy(out, resp.Body)
if err != nil {
return fmt.Errorf("error: Cannot Copy File Error: ", err.Error())
return fmt.Errorf("error: Cannot Copy File Error: %q", err.Error())
}

return nil
Expand Down
61 changes: 9 additions & 52 deletions avrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func AudioRecordTraffic() {
createDirIfNotExist(AudioRecordSavePath)
createDirIfNotExist(AudioRecordArchivePath)
emptydirchk, err := dirIsEmpty(AudioRecordSavePath)
if err == nil && emptydirchk == false {
if err == nil && !emptydirchk {

filezip := time.Now().Format("20060102150405") + ".zip"
go zipit(AudioRecordSavePath+"/", AudioRecordArchivePath+"/"+filezip)
Expand All @@ -77,7 +77,6 @@ func AudioRecordTraffic() {
go audiorecordtraffic()
log.Println("debug: sox is Recording Traffic to", AudioRecordSavePath)

return
}

// Record ambient audio from microphone with sox
Expand All @@ -87,7 +86,7 @@ func AudioRecordAmbient() {
createDirIfNotExist(AudioRecordSavePath)
createDirIfNotExist(AudioRecordArchivePath)
emptydirchk, err := dirIsEmpty(AudioRecordSavePath)
if err == nil && emptydirchk == false {
if err == nil && !emptydirchk {
filezip := time.Now().Format("20060102150405") + ".zip"
go zipit(AudioRecordSavePath+"/", AudioRecordArchivePath+"/"+filezip) // path to end with "/" or not?
log.Println("info: Archiving Old Audio Files to", AudioRecordArchivePath+"/"+filezip)
Expand All @@ -99,7 +98,6 @@ func AudioRecordAmbient() {
time.Sleep(1 * time.Second)
go audiorecordambientmux()

return
}

// Record both incoming Mumble traffic and ambient audio with sox
Expand All @@ -109,7 +107,7 @@ func AudioRecordCombo() {
createDirIfNotExist(AudioRecordSavePath)
createDirIfNotExist(AudioRecordArchivePath)
emptydirchk, err := dirIsEmpty(AudioRecordSavePath)
if err == nil && emptydirchk == false {
if err == nil && !emptydirchk {
filezip := time.Now().Format("20060102150405") + ".zip"
go zipit(AudioRecordSavePath+"/", AudioRecordArchivePath+"/"+filezip)
log.Println("info: Archiving Old Audio Files to", AudioRecordArchivePath+"/"+filezip)
Expand All @@ -121,28 +119,6 @@ func AudioRecordCombo() {
time.Sleep(1 * time.Second)
go audiorecordcombomux()

return
}

//Record traffic with mux exclusion. Allow new start only if currently not running.

func audiorecordtrafficmux() { // check if mux for this is working?

JobIsrunningMu.Lock()
start := !jobIsRunning
jobIsRunning = true
JobIsrunningMu.Unlock()

if start {
go func() {
audiorecordtraffic()
JobIsrunningMu.Lock()
jobIsRunning = false
JobIsrunningMu.Unlock()
}()
} else {
log.Println("info: Traffic Audio Recording is Already Running. Please Wait.")
}
}

// sox function for traffic recording
Expand All @@ -151,7 +127,7 @@ func audiorecordtraffic() {

// check if external program is installed?
checkfile := isCommandAvailable("/usr/bin/sox")
if checkfile == false {
if !checkfile {
log.Println("error: sox is Missing. Is the Package Installed?")
}

Expand Down Expand Up @@ -206,7 +182,7 @@ func audiorecordtraffic() {

emptydirchk, err := dirIsEmpty(AudioRecordSavePath) // If sox didn't start recording for wrong parameters or any reason... No file.

if err == nil && emptydirchk == false {
if err == nil && !emptydirchk {
log.Println("info: sox is Recording Traffic to", AudioRecordSavePath)
log.Println("info: sox will Go On Recording, Until it Runs out of Space or is Interrupted")

Expand Down Expand Up @@ -256,7 +232,7 @@ func audiorecordambientmux() {
func audiorecordambient() {

checkfile := isCommandAvailable("/usr/bin/sox")
if checkfile == false {
if !checkfile {
log.Println("error: sox is Missing. Is the Package Installed?")
}

Expand Down Expand Up @@ -308,7 +284,7 @@ func audiorecordambient() {

emptydirchk, err := dirIsEmpty(AudioRecordSavePath) // If sox didn't start recording for wrong parameters or any reason... No file.

if err == nil && emptydirchk == false {
if err == nil && !emptydirchk {
log.Println("info: sox is Recording Ambient Audio to", AudioRecordSavePath)
log.Println("warn: sox will Go On Recording, Until it Runs out of Space or is Interrupted")

Expand Down Expand Up @@ -358,7 +334,7 @@ func audiorecordcombomux() {
func audiorecordcombo() {

checkfile := isCommandAvailable("/usr/bin/sox")
if checkfile == false {
if !checkfile {
log.Println("error: sox is Missing. Is the Package Installed?")
}

Expand Down Expand Up @@ -416,7 +392,7 @@ func audiorecordcombo() {

emptydirchk, err := dirIsEmpty(AudioRecordSavePath) // If sox didn't start recording for wrong parameters or any reason... No files.

if err == nil && emptydirchk == false {
if err == nil && !emptydirchk {
log.Println("info: sox is Recording Mixed Audio to", AudioRecordSavePath)
log.Println("warn: sox will Go On Recording, Until it Runs out of Space or is Interrupted")

Expand All @@ -439,22 +415,3 @@ func audiorecordcombo() {
}
}
}

func fileserve3mux() {

JobIsrunningMu.Lock()
start := !jobIsRunning
jobIsRunning = true
JobIsrunningMu.Unlock()

if start {
go func() {
fileserve3()
JobIsrunningMu.Lock()
jobIsRunning = false
JobIsrunningMu.Unlock()
}()
} else {
log.Println("info: Ambient Audio Recording is Already Running. Please Wait.")
}
}
52 changes: 25 additions & 27 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ import (
"crypto/rand"
"crypto/tls"
"fmt"
"io"
"log"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"

"github.com/comail/colog"
hd44780 "github.com/talkkonnect/go-hd44780"
"github.com/talkkonnect/gpio"
Expand All @@ -42,14 +51,6 @@ import (
_ "github.com/talkkonnect/gumble/opus"
term "github.com/talkkonnect/termbox-go"
"github.com/talkkonnect/volume-go"
"io"
"log"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"
)

var (
Expand All @@ -59,8 +60,6 @@ var (
prevParticipantCount int = 0
prevButtonPress string = "none"
maxchannelid uint32
origVolume int
tempVolume int
ConfigXMLFile string
Streaming bool
ServerHop bool
Expand All @@ -76,7 +75,7 @@ var (
GPSSpeed float64
GPSCourse float64
GPSVariation float64
m string
m string
)

type Talkkonnect struct {
Expand Down Expand Up @@ -173,7 +172,6 @@ func Init(file string, ServerIndex string) {
log.Println("info: Default Loglevel unset in XML config automatically loglevel to Info")
}


if APEnabled {
log.Println("info: Contacting http Provisioning Server Pls Wait")
err := autoProvision()
Expand All @@ -190,7 +188,7 @@ func Init(file string, ServerIndex string) {
if NextServerIndex > 0 {
AccountIndex = NextServerIndex
} else {
AccountIndex, err = strconv.Atoi(ServerIndex)
AccountIndex, _ = strconv.Atoi(ServerIndex)
}

b := Talkkonnect{
Expand All @@ -203,7 +201,7 @@ func Init(file string, ServerIndex string) {
Daemonize: Daemonize,
}

if MQTTEnabled == true {
if MQTTEnabled {
log.Printf("info: Attempting to Contact MQTT Server")
log.Printf("info: MQTT Broker : %s\n", MQTTBroker)
log.Printf("info: Subscribed topic : %s\n", MQTTTopic)
Expand Down Expand Up @@ -303,7 +301,7 @@ func (b *Talkkonnect) ClientStart() {
log.Println("info: Target Board Set as PC (gpio disabled) ")
}

if (TargetBoard == "rpi" && LCDBackLightTimerEnabled == true) && (OLEDEnabled == true || LCDEnabled == true) {
if (TargetBoard == "rpi" && LCDBackLightTimerEnabled) && (OLEDEnabled || LCDEnabled) {

log.Println("info: Backlight Timer Enabled by Config")
BackLightTime = *BackLightTimePtr
Expand All @@ -325,7 +323,7 @@ func (b *Talkkonnect) ClientStart() {
}
lcd.ToggleBacklight()
}
if OLEDEnabled == true && OLEDInterfacetype == "i2c" {
if OLEDEnabled && OLEDInterfacetype == "i2c" {
Oled.DisplayOff()
LCDIsDark = true
}
Expand Down Expand Up @@ -371,7 +369,7 @@ func (b *Talkkonnect) ClientStart() {
if HeartBeatEnabled {
b.LEDOff(b.HeartBeatLED)
}
if KillHeartBeat == true {
if KillHeartBeat {
HeartBeat.Stop()
}

Expand All @@ -394,31 +392,31 @@ func (b *Talkkonnect) ClientStart() {

b.BackLightTimer()

if LCDEnabled == true {
if LCDEnabled {
b.LEDOn(b.BackLightLED)
LCDIsDark = false
}

if OLEDEnabled == true {
if OLEDEnabled {
Oled.DisplayOn()
LCDIsDark = false
}

if AudioRecordEnabled == true {
if AudioRecordEnabled {

if AudioRecordOnStart == true {
if AudioRecordOnStart {

if AudioRecordMode != "" {

if AudioRecordMode == "traffic" {
log.Println("info: Incoming Traffic will be Recorded with sox")
AudioRecordTraffic()
if TargetBoard == "rpi" {
if LCDEnabled == true {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Traffic Recording ->"} // 4
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled == true {
if OLEDEnabled {
oledDisplay(false, 6, 1, "Traffic Recording") // 6
}
}
Expand All @@ -427,11 +425,11 @@ func (b *Talkkonnect) ClientStart() {
log.Println("info: Ambient Audio from Mic will be Recorded with sox")
AudioRecordAmbient()
if TargetBoard == "rpi" {
if LCDEnabled == true {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Mic Recording ->"} // 4
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled == true {
if OLEDEnabled {
oledDisplay(false, 6, 1, "Mic Recording") // 6
}
}
Expand All @@ -440,11 +438,11 @@ func (b *Talkkonnect) ClientStart() {
log.Println("info: Both Incoming Traffic and Ambient Audio from Mic will be Recorded with sox")
AudioRecordCombo()
if TargetBoard == "rpi" {
if LCDEnabled == true {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Combo Recording ->"} // 4
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled == true {
if OLEDEnabled {
oledDisplay(false, 6, 1, "Combo Recording") //6
}
}
Expand Down
Loading

0 comments on commit 7dc8204

Please sign in to comment.