mirror of
https://github.com/nonoo/kappanhang.git
synced 2025-12-06 08:02:00 +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
|
// Do not send silence frames to the radio unnecessarily
|
||||||
if allZero(frameBuf[:n]) {
|
if isAllZero(frameBuf[:n]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
buf.Write(frameBuf[:n])
|
buf.Write(frameBuf[:n])
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -129,14 +128,6 @@ func (s *controlStream) sendRequestSerialAndAudio() error {
|
||||||
return nil
|
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 {
|
func (s *controlStream) handleRead(r []byte) error {
|
||||||
switch len(r) {
|
switch len(r) {
|
||||||
case 64:
|
case 64:
|
||||||
|
|
@ -207,7 +198,7 @@ func (s *controlStream) handleRead(r []byte) error {
|
||||||
s.secondAuthTimer.Stop()
|
s.secondAuthTimer.Stop()
|
||||||
s.requestSerialAndAudioTimeout.Stop()
|
s.requestSerialAndAudioTimeout.Stop()
|
||||||
|
|
||||||
devName := s.parseNullTerminatedString(r[64:])
|
devName := parseNullTerminatedString(r[64:])
|
||||||
log.Print("got serial and audio request success, device name: ", devName)
|
log.Print("got serial and audio request success, device name: ", devName)
|
||||||
|
|
||||||
// Stuff can change in the meantime because of a previous login...
|
// Stuff can change in the meantime because of a previous login...
|
||||||
|
|
|
||||||
12
util.go
12
util.go
|
|
@ -1,7 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
// Checks if all bytes are zeros
|
// Checks if all bytes are zeros
|
||||||
func allZero(s []byte) bool {
|
func isAllZero(s []byte) bool {
|
||||||
for _, v := range s {
|
for _, v := range s {
|
||||||
if v != 0 {
|
if v != 0 {
|
||||||
return false
|
return false
|
||||||
|
|
@ -9,3 +11,11 @@ func allZero(s []byte) bool {
|
||||||
}
|
}
|
||||||
return true
|
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