This commit is contained in:
Nonoo 2020-10-27 09:25:36 +01:00
parent 5a6d2b5901
commit bb1b04caae
3 changed files with 13 additions and 12 deletions

View file

@ -98,7 +98,7 @@ func (a *audioStruct) recLoop(deinitNeededChan, deinitFinishedChan chan bool) {
}
// Do not send silence frames to the radio unnecessarily
if allZero(frameBuf[:n]) {
if isAllZero(frameBuf[:n]) {
continue
}
buf.Write(frameBuf[:n])

View file

@ -5,7 +5,6 @@ import (
"encoding/binary"
"errors"
"fmt"
"strings"
"time"
)
@ -129,14 +128,6 @@ func (s *controlStream) sendRequestSerialAndAudio() error {
return nil
}
func (s *controlStream) parseNullTerminatedString(d []byte) (res string) {
nullIndex := strings.Index(string(d), "\x00")
if nullIndex > 0 {
res = string(d[:nullIndex])
}
return
}
func (s *controlStream) handleRead(r []byte) error {
switch len(r) {
case 64:
@ -207,7 +198,7 @@ func (s *controlStream) handleRead(r []byte) error {
s.secondAuthTimer.Stop()
s.requestSerialAndAudioTimeout.Stop()
devName := s.parseNullTerminatedString(r[64:])
devName := parseNullTerminatedString(r[64:])
log.Print("got serial and audio request success, device name: ", devName)
// Stuff can change in the meantime because of a previous login...

12
util.go
View file

@ -1,7 +1,9 @@
package main
import "strings"
// Checks if all bytes are zeros
func allZero(s []byte) bool {
func isAllZero(s []byte) bool {
for _, v := range s {
if v != 0 {
return false
@ -9,3 +11,11 @@ func allZero(s []byte) bool {
}
return true
}
func parseNullTerminatedString(d []byte) (res string) {
nullIndex := strings.Index(string(d), "\x00")
if nullIndex > 0 {
res = string(d[:nullIndex])
}
return
}