mirror of
https://github.com/nonoo/kappanhang.git
synced 2025-12-05 23:52:01 +01:00
Cleanup
This commit is contained in:
parent
5a6d2b5901
commit
bb1b04caae
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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
12
util.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue